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

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.116! raeburn     4: # $Id: loncommon.pm,v 1.1075.2.115 2016/10/22 19:10:11 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.1075.2.69  raeburn    72: use Apache::courseclassifier();
1.479     albertel   73: use LONCAPA qw(:DEFAULT :match);
1.657     raeburn    74: use DateTime::TimeZone;
1.1075.2.102  raeburn    75: use DateTime::Locale;
1.1075.2.94  raeburn    76: use Encode();
1.1075.2.14  raeburn    77: use Authen::Captcha;
                     78: use Captcha::reCAPTCHA;
1.1075.2.107  raeburn    79: use JSON::DWIW;
                     80: use LWP::UserAgent;
1.1075.2.64  raeburn    81: use Crypt::DES;
                     82: use DynaLoader; # for Crypt::DES version
1.117     www        83: 
1.517     raeburn    84: # ---------------------------------------------- Designs
                     85: use vars qw(%defaultdesign);
                     86: 
1.22      www        87: my $readit;
                     88: 
1.517     raeburn    89: 
1.157     matthew    90: ##
                     91: ## Global Variables
                     92: ##
1.46      matthew    93: 
1.643     foxr       94: 
                     95: # ----------------------------------------------- SSI with retries:
                     96: #
                     97: 
                     98: =pod
                     99: 
1.648     raeburn   100: =head1 Server Side include with retries:
1.643     foxr      101: 
                    102: =over 4
                    103: 
1.648     raeburn   104: =item * &ssi_with_retries(resource,retries form)
1.643     foxr      105: 
                    106: Performs an ssi with some number of retries.  Retries continue either
                    107: until the result is ok or until the retry count supplied by the
                    108: caller is exhausted.  
                    109: 
                    110: Inputs:
1.648     raeburn   111: 
                    112: =over 4
                    113: 
1.643     foxr      114: resource   - Identifies the resource to insert.
1.648     raeburn   115: 
1.643     foxr      116: retries    - Count of the number of retries allowed.
1.648     raeburn   117: 
1.643     foxr      118: form       - Hash that identifies the rendering options.
                    119: 
1.648     raeburn   120: =back
                    121: 
                    122: Returns:
                    123: 
                    124: =over 4
                    125: 
1.643     foxr      126: content    - The content of the response.  If retries were exhausted this is empty.
1.648     raeburn   127: 
1.643     foxr      128: response   - The response from the last attempt (which may or may not have been successful.
                    129: 
1.648     raeburn   130: =back
                    131: 
                    132: =back
                    133: 
1.643     foxr      134: =cut
                    135: 
                    136: sub ssi_with_retries {
                    137:     my ($resource, $retries, %form) = @_;
                    138: 
                    139: 
                    140:     my $ok = 0;			# True if we got a good response.
                    141:     my $content;
                    142:     my $response;
                    143: 
                    144:     # Try to get the ssi done. within the retries count:
                    145: 
                    146:     do {
                    147: 	($content, $response) = &Apache::lonnet::ssi($resource, %form);
                    148: 	$ok      = $response->is_success;
1.650     www       149:         if (!$ok) {
                    150:             &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
                    151:         }
1.643     foxr      152: 	$retries--;
                    153:     } while (!$ok && ($retries > 0));
                    154: 
                    155:     if (!$ok) {
                    156: 	$content = '';		# On error return an empty content.
                    157:     }
                    158:     return ($content, $response);
                    159: 
                    160: }
                    161: 
                    162: 
                    163: 
1.20      www       164: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12      harris41  165: my %language;
1.124     www       166: my %supported_language;
1.1048    foxr      167: my %latex_language;		# For choosing hyphenation in <transl..>
                    168: my %latex_language_bykey;	# for choosing hyphenation from metadata
1.12      harris41  169: my %cprtag;
1.192     taceyjo1  170: my %scprtag;
1.351     www       171: my %fe; my %fd; my %fm;
1.41      ng        172: my %category_extensions;
1.12      harris41  173: 
1.46      matthew   174: # ---------------------------------------------- Thesaurus variables
1.144     matthew   175: #
                    176: # %Keywords:
                    177: #      A hash used by &keyword to determine if a word is considered a keyword.
                    178: # $thesaurus_db_file 
                    179: #      Scalar containing the full path to the thesaurus database.
1.46      matthew   180: 
                    181: my %Keywords;
                    182: my $thesaurus_db_file;
                    183: 
1.144     matthew   184: #
                    185: # Initialize values from language.tab, copyright.tab, filetypes.tab,
                    186: # thesaurus.tab, and filecategories.tab.
                    187: #
1.18      www       188: BEGIN {
1.46      matthew   189:     # Variable initialization
                    190:     $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
                    191:     #
1.22      www       192:     unless ($readit) {
1.12      harris41  193: # ------------------------------------------------------------------- languages
                    194:     {
1.158     raeburn   195:         my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    196:                                    '/language.tab';
                    197:         if ( open(my $fh,"<$langtabfile") ) {
1.356     albertel  198:             while (my $line = <$fh>) {
                    199:                 next if ($line=~/^\#/);
                    200:                 chomp($line);
1.1048    foxr      201:                 my ($key,$two,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158     raeburn   202:                 $language{$key}=$val.' - '.$enc;
                    203:                 if ($sup) {
                    204:                     $supported_language{$key}=$sup;
                    205:                 }
1.1048    foxr      206: 		if ($latex) {
                    207: 		    $latex_language_bykey{$key} = $latex;
                    208: 		    $latex_language{$two} = $latex;
                    209: 		}
1.158     raeburn   210:             }
                    211:             close($fh);
                    212:         }
1.12      harris41  213:     }
                    214: # ------------------------------------------------------------------ copyrights
                    215:     {
1.158     raeburn   216:         my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
                    217:                                   '/copyright.tab';
                    218:         if ( open (my $fh,"<$copyrightfile") ) {
1.356     albertel  219:             while (my $line = <$fh>) {
                    220:                 next if ($line=~/^\#/);
                    221:                 chomp($line);
                    222:                 my ($key,$val)=(split(/\s+/,$line,2));
1.158     raeburn   223:                 $cprtag{$key}=$val;
                    224:             }
                    225:             close($fh);
                    226:         }
1.12      harris41  227:     }
1.351     www       228: # ----------------------------------------------------------- source copyrights
1.192     taceyjo1  229:     {
                    230:         my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
                    231:                                   '/source_copyright.tab';
                    232:         if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356     albertel  233:             while (my $line = <$fh>) {
                    234:                 next if ($line =~ /^\#/);
                    235:                 chomp($line);
                    236:                 my ($key,$val)=(split(/\s+/,$line,2));
1.192     taceyjo1  237:                 $scprtag{$key}=$val;
                    238:             }
                    239:             close($fh);
                    240:         }
                    241:     }
1.63      www       242: 
1.517     raeburn   243: # -------------------------------------------------------------- default domain designs
1.63      www       244:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517     raeburn   245:     my $designfile = $designdir.'/default.tab';
                    246:     if ( open (my $fh,"<$designfile") ) {
                    247:         while (my $line = <$fh>) {
                    248:             next if ($line =~ /^\#/);
                    249:             chomp($line);
                    250:             my ($key,$val)=(split(/\=/,$line));
                    251:             if ($val) { $defaultdesign{$key}=$val; }
                    252:         }
                    253:         close($fh);
1.63      www       254:     }
                    255: 
1.15      harris41  256: # ------------------------------------------------------------- file categories
                    257:     {
1.158     raeburn   258:         my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    259:                                   '/filecategories.tab';
                    260:         if ( open (my $fh,"<$categoryfile") ) {
1.356     albertel  261: 	    while (my $line = <$fh>) {
                    262: 		next if ($line =~ /^\#/);
                    263: 		chomp($line);
                    264:                 my ($extension,$category)=(split(/\s+/,$line,2));
1.158     raeburn   265:                 push @{$category_extensions{lc($category)}},$extension;
                    266:             }
                    267:             close($fh);
                    268:         }
                    269: 
1.15      harris41  270:     }
1.12      harris41  271: # ------------------------------------------------------------------ file types
                    272:     {
1.158     raeburn   273:         my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    274:                '/filetypes.tab';
                    275:         if ( open (my $fh,"<$typesfile") ) {
1.356     albertel  276:             while (my $line = <$fh>) {
                    277: 		next if ($line =~ /^\#/);
                    278: 		chomp($line);
                    279:                 my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158     raeburn   280:                 if ($descr ne '') {
                    281:                     $fe{$ending}=lc($emb);
                    282:                     $fd{$ending}=$descr;
1.351     www       283:                     if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158     raeburn   284:                 }
                    285:             }
                    286:             close($fh);
                    287:         }
1.12      harris41  288:     }
1.22      www       289:     &Apache::lonnet::logthis(
1.705     tempelho  290:              "<span style='color:yellow;'>INFO: Read file types</span>");
1.22      www       291:     $readit=1;
1.46      matthew   292:     }  # end of unless($readit) 
1.32      matthew   293:     
                    294: }
1.112     bowersj2  295: 
1.42      matthew   296: ###############################################################
                    297: ##           HTML and Javascript Helper Functions            ##
                    298: ###############################################################
                    299: 
                    300: =pod 
                    301: 
1.112     bowersj2  302: =head1 HTML and Javascript Functions
1.42      matthew   303: 
1.112     bowersj2  304: =over 4
                    305: 
1.648     raeburn   306: =item * &browser_and_searcher_javascript()
1.112     bowersj2  307: 
                    308: X<browsing, javascript>X<searching, javascript>Returns a string
                    309: containing javascript with two functions, C<openbrowser> and
                    310: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
                    311: tags.
1.42      matthew   312: 
1.648     raeburn   313: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42      matthew   314: 
                    315: inputs: formname, elementname, only, omit
                    316: 
                    317: formname and elementname indicate the name of the html form and name of
                    318: the element that the results of the browsing selection are to be placed in. 
                    319: 
                    320: Specifying 'only' will restrict the browser to displaying only files
1.185     www       321: with the given extension.  Can be a comma separated list.
1.42      matthew   322: 
                    323: Specifying 'omit' will restrict the browser to NOT displaying files
1.185     www       324: with the given extension.  Can be a comma separated list.
1.42      matthew   325: 
1.648     raeburn   326: =item * &opensearcher(formname,elementname) [javascript]
1.42      matthew   327: 
                    328: Inputs: formname, elementname
                    329: 
                    330: formname and elementname specify the name of the html form and the name
                    331: of the element the selection from the search results will be placed in.
1.542     raeburn   332: 
1.42      matthew   333: =cut
                    334: 
                    335: sub browser_and_searcher_javascript {
1.199     albertel  336:     my ($mode)=@_;
                    337:     if (!defined($mode)) { $mode='edit'; }
1.453     albertel  338:     my $resurl=&escape_single(&lastresurl());
1.42      matthew   339:     return <<END;
1.219     albertel  340: // <!-- BEGIN LON-CAPA Internal
1.50      matthew   341:     var editbrowser = null;
1.135     albertel  342:     function openbrowser(formname,elementname,only,omit,titleelement) {
1.170     www       343:         var url = '$resurl/?';
1.42      matthew   344:         if (editbrowser == null) {
                    345:             url += 'launch=1&';
                    346:         }
                    347:         url += 'catalogmode=interactive&';
1.199     albertel  348:         url += 'mode=$mode&';
1.611     albertel  349:         url += 'inhibitmenu=yes&';
1.42      matthew   350:         url += 'form=' + formname + '&';
                    351:         if (only != null) {
                    352:             url += 'only=' + only + '&';
1.217     albertel  353:         } else {
                    354:             url += 'only=&';
                    355: 	}
1.42      matthew   356:         if (omit != null) {
                    357:             url += 'omit=' + omit + '&';
1.217     albertel  358:         } else {
                    359:             url += 'omit=&';
                    360: 	}
1.135     albertel  361:         if (titleelement != null) {
                    362:             url += 'titleelement=' + titleelement + '&';
1.217     albertel  363:         } else {
                    364: 	    url += 'titleelement=&';
                    365: 	}
1.42      matthew   366:         url += 'element=' + elementname + '';
                    367:         var title = 'Browser';
1.435     albertel  368:         var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42      matthew   369:         options += ',width=700,height=600';
                    370:         editbrowser = open(url,title,options,'1');
                    371:         editbrowser.focus();
                    372:     }
                    373:     var editsearcher;
1.135     albertel  374:     function opensearcher(formname,elementname,titleelement) {
1.42      matthew   375:         var url = '/adm/searchcat?';
                    376:         if (editsearcher == null) {
                    377:             url += 'launch=1&';
                    378:         }
                    379:         url += 'catalogmode=interactive&';
1.199     albertel  380:         url += 'mode=$mode&';
1.42      matthew   381:         url += 'form=' + formname + '&';
1.135     albertel  382:         if (titleelement != null) {
                    383:             url += 'titleelement=' + titleelement + '&';
1.217     albertel  384:         } else {
                    385: 	    url += 'titleelement=&';
                    386: 	}
1.42      matthew   387:         url += 'element=' + elementname + '';
                    388:         var title = 'Search';
1.435     albertel  389:         var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42      matthew   390:         options += ',width=700,height=600';
                    391:         editsearcher = open(url,title,options,'1');
                    392:         editsearcher.focus();
                    393:     }
1.219     albertel  394: // END LON-CAPA Internal -->
1.42      matthew   395: END
1.170     www       396: }
                    397: 
                    398: sub lastresurl {
1.258     albertel  399:     if ($env{'environment.lastresurl'}) {
                    400: 	return $env{'environment.lastresurl'}
1.170     www       401:     } else {
                    402: 	return '/res';
                    403:     }
                    404: }
                    405: 
                    406: sub storeresurl {
                    407:     my $resurl=&Apache::lonnet::clutter(shift);
                    408:     unless ($resurl=~/^\/res/) { return 0; }
                    409:     $resurl=~s/\/$//;
                    410:     &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646     raeburn   411:     &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170     www       412:     return 1;
1.42      matthew   413: }
                    414: 
1.74      www       415: sub studentbrowser_javascript {
1.111     www       416:    unless (
1.258     albertel  417:             (($env{'request.course.id'}) && 
1.302     albertel  418:              (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    419: 	      || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                    420: 					  '/'.$env{'request.course.sec'})
                    421: 	      ))
1.258     albertel  422:          || ($env{'request.role'}=~/^(au|dc|su)/)
1.111     www       423:           ) { return ''; }  
1.74      www       424:    return (<<'ENDSTDBRW');
1.776     bisitz    425: <script type="text/javascript" language="Javascript">
1.824     bisitz    426: // <![CDATA[
1.74      www       427:     var stdeditbrowser;
1.999     www       428:     function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74      www       429:         var url = '/adm/pickstudent?';
                    430:         var filter;
1.558     albertel  431: 	if (!ignorefilter) {
                    432: 	    eval('filter=document.'+formname+'.'+uname+'.value;');
                    433: 	}
1.74      www       434:         if (filter != null) {
                    435:            if (filter != '') {
                    436:                url += 'filter='+filter+'&';
                    437: 	   }
                    438:         }
                    439:         url += 'form=' + formname + '&unameelement='+uname+
1.999     www       440:                                     '&udomelement='+udom+
                    441:                                     '&clicker='+clicker;
1.111     www       442: 	if (roleflag) { url+="&roles=1"; }
1.793     raeburn   443:         if (courseadvonly) { url+="&courseadvonly=1"; }
1.102     www       444:         var title = 'Student_Browser';
1.74      www       445:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    446:         options += ',width=700,height=600';
                    447:         stdeditbrowser = open(url,title,options,'1');
                    448:         stdeditbrowser.focus();
                    449:     }
1.824     bisitz    450: // ]]>
1.74      www       451: </script>
                    452: ENDSTDBRW
                    453: }
1.42      matthew   454: 
1.1003    www       455: sub resourcebrowser_javascript {
                    456:    unless ($env{'request.course.id'}) { return ''; }
1.1004    www       457:    return (<<'ENDRESBRW');
1.1003    www       458: <script type="text/javascript" language="Javascript">
                    459: // <![CDATA[
                    460:     var reseditbrowser;
1.1004    www       461:     function openresbrowser(formname,reslink) {
1.1005    www       462:         var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003    www       463:         var title = 'Resource_Browser';
                    464:         var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005    www       465:         options += ',width=700,height=500';
1.1004    www       466:         reseditbrowser = open(url,title,options,'1');
                    467:         reseditbrowser.focus();
1.1003    www       468:     }
                    469: // ]]>
                    470: </script>
1.1004    www       471: ENDRESBRW
1.1003    www       472: }
                    473: 
1.74      www       474: sub selectstudent_link {
1.999     www       475:    my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
                    476:    my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
                    477:                       &Apache::lonhtmlcommon::entity_encode($unameele)."','".
                    478:                       &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258     albertel  479:    if ($env{'request.course.id'}) {  
1.302     albertel  480:        if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    481: 	   && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                    482: 					'/'.$env{'request.course.sec'})) {
1.111     www       483: 	   return '';
                    484:        }
1.999     www       485:        $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793     raeburn   486:        if ($courseadvonly)  {
                    487:            $callargs .= ",'',1,1";
                    488:        }
                    489:        return '<span class="LC_nobreak">'.
                    490:               '<a href="javascript:openstdbrowser('.$callargs.');">'.
                    491:               &mt('Select User').'</a></span>';
1.74      www       492:    }
1.258     albertel  493:    if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012    www       494:        $callargs .= ",'',1"; 
1.793     raeburn   495:        return '<span class="LC_nobreak">'.
                    496:               '<a href="javascript:openstdbrowser('.$callargs.');">'.
                    497:               &mt('Select User').'</a></span>';
1.111     www       498:    }
                    499:    return '';
1.91      www       500: }
                    501: 
1.1004    www       502: sub selectresource_link {
                    503:    my ($form,$reslink,$arg)=@_;
                    504:    
                    505:    my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
                    506:                       &Apache::lonhtmlcommon::entity_encode($reslink)."'";
                    507:    unless ($env{'request.course.id'}) { return $arg; }
                    508:    return '<span class="LC_nobreak">'.
                    509:               '<a href="javascript:openresbrowser('.$callargs.');">'.
                    510:               $arg.'</a></span>';
                    511: }
                    512: 
                    513: 
                    514: 
1.653     raeburn   515: sub authorbrowser_javascript {
                    516:     return <<"ENDAUTHORBRW";
1.776     bisitz    517: <script type="text/javascript" language="JavaScript">
1.824     bisitz    518: // <![CDATA[
1.653     raeburn   519: var stdeditbrowser;
                    520: 
                    521: function openauthorbrowser(formname,udom) {
                    522:     var url = '/adm/pickauthor?';
                    523:     url += 'form='+formname+'&roledom='+udom;
                    524:     var title = 'Author_Browser';
                    525:     var options = 'scrollbars=1,resizable=1,menubar=0';
                    526:     options += ',width=700,height=600';
                    527:     stdeditbrowser = open(url,title,options,'1');
                    528:     stdeditbrowser.focus();
                    529: }
                    530: 
1.824     bisitz    531: // ]]>
1.653     raeburn   532: </script>
                    533: ENDAUTHORBRW
                    534: }
                    535: 
1.91      www       536: sub coursebrowser_javascript {
1.1075.2.31  raeburn   537:     my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1075.2.95  raeburn   538:         $credits_element,$instcode) = @_;
1.932     raeburn   539:     my $wintitle = 'Course_Browser';
1.931     raeburn   540:     if ($crstype eq 'Community') {
1.932     raeburn   541:         $wintitle = 'Community_Browser';
1.909     raeburn   542:     }
1.876     raeburn   543:     my $id_functions = &javascript_index_functions();
                    544:     my $output = '
1.776     bisitz    545: <script type="text/javascript" language="JavaScript">
1.824     bisitz    546: // <![CDATA[
1.468     raeburn   547:     var stdeditbrowser;'."\n";
1.876     raeburn   548: 
                    549:     $output .= <<"ENDSTDBRW";
1.909     raeburn   550:     function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91      www       551:         var url = '/adm/pickcourse?';
1.895     raeburn   552:         var formid = getFormIdByName(formname);
1.876     raeburn   553:         var domainfilter = getDomainFromSelectbox(formname,udom);
1.128     albertel  554:         if (domainfilter != null) {
                    555:            if (domainfilter != '') {
                    556:                url += 'domainfilter='+domainfilter+'&';
                    557: 	   }
                    558:         }
1.91      www       559:         url += 'form=' + formname + '&cnumelement='+uname+
1.187     albertel  560: 	                            '&cdomelement='+udom+
                    561:                                     '&cnameelement='+desc;
1.468     raeburn   562:         if (extra_element !=null && extra_element != '') {
1.594     raeburn   563:             if (formname == 'rolechoice' || formname == 'studentform') {
1.468     raeburn   564:                 url += '&roleelement='+extra_element;
                    565:                 if (domainfilter == null || domainfilter == '') {
                    566:                     url += '&domainfilter='+extra_element;
                    567:                 }
1.234     raeburn   568:             }
1.468     raeburn   569:             else {
                    570:                 if (formname == 'portform') {
                    571:                     url += '&setroles='+extra_element;
1.800     raeburn   572:                 } else {
                    573:                     if (formname == 'rules') {
                    574:                         url += '&fixeddom='+extra_element; 
                    575:                     }
1.468     raeburn   576:                 }
                    577:             }     
1.230     raeburn   578:         }
1.909     raeburn   579:         if (type != null && type != '') {
                    580:             url += '&type='+type;
                    581:         }
                    582:         if (type_elem != null && type_elem != '') {
                    583:             url += '&typeelement='+type_elem;
                    584:         }
1.872     raeburn   585:         if (formname == 'ccrs') {
                    586:             var ownername = document.forms[formid].ccuname.value;
                    587:             var ownerdom =  document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1075.2.101  raeburn   588:             url += '&cloner='+ownername+':'+ownerdom;
                    589:             if (type == 'Course') {
                    590:                 url += '&crscode='+document.forms[formid].crscode.value;
                    591:             }
1.1075.2.95  raeburn   592:         }
                    593:         if (formname == 'requestcrs') {
                    594:             url += '&crsdom=$domainfilter&crscode=$instcode';
1.872     raeburn   595:         }
1.293     raeburn   596:         if (multflag !=null && multflag != '') {
                    597:             url += '&multiple='+multflag;
                    598:         }
1.909     raeburn   599:         var title = '$wintitle';
1.91      www       600:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    601:         options += ',width=700,height=600';
                    602:         stdeditbrowser = open(url,title,options,'1');
                    603:         stdeditbrowser.focus();
                    604:     }
1.876     raeburn   605: $id_functions
                    606: ENDSTDBRW
1.1075.2.31  raeburn   607:     if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
                    608:         $output .= &setsec_javascript($sec_element,$formname,$role_element,
                    609:                                       $credits_element);
1.876     raeburn   610:     }
                    611:     $output .= '
                    612: // ]]>
                    613: </script>';
                    614:     return $output;
                    615: }
                    616: 
                    617: sub javascript_index_functions {
                    618:     return <<"ENDJS";
                    619: 
                    620: function getFormIdByName(formname) {
                    621:     for (var i=0;i<document.forms.length;i++) {
                    622:         if (document.forms[i].name == formname) {
                    623:             return i;
                    624:         }
                    625:     }
                    626:     return -1;
                    627: }
                    628: 
                    629: function getIndexByName(formid,item) {
                    630:     for (var i=0;i<document.forms[formid].elements.length;i++) {
                    631:         if (document.forms[formid].elements[i].name == item) {
                    632:             return i;
                    633:         }
                    634:     }
                    635:     return -1;
                    636: }
1.468     raeburn   637: 
1.876     raeburn   638: function getDomainFromSelectbox(formname,udom) {
                    639:     var userdom;
                    640:     var formid = getFormIdByName(formname);
                    641:     if (formid > -1) {
                    642:         var domid = getIndexByName(formid,udom);
                    643:         if (domid > -1) {
                    644:             if (document.forms[formid].elements[domid].type == 'select-one') {
                    645:                 userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
                    646:             }
                    647:             if (document.forms[formid].elements[domid].type == 'hidden') {
                    648:                 userdom=document.forms[formid].elements[domid].value;
1.468     raeburn   649:             }
                    650:         }
                    651:     }
1.876     raeburn   652:     return userdom;
                    653: }
                    654: 
                    655: ENDJS
1.468     raeburn   656: 
1.876     raeburn   657: }
                    658: 
1.1017    raeburn   659: sub javascript_array_indexof {
1.1018    raeburn   660:     return <<ENDJS;
1.1017    raeburn   661: <script type="text/javascript" language="JavaScript">
                    662: // <![CDATA[
                    663: 
                    664: if (!Array.prototype.indexOf) {
                    665:     Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
                    666:         "use strict";
                    667:         if (this === void 0 || this === null) {
                    668:             throw new TypeError();
                    669:         }
                    670:         var t = Object(this);
                    671:         var len = t.length >>> 0;
                    672:         if (len === 0) {
                    673:             return -1;
                    674:         }
                    675:         var n = 0;
                    676:         if (arguments.length > 0) {
                    677:             n = Number(arguments[1]);
                    678:             if (n !== n) { // shortcut for verifying if it's NaN
                    679:                 n = 0;
                    680:             } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
                    681:                 n = (n > 0 || -1) * Math.floor(Math.abs(n));
                    682:             }
                    683:         }
                    684:         if (n >= len) {
                    685:             return -1;
                    686:         }
                    687:         var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
                    688:         for (; k < len; k++) {
                    689:             if (k in t && t[k] === searchElement) {
                    690:                 return k;
                    691:             }
                    692:         }
                    693:         return -1;
                    694:     }
                    695: }
                    696: 
                    697: // ]]>
                    698: </script>
                    699: 
                    700: ENDJS
                    701: 
                    702: }
                    703: 
1.876     raeburn   704: sub userbrowser_javascript {
                    705:     my $id_functions = &javascript_index_functions();
                    706:     return <<"ENDUSERBRW";
                    707: 
1.888     raeburn   708: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876     raeburn   709:     var url = '/adm/pickuser?';
                    710:     var userdom = getDomainFromSelectbox(formname,udom);
                    711:     if (userdom != null) {
                    712:        if (userdom != '') {
                    713:            url += 'srchdom='+userdom+'&';
                    714:        }
                    715:     }
                    716:     url += 'form=' + formname + '&unameelement='+uname+
                    717:                                 '&udomelement='+udom+
                    718:                                 '&ulastelement='+ulast+
                    719:                                 '&ufirstelement='+ufirst+
                    720:                                 '&uemailelement='+uemail+
1.881     raeburn   721:                                 '&hideudomelement='+hideudom+
                    722:                                 '&coursedom='+crsdom;
1.888     raeburn   723:     if ((caller != null) && (caller != undefined)) {
                    724:         url += '&caller='+caller;
                    725:     }
1.876     raeburn   726:     var title = 'User_Browser';
                    727:     var options = 'scrollbars=1,resizable=1,menubar=0';
                    728:     options += ',width=700,height=600';
                    729:     var stdeditbrowser = open(url,title,options,'1');
                    730:     stdeditbrowser.focus();
                    731: }
                    732: 
1.888     raeburn   733: function fix_domain (formname,udom,origdom,uname) {
1.876     raeburn   734:     var formid = getFormIdByName(formname);
                    735:     if (formid > -1) {
1.888     raeburn   736:         var unameid = getIndexByName(formid,uname);
1.876     raeburn   737:         var domid = getIndexByName(formid,udom);
                    738:         var hidedomid = getIndexByName(formid,origdom);
                    739:         if (hidedomid > -1) {
                    740:             var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888     raeburn   741:             var unameval = document.forms[formid].elements[unameid].value;
                    742:             if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
                    743:                 if (domid > -1) {
                    744:                     var slct = document.forms[formid].elements[domid];
                    745:                     if (slct.type == 'select-one') {
                    746:                         var i;
                    747:                         for (i=0;i<slct.length;i++) {
                    748:                             if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
                    749:                         }
                    750:                     }
                    751:                     if (slct.type == 'hidden') {
                    752:                         slct.value = fixeddom;
1.876     raeburn   753:                     }
                    754:                 }
1.468     raeburn   755:             }
                    756:         }
                    757:     }
1.876     raeburn   758:     return;
                    759: }
                    760: 
                    761: $id_functions
                    762: ENDUSERBRW
1.468     raeburn   763: }
                    764: 
                    765: sub setsec_javascript {
1.1075.2.31  raeburn   766:     my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905     raeburn   767:     my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
                    768:         $communityrolestr);
                    769:     if ($role_element ne '') {
                    770:         my @allroles = ('st','ta','ep','in','ad');
                    771:         foreach my $crstype ('Course','Community') {
                    772:             if ($crstype eq 'Community') {
                    773:                 foreach my $role (@allroles) {
                    774:                     push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
                    775:                 }
                    776:                 push(@communityrolenames,&Apache::lonnet::plaintext('co'));
                    777:             } else {
                    778:                 foreach my $role (@allroles) {
                    779:                     push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
                    780:                 }
                    781:                 push(@courserolenames,&Apache::lonnet::plaintext('cc'));
                    782:             }
                    783:         }
                    784:         $rolestr = '"'.join('","',@allroles).'"';
                    785:         $courserolestr = '"'.join('","',@courserolenames).'"';
                    786:         $communityrolestr = '"'.join('","',@communityrolenames).'"';
                    787:     }
1.468     raeburn   788:     my $setsections = qq|
                    789: function setSect(sectionlist) {
1.629     raeburn   790:     var sectionsArray = new Array();
                    791:     if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
                    792:         sectionsArray = sectionlist.split(",");
                    793:     }
1.468     raeburn   794:     var numSections = sectionsArray.length;
                    795:     document.$formname.$sec_element.length = 0;
                    796:     if (numSections == 0) {
                    797:         document.$formname.$sec_element.multiple=false;
                    798:         document.$formname.$sec_element.size=1;
                    799:         document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
                    800:     } else {
                    801:         if (numSections == 1) {
                    802:             document.$formname.$sec_element.multiple=false;
                    803:             document.$formname.$sec_element.size=1;
                    804:             document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
                    805:             document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
                    806:             document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
                    807:         } else {
                    808:             for (var i=0; i<numSections; i++) {
                    809:                 document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
                    810:             }
                    811:             document.$formname.$sec_element.multiple=true
                    812:             if (numSections < 3) {
                    813:                 document.$formname.$sec_element.size=numSections;
                    814:             } else {
                    815:                 document.$formname.$sec_element.size=3;
                    816:             }
                    817:             document.$formname.$sec_element.options[0].selected = false
                    818:         }
                    819:     }
1.91      www       820: }
1.905     raeburn   821: 
                    822: function setRole(crstype) {
1.468     raeburn   823: |;
1.905     raeburn   824:     if ($role_element eq '') {
                    825:         $setsections .= '    return;
                    826: }
                    827: ';
                    828:     } else {
                    829:         $setsections .= qq|
                    830:     var elementLength = document.$formname.$role_element.length;
                    831:     var allroles = Array($rolestr);
                    832:     var courserolenames = Array($courserolestr);
                    833:     var communityrolenames = Array($communityrolestr);
                    834:     if (elementLength != undefined) {
                    835:         if (document.$formname.$role_element.options[5].value == 'cc') {
                    836:             if (crstype == 'Course') {
                    837:                 return;
                    838:             } else {
                    839:                 allroles[5] = 'co';
                    840:                 for (var i=0; i<6; i++) {
                    841:                     document.$formname.$role_element.options[i].value = allroles[i];
                    842:                     document.$formname.$role_element.options[i].text = communityrolenames[i];
                    843:                 }
                    844:             }
                    845:         } else {
                    846:             if (crstype == 'Community') {
                    847:                 return;
                    848:             } else {
                    849:                 allroles[5] = 'cc';
                    850:                 for (var i=0; i<6; i++) {
                    851:                     document.$formname.$role_element.options[i].value = allroles[i];
                    852:                     document.$formname.$role_element.options[i].text = courserolenames[i];
                    853:                 }
                    854:             }
                    855:         }
                    856:     }
                    857:     return;
                    858: }
                    859: |;
                    860:     }
1.1075.2.31  raeburn   861:     if ($credits_element) {
                    862:         $setsections .= qq|
                    863: function setCredits(defaultcredits) {
                    864:     document.$formname.$credits_element.value = defaultcredits;
                    865:     return;
                    866: }
                    867: |;
                    868:     }
1.468     raeburn   869:     return $setsections;
                    870: }
                    871: 
1.91      www       872: sub selectcourse_link {
1.909     raeburn   873:    my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
                    874:        $typeelement) = @_;
                    875:    my $type = $selecttype;
1.871     raeburn   876:    my $linktext = &mt('Select Course');
                    877:    if ($selecttype eq 'Community') {
1.909     raeburn   878:        $linktext = &mt('Select Community');
1.906     raeburn   879:    } elsif ($selecttype eq 'Course/Community') {
                    880:        $linktext = &mt('Select Course/Community');
1.909     raeburn   881:        $type = '';
1.1019    raeburn   882:    } elsif ($selecttype eq 'Select') {
                    883:        $linktext = &mt('Select');
                    884:        $type = '';
1.871     raeburn   885:    }
1.787     bisitz    886:    return '<span class="LC_nobreak">'
                    887:          ."<a href='"
                    888:          .'javascript:opencrsbrowser("'.$form.'","'.$unameele
                    889:          .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909     raeburn   890:          .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871     raeburn   891:          ."'>".$linktext.'</a>'
1.787     bisitz    892:          .'</span>';
1.74      www       893: }
1.42      matthew   894: 
1.653     raeburn   895: sub selectauthor_link {
                    896:    my ($form,$udom)=@_;
                    897:    return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
                    898:           &mt('Select Author').'</a>';
                    899: }
                    900: 
1.876     raeburn   901: sub selectuser_link {
1.881     raeburn   902:     my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888     raeburn   903:         $coursedom,$linktext,$caller) = @_;
1.876     raeburn   904:     return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888     raeburn   905:            "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881     raeburn   906:            ');">'.$linktext.'</a>';
1.876     raeburn   907: }
                    908: 
1.273     raeburn   909: sub check_uncheck_jscript {
                    910:     my $jscript = <<"ENDSCRT";
                    911: function checkAll(field) {
                    912:     if (field.length > 0) {
                    913:         for (i = 0; i < field.length; i++) {
1.1075.2.14  raeburn   914:             if (!field[i].disabled) {
                    915:                 field[i].checked = true;
                    916:             }
1.273     raeburn   917:         }
                    918:     } else {
1.1075.2.14  raeburn   919:         if (!field.disabled) {
                    920:             field.checked = true;
                    921:         }
1.273     raeburn   922:     }
                    923: }
                    924:  
                    925: function uncheckAll(field) {
                    926:     if (field.length > 0) {
                    927:         for (i = 0; i < field.length; i++) {
                    928:             field[i].checked = false ;
1.543     albertel  929:         }
                    930:     } else {
1.273     raeburn   931:         field.checked = false ;
                    932:     }
                    933: }
                    934: ENDSCRT
                    935:     return $jscript;
                    936: }
                    937: 
1.656     www       938: sub select_timezone {
1.1075.2.115  raeburn   939:    my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
                    940:    my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.659     raeburn   941:    if ($includeempty) {
                    942:        $output .= '<option value=""';
                    943:        if (($selected eq '') || ($selected eq 'local')) {
                    944:            $output .= ' selected="selected" ';
                    945:        }
                    946:        $output .= '> </option>';
                    947:    }
1.657     raeburn   948:    my @timezones = DateTime::TimeZone->all_names;
                    949:    foreach my $tzone (@timezones) {
                    950:        $output.= '<option value="'.$tzone.'"';
                    951:        if ($tzone eq $selected) {
                    952:            $output.=' selected="selected"';
                    953:        }
                    954:        $output.=">$tzone</option>\n";
1.656     www       955:    }
                    956:    $output.="</select>";
                    957:    return $output;
                    958: }
1.273     raeburn   959: 
1.687     raeburn   960: sub select_datelocale {
1.1075.2.115  raeburn   961:     my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
                    962:     my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687     raeburn   963:     if ($includeempty) {
                    964:         $output .= '<option value=""';
                    965:         if ($selected eq '') {
                    966:             $output .= ' selected="selected" ';
                    967:         }
                    968:         $output .= '> </option>';
                    969:     }
1.1075.2.102  raeburn   970:     my @languages = &Apache::lonlocal::preferred_languages();
1.687     raeburn   971:     my (@possibles,%locale_names);
1.1075.2.102  raeburn   972:     my @locales = DateTime::Locale->ids();
                    973:     foreach my $id (@locales) {
                    974:         if ($id ne '') {
                    975:             my ($en_terr,$native_terr);
                    976:             my $loc = DateTime::Locale->load($id);
                    977:             if (ref($loc)) {
                    978:                 $en_terr = $loc->name();
                    979:                 $native_terr = $loc->native_name();
1.687     raeburn   980:                 if (grep(/^en$/,@languages) || !@languages) {
                    981:                     if ($en_terr ne '') {
                    982:                         $locale_names{$id} = '('.$en_terr.')';
                    983:                     } elsif ($native_terr ne '') {
                    984:                         $locale_names{$id} = $native_terr;
                    985:                     }
                    986:                 } else {
                    987:                     if ($native_terr ne '') {
                    988:                         $locale_names{$id} = $native_terr.' ';
                    989:                     } elsif ($en_terr ne '') {
                    990:                         $locale_names{$id} = '('.$en_terr.')';
                    991:                     }
                    992:                 }
1.1075.2.94  raeburn   993:                 $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1075.2.102  raeburn   994:                 push(@possibles,$id);
1.687     raeburn   995:             }
                    996:         }
                    997:     }
                    998:     foreach my $item (sort(@possibles)) {
                    999:         $output.= '<option value="'.$item.'"';
                   1000:         if ($item eq $selected) {
                   1001:             $output.=' selected="selected"';
                   1002:         }
                   1003:         $output.=">$item";
                   1004:         if ($locale_names{$item} ne '') {
1.1075.2.94  raeburn  1005:             $output.='  '.$locale_names{$item};
1.687     raeburn  1006:         }
                   1007:         $output.="</option>\n";
                   1008:     }
                   1009:     $output.="</select>";
                   1010:     return $output;
                   1011: }
                   1012: 
1.792     raeburn  1013: sub select_language {
1.1075.2.115  raeburn  1014:     my ($name,$selected,$includeempty,$noedit) = @_;
1.792     raeburn  1015:     my %langchoices;
                   1016:     if ($includeempty) {
1.1075.2.32  raeburn  1017:         %langchoices = ('' => 'No language preference');
1.792     raeburn  1018:     }
                   1019:     foreach my $id (&languageids()) {
                   1020:         my $code = &supportedlanguagecode($id);
                   1021:         if ($code) {
                   1022:             $langchoices{$code} = &plainlanguagedescription($id);
                   1023:         }
                   1024:     }
1.1075.2.32  raeburn  1025:     %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.1075.2.115  raeburn  1026:     return &select_form($selected,$name,\%langchoices,undef,$noedit);
1.792     raeburn  1027: }
                   1028: 
1.42      matthew  1029: =pod
1.36      matthew  1030: 
1.648     raeburn  1031: =item * &linked_select_forms(...)
1.36      matthew  1032: 
                   1033: linked_select_forms returns a string containing a <script></script> block
                   1034: and html for two <select> menus.  The select menus will be linked in that
                   1035: changing the value of the first menu will result in new values being placed
                   1036: in the second menu.  The values in the select menu will appear in alphabetical
1.609     raeburn  1037: order unless a defined order is provided.
1.36      matthew  1038: 
                   1039: linked_select_forms takes the following ordered inputs:
                   1040: 
                   1041: =over 4
                   1042: 
1.112     bowersj2 1043: =item * $formname, the name of the <form> tag
1.36      matthew  1044: 
1.112     bowersj2 1045: =item * $middletext, the text which appears between the <select> tags
1.36      matthew  1046: 
1.112     bowersj2 1047: =item * $firstdefault, the default value for the first menu
1.36      matthew  1048: 
1.112     bowersj2 1049: =item * $firstselectname, the name of the first <select> tag
1.36      matthew  1050: 
1.112     bowersj2 1051: =item * $secondselectname, the name of the second <select> tag
1.36      matthew  1052: 
1.112     bowersj2 1053: =item * $hashref, a reference to a hash containing the data for the menus.
1.36      matthew  1054: 
1.609     raeburn  1055: =item * $menuorder, the order of values in the first menu
                   1056: 
1.1075.2.31  raeburn  1057: =item * $onchangefirst, additional javascript call to execute for an onchange
                   1058:         event for the first <select> tag
                   1059: 
                   1060: =item * $onchangesecond, additional javascript call to execute for an onchange
                   1061:         event for the second <select> tag
                   1062: 
1.41      ng       1063: =back 
                   1064: 
1.36      matthew  1065: Below is an example of such a hash.  Only the 'text', 'default', and 
                   1066: 'select2' keys must appear as stated.  keys(%menu) are the possible 
                   1067: values for the first select menu.  The text that coincides with the 
1.41      ng       1068: first menu value is given in $menu{$choice1}->{'text'}.  The values 
1.36      matthew  1069: and text for the second menu are given in the hash pointed to by 
                   1070: $menu{$choice1}->{'select2'}.  
                   1071: 
1.112     bowersj2 1072:  my %menu = ( A1 => { text =>"Choice A1" ,
                   1073:                        default => "B3",
                   1074:                        select2 => { 
                   1075:                            B1 => "Choice B1",
                   1076:                            B2 => "Choice B2",
                   1077:                            B3 => "Choice B3",
                   1078:                            B4 => "Choice B4"
1.609     raeburn  1079:                            },
                   1080:                        order => ['B4','B3','B1','B2'],
1.112     bowersj2 1081:                    },
                   1082:                A2 => { text =>"Choice A2" ,
                   1083:                        default => "C2",
                   1084:                        select2 => { 
                   1085:                            C1 => "Choice C1",
                   1086:                            C2 => "Choice C2",
                   1087:                            C3 => "Choice C3"
1.609     raeburn  1088:                            },
                   1089:                        order => ['C2','C1','C3'],
1.112     bowersj2 1090:                    },
                   1091:                A3 => { text =>"Choice A3" ,
                   1092:                        default => "D6",
                   1093:                        select2 => { 
                   1094:                            D1 => "Choice D1",
                   1095:                            D2 => "Choice D2",
                   1096:                            D3 => "Choice D3",
                   1097:                            D4 => "Choice D4",
                   1098:                            D5 => "Choice D5",
                   1099:                            D6 => "Choice D6",
                   1100:                            D7 => "Choice D7"
1.609     raeburn  1101:                            },
                   1102:                        order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112     bowersj2 1103:                    }
                   1104:                );
1.36      matthew  1105: 
                   1106: =cut
                   1107: 
                   1108: sub linked_select_forms {
                   1109:     my ($formname,
                   1110:         $middletext,
                   1111:         $firstdefault,
                   1112:         $firstselectname,
                   1113:         $secondselectname, 
1.609     raeburn  1114:         $hashref,
                   1115:         $menuorder,
1.1075.2.31  raeburn  1116:         $onchangefirst,
                   1117:         $onchangesecond
1.36      matthew  1118:         ) = @_;
                   1119:     my $second = "document.$formname.$secondselectname";
                   1120:     my $first = "document.$formname.$firstselectname";
                   1121:     # output the javascript to do the changing
                   1122:     my $result = '';
1.776     bisitz   1123:     $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824     bisitz   1124:     $result.="// <![CDATA[\n";
1.36      matthew  1125:     $result.="var select2data = new Object();\n";
                   1126:     $" = '","';
                   1127:     my $debug = '';
                   1128:     foreach my $s1 (sort(keys(%$hashref))) {
                   1129:         $result.="select2data.d_$s1 = new Object();\n";        
                   1130:         $result.="select2data.d_$s1.def = new String('".
                   1131:             $hashref->{$s1}->{'default'}."');\n";
1.609     raeburn  1132:         $result.="select2data.d_$s1.values = new Array(";
1.36      matthew  1133:         my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609     raeburn  1134:         if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
                   1135:             @s2values = @{$hashref->{$s1}->{'order'}};
                   1136:         }
1.36      matthew  1137:         $result.="\"@s2values\");\n";
                   1138:         $result.="select2data.d_$s1.texts = new Array(";        
                   1139:         my @s2texts;
                   1140:         foreach my $value (@s2values) {
                   1141:             push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
                   1142:         }
                   1143:         $result.="\"@s2texts\");\n";
                   1144:     }
                   1145:     $"=' ';
                   1146:     $result.= <<"END";
                   1147: 
                   1148: function select1_changed() {
                   1149:     // Determine new choice
                   1150:     var newvalue = "d_" + $first.value;
                   1151:     // update select2
                   1152:     var values     = select2data[newvalue].values;
                   1153:     var texts      = select2data[newvalue].texts;
                   1154:     var select2def = select2data[newvalue].def;
                   1155:     var i;
                   1156:     // out with the old
                   1157:     for (i = 0; i < $second.options.length; i++) {
                   1158:         $second.options[i] = null;
                   1159:     }
                   1160:     // in with the nuclear
                   1161:     for (i=0;i<values.length; i++) {
                   1162:         $second.options[i] = new Option(values[i]);
1.143     matthew  1163:         $second.options[i].value = values[i];
1.36      matthew  1164:         $second.options[i].text = texts[i];
                   1165:         if (values[i] == select2def) {
                   1166:             $second.options[i].selected = true;
                   1167:         }
                   1168:     }
                   1169: }
1.824     bisitz   1170: // ]]>
1.36      matthew  1171: </script>
                   1172: END
                   1173:     # output the initial values for the selection lists
1.1075.2.31  raeburn  1174:     $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed();$onchangefirst\">\n";
1.609     raeburn  1175:     my @order = sort(keys(%{$hashref}));
                   1176:     if (ref($menuorder) eq 'ARRAY') {
                   1177:         @order = @{$menuorder};
                   1178:     }
                   1179:     foreach my $value (@order) {
1.36      matthew  1180:         $result.="    <option value=\"$value\" ";
1.253     albertel 1181:         $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119     www      1182:         $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36      matthew  1183:     }
                   1184:     $result .= "</select>\n";
                   1185:     my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
                   1186:     $result .= $middletext;
1.1075.2.31  raeburn  1187:     $result .= "<select size=\"1\" name=\"$secondselectname\"";
                   1188:     if ($onchangesecond) {
                   1189:         $result .= ' onchange="'.$onchangesecond.'"';
                   1190:     }
                   1191:     $result .= ">\n";
1.36      matthew  1192:     my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609     raeburn  1193:     
                   1194:     my @secondorder = sort(keys(%select2));
                   1195:     if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
                   1196:         @secondorder = @{$hashref->{$firstdefault}->{'order'}};
                   1197:     }
                   1198:     foreach my $value (@secondorder) {
1.36      matthew  1199:         $result.="    <option value=\"$value\" ";        
1.253     albertel 1200:         $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119     www      1201:         $result.=">".&mt($select2{$value})."</option>\n";
1.36      matthew  1202:     }
                   1203:     $result .= "</select>\n";
                   1204:     #    return $debug;
                   1205:     return $result;
                   1206: }   #  end of sub linked_select_forms {
                   1207: 
1.45      matthew  1208: =pod
1.44      bowersj2 1209: 
1.973     raeburn  1210: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44      bowersj2 1211: 
1.112     bowersj2 1212: Returns a string corresponding to an HTML link to the given help
                   1213: $topic, where $topic corresponds to the name of a .tex file in
                   1214: /home/httpd/html/adm/help/tex, with underscores replaced by
                   1215: spaces. 
                   1216: 
                   1217: $text will optionally be linked to the same topic, allowing you to
                   1218: link text in addition to the graphic. If you do not want to link
                   1219: text, but wish to specify one of the later parameters, pass an
                   1220: empty string. 
                   1221: 
                   1222: $stayOnPage is a value that will be interpreted as a boolean. If true,
                   1223: the link will not open a new window. If false, the link will open
                   1224: a new window using Javascript. (Default is false.) 
                   1225: 
                   1226: $width and $height are optional numerical parameters that will
                   1227: override the width and height of the popped up window, which may
1.973     raeburn  1228: be useful for certain help topics with big pictures included.
                   1229: 
                   1230: $imgid is the id of the img tag used for the help icon. This may be
                   1231: used in a javascript call to switch the image src.  See 
                   1232: lonhtmlcommon::htmlareaselectactive() for an example.
1.44      bowersj2 1233: 
                   1234: =cut
                   1235: 
                   1236: sub help_open_topic {
1.973     raeburn  1237:     my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48      bowersj2 1238:     $text = "" if (not defined $text);
1.44      bowersj2 1239:     $stayOnPage = 0 if (not defined $stayOnPage);
1.1033    www      1240:     $width = 500 if (not defined $width);
1.44      bowersj2 1241:     $height = 400 if (not defined $height);
                   1242:     my $filename = $topic;
                   1243:     $filename =~ s/ /_/g;
                   1244: 
1.48      bowersj2 1245:     my $template = "";
                   1246:     my $link;
1.572     banghart 1247:     
1.159     www      1248:     $topic=~s/\W/\_/g;
1.44      bowersj2 1249: 
1.572     banghart 1250:     if (!$stayOnPage) {
1.1075.2.50  raeburn  1251:         if ($env{'browser.mobile'}) {
                   1252: 	    $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
                   1253:         } else {
                   1254:             $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1255:         }
1.1037    www      1256:     } elsif ($stayOnPage eq 'popup') {
                   1257:         $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 1258:     } else {
1.48      bowersj2 1259: 	$link = "/adm/help/${filename}.hlp";
                   1260:     }
                   1261: 
                   1262:     # Add the text
1.755     neumanie 1263:     if ($text ne "") {	
1.763     bisitz   1264: 	$template.='<span class="LC_help_open_topic">'
                   1265:                   .'<a target="_top" href="'.$link.'">'
                   1266:                   .$text.'</a>';
1.48      bowersj2 1267:     }
                   1268: 
1.763     bisitz   1269:     # (Always) Add the graphic
1.179     matthew  1270:     my $title = &mt('Online Help');
1.667     raeburn  1271:     my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973     raeburn  1272:     if ($imgid ne '') {
                   1273:         $imgid = ' id="'.$imgid.'"';
                   1274:     }
1.763     bisitz   1275:     $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
                   1276:               .'<img src="'.$helpicon.'" border="0"'
                   1277:               .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973     raeburn  1278:               .' title="'.$title.'" style="vertical-align:middle;"'.$imgid 
1.763     bisitz   1279:               .' /></a>';
                   1280:     if ($text ne "") {	
                   1281:         $template.='</span>';
                   1282:     }
1.44      bowersj2 1283:     return $template;
                   1284: 
1.106     bowersj2 1285: }
                   1286: 
                   1287: # This is a quicky function for Latex cheatsheet editing, since it 
                   1288: # appears in at least four places
                   1289: sub helpLatexCheatsheet {
1.1037    www      1290:     my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732     raeburn  1291:     my $out;
1.106     bowersj2 1292:     my $addOther = '';
1.732     raeburn  1293:     if ($topic) {
1.1037    www      1294: 	$addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763     bisitz   1295:     }
                   1296:     $out = '<span>' # Start cheatsheet
                   1297: 	  .$addOther
                   1298:           .'<span>'
1.1037    www      1299: 	  .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763     bisitz   1300: 	  .'</span> <span>'
1.1037    www      1301: 	  .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763     bisitz   1302: 	  .'</span>';
1.732     raeburn  1303:     unless ($not_author) {
1.763     bisitz   1304:         $out .= ' <span>'
1.1037    www      1305: 	       .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1.1075.2.71  raeburn  1306: 	       .'</span> <span>'
1.1075.2.78  raeburn  1307:                .&help_open_topic('Authoring_Multilingual_Problems',&mt('Languages'),$stayOnPage,undef,600)
1.1075.2.71  raeburn  1308:                .'</span>';
1.732     raeburn  1309:     }
1.763     bisitz   1310:     $out .= '</span>'; # End cheatsheet
1.732     raeburn  1311:     return $out;
1.172     www      1312: }
                   1313: 
1.430     albertel 1314: sub general_help {
                   1315:     my $helptopic='Student_Intro';
                   1316:     if ($env{'request.role'}=~/^(ca|au)/) {
                   1317: 	$helptopic='Authoring_Intro';
1.907     raeburn  1318:     } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430     albertel 1319: 	$helptopic='Course_Coordination_Intro';
1.672     raeburn  1320:     } elsif ($env{'request.role'}=~/^dc/) {
                   1321:         $helptopic='Domain_Coordination_Intro';
1.430     albertel 1322:     }
                   1323:     return $helptopic;
                   1324: }
                   1325: 
                   1326: sub update_help_link {
                   1327:     my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
                   1328:     my $origurl = $ENV{'REQUEST_URI'};
                   1329:     $origurl=~s|^/~|/priv/|;
                   1330:     my $timestamp = time;
                   1331:     foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
                   1332:         $$datum = &escape($$datum);
                   1333:     }
                   1334: 
                   1335:     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";
                   1336:     my $output .= <<"ENDOUTPUT";
                   1337: <script type="text/javascript">
1.824     bisitz   1338: // <![CDATA[
1.430     albertel 1339: banner_link = '$banner_link';
1.824     bisitz   1340: // ]]>
1.430     albertel 1341: </script>
                   1342: ENDOUTPUT
                   1343:     return $output;
                   1344: }
                   1345: 
                   1346: # now just updates the help link and generates a blue icon
1.193     raeburn  1347: sub help_open_menu {
1.430     albertel 1348:     my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text) 
1.552     banghart 1349: 	= @_;    
1.949     droeschl 1350:     $stayOnPage = 1;
1.430     albertel 1351:     my $output;
                   1352:     if ($component_help) {
                   1353: 	if (!$text) {
                   1354: 	    $output=&help_open_topic($component_help,undef,$stayOnPage,
                   1355: 				       $width,$height);
                   1356: 	} else {
                   1357: 	    my $help_text;
                   1358: 	    $help_text=&unescape($topic);
                   1359: 	    $output='<table><tr><td>'.
                   1360: 		&help_open_topic($component_help,$help_text,$stayOnPage,
                   1361: 				 $width,$height).'</td></tr></table>';
                   1362: 	}
                   1363:     }
                   1364:     my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
                   1365:     return $output.$banner_link;
                   1366: }
                   1367: 
                   1368: sub top_nav_help {
                   1369:     my ($text) = @_;
1.436     albertel 1370:     $text = &mt($text);
1.1075.2.60  raeburn  1371:     my $stay_on_page;
                   1372:     unless ($env{'environment.remote'} eq 'on') {
                   1373:         $stay_on_page = 1;
                   1374:     }
1.1075.2.61  raeburn  1375:     my ($link,$banner_link);
                   1376:     unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
                   1377:         $link = ($stay_on_page) ? "javascript:helpMenu('display')"
                   1378: 	                         : "javascript:helpMenu('open')";
                   1379:         $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
                   1380:     }
1.201     raeburn  1381:     my $title = &mt('Get help');
1.1075.2.61  raeburn  1382:     if ($link) {
                   1383:         return <<"END";
1.436     albertel 1384: $banner_link
1.1075.2.56  raeburn  1385: <a href="$link" title="$title">$text</a>
1.436     albertel 1386: END
1.1075.2.61  raeburn  1387:     } else {
                   1388:         return '&nbsp;'.$text.'&nbsp;';
                   1389:     }
1.436     albertel 1390: }
                   1391: 
                   1392: sub help_menu_js {
1.1075.2.52  raeburn  1393:     my ($httphost) = @_;
1.949     droeschl 1394:     my $stayOnPage = 1;
1.436     albertel 1395:     my $width = 620;
                   1396:     my $height = 600;
1.430     albertel 1397:     my $helptopic=&general_help();
1.1075.2.52  raeburn  1398:     my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261     albertel 1399:     my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331     albertel 1400:     my $start_page =
                   1401:         &Apache::loncommon::start_page('Help Menu', undef,
                   1402: 				       {'frameset'    => 1,
                   1403: 					'js_ready'    => 1,
1.1075.2.52  raeburn  1404:                                         'use_absolute' => $httphost, 
1.331     albertel 1405: 					'add_entries' => {
                   1406: 					    'border' => '0',
1.579     raeburn  1407: 					    'rows'   => "110,*",},});
1.331     albertel 1408:     my $end_page =
                   1409:         &Apache::loncommon::end_page({'frameset' => 1,
                   1410: 				      'js_ready' => 1,});
                   1411: 
1.436     albertel 1412:     my $template .= <<"ENDTEMPLATE";
                   1413: <script type="text/javascript">
1.877     bisitz   1414: // <![CDATA[
1.253     albertel 1415: // <!-- BEGIN LON-CAPA Internal
1.430     albertel 1416: var banner_link = '';
1.243     raeburn  1417: function helpMenu(target) {
                   1418:     var caller = this;
                   1419:     if (target == 'open') {
                   1420:         var newWindow = null;
                   1421:         try {
1.262     albertel 1422:             newWindow =  window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243     raeburn  1423:         }
                   1424:         catch(error) {
                   1425:             writeHelp(caller);
                   1426:             return;
                   1427:         }
                   1428:         if (newWindow) {
                   1429:             caller = newWindow;
                   1430:         }
1.193     raeburn  1431:     }
1.243     raeburn  1432:     writeHelp(caller);
                   1433:     return;
                   1434: }
                   1435: function writeHelp(caller) {
1.1075.2.61  raeburn  1436:     caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
                   1437:     caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
                   1438:     caller.document.close();
                   1439:     caller.focus();
1.193     raeburn  1440: }
1.877     bisitz   1441: // END LON-CAPA Internal -->
1.253     albertel 1442: // ]]>
1.436     albertel 1443: </script>
1.193     raeburn  1444: ENDTEMPLATE
                   1445:     return $template;
                   1446: }
                   1447: 
1.172     www      1448: sub help_open_bug {
                   1449:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1450:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1451:     unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
                   1452:     $text = "" if (not defined $text);
                   1453: 	$stayOnPage=1;
1.184     albertel 1454:     $width = 600 if (not defined $width);
                   1455:     $height = 600 if (not defined $height);
1.172     www      1456: 
                   1457:     $topic=~s/\W+/\+/g;
                   1458:     my $link='';
                   1459:     my $template='';
1.379     albertel 1460:     my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&amp;bug_file_loc='.
                   1461: 	&escape($ENV{'REQUEST_URI'}).'&amp;component='.$topic;
1.172     www      1462:     if (!$stayOnPage)
                   1463:     {
                   1464: 	$link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1465:     }
                   1466:     else
                   1467:     {
                   1468: 	$link = $url;
                   1469:     }
                   1470:     # Add the text
                   1471:     if ($text ne "")
                   1472:     {
                   1473: 	$template .= 
                   1474:   "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1475:   "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172     www      1476:     }
                   1477: 
                   1478:     # Add the graphic
1.179     matthew  1479:     my $title = &mt('Report a Bug');
1.215     albertel 1480:     my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172     www      1481:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1482:  <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172     www      1483: ENDTEMPLATE
                   1484:     if ($text ne '') { $template.='</td></tr></table>' };
                   1485:     return $template;
                   1486: 
                   1487: }
                   1488: 
                   1489: sub help_open_faq {
                   1490:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1491:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1492:     unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
                   1493:     $text = "" if (not defined $text);
                   1494: 	$stayOnPage=1;
                   1495:     $width = 350 if (not defined $width);
                   1496:     $height = 400 if (not defined $height);
                   1497: 
                   1498:     $topic=~s/\W+/\+/g;
                   1499:     my $link='';
                   1500:     my $template='';
                   1501:     my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
                   1502:     if (!$stayOnPage)
                   1503:     {
                   1504: 	$link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1505:     }
                   1506:     else
                   1507:     {
                   1508: 	$link = $url;
                   1509:     }
                   1510: 
                   1511:     # Add the text
                   1512:     if ($text ne "")
                   1513:     {
                   1514: 	$template .= 
1.173     www      1515:   "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1516:   "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172     www      1517:     }
                   1518: 
                   1519:     # Add the graphic
1.179     matthew  1520:     my $title = &mt('View the FAQ');
1.215     albertel 1521:     my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172     www      1522:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1523:  <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172     www      1524: ENDTEMPLATE
                   1525:     if ($text ne '') { $template.='</td></tr></table>' };
                   1526:     return $template;
                   1527: 
1.44      bowersj2 1528: }
1.37      matthew  1529: 
1.180     matthew  1530: ###############################################################
                   1531: ###############################################################
                   1532: 
1.45      matthew  1533: =pod
                   1534: 
1.648     raeburn  1535: =item * &change_content_javascript():
1.256     matthew  1536: 
                   1537: This and the next function allow you to create small sections of an
                   1538: otherwise static HTML page that you can update on the fly with
                   1539: Javascript, even in Netscape 4.
                   1540: 
                   1541: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
                   1542: must be written to the HTML page once. It will prove the Javascript
                   1543: function "change(name, content)". Calling the change function with the
                   1544: name of the section 
                   1545: you want to update, matching the name passed to C<changable_area>, and
                   1546: the new content you want to put in there, will put the content into
                   1547: that area.
                   1548: 
                   1549: B<Note>: Netscape 4 only reserves enough space for the changable area
                   1550: to contain room for the original contents. You need to "make space"
                   1551: for whatever changes you wish to make, and be B<sure> to check your
                   1552: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
                   1553: it's adequate for updating a one-line status display, but little more.
                   1554: This script will set the space to 100% width, so you only need to
                   1555: worry about height in Netscape 4.
                   1556: 
                   1557: Modern browsers are much less limiting, and if you can commit to the
                   1558: user not using Netscape 4, this feature may be used freely with
                   1559: pretty much any HTML.
                   1560: 
                   1561: =cut
                   1562: 
                   1563: sub change_content_javascript {
                   1564:     # If we're on Netscape 4, we need to use Layer-based code
1.258     albertel 1565:     if ($env{'browser.type'} eq 'netscape' &&
                   1566: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1567: 	return (<<NETSCAPE4);
                   1568: 	function change(name, content) {
                   1569: 	    doc = document.layers[name+"___escape"].layers[0].document;
                   1570: 	    doc.open();
                   1571: 	    doc.write(content);
                   1572: 	    doc.close();
                   1573: 	}
                   1574: NETSCAPE4
                   1575:     } else {
                   1576: 	# Otherwise, we need to use semi-standards-compliant code
                   1577: 	# (technically, "innerHTML" isn't standard but the equivalent
                   1578: 	# is really scary, and every useful browser supports it
                   1579: 	return (<<DOMBASED);
                   1580: 	function change(name, content) {
                   1581: 	    element = document.getElementById(name);
                   1582: 	    element.innerHTML = content;
                   1583: 	}
                   1584: DOMBASED
                   1585:     }
                   1586: }
                   1587: 
                   1588: =pod
                   1589: 
1.648     raeburn  1590: =item * &changable_area($name,$origContent):
1.256     matthew  1591: 
                   1592: This provides a "changable area" that can be modified on the fly via
                   1593: the Javascript code provided in C<change_content_javascript>. $name is
                   1594: the name you will use to reference the area later; do not repeat the
                   1595: same name on a given HTML page more then once. $origContent is what
                   1596: the area will originally contain, which can be left blank.
                   1597: 
                   1598: =cut
                   1599: 
                   1600: sub changable_area {
                   1601:     my ($name, $origContent) = @_;
                   1602: 
1.258     albertel 1603:     if ($env{'browser.type'} eq 'netscape' &&
                   1604: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1605: 	# If this is netscape 4, we need to use the Layer tag
                   1606: 	return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
                   1607:     } else {
                   1608: 	return "<span id='$name'>$origContent</span>";
                   1609:     }
                   1610: }
                   1611: 
                   1612: =pod
                   1613: 
1.648     raeburn  1614: =item * &viewport_geometry_js 
1.590     raeburn  1615: 
                   1616: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
                   1617: 
                   1618: =cut
                   1619: 
                   1620: 
                   1621: sub viewport_geometry_js { 
                   1622:     return <<"GEOMETRY";
                   1623: var Geometry = {};
                   1624: function init_geometry() {
                   1625:     if (Geometry.init) { return };
                   1626:     Geometry.init=1;
                   1627:     if (window.innerHeight) {
                   1628:         Geometry.getViewportHeight   = function() { return window.innerHeight; };
                   1629:         Geometry.getViewportWidth   = function() { return window.innerWidth; };
                   1630:         Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
                   1631:         Geometry.getVerticalScroll   = function() { return window.pageYOffset; };
                   1632:     }
                   1633:     else if (document.documentElement && document.documentElement.clientHeight) {
                   1634:         Geometry.getViewportHeight =
                   1635:             function() { return document.documentElement.clientHeight; };
                   1636:         Geometry.getViewportWidth =
                   1637:             function() { return document.documentElement.clientWidth; };
                   1638: 
                   1639:         Geometry.getHorizontalScroll =
                   1640:             function() { return document.documentElement.scrollLeft; };
                   1641:         Geometry.getVerticalScroll =
                   1642:             function() { return document.documentElement.scrollTop; };
                   1643:     }
                   1644:     else if (document.body.clientHeight) {
                   1645:         Geometry.getViewportHeight =
                   1646:             function() { return document.body.clientHeight; };
                   1647:         Geometry.getViewportWidth =
                   1648:             function() { return document.body.clientWidth; };
                   1649:         Geometry.getHorizontalScroll =
                   1650:             function() { return document.body.scrollLeft; };
                   1651:         Geometry.getVerticalScroll =
                   1652:             function() { return document.body.scrollTop; };
                   1653:     }
                   1654: }
                   1655: 
                   1656: GEOMETRY
                   1657: }
                   1658: 
                   1659: =pod
                   1660: 
1.648     raeburn  1661: =item * &viewport_size_js()
1.590     raeburn  1662: 
                   1663: 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. 
                   1664: 
                   1665: =cut
                   1666: 
                   1667: sub viewport_size_js {
                   1668:     my $geometry = &viewport_geometry_js();
                   1669:     return <<"DIMS";
                   1670: 
                   1671: $geometry
                   1672: 
                   1673: function getViewportDims(width,height) {
                   1674:     init_geometry();
                   1675:     width.value = Geometry.getViewportWidth();
                   1676:     height.value = Geometry.getViewportHeight();
                   1677:     return;
                   1678: }
                   1679: 
                   1680: DIMS
                   1681: }
                   1682: 
                   1683: =pod
                   1684: 
1.648     raeburn  1685: =item * &resize_textarea_js()
1.565     albertel 1686: 
                   1687: emits the needed javascript to resize a textarea to be as big as possible
                   1688: 
                   1689: creates a function resize_textrea that takes two IDs first should be
                   1690: the id of the element to resize, second should be the id of a div that
                   1691: surrounds everything that comes after the textarea, this routine needs
                   1692: to be attached to the <body> for the onload and onresize events.
                   1693: 
1.648     raeburn  1694: =back
1.565     albertel 1695: 
                   1696: =cut
                   1697: 
                   1698: sub resize_textarea_js {
1.590     raeburn  1699:     my $geometry = &viewport_geometry_js();
1.565     albertel 1700:     return <<"RESIZE";
                   1701:     <script type="text/javascript">
1.824     bisitz   1702: // <![CDATA[
1.590     raeburn  1703: $geometry
1.565     albertel 1704: 
1.588     albertel 1705: function getX(element) {
                   1706:     var x = 0;
                   1707:     while (element) {
                   1708: 	x += element.offsetLeft;
                   1709: 	element = element.offsetParent;
                   1710:     }
                   1711:     return x;
                   1712: }
                   1713: function getY(element) {
                   1714:     var y = 0;
                   1715:     while (element) {
                   1716: 	y += element.offsetTop;
                   1717: 	element = element.offsetParent;
                   1718:     }
                   1719:     return y;
                   1720: }
                   1721: 
                   1722: 
1.565     albertel 1723: function resize_textarea(textarea_id,bottom_id) {
                   1724:     init_geometry();
                   1725:     var textarea        = document.getElementById(textarea_id);
                   1726:     //alert(textarea);
                   1727: 
1.588     albertel 1728:     var textarea_top    = getY(textarea);
1.565     albertel 1729:     var textarea_height = textarea.offsetHeight;
                   1730:     var bottom          = document.getElementById(bottom_id);
1.588     albertel 1731:     var bottom_top      = getY(bottom);
1.565     albertel 1732:     var bottom_height   = bottom.offsetHeight;
                   1733:     var window_height   = Geometry.getViewportHeight();
1.588     albertel 1734:     var fudge           = 23;
1.565     albertel 1735:     var new_height      = window_height-fudge-textarea_top-bottom_height;
                   1736:     if (new_height < 300) {
                   1737: 	new_height = 300;
                   1738:     }
                   1739:     textarea.style.height=new_height+'px';
                   1740: }
1.824     bisitz   1741: // ]]>
1.565     albertel 1742: </script>
                   1743: RESIZE
                   1744: 
                   1745: }
                   1746: 
1.1075.2.112  raeburn  1747: sub colorfuleditor_js {
                   1748:     return <<"COLORFULEDIT"
                   1749: <script type="text/javascript">
                   1750: // <![CDATA[>
                   1751:     function fold_box(curDepth, lastresource){
                   1752: 
                   1753:     // we need a list because there can be several blocks you need to fold in one tag
                   1754:         var block = document.getElementsByName('foldblock_'+curDepth);
                   1755:     // but there is only one folding button per tag
                   1756:         var foldbutton = document.getElementById('folding_btn_'+curDepth);
                   1757: 
                   1758:         if(block.item(0).style.display == 'none'){
                   1759: 
                   1760:             foldbutton.value = '@{[&mt("Hide")]}';
                   1761:             for (i = 0; i < block.length; i++){
                   1762:                 block.item(i).style.display = '';
                   1763:             }
                   1764:         }else{
                   1765: 
                   1766:             foldbutton.value = '@{[&mt("Show")]}';
                   1767:             for (i = 0; i < block.length; i++){
                   1768:                 // block.item(i).style.visibility = 'collapse';
                   1769:                 block.item(i).style.display = 'none';
                   1770:             }
                   1771:         };
                   1772:         saveState(lastresource);
                   1773:     }
                   1774: 
                   1775:     function saveState (lastresource) {
                   1776: 
                   1777:         var tag_list = getTagList();
                   1778:         if(tag_list != null){
                   1779:             var timestamp = new Date().getTime();
                   1780:             var key = lastresource;
                   1781: 
                   1782:             // the value pattern is: 'time;key1,value1;key2,value2; ... '
                   1783:             // starting with timestamp
                   1784:             var value = timestamp+';';
                   1785: 
                   1786:             // building the list of key-value pairs
                   1787:             for(var i = 0; i < tag_list.length; i++){
                   1788:                 value += tag_list[i]+',';
                   1789:                 value += document.getElementsByName(tag_list[i])[0].style.display+';';
                   1790:             }
                   1791: 
                   1792:             // only iterate whole storage if nothing to override
                   1793:             if(localStorage.getItem(key) == null){
                   1794: 
                   1795:                 // prevent storage from growing large
                   1796:                 if(localStorage.length > 50){
                   1797:                     var regex_getTimestamp = /^(?:\d)+;/;
                   1798:                     var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
                   1799:                     var oldest_key;
                   1800: 
                   1801:                     for(var i = 1; i < localStorage.length; i++){
                   1802:                         if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
                   1803:                             oldest_key = localStorage.key(i);
                   1804:                             oldest_timestamp = regex_getTimestamp.exec(oldest_key);
                   1805:                         }
                   1806:                     }
                   1807:                     localStorage.removeItem(oldest_key);
                   1808:                 }
                   1809:             }
                   1810:             localStorage.setItem(key,value);
                   1811:         }
                   1812:     }
                   1813: 
                   1814:     // restore folding status of blocks (on page load)
                   1815:     function restoreState (lastresource) {
                   1816:         if(localStorage.getItem(lastresource) != null){
                   1817:             var key = lastresource;
                   1818:             var value = localStorage.getItem(key);
                   1819:             var regex_delTimestamp = /^\d+;/;
                   1820: 
                   1821:             value.replace(regex_delTimestamp, '');
                   1822: 
                   1823:             var valueArr = value.split(';');
                   1824:             var pairs;
                   1825:             var elements;
                   1826:             for (var i = 0; i < valueArr.length; i++){
                   1827:                 pairs = valueArr[i].split(',');
                   1828:                 elements = document.getElementsByName(pairs[0]);
                   1829: 
                   1830:                 for (var j = 0; j < elements.length; j++){
                   1831:                     elements[j].style.display = pairs[1];
                   1832:                     if (pairs[1] == "none"){
                   1833:                         var regex_id = /([_\\d]+)\$/;
                   1834:                         regex_id.exec(pairs[0]);
                   1835:                         document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
                   1836:                     }
                   1837:                 }
                   1838:             }
                   1839:         }
                   1840:     }
                   1841: 
                   1842:     function getTagList () {
                   1843: 
                   1844:         var stringToSearch = document.lonhomework.innerHTML;
                   1845: 
                   1846:         var ret = new Array();
                   1847:         var regex_findBlock = /(foldblock_.*?)"/g;
                   1848:         var tag_list = stringToSearch.match(regex_findBlock);
                   1849: 
                   1850:         if(tag_list != null){
                   1851:             for(var i = 0; i < tag_list.length; i++){
                   1852:                 ret.push(tag_list[i].replace(/"/, ''));
                   1853:             }
                   1854:         }
                   1855:         return ret;
                   1856:     }
                   1857: 
                   1858:     function saveScrollPosition (resource) {
                   1859:         var tag_list = getTagList();
                   1860: 
                   1861:         // we dont always want to jump to the first block
                   1862:         // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
                   1863:         if(\$(window).scrollTop() > 170){
                   1864:             if(tag_list != null){
                   1865:                 var result;
                   1866:                 for(var i = 0; i < tag_list.length; i++){
                   1867:                     if(isElementInViewport(tag_list[i])){
                   1868:                         result += tag_list[i]+';';
                   1869:                     }
                   1870:                 }
                   1871:                 sessionStorage.setItem('anchor_'+resource, result);
                   1872:             }
                   1873:         } else {
                   1874:             // we dont need to save zero, just delete the item to leave everything tidy
                   1875:             sessionStorage.removeItem('anchor_'+resource);
                   1876:         }
                   1877:     }
                   1878: 
                   1879:     function restoreScrollPosition(resource){
                   1880: 
                   1881:         var elem = sessionStorage.getItem('anchor_'+resource);
                   1882:         if(elem != null){
                   1883:             var tag_list = elem.split(';');
                   1884:             var elem_list;
                   1885: 
                   1886:             for(var i = 0; i < tag_list.length; i++){
                   1887:                 elem_list = document.getElementsByName(tag_list[i]);
                   1888: 
                   1889:                 if(elem_list.length > 0){
                   1890:                     elem = elem_list[0];
                   1891:                     break;
                   1892:                 }
                   1893:             }
                   1894:             elem.scrollIntoView();
                   1895:         }
                   1896:     }
                   1897: 
                   1898:     function isElementInViewport(el) {
                   1899: 
                   1900:         // change to last element instead of first
                   1901:         var elem = document.getElementsByName(el);
                   1902:         var rect = elem[0].getBoundingClientRect();
                   1903: 
                   1904:         return (
                   1905:             rect.top >= 0 &&
                   1906:             rect.left >= 0 &&
                   1907:             rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
                   1908:             rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
                   1909:         );
                   1910:     }
                   1911: 
                   1912:     function autosize(depth){
                   1913:         var cmInst = window['cm'+depth];
                   1914:         var fitsizeButton = document.getElementById('fitsize'+depth);
                   1915: 
                   1916:         // is fixed size, switching to dynamic
                   1917:         if (sessionStorage.getItem("autosized_"+depth) == null) {
                   1918:             cmInst.setSize("","auto");
                   1919:             fitsizeButton.value = "@{[&mt('Fixed size')]}";
                   1920:             sessionStorage.setItem("autosized_"+depth, "yes");
                   1921: 
                   1922:         // is dynamic size, switching to fixed
                   1923:         } else {
                   1924:             cmInst.setSize("","300px");
                   1925:             fitsizeButton.value = "@{[&mt('Dynamic size')]}";
                   1926:             sessionStorage.removeItem("autosized_"+depth);
                   1927:         }
                   1928:     }
                   1929: 
                   1930: 
                   1931: 
                   1932: // ]]>
                   1933: </script>
                   1934: COLORFULEDIT
                   1935: }
                   1936: 
                   1937: sub xmleditor_js {
                   1938:     return <<XMLEDIT
                   1939: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
                   1940: <script type="text/javascript">
                   1941: // <![CDATA[>
                   1942: 
                   1943:     function saveScrollPosition (resource) {
                   1944: 
                   1945:         var scrollPos = \$(window).scrollTop();
                   1946:         sessionStorage.setItem(resource,scrollPos);
                   1947:     }
                   1948: 
                   1949:     function restoreScrollPosition(resource){
                   1950: 
                   1951:         var scrollPos = sessionStorage.getItem(resource);
                   1952:         \$(window).scrollTop(scrollPos);
                   1953:     }
                   1954: 
                   1955:     // unless internet explorer
                   1956:     if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
                   1957: 
                   1958:         \$(document).ready(function() {
                   1959:              \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
                   1960:         });
                   1961:     }
                   1962: 
                   1963:     // inserts text at cursor position into codemirror (xml editor only)
                   1964:     function insertText(text){
                   1965:         cm.focus();
                   1966:         var curPos = cm.getCursor();
                   1967:         cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
                   1968:     }
                   1969: // ]]>
                   1970: </script>
                   1971: XMLEDIT
                   1972: }
                   1973: 
                   1974: sub insert_folding_button {
                   1975:     my $curDepth = $Apache::lonxml::curdepth;
                   1976:     my $lastresource = $env{'request.ambiguous'};
                   1977: 
                   1978:     return "<input type=\"button\" id=\"folding_btn_$curDepth\"
                   1979:             value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
                   1980: }
                   1981: 
                   1982: 
1.565     albertel 1983: =pod
                   1984: 
1.256     matthew  1985: =head1 Excel and CSV file utility routines
                   1986: 
                   1987: =cut
                   1988: 
                   1989: ###############################################################
                   1990: ###############################################################
                   1991: 
                   1992: =pod
                   1993: 
1.1075.2.56  raeburn  1994: =over 4
                   1995: 
1.648     raeburn  1996: =item * &csv_translate($text) 
1.37      matthew  1997: 
1.185     www      1998: Translate $text to allow it to be output as a 'comma separated values' 
1.37      matthew  1999: format.
                   2000: 
                   2001: =cut
                   2002: 
1.180     matthew  2003: ###############################################################
                   2004: ###############################################################
1.37      matthew  2005: sub csv_translate {
                   2006:     my $text = shift;
                   2007:     $text =~ s/\"/\"\"/g;
1.209     albertel 2008:     $text =~ s/\n/ /g;
1.37      matthew  2009:     return $text;
                   2010: }
1.180     matthew  2011: 
                   2012: ###############################################################
                   2013: ###############################################################
                   2014: 
                   2015: =pod
                   2016: 
1.648     raeburn  2017: =item * &define_excel_formats()
1.180     matthew  2018: 
                   2019: Define some commonly used Excel cell formats.
                   2020: 
                   2021: Currently supported formats:
                   2022: 
                   2023: =over 4
                   2024: 
                   2025: =item header
                   2026: 
                   2027: =item bold
                   2028: 
                   2029: =item h1
                   2030: 
                   2031: =item h2
                   2032: 
                   2033: =item h3
                   2034: 
1.256     matthew  2035: =item h4
                   2036: 
                   2037: =item i
                   2038: 
1.180     matthew  2039: =item date
                   2040: 
                   2041: =back
                   2042: 
                   2043: Inputs: $workbook
                   2044: 
                   2045: Returns: $format, a hash reference.
                   2046: 
1.1057    foxr     2047: 
1.180     matthew  2048: =cut
                   2049: 
                   2050: ###############################################################
                   2051: ###############################################################
                   2052: sub define_excel_formats {
                   2053:     my ($workbook) = @_;
                   2054:     my $format;
                   2055:     $format->{'header'} = $workbook->add_format(bold      => 1, 
                   2056:                                                 bottom    => 1,
                   2057:                                                 align     => 'center');
                   2058:     $format->{'bold'} = $workbook->add_format(bold=>1);
                   2059:     $format->{'h1'}   = $workbook->add_format(bold=>1, size=>18);
                   2060:     $format->{'h2'}   = $workbook->add_format(bold=>1, size=>16);
                   2061:     $format->{'h3'}   = $workbook->add_format(bold=>1, size=>14);
1.255     matthew  2062:     $format->{'h4'}   = $workbook->add_format(bold=>1, size=>12);
1.246     matthew  2063:     $format->{'i'}    = $workbook->add_format(italic=>1);
1.180     matthew  2064:     $format->{'date'} = $workbook->add_format(num_format=>
1.207     matthew  2065:                                             'mm/dd/yyyy hh:mm:ss');
1.180     matthew  2066:     return $format;
                   2067: }
                   2068: 
                   2069: ###############################################################
                   2070: ###############################################################
1.113     bowersj2 2071: 
                   2072: =pod
                   2073: 
1.648     raeburn  2074: =item * &create_workbook()
1.255     matthew  2075: 
                   2076: Create an Excel worksheet.  If it fails, output message on the
                   2077: request object and return undefs.
                   2078: 
                   2079: Inputs: Apache request object
                   2080: 
                   2081: Returns (undef) on failure, 
                   2082:     Excel worksheet object, scalar with filename, and formats 
                   2083:     from &Apache::loncommon::define_excel_formats on success
                   2084: 
                   2085: =cut
                   2086: 
                   2087: ###############################################################
                   2088: ###############################################################
                   2089: sub create_workbook {
                   2090:     my ($r) = @_;
                   2091:         #
                   2092:     # Create the excel spreadsheet
                   2093:     my $filename = '/prtspool/'.
1.258     albertel 2094:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255     matthew  2095:         time.'_'.rand(1000000000).'.xls';
                   2096:     my $workbook  = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
                   2097:     if (! defined($workbook)) {
                   2098:         $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928     bisitz   2099:         $r->print(
                   2100:             '<p class="LC_error">'
                   2101:            .&mt('Problems occurred in creating the new Excel file.')
                   2102:            .' '.&mt('This error has been logged.')
                   2103:            .' '.&mt('Please alert your LON-CAPA administrator.')
                   2104:            .'</p>'
                   2105:         );
1.255     matthew  2106:         return (undef);
                   2107:     }
                   2108:     #
1.1014    foxr     2109:     $workbook->set_tempdir(LONCAPA::tempdir());
1.255     matthew  2110:     #
                   2111:     my $format = &Apache::loncommon::define_excel_formats($workbook);
                   2112:     return ($workbook,$filename,$format);
                   2113: }
                   2114: 
                   2115: ###############################################################
                   2116: ###############################################################
                   2117: 
                   2118: =pod
                   2119: 
1.648     raeburn  2120: =item * &create_text_file()
1.113     bowersj2 2121: 
1.542     raeburn  2122: Create a file to write to and eventually make available to the user.
1.256     matthew  2123: If file creation fails, outputs an error message on the request object and 
                   2124: return undefs.
1.113     bowersj2 2125: 
1.256     matthew  2126: Inputs: Apache request object, and file suffix
1.113     bowersj2 2127: 
1.256     matthew  2128: Returns (undef) on failure, 
                   2129:     Filehandle and filename on success.
1.113     bowersj2 2130: 
                   2131: =cut
                   2132: 
1.256     matthew  2133: ###############################################################
                   2134: ###############################################################
                   2135: sub create_text_file {
                   2136:     my ($r,$suffix) = @_;
                   2137:     if (! defined($suffix)) { $suffix = 'txt'; };
                   2138:     my $fh;
                   2139:     my $filename = '/prtspool/'.
1.258     albertel 2140:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256     matthew  2141:         time.'_'.rand(1000000000).'.'.$suffix;
                   2142:     $fh = Apache::File->new('>/home/httpd'.$filename);
                   2143:     if (! defined($fh)) {
                   2144:         $r->log_error("Couldn't open $filename for output $!");
1.928     bisitz   2145:         $r->print(
                   2146:             '<p class="LC_error">'
                   2147:            .&mt('Problems occurred in creating the output file.')
                   2148:            .' '.&mt('This error has been logged.')
                   2149:            .' '.&mt('Please alert your LON-CAPA administrator.')
                   2150:            .'</p>'
                   2151:         );
1.113     bowersj2 2152:     }
1.256     matthew  2153:     return ($fh,$filename)
1.113     bowersj2 2154: }
                   2155: 
                   2156: 
1.256     matthew  2157: =pod 
1.113     bowersj2 2158: 
                   2159: =back
                   2160: 
                   2161: =cut
1.37      matthew  2162: 
                   2163: ###############################################################
1.33      matthew  2164: ##        Home server <option> list generating code          ##
                   2165: ###############################################################
1.35      matthew  2166: 
1.169     www      2167: # ------------------------------------------
                   2168: 
                   2169: sub domain_select {
                   2170:     my ($name,$value,$multiple)=@_;
                   2171:     my %domains=map { 
1.514     albertel 2172: 	$_ => $_.' '. &Apache::lonnet::domain($_,'description') 
1.512     albertel 2173:     } &Apache::lonnet::all_domains();
1.169     www      2174:     if ($multiple) {
                   2175: 	$domains{''}=&mt('Any domain');
1.550     albertel 2176: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287     albertel 2177: 	return &multiple_select_form($name,$value,4,\%domains);
1.169     www      2178:     } else {
1.550     albertel 2179: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970     raeburn  2180: 	return &select_form($name,$value,\%domains);
1.169     www      2181:     }
                   2182: }
                   2183: 
1.282     albertel 2184: #-------------------------------------------
                   2185: 
                   2186: =pod
                   2187: 
1.519     raeburn  2188: =head1 Routines for form select boxes
                   2189: 
                   2190: =over 4
                   2191: 
1.648     raeburn  2192: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282     albertel 2193: 
                   2194: Returns a string containing a <select> element int multiple mode
                   2195: 
                   2196: 
                   2197: Args:
                   2198:   $name - name of the <select> element
1.506     raeburn  2199:   $value - scalar or array ref of values that should already be selected
1.282     albertel 2200:   $size - number of rows long the select element is
1.283     albertel 2201:   $hash - the elements should be 'option' => 'shown text'
1.282     albertel 2202:           (shown text should already have been &mt())
1.506     raeburn  2203:   $order - (optional) array ref of the order to show the elements in
1.283     albertel 2204: 
1.282     albertel 2205: =cut
                   2206: 
                   2207: #-------------------------------------------
1.169     www      2208: sub multiple_select_form {
1.284     albertel 2209:     my ($name,$value,$size,$hash,$order)=@_;
1.169     www      2210:     my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
                   2211:     my $output='';
1.191     matthew  2212:     if (! defined($size)) {
                   2213:         $size = 4;
1.283     albertel 2214:         if (scalar(keys(%$hash))<4) {
                   2215:             $size = scalar(keys(%$hash));
1.191     matthew  2216:         }
                   2217:     }
1.734     bisitz   2218:     $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501     banghart 2219:     my @order;
1.506     raeburn  2220:     if (ref($order) eq 'ARRAY')  {
                   2221:         @order = @{$order};
                   2222:     } else {
                   2223:         @order = sort(keys(%$hash));
1.501     banghart 2224:     }
                   2225:     if (exists($$hash{'select_form_order'})) {
                   2226:         @order = @{$$hash{'select_form_order'}};
                   2227:     }
                   2228:         
1.284     albertel 2229:     foreach my $key (@order) {
1.356     albertel 2230:         $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284     albertel 2231:         $output.='selected="selected" ' if ($selected{$key});
                   2232:         $output.='>'.$hash->{$key}."</option>\n";
1.169     www      2233:     }
                   2234:     $output.="</select>\n";
                   2235:     return $output;
                   2236: }
                   2237: 
1.88      www      2238: #-------------------------------------------
                   2239: 
                   2240: =pod
                   2241: 
1.1075.2.115  raeburn  2242: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88      www      2243: 
                   2244: Returns a string containing a <select name='$name' size='1'> form to 
1.970     raeburn  2245: allow a user to select options from a ref to a hash containing:
                   2246: option_name => displayed text. An optional $onchange can include
1.1075.2.115  raeburn  2247: a javascript onchange item, e.g., onchange="this.form.submit();".
                   2248: An optional arg -- $readonly -- if true will cause the select form
                   2249: to be disabled, e.g., for the case where an instructor has a section-
                   2250: specific role, and is viewing/modifying parameters.  
1.970     raeburn  2251: 
1.88      www      2252: See lonrights.pm for an example invocation and use.
                   2253: 
                   2254: =cut
                   2255: 
                   2256: #-------------------------------------------
                   2257: sub select_form {
1.1075.2.115  raeburn  2258:     my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970     raeburn  2259:     return unless (ref($hashref) eq 'HASH');
                   2260:     if ($onchange) {
                   2261:         $onchange = ' onchange="'.$onchange.'"';
                   2262:     }
                   2263:     my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128     albertel 2264:     my @keys;
1.970     raeburn  2265:     if (exists($hashref->{'select_form_order'})) {
                   2266: 	@keys=@{$hashref->{'select_form_order'}};
1.128     albertel 2267:     } else {
1.970     raeburn  2268: 	@keys=sort(keys(%{$hashref}));
1.128     albertel 2269:     }
1.356     albertel 2270:     foreach my $key (@keys) {
                   2271:         $selectform.=
                   2272: 	    '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
                   2273:             ($key eq $def ? 'selected="selected" ' : '').
1.970     raeburn  2274:                 ">".$hashref->{$key}."</option>\n";
1.88      www      2275:     }
                   2276:     $selectform.="</select>";
                   2277:     return $selectform;
                   2278: }
                   2279: 
1.475     www      2280: # For display filters
                   2281: 
                   2282: sub display_filter {
1.1074    raeburn  2283:     my ($context) = @_;
1.475     www      2284:     if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477     www      2285:     if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074    raeburn  2286:     my $phraseinput = 'hidden';
                   2287:     my $includeinput = 'hidden';
                   2288:     my ($checked,$includetypestext);
                   2289:     if ($env{'form.displayfilter'} eq 'containing') {
                   2290:         $phraseinput = 'text'; 
                   2291:         if ($context eq 'parmslog') {
                   2292:             $includeinput = 'checkbox';
                   2293:             if ($env{'form.includetypes'}) {
                   2294:                 $checked = ' checked="checked"';
                   2295:             }
                   2296:             $includetypestext = &mt('Include parameter types');
                   2297:         }
                   2298:     } else {
                   2299:         $includetypestext = '&nbsp;';
                   2300:     }
                   2301:     my ($additional,$secondid,$thirdid);
                   2302:     if ($context eq 'parmslog') {
                   2303:         $additional = 
                   2304:             '<label><input type="'.$includeinput.'" name="includetypes"'. 
                   2305:             $checked.' name="includetypes" value="1" id="includetypes" />'.
                   2306:             '&nbsp;<span id="includetypestext">'.$includetypestext.'</span>'.
                   2307:             '</label>';
                   2308:         $secondid = 'includetypes';
                   2309:         $thirdid = 'includetypestext';
                   2310:     }
                   2311:     my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
                   2312:                                                     '$secondid','$thirdid')";
                   2313:     return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475     www      2314: 			       &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
                   2315: 							   (&mt('all'),10,20,50,100,1000,10000))).
1.714     bisitz   2316: 	   '</label></span> <span class="LC_nobreak">'.
1.1074    raeburn  2317:            &mt('Filter: [_1]',
1.477     www      2318: 	   &select_form($env{'form.displayfilter'},
                   2319: 			'displayfilter',
1.970     raeburn  2320: 			{'currentfolder' => 'Current folder/page',
1.477     www      2321: 			 'containing' => 'Containing phrase',
1.1074    raeburn  2322: 			 'none' => 'None'},$onchange)).'&nbsp;'.
                   2323: 			 '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
                   2324:                          &HTML::Entities::encode($env{'form.containingphrase'}).
                   2325:                          '" />'.$additional;
                   2326: }
                   2327: 
                   2328: sub display_filter_js {
                   2329:     my $includetext = &mt('Include parameter types');
                   2330:     return <<"ENDJS";
                   2331:   
                   2332: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
                   2333:     var firstType = 'hidden';
                   2334:     if (setter.options[setter.selectedIndex].value == 'containing') {
                   2335:         firstType = 'text';
                   2336:     }
                   2337:     firstObject = document.getElementById(firstid);
                   2338:     if (typeof(firstObject) == 'object') {
                   2339:         if (firstObject.type != firstType) {
                   2340:             changeInputType(firstObject,firstType);
                   2341:         }
                   2342:     }
                   2343:     if (context == 'parmslog') {
                   2344:         var secondType = 'hidden';
                   2345:         if (firstType == 'text') {
                   2346:             secondType = 'checkbox';
                   2347:         }
                   2348:         secondObject = document.getElementById(secondid);  
                   2349:         if (typeof(secondObject) == 'object') {
                   2350:             if (secondObject.type != secondType) {
                   2351:                 changeInputType(secondObject,secondType);
                   2352:             }
                   2353:         }
                   2354:         var textItem = document.getElementById(thirdid);
                   2355:         var currtext = textItem.innerHTML;
                   2356:         var newtext;
                   2357:         if (firstType == 'text') {
                   2358:             newtext = '$includetext';
                   2359:         } else {
                   2360:             newtext = '&nbsp;';
                   2361:         }
                   2362:         if (currtext != newtext) {
                   2363:             textItem.innerHTML = newtext;
                   2364:         }
                   2365:     }
                   2366:     return;
                   2367: }
                   2368: 
                   2369: function changeInputType(oldObject,newType) {
                   2370:     var newObject = document.createElement('input');
                   2371:     newObject.type = newType;
                   2372:     if (oldObject.size) {
                   2373:         newObject.size = oldObject.size;
                   2374:     }
                   2375:     if (oldObject.value) {
                   2376:         newObject.value = oldObject.value;
                   2377:     }
                   2378:     if (oldObject.name) {
                   2379:         newObject.name = oldObject.name;
                   2380:     }
                   2381:     if (oldObject.id) {
                   2382:         newObject.id = oldObject.id;
                   2383:     }
                   2384:     oldObject.parentNode.replaceChild(newObject,oldObject);
                   2385:     return;
                   2386: }
                   2387: 
                   2388: ENDJS
1.475     www      2389: }
                   2390: 
1.167     www      2391: sub gradeleveldescription {
                   2392:     my $gradelevel=shift;
                   2393:     my %gradelevels=(0 => 'Not specified',
                   2394: 		     1 => 'Grade 1',
                   2395: 		     2 => 'Grade 2',
                   2396: 		     3 => 'Grade 3',
                   2397: 		     4 => 'Grade 4',
                   2398: 		     5 => 'Grade 5',
                   2399: 		     6 => 'Grade 6',
                   2400: 		     7 => 'Grade 7',
                   2401: 		     8 => 'Grade 8',
                   2402: 		     9 => 'Grade 9',
                   2403: 		     10 => 'Grade 10',
                   2404: 		     11 => 'Grade 11',
                   2405: 		     12 => 'Grade 12',
                   2406: 		     13 => 'Grade 13',
                   2407: 		     14 => '100 Level',
                   2408: 		     15 => '200 Level',
                   2409: 		     16 => '300 Level',
                   2410: 		     17 => '400 Level',
                   2411: 		     18 => 'Graduate Level');
                   2412:     return &mt($gradelevels{$gradelevel});
                   2413: }
                   2414: 
1.163     www      2415: sub select_level_form {
                   2416:     my ($deflevel,$name)=@_;
                   2417:     unless ($deflevel) { $deflevel=0; }
1.167     www      2418:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
                   2419:     for (my $i=0; $i<=18; $i++) {
                   2420:         $selectform.="<option value=\"$i\" ".
1.253     albertel 2421:             ($i==$deflevel ? 'selected="selected" ' : '').
1.167     www      2422:                 ">".&gradeleveldescription($i)."</option>\n";
                   2423:     }
                   2424:     $selectform.="</select>";
                   2425:     return $selectform;
1.163     www      2426: }
1.167     www      2427: 
1.35      matthew  2428: #-------------------------------------------
                   2429: 
1.45      matthew  2430: =pod
                   2431: 
1.1075.2.115  raeburn  2432: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35      matthew  2433: 
                   2434: Returns a string containing a <select name='$name' size='1'> form to 
                   2435: allow a user to select the domain to preform an operation in.  
                   2436: See loncreateuser.pm for an example invocation and use.
                   2437: 
1.90      www      2438: If the $includeempty flag is set, it also includes an empty choice ("no domain
                   2439: selected");
                   2440: 
1.743     raeburn  2441: If the $showdomdesc flag is set, the domain name is followed by the domain description.
                   2442: 
1.910     raeburn  2443: 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.
                   2444: 
1.1075.2.36  raeburn  2445: The optional $incdoms is a reference to an array of domains which will be the only available options.
                   2446: 
1.1075.2.115  raeburn  2447: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
                   2448: 
                   2449: The optional $disabled argument, if true, adds the disabled attribute to the select tag. 
1.563     raeburn  2450: 
1.35      matthew  2451: =cut
                   2452: 
                   2453: #-------------------------------------------
1.34      matthew  2454: sub select_dom_form {
1.1075.2.115  raeburn  2455:     my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872     raeburn  2456:     if ($onchange) {
1.874     raeburn  2457:         $onchange = ' onchange="'.$onchange.'"';
1.743     raeburn  2458:     }
1.1075.2.115  raeburn  2459:     if ($disabled) {
                   2460:         $disabled = ' disabled="disabled"';
                   2461:     }
1.1075.2.36  raeburn  2462:     my (@domains,%exclude);
1.910     raeburn  2463:     if (ref($incdoms) eq 'ARRAY') {
                   2464:         @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
                   2465:     } else {
                   2466:         @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
                   2467:     }
1.90      www      2468:     if ($includeempty) { @domains=('',@domains); }
1.1075.2.36  raeburn  2469:     if (ref($excdoms) eq 'ARRAY') {
                   2470:         map { $exclude{$_} = 1; } @{$excdoms};
                   2471:     }
1.1075.2.115  raeburn  2472:     my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356     albertel 2473:     foreach my $dom (@domains) {
1.1075.2.36  raeburn  2474:         next if ($exclude{$dom});
1.356     albertel 2475:         $selectdomain.="<option value=\"$dom\" ".
1.563     raeburn  2476:             ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
                   2477:         if ($showdomdesc) {
                   2478:             if ($dom ne '') {
                   2479:                 my $domdesc = &Apache::lonnet::domain($dom,'description');
                   2480:                 if ($domdesc ne '') {
                   2481:                     $selectdomain .= ' ('.$domdesc.')';
                   2482:                 }
                   2483:             } 
                   2484:         }
                   2485:         $selectdomain .= "</option>\n";
1.34      matthew  2486:     }
                   2487:     $selectdomain.="</select>";
                   2488:     return $selectdomain;
                   2489: }
                   2490: 
1.35      matthew  2491: #-------------------------------------------
                   2492: 
1.45      matthew  2493: =pod
                   2494: 
1.648     raeburn  2495: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35      matthew  2496: 
1.586     raeburn  2497: input: 4 arguments (two required, two optional) - 
                   2498:     $domain - domain of new user
                   2499:     $name - name of form element
                   2500:     $default - Value of 'default' causes a default item to be first 
                   2501:                             option, and selected by default. 
                   2502:     $hide - Value of 'hide' causes hiding of the name of the server, 
                   2503:                             if 1 server found, or default, if 0 found.
1.594     raeburn  2504: output: returns 2 items: 
1.586     raeburn  2505: (a) form element which contains either:
                   2506:    (i) <select name="$name">
                   2507:         <option value="$hostid1">$hostid $servers{$hostid}</option>
                   2508:         <option value="$hostid2">$hostid $servers{$hostid}</option>       
                   2509:        </select>
                   2510:        form item if there are multiple library servers in $domain, or
                   2511:    (ii) an <input type="hidden" name="$name" value="$hostid" /> form item 
                   2512:        if there is only one library server in $domain.
                   2513: 
                   2514: (b) number of library servers found.
                   2515: 
                   2516: See loncreateuser.pm for example of use.
1.35      matthew  2517: 
                   2518: =cut
                   2519: 
                   2520: #-------------------------------------------
1.586     raeburn  2521: sub home_server_form_item {
                   2522:     my ($domain,$name,$default,$hide) = @_;
1.513     albertel 2523:     my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586     raeburn  2524:     my $result;
                   2525:     my $numlib = keys(%servers);
                   2526:     if ($numlib > 1) {
                   2527:         $result .= '<select name="'.$name.'" />'."\n";
                   2528:         if ($default) {
1.804     bisitz   2529:             $result .= '<option value="default" selected="selected">'.&mt('default').
1.586     raeburn  2530:                        '</option>'."\n";
                   2531:         }
                   2532:         foreach my $hostid (sort(keys(%servers))) {
                   2533:             $result.= '<option value="'.$hostid.'">'.
                   2534: 	              $hostid.' '.$servers{$hostid}."</option>\n";
                   2535:         }
                   2536:         $result .= '</select>'."\n";
                   2537:     } elsif ($numlib == 1) {
                   2538:         my $hostid;
                   2539:         foreach my $item (keys(%servers)) {
                   2540:             $hostid = $item;
                   2541:         }
                   2542:         $result .= '<input type="hidden" name="'.$name.'" value="'.
                   2543:                    $hostid.'" />';
                   2544:                    if (!$hide) {
                   2545:                        $result .= $hostid.' '.$servers{$hostid};
                   2546:                    }
                   2547:                    $result .= "\n";
                   2548:     } elsif ($default) {
                   2549:         $result .= '<input type="hidden" name="'.$name.
                   2550:                    '" value="default" />';
                   2551:                    if (!$hide) {
                   2552:                        $result .= &mt('default');
                   2553:                    }
                   2554:                    $result .= "\n";
1.33      matthew  2555:     }
1.586     raeburn  2556:     return ($result,$numlib);
1.33      matthew  2557: }
1.112     bowersj2 2558: 
                   2559: =pod
                   2560: 
1.534     albertel 2561: =back 
                   2562: 
1.112     bowersj2 2563: =cut
1.87      matthew  2564: 
                   2565: ###############################################################
1.112     bowersj2 2566: ##                  Decoding User Agent                      ##
1.87      matthew  2567: ###############################################################
                   2568: 
                   2569: =pod
                   2570: 
1.112     bowersj2 2571: =head1 Decoding the User Agent
                   2572: 
                   2573: =over 4
                   2574: 
                   2575: =item * &decode_user_agent()
1.87      matthew  2576: 
                   2577: Inputs: $r
                   2578: 
                   2579: Outputs:
                   2580: 
                   2581: =over 4
                   2582: 
1.112     bowersj2 2583: =item * $httpbrowser
1.87      matthew  2584: 
1.112     bowersj2 2585: =item * $clientbrowser
1.87      matthew  2586: 
1.112     bowersj2 2587: =item * $clientversion
1.87      matthew  2588: 
1.112     bowersj2 2589: =item * $clientmathml
1.87      matthew  2590: 
1.112     bowersj2 2591: =item * $clientunicode
1.87      matthew  2592: 
1.112     bowersj2 2593: =item * $clientos
1.87      matthew  2594: 
1.1075.2.42  raeburn  2595: =item * $clientmobile
                   2596: 
                   2597: =item * $clientinfo
                   2598: 
1.1075.2.77  raeburn  2599: =item * $clientosversion
                   2600: 
1.87      matthew  2601: =back
                   2602: 
1.157     matthew  2603: =back 
                   2604: 
1.87      matthew  2605: =cut
                   2606: 
                   2607: ###############################################################
                   2608: ###############################################################
                   2609: sub decode_user_agent {
1.247     albertel 2610:     my ($r)=@_;
1.87      matthew  2611:     my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
                   2612:     my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
                   2613:     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247     albertel 2614:     if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87      matthew  2615:     my $clientbrowser='unknown';
                   2616:     my $clientversion='0';
                   2617:     my $clientmathml='';
                   2618:     my $clientunicode='0';
1.1075.2.42  raeburn  2619:     my $clientmobile=0;
1.1075.2.77  raeburn  2620:     my $clientosversion='';
1.87      matthew  2621:     for (my $i=0;$i<=$#browsertype;$i++) {
1.1075.2.76  raeburn  2622:         my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87      matthew  2623: 	if (($httpbrowser=~/$match/i)  && ($httpbrowser!~/$notmatch/i)) {
                   2624: 	    $clientbrowser=$bname;
                   2625:             $httpbrowser=~/$vreg/i;
                   2626: 	    $clientversion=$1;
                   2627:             $clientmathml=($clientversion>=$minv);
                   2628:             $clientunicode=($clientversion>=$univ);
                   2629: 	}
                   2630:     }
                   2631:     my $clientos='unknown';
1.1075.2.42  raeburn  2632:     my $clientinfo;
1.87      matthew  2633:     if (($httpbrowser=~/linux/i) ||
                   2634:         ($httpbrowser=~/unix/i) ||
                   2635:         ($httpbrowser=~/ux/i) ||
                   2636:         ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
                   2637:     if (($httpbrowser=~/vax/i) ||
                   2638:         ($httpbrowser=~/vms/i)) { $clientos='vms'; }
                   2639:     if ($httpbrowser=~/next/i) { $clientos='next'; }
                   2640:     if (($httpbrowser=~/mac/i) ||
                   2641:         ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1075.2.77  raeburn  2642:     if ($httpbrowser=~/win/i) {
                   2643:         $clientos='win';
                   2644:         if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
                   2645:             $clientosversion = $1;
                   2646:         }
                   2647:     }
1.87      matthew  2648:     if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1075.2.42  raeburn  2649:     if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
                   2650:         $clientmobile=lc($1);
                   2651:     }
                   2652:     if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
                   2653:         $clientinfo = 'firefox-'.$1;
                   2654:     } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
                   2655:         $clientinfo = 'chromeframe-'.$1;
                   2656:     }
1.87      matthew  2657:     return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.77  raeburn  2658:             $clientunicode,$clientos,$clientmobile,$clientinfo,
                   2659:             $clientosversion);
1.87      matthew  2660: }
                   2661: 
1.32      matthew  2662: ###############################################################
                   2663: ##    Authentication changing form generation subroutines    ##
                   2664: ###############################################################
                   2665: ##
                   2666: ## All of the authform_xxxxxxx subroutines take their inputs in a
                   2667: ## hash, and have reasonable default values.
                   2668: ##
                   2669: ##    formname = the name given in the <form> tag.
1.35      matthew  2670: #-------------------------------------------
                   2671: 
1.45      matthew  2672: =pod
                   2673: 
1.112     bowersj2 2674: =head1 Authentication Routines
                   2675: 
                   2676: =over 4
                   2677: 
1.648     raeburn  2678: =item * &authform_xxxxxx()
1.35      matthew  2679: 
                   2680: The authform_xxxxxx subroutines provide javascript and html forms which 
                   2681: handle some of the conveniences required for authentication forms.  
                   2682: This is not an optimal method, but it works.  
                   2683: 
                   2684: =over 4
                   2685: 
1.112     bowersj2 2686: =item * authform_header
1.35      matthew  2687: 
1.112     bowersj2 2688: =item * authform_authorwarning
1.35      matthew  2689: 
1.112     bowersj2 2690: =item * authform_nochange
1.35      matthew  2691: 
1.112     bowersj2 2692: =item * authform_kerberos
1.35      matthew  2693: 
1.112     bowersj2 2694: =item * authform_internal
1.35      matthew  2695: 
1.112     bowersj2 2696: =item * authform_filesystem
1.35      matthew  2697: 
                   2698: =back
                   2699: 
1.648     raeburn  2700: See loncreateuser.pm for invocation and use examples.
1.157     matthew  2701: 
1.35      matthew  2702: =cut
                   2703: 
                   2704: #-------------------------------------------
1.32      matthew  2705: sub authform_header{  
                   2706:     my %in = (
                   2707:         formname => 'cu',
1.80      albertel 2708:         kerb_def_dom => '',
1.32      matthew  2709:         @_,
                   2710:     );
                   2711:     $in{'formname'} = 'document.' . $in{'formname'};
                   2712:     my $result='';
1.80      albertel 2713: 
                   2714: #---------------------------------------------- Code for upper case translation
                   2715:     my $Javascript_toUpperCase;
                   2716:     unless ($in{kerb_def_dom}) {
                   2717:         $Javascript_toUpperCase =<<"END";
                   2718:         switch (choice) {
                   2719:            case 'krb': currentform.elements[choicearg].value =
                   2720:                currentform.elements[choicearg].value.toUpperCase();
                   2721:                break;
                   2722:            default:
                   2723:         }
                   2724: END
                   2725:     } else {
                   2726:         $Javascript_toUpperCase = "";
                   2727:     }
                   2728: 
1.165     raeburn  2729:     my $radioval = "'nochange'";
1.591     raeburn  2730:     if (defined($in{'curr_authtype'})) {
                   2731:         if ($in{'curr_authtype'} ne '') {
                   2732:             $radioval = "'".$in{'curr_authtype'}."arg'";
                   2733:         }
1.174     matthew  2734:     }
1.165     raeburn  2735:     my $argfield = 'null';
1.591     raeburn  2736:     if (defined($in{'mode'})) {
1.165     raeburn  2737:         if ($in{'mode'} eq 'modifycourse')  {
1.591     raeburn  2738:             if (defined($in{'curr_autharg'})) {
                   2739:                 if ($in{'curr_autharg'} ne '') {
1.165     raeburn  2740:                     $argfield = "'$in{'curr_autharg'}'";
                   2741:                 }
                   2742:             }
                   2743:         }
                   2744:     }
                   2745: 
1.32      matthew  2746:     $result.=<<"END";
                   2747: var current = new Object();
1.165     raeburn  2748: current.radiovalue = $radioval;
                   2749: current.argfield = $argfield;
1.32      matthew  2750: 
                   2751: function changed_radio(choice,currentform) {
                   2752:     var choicearg = choice + 'arg';
                   2753:     // If a radio button in changed, we need to change the argfield
                   2754:     if (current.radiovalue != choice) {
                   2755:         current.radiovalue = choice;
                   2756:         if (current.argfield != null) {
                   2757:             currentform.elements[current.argfield].value = '';
                   2758:         }
                   2759:         if (choice == 'nochange') {
                   2760:             current.argfield = null;
                   2761:         } else {
                   2762:             current.argfield = choicearg;
                   2763:             switch(choice) {
                   2764:                 case 'krb': 
                   2765:                     currentform.elements[current.argfield].value = 
                   2766:                         "$in{'kerb_def_dom'}";
                   2767:                 break;
                   2768:               default:
                   2769:                 break;
                   2770:             }
                   2771:         }
                   2772:     }
                   2773:     return;
                   2774: }
1.22      www      2775: 
1.32      matthew  2776: function changed_text(choice,currentform) {
                   2777:     var choicearg = choice + 'arg';
                   2778:     if (currentform.elements[choicearg].value !='') {
1.80      albertel 2779:         $Javascript_toUpperCase
1.32      matthew  2780:         // clear old field
                   2781:         if ((current.argfield != choicearg) && (current.argfield != null)) {
                   2782:             currentform.elements[current.argfield].value = '';
                   2783:         }
                   2784:         current.argfield = choicearg;
                   2785:     }
                   2786:     set_auth_radio_buttons(choice,currentform);
                   2787:     return;
1.20      www      2788: }
1.32      matthew  2789: 
                   2790: function set_auth_radio_buttons(newvalue,currentform) {
1.986     raeburn  2791:     var numauthchoices = currentform.login.length;
                   2792:     if (typeof numauthchoices  == "undefined") {
                   2793:         return;
                   2794:     } 
1.32      matthew  2795:     var i=0;
1.986     raeburn  2796:     while (i < numauthchoices) {
1.32      matthew  2797:         if (currentform.login[i].value == newvalue) { break; }
                   2798:         i++;
                   2799:     }
1.986     raeburn  2800:     if (i == numauthchoices) {
1.32      matthew  2801:         return;
                   2802:     }
                   2803:     current.radiovalue = newvalue;
                   2804:     currentform.login[i].checked = true;
                   2805:     return;
                   2806: }
                   2807: END
                   2808:     return $result;
                   2809: }
                   2810: 
1.1075.2.20  raeburn  2811: sub authform_authorwarning {
1.32      matthew  2812:     my $result='';
1.144     matthew  2813:     $result='<i>'.
                   2814:         &mt('As a general rule, only authors or co-authors should be '.
                   2815:             'filesystem authenticated '.
                   2816:             '(which allows access to the server filesystem).')."</i>\n";
1.32      matthew  2817:     return $result;
                   2818: }
                   2819: 
1.1075.2.20  raeburn  2820: sub authform_nochange {
1.32      matthew  2821:     my %in = (
                   2822:               formname => 'document.cu',
                   2823:               kerb_def_dom => 'MSU.EDU',
                   2824:               @_,
                   2825:           );
1.1075.2.20  raeburn  2826:     my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'}); 
1.586     raeburn  2827:     my $result;
1.1075.2.20  raeburn  2828:     if (!$authnum) {
                   2829:         $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586     raeburn  2830:     } else {
                   2831:         $result = '<label>'.&mt('[_1] Do not change login data',
                   2832:                   '<input type="radio" name="login" value="nochange" '.
                   2833:                   'checked="checked" onclick="'.
1.281     albertel 2834:             "javascript:changed_radio('nochange',$in{'formname'});".'" />').
                   2835: 	    '</label>';
1.586     raeburn  2836:     }
1.32      matthew  2837:     return $result;
                   2838: }
                   2839: 
1.591     raeburn  2840: sub authform_kerberos {
1.32      matthew  2841:     my %in = (
                   2842:               formname => 'document.cu',
                   2843:               kerb_def_dom => 'MSU.EDU',
1.80      albertel 2844:               kerb_def_auth => 'krb4',
1.32      matthew  2845:               @_,
                   2846:               );
1.586     raeburn  2847:     my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
                   2848:         $autharg,$jscall);
1.1075.2.20  raeburn  2849:     my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80      albertel 2850:     if ($in{'kerb_def_auth'} eq 'krb5') {
1.772     bisitz   2851:        $check5 = ' checked="checked"';
1.80      albertel 2852:     } else {
1.772     bisitz   2853:        $check4 = ' checked="checked"';
1.80      albertel 2854:     }
1.165     raeburn  2855:     $krbarg = $in{'kerb_def_dom'};
1.591     raeburn  2856:     if (defined($in{'curr_authtype'})) {
                   2857:         if ($in{'curr_authtype'} eq 'krb') {
1.772     bisitz   2858:             $krbcheck = ' checked="checked"';
1.623     raeburn  2859:             if (defined($in{'mode'})) {
                   2860:                 if ($in{'mode'} eq 'modifyuser') {
                   2861:                     $krbcheck = '';
                   2862:                 }
                   2863:             }
1.591     raeburn  2864:             if (defined($in{'curr_kerb_ver'})) {
                   2865:                 if ($in{'curr_krb_ver'} eq '5') {
1.772     bisitz   2866:                     $check5 = ' checked="checked"';
1.591     raeburn  2867:                     $check4 = '';
                   2868:                 } else {
1.772     bisitz   2869:                     $check4 = ' checked="checked"';
1.591     raeburn  2870:                     $check5 = '';
                   2871:                 }
1.586     raeburn  2872:             }
1.591     raeburn  2873:             if (defined($in{'curr_autharg'})) {
1.165     raeburn  2874:                 $krbarg = $in{'curr_autharg'};
                   2875:             }
1.586     raeburn  2876:             if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591     raeburn  2877:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2878:                     $result = 
                   2879:     &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
                   2880:         $in{'curr_autharg'},$krbver);
                   2881:                 } else {
                   2882:                     $result =
                   2883:     &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
                   2884:                 }
                   2885:                 return $result; 
                   2886:             }
                   2887:         }
                   2888:     } else {
                   2889:         if ($authnum == 1) {
1.784     bisitz   2890:             $authtype = '<input type="hidden" name="login" value="krb" />';
1.165     raeburn  2891:         }
                   2892:     }
1.586     raeburn  2893:     if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
                   2894:         return;
1.587     raeburn  2895:     } elsif ($authtype eq '') {
1.591     raeburn  2896:         if (defined($in{'mode'})) {
1.587     raeburn  2897:             if ($in{'mode'} eq 'modifycourse') {
                   2898:                 if ($authnum == 1) {
1.1075.2.20  raeburn  2899:                     $authtype = '<input type="radio" name="login" value="krb" />';
1.587     raeburn  2900:                 }
                   2901:             }
                   2902:         }
1.586     raeburn  2903:     }
                   2904:     $jscall = "javascript:changed_radio('krb',$in{'formname'});";
                   2905:     if ($authtype eq '') {
                   2906:         $authtype = '<input type="radio" name="login" value="krb" '.
                   2907:                     'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
                   2908:                     $krbcheck.' />';
                   2909:     }
                   2910:     if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1075.2.20  raeburn  2911:         ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586     raeburn  2912:          $in{'curr_authtype'} eq 'krb5') ||
1.1075.2.20  raeburn  2913:         (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586     raeburn  2914:          $in{'curr_authtype'} eq 'krb4')) {
                   2915:         $result .= &mt
1.144     matthew  2916:         ('[_1] Kerberos authenticated with domain [_2] '.
1.281     albertel 2917:          '[_3] Version 4 [_4] Version 5 [_5]',
1.586     raeburn  2918:          '<label>'.$authtype,
1.281     albertel 2919:          '</label><input type="text" size="10" name="krbarg" '.
1.165     raeburn  2920:              'value="'.$krbarg.'" '.
1.144     matthew  2921:              'onchange="'.$jscall.'" />',
1.281     albertel 2922:          '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
                   2923:          '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
                   2924: 	 '</label>');
1.586     raeburn  2925:     } elsif ($can_assign{'krb4'}) {
                   2926:         $result .= &mt
                   2927:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2928:          '[_3] Version 4 [_4]',
                   2929:          '<label>'.$authtype,
                   2930:          '</label><input type="text" size="10" name="krbarg" '.
                   2931:              'value="'.$krbarg.'" '.
                   2932:              'onchange="'.$jscall.'" />',
                   2933:          '<label><input type="hidden" name="krbver" value="4" />',
                   2934:          '</label>');
                   2935:     } elsif ($can_assign{'krb5'}) {
                   2936:         $result .= &mt
                   2937:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2938:          '[_3] Version 5 [_4]',
                   2939:          '<label>'.$authtype,
                   2940:          '</label><input type="text" size="10" name="krbarg" '.
                   2941:              'value="'.$krbarg.'" '.
                   2942:              'onchange="'.$jscall.'" />',
                   2943:          '<label><input type="hidden" name="krbver" value="5" />',
                   2944:          '</label>');
                   2945:     }
1.32      matthew  2946:     return $result;
                   2947: }
                   2948: 
1.1075.2.20  raeburn  2949: sub authform_internal {
1.586     raeburn  2950:     my %in = (
1.32      matthew  2951:                 formname => 'document.cu',
                   2952:                 kerb_def_dom => 'MSU.EDU',
                   2953:                 @_,
                   2954:                 );
1.586     raeburn  2955:     my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
1.1075.2.20  raeburn  2956:     my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591     raeburn  2957:     if (defined($in{'curr_authtype'})) {
                   2958:         if ($in{'curr_authtype'} eq 'int') {
1.586     raeburn  2959:             if ($can_assign{'int'}) {
1.772     bisitz   2960:                 $intcheck = 'checked="checked" ';
1.623     raeburn  2961:                 if (defined($in{'mode'})) {
                   2962:                     if ($in{'mode'} eq 'modifyuser') {
                   2963:                         $intcheck = '';
                   2964:                     }
                   2965:                 }
1.591     raeburn  2966:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2967:                     $intarg = $in{'curr_autharg'};
                   2968:                 }
                   2969:             } else {
                   2970:                 $result = &mt('Currently internally authenticated.');
                   2971:                 return $result;
1.165     raeburn  2972:             }
                   2973:         }
1.586     raeburn  2974:     } else {
                   2975:         if ($authnum == 1) {
1.784     bisitz   2976:             $authtype = '<input type="hidden" name="login" value="int" />';
1.586     raeburn  2977:         }
                   2978:     }
                   2979:     if (!$can_assign{'int'}) {
                   2980:         return;
1.587     raeburn  2981:     } elsif ($authtype eq '') {
1.591     raeburn  2982:         if (defined($in{'mode'})) {
1.587     raeburn  2983:             if ($in{'mode'} eq 'modifycourse') {
                   2984:                 if ($authnum == 1) {
1.1075.2.20  raeburn  2985:                     $authtype = '<input type="radio" name="login" value="int" />';
1.587     raeburn  2986:                 }
                   2987:             }
                   2988:         }
1.165     raeburn  2989:     }
1.586     raeburn  2990:     $jscall = "javascript:changed_radio('int',$in{'formname'});";
                   2991:     if ($authtype eq '') {
                   2992:         $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
                   2993:                     ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
                   2994:     }
1.605     bisitz   2995:     $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586     raeburn  2996:                $intarg.'" onchange="'.$jscall.'" />';
                   2997:     $result = &mt
1.144     matthew  2998:         ('[_1] Internally authenticated (with initial password [_2])',
1.586     raeburn  2999:          '<label>'.$authtype,'</label>'.$autharg);
1.824     bisitz   3000:     $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  3001:     return $result;
                   3002: }
                   3003: 
1.1075.2.20  raeburn  3004: sub authform_local {
1.32      matthew  3005:     my %in = (
                   3006:               formname => 'document.cu',
                   3007:               kerb_def_dom => 'MSU.EDU',
                   3008:               @_,
                   3009:               );
1.586     raeburn  3010:     my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
1.1075.2.20  raeburn  3011:     my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591     raeburn  3012:     if (defined($in{'curr_authtype'})) {
                   3013:         if ($in{'curr_authtype'} eq 'loc') {
1.586     raeburn  3014:             if ($can_assign{'loc'}) {
1.772     bisitz   3015:                 $loccheck = 'checked="checked" ';
1.623     raeburn  3016:                 if (defined($in{'mode'})) {
                   3017:                     if ($in{'mode'} eq 'modifyuser') {
                   3018:                         $loccheck = '';
                   3019:                     }
                   3020:                 }
1.591     raeburn  3021:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  3022:                     $locarg = $in{'curr_autharg'};
                   3023:                 }
                   3024:             } else {
                   3025:                 $result = &mt('Currently using local (institutional) authentication.');
                   3026:                 return $result;
1.165     raeburn  3027:             }
                   3028:         }
1.586     raeburn  3029:     } else {
                   3030:         if ($authnum == 1) {
1.784     bisitz   3031:             $authtype = '<input type="hidden" name="login" value="loc" />';
1.586     raeburn  3032:         }
                   3033:     }
                   3034:     if (!$can_assign{'loc'}) {
                   3035:         return;
1.587     raeburn  3036:     } elsif ($authtype eq '') {
1.591     raeburn  3037:         if (defined($in{'mode'})) {
1.587     raeburn  3038:             if ($in{'mode'} eq 'modifycourse') {
                   3039:                 if ($authnum == 1) {
1.1075.2.20  raeburn  3040:                     $authtype = '<input type="radio" name="login" value="loc" />';
1.587     raeburn  3041:                 }
                   3042:             }
                   3043:         }
1.165     raeburn  3044:     }
1.586     raeburn  3045:     $jscall = "javascript:changed_radio('loc',$in{'formname'});";
                   3046:     if ($authtype eq '') {
                   3047:         $authtype = '<input type="radio" name="login" value="loc" '.
                   3048:                     $loccheck.' onchange="'.$jscall.'" onclick="'.
                   3049:                     $jscall.'" />';
                   3050:     }
                   3051:     $autharg = '<input type="text" size="10" name="locarg" value="'.
                   3052:                $locarg.'" onchange="'.$jscall.'" />';
                   3053:     $result = &mt('[_1] Local Authentication with argument [_2]',
                   3054:                   '<label>'.$authtype,'</label>'.$autharg);
1.32      matthew  3055:     return $result;
                   3056: }
                   3057: 
1.1075.2.20  raeburn  3058: sub authform_filesystem {
1.32      matthew  3059:     my %in = (
                   3060:               formname => 'document.cu',
                   3061:               kerb_def_dom => 'MSU.EDU',
                   3062:               @_,
                   3063:               );
1.586     raeburn  3064:     my ($fsyscheck,$result,$authtype,$autharg,$jscall);
1.1075.2.20  raeburn  3065:     my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591     raeburn  3066:     if (defined($in{'curr_authtype'})) {
                   3067:         if ($in{'curr_authtype'} eq 'fsys') {
1.586     raeburn  3068:             if ($can_assign{'fsys'}) {
1.772     bisitz   3069:                 $fsyscheck = 'checked="checked" ';
1.623     raeburn  3070:                 if (defined($in{'mode'})) {
                   3071:                     if ($in{'mode'} eq 'modifyuser') {
                   3072:                         $fsyscheck = '';
                   3073:                     }
                   3074:                 }
1.586     raeburn  3075:             } else {
                   3076:                 $result = &mt('Currently Filesystem Authenticated.');
                   3077:                 return $result;
                   3078:             }           
                   3079:         }
                   3080:     } else {
                   3081:         if ($authnum == 1) {
1.784     bisitz   3082:             $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586     raeburn  3083:         }
                   3084:     }
                   3085:     if (!$can_assign{'fsys'}) {
                   3086:         return;
1.587     raeburn  3087:     } elsif ($authtype eq '') {
1.591     raeburn  3088:         if (defined($in{'mode'})) {
1.587     raeburn  3089:             if ($in{'mode'} eq 'modifycourse') {
                   3090:                 if ($authnum == 1) {
1.1075.2.20  raeburn  3091:                     $authtype = '<input type="radio" name="login" value="fsys" />';
1.587     raeburn  3092:                 }
                   3093:             }
                   3094:         }
1.586     raeburn  3095:     }
                   3096:     $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
                   3097:     if ($authtype eq '') {
                   3098:         $authtype = '<input type="radio" name="login" value="fsys" '.
                   3099:                     $fsyscheck.' onchange="'.$jscall.'" onclick="'.
                   3100:                     $jscall.'" />';
                   3101:     }
                   3102:     $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
                   3103:                ' onchange="'.$jscall.'" />';
                   3104:     $result = &mt
1.144     matthew  3105:         ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281     albertel 3106:          '<label><input type="radio" name="login" value="fsys" '.
1.586     raeburn  3107:          $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605     bisitz   3108:          '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144     matthew  3109:                   'onchange="'.$jscall.'" />');
1.32      matthew  3110:     return $result;
                   3111: }
                   3112: 
1.586     raeburn  3113: sub get_assignable_auth {
                   3114:     my ($dom) = @_;
                   3115:     if ($dom eq '') {
                   3116:         $dom = $env{'request.role.domain'};
                   3117:     }
                   3118:     my %can_assign = (
                   3119:                           krb4 => 1,
                   3120:                           krb5 => 1,
                   3121:                           int  => 1,
                   3122:                           loc  => 1,
                   3123:                      );
                   3124:     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
                   3125:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   3126:         if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
                   3127:             my $authhash = $domconfig{'usercreation'}{'authtypes'};
                   3128:             my $context;
                   3129:             if ($env{'request.role'} =~ /^au/) {
                   3130:                 $context = 'author';
                   3131:             } elsif ($env{'request.role'} =~ /^dc/) {
                   3132:                 $context = 'domain';
                   3133:             } elsif ($env{'request.course.id'}) {
                   3134:                 $context = 'course';
                   3135:             }
                   3136:             if ($context) {
                   3137:                 if (ref($authhash->{$context}) eq 'HASH') {
                   3138:                    %can_assign = %{$authhash->{$context}}; 
                   3139:                 }
                   3140:             }
                   3141:         }
                   3142:     }
                   3143:     my $authnum = 0;
                   3144:     foreach my $key (keys(%can_assign)) {
                   3145:         if ($can_assign{$key}) {
                   3146:             $authnum ++;
                   3147:         }
                   3148:     }
                   3149:     if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
                   3150:         $authnum --;
                   3151:     }
                   3152:     return ($authnum,%can_assign);
                   3153: }
                   3154: 
1.80      albertel 3155: ###############################################################
                   3156: ##    Get Kerberos Defaults for Domain                 ##
                   3157: ###############################################################
                   3158: ##
                   3159: ## Returns default kerberos version and an associated argument
                   3160: ## as listed in file domain.tab. If not listed, provides
                   3161: ## appropriate default domain and kerberos version.
                   3162: ##
                   3163: #-------------------------------------------
                   3164: 
                   3165: =pod
                   3166: 
1.648     raeburn  3167: =item * &get_kerberos_defaults()
1.80      albertel 3168: 
                   3169: get_kerberos_defaults($target_domain) returns the default kerberos
1.641     raeburn  3170: version and domain. If not found, it defaults to version 4 and the 
                   3171: domain of the server.
1.80      albertel 3172: 
1.648     raeburn  3173: =over 4
                   3174: 
1.80      albertel 3175: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
                   3176: 
1.648     raeburn  3177: =back
                   3178: 
                   3179: =back
                   3180: 
1.80      albertel 3181: =cut
                   3182: 
                   3183: #-------------------------------------------
                   3184: sub get_kerberos_defaults {
                   3185:     my $domain=shift;
1.641     raeburn  3186:     my ($krbdef,$krbdefdom);
                   3187:     my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
                   3188:     if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
                   3189:         $krbdef = $domdefaults{'auth_def'};
                   3190:         $krbdefdom = $domdefaults{'auth_arg_def'};
                   3191:     } else {
1.80      albertel 3192:         $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
                   3193:         my $krbdefdom=$1;
                   3194:         $krbdefdom=~tr/a-z/A-Z/;
                   3195:         $krbdef = "krb4";
                   3196:     }
                   3197:     return ($krbdef,$krbdefdom);
                   3198: }
1.112     bowersj2 3199: 
1.32      matthew  3200: 
1.46      matthew  3201: ###############################################################
                   3202: ##                Thesaurus Functions                        ##
                   3203: ###############################################################
1.20      www      3204: 
1.46      matthew  3205: =pod
1.20      www      3206: 
1.112     bowersj2 3207: =head1 Thesaurus Functions
                   3208: 
                   3209: =over 4
                   3210: 
1.648     raeburn  3211: =item * &initialize_keywords()
1.46      matthew  3212: 
                   3213: Initializes the package variable %Keywords if it is empty.  Uses the
                   3214: package variable $thesaurus_db_file.
                   3215: 
                   3216: =cut
                   3217: 
                   3218: ###################################################
                   3219: 
                   3220: sub initialize_keywords {
                   3221:     return 1 if (scalar keys(%Keywords));
                   3222:     # If we are here, %Keywords is empty, so fill it up
                   3223:     #   Make sure the file we need exists...
                   3224:     if (! -e $thesaurus_db_file) {
                   3225:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
                   3226:                                  " failed because it does not exist");
                   3227:         return 0;
                   3228:     }
                   3229:     #   Set up the hash as a database
                   3230:     my %thesaurus_db;
                   3231:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 3232:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  3233:         &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
                   3234:                                  $thesaurus_db_file);
                   3235:         return 0;
                   3236:     } 
                   3237:     #  Get the average number of appearances of a word.
                   3238:     my $avecount = $thesaurus_db{'average.count'};
                   3239:     #  Put keywords (those that appear > average) into %Keywords
                   3240:     while (my ($word,$data)=each (%thesaurus_db)) {
                   3241:         my ($count,undef) = split /:/,$data;
                   3242:         $Keywords{$word}++ if ($count > $avecount);
                   3243:     }
                   3244:     untie %thesaurus_db;
                   3245:     # Remove special values from %Keywords.
1.356     albertel 3246:     foreach my $value ('total.count','average.count') {
                   3247:         delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586     raeburn  3248:   }
1.46      matthew  3249:     return 1;
                   3250: }
                   3251: 
                   3252: ###################################################
                   3253: 
                   3254: =pod
                   3255: 
1.648     raeburn  3256: =item * &keyword($word)
1.46      matthew  3257: 
                   3258: Returns true if $word is a keyword.  A keyword is a word that appears more 
                   3259: than the average number of times in the thesaurus database.  Calls 
                   3260: &initialize_keywords
                   3261: 
                   3262: =cut
                   3263: 
                   3264: ###################################################
1.20      www      3265: 
                   3266: sub keyword {
1.46      matthew  3267:     return if (!&initialize_keywords());
                   3268:     my $word=lc(shift());
                   3269:     $word=~s/\W//g;
                   3270:     return exists($Keywords{$word});
1.20      www      3271: }
1.46      matthew  3272: 
                   3273: ###############################################################
                   3274: 
                   3275: =pod 
1.20      www      3276: 
1.648     raeburn  3277: =item * &get_related_words()
1.46      matthew  3278: 
1.160     matthew  3279: Look up a word in the thesaurus.  Takes a scalar argument and returns
1.46      matthew  3280: an array of words.  If the keyword is not in the thesaurus, an empty array
                   3281: will be returned.  The order of the words returned is determined by the
                   3282: database which holds them.
                   3283: 
                   3284: Uses global $thesaurus_db_file.
                   3285: 
1.1057    foxr     3286: 
1.46      matthew  3287: =cut
                   3288: 
                   3289: ###############################################################
                   3290: sub get_related_words {
                   3291:     my $keyword = shift;
                   3292:     my %thesaurus_db;
                   3293:     if (! -e $thesaurus_db_file) {
                   3294:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
                   3295:                                  "failed because the file does not exist");
                   3296:         return ();
                   3297:     }
                   3298:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 3299:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  3300:         return ();
                   3301:     } 
                   3302:     my @Words=();
1.429     www      3303:     my $count=0;
1.46      matthew  3304:     if (exists($thesaurus_db{$keyword})) {
1.356     albertel 3305: 	# The first element is the number of times
                   3306: 	# the word appears.  We do not need it now.
1.429     www      3307: 	my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
                   3308: 	my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
                   3309: 	my $threshold=$mostfrequentcount/10;
                   3310:         foreach my $possibleword (@RelatedWords) {
                   3311:             my ($word,$wordcount)=split(/\,/,$possibleword);
                   3312:             if ($wordcount>$threshold) {
                   3313: 		push(@Words,$word);
                   3314:                 $count++;
                   3315:                 if ($count>10) { last; }
                   3316: 	    }
1.20      www      3317:         }
                   3318:     }
1.46      matthew  3319:     untie %thesaurus_db;
                   3320:     return @Words;
1.14      harris41 3321: }
1.46      matthew  3322: 
1.112     bowersj2 3323: =pod
                   3324: 
                   3325: =back
                   3326: 
                   3327: =cut
1.61      www      3328: 
                   3329: # -------------------------------------------------------------- Plaintext name
1.81      albertel 3330: =pod
                   3331: 
1.112     bowersj2 3332: =head1 User Name Functions
                   3333: 
                   3334: =over 4
                   3335: 
1.648     raeburn  3336: =item * &plainname($uname,$udom,$first)
1.81      albertel 3337: 
1.112     bowersj2 3338: Takes a users logon name and returns it as a string in
1.226     albertel 3339: "first middle last generation" form 
                   3340: if $first is set to 'lastname' then it returns it as
                   3341: 'lastname generation, firstname middlename' if their is a lastname
1.81      albertel 3342: 
                   3343: =cut
1.61      www      3344: 
1.295     www      3345: 
1.81      albertel 3346: ###############################################################
1.61      www      3347: sub plainname {
1.226     albertel 3348:     my ($uname,$udom,$first)=@_;
1.537     albertel 3349:     return if (!defined($uname) || !defined($udom));
1.295     www      3350:     my %names=&getnames($uname,$udom);
1.226     albertel 3351:     my $name=&Apache::lonnet::format_name($names{'firstname'},
                   3352: 					  $names{'middlename'},
                   3353: 					  $names{'lastname'},
                   3354: 					  $names{'generation'},$first);
                   3355:     $name=~s/^\s+//;
1.62      www      3356:     $name=~s/\s+$//;
                   3357:     $name=~s/\s+/ /g;
1.353     albertel 3358:     if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62      www      3359:     return $name;
1.61      www      3360: }
1.66      www      3361: 
                   3362: # -------------------------------------------------------------------- Nickname
1.81      albertel 3363: =pod
                   3364: 
1.648     raeburn  3365: =item * &nickname($uname,$udom)
1.81      albertel 3366: 
                   3367: Gets a users name and returns it as a string as
                   3368: 
                   3369: "&quot;nickname&quot;"
1.66      www      3370: 
1.81      albertel 3371: if the user has a nickname or
                   3372: 
                   3373: "first middle last generation"
                   3374: 
                   3375: if the user does not
                   3376: 
                   3377: =cut
1.66      www      3378: 
                   3379: sub nickname {
                   3380:     my ($uname,$udom)=@_;
1.537     albertel 3381:     return if (!defined($uname) || !defined($udom));
1.295     www      3382:     my %names=&getnames($uname,$udom);
1.68      albertel 3383:     my $name=$names{'nickname'};
1.66      www      3384:     if ($name) {
                   3385:        $name='&quot;'.$name.'&quot;'; 
                   3386:     } else {
                   3387:        $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
                   3388: 	     $names{'lastname'}.' '.$names{'generation'};
                   3389:        $name=~s/\s+$//;
                   3390:        $name=~s/\s+/ /g;
                   3391:     }
                   3392:     return $name;
                   3393: }
                   3394: 
1.295     www      3395: sub getnames {
                   3396:     my ($uname,$udom)=@_;
1.537     albertel 3397:     return if (!defined($uname) || !defined($udom));
1.433     albertel 3398:     if ($udom eq 'public' && $uname eq 'public') {
                   3399: 	return ('lastname' => &mt('Public'));
                   3400:     }
1.295     www      3401:     my $id=$uname.':'.$udom;
                   3402:     my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
                   3403:     if ($cached) {
                   3404: 	return %{$names};
                   3405:     } else {
                   3406: 	my %loadnames=&Apache::lonnet::get('environment',
                   3407:                     ['firstname','middlename','lastname','generation','nickname'],
                   3408: 					 $udom,$uname);
                   3409: 	&Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
                   3410: 	return %loadnames;
                   3411:     }
                   3412: }
1.61      www      3413: 
1.542     raeburn  3414: # -------------------------------------------------------------------- getemails
1.648     raeburn  3415: 
1.542     raeburn  3416: =pod
                   3417: 
1.648     raeburn  3418: =item * &getemails($uname,$udom)
1.542     raeburn  3419: 
                   3420: Gets a user's email information and returns it as a hash with keys:
                   3421: notification, critnotification, permanentemail
                   3422: 
                   3423: For notification and critnotification, values are comma-separated lists 
1.648     raeburn  3424: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542     raeburn  3425:  
1.648     raeburn  3426: 
1.542     raeburn  3427: =cut
                   3428: 
1.648     raeburn  3429: 
1.466     albertel 3430: sub getemails {
                   3431:     my ($uname,$udom)=@_;
                   3432:     if ($udom eq 'public' && $uname eq 'public') {
                   3433: 	return;
                   3434:     }
1.467     www      3435:     if (!$udom) { $udom=$env{'user.domain'}; }
                   3436:     if (!$uname) { $uname=$env{'user.name'}; }
1.466     albertel 3437:     my $id=$uname.':'.$udom;
                   3438:     my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
                   3439:     if ($cached) {
                   3440: 	return %{$names};
                   3441:     } else {
                   3442: 	my %loadnames=&Apache::lonnet::get('environment',
                   3443:                     			   ['notification','critnotification',
                   3444: 					    'permanentemail'],
                   3445: 					   $udom,$uname);
                   3446: 	&Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
                   3447: 	return %loadnames;
                   3448:     }
                   3449: }
                   3450: 
1.551     albertel 3451: sub flush_email_cache {
                   3452:     my ($uname,$udom)=@_;
                   3453:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   3454:     if (!$uname) { $uname=$env{'user.name'};   }
                   3455:     return if ($udom eq 'public' && $uname eq 'public');
                   3456:     my $id=$uname.':'.$udom;
                   3457:     &Apache::lonnet::devalidate_cache_new('emailscache',$id);
                   3458: }
                   3459: 
1.728     raeburn  3460: # -------------------------------------------------------------------- getlangs
                   3461: 
                   3462: =pod
                   3463: 
                   3464: =item * &getlangs($uname,$udom)
                   3465: 
                   3466: Gets a user's language preference and returns it as a hash with key:
                   3467: language.
                   3468: 
                   3469: =cut
                   3470: 
                   3471: 
                   3472: sub getlangs {
                   3473:     my ($uname,$udom) = @_;
                   3474:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   3475:     if (!$uname) { $uname=$env{'user.name'};   }
                   3476:     my $id=$uname.':'.$udom;
                   3477:     my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
                   3478:     if ($cached) {
                   3479:         return %{$langs};
                   3480:     } else {
                   3481:         my %loadlangs=&Apache::lonnet::get('environment',['languages'],
                   3482:                                            $udom,$uname);
                   3483:         &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
                   3484:         return %loadlangs;
                   3485:     }
                   3486: }
                   3487: 
                   3488: sub flush_langs_cache {
                   3489:     my ($uname,$udom)=@_;
                   3490:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   3491:     if (!$uname) { $uname=$env{'user.name'};   }
                   3492:     return if ($udom eq 'public' && $uname eq 'public');
                   3493:     my $id=$uname.':'.$udom;
                   3494:     &Apache::lonnet::devalidate_cache_new('userlangs',$id);
                   3495: }
                   3496: 
1.61      www      3497: # ------------------------------------------------------------------ Screenname
1.81      albertel 3498: 
                   3499: =pod
                   3500: 
1.648     raeburn  3501: =item * &screenname($uname,$udom)
1.81      albertel 3502: 
                   3503: Gets a users screenname and returns it as a string
                   3504: 
                   3505: =cut
1.61      www      3506: 
                   3507: sub screenname {
                   3508:     my ($uname,$udom)=@_;
1.258     albertel 3509:     if ($uname eq $env{'user.name'} &&
                   3510: 	$udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212     albertel 3511:     my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68      albertel 3512:     return $names{'screenname'};
1.62      www      3513: }
                   3514: 
1.212     albertel 3515: 
1.802     bisitz   3516: # ------------------------------------------------------------- Confirm Wrapper
                   3517: =pod
                   3518: 
1.1075.2.42  raeburn  3519: =item * &confirmwrapper($message)
1.802     bisitz   3520: 
                   3521: Wrap messages about completion of operation in box
                   3522: 
                   3523: =cut
                   3524: 
                   3525: sub confirmwrapper {
                   3526:     my ($message)=@_;
                   3527:     if ($message) {
                   3528:         return "\n".'<div class="LC_confirm_box">'."\n"
                   3529:                .$message."\n"
                   3530:                .'</div>'."\n";
                   3531:     } else {
                   3532:         return $message;
                   3533:     }
                   3534: }
                   3535: 
1.62      www      3536: # ------------------------------------------------------------- Message Wrapper
                   3537: 
                   3538: sub messagewrapper {
1.369     www      3539:     my ($link,$username,$domain,$subject,$text)=@_;
1.62      www      3540:     return 
1.441     albertel 3541:         '<a href="/adm/email?compose=individual&amp;'.
                   3542:         'recname='.$username.'&amp;recdom='.$domain.
                   3543: 	'&amp;subject='.&escape($subject).'&amp;text='.&escape($text).'" '.
1.200     matthew  3544:         'title="'.&mt('Send message').'">'.$link.'</a>';
1.74      www      3545: }
1.802     bisitz   3546: 
1.74      www      3547: # --------------------------------------------------------------- Notes Wrapper
                   3548: 
                   3549: sub noteswrapper {
                   3550:     my ($link,$un,$do)=@_;
                   3551:     return 
1.896     amueller 3552: "<a href='/adm/email?recordftf=retrieve&amp;recname=$un&amp;recdom=$do'>$link</a>";
1.62      www      3553: }
1.802     bisitz   3554: 
1.62      www      3555: # ------------------------------------------------------------- Aboutme Wrapper
                   3556: 
                   3557: sub aboutmewrapper {
1.1070    raeburn  3558:     my ($link,$username,$domain,$target,$class)=@_;
1.447     raeburn  3559:     if (!defined($username)  && !defined($domain)) {
                   3560:         return;
                   3561:     }
1.1075.2.15  raeburn  3562:     return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070    raeburn  3563: 	($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62      www      3564: }
                   3565: 
                   3566: # ------------------------------------------------------------ Syllabus Wrapper
                   3567: 
                   3568: sub syllabuswrapper {
1.707     bisitz   3569:     my ($linktext,$coursedir,$domain)=@_;
1.208     matthew  3570:     return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61      www      3571: }
1.14      harris41 3572: 
1.802     bisitz   3573: # -----------------------------------------------------------------------------
                   3574: 
1.208     matthew  3575: sub track_student_link {
1.887     raeburn  3576:     my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268     albertel 3577:     my $link ="/adm/trackstudent?";
1.208     matthew  3578:     my $title = 'View recent activity';
                   3579:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   3580:         defined($sdom)  && $sdom  !~ /^\s*$/) {
1.268     albertel 3581:         $link .= "selected_student=$sname:$sdom";
1.208     matthew  3582:         $title .= ' of this student';
1.268     albertel 3583:     } 
1.208     matthew  3584:     if (defined($target) && $target !~ /^\s*$/) {
                   3585:         $target = qq{target="$target"};
                   3586:     } else {
                   3587:         $target = '';
                   3588:     }
1.268     albertel 3589:     if ($start) { $link.='&amp;start='.$start; }
1.887     raeburn  3590:     if ($only_body) { $link .= '&amp;only_body=1'; }
1.554     albertel 3591:     $title = &mt($title);
                   3592:     $linktext = &mt($linktext);
1.448     albertel 3593:     return qq{<a href="$link" title="$title" $target>$linktext</a>}.
                   3594: 	&help_open_topic('View_recent_activity');
1.208     matthew  3595: }
                   3596: 
1.781     raeburn  3597: sub slot_reservations_link {
                   3598:     my ($linktext,$sname,$sdom,$target) = @_;
                   3599:     my $link ="/adm/slotrequest?command=showresv&amp;origin=aboutme";
                   3600:     my $title = 'View slot reservation history';
                   3601:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   3602:         defined($sdom)  && $sdom  !~ /^\s*$/) {
                   3603:         $link .= "&amp;uname=$sname&amp;udom=$sdom";
                   3604:         $title .= ' of this student';
                   3605:     }
                   3606:     if (defined($target) && $target !~ /^\s*$/) {
                   3607:         $target = qq{target="$target"};
                   3608:     } else {
                   3609:         $target = '';
                   3610:     }
                   3611:     $title = &mt($title);
                   3612:     $linktext = &mt($linktext);
                   3613:     return qq{<a href="$link" title="$title" $target>$linktext</a>};
                   3614: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
                   3615: 
                   3616: }
                   3617: 
1.508     www      3618: # ===================================================== Display a student photo
                   3619: 
                   3620: 
1.509     albertel 3621: sub student_image_tag {
1.508     www      3622:     my ($domain,$user)=@_;
                   3623:     my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
                   3624:     if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
                   3625: 	return '<img src="'.$imgsrc.'" align="right" />';
                   3626:     } else {
                   3627: 	return '';
                   3628:     }
                   3629: }
                   3630: 
1.112     bowersj2 3631: =pod
                   3632: 
                   3633: =back
                   3634: 
                   3635: =head1 Access .tab File Data
                   3636: 
                   3637: =over 4
                   3638: 
1.648     raeburn  3639: =item * &languageids() 
1.112     bowersj2 3640: 
                   3641: returns list of all language ids
                   3642: 
                   3643: =cut
                   3644: 
1.14      harris41 3645: sub languageids {
1.16      harris41 3646:     return sort(keys(%language));
1.14      harris41 3647: }
                   3648: 
1.112     bowersj2 3649: =pod
                   3650: 
1.648     raeburn  3651: =item * &languagedescription() 
1.112     bowersj2 3652: 
                   3653: returns description of a specified language id
                   3654: 
                   3655: =cut
                   3656: 
1.14      harris41 3657: sub languagedescription {
1.125     www      3658:     my $code=shift;
                   3659:     return  ($supported_language{$code}?'* ':'').
                   3660:             $language{$code}.
1.126     www      3661: 	    ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145     www      3662: }
                   3663: 
1.1048    foxr     3664: =pod
                   3665: 
                   3666: =item * &plainlanguagedescription
                   3667: 
                   3668: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
                   3669: and the language character encoding (e.g. ISO) separated by a ' - ' string.
                   3670: 
                   3671: =cut
                   3672: 
1.145     www      3673: sub plainlanguagedescription {
                   3674:     my $code=shift;
                   3675:     return $language{$code};
                   3676: }
                   3677: 
1.1048    foxr     3678: =pod
                   3679: 
                   3680: =item * &supportedlanguagecode
                   3681: 
                   3682: Returns the supported language code (e.g. sptutf maps to pt) given a language
                   3683: code.
                   3684: 
                   3685: =cut
                   3686: 
1.145     www      3687: sub supportedlanguagecode {
                   3688:     my $code=shift;
                   3689:     return $supported_language{$code};
1.97      www      3690: }
                   3691: 
1.112     bowersj2 3692: =pod
                   3693: 
1.1048    foxr     3694: =item * &latexlanguage()
                   3695: 
                   3696: Given a language key code returns the correspondnig language to use
                   3697: to select the correct hyphenation on LaTeX printouts.  This is undef if there
                   3698: is no supported hyphenation for the language code.
                   3699: 
                   3700: =cut
                   3701: 
                   3702: sub latexlanguage {
                   3703:     my $code = shift;
                   3704:     return $latex_language{$code};
                   3705: }
                   3706: 
                   3707: =pod
                   3708: 
                   3709: =item * &latexhyphenation()
                   3710: 
                   3711: Same as above but what's supplied is the language as it might be stored
                   3712: in the metadata.
                   3713: 
                   3714: =cut
                   3715: 
                   3716: sub latexhyphenation {
                   3717:     my $key = shift;
                   3718:     return $latex_language_bykey{$key};
                   3719: }
                   3720: 
                   3721: =pod
                   3722: 
1.648     raeburn  3723: =item * &copyrightids() 
1.112     bowersj2 3724: 
                   3725: returns list of all copyrights
                   3726: 
                   3727: =cut
                   3728: 
                   3729: sub copyrightids {
                   3730:     return sort(keys(%cprtag));
                   3731: }
                   3732: 
                   3733: =pod
                   3734: 
1.648     raeburn  3735: =item * &copyrightdescription() 
1.112     bowersj2 3736: 
                   3737: returns description of a specified copyright id
                   3738: 
                   3739: =cut
                   3740: 
                   3741: sub copyrightdescription {
1.166     www      3742:     return &mt($cprtag{shift(@_)});
1.112     bowersj2 3743: }
1.197     matthew  3744: 
                   3745: =pod
                   3746: 
1.648     raeburn  3747: =item * &source_copyrightids() 
1.192     taceyjo1 3748: 
                   3749: returns list of all source copyrights
                   3750: 
                   3751: =cut
                   3752: 
                   3753: sub source_copyrightids {
                   3754:     return sort(keys(%scprtag));
                   3755: }
                   3756: 
                   3757: =pod
                   3758: 
1.648     raeburn  3759: =item * &source_copyrightdescription() 
1.192     taceyjo1 3760: 
                   3761: returns description of a specified source copyright id
                   3762: 
                   3763: =cut
                   3764: 
                   3765: sub source_copyrightdescription {
                   3766:     return &mt($scprtag{shift(@_)});
                   3767: }
1.112     bowersj2 3768: 
                   3769: =pod
                   3770: 
1.648     raeburn  3771: =item * &filecategories() 
1.112     bowersj2 3772: 
                   3773: returns list of all file categories
                   3774: 
                   3775: =cut
                   3776: 
                   3777: sub filecategories {
                   3778:     return sort(keys(%category_extensions));
                   3779: }
                   3780: 
                   3781: =pod
                   3782: 
1.648     raeburn  3783: =item * &filecategorytypes() 
1.112     bowersj2 3784: 
                   3785: returns list of file types belonging to a given file
                   3786: category
                   3787: 
                   3788: =cut
                   3789: 
                   3790: sub filecategorytypes {
1.356     albertel 3791:     my ($cat) = @_;
                   3792:     return @{$category_extensions{lc($cat)}};
1.112     bowersj2 3793: }
                   3794: 
                   3795: =pod
                   3796: 
1.648     raeburn  3797: =item * &fileembstyle() 
1.112     bowersj2 3798: 
                   3799: returns embedding style for a specified file type
                   3800: 
                   3801: =cut
                   3802: 
                   3803: sub fileembstyle {
                   3804:     return $fe{lc(shift(@_))};
1.169     www      3805: }
                   3806: 
1.351     www      3807: sub filemimetype {
                   3808:     return $fm{lc(shift(@_))};
                   3809: }
                   3810: 
1.169     www      3811: 
                   3812: sub filecategoryselect {
                   3813:     my ($name,$value)=@_;
1.189     matthew  3814:     return &select_form($value,$name,
1.970     raeburn  3815:                         {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112     bowersj2 3816: }
                   3817: 
                   3818: =pod
                   3819: 
1.648     raeburn  3820: =item * &filedescription() 
1.112     bowersj2 3821: 
                   3822: returns description for a specified file type
                   3823: 
                   3824: =cut
                   3825: 
                   3826: sub filedescription {
1.188     matthew  3827:     my $file_description = $fd{lc(shift())};
                   3828:     $file_description =~ s:([\[\]]):~$1:g;
                   3829:     return &mt($file_description);
1.112     bowersj2 3830: }
                   3831: 
                   3832: =pod
                   3833: 
1.648     raeburn  3834: =item * &filedescriptionex() 
1.112     bowersj2 3835: 
                   3836: returns description for a specified file type with
                   3837: extra formatting
                   3838: 
                   3839: =cut
                   3840: 
                   3841: sub filedescriptionex {
                   3842:     my $ex=shift;
1.188     matthew  3843:     my $file_description = $fd{lc($ex)};
                   3844:     $file_description =~ s:([\[\]]):~$1:g;
                   3845:     return '.'.$ex.' '.&mt($file_description);
1.112     bowersj2 3846: }
                   3847: 
                   3848: # End of .tab access
                   3849: =pod
                   3850: 
                   3851: =back
                   3852: 
                   3853: =cut
                   3854: 
                   3855: # ------------------------------------------------------------------ File Types
                   3856: sub fileextensions {
                   3857:     return sort(keys(%fe));
                   3858: }
                   3859: 
1.97      www      3860: # ----------------------------------------------------------- Display Languages
                   3861: # returns a hash with all desired display languages
                   3862: #
                   3863: 
                   3864: sub display_languages {
                   3865:     my %languages=();
1.695     raeburn  3866:     foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356     albertel 3867: 	$languages{$lang}=1;
1.97      www      3868:     }
                   3869:     &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258     albertel 3870:     if ($env{'form.displaylanguage'}) {
1.356     albertel 3871: 	foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
                   3872: 	    $languages{$lang}=1;
1.97      www      3873:         }
                   3874:     }
                   3875:     return %languages;
1.14      harris41 3876: }
                   3877: 
1.582     albertel 3878: sub languages {
                   3879:     my ($possible_langs) = @_;
1.695     raeburn  3880:     my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582     albertel 3881:     if (!ref($possible_langs)) {
                   3882: 	if( wantarray ) {
                   3883: 	    return @preferred_langs;
                   3884: 	} else {
                   3885: 	    return $preferred_langs[0];
                   3886: 	}
                   3887:     }
                   3888:     my %possibilities = map { $_ => 1 } (@$possible_langs);
                   3889:     my @preferred_possibilities;
                   3890:     foreach my $preferred_lang (@preferred_langs) {
                   3891: 	if (exists($possibilities{$preferred_lang})) {
                   3892: 	    push(@preferred_possibilities, $preferred_lang);
                   3893: 	}
                   3894:     }
                   3895:     if( wantarray ) {
                   3896: 	return @preferred_possibilities;
                   3897:     }
                   3898:     return $preferred_possibilities[0];
                   3899: }
                   3900: 
1.742     raeburn  3901: sub user_lang {
                   3902:     my ($touname,$toudom,$fromcid) = @_;
                   3903:     my @userlangs;
                   3904:     if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
                   3905:         @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
                   3906:                     $env{'course.'.$fromcid.'.languages'}));
                   3907:     } else {
                   3908:         my %langhash = &getlangs($touname,$toudom);
                   3909:         if ($langhash{'languages'} ne '') {
                   3910:             @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
                   3911:         } else {
                   3912:             my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
                   3913:             if ($domdefs{'lang_def'} ne '') {
                   3914:                 @userlangs = ($domdefs{'lang_def'});
                   3915:             }
                   3916:         }
                   3917:     }
                   3918:     my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
                   3919:     my $user_lh = Apache::localize->get_handle(@languages);
                   3920:     return $user_lh;
                   3921: }
                   3922: 
                   3923: 
1.112     bowersj2 3924: ###############################################################
                   3925: ##               Student Answer Attempts                     ##
                   3926: ###############################################################
                   3927: 
                   3928: =pod
                   3929: 
                   3930: =head1 Alternate Problem Views
                   3931: 
                   3932: =over 4
                   3933: 
1.648     raeburn  3934: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1075.2.86  raeburn  3935:     $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112     bowersj2 3936: 
                   3937: Return string with previous attempt on problem. Arguments:
                   3938: 
                   3939: =over 4
                   3940: 
                   3941: =item * $symb: Problem, including path
                   3942: 
                   3943: =item * $username: username of the desired student
                   3944: 
                   3945: =item * $domain: domain of the desired student
1.14      harris41 3946: 
1.112     bowersj2 3947: =item * $course: Course ID
1.14      harris41 3948: 
1.112     bowersj2 3949: =item * $getattempt: Leave blank for all attempts, otherwise put
                   3950:     something
1.14      harris41 3951: 
1.112     bowersj2 3952: =item * $regexp: if string matches this regexp, the string will be
                   3953:     sent to $gradesub
1.14      harris41 3954: 
1.112     bowersj2 3955: =item * $gradesub: routine that processes the string if it matches $regexp
1.14      harris41 3956: 
1.1075.2.86  raeburn  3957: =item * $usec: section of the desired student
                   3958: 
                   3959: =item * $identifier: counter for student (multiple students one problem) or
                   3960:     problem (one student; whole sequence).
                   3961: 
1.112     bowersj2 3962: =back
1.14      harris41 3963: 
1.112     bowersj2 3964: The output string is a table containing all desired attempts, if any.
1.16      harris41 3965: 
1.112     bowersj2 3966: =cut
1.1       albertel 3967: 
                   3968: sub get_previous_attempt {
1.1075.2.86  raeburn  3969:   my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1       albertel 3970:   my $prevattempts='';
1.43      ng       3971:   no strict 'refs';
1.1       albertel 3972:   if ($symb) {
1.3       albertel 3973:     my (%returnhash)=
                   3974:       &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1       albertel 3975:     if ($returnhash{'version'}) {
                   3976:       my %lasthash=();
                   3977:       my $version;
                   3978:       for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.91  raeburn  3979:         foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
                   3980:             if ($key =~ /\.rawrndseed$/) {
                   3981:                 my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
                   3982:                 $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
                   3983:             } else {
                   3984:                 $lasthash{$key}=$returnhash{$version.':'.$key};
                   3985:             }
1.19      harris41 3986:         }
1.1       albertel 3987:       }
1.596     albertel 3988:       $prevattempts=&start_data_table().&start_data_table_header_row();
                   3989:       $prevattempts.='<th>'.&mt('History').'</th>';
1.1075.2.86  raeburn  3990:       my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945     raeburn  3991:       my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356     albertel 3992:       foreach my $key (sort(keys(%lasthash))) {
                   3993: 	my ($ign,@parts) = split(/\./,$key);
1.41      ng       3994: 	if ($#parts > 0) {
1.31      albertel 3995: 	  my $data=$parts[-1];
1.989     raeburn  3996:           next if ($data eq 'foilorder');
1.31      albertel 3997: 	  pop(@parts);
1.1010    www      3998:           $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.'&nbsp;</th>';
1.945     raeburn  3999:           if ($data eq 'type') {
                   4000:               unless ($showsurv) {
                   4001:                   my $id = join(',',@parts);
                   4002:                   $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978     raeburn  4003:                   if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
                   4004:                       $lasthidden{$ign.'.'.$id} = 1;
                   4005:                   }
1.945     raeburn  4006:               }
1.1075.2.86  raeburn  4007:               if ($identifier ne '') {
                   4008:                   my $id = join(',',@parts);
                   4009:                   if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
                   4010:                                                $domain,$username,$usec,undef,$course) =~ /^no/) {
                   4011:                       $hidestatus{$ign.'.'.$id} = 1;
                   4012:                   }
                   4013:               }
                   4014:           } elsif ($data eq 'regrader') {
                   4015:               if (($identifier ne '') && (@parts)) {
                   4016:                   my $id = join(',',@parts);
                   4017:                   $regraded{$ign.'.'.$id} = 1;
                   4018:               }
1.1010    www      4019:           } 
1.31      albertel 4020: 	} else {
1.41      ng       4021: 	  if ($#parts == 0) {
                   4022: 	    $prevattempts.='<th>'.$parts[0].'</th>';
                   4023: 	  } else {
                   4024: 	    $prevattempts.='<th>'.$ign.'</th>';
                   4025: 	  }
1.31      albertel 4026: 	}
1.16      harris41 4027:       }
1.596     albertel 4028:       $prevattempts.=&end_data_table_header_row();
1.40      ng       4029:       if ($getattempt eq '') {
1.1075.2.86  raeburn  4030:         my (%solved,%resets,%probstatus);
                   4031:         if (($identifier ne '') && (keys(%regraded) > 0)) {
                   4032:             for ($version=1;$version<=$returnhash{'version'};$version++) {
                   4033:                 foreach my $id (keys(%regraded)) {
                   4034:                     if (($returnhash{$version.':'.$id.'.regrader'}) &&
                   4035:                         ($returnhash{$version.':'.$id.'.tries'} eq '') &&
                   4036:                         ($returnhash{$version.':'.$id.'.award'} eq '')) {
                   4037:                         push(@{$resets{$id}},$version);
                   4038:                     }
                   4039:                 }
                   4040:             }
                   4041:         }
1.40      ng       4042: 	for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.86  raeburn  4043:             my (@hidden,@unsolved);
1.945     raeburn  4044:             if (%typeparts) {
                   4045:                 foreach my $id (keys(%typeparts)) {
1.1075.2.86  raeburn  4046:                     if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
                   4047:                         ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945     raeburn  4048:                         push(@hidden,$id);
1.1075.2.86  raeburn  4049:                     } elsif ($identifier ne '') {
                   4050:                         unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
                   4051:                                 ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
                   4052:                                 ($hidestatus{$id})) {
                   4053:                             next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
                   4054:                             if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
                   4055:                                 push(@{$solved{$id}},$version);
                   4056:                             } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
                   4057:                                      (ref($solved{$id}) eq 'ARRAY')) {
                   4058:                                 my $skip;
                   4059:                                 if (ref($resets{$id}) eq 'ARRAY') {
                   4060:                                     foreach my $reset (@{$resets{$id}}) {
                   4061:                                         if ($reset > $solved{$id}[-1]) {
                   4062:                                             $skip=1;
                   4063:                                             last;
                   4064:                                         }
                   4065:                                     }
                   4066:                                 }
                   4067:                                 unless ($skip) {
                   4068:                                     my ($ign,$partslist) = split(/\./,$id,2);
                   4069:                                     push(@unsolved,$partslist);
                   4070:                                 }
                   4071:                             }
                   4072:                         }
1.945     raeburn  4073:                     }
                   4074:                 }
                   4075:             }
                   4076:             $prevattempts.=&start_data_table_row().
1.1075.2.86  raeburn  4077:                            '<td>'.&mt('Transaction [_1]',$version);
                   4078:             if (@unsolved) {
                   4079:                 $prevattempts .= '<span class="LC_nobreak"><label>'.
                   4080:                                  '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
                   4081:                                  &mt('Hide').'</label></span>';
                   4082:             }
                   4083:             $prevattempts .= '</td>';
1.945     raeburn  4084:             if (@hidden) {
                   4085:                 foreach my $key (sort(keys(%lasthash))) {
1.989     raeburn  4086:                     next if ($key =~ /\.foilorder$/);
1.945     raeburn  4087:                     my $hide;
                   4088:                     foreach my $id (@hidden) {
                   4089:                         if ($key =~ /^\Q$id\E/) {
                   4090:                             $hide = 1;
                   4091:                             last;
                   4092:                         }
                   4093:                     }
                   4094:                     if ($hide) {
                   4095:                         my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
                   4096:                         if (($data eq 'award') || ($data eq 'awarddetail')) {
                   4097:                             my $value = &format_previous_attempt_value($key,
                   4098:                                              $returnhash{$version.':'.$key});
                   4099:                             $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   4100:                         } else {
                   4101:                             $prevattempts.='<td>&nbsp;</td>';
                   4102:                         }
                   4103:                     } else {
                   4104:                         if ($key =~ /\./) {
1.1075.2.91  raeburn  4105:                             my $value = $returnhash{$version.':'.$key};
                   4106:                             if ($key =~ /\.rndseed$/) {
                   4107:                                 my ($id) = ($key =~ /^(.+)\.rndseed$/);
                   4108:                                 if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
                   4109:                                     $value = $returnhash{$version.':'.$id.'.rawrndseed'};
                   4110:                                 }
                   4111:                             }
                   4112:                             $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
                   4113:                                            '&nbsp;</td>';
1.945     raeburn  4114:                         } else {
                   4115:                             $prevattempts.='<td>&nbsp;</td>';
                   4116:                         }
                   4117:                     }
                   4118:                 }
                   4119:             } else {
                   4120: 	        foreach my $key (sort(keys(%lasthash))) {
1.989     raeburn  4121:                     next if ($key =~ /\.foilorder$/);
1.1075.2.91  raeburn  4122:                     my $value = $returnhash{$version.':'.$key};
                   4123:                     if ($key =~ /\.rndseed$/) {
                   4124:                         my ($id) = ($key =~ /^(.+)\.rndseed$/);
                   4125:                         if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
                   4126:                             $value = $returnhash{$version.':'.$id.'.rawrndseed'};
                   4127:                         }
                   4128:                     }
                   4129:                     $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
                   4130:                                    '&nbsp;</td>';
1.945     raeburn  4131: 	        }
                   4132:             }
                   4133: 	    $prevattempts.=&end_data_table_row();
1.40      ng       4134: 	 }
1.1       albertel 4135:       }
1.945     raeburn  4136:       my @currhidden = keys(%lasthidden);
1.596     albertel 4137:       $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356     albertel 4138:       foreach my $key (sort(keys(%lasthash))) {
1.989     raeburn  4139:           next if ($key =~ /\.foilorder$/);
1.945     raeburn  4140:           if (%typeparts) {
                   4141:               my $hidden;
                   4142:               foreach my $id (@currhidden) {
                   4143:                   if ($key =~ /^\Q$id\E/) {
                   4144:                       $hidden = 1;
                   4145:                       last;
                   4146:                   }
                   4147:               }
                   4148:               if ($hidden) {
                   4149:                   my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
                   4150:                   if (($data eq 'award') || ($data eq 'awarddetail')) {
                   4151:                       my $value = &format_previous_attempt_value($key,$lasthash{$key});
                   4152:                       if ($key =~/$regexp$/ && (defined &$gradesub)) {
                   4153:                           $value = &$gradesub($value);
                   4154:                       }
                   4155:                       $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   4156:                   } else {
                   4157:                       $prevattempts.='<td>&nbsp;</td>';
                   4158:                   }
                   4159:               } else {
                   4160:                   my $value = &format_previous_attempt_value($key,$lasthash{$key});
                   4161:                   if ($key =~/$regexp$/ && (defined &$gradesub)) {
                   4162:                       $value = &$gradesub($value);
                   4163:                   }
                   4164:                   $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   4165:               }
                   4166:           } else {
                   4167: 	      my $value = &format_previous_attempt_value($key,$lasthash{$key});
                   4168: 	      if ($key =~/$regexp$/ && (defined &$gradesub)) {
                   4169:                   $value = &$gradesub($value);
                   4170:               }
                   4171: 	      $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   4172:           }
1.16      harris41 4173:       }
1.596     albertel 4174:       $prevattempts.= &end_data_table_row().&end_data_table();
1.1       albertel 4175:     } else {
1.596     albertel 4176:       $prevattempts=
                   4177: 	  &start_data_table().&start_data_table_row().
                   4178: 	  '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
                   4179: 	  &end_data_table_row().&end_data_table();
1.1       albertel 4180:     }
                   4181:   } else {
1.596     albertel 4182:     $prevattempts=
                   4183: 	  &start_data_table().&start_data_table_row().
                   4184: 	  '<td>'.&mt('No data.').'</td>'.
                   4185: 	  &end_data_table_row().&end_data_table();
1.1       albertel 4186:   }
1.10      albertel 4187: }
                   4188: 
1.581     albertel 4189: sub format_previous_attempt_value {
                   4190:     my ($key,$value) = @_;
1.1011    www      4191:     if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581     albertel 4192: 	$value = &Apache::lonlocal::locallocaltime($value);
                   4193:     } elsif (ref($value) eq 'ARRAY') {
                   4194: 	$value = '('.join(', ', @{ $value }).')';
1.988     raeburn  4195:     } elsif ($key =~ /answerstring$/) {
                   4196:         my %answers = &Apache::lonnet::str2hash($value);
                   4197:         my @anskeys = sort(keys(%answers));
                   4198:         if (@anskeys == 1) {
                   4199:             my $answer = $answers{$anskeys[0]};
1.1001    raeburn  4200:             if ($answer =~ m{\0}) {
                   4201:                 $answer =~ s{\0}{,}g;
1.988     raeburn  4202:             }
                   4203:             my $tag_internal_answer_name = 'INTERNAL';
                   4204:             if ($anskeys[0] eq $tag_internal_answer_name) {
                   4205:                 $value = $answer; 
                   4206:             } else {
                   4207:                 $value = $anskeys[0].'='.$answer;
                   4208:             }
                   4209:         } else {
                   4210:             foreach my $ans (@anskeys) {
                   4211:                 my $answer = $answers{$ans};
1.1001    raeburn  4212:                 if ($answer =~ m{\0}) {
                   4213:                     $answer =~ s{\0}{,}g;
1.988     raeburn  4214:                 }
                   4215:                 $value .=  $ans.'='.$answer.'<br />';;
                   4216:             } 
                   4217:         }
1.581     albertel 4218:     } else {
                   4219: 	$value = &unescape($value);
                   4220:     }
                   4221:     return $value;
                   4222: }
                   4223: 
                   4224: 
1.107     albertel 4225: sub relative_to_absolute {
                   4226:     my ($url,$output)=@_;
                   4227:     my $parser=HTML::TokeParser->new(\$output);
                   4228:     my $token;
                   4229:     my $thisdir=$url;
                   4230:     my @rlinks=();
                   4231:     while ($token=$parser->get_token) {
                   4232: 	if ($token->[0] eq 'S') {
                   4233: 	    if ($token->[1] eq 'a') {
                   4234: 		if ($token->[2]->{'href'}) {
                   4235: 		    $rlinks[$#rlinks+1]=$token->[2]->{'href'};
                   4236: 		}
                   4237: 	    } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
                   4238: 		$rlinks[$#rlinks+1]=$token->[2]->{'src'};
                   4239: 	    } elsif ($token->[1] eq 'base') {
                   4240: 		$thisdir=$token->[2]->{'href'};
                   4241: 	    }
                   4242: 	}
                   4243:     }
                   4244:     $thisdir=~s-/[^/]*$--;
1.356     albertel 4245:     foreach my $link (@rlinks) {
1.726     raeburn  4246: 	unless (($link=~/^https?\:\/\//i) ||
1.356     albertel 4247: 		($link=~/^\//) ||
                   4248: 		($link=~/^javascript:/i) ||
                   4249: 		($link=~/^mailto:/i) ||
                   4250: 		($link=~/^\#/)) {
                   4251: 	    my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
                   4252: 	    $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107     albertel 4253: 	}
                   4254:     }
                   4255: # -------------------------------------------------- Deal with Applet codebases
                   4256:     $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
                   4257:     return $output;
                   4258: }
                   4259: 
1.112     bowersj2 4260: =pod
                   4261: 
1.648     raeburn  4262: =item * &get_student_view()
1.112     bowersj2 4263: 
                   4264: show a snapshot of what student was looking at
                   4265: 
                   4266: =cut
                   4267: 
1.10      albertel 4268: sub get_student_view {
1.186     albertel 4269:   my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114     www      4270:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 4271:   my (%form);
1.10      albertel 4272:   my @elements=('symb','courseid','domain','username');
                   4273:   foreach my $element (@elements) {
1.186     albertel 4274:       $form{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 4275:   }
1.186     albertel 4276:   if (defined($moreenv)) {
                   4277:       %form=(%form,%{$moreenv});
                   4278:   }
1.236     albertel 4279:   if (defined($target)) { $form{'grade_target'} = $target; }
1.107     albertel 4280:   $feedurl=&Apache::lonnet::clutter($feedurl);
1.650     www      4281:   my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11      albertel 4282:   $userview=~s/\<body[^\>]*\>//gi;
                   4283:   $userview=~s/\<\/body\>//gi;
                   4284:   $userview=~s/\<html\>//gi;
                   4285:   $userview=~s/\<\/html\>//gi;
                   4286:   $userview=~s/\<head\>//gi;
                   4287:   $userview=~s/\<\/head\>//gi;
                   4288:   $userview=~s/action\s*\=/would_be_action\=/gi;
1.107     albertel 4289:   $userview=&relative_to_absolute($feedurl,$userview);
1.650     www      4290:   if (wantarray) {
                   4291:      return ($userview,$response);
                   4292:   } else {
                   4293:      return $userview;
                   4294:   }
                   4295: }
                   4296: 
                   4297: sub get_student_view_with_retries {
                   4298:   my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
                   4299: 
                   4300:     my $ok = 0;                 # True if we got a good response.
                   4301:     my $content;
                   4302:     my $response;
                   4303: 
                   4304:     # Try to get the student_view done. within the retries count:
                   4305:     
                   4306:     do {
                   4307:          ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
                   4308:          $ok      = $response->is_success;
                   4309:          if (!$ok) {
                   4310:             &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
                   4311:          }
                   4312:          $retries--;
                   4313:     } while (!$ok && ($retries > 0));
                   4314:     
                   4315:     if (!$ok) {
                   4316:        $content = '';          # On error return an empty content.
                   4317:     }
1.651     www      4318:     if (wantarray) {
                   4319:        return ($content, $response);
                   4320:     } else {
                   4321:        return $content;
                   4322:     }
1.11      albertel 4323: }
                   4324: 
1.112     bowersj2 4325: =pod
                   4326: 
1.648     raeburn  4327: =item * &get_student_answers() 
1.112     bowersj2 4328: 
                   4329: show a snapshot of how student was answering problem
                   4330: 
                   4331: =cut
                   4332: 
1.11      albertel 4333: sub get_student_answers {
1.100     sakharuk 4334:   my ($symb,$username,$domain,$courseid,%form) = @_;
1.114     www      4335:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 4336:   my (%moreenv);
1.11      albertel 4337:   my @elements=('symb','courseid','domain','username');
                   4338:   foreach my $element (@elements) {
1.186     albertel 4339:     $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 4340:   }
1.186     albertel 4341:   $moreenv{'grade_target'}='answer';
                   4342:   %moreenv=(%form,%moreenv);
1.497     raeburn  4343:   $feedurl = &Apache::lonnet::clutter($feedurl);
                   4344:   my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10      albertel 4345:   return $userview;
1.1       albertel 4346: }
1.116     albertel 4347: 
                   4348: =pod
                   4349: 
                   4350: =item * &submlink()
                   4351: 
1.242     albertel 4352: Inputs: $text $uname $udom $symb $target
1.116     albertel 4353: 
                   4354: Returns: A link to grades.pm such as to see the SUBM view of a student
                   4355: 
                   4356: =cut
                   4357: 
                   4358: ###############################################
                   4359: sub submlink {
1.242     albertel 4360:     my ($text,$uname,$udom,$symb,$target)=@_;
1.116     albertel 4361:     if (!($uname && $udom)) {
                   4362: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 4363: 	    &Apache::lonnet::whichuser($symb);
1.116     albertel 4364: 	if (!$symb) { $symb=$cursymb; }
                   4365:     }
1.254     matthew  4366:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      4367:     $symb=&escape($symb);
1.960     bisitz   4368:     if ($target) { $target=" target=\"$target\""; }
                   4369:     return
                   4370:         '<a href="/adm/grades?command=submission'.
                   4371:         '&amp;symb='.$symb.
                   4372:         '&amp;student='.$uname.
                   4373:         '&amp;userdom='.$udom.'"'.
                   4374:         $target.'>'.$text.'</a>';
1.242     albertel 4375: }
                   4376: ##############################################
                   4377: 
                   4378: =pod
                   4379: 
                   4380: =item * &pgrdlink()
                   4381: 
                   4382: Inputs: $text $uname $udom $symb $target
                   4383: 
                   4384: Returns: A link to grades.pm such as to see the PGRD view of a student
                   4385: 
                   4386: =cut
                   4387: 
                   4388: ###############################################
                   4389: sub pgrdlink {
                   4390:     my $link=&submlink(@_);
                   4391:     $link=~s/(&command=submission)/$1&showgrading=yes/;
                   4392:     return $link;
                   4393: }
                   4394: ##############################################
                   4395: 
                   4396: =pod
                   4397: 
                   4398: =item * &pprmlink()
                   4399: 
                   4400: Inputs: $text $uname $udom $symb $target
                   4401: 
                   4402: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283     albertel 4403: student and a specific resource
1.242     albertel 4404: 
                   4405: =cut
                   4406: 
                   4407: ###############################################
                   4408: sub pprmlink {
                   4409:     my ($text,$uname,$udom,$symb,$target)=@_;
                   4410:     if (!($uname && $udom)) {
                   4411: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 4412: 	    &Apache::lonnet::whichuser($symb);
1.242     albertel 4413: 	if (!$symb) { $symb=$cursymb; }
                   4414:     }
1.254     matthew  4415:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      4416:     $symb=&escape($symb);
1.242     albertel 4417:     if ($target) { $target="target=\"$target\""; }
1.595     albertel 4418:     return '<a href="/adm/parmset?command=set&amp;'.
                   4419: 	'symb='.$symb.'&amp;uname='.$uname.
                   4420: 	'&amp;udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116     albertel 4421: }
                   4422: ##############################################
1.37      matthew  4423: 
1.112     bowersj2 4424: =pod
                   4425: 
                   4426: =back
                   4427: 
                   4428: =cut
                   4429: 
1.37      matthew  4430: ###############################################
1.51      www      4431: 
                   4432: 
                   4433: sub timehash {
1.687     raeburn  4434:     my ($thistime) = @_;
                   4435:     my $timezone = &Apache::lonlocal::gettimezone();
                   4436:     my $dt = DateTime->from_epoch(epoch => $thistime)
                   4437:                      ->set_time_zone($timezone);
                   4438:     my $wday = $dt->day_of_week();
                   4439:     if ($wday == 7) { $wday = 0; }
                   4440:     return ( 'second' => $dt->second(),
                   4441:              'minute' => $dt->minute(),
                   4442:              'hour'   => $dt->hour(),
                   4443:              'day'     => $dt->day_of_month(),
                   4444:              'month'   => $dt->month(),
                   4445:              'year'    => $dt->year(),
                   4446:              'weekday' => $wday,
                   4447:              'dayyear' => $dt->day_of_year(),
                   4448:              'dlsav'   => $dt->is_dst() );
1.51      www      4449: }
                   4450: 
1.370     www      4451: sub utc_string {
                   4452:     my ($date)=@_;
1.371     www      4453:     return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370     www      4454: }
                   4455: 
1.51      www      4456: sub maketime {
                   4457:     my %th=@_;
1.687     raeburn  4458:     my ($epoch_time,$timezone,$dt);
                   4459:     $timezone = &Apache::lonlocal::gettimezone();
                   4460:     eval {
                   4461:         $dt = DateTime->new( year   => $th{'year'},
                   4462:                              month  => $th{'month'},
                   4463:                              day    => $th{'day'},
                   4464:                              hour   => $th{'hour'},
                   4465:                              minute => $th{'minute'},
                   4466:                              second => $th{'second'},
                   4467:                              time_zone => $timezone,
                   4468:                          );
                   4469:     };
                   4470:     if (!$@) {
                   4471:         $epoch_time = $dt->epoch;
                   4472:         if ($epoch_time) {
                   4473:             return $epoch_time;
                   4474:         }
                   4475:     }
1.51      www      4476:     return POSIX::mktime(
                   4477:         ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210     www      4478:          $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70      www      4479: }
                   4480: 
                   4481: #########################################
1.51      www      4482: 
                   4483: sub findallcourses {
1.482     raeburn  4484:     my ($roles,$uname,$udom) = @_;
1.355     albertel 4485:     my %roles;
                   4486:     if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348     albertel 4487:     my %courses;
1.51      www      4488:     my $now=time;
1.482     raeburn  4489:     if (!defined($uname)) {
                   4490:         $uname = $env{'user.name'};
                   4491:     }
                   4492:     if (!defined($udom)) {
                   4493:         $udom = $env{'user.domain'};
                   4494:     }
                   4495:     if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073    raeburn  4496:         my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482     raeburn  4497:         if (!%roles) {
                   4498:             %roles = (
                   4499:                        cc => 1,
1.907     raeburn  4500:                        co => 1,
1.482     raeburn  4501:                        in => 1,
                   4502:                        ep => 1,
                   4503:                        ta => 1,
                   4504:                        cr => 1,
                   4505:                        st => 1,
                   4506:              );
                   4507:         }
                   4508:         foreach my $entry (keys(%roleshash)) {
                   4509:             my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
                   4510:             if ($trole =~ /^cr/) { 
                   4511:                 next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
                   4512:             } else {
                   4513:                 next if (!exists($roles{$trole}));
                   4514:             }
                   4515:             if ($tend) {
                   4516:                 next if ($tend < $now);
                   4517:             }
                   4518:             if ($tstart) {
                   4519:                 next if ($tstart > $now);
                   4520:             }
1.1058    raeburn  4521:             my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482     raeburn  4522:             (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058    raeburn  4523:             my $value = $trole.'/'.$cdom.'/';
1.482     raeburn  4524:             if ($secpart eq '') {
                   4525:                 ($cnum,$role) = split(/_/,$cnumpart); 
                   4526:                 $sec = 'none';
1.1058    raeburn  4527:                 $value .= $cnum.'/';
1.482     raeburn  4528:             } else {
                   4529:                 $cnum = $cnumpart;
                   4530:                 ($sec,$role) = split(/_/,$secpart);
1.1058    raeburn  4531:                 $value .= $cnum.'/'.$sec;
                   4532:             }
                   4533:             if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
                   4534:                 unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
                   4535:                     push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
                   4536:                 }
                   4537:             } else {
                   4538:                 @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490     raeburn  4539:             }
1.482     raeburn  4540:         }
                   4541:     } else {
                   4542:         foreach my $key (keys(%env)) {
1.483     albertel 4543: 	    if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
                   4544:                  $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482     raeburn  4545: 	        my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
                   4546: 	        next if ($role eq 'ca' || $role eq 'aa');
                   4547: 	        next if (%roles && !exists($roles{$role}));
                   4548: 	        my ($starttime,$endtime)=split(/\./,$env{$key});
                   4549:                 my $active=1;
                   4550:                 if ($starttime) {
                   4551: 		    if ($now<$starttime) { $active=0; }
                   4552:                 }
                   4553:                 if ($endtime) {
                   4554:                     if ($now>$endtime) { $active=0; }
                   4555:                 }
                   4556:                 if ($active) {
1.1058    raeburn  4557:                     my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482     raeburn  4558:                     if ($sec eq '') {
                   4559:                         $sec = 'none';
1.1058    raeburn  4560:                     } else {
                   4561:                         $value .= $sec;
                   4562:                     }
                   4563:                     if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
                   4564:                         unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
                   4565:                             push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
                   4566:                         }
                   4567:                     } else {
                   4568:                         @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482     raeburn  4569:                     }
1.474     raeburn  4570:                 }
                   4571:             }
1.51      www      4572:         }
                   4573:     }
1.474     raeburn  4574:     return %courses;
1.51      www      4575: }
1.37      matthew  4576: 
1.54      www      4577: ###############################################
1.474     raeburn  4578: 
                   4579: sub blockcheck {
1.1075.2.73  raeburn  4580:     my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490     raeburn  4581: 
1.1075.2.73  raeburn  4582:     if (defined($udom) && defined($uname)) {
                   4583:         # If uname and udom are for a course, check for blocks in the course.
                   4584:         if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
                   4585:             my ($startblock,$endblock,$triggerblock) =
                   4586:                 &get_blocks($setters,$activity,$udom,$uname,$url);
                   4587:             return ($startblock,$endblock,$triggerblock);
                   4588:         }
                   4589:     } else {
1.490     raeburn  4590:         $udom = $env{'user.domain'};
                   4591:         $uname = $env{'user.name'};
                   4592:     }
                   4593: 
1.502     raeburn  4594:     my $startblock = 0;
                   4595:     my $endblock = 0;
1.1062    raeburn  4596:     my $triggerblock = '';
1.482     raeburn  4597:     my %live_courses = &findallcourses(undef,$uname,$udom);
1.474     raeburn  4598: 
1.490     raeburn  4599:     # If uname is for a user, and activity is course-specific, i.e.,
                   4600:     # boards, chat or groups, check for blocking in current course only.
1.474     raeburn  4601: 
1.490     raeburn  4602:     if (($activity eq 'boards' || $activity eq 'chat' ||
1.1075.2.73  raeburn  4603:          $activity eq 'groups' || $activity eq 'printout') &&
                   4604:         ($env{'request.course.id'})) {
1.490     raeburn  4605:         foreach my $key (keys(%live_courses)) {
                   4606:             if ($key ne $env{'request.course.id'}) {
                   4607:                 delete($live_courses{$key});
                   4608:             }
                   4609:         }
                   4610:     }
                   4611: 
                   4612:     my $otheruser = 0;
                   4613:     my %own_courses;
                   4614:     if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
                   4615:         # Resource belongs to user other than current user.
                   4616:         $otheruser = 1;
                   4617:         # Gather courses for current user
                   4618:         %own_courses = 
                   4619:             &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
                   4620:     }
                   4621: 
                   4622:     # Gather active course roles - course coordinator, instructor, 
                   4623:     # exam proctor, ta, student, or custom role.
1.474     raeburn  4624: 
                   4625:     foreach my $course (keys(%live_courses)) {
1.482     raeburn  4626:         my ($cdom,$cnum);
                   4627:         if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
                   4628:             $cdom = $env{'course.'.$course.'.domain'};
                   4629:             $cnum = $env{'course.'.$course.'.num'};
                   4630:         } else {
1.490     raeburn  4631:             ($cdom,$cnum) = split(/_/,$course); 
1.482     raeburn  4632:         }
                   4633:         my $no_ownblock = 0;
                   4634:         my $no_userblock = 0;
1.533     raeburn  4635:         if ($otheruser && $activity ne 'com') {
1.490     raeburn  4636:             # Check if current user has 'evb' priv for this
                   4637:             if (defined($own_courses{$course})) {
                   4638:                 foreach my $sec (keys(%{$own_courses{$course}})) {
                   4639:                     my $checkrole = 'cm./'.$cdom.'/'.$cnum;
                   4640:                     if ($sec ne 'none') {
                   4641:                         $checkrole .= '/'.$sec;
                   4642:                     }
                   4643:                     if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   4644:                         $no_ownblock = 1;
                   4645:                         last;
                   4646:                     }
                   4647:                 }
                   4648:             }
                   4649:             # if they have 'evb' priv and are currently not playing student
                   4650:             next if (($no_ownblock) &&
                   4651:                  ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
                   4652:         }
1.474     raeburn  4653:         foreach my $sec (keys(%{$live_courses{$course}})) {
1.482     raeburn  4654:             my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474     raeburn  4655:             if ($sec ne 'none') {
1.482     raeburn  4656:                 $checkrole .= '/'.$sec;
1.474     raeburn  4657:             }
1.490     raeburn  4658:             if ($otheruser) {
                   4659:                 # Resource belongs to user other than current user.
                   4660:                 # Assemble privs for that user, and check for 'evb' priv.
1.1058    raeburn  4661:                 my (%allroles,%userroles);
                   4662:                 if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
                   4663:                     foreach my $entry (@{$live_courses{$course}{$sec}}) { 
                   4664:                         my ($trole,$tdom,$tnum,$tsec);
                   4665:                         if ($entry =~ /^cr/) {
                   4666:                             ($trole,$tdom,$tnum,$tsec) = 
                   4667:                                 ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
                   4668:                         } else {
                   4669:                            ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
                   4670:                         }
                   4671:                         my ($spec,$area,$trest);
                   4672:                         $area = '/'.$tdom.'/'.$tnum;
                   4673:                         $trest = $tnum;
                   4674:                         if ($tsec ne '') {
                   4675:                             $area .= '/'.$tsec;
                   4676:                             $trest .= '/'.$tsec;
                   4677:                         }
                   4678:                         $spec = $trole.'.'.$area;
                   4679:                         if ($trole =~ /^cr/) {
                   4680:                             &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
                   4681:                                                               $tdom,$spec,$trest,$area);
                   4682:                         } else {
                   4683:                             &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
                   4684:                                                                 $tdom,$spec,$trest,$area);
                   4685:                         }
                   4686:                     }
                   4687:                     my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
                   4688:                     if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
                   4689:                         if ($1) {
                   4690:                             $no_userblock = 1;
                   4691:                             last;
                   4692:                         }
1.486     raeburn  4693:                     }
                   4694:                 }
1.490     raeburn  4695:             } else {
                   4696:                 # Resource belongs to current user
                   4697:                 # Check for 'evb' priv via lonnet::allowed().
1.482     raeburn  4698:                 if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   4699:                     $no_ownblock = 1;
                   4700:                     last;
                   4701:                 }
1.474     raeburn  4702:             }
                   4703:         }
                   4704:         # if they have the evb priv and are currently not playing student
1.482     raeburn  4705:         next if (($no_ownblock) &&
1.491     albertel 4706:                  ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482     raeburn  4707:         next if ($no_userblock);
1.474     raeburn  4708: 
1.866     kalberla 4709:         # Retrieve blocking times and identity of locker for course
1.490     raeburn  4710:         # of specified user, unless user has 'evb' privilege.
1.502     raeburn  4711:         
1.1062    raeburn  4712:         my ($start,$end,$trigger) = 
                   4713:             &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502     raeburn  4714:         if (($start != 0) && 
                   4715:             (($startblock == 0) || ($startblock > $start))) {
                   4716:             $startblock = $start;
1.1062    raeburn  4717:             if ($trigger ne '') {
                   4718:                 $triggerblock = $trigger;
                   4719:             }
1.502     raeburn  4720:         }
                   4721:         if (($end != 0)  &&
                   4722:             (($endblock == 0) || ($endblock < $end))) {
                   4723:             $endblock = $end;
1.1062    raeburn  4724:             if ($trigger ne '') {
                   4725:                 $triggerblock = $trigger;
                   4726:             }
1.502     raeburn  4727:         }
1.490     raeburn  4728:     }
1.1062    raeburn  4729:     return ($startblock,$endblock,$triggerblock);
1.490     raeburn  4730: }
                   4731: 
                   4732: sub get_blocks {
1.1062    raeburn  4733:     my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490     raeburn  4734:     my $startblock = 0;
                   4735:     my $endblock = 0;
1.1062    raeburn  4736:     my $triggerblock = '';
1.490     raeburn  4737:     my $course = $cdom.'_'.$cnum;
                   4738:     $setters->{$course} = {};
                   4739:     $setters->{$course}{'staff'} = [];
                   4740:     $setters->{$course}{'times'} = [];
1.1062    raeburn  4741:     $setters->{$course}{'triggers'} = [];
                   4742:     my (@blockers,%triggered);
                   4743:     my $now = time;
                   4744:     my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
                   4745:     if ($activity eq 'docs') {
                   4746:         @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
                   4747:         foreach my $block (@blockers) {
                   4748:             if ($block =~ /^firstaccess____(.+)$/) {
                   4749:                 my $item = $1;
                   4750:                 my $type = 'map';
                   4751:                 my $timersymb = $item;
                   4752:                 if ($item eq 'course') {
                   4753:                     $type = 'course';
                   4754:                 } elsif ($item =~ /___\d+___/) {
                   4755:                     $type = 'resource';
                   4756:                 } else {
                   4757:                     $timersymb = &Apache::lonnet::symbread($item);
                   4758:                 }
                   4759:                 my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
                   4760:                 my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
                   4761:                 $triggered{$block} = {
                   4762:                                        start => $start,
                   4763:                                        end   => $end,
                   4764:                                        type  => $type,
                   4765:                                      };
                   4766:             }
                   4767:         }
                   4768:     } else {
                   4769:         foreach my $block (keys(%commblocks)) {
                   4770:             if ($block =~ m/^(\d+)____(\d+)$/) { 
                   4771:                 my ($start,$end) = ($1,$2);
                   4772:                 if ($start <= time && $end >= time) {
                   4773:                     if (ref($commblocks{$block}) eq 'HASH') {
                   4774:                         if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
                   4775:                             if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
                   4776:                                 unless(grep(/^\Q$block\E$/,@blockers)) {
                   4777:                                     push(@blockers,$block);
                   4778:                                 }
                   4779:                             }
                   4780:                         }
                   4781:                     }
                   4782:                 }
                   4783:             } elsif ($block =~ /^firstaccess____(.+)$/) {
                   4784:                 my $item = $1;
                   4785:                 my $timersymb = $item; 
                   4786:                 my $type = 'map';
                   4787:                 if ($item eq 'course') {
                   4788:                     $type = 'course';
                   4789:                 } elsif ($item =~ /___\d+___/) {
                   4790:                     $type = 'resource';
                   4791:                 } else {
                   4792:                     $timersymb = &Apache::lonnet::symbread($item);
                   4793:                 }
                   4794:                 my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
                   4795:                 my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb}; 
                   4796:                 if ($start && $end) {
                   4797:                     if (($start <= time) && ($end >= time)) {
                   4798:                         unless (grep(/^\Q$block\E$/,@blockers)) {
                   4799:                             push(@blockers,$block);
                   4800:                             $triggered{$block} = {
                   4801:                                                    start => $start,
                   4802:                                                    end   => $end,
                   4803:                                                    type  => $type,
                   4804:                                                  };
                   4805:                         }
                   4806:                     }
1.490     raeburn  4807:                 }
1.1062    raeburn  4808:             }
                   4809:         }
                   4810:     }
                   4811:     foreach my $blocker (@blockers) {
                   4812:         my ($staff_name,$staff_dom,$title,$blocks) =
                   4813:             &parse_block_record($commblocks{$blocker});
                   4814:         push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
                   4815:         my ($start,$end,$triggertype);
                   4816:         if ($blocker =~ m/^(\d+)____(\d+)$/) {
                   4817:             ($start,$end) = ($1,$2);
                   4818:         } elsif (ref($triggered{$blocker}) eq 'HASH') {
                   4819:             $start = $triggered{$blocker}{'start'};
                   4820:             $end = $triggered{$blocker}{'end'};
                   4821:             $triggertype = $triggered{$blocker}{'type'};
                   4822:         }
                   4823:         if ($start) {
                   4824:             push(@{$$setters{$course}{'times'}}, [$start,$end]);
                   4825:             if ($triggertype) {
                   4826:                 push(@{$$setters{$course}{'triggers'}},$triggertype);
                   4827:             } else {
                   4828:                 push(@{$$setters{$course}{'triggers'}},0);
                   4829:             }
                   4830:             if ( ($startblock == 0) || ($startblock > $start) ) {
                   4831:                 $startblock = $start;
                   4832:                 if ($triggertype) {
                   4833:                     $triggerblock = $blocker;
1.474     raeburn  4834:                 }
                   4835:             }
1.1062    raeburn  4836:             if ( ($endblock == 0) || ($endblock < $end) ) {
                   4837:                $endblock = $end;
                   4838:                if ($triggertype) {
                   4839:                    $triggerblock = $blocker;
                   4840:                }
                   4841:             }
1.474     raeburn  4842:         }
                   4843:     }
1.1062    raeburn  4844:     return ($startblock,$endblock,$triggerblock);
1.474     raeburn  4845: }
                   4846: 
                   4847: sub parse_block_record {
                   4848:     my ($record) = @_;
                   4849:     my ($setuname,$setudom,$title,$blocks);
                   4850:     if (ref($record) eq 'HASH') {
                   4851:         ($setuname,$setudom) = split(/:/,$record->{'setter'});
                   4852:         $title = &unescape($record->{'event'});
                   4853:         $blocks = $record->{'blocks'};
                   4854:     } else {
                   4855:         my @data = split(/:/,$record,3);
                   4856:         if (scalar(@data) eq 2) {
                   4857:             $title = $data[1];
                   4858:             ($setuname,$setudom) = split(/@/,$data[0]);
                   4859:         } else {
                   4860:             ($setuname,$setudom,$title) = @data;
                   4861:         }
                   4862:         $blocks = { 'com' => 'on' };
                   4863:     }
                   4864:     return ($setuname,$setudom,$title,$blocks);
                   4865: }
                   4866: 
1.854     kalberla 4867: sub blocking_status {
1.1075.2.73  raeburn  4868:     my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061    raeburn  4869:     my %setters;
1.890     droeschl 4870: 
1.1061    raeburn  4871: # check for active blocking
1.1062    raeburn  4872:     my ($startblock,$endblock,$triggerblock) = 
1.1075.2.73  raeburn  4873:         &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062    raeburn  4874:     my $blocked = 0;
                   4875:     if ($startblock && $endblock) {
                   4876:         $blocked = 1;
                   4877:     }
1.890     droeschl 4878: 
1.1061    raeburn  4879: # caller just wants to know whether a block is active
                   4880:     if (!wantarray) { return $blocked; }
                   4881: 
                   4882: # build a link to a popup window containing the details
                   4883:     my $querystring  = "?activity=$activity";
                   4884: # $uname and $udom decide whose portfolio the user is trying to look at
1.1075.2.97  raeburn  4885:     if (($activity eq 'port') || ($activity eq 'passwd')) {
                   4886:         $querystring .= "&amp;udom=$udom"      if ($udom =~ /^$match_domain$/);
                   4887:         $querystring .= "&amp;uname=$uname"    if ($uname =~ /^$match_username$/);
1.1062    raeburn  4888:     } elsif ($activity eq 'docs') {
                   4889:         $querystring .= '&amp;url='.&HTML::Entities::encode($url,'&"');
                   4890:     }
1.1061    raeburn  4891: 
                   4892:     my $output .= <<'END_MYBLOCK';
                   4893: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
                   4894:     var options = "width=" + w + ",height=" + h + ",";
                   4895:     options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
                   4896:     options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
                   4897:     var newWin = window.open(url, wdwName, options);
                   4898:     newWin.focus();
                   4899: }
1.890     droeschl 4900: END_MYBLOCK
1.854     kalberla 4901: 
1.1061    raeburn  4902:     $output = Apache::lonhtmlcommon::scripttag($output);
1.890     droeschl 4903:   
1.1061    raeburn  4904:     my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062    raeburn  4905:     my $text = &mt('Communication Blocked');
1.1075.2.93  raeburn  4906:     my $class = 'LC_comblock';
1.1062    raeburn  4907:     if ($activity eq 'docs') {
                   4908:         $text = &mt('Content Access Blocked');
1.1075.2.93  raeburn  4909:         $class = '';
1.1063    raeburn  4910:     } elsif ($activity eq 'printout') {
                   4911:         $text = &mt('Printing Blocked');
1.1075.2.97  raeburn  4912:     } elsif ($activity eq 'passwd') {
                   4913:         $text = &mt('Password Changing Blocked');
1.1062    raeburn  4914:     }
1.1061    raeburn  4915:     $output .= <<"END_BLOCK";
1.1075.2.93  raeburn  4916: <div class='$class'>
1.869     kalberla 4917:   <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890     droeschl 4918:   title='$text'>
                   4919:   <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869     kalberla 4920:   <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring' 
1.890     droeschl 4921:   title='$text'>$text</a>
1.867     kalberla 4922: </div>
                   4923: 
                   4924: END_BLOCK
1.474     raeburn  4925: 
1.1061    raeburn  4926:     return ($blocked, $output);
1.854     kalberla 4927: }
1.490     raeburn  4928: 
1.60      matthew  4929: ###############################################
                   4930: 
1.682     raeburn  4931: sub check_ip_acc {
1.1075.2.105  raeburn  4932:     my ($acc,$clientip)=@_;
1.682     raeburn  4933:     &Apache::lonxml::debug("acc is $acc");
                   4934:     if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
                   4935:         return 1;
                   4936:     }
                   4937:     my $allowed=0;
1.1075.2.111  raeburn  4938:     my $ip=$ENV{'REMOTE_ADDR'} || $clientip || $env{'request.host'};
1.682     raeburn  4939: 
                   4940:     my $name;
                   4941:     foreach my $pattern (split(',',$acc)) {
                   4942:         $pattern =~ s/^\s*//;
                   4943:         $pattern =~ s/\s*$//;
                   4944:         if ($pattern =~ /\*$/) {
                   4945:             #35.8.*
                   4946:             $pattern=~s/\*//;
                   4947:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   4948:         } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
                   4949:             #35.8.3.[34-56]
                   4950:             my $low=$2;
                   4951:             my $high=$3;
                   4952:             $pattern=$1;
                   4953:             if ($ip =~ /^\Q$pattern\E/) {
                   4954:                 my $last=(split(/\./,$ip))[3];
                   4955:                 if ($last <=$high && $last >=$low) { $allowed=1; }
                   4956:             }
                   4957:         } elsif ($pattern =~ /^\*/) {
                   4958:             #*.msu.edu
                   4959:             $pattern=~s/\*//;
                   4960:             if (!defined($name)) {
                   4961:                 use Socket;
                   4962:                 my $netaddr=inet_aton($ip);
                   4963:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   4964:             }
                   4965:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   4966:         } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
                   4967:             #127.0.0.1
                   4968:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   4969:         } else {
                   4970:             #some.name.com
                   4971:             if (!defined($name)) {
                   4972:                 use Socket;
                   4973:                 my $netaddr=inet_aton($ip);
                   4974:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   4975:             }
                   4976:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   4977:         }
                   4978:         if ($allowed) { last; }
                   4979:     }
                   4980:     return $allowed;
                   4981: }
                   4982: 
                   4983: ###############################################
                   4984: 
1.60      matthew  4985: =pod
                   4986: 
1.112     bowersj2 4987: =head1 Domain Template Functions
                   4988: 
                   4989: =over 4
                   4990: 
                   4991: =item * &determinedomain()
1.60      matthew  4992: 
                   4993: Inputs: $domain (usually will be undef)
                   4994: 
1.63      www      4995: Returns: Determines which domain should be used for designs
1.60      matthew  4996: 
                   4997: =cut
1.54      www      4998: 
1.60      matthew  4999: ###############################################
1.63      www      5000: sub determinedomain {
                   5001:     my $domain=shift;
1.531     albertel 5002:     if (! $domain) {
1.60      matthew  5003:         # Determine domain if we have not been given one
1.893     raeburn  5004:         $domain = &Apache::lonnet::default_login_domain();
1.258     albertel 5005:         if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
                   5006:         if ($env{'request.role.domain'}) { 
                   5007:             $domain=$env{'request.role.domain'}; 
1.60      matthew  5008:         }
                   5009:     }
1.63      www      5010:     return $domain;
                   5011: }
                   5012: ###############################################
1.517     raeburn  5013: 
1.518     albertel 5014: sub devalidate_domconfig_cache {
                   5015:     my ($udom)=@_;
                   5016:     &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
                   5017: }
                   5018: 
                   5019: # ---------------------- Get domain configuration for a domain
                   5020: sub get_domainconf {
                   5021:     my ($udom) = @_;
                   5022:     my $cachetime=1800;
                   5023:     my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
                   5024:     if (defined($cached)) { return %{$result}; }
                   5025: 
                   5026:     my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948     raeburn  5027: 					     ['login','rolecolors','autoenroll'],$udom);
1.632     raeburn  5028:     my (%designhash,%legacy);
1.518     albertel 5029:     if (keys(%domconfig) > 0) {
                   5030:         if (ref($domconfig{'login'}) eq 'HASH') {
1.632     raeburn  5031:             if (keys(%{$domconfig{'login'}})) {
                   5032:                 foreach my $key (keys(%{$domconfig{'login'}})) {
1.699     raeburn  5033:                     if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1075.2.87  raeburn  5034:                         if (($key eq 'loginvia') || ($key eq 'headtag')) {
                   5035:                             if (ref($domconfig{'login'}{$key}) eq 'HASH') {
                   5036:                                 foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
                   5037:                                     if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
                   5038:                                         if ($key eq 'loginvia') {
                   5039:                                             if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
                   5040:                                                 my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
                   5041:                                                 $designhash{$udom.'.login.loginvia'} = $server;
                   5042:                                                 if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
                   5043:                                                     $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
                   5044:                                                 } else {
                   5045:                                                     $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
                   5046:                                                 }
1.948     raeburn  5047:                                             }
1.1075.2.87  raeburn  5048:                                         } elsif ($key eq 'headtag') {
                   5049:                                             if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
                   5050:                                                 $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948     raeburn  5051:                                             }
1.946     raeburn  5052:                                         }
1.1075.2.87  raeburn  5053:                                         if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
                   5054:                                             $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
                   5055:                                         }
1.946     raeburn  5056:                                     }
                   5057:                                 }
                   5058:                             }
                   5059:                         } else {
                   5060:                             foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
                   5061:                                 $designhash{$udom.'.login.'.$key.'_'.$img} = 
                   5062:                                     $domconfig{'login'}{$key}{$img};
                   5063:                             }
1.699     raeburn  5064:                         }
                   5065:                     } else {
                   5066:                         $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
                   5067:                     }
1.632     raeburn  5068:                 }
                   5069:             } else {
                   5070:                 $legacy{'login'} = 1;
1.518     albertel 5071:             }
1.632     raeburn  5072:         } else {
                   5073:             $legacy{'login'} = 1;
1.518     albertel 5074:         }
                   5075:         if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632     raeburn  5076:             if (keys(%{$domconfig{'rolecolors'}})) {
                   5077:                 foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
                   5078:                     if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
                   5079:                         foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
                   5080:                             $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
                   5081:                         }
1.518     albertel 5082:                     }
                   5083:                 }
1.632     raeburn  5084:             } else {
                   5085:                 $legacy{'rolecolors'} = 1;
1.518     albertel 5086:             }
1.632     raeburn  5087:         } else {
                   5088:             $legacy{'rolecolors'} = 1;
1.518     albertel 5089:         }
1.948     raeburn  5090:         if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   5091:             if ($domconfig{'autoenroll'}{'co-owners'}) {
                   5092:                 $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
                   5093:             }
                   5094:         }
1.632     raeburn  5095:         if (keys(%legacy) > 0) {
                   5096:             my %legacyhash = &get_legacy_domconf($udom);
                   5097:             foreach my $item (keys(%legacyhash)) {
                   5098:                 if ($item =~ /^\Q$udom\E\.login/) {
                   5099:                     if ($legacy{'login'}) { 
                   5100:                         $designhash{$item} = $legacyhash{$item};
                   5101:                     }
                   5102:                 } else {
                   5103:                     if ($legacy{'rolecolors'}) {
                   5104:                         $designhash{$item} = $legacyhash{$item};
                   5105:                     }
1.518     albertel 5106:                 }
                   5107:             }
                   5108:         }
1.632     raeburn  5109:     } else {
                   5110:         %designhash = &get_legacy_domconf($udom); 
1.518     albertel 5111:     }
                   5112:     &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
                   5113: 				  $cachetime);
                   5114:     return %designhash;
                   5115: }
                   5116: 
1.632     raeburn  5117: sub get_legacy_domconf {
                   5118:     my ($udom) = @_;
                   5119:     my %legacyhash;
                   5120:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
                   5121:     my $designfile =  $designdir.'/'.$udom.'.tab';
                   5122:     if (-e $designfile) {
                   5123:         if ( open (my $fh,"<$designfile") ) {
                   5124:             while (my $line = <$fh>) {
                   5125:                 next if ($line =~ /^\#/);
                   5126:                 chomp($line);
                   5127:                 my ($key,$val)=(split(/\=/,$line));
                   5128:                 if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
                   5129:             }
                   5130:             close($fh);
                   5131:         }
                   5132:     }
1.1026    raeburn  5133:     if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632     raeburn  5134:         $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
                   5135:     }
                   5136:     return %legacyhash;
                   5137: }
                   5138: 
1.63      www      5139: =pod
                   5140: 
1.112     bowersj2 5141: =item * &domainlogo()
1.63      www      5142: 
                   5143: Inputs: $domain (usually will be undef)
                   5144: 
                   5145: Returns: A link to a domain logo, if the domain logo exists.
                   5146: If the domain logo does not exist, a description of the domain.
                   5147: 
                   5148: =cut
1.112     bowersj2 5149: 
1.63      www      5150: ###############################################
                   5151: sub domainlogo {
1.517     raeburn  5152:     my $domain = &determinedomain(shift);
1.518     albertel 5153:     my %designhash = &get_domainconf($domain);    
1.517     raeburn  5154:     # See if there is a logo
                   5155:     if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519     raeburn  5156:         my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538     albertel 5157:         if ($imgsrc =~ m{^/(adm|res)/}) {
                   5158: 	    if ($imgsrc =~ m{^/res/}) {
                   5159: 		my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
                   5160: 		&Apache::lonnet::repcopy($local_name);
                   5161: 	    }
                   5162: 	   $imgsrc = &lonhttpdurl($imgsrc);
1.519     raeburn  5163:         } 
                   5164:         return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514     albertel 5165:     } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
                   5166:         return &Apache::lonnet::domain($domain,'description');
1.59      www      5167:     } else {
1.60      matthew  5168:         return '';
1.59      www      5169:     }
                   5170: }
1.63      www      5171: ##############################################
                   5172: 
                   5173: =pod
                   5174: 
1.112     bowersj2 5175: =item * &designparm()
1.63      www      5176: 
                   5177: Inputs: $which parameter; $domain (usually will be undef)
                   5178: 
                   5179: Returns: value of designparamter $which
                   5180: 
                   5181: =cut
1.112     bowersj2 5182: 
1.397     albertel 5183: 
1.400     albertel 5184: ##############################################
1.397     albertel 5185: sub designparm {
                   5186:     my ($which,$domain)=@_;
                   5187:     if (exists($env{'environment.color.'.$which})) {
1.817     bisitz   5188:         return $env{'environment.color.'.$which};
1.96      www      5189:     }
1.63      www      5190:     $domain=&determinedomain($domain);
1.1016    raeburn  5191:     my %domdesign;
                   5192:     unless ($domain eq 'public') {
                   5193:         %domdesign = &get_domainconf($domain);
                   5194:     }
1.520     raeburn  5195:     my $output;
1.517     raeburn  5196:     if ($domdesign{$domain.'.'.$which} ne '') {
1.817     bisitz   5197:         $output = $domdesign{$domain.'.'.$which};
1.63      www      5198:     } else {
1.520     raeburn  5199:         $output = $defaultdesign{$which};
                   5200:     }
                   5201:     if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635     raeburn  5202:         ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538     albertel 5203:         if ($output =~ m{^/(adm|res)/}) {
1.817     bisitz   5204:             if ($output =~ m{^/res/}) {
                   5205:                 my $local_name = &Apache::lonnet::filelocation('',$output);
                   5206:                 &Apache::lonnet::repcopy($local_name);
                   5207:             }
1.520     raeburn  5208:             $output = &lonhttpdurl($output);
                   5209:         }
1.63      www      5210:     }
1.520     raeburn  5211:     return $output;
1.63      www      5212: }
1.59      www      5213: 
1.822     bisitz   5214: ##############################################
                   5215: =pod
                   5216: 
1.832     bisitz   5217: =item * &authorspace()
                   5218: 
1.1028    raeburn  5219: Inputs: $url (usually will be undef).
1.832     bisitz   5220: 
1.1075.2.40  raeburn  5221: Returns: Path to Authoring Space containing the resource or 
1.1028    raeburn  5222:          directory being viewed (or for which action is being taken). 
                   5223:          If $url is provided, and begins /priv/<domain>/<uname>
                   5224:          the path will be that portion of the $context argument.
                   5225:          Otherwise the path will be for the author space of the current
                   5226:          user when the current role is author, or for that of the 
                   5227:          co-author/assistant co-author space when the current role 
                   5228:          is co-author or assistant co-author.
1.832     bisitz   5229: 
                   5230: =cut
                   5231: 
                   5232: sub authorspace {
1.1028    raeburn  5233:     my ($url) = @_;
                   5234:     if ($url ne '') {
                   5235:         if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
                   5236:            return $1;
                   5237:         }
                   5238:     }
1.832     bisitz   5239:     my $caname = '';
1.1024    www      5240:     my $cadom = '';
1.1028    raeburn  5241:     if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024    www      5242:         ($cadom,$caname) =
1.832     bisitz   5243:             ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028    raeburn  5244:     } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832     bisitz   5245:         $caname = $env{'user.name'};
1.1024    www      5246:         $cadom = $env{'user.domain'};
1.832     bisitz   5247:     }
1.1028    raeburn  5248:     if (($caname ne '') && ($cadom ne '')) {
                   5249:         return "/priv/$cadom/$caname/";
                   5250:     }
                   5251:     return;
1.832     bisitz   5252: }
                   5253: 
                   5254: ##############################################
                   5255: =pod
                   5256: 
1.822     bisitz   5257: =item * &head_subbox()
                   5258: 
                   5259: Inputs: $content (contains HTML code with page functions, etc.)
                   5260: 
                   5261: Returns: HTML div with $content
                   5262:          To be included in page header
                   5263: 
                   5264: =cut
                   5265: 
                   5266: sub head_subbox {
                   5267:     my ($content)=@_;
                   5268:     my $output =
1.993     raeburn  5269:         '<div class="LC_head_subbox">'
1.822     bisitz   5270:        .$content
                   5271:        .'</div>'
                   5272: }
                   5273: 
                   5274: ##############################################
                   5275: =pod
                   5276: 
                   5277: =item * &CSTR_pageheader()
                   5278: 
1.1026    raeburn  5279: Input: (optional) filename from which breadcrumb trail is built.
                   5280:        In most cases no input as needed, as $env{'request.filename'}
                   5281:        is appropriate for use in building the breadcrumb trail.
1.822     bisitz   5282: 
                   5283: Returns: HTML div with CSTR path and recent box
1.1075.2.40  raeburn  5284:          To be included on Authoring Space pages
1.822     bisitz   5285: 
                   5286: =cut
                   5287: 
                   5288: sub CSTR_pageheader {
1.1026    raeburn  5289:     my ($trailfile) = @_;
                   5290:     if ($trailfile eq '') {
                   5291:         $trailfile = $env{'request.filename'};
                   5292:     }
                   5293: 
                   5294: # this is for resources; directories have customtitle, and crumbs
                   5295: # and select recent are created in lonpubdir.pm
                   5296: 
                   5297:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022    www      5298:     my ($udom,$uname,$thisdisfn)=
1.1075.2.29  raeburn  5299:         ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026    raeburn  5300:     my $formaction = "/priv/$udom/$uname/$thisdisfn";
                   5301:     $formaction =~ s{/+}{/}g;
1.822     bisitz   5302: 
                   5303:     my $parentpath = '';
                   5304:     my $lastitem = '';
                   5305:     if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
                   5306:         $parentpath = $1;
                   5307:         $lastitem = $2;
                   5308:     } else {
                   5309:         $lastitem = $thisdisfn;
                   5310:     }
1.921     bisitz   5311: 
                   5312:     my $output =
1.822     bisitz   5313:          '<div>'
                   5314:         .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40  raeburn  5315:         .'<b>'.&mt('Authoring Space:').'</b> '
1.822     bisitz   5316:         .'<form name="dirs" method="post" action="'.$formaction
1.921     bisitz   5317:         .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024    www      5318:         .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921     bisitz   5319: 
                   5320:     if ($lastitem) {
                   5321:         $output .=
                   5322:              '<span class="LC_filename">'
                   5323:             .$lastitem
                   5324:             .'</span>';
                   5325:     }
                   5326:     $output .=
                   5327:          '<br />'
1.822     bisitz   5328:         #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
                   5329:         .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
                   5330:         .'</form>'
                   5331:         .&Apache::lonmenu::constspaceform()
                   5332:         .'</div>';
1.921     bisitz   5333: 
                   5334:     return $output;
1.822     bisitz   5335: }
                   5336: 
1.60      matthew  5337: ###############################################
                   5338: ###############################################
                   5339: 
                   5340: =pod
                   5341: 
1.112     bowersj2 5342: =back
                   5343: 
1.549     albertel 5344: =head1 HTML Helpers
1.112     bowersj2 5345: 
                   5346: =over 4
                   5347: 
                   5348: =item * &bodytag()
1.60      matthew  5349: 
                   5350: Returns a uniform header for LON-CAPA web pages.
                   5351: 
                   5352: Inputs: 
                   5353: 
1.112     bowersj2 5354: =over 4
                   5355: 
                   5356: =item * $title, A title to be displayed on the page.
                   5357: 
                   5358: =item * $function, the current role (can be undef).
                   5359: 
                   5360: =item * $addentries, extra parameters for the <body> tag.
                   5361: 
                   5362: =item * $bodyonly, if defined, only return the <body> tag.
                   5363: 
                   5364: =item * $domain, if defined, force a given domain.
                   5365: 
                   5366: =item * $forcereg, if page should register as content page (relevant for 
1.86      www      5367:             text interface only)
1.60      matthew  5368: 
1.814     bisitz   5369: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
                   5370:                      navigational links
1.317     albertel 5371: 
1.338     albertel 5372: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
                   5373: 
1.1075.2.12  raeburn  5374: =item * $no_inline_link, if true and in remote mode, don't show the
                   5375:          'Switch To Inline Menu' link
                   5376: 
1.460     albertel 5377: =item * $args, optional argument valid values are
                   5378:             no_auto_mt_title -> prevents &mt()ing the title arg
                   5379: 
1.1075.2.15  raeburn  5380: =item * $advtoolsref, optional argument, ref to an array containing
                   5381:             inlineremote items to be added in "Functions" menu below
                   5382:             breadcrumbs.
                   5383: 
1.112     bowersj2 5384: =back
                   5385: 
1.60      matthew  5386: Returns: A uniform header for LON-CAPA web pages.  
                   5387: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
                   5388: If $bodyonly is undef or zero, an html string containing a <body> tag and 
                   5389: other decorations will be returned.
                   5390: 
                   5391: =cut
                   5392: 
1.54      www      5393: sub bodytag {
1.831     bisitz   5394:     my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.15  raeburn  5395:         $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
1.339     albertel 5396: 
1.954     raeburn  5397:     my $public;
                   5398:     if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
                   5399:         || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
                   5400:         $public = 1;
                   5401:     }
1.460     albertel 5402:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52  raeburn  5403:     my $httphost = $args->{'use_absolute'};
1.339     albertel 5404: 
1.183     matthew  5405:     $function = &get_users_function() if (!$function);
1.339     albertel 5406:     my $img =    &designparm($function.'.img',$domain);
                   5407:     my $font =   &designparm($function.'.font',$domain);
                   5408:     my $pgbg   = $bgcolor || &designparm($function.'.pgbg',$domain);
                   5409: 
1.803     bisitz   5410:     my %design = ( 'style'   => 'margin-top: 0',
1.535     albertel 5411: 		   'bgcolor' => $pgbg,
1.339     albertel 5412: 		   'text'    => $font,
                   5413:                    'alink'   => &designparm($function.'.alink',$domain),
                   5414: 		   'vlink'   => &designparm($function.'.vlink',$domain),
                   5415: 		   'link'    => &designparm($function.'.link',$domain),);
1.438     albertel 5416:     @design{keys(%$addentries)} = @$addentries{keys(%$addentries)}; 
1.339     albertel 5417: 
1.63      www      5418:  # role and realm
1.1075.2.68  raeburn  5419:     my ($role,$realm) = split(m{\./},$env{'request.role'},2);
                   5420:     if ($realm) {
                   5421:         $realm = '/'.$realm;
                   5422:     }
1.378     raeburn  5423:     if ($role  eq 'ca') {
1.479     albertel 5424:         my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500     albertel 5425:         $realm = &plainname($rname,$rdom);
1.378     raeburn  5426:     } 
1.55      www      5427: # realm
1.258     albertel 5428:     if ($env{'request.course.id'}) {
1.378     raeburn  5429:         if ($env{'request.role'} !~ /^cr/) {
                   5430:             $role = &Apache::lonnet::plaintext($role,&course_type());
1.1075.2.115  raeburn  5431:         } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
                   5432:             $role = &mt('Helpdesk[_1]','&nbsp;'.$2);
                   5433:         } else {
                   5434:             $role = (split(/\//,$role,4))[-1];
1.378     raeburn  5435:         }
1.898     raeburn  5436:         if ($env{'request.course.sec'}) {
                   5437:             $role .= ('&nbsp;'x2).'-&nbsp;'.&mt('section:').'&nbsp;'.$env{'request.course.sec'};
                   5438:         }   
1.359     albertel 5439: 	$realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378     raeburn  5440:     } else {
                   5441:         $role = &Apache::lonnet::plaintext($role);
1.54      www      5442:     }
1.433     albertel 5443: 
1.359     albertel 5444:     if (!$realm) { $realm='&nbsp;'; }
1.330     albertel 5445: 
1.438     albertel 5446:     my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329     albertel 5447: 
1.101     www      5448: # construct main body tag
1.359     albertel 5449:     my $bodytag = "<body $extra_body_attr>".
1.1075.2.100  raeburn  5450: 	&Apache::lontexconvert::init_math_support();
1.252     albertel 5451: 
1.1075.2.38  raeburn  5452:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   5453: 
                   5454:     if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60      matthew  5455:         return $bodytag;
1.1075.2.38  raeburn  5456:     }
1.359     albertel 5457: 
1.954     raeburn  5458:     if ($public) {
1.433     albertel 5459: 	undef($role);
                   5460:     }
1.359     albertel 5461:     
1.762     bisitz   5462:     my $titleinfo = '<h1>'.$title.'</h1>';
1.359     albertel 5463:     #
                   5464:     # Extra info if you are the DC
                   5465:     my $dc_info = '';
                   5466:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   5467:                         $env{'course.'.$env{'request.course.id'}.
                   5468:                                  '.domain'}.'/'})) {
                   5469:         my $cid = $env{'request.course.id'};
1.917     raeburn  5470:         $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380     www      5471:         $dc_info =~ s/\s+$//;
1.359     albertel 5472:     }
                   5473: 
1.1075.2.108  raeburn  5474:     $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.903     droeschl 5475: 
1.1075.2.13  raeburn  5476:     if ($env{'request.state'} eq 'construct') { $forcereg=1; }
                   5477: 
1.1075.2.38  raeburn  5478: 
                   5479: 
1.1075.2.21  raeburn  5480:     my $funclist;
                   5481:     if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52  raeburn  5482:         $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21  raeburn  5483:                     Apache::lonmenu::serverform();
                   5484:         my $forbodytag;
                   5485:         &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
                   5486:                                             $forcereg,$args->{'group'},
                   5487:                                             $args->{'bread_crumbs'},
                   5488:                                             $advtoolsref,'',\$forbodytag);
                   5489:         unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
                   5490:             $funclist = $forbodytag;
                   5491:         }
                   5492:     } else {
1.903     droeschl 5493: 
                   5494:         #    if ($env{'request.state'} eq 'construct') {
                   5495:         #        $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
                   5496:         #    }
                   5497: 
1.1075.2.38  raeburn  5498:         $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52  raeburn  5499:             Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359     albertel 5500: 
1.1075.2.38  raeburn  5501:         my ($left,$right) = Apache::lonmenu::primary_menu();
1.1075.2.2  raeburn  5502: 
1.916     droeschl 5503:         if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.22  raeburn  5504:             if ($dc_info) {
                   5505:                  $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
1.1075.2.1  raeburn  5506:             }
1.1075.2.38  raeburn  5507:             $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.1075.2.22  raeburn  5508:                            <em>$realm</em> $dc_info</div>|;
1.903     droeschl 5509:             return $bodytag;
                   5510:         }
1.894     droeschl 5511: 
1.927     raeburn  5512:         unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1075.2.38  raeburn  5513:             $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927     raeburn  5514:         }
1.916     droeschl 5515: 
1.1075.2.38  raeburn  5516:         $bodytag .= $right;
1.852     droeschl 5517: 
1.917     raeburn  5518:         if ($dc_info) {
                   5519:             $dc_info = &dc_courseid_toggle($dc_info);
                   5520:         }
                   5521:         $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916     droeschl 5522: 
1.1075.2.61  raeburn  5523:         #if directed to not display the secondary menu, don't.
                   5524:         if ($args->{'no_secondary_menu'}) {
                   5525:             return $bodytag;
                   5526:         }
1.903     droeschl 5527:         #don't show menus for public users
1.954     raeburn  5528:         if (!$public){
1.1075.2.52  raeburn  5529:             $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903     droeschl 5530:             $bodytag .= Apache::lonmenu::serverform();
1.920     raeburn  5531:             $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
                   5532:             if ($env{'request.state'} eq 'construct') {
1.962     droeschl 5533:                 $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920     raeburn  5534:                                 $args->{'bread_crumbs'});
1.1075.2.116! raeburn  5535:             } elsif ($forcereg) {
1.1075.2.22  raeburn  5536:                 $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1075.2.116! raeburn  5537:                                                             $args->{'group'},
        !          5538:                                                             $args->{'hide_buttons'});
1.1075.2.15  raeburn  5539:             } else {
1.1075.2.21  raeburn  5540:                 my $forbodytag;
                   5541:                 &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
                   5542:                                                     $forcereg,$args->{'group'},
                   5543:                                                     $args->{'bread_crumbs'},
                   5544:                                                     $advtoolsref,'',\$forbodytag);
                   5545:                 unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
                   5546:                     $bodytag .= $forbodytag;
                   5547:                 }
1.920     raeburn  5548:             }
1.903     droeschl 5549:         }else{
                   5550:             # this is to seperate menu from content when there's no secondary
                   5551:             # menu. Especially needed for public accessible ressources.
                   5552:             $bodytag .= '<hr style="clear:both" />';
                   5553:             $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end'); 
1.235     raeburn  5554:         }
1.903     droeschl 5555: 
1.235     raeburn  5556:         return $bodytag;
1.1075.2.12  raeburn  5557:     }
                   5558: 
                   5559: #
                   5560: # Top frame rendering, Remote is up
                   5561: #
                   5562: 
                   5563:     my $imgsrc = $img;
                   5564:     if ($img =~ /^\/adm/) {
                   5565:         $imgsrc = &lonhttpdurl($img);
                   5566:     }
                   5567:     my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
                   5568: 
1.1075.2.60  raeburn  5569:     my $help=($no_inline_link?''
                   5570:               :&Apache::loncommon::top_nav_help('Help'));
                   5571: 
1.1075.2.12  raeburn  5572:     # Explicit link to get inline menu
                   5573:     my $menu= ($no_inline_link?''
                   5574:                :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
                   5575: 
                   5576:     if ($dc_info) {
                   5577:         $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
                   5578:     }
                   5579: 
1.1075.2.38  raeburn  5580:     my $name = &plainname($env{'user.name'},$env{'user.domain'});
                   5581:     unless ($public) {
                   5582:         $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
                   5583:                                 undef,'LC_menubuttons_link');
                   5584:     }
                   5585: 
1.1075.2.12  raeburn  5586:     unless ($env{'form.inhibitmenu'}) {
                   5587:         $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38  raeburn  5588:                        <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.60  raeburn  5589:                        <li>$help</li>
1.1075.2.12  raeburn  5590:                        <li>$menu</li>
                   5591:                        </ol><div id="LC_realm"> $realm $dc_info</div>|;
                   5592:     }
1.1075.2.13  raeburn  5593:     if ($env{'request.state'} eq 'construct') {
                   5594:         if (!$public){
                   5595:             if ($env{'request.state'} eq 'construct') {
                   5596:                 $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52  raeburn  5597:                                 &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13  raeburn  5598:                             &Apache::lonhtmlcommon::scripttag('','end').
                   5599:                             &Apache::lonmenu::innerregister($forcereg,
                   5600:                                                             $args->{'bread_crumbs'});
                   5601:             }
                   5602:         }
                   5603:     }
1.1075.2.21  raeburn  5604:     return $bodytag."\n".$funclist;
1.182     matthew  5605: }
                   5606: 
1.917     raeburn  5607: sub dc_courseid_toggle {
                   5608:     my ($dc_info) = @_;
1.980     raeburn  5609:     return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069    raeburn  5610:            '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917     raeburn  5611:            &mt('(More ...)').'</a></span>'.
                   5612:            '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
                   5613: }
                   5614: 
1.330     albertel 5615: sub make_attr_string {
                   5616:     my ($register,$attr_ref) = @_;
                   5617: 
                   5618:     if ($attr_ref && !ref($attr_ref)) {
                   5619: 	die("addentries Must be a hash ref ".
                   5620: 	    join(':',caller(1))." ".
                   5621: 	    join(':',caller(0))." ");
                   5622:     }
                   5623: 
                   5624:     if ($register) {
1.339     albertel 5625: 	my ($on_load,$on_unload);
                   5626: 	foreach my $key (keys(%{$attr_ref})) {
                   5627: 	    if      (lc($key) eq 'onload') {
                   5628: 		$on_load.=$attr_ref->{$key}.';';
                   5629: 		delete($attr_ref->{$key});
                   5630: 
                   5631: 	    } elsif (lc($key) eq 'onunload') {
                   5632: 		$on_unload.=$attr_ref->{$key}.';';
                   5633: 		delete($attr_ref->{$key});
                   5634: 	    }
                   5635: 	}
1.1075.2.12  raeburn  5636:         if ($env{'environment.remote'} eq 'on') {
                   5637:             $attr_ref->{'onload'}  =
                   5638:                 &Apache::lonmenu::loadevents().  $on_load;
                   5639:             $attr_ref->{'onunload'}=
                   5640:                 &Apache::lonmenu::unloadevents().$on_unload;
                   5641:         } else {  
                   5642: 	    $attr_ref->{'onload'}  = $on_load;
                   5643: 	    $attr_ref->{'onunload'}= $on_unload;
                   5644:         }
1.330     albertel 5645:     }
1.339     albertel 5646: 
1.330     albertel 5647:     my $attr_string;
1.1075.2.56  raeburn  5648:     foreach my $attr (sort(keys(%$attr_ref))) {
1.330     albertel 5649: 	$attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
                   5650:     }
                   5651:     return $attr_string;
                   5652: }
                   5653: 
                   5654: 
1.182     matthew  5655: ###############################################
1.251     albertel 5656: ###############################################
                   5657: 
                   5658: =pod
                   5659: 
                   5660: =item * &endbodytag()
                   5661: 
                   5662: Returns a uniform footer for LON-CAPA web pages.
                   5663: 
1.635     raeburn  5664: Inputs: 1 - optional reference to an args hash
                   5665: If in the hash, key for noredirectlink has a value which evaluates to true,
                   5666: a 'Continue' link is not displayed if the page contains an
                   5667: internal redirect in the <head></head> section,
                   5668: i.e., $env{'internal.head.redirect'} exists   
1.251     albertel 5669: 
                   5670: =cut
                   5671: 
                   5672: sub endbodytag {
1.635     raeburn  5673:     my ($args) = @_;
1.1075.2.6  raeburn  5674:     my $endbodytag;
                   5675:     unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
                   5676:         $endbodytag='</body>';
                   5677:     }
1.315     albertel 5678:     if ( exists( $env{'internal.head.redirect'} ) ) {
1.635     raeburn  5679:         if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
                   5680: 	    $endbodytag=
                   5681: 	        "<br /><a href=\"$env{'internal.head.redirect'}\">".
                   5682: 	        &mt('Continue').'</a>'.
                   5683: 	        $endbodytag;
                   5684:         }
1.315     albertel 5685:     }
1.251     albertel 5686:     return $endbodytag;
                   5687: }
                   5688: 
1.352     albertel 5689: =pod
                   5690: 
                   5691: =item * &standard_css()
                   5692: 
                   5693: Returns a style sheet
                   5694: 
                   5695: Inputs: (all optional)
                   5696:             domain         -> force to color decorate a page for a specific
                   5697:                                domain
                   5698:             function       -> force usage of a specific rolish color scheme
                   5699:             bgcolor        -> override the default page bgcolor
                   5700: 
                   5701: =cut
                   5702: 
1.343     albertel 5703: sub standard_css {
1.345     albertel 5704:     my ($function,$domain,$bgcolor) = @_;
1.352     albertel 5705:     $function  = &get_users_function() if (!$function);
                   5706:     my $img    = &designparm($function.'.img',   $domain);
                   5707:     my $tabbg  = &designparm($function.'.tabbg', $domain);
                   5708:     my $font   = &designparm($function.'.font',  $domain);
1.801     tempelho 5709:     my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791     tempelho 5710: #second colour for later usage
1.345     albertel 5711:     my $sidebg = &designparm($function.'.sidebg',$domain);
1.382     albertel 5712:     my $pgbg_or_bgcolor =
                   5713: 	         $bgcolor ||
1.352     albertel 5714: 	         &designparm($function.'.pgbg',  $domain);
1.382     albertel 5715:     my $pgbg   = &designparm($function.'.pgbg',  $domain);
1.352     albertel 5716:     my $alink  = &designparm($function.'.alink', $domain);
                   5717:     my $vlink  = &designparm($function.'.vlink', $domain);
                   5718:     my $link   = &designparm($function.'.link',  $domain);
                   5719: 
1.602     albertel 5720:     my $sans                 = 'Verdana,Arial,Helvetica,sans-serif';
1.395     albertel 5721:     my $mono                 = 'monospace';
1.850     bisitz   5722:     my $data_table_head      = $sidebg;
                   5723:     my $data_table_light     = '#FAFAFA';
1.1060    bisitz   5724:     my $data_table_dark      = '#E0E0E0';
1.470     banghart 5725:     my $data_table_darker    = '#CCCCCC';
1.349     albertel 5726:     my $data_table_highlight = '#FFFF00';
1.352     albertel 5727:     my $mail_new             = '#FFBB77';
                   5728:     my $mail_new_hover       = '#DD9955';
                   5729:     my $mail_read            = '#BBBB77';
                   5730:     my $mail_read_hover      = '#999944';
                   5731:     my $mail_replied         = '#AAAA88';
                   5732:     my $mail_replied_hover   = '#888855';
                   5733:     my $mail_other           = '#99BBBB';
                   5734:     my $mail_other_hover     = '#669999';
1.391     albertel 5735:     my $table_header         = '#DDDDDD';
1.489     raeburn  5736:     my $feedback_link_bg     = '#BBBBBB';
1.911     bisitz   5737:     my $lg_border_color      = '#C8C8C8';
1.952     onken    5738:     my $button_hover         = '#BF2317';
1.392     albertel 5739: 
1.608     albertel 5740:     my $border = ($env{'browser.type'} eq 'explorer' ||
1.911     bisitz   5741:       $env{'browser.type'} eq 'safari'     ) ? '0 2px 0 2px'
                   5742:                                              : '0 3px 0 4px';
1.448     albertel 5743: 
1.523     albertel 5744: 
1.343     albertel 5745:     return <<END;
1.947     droeschl 5746: 
                   5747: /* needed for iframe to allow 100% height in FF */
                   5748: body, html { 
                   5749:     margin: 0;
                   5750:     padding: 0 0.5%;
                   5751:     height: 99%; /* to avoid scrollbars */
                   5752: }
                   5753: 
1.795     www      5754: body {
1.911     bisitz   5755:   font-family: $sans;
                   5756:   line-height:130%;
                   5757:   font-size:0.83em;
                   5758:   color:$font;
1.795     www      5759: }
                   5760: 
1.959     onken    5761: a:focus,
                   5762: a:focus img {
1.795     www      5763:   color: red;
                   5764: }
1.698     harmsja  5765: 
1.911     bisitz   5766: form, .inline {
                   5767:   display: inline;
1.795     www      5768: }
1.721     harmsja  5769: 
1.795     www      5770: .LC_right {
1.911     bisitz   5771:   text-align:right;
1.795     www      5772: }
                   5773: 
                   5774: .LC_middle {
1.911     bisitz   5775:   vertical-align:middle;
1.795     www      5776: }
1.721     harmsja  5777: 
1.1075.2.38  raeburn  5778: .LC_floatleft {
                   5779:   float: left;
                   5780: }
                   5781: 
                   5782: .LC_floatright {
                   5783:   float: right;
                   5784: }
                   5785: 
1.911     bisitz   5786: .LC_400Box {
                   5787:   width:400px;
                   5788: }
1.721     harmsja  5789: 
1.947     droeschl 5790: .LC_iframecontainer {
                   5791:     width: 98%;
                   5792:     margin: 0;
                   5793:     position: fixed;
                   5794:     top: 8.5em;
                   5795:     bottom: 0;
                   5796: }
                   5797: 
                   5798: .LC_iframecontainer iframe{
                   5799:     border: none;
                   5800:     width: 100%;
                   5801:     height: 100%;
                   5802: }
                   5803: 
1.778     bisitz   5804: .LC_filename {
                   5805:   font-family: $mono;
                   5806:   white-space:pre;
1.921     bisitz   5807:   font-size: 120%;
1.778     bisitz   5808: }
                   5809: 
                   5810: .LC_fileicon {
                   5811:   border: none;
                   5812:   height: 1.3em;
                   5813:   vertical-align: text-bottom;
                   5814:   margin-right: 0.3em;
                   5815:   text-decoration:none;
                   5816: }
                   5817: 
1.1008    www      5818: .LC_setting {
                   5819:   text-decoration:underline;
                   5820: }
                   5821: 
1.350     albertel 5822: .LC_error {
                   5823:   color: red;
                   5824: }
1.795     www      5825: 
1.1075.2.15  raeburn  5826: .LC_warning {
                   5827:   color: darkorange;
                   5828: }
                   5829: 
1.457     albertel 5830: .LC_diff_removed {
1.733     bisitz   5831:   color: red;
1.394     albertel 5832: }
1.532     albertel 5833: 
                   5834: .LC_info,
1.457     albertel 5835: .LC_success,
                   5836: .LC_diff_added {
1.350     albertel 5837:   color: green;
                   5838: }
1.795     www      5839: 
1.802     bisitz   5840: div.LC_confirm_box {
                   5841:   background-color: #FAFAFA;
                   5842:   border: 1px solid $lg_border_color;
                   5843:   margin-right: 0;
                   5844:   padding: 5px;
                   5845: }
                   5846: 
                   5847: div.LC_confirm_box .LC_error img,
                   5848: div.LC_confirm_box .LC_success img {
                   5849:   vertical-align: middle;
                   5850: }
                   5851: 
1.1075.2.108  raeburn  5852: .LC_maxwidth {
                   5853:   max-width: 100%;
                   5854:   height: auto;
                   5855: }
                   5856: 
                   5857: .LC_textsize_mobile {
                   5858:   \@media only screen and (max-device-width: 480px) {
                   5859:       -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
                   5860:   }
                   5861: }
                   5862: 
1.440     albertel 5863: .LC_icon {
1.771     droeschl 5864:   border: none;
1.790     droeschl 5865:   vertical-align: middle;
1.771     droeschl 5866: }
                   5867: 
1.543     albertel 5868: .LC_docs_spacer {
                   5869:   width: 25px;
                   5870:   height: 1px;
1.771     droeschl 5871:   border: none;
1.543     albertel 5872: }
1.346     albertel 5873: 
1.532     albertel 5874: .LC_internal_info {
1.735     bisitz   5875:   color: #999999;
1.532     albertel 5876: }
                   5877: 
1.794     www      5878: .LC_discussion {
1.1050    www      5879:   background: $data_table_dark;
1.911     bisitz   5880:   border: 1px solid black;
                   5881:   margin: 2px;
1.794     www      5882: }
                   5883: 
                   5884: .LC_disc_action_left {
1.1050    www      5885:   background: $sidebg;
1.911     bisitz   5886:   text-align: left;
1.1050    www      5887:   padding: 4px;
                   5888:   margin: 2px;
1.794     www      5889: }
                   5890: 
                   5891: .LC_disc_action_right {
1.1050    www      5892:   background: $sidebg;
1.911     bisitz   5893:   text-align: right;
1.1050    www      5894:   padding: 4px;
                   5895:   margin: 2px;
1.794     www      5896: }
                   5897: 
                   5898: .LC_disc_new_item {
1.911     bisitz   5899:   background: white;
                   5900:   border: 2px solid red;
1.1050    www      5901:   margin: 4px;
                   5902:   padding: 4px;
1.794     www      5903: }
                   5904: 
                   5905: .LC_disc_old_item {
1.911     bisitz   5906:   background: white;
1.1050    www      5907:   margin: 4px;
                   5908:   padding: 4px;
1.794     www      5909: }
                   5910: 
1.458     albertel 5911: table.LC_pastsubmission {
                   5912:   border: 1px solid black;
                   5913:   margin: 2px;
                   5914: }
                   5915: 
1.924     bisitz   5916: table#LC_menubuttons {
1.345     albertel 5917:   width: 100%;
                   5918:   background: $pgbg;
1.392     albertel 5919:   border: 2px;
1.402     albertel 5920:   border-collapse: separate;
1.803     bisitz   5921:   padding: 0;
1.345     albertel 5922: }
1.392     albertel 5923: 
1.801     tempelho 5924: table#LC_title_bar a {
                   5925:   color: $fontmenu;
                   5926: }
1.836     bisitz   5927: 
1.807     droeschl 5928: table#LC_title_bar {
1.819     tempelho 5929:   clear: both;
1.836     bisitz   5930:   display: none;
1.807     droeschl 5931: }
                   5932: 
1.795     www      5933: table#LC_title_bar,
1.933     droeschl 5934: table.LC_breadcrumbs, /* obsolete? */
1.393     albertel 5935: table#LC_title_bar.LC_with_remote {
1.359     albertel 5936:   width: 100%;
1.392     albertel 5937:   border-color: $pgbg;
                   5938:   border-style: solid;
                   5939:   border-width: $border;
1.379     albertel 5940:   background: $pgbg;
1.801     tempelho 5941:   color: $fontmenu;
1.392     albertel 5942:   border-collapse: collapse;
1.803     bisitz   5943:   padding: 0;
1.819     tempelho 5944:   margin: 0;
1.359     albertel 5945: }
1.795     www      5946: 
1.933     droeschl 5947: ul.LC_breadcrumb_tools_outerlist {
1.913     droeschl 5948:     margin: 0;
                   5949:     padding: 0;
1.933     droeschl 5950:     position: relative;
                   5951:     list-style: none;
1.913     droeschl 5952: }
1.933     droeschl 5953: ul.LC_breadcrumb_tools_outerlist li {
1.913     droeschl 5954:     display: inline;
                   5955: }
1.933     droeschl 5956: 
                   5957: .LC_breadcrumb_tools_navigation {
1.913     droeschl 5958:     padding: 0;
1.933     droeschl 5959:     margin: 0;
                   5960:     float: left;
1.913     droeschl 5961: }
1.933     droeschl 5962: .LC_breadcrumb_tools_tools {
                   5963:     padding: 0;
                   5964:     margin: 0;
1.913     droeschl 5965:     float: right;
                   5966: }
                   5967: 
1.359     albertel 5968: table#LC_title_bar td {
                   5969:   background: $tabbg;
                   5970: }
1.795     www      5971: 
1.911     bisitz   5972: table#LC_menubuttons img {
1.803     bisitz   5973:   border: none;
1.346     albertel 5974: }
1.795     www      5975: 
1.842     droeschl 5976: .LC_breadcrumbs_component {
1.911     bisitz   5977:   float: right;
                   5978:   margin: 0 1em;
1.357     albertel 5979: }
1.842     droeschl 5980: .LC_breadcrumbs_component img {
1.911     bisitz   5981:   vertical-align: middle;
1.777     tempelho 5982: }
1.795     www      5983: 
1.1075.2.108  raeburn  5984: .LC_breadcrumbs_hoverable {
                   5985:   background: $sidebg;
                   5986: }
                   5987: 
1.383     albertel 5988: td.LC_table_cell_checkbox {
                   5989:   text-align: center;
                   5990: }
1.795     www      5991: 
                   5992: .LC_fontsize_small {
1.911     bisitz   5993:   font-size: 70%;
1.705     tempelho 5994: }
                   5995: 
1.844     bisitz   5996: #LC_breadcrumbs {
1.911     bisitz   5997:   clear:both;
                   5998:   background: $sidebg;
                   5999:   border-bottom: 1px solid $lg_border_color;
                   6000:   line-height: 2.5em;
1.933     droeschl 6001:   overflow: hidden;
1.911     bisitz   6002:   margin: 0;
                   6003:   padding: 0;
1.995     raeburn  6004:   text-align: left;
1.819     tempelho 6005: }
1.862     bisitz   6006: 
1.1075.2.16  raeburn  6007: .LC_head_subbox, .LC_actionbox {
1.911     bisitz   6008:   clear:both;
                   6009:   background: #F8F8F8; /* $sidebg; */
1.915     droeschl 6010:   border: 1px solid $sidebg;
1.1075.2.16  raeburn  6011:   margin: 0 0 10px 0;
1.966     bisitz   6012:   padding: 3px;
1.995     raeburn  6013:   text-align: left;
1.822     bisitz   6014: }
                   6015: 
1.795     www      6016: .LC_fontsize_medium {
1.911     bisitz   6017:   font-size: 85%;
1.705     tempelho 6018: }
                   6019: 
1.795     www      6020: .LC_fontsize_large {
1.911     bisitz   6021:   font-size: 120%;
1.705     tempelho 6022: }
                   6023: 
1.346     albertel 6024: .LC_menubuttons_inline_text {
                   6025:   color: $font;
1.698     harmsja  6026:   font-size: 90%;
1.701     harmsja  6027:   padding-left:3px;
1.346     albertel 6028: }
                   6029: 
1.934     droeschl 6030: .LC_menubuttons_inline_text img{
                   6031:   vertical-align: middle;
                   6032: }
                   6033: 
1.1051    www      6034: li.LC_menubuttons_inline_text img {
1.951     onken    6035:   cursor:pointer;
1.1002    droeschl 6036:   text-decoration: none;
1.951     onken    6037: }
                   6038: 
1.526     www      6039: .LC_menubuttons_link {
                   6040:   text-decoration: none;
                   6041: }
1.795     www      6042: 
1.522     albertel 6043: .LC_menubuttons_category {
1.521     www      6044:   color: $font;
1.526     www      6045:   background: $pgbg;
1.521     www      6046:   font-size: larger;
                   6047:   font-weight: bold;
                   6048: }
                   6049: 
1.346     albertel 6050: td.LC_menubuttons_text {
1.911     bisitz   6051:   color: $font;
1.346     albertel 6052: }
1.706     harmsja  6053: 
1.346     albertel 6054: .LC_current_location {
                   6055:   background: $tabbg;
                   6056: }
1.795     www      6057: 
1.938     bisitz   6058: table.LC_data_table {
1.347     albertel 6059:   border: 1px solid #000000;
1.402     albertel 6060:   border-collapse: separate;
1.426     albertel 6061:   border-spacing: 1px;
1.610     albertel 6062:   background: $pgbg;
1.347     albertel 6063: }
1.795     www      6064: 
1.422     albertel 6065: .LC_data_table_dense {
                   6066:   font-size: small;
                   6067: }
1.795     www      6068: 
1.507     raeburn  6069: table.LC_nested_outer {
                   6070:   border: 1px solid #000000;
1.589     raeburn  6071:   border-collapse: collapse;
1.803     bisitz   6072:   border-spacing: 0;
1.507     raeburn  6073:   width: 100%;
                   6074: }
1.795     www      6075: 
1.879     raeburn  6076: table.LC_innerpickbox,
1.507     raeburn  6077: table.LC_nested {
1.803     bisitz   6078:   border: none;
1.589     raeburn  6079:   border-collapse: collapse;
1.803     bisitz   6080:   border-spacing: 0;
1.507     raeburn  6081:   width: 100%;
                   6082: }
1.795     www      6083: 
1.911     bisitz   6084: table.LC_data_table tr th,
                   6085: table.LC_calendar tr th,
1.879     raeburn  6086: table.LC_prior_tries tr th,
                   6087: table.LC_innerpickbox tr th {
1.349     albertel 6088:   font-weight: bold;
                   6089:   background-color: $data_table_head;
1.801     tempelho 6090:   color:$fontmenu;
1.701     harmsja  6091:   font-size:90%;
1.347     albertel 6092: }
1.795     www      6093: 
1.879     raeburn  6094: table.LC_innerpickbox tr th,
                   6095: table.LC_innerpickbox tr td {
                   6096:   vertical-align: top;
                   6097: }
                   6098: 
1.711     raeburn  6099: table.LC_data_table tr.LC_info_row > td {
1.735     bisitz   6100:   background-color: #CCCCCC;
1.711     raeburn  6101:   font-weight: bold;
                   6102:   text-align: left;
                   6103: }
1.795     www      6104: 
1.912     bisitz   6105: table.LC_data_table tr.LC_odd_row > td {
                   6106:   background-color: $data_table_light;
                   6107:   padding: 2px;
                   6108:   vertical-align: top;
                   6109: }
                   6110: 
1.809     bisitz   6111: table.LC_pick_box tr > td.LC_odd_row {
1.349     albertel 6112:   background-color: $data_table_light;
1.912     bisitz   6113:   vertical-align: top;
                   6114: }
                   6115: 
                   6116: table.LC_data_table tr.LC_even_row > td {
                   6117:   background-color: $data_table_dark;
1.425     albertel 6118:   padding: 2px;
1.900     bisitz   6119:   vertical-align: top;
1.347     albertel 6120: }
1.795     www      6121: 
1.809     bisitz   6122: table.LC_pick_box tr > td.LC_even_row {
1.349     albertel 6123:   background-color: $data_table_dark;
1.900     bisitz   6124:   vertical-align: top;
1.347     albertel 6125: }
1.795     www      6126: 
1.425     albertel 6127: table.LC_data_table tr.LC_data_table_highlight td {
                   6128:   background-color: $data_table_darker;
                   6129: }
1.795     www      6130: 
1.639     raeburn  6131: table.LC_data_table tr td.LC_leftcol_header {
                   6132:   background-color: $data_table_head;
                   6133:   font-weight: bold;
                   6134: }
1.795     www      6135: 
1.451     albertel 6136: table.LC_data_table tr.LC_empty_row td,
1.507     raeburn  6137: table.LC_nested tr.LC_empty_row td {
1.421     albertel 6138:   font-weight: bold;
                   6139:   font-style: italic;
                   6140:   text-align: center;
                   6141:   padding: 8px;
1.347     albertel 6142: }
1.795     www      6143: 
1.1075.2.30  raeburn  6144: table.LC_data_table tr.LC_empty_row td,
                   6145: table.LC_data_table tr.LC_footer_row td {
1.940     bisitz   6146:   background-color: $sidebg;
                   6147: }
                   6148: 
                   6149: table.LC_nested tr.LC_empty_row td {
                   6150:   background-color: #FFFFFF;
                   6151: }
                   6152: 
1.890     droeschl 6153: table.LC_caption {
                   6154: }
                   6155: 
1.507     raeburn  6156: table.LC_nested tr.LC_empty_row td {
1.465     albertel 6157:   padding: 4ex
                   6158: }
1.795     www      6159: 
1.507     raeburn  6160: table.LC_nested_outer tr th {
                   6161:   font-weight: bold;
1.801     tempelho 6162:   color:$fontmenu;
1.507     raeburn  6163:   background-color: $data_table_head;
1.701     harmsja  6164:   font-size: small;
1.507     raeburn  6165:   border-bottom: 1px solid #000000;
                   6166: }
1.795     www      6167: 
1.507     raeburn  6168: table.LC_nested_outer tr td.LC_subheader {
                   6169:   background-color: $data_table_head;
                   6170:   font-weight: bold;
                   6171:   font-size: small;
                   6172:   border-bottom: 1px solid #000000;
                   6173:   text-align: right;
1.451     albertel 6174: }
1.795     www      6175: 
1.507     raeburn  6176: table.LC_nested tr.LC_info_row td {
1.735     bisitz   6177:   background-color: #CCCCCC;
1.451     albertel 6178:   font-weight: bold;
                   6179:   font-size: small;
1.507     raeburn  6180:   text-align: center;
                   6181: }
1.795     www      6182: 
1.589     raeburn  6183: table.LC_nested tr.LC_info_row td.LC_left_item,
                   6184: table.LC_nested_outer tr th.LC_left_item {
1.507     raeburn  6185:   text-align: left;
1.451     albertel 6186: }
1.795     www      6187: 
1.507     raeburn  6188: table.LC_nested td {
1.735     bisitz   6189:   background-color: #FFFFFF;
1.451     albertel 6190:   font-size: small;
1.507     raeburn  6191: }
1.795     www      6192: 
1.507     raeburn  6193: table.LC_nested_outer tr th.LC_right_item,
                   6194: table.LC_nested tr.LC_info_row td.LC_right_item,
                   6195: table.LC_nested tr.LC_odd_row td.LC_right_item,
                   6196: table.LC_nested tr td.LC_right_item {
1.451     albertel 6197:   text-align: right;
                   6198: }
                   6199: 
1.507     raeburn  6200: table.LC_nested tr.LC_odd_row td {
1.735     bisitz   6201:   background-color: #EEEEEE;
1.451     albertel 6202: }
                   6203: 
1.473     raeburn  6204: table.LC_createuser {
                   6205: }
                   6206: 
                   6207: table.LC_createuser tr.LC_section_row td {
1.701     harmsja  6208:   font-size: small;
1.473     raeburn  6209: }
                   6210: 
                   6211: table.LC_createuser tr.LC_info_row td  {
1.735     bisitz   6212:   background-color: #CCCCCC;
1.473     raeburn  6213:   font-weight: bold;
                   6214:   text-align: center;
                   6215: }
                   6216: 
1.349     albertel 6217: table.LC_calendar {
                   6218:   border: 1px solid #000000;
                   6219:   border-collapse: collapse;
1.917     raeburn  6220:   width: 98%;
1.349     albertel 6221: }
1.795     www      6222: 
1.349     albertel 6223: table.LC_calendar_pickdate {
                   6224:   font-size: xx-small;
                   6225: }
1.795     www      6226: 
1.349     albertel 6227: table.LC_calendar tr td {
                   6228:   border: 1px solid #000000;
                   6229:   vertical-align: top;
1.917     raeburn  6230:   width: 14%;
1.349     albertel 6231: }
1.795     www      6232: 
1.349     albertel 6233: table.LC_calendar tr td.LC_calendar_day_empty {
                   6234:   background-color: $data_table_dark;
                   6235: }
1.795     www      6236: 
1.779     bisitz   6237: table.LC_calendar tr td.LC_calendar_day_current {
                   6238:   background-color: $data_table_highlight;
1.777     tempelho 6239: }
1.795     www      6240: 
1.938     bisitz   6241: table.LC_data_table tr td.LC_mail_new {
1.349     albertel 6242:   background-color: $mail_new;
                   6243: }
1.795     www      6244: 
1.938     bisitz   6245: table.LC_data_table tr.LC_mail_new:hover {
1.349     albertel 6246:   background-color: $mail_new_hover;
                   6247: }
1.795     www      6248: 
1.938     bisitz   6249: table.LC_data_table tr td.LC_mail_read {
1.349     albertel 6250:   background-color: $mail_read;
                   6251: }
1.795     www      6252: 
1.938     bisitz   6253: /*
                   6254: table.LC_data_table tr.LC_mail_read:hover {
1.349     albertel 6255:   background-color: $mail_read_hover;
                   6256: }
1.938     bisitz   6257: */
1.795     www      6258: 
1.938     bisitz   6259: table.LC_data_table tr td.LC_mail_replied {
1.349     albertel 6260:   background-color: $mail_replied;
                   6261: }
1.795     www      6262: 
1.938     bisitz   6263: /*
                   6264: table.LC_data_table tr.LC_mail_replied:hover {
1.349     albertel 6265:   background-color: $mail_replied_hover;
                   6266: }
1.938     bisitz   6267: */
1.795     www      6268: 
1.938     bisitz   6269: table.LC_data_table tr td.LC_mail_other {
1.349     albertel 6270:   background-color: $mail_other;
                   6271: }
1.795     www      6272: 
1.938     bisitz   6273: /*
                   6274: table.LC_data_table tr.LC_mail_other:hover {
1.349     albertel 6275:   background-color: $mail_other_hover;
                   6276: }
1.938     bisitz   6277: */
1.494     raeburn  6278: 
1.777     tempelho 6279: table.LC_data_table tr > td.LC_browser_file,
                   6280: table.LC_data_table tr > td.LC_browser_file_published {
1.899     bisitz   6281:   background: #AAEE77;
1.389     albertel 6282: }
1.795     www      6283: 
1.777     tempelho 6284: table.LC_data_table tr > td.LC_browser_file_locked,
                   6285: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389     albertel 6286:   background: #FFAA99;
1.387     albertel 6287: }
1.795     www      6288: 
1.777     tempelho 6289: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899     bisitz   6290:   background: #888888;
1.779     bisitz   6291: }
1.795     www      6292: 
1.777     tempelho 6293: table.LC_data_table tr > td.LC_browser_file_modified,
1.779     bisitz   6294: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899     bisitz   6295:   background: #F8F866;
1.777     tempelho 6296: }
1.795     www      6297: 
1.696     bisitz   6298: table.LC_data_table tr.LC_browser_folder > td {
1.899     bisitz   6299:   background: #E0E8FF;
1.387     albertel 6300: }
1.696     bisitz   6301: 
1.707     bisitz   6302: table.LC_data_table tr > td.LC_roles_is {
1.911     bisitz   6303:   /* background: #77FF77; */
1.707     bisitz   6304: }
1.795     www      6305: 
1.707     bisitz   6306: table.LC_data_table tr > td.LC_roles_future {
1.939     bisitz   6307:   border-right: 8px solid #FFFF77;
1.707     bisitz   6308: }
1.795     www      6309: 
1.707     bisitz   6310: table.LC_data_table tr > td.LC_roles_will {
1.939     bisitz   6311:   border-right: 8px solid #FFAA77;
1.707     bisitz   6312: }
1.795     www      6313: 
1.707     bisitz   6314: table.LC_data_table tr > td.LC_roles_expired {
1.939     bisitz   6315:   border-right: 8px solid #FF7777;
1.707     bisitz   6316: }
1.795     www      6317: 
1.707     bisitz   6318: table.LC_data_table tr > td.LC_roles_will_not {
1.939     bisitz   6319:   border-right: 8px solid #AAFF77;
1.707     bisitz   6320: }
1.795     www      6321: 
1.707     bisitz   6322: table.LC_data_table tr > td.LC_roles_selected {
1.939     bisitz   6323:   border-right: 8px solid #11CC55;
1.707     bisitz   6324: }
                   6325: 
1.388     albertel 6326: span.LC_current_location {
1.701     harmsja  6327:   font-size:larger;
1.388     albertel 6328:   background: $pgbg;
                   6329: }
1.387     albertel 6330: 
1.1029    www      6331: span.LC_current_nav_location {
                   6332:   font-weight:bold;
                   6333:   background: $sidebg;
                   6334: }
                   6335: 
1.395     albertel 6336: span.LC_parm_menu_item {
                   6337:   font-size: larger;
                   6338: }
1.795     www      6339: 
1.395     albertel 6340: span.LC_parm_scope_all {
                   6341:   color: red;
                   6342: }
1.795     www      6343: 
1.395     albertel 6344: span.LC_parm_scope_folder {
                   6345:   color: green;
                   6346: }
1.795     www      6347: 
1.395     albertel 6348: span.LC_parm_scope_resource {
                   6349:   color: orange;
                   6350: }
1.795     www      6351: 
1.395     albertel 6352: span.LC_parm_part {
                   6353:   color: blue;
                   6354: }
1.795     www      6355: 
1.911     bisitz   6356: span.LC_parm_folder,
                   6357: span.LC_parm_symb {
1.395     albertel 6358:   font-size: x-small;
                   6359:   font-family: $mono;
                   6360:   color: #AAAAAA;
                   6361: }
                   6362: 
1.977     bisitz   6363: ul.LC_parm_parmlist li {
                   6364:   display: inline-block;
                   6365:   padding: 0.3em 0.8em;
                   6366:   vertical-align: top;
                   6367:   width: 150px;
                   6368:   border-top:1px solid $lg_border_color;
                   6369: }
                   6370: 
1.795     www      6371: td.LC_parm_overview_level_menu,
                   6372: td.LC_parm_overview_map_menu,
                   6373: td.LC_parm_overview_parm_selectors,
                   6374: td.LC_parm_overview_restrictions  {
1.396     albertel 6375:   border: 1px solid black;
                   6376:   border-collapse: collapse;
                   6377: }
1.795     www      6378: 
1.396     albertel 6379: table.LC_parm_overview_restrictions td {
                   6380:   border-width: 1px 4px 1px 4px;
                   6381:   border-style: solid;
                   6382:   border-color: $pgbg;
                   6383:   text-align: center;
                   6384: }
1.795     www      6385: 
1.396     albertel 6386: table.LC_parm_overview_restrictions th {
                   6387:   background: $tabbg;
                   6388:   border-width: 1px 4px 1px 4px;
                   6389:   border-style: solid;
                   6390:   border-color: $pgbg;
                   6391: }
1.795     www      6392: 
1.398     albertel 6393: table#LC_helpmenu {
1.803     bisitz   6394:   border: none;
1.398     albertel 6395:   height: 55px;
1.803     bisitz   6396:   border-spacing: 0;
1.398     albertel 6397: }
                   6398: 
                   6399: table#LC_helpmenu fieldset legend {
                   6400:   font-size: larger;
                   6401: }
1.795     www      6402: 
1.397     albertel 6403: table#LC_helpmenu_links {
                   6404:   width: 100%;
                   6405:   border: 1px solid black;
                   6406:   background: $pgbg;
1.803     bisitz   6407:   padding: 0;
1.397     albertel 6408:   border-spacing: 1px;
                   6409: }
1.795     www      6410: 
1.397     albertel 6411: table#LC_helpmenu_links tr td {
                   6412:   padding: 1px;
                   6413:   background: $tabbg;
1.399     albertel 6414:   text-align: center;
                   6415:   font-weight: bold;
1.397     albertel 6416: }
1.396     albertel 6417: 
1.795     www      6418: table#LC_helpmenu_links a:link,
                   6419: table#LC_helpmenu_links a:visited,
1.397     albertel 6420: table#LC_helpmenu_links a:active {
                   6421:   text-decoration: none;
                   6422:   color: $font;
                   6423: }
1.795     www      6424: 
1.397     albertel 6425: table#LC_helpmenu_links a:hover {
                   6426:   text-decoration: underline;
                   6427:   color: $vlink;
                   6428: }
1.396     albertel 6429: 
1.417     albertel 6430: .LC_chrt_popup_exists {
                   6431:   border: 1px solid #339933;
                   6432:   margin: -1px;
                   6433: }
1.795     www      6434: 
1.417     albertel 6435: .LC_chrt_popup_up {
                   6436:   border: 1px solid yellow;
                   6437:   margin: -1px;
                   6438: }
1.795     www      6439: 
1.417     albertel 6440: .LC_chrt_popup {
                   6441:   border: 1px solid #8888FF;
                   6442:   background: #CCCCFF;
                   6443: }
1.795     www      6444: 
1.421     albertel 6445: table.LC_pick_box {
                   6446:   border-collapse: separate;
                   6447:   background: white;
                   6448:   border: 1px solid black;
                   6449:   border-spacing: 1px;
                   6450: }
1.795     www      6451: 
1.421     albertel 6452: table.LC_pick_box td.LC_pick_box_title {
1.850     bisitz   6453:   background: $sidebg;
1.421     albertel 6454:   font-weight: bold;
1.900     bisitz   6455:   text-align: left;
1.740     bisitz   6456:   vertical-align: top;
1.421     albertel 6457:   width: 184px;
                   6458:   padding: 8px;
                   6459: }
1.795     www      6460: 
1.579     raeburn  6461: table.LC_pick_box td.LC_pick_box_value {
                   6462:   text-align: left;
                   6463:   padding: 8px;
                   6464: }
1.795     www      6465: 
1.579     raeburn  6466: table.LC_pick_box td.LC_pick_box_select {
                   6467:   text-align: left;
                   6468:   padding: 8px;
                   6469: }
1.795     www      6470: 
1.424     albertel 6471: table.LC_pick_box td.LC_pick_box_separator {
1.803     bisitz   6472:   padding: 0;
1.421     albertel 6473:   height: 1px;
                   6474:   background: black;
                   6475: }
1.795     www      6476: 
1.421     albertel 6477: table.LC_pick_box td.LC_pick_box_submit {
                   6478:   text-align: right;
                   6479: }
1.795     www      6480: 
1.579     raeburn  6481: table.LC_pick_box td.LC_evenrow_value {
                   6482:   text-align: left;
                   6483:   padding: 8px;
                   6484:   background-color: $data_table_light;
                   6485: }
1.795     www      6486: 
1.579     raeburn  6487: table.LC_pick_box td.LC_oddrow_value {
                   6488:   text-align: left;
                   6489:   padding: 8px;
                   6490:   background-color: $data_table_light;
                   6491: }
1.795     www      6492: 
1.579     raeburn  6493: span.LC_helpform_receipt_cat {
                   6494:   font-weight: bold;
                   6495: }
1.795     www      6496: 
1.424     albertel 6497: table.LC_group_priv_box {
                   6498:   background: white;
                   6499:   border: 1px solid black;
                   6500:   border-spacing: 1px;
                   6501: }
1.795     www      6502: 
1.424     albertel 6503: table.LC_group_priv_box td.LC_pick_box_title {
                   6504:   background: $tabbg;
                   6505:   font-weight: bold;
                   6506:   text-align: right;
                   6507:   width: 184px;
                   6508: }
1.795     www      6509: 
1.424     albertel 6510: table.LC_group_priv_box td.LC_groups_fixed {
                   6511:   background: $data_table_light;
                   6512:   text-align: center;
                   6513: }
1.795     www      6514: 
1.424     albertel 6515: table.LC_group_priv_box td.LC_groups_optional {
                   6516:   background: $data_table_dark;
                   6517:   text-align: center;
                   6518: }
1.795     www      6519: 
1.424     albertel 6520: table.LC_group_priv_box td.LC_groups_functionality {
                   6521:   background: $data_table_darker;
                   6522:   text-align: center;
                   6523:   font-weight: bold;
                   6524: }
1.795     www      6525: 
1.424     albertel 6526: table.LC_group_priv td {
                   6527:   text-align: left;
1.803     bisitz   6528:   padding: 0;
1.424     albertel 6529: }
                   6530: 
                   6531: .LC_navbuttons {
                   6532:   margin: 2ex 0ex 2ex 0ex;
                   6533: }
1.795     www      6534: 
1.423     albertel 6535: .LC_topic_bar {
                   6536:   font-weight: bold;
                   6537:   background: $tabbg;
1.918     wenzelju 6538:   margin: 1em 0em 1em 2em;
1.805     bisitz   6539:   padding: 3px;
1.918     wenzelju 6540:   font-size: 1.2em;
1.423     albertel 6541: }
1.795     www      6542: 
1.423     albertel 6543: .LC_topic_bar span {
1.918     wenzelju 6544:   left: 0.5em;
                   6545:   position: absolute;
1.423     albertel 6546:   vertical-align: middle;
1.918     wenzelju 6547:   font-size: 1.2em;
1.423     albertel 6548: }
1.795     www      6549: 
1.423     albertel 6550: table.LC_course_group_status {
                   6551:   margin: 20px;
                   6552: }
1.795     www      6553: 
1.423     albertel 6554: table.LC_status_selector td {
                   6555:   vertical-align: top;
                   6556:   text-align: center;
1.424     albertel 6557:   padding: 4px;
                   6558: }
1.795     www      6559: 
1.599     albertel 6560: div.LC_feedback_link {
1.616     albertel 6561:   clear: both;
1.829     kalberla 6562:   background: $sidebg;
1.779     bisitz   6563:   width: 100%;
1.829     kalberla 6564:   padding-bottom: 10px;
                   6565:   border: 1px $tabbg solid;
1.833     kalberla 6566:   height: 22px;
                   6567:   line-height: 22px;
                   6568:   padding-top: 5px;
                   6569: }
                   6570: 
                   6571: div.LC_feedback_link img {
                   6572:   height: 22px;
1.867     kalberla 6573:   vertical-align:middle;
1.829     kalberla 6574: }
                   6575: 
1.911     bisitz   6576: div.LC_feedback_link a {
1.829     kalberla 6577:   text-decoration: none;
1.489     raeburn  6578: }
1.795     www      6579: 
1.867     kalberla 6580: div.LC_comblock {
1.911     bisitz   6581:   display:inline;
1.867     kalberla 6582:   color:$font;
                   6583:   font-size:90%;
                   6584: }
                   6585: 
                   6586: div.LC_feedback_link div.LC_comblock {
                   6587:   padding-left:5px;
                   6588: }
                   6589: 
                   6590: div.LC_feedback_link div.LC_comblock a {
                   6591:   color:$font;
                   6592: }
                   6593: 
1.489     raeburn  6594: span.LC_feedback_link {
1.858     bisitz   6595:   /* background: $feedback_link_bg; */
1.599     albertel 6596:   font-size: larger;
                   6597: }
1.795     www      6598: 
1.599     albertel 6599: span.LC_message_link {
1.858     bisitz   6600:   /* background: $feedback_link_bg; */
1.599     albertel 6601:   font-size: larger;
                   6602:   position: absolute;
                   6603:   right: 1em;
1.489     raeburn  6604: }
1.421     albertel 6605: 
1.515     albertel 6606: table.LC_prior_tries {
1.524     albertel 6607:   border: 1px solid #000000;
                   6608:   border-collapse: separate;
                   6609:   border-spacing: 1px;
1.515     albertel 6610: }
1.523     albertel 6611: 
1.515     albertel 6612: table.LC_prior_tries td {
1.524     albertel 6613:   padding: 2px;
1.515     albertel 6614: }
1.523     albertel 6615: 
                   6616: .LC_answer_correct {
1.795     www      6617:   background: lightgreen;
                   6618:   color: darkgreen;
                   6619:   padding: 6px;
1.523     albertel 6620: }
1.795     www      6621: 
1.523     albertel 6622: .LC_answer_charged_try {
1.797     www      6623:   background: #FFAAAA;
1.795     www      6624:   color: darkred;
                   6625:   padding: 6px;
1.523     albertel 6626: }
1.795     www      6627: 
1.779     bisitz   6628: .LC_answer_not_charged_try,
1.523     albertel 6629: .LC_answer_no_grade,
                   6630: .LC_answer_late {
1.795     www      6631:   background: lightyellow;
1.523     albertel 6632:   color: black;
1.795     www      6633:   padding: 6px;
1.523     albertel 6634: }
1.795     www      6635: 
1.523     albertel 6636: .LC_answer_previous {
1.795     www      6637:   background: lightblue;
                   6638:   color: darkblue;
                   6639:   padding: 6px;
1.523     albertel 6640: }
1.795     www      6641: 
1.779     bisitz   6642: .LC_answer_no_message {
1.777     tempelho 6643:   background: #FFFFFF;
                   6644:   color: black;
1.795     www      6645:   padding: 6px;
1.779     bisitz   6646: }
1.795     www      6647: 
1.779     bisitz   6648: .LC_answer_unknown {
                   6649:   background: orange;
                   6650:   color: black;
1.795     www      6651:   padding: 6px;
1.777     tempelho 6652: }
1.795     www      6653: 
1.529     albertel 6654: span.LC_prior_numerical,
                   6655: span.LC_prior_string,
                   6656: span.LC_prior_custom,
                   6657: span.LC_prior_reaction,
                   6658: span.LC_prior_math {
1.925     bisitz   6659:   font-family: $mono;
1.523     albertel 6660:   white-space: pre;
                   6661: }
                   6662: 
1.525     albertel 6663: span.LC_prior_string {
1.925     bisitz   6664:   font-family: $mono;
1.525     albertel 6665:   white-space: pre;
                   6666: }
                   6667: 
1.523     albertel 6668: table.LC_prior_option {
                   6669:   width: 100%;
                   6670:   border-collapse: collapse;
                   6671: }
1.795     www      6672: 
1.911     bisitz   6673: table.LC_prior_rank,
1.795     www      6674: table.LC_prior_match {
1.528     albertel 6675:   border-collapse: collapse;
                   6676: }
1.795     www      6677: 
1.528     albertel 6678: table.LC_prior_option tr td,
                   6679: table.LC_prior_rank tr td,
                   6680: table.LC_prior_match tr td {
1.524     albertel 6681:   border: 1px solid #000000;
1.515     albertel 6682: }
                   6683: 
1.855     bisitz   6684: .LC_nobreak {
1.544     albertel 6685:   white-space: nowrap;
1.519     raeburn  6686: }
                   6687: 
1.576     raeburn  6688: span.LC_cusr_emph {
                   6689:   font-style: italic;
                   6690: }
                   6691: 
1.633     raeburn  6692: span.LC_cusr_subheading {
                   6693:   font-weight: normal;
                   6694:   font-size: 85%;
                   6695: }
                   6696: 
1.861     bisitz   6697: div.LC_docs_entry_move {
1.859     bisitz   6698:   border: 1px solid #BBBBBB;
1.545     albertel 6699:   background: #DDDDDD;
1.861     bisitz   6700:   width: 22px;
1.859     bisitz   6701:   padding: 1px;
                   6702:   margin: 0;
1.545     albertel 6703: }
                   6704: 
1.861     bisitz   6705: table.LC_data_table tr > td.LC_docs_entry_commands,
                   6706: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545     albertel 6707:   font-size: x-small;
                   6708: }
1.795     www      6709: 
1.861     bisitz   6710: .LC_docs_entry_parameter {
                   6711:   white-space: nowrap;
                   6712: }
                   6713: 
1.544     albertel 6714: .LC_docs_copy {
1.545     albertel 6715:   color: #000099;
1.544     albertel 6716: }
1.795     www      6717: 
1.544     albertel 6718: .LC_docs_cut {
1.545     albertel 6719:   color: #550044;
1.544     albertel 6720: }
1.795     www      6721: 
1.544     albertel 6722: .LC_docs_rename {
1.545     albertel 6723:   color: #009900;
1.544     albertel 6724: }
1.795     www      6725: 
1.544     albertel 6726: .LC_docs_remove {
1.545     albertel 6727:   color: #990000;
                   6728: }
                   6729: 
1.547     albertel 6730: .LC_docs_reinit_warn,
                   6731: .LC_docs_ext_edit {
                   6732:   font-size: x-small;
                   6733: }
                   6734: 
1.545     albertel 6735: table.LC_docs_adddocs td,
                   6736: table.LC_docs_adddocs th {
                   6737:   border: 1px solid #BBBBBB;
                   6738:   padding: 4px;
                   6739:   background: #DDDDDD;
1.543     albertel 6740: }
                   6741: 
1.584     albertel 6742: table.LC_sty_begin {
                   6743:   background: #BBFFBB;
                   6744: }
1.795     www      6745: 
1.584     albertel 6746: table.LC_sty_end {
                   6747:   background: #FFBBBB;
                   6748: }
                   6749: 
1.589     raeburn  6750: table.LC_double_column {
1.803     bisitz   6751:   border-width: 0;
1.589     raeburn  6752:   border-collapse: collapse;
                   6753:   width: 100%;
                   6754:   padding: 2px;
                   6755: }
                   6756: 
                   6757: table.LC_double_column tr td.LC_left_col {
1.590     raeburn  6758:   top: 2px;
1.589     raeburn  6759:   left: 2px;
                   6760:   width: 47%;
                   6761:   vertical-align: top;
                   6762: }
                   6763: 
                   6764: table.LC_double_column tr td.LC_right_col {
                   6765:   top: 2px;
1.779     bisitz   6766:   right: 2px;
1.589     raeburn  6767:   width: 47%;
                   6768:   vertical-align: top;
                   6769: }
                   6770: 
1.591     raeburn  6771: div.LC_left_float {
                   6772:   float: left;
                   6773:   padding-right: 5%;
1.597     albertel 6774:   padding-bottom: 4px;
1.591     raeburn  6775: }
                   6776: 
                   6777: div.LC_clear_float_header {
1.597     albertel 6778:   padding-bottom: 2px;
1.591     raeburn  6779: }
                   6780: 
                   6781: div.LC_clear_float_footer {
1.597     albertel 6782:   padding-top: 10px;
1.591     raeburn  6783:   clear: both;
                   6784: }
                   6785: 
1.597     albertel 6786: div.LC_grade_show_user {
1.941     bisitz   6787: /*  border-left: 5px solid $sidebg; */
                   6788:   border-top: 5px solid #000000;
                   6789:   margin: 50px 0 0 0;
1.936     bisitz   6790:   padding: 15px 0 5px 10px;
1.597     albertel 6791: }
1.795     www      6792: 
1.936     bisitz   6793: div.LC_grade_show_user_odd_row {
1.941     bisitz   6794: /*  border-left: 5px solid #000000; */
                   6795: }
                   6796: 
                   6797: div.LC_grade_show_user div.LC_Box {
                   6798:   margin-right: 50px;
1.597     albertel 6799: }
                   6800: 
                   6801: div.LC_grade_submissions,
                   6802: div.LC_grade_message_center,
1.936     bisitz   6803: div.LC_grade_info_links {
1.597     albertel 6804:   margin: 5px;
                   6805:   width: 99%;
                   6806:   background: #FFFFFF;
                   6807: }
1.795     www      6808: 
1.597     albertel 6809: div.LC_grade_submissions_header,
1.936     bisitz   6810: div.LC_grade_message_center_header {
1.705     tempelho 6811:   font-weight: bold;
                   6812:   font-size: large;
1.597     albertel 6813: }
1.795     www      6814: 
1.597     albertel 6815: div.LC_grade_submissions_body,
1.936     bisitz   6816: div.LC_grade_message_center_body {
1.597     albertel 6817:   border: 1px solid black;
                   6818:   width: 99%;
                   6819:   background: #FFFFFF;
                   6820: }
1.795     www      6821: 
1.613     albertel 6822: table.LC_scantron_action {
                   6823:   width: 100%;
                   6824: }
1.795     www      6825: 
1.613     albertel 6826: table.LC_scantron_action tr th {
1.698     harmsja  6827:   font-weight:bold;
                   6828:   font-style:normal;
1.613     albertel 6829: }
1.795     www      6830: 
1.779     bisitz   6831: .LC_edit_problem_header,
1.614     albertel 6832: div.LC_edit_problem_footer {
1.705     tempelho 6833:   font-weight: normal;
                   6834:   font-size:  medium;
1.602     albertel 6835:   margin: 2px;
1.1060    bisitz   6836:   background-color: $sidebg;
1.600     albertel 6837: }
1.795     www      6838: 
1.600     albertel 6839: div.LC_edit_problem_header,
1.602     albertel 6840: div.LC_edit_problem_header div,
1.614     albertel 6841: div.LC_edit_problem_footer,
                   6842: div.LC_edit_problem_footer div,
1.602     albertel 6843: div.LC_edit_problem_editxml_header,
                   6844: div.LC_edit_problem_editxml_header div {
1.1075.2.112  raeburn  6845:   z-index: 100;
1.600     albertel 6846: }
1.795     www      6847: 
1.600     albertel 6848: div.LC_edit_problem_header_title {
1.705     tempelho 6849:   font-weight: bold;
                   6850:   font-size: larger;
1.602     albertel 6851:   background: $tabbg;
                   6852:   padding: 3px;
1.1060    bisitz   6853:   margin: 0 0 5px 0;
1.602     albertel 6854: }
1.795     www      6855: 
1.602     albertel 6856: table.LC_edit_problem_header_title {
                   6857:   width: 100%;
1.600     albertel 6858:   background: $tabbg;
1.602     albertel 6859: }
                   6860: 
1.1075.2.112  raeburn  6861: div.LC_edit_actionbar {
                   6862:     background-color: $sidebg;
                   6863:     margin: 0;
                   6864:     padding: 0;
                   6865:     line-height: 200%;
1.602     albertel 6866: }
1.795     www      6867: 
1.1075.2.112  raeburn  6868: div.LC_edit_actionbar div{
                   6869:     padding: 0;
                   6870:     margin: 0;
                   6871:     display: inline-block;
1.600     albertel 6872: }
1.795     www      6873: 
1.1075.2.34  raeburn  6874: .LC_edit_opt {
                   6875:   padding-left: 1em;
                   6876:   white-space: nowrap;
                   6877: }
                   6878: 
1.1075.2.57  raeburn  6879: .LC_edit_problem_latexhelper{
                   6880:     text-align: right;
                   6881: }
                   6882: 
                   6883: #LC_edit_problem_colorful div{
                   6884:     margin-left: 40px;
                   6885: }
                   6886: 
1.1075.2.112  raeburn  6887: #LC_edit_problem_codemirror div{
                   6888:     margin-left: 0px;
                   6889: }
                   6890: 
1.911     bisitz   6891: img.stift {
1.803     bisitz   6892:   border-width: 0;
                   6893:   vertical-align: middle;
1.677     riegler  6894: }
1.680     riegler  6895: 
1.923     bisitz   6896: table td.LC_mainmenu_col_fieldset {
1.680     riegler  6897:   vertical-align: top;
1.777     tempelho 6898: }
1.795     www      6899: 
1.716     raeburn  6900: div.LC_createcourse {
1.911     bisitz   6901:   margin: 10px 10px 10px 10px;
1.716     raeburn  6902: }
                   6903: 
1.917     raeburn  6904: .LC_dccid {
1.1075.2.38  raeburn  6905:   float: right;
1.917     raeburn  6906:   margin: 0.2em 0 0 0;
                   6907:   padding: 0;
                   6908:   font-size: 90%;
                   6909:   display:none;
                   6910: }
                   6911: 
1.897     wenzelju 6912: ol.LC_primary_menu a:hover,
1.721     harmsja  6913: ol#LC_MenuBreadcrumbs a:hover,
                   6914: ol#LC_PathBreadcrumbs a:hover,
1.897     wenzelju 6915: ul#LC_secondary_menu a:hover,
1.721     harmsja  6916: .LC_FormSectionClearButton input:hover
1.795     www      6917: ul.LC_TabContent   li:hover a {
1.952     onken    6918:   color:$button_hover;
1.911     bisitz   6919:   text-decoration:none;
1.693     droeschl 6920: }
                   6921: 
1.779     bisitz   6922: h1 {
1.911     bisitz   6923:   padding: 0;
                   6924:   line-height:130%;
1.693     droeschl 6925: }
1.698     harmsja  6926: 
1.911     bisitz   6927: h2,
                   6928: h3,
                   6929: h4,
                   6930: h5,
                   6931: h6 {
                   6932:   margin: 5px 0 5px 0;
                   6933:   padding: 0;
                   6934:   line-height:130%;
1.693     droeschl 6935: }
1.795     www      6936: 
                   6937: .LC_hcell {
1.911     bisitz   6938:   padding:3px 15px 3px 15px;
                   6939:   margin: 0;
                   6940:   background-color:$tabbg;
                   6941:   color:$fontmenu;
                   6942:   border-bottom:solid 1px $lg_border_color;
1.693     droeschl 6943: }
1.795     www      6944: 
1.840     bisitz   6945: .LC_Box > .LC_hcell {
1.911     bisitz   6946:   margin: 0 -10px 10px -10px;
1.835     bisitz   6947: }
                   6948: 
1.721     harmsja  6949: .LC_noBorder {
1.911     bisitz   6950:   border: 0;
1.698     harmsja  6951: }
1.693     droeschl 6952: 
1.721     harmsja  6953: .LC_FormSectionClearButton input {
1.911     bisitz   6954:   background-color:transparent;
                   6955:   border: none;
                   6956:   cursor:pointer;
                   6957:   text-decoration:underline;
1.693     droeschl 6958: }
1.763     bisitz   6959: 
                   6960: .LC_help_open_topic {
1.911     bisitz   6961:   color: #FFFFFF;
                   6962:   background-color: #EEEEFF;
                   6963:   margin: 1px;
                   6964:   padding: 4px;
                   6965:   border: 1px solid #000033;
                   6966:   white-space: nowrap;
                   6967:   /* vertical-align: middle; */
1.759     neumanie 6968: }
1.693     droeschl 6969: 
1.911     bisitz   6970: dl,
                   6971: ul,
                   6972: div,
                   6973: fieldset {
                   6974:   margin: 10px 10px 10px 0;
                   6975:   /* overflow: hidden; */
1.693     droeschl 6976: }
1.795     www      6977: 
1.1075.2.90  raeburn  6978: article.geogebraweb div {
                   6979:     margin: 0;
                   6980: }
                   6981: 
1.838     bisitz   6982: fieldset > legend {
1.911     bisitz   6983:   font-weight: bold;
                   6984:   padding: 0 5px 0 5px;
1.838     bisitz   6985: }
                   6986: 
1.813     bisitz   6987: #LC_nav_bar {
1.911     bisitz   6988:   float: left;
1.995     raeburn  6989:   background-color: $pgbg_or_bgcolor;
1.966     bisitz   6990:   margin: 0 0 2px 0;
1.807     droeschl 6991: }
                   6992: 
1.916     droeschl 6993: #LC_realm {
                   6994:   margin: 0.2em 0 0 0;
                   6995:   padding: 0;
                   6996:   font-weight: bold;
                   6997:   text-align: center;
1.995     raeburn  6998:   background-color: $pgbg_or_bgcolor;
1.916     droeschl 6999: }
                   7000: 
1.911     bisitz   7001: #LC_nav_bar em {
                   7002:   font-weight: bold;
                   7003:   font-style: normal;
1.807     droeschl 7004: }
                   7005: 
1.897     wenzelju 7006: ol.LC_primary_menu {
1.934     droeschl 7007:   margin: 0;
1.1075.2.2  raeburn  7008:   padding: 0;
1.807     droeschl 7009: }
                   7010: 
1.852     droeschl 7011: ol#LC_PathBreadcrumbs {
1.911     bisitz   7012:   margin: 0;
1.693     droeschl 7013: }
                   7014: 
1.897     wenzelju 7015: ol.LC_primary_menu li {
1.1075.2.2  raeburn  7016:   color: RGB(80, 80, 80);
                   7017:   vertical-align: middle;
                   7018:   text-align: left;
                   7019:   list-style: none;
1.1075.2.112  raeburn  7020:   position: relative;
1.1075.2.2  raeburn  7021:   float: left;
1.1075.2.112  raeburn  7022:   z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
                   7023:   line-height: 1.5em;
1.1075.2.2  raeburn  7024: }
                   7025: 
1.1075.2.113  raeburn  7026: ol.LC_primary_menu li a, 
1.1075.2.112  raeburn  7027: ol.LC_primary_menu li p {
1.1075.2.2  raeburn  7028:   display: block;
                   7029:   margin: 0;
                   7030:   padding: 0 5px 0 10px;
                   7031:   text-decoration: none;
                   7032: }
                   7033: 
1.1075.2.112  raeburn  7034: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
                   7035:   display: inline-block;
                   7036:   width: 95%;
                   7037:   text-align: left;
                   7038: }
                   7039: 
                   7040: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
                   7041:   display: inline-block;
                   7042:   width: 5%;
                   7043:   float: right;
                   7044:   text-align: right;
                   7045:   font-size: 70%;
                   7046: }
                   7047: 
                   7048: ol.LC_primary_menu ul {
1.1075.2.2  raeburn  7049:   display: none;
1.1075.2.112  raeburn  7050:   width: 15em;
1.1075.2.2  raeburn  7051:   background-color: $data_table_light;
1.1075.2.112  raeburn  7052:   position: absolute;
                   7053:   top: 100%;
                   7054: }
                   7055: 
                   7056: ol.LC_primary_menu ul ul {
                   7057:   left: 100%;
                   7058:   top: 0;
1.1075.2.2  raeburn  7059: }
                   7060: 
1.1075.2.112  raeburn  7061: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1075.2.2  raeburn  7062:   display: block;
                   7063:   position: absolute;
                   7064:   margin: 0;
                   7065:   padding: 0;
1.1075.2.5  raeburn  7066:   z-index: 2;
1.1075.2.2  raeburn  7067: }
                   7068: 
                   7069: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1075.2.112  raeburn  7070: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1075.2.2  raeburn  7071:   font-size: 90%;
1.911     bisitz   7072:   vertical-align: top;
1.1075.2.2  raeburn  7073:   float: none;
1.1075.2.5  raeburn  7074:   border-left: 1px solid black;
                   7075:   border-right: 1px solid black;
1.1075.2.112  raeburn  7076: /* A dark bottom border to visualize different menu options;
                   7077: overwritten in the create_submenu routine for the last border-bottom of the menu */
                   7078:   border-bottom: 1px solid $data_table_dark;
1.1075.2.2  raeburn  7079: }
                   7080: 
1.1075.2.112  raeburn  7081: ol.LC_primary_menu li li p:hover {
                   7082:   color:$button_hover;
                   7083:   text-decoration:none;
                   7084:   background-color:$data_table_dark;
1.1075.2.2  raeburn  7085: }
                   7086: 
                   7087: ol.LC_primary_menu li li a:hover {
                   7088:    color:$button_hover;
                   7089:    background-color:$data_table_dark;
1.693     droeschl 7090: }
                   7091: 
1.1075.2.112  raeburn  7092: /* Font-size equal to the size of the predecessors*/
                   7093: ol.LC_primary_menu li:hover li li {
                   7094:   font-size: 100%;
                   7095: }
                   7096: 
1.897     wenzelju 7097: ol.LC_primary_menu li img {
1.911     bisitz   7098:   vertical-align: bottom;
1.934     droeschl 7099:   height: 1.1em;
1.1075.2.3  raeburn  7100:   margin: 0.2em 0 0 0;
1.693     droeschl 7101: }
                   7102: 
1.897     wenzelju 7103: ol.LC_primary_menu a {
1.911     bisitz   7104:   color: RGB(80, 80, 80);
                   7105:   text-decoration: none;
1.693     droeschl 7106: }
1.795     www      7107: 
1.949     droeschl 7108: ol.LC_primary_menu a.LC_new_message {
                   7109:   font-weight:bold;
                   7110:   color: darkred;
                   7111: }
                   7112: 
1.975     raeburn  7113: ol.LC_docs_parameters {
                   7114:   margin-left: 0;
                   7115:   padding: 0;
                   7116:   list-style: none;
                   7117: }
                   7118: 
                   7119: ol.LC_docs_parameters li {
                   7120:   margin: 0;
                   7121:   padding-right: 20px;
                   7122:   display: inline;
                   7123: }
                   7124: 
1.976     raeburn  7125: ol.LC_docs_parameters li:before {
                   7126:   content: "\\002022 \\0020";
                   7127: }
                   7128: 
                   7129: li.LC_docs_parameters_title {
                   7130:   font-weight: bold;
                   7131: }
                   7132: 
                   7133: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
                   7134:   content: "";
                   7135: }
                   7136: 
1.897     wenzelju 7137: ul#LC_secondary_menu {
1.1075.2.23  raeburn  7138:   clear: right;
1.911     bisitz   7139:   color: $fontmenu;
                   7140:   background: $tabbg;
                   7141:   list-style: none;
                   7142:   padding: 0;
                   7143:   margin: 0;
                   7144:   width: 100%;
1.995     raeburn  7145:   text-align: left;
1.1075.2.4  raeburn  7146:   float: left;
1.808     droeschl 7147: }
                   7148: 
1.897     wenzelju 7149: ul#LC_secondary_menu li {
1.911     bisitz   7150:   font-weight: bold;
                   7151:   line-height: 1.8em;
                   7152:   border-right: 1px solid black;
1.1075.2.4  raeburn  7153:   float: left;
                   7154: }
                   7155: 
                   7156: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
                   7157:   background-color: $data_table_light;
                   7158: }
                   7159: 
                   7160: ul#LC_secondary_menu li a {
                   7161:   padding: 0 0.8em;
                   7162: }
                   7163: 
                   7164: ul#LC_secondary_menu li ul {
                   7165:   display: none;
                   7166: }
                   7167: 
                   7168: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
                   7169:   display: block;
                   7170:   position: absolute;
                   7171:   margin: 0;
                   7172:   padding: 0;
                   7173:   list-style:none;
                   7174:   float: none;
                   7175:   background-color: $data_table_light;
1.1075.2.5  raeburn  7176:   z-index: 2;
1.1075.2.10  raeburn  7177:   margin-left: -1px;
1.1075.2.4  raeburn  7178: }
                   7179: 
                   7180: ul#LC_secondary_menu li ul li {
                   7181:   font-size: 90%;
                   7182:   vertical-align: top;
                   7183:   border-left: 1px solid black;
                   7184:   border-right: 1px solid black;
1.1075.2.33  raeburn  7185:   background-color: $data_table_light;
1.1075.2.4  raeburn  7186:   list-style:none;
                   7187:   float: none;
                   7188: }
                   7189: 
                   7190: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
                   7191:   background-color: $data_table_dark;
1.807     droeschl 7192: }
                   7193: 
1.847     tempelho 7194: ul.LC_TabContent {
1.911     bisitz   7195:   display:block;
                   7196:   background: $sidebg;
                   7197:   border-bottom: solid 1px $lg_border_color;
                   7198:   list-style:none;
1.1020    raeburn  7199:   margin: -1px -10px 0 -10px;
1.911     bisitz   7200:   padding: 0;
1.693     droeschl 7201: }
                   7202: 
1.795     www      7203: ul.LC_TabContent li,
                   7204: ul.LC_TabContentBigger li {
1.911     bisitz   7205:   float:left;
1.741     harmsja  7206: }
1.795     www      7207: 
1.897     wenzelju 7208: ul#LC_secondary_menu li a {
1.911     bisitz   7209:   color: $fontmenu;
                   7210:   text-decoration: none;
1.693     droeschl 7211: }
1.795     www      7212: 
1.721     harmsja  7213: ul.LC_TabContent {
1.952     onken    7214:   min-height:20px;
1.721     harmsja  7215: }
1.795     www      7216: 
                   7217: ul.LC_TabContent li {
1.911     bisitz   7218:   vertical-align:middle;
1.959     onken    7219:   padding: 0 16px 0 10px;
1.911     bisitz   7220:   background-color:$tabbg;
                   7221:   border-bottom:solid 1px $lg_border_color;
1.1020    raeburn  7222:   border-left: solid 1px $font;
1.721     harmsja  7223: }
1.795     www      7224: 
1.847     tempelho 7225: ul.LC_TabContent .right {
1.911     bisitz   7226:   float:right;
1.847     tempelho 7227: }
                   7228: 
1.911     bisitz   7229: ul.LC_TabContent li a,
                   7230: ul.LC_TabContent li {
                   7231:   color:rgb(47,47,47);
                   7232:   text-decoration:none;
                   7233:   font-size:95%;
                   7234:   font-weight:bold;
1.952     onken    7235:   min-height:20px;
                   7236: }
                   7237: 
1.959     onken    7238: ul.LC_TabContent li a:hover,
                   7239: ul.LC_TabContent li a:focus {
1.952     onken    7240:   color: $button_hover;
1.959     onken    7241:   background:none;
                   7242:   outline:none;
1.952     onken    7243: }
                   7244: 
                   7245: ul.LC_TabContent li:hover {
                   7246:   color: $button_hover;
                   7247:   cursor:pointer;
1.721     harmsja  7248: }
1.795     www      7249: 
1.911     bisitz   7250: ul.LC_TabContent li.active {
1.952     onken    7251:   color: $font;
1.911     bisitz   7252:   background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952     onken    7253:   border-bottom:solid 1px #FFFFFF;
                   7254:   cursor: default;
1.744     ehlerst  7255: }
1.795     www      7256: 
1.959     onken    7257: ul.LC_TabContent li.active a {
                   7258:   color:$font;
                   7259:   background:#FFFFFF;
                   7260:   outline: none;
                   7261: }
1.1047    raeburn  7262: 
                   7263: ul.LC_TabContent li.goback {
                   7264:   float: left;
                   7265:   border-left: none;
                   7266: }
                   7267: 
1.870     tempelho 7268: #maincoursedoc {
1.911     bisitz   7269:   clear:both;
1.870     tempelho 7270: }
                   7271: 
                   7272: ul.LC_TabContentBigger {
1.911     bisitz   7273:   display:block;
                   7274:   list-style:none;
                   7275:   padding: 0;
1.870     tempelho 7276: }
                   7277: 
1.795     www      7278: ul.LC_TabContentBigger li {
1.911     bisitz   7279:   vertical-align:bottom;
                   7280:   height: 30px;
                   7281:   font-size:110%;
                   7282:   font-weight:bold;
                   7283:   color: #737373;
1.841     tempelho 7284: }
                   7285: 
1.957     onken    7286: ul.LC_TabContentBigger li.active {
                   7287:   position: relative;
                   7288:   top: 1px;
                   7289: }
                   7290: 
1.870     tempelho 7291: ul.LC_TabContentBigger li a {
1.911     bisitz   7292:   background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
                   7293:   height: 30px;
                   7294:   line-height: 30px;
                   7295:   text-align: center;
                   7296:   display: block;
                   7297:   text-decoration: none;
1.958     onken    7298:   outline: none;  
1.741     harmsja  7299: }
1.795     www      7300: 
1.870     tempelho 7301: ul.LC_TabContentBigger li.active a {
1.911     bisitz   7302:   background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
                   7303:   color:$font;
1.744     ehlerst  7304: }
1.795     www      7305: 
1.870     tempelho 7306: ul.LC_TabContentBigger li b {
1.911     bisitz   7307:   background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
                   7308:   display: block;
                   7309:   float: left;
                   7310:   padding: 0 30px;
1.957     onken    7311:   border-bottom: 1px solid $lg_border_color;
1.870     tempelho 7312: }
                   7313: 
1.956     onken    7314: ul.LC_TabContentBigger li:hover b {
                   7315:   color:$button_hover;
                   7316: }
                   7317: 
1.870     tempelho 7318: ul.LC_TabContentBigger li.active b {
1.911     bisitz   7319:   background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
                   7320:   color:$font;
1.957     onken    7321:   border: 0;
1.741     harmsja  7322: }
1.693     droeschl 7323: 
1.870     tempelho 7324: 
1.862     bisitz   7325: ul.LC_CourseBreadcrumbs {
                   7326:   background: $sidebg;
1.1020    raeburn  7327:   height: 2em;
1.862     bisitz   7328:   padding-left: 10px;
1.1020    raeburn  7329:   margin: 0;
1.862     bisitz   7330:   list-style-position: inside;
                   7331: }
                   7332: 
1.911     bisitz   7333: ol#LC_MenuBreadcrumbs,
1.862     bisitz   7334: ol#LC_PathBreadcrumbs {
1.911     bisitz   7335:   padding-left: 10px;
                   7336:   margin: 0;
1.933     droeschl 7337:   height: 2.5em;  /* equal to #LC_breadcrumbs line-height */
1.693     droeschl 7338: }
                   7339: 
1.911     bisitz   7340: ol#LC_MenuBreadcrumbs li,
                   7341: ol#LC_PathBreadcrumbs li,
1.862     bisitz   7342: ul.LC_CourseBreadcrumbs li {
1.911     bisitz   7343:   display: inline;
1.933     droeschl 7344:   white-space: normal;  
1.693     droeschl 7345: }
                   7346: 
1.823     bisitz   7347: ol#LC_MenuBreadcrumbs li a,
1.862     bisitz   7348: ul.LC_CourseBreadcrumbs li a {
1.911     bisitz   7349:   text-decoration: none;
                   7350:   font-size:90%;
1.693     droeschl 7351: }
1.795     www      7352: 
1.969     droeschl 7353: ol#LC_MenuBreadcrumbs h1 {
                   7354:   display: inline;
                   7355:   font-size: 90%;
                   7356:   line-height: 2.5em;
                   7357:   margin: 0;
                   7358:   padding: 0;
                   7359: }
                   7360: 
1.795     www      7361: ol#LC_PathBreadcrumbs li a {
1.911     bisitz   7362:   text-decoration:none;
                   7363:   font-size:100%;
                   7364:   font-weight:bold;
1.693     droeschl 7365: }
1.795     www      7366: 
1.840     bisitz   7367: .LC_Box {
1.911     bisitz   7368:   border: solid 1px $lg_border_color;
                   7369:   padding: 0 10px 10px 10px;
1.746     neumanie 7370: }
1.795     www      7371: 
1.1020    raeburn  7372: .LC_DocsBox {
                   7373:   border: solid 1px $lg_border_color;
                   7374:   padding: 0 0 10px 10px;
                   7375: }
                   7376: 
1.795     www      7377: .LC_AboutMe_Image {
1.911     bisitz   7378:   float:left;
                   7379:   margin-right:10px;
1.747     neumanie 7380: }
1.795     www      7381: 
                   7382: .LC_Clear_AboutMe_Image {
1.911     bisitz   7383:   clear:left;
1.747     neumanie 7384: }
1.795     www      7385: 
1.721     harmsja  7386: dl.LC_ListStyleClean dt {
1.911     bisitz   7387:   padding-right: 5px;
                   7388:   display: table-header-group;
1.693     droeschl 7389: }
                   7390: 
1.721     harmsja  7391: dl.LC_ListStyleClean dd {
1.911     bisitz   7392:   display: table-row;
1.693     droeschl 7393: }
                   7394: 
1.721     harmsja  7395: .LC_ListStyleClean,
                   7396: .LC_ListStyleSimple,
                   7397: .LC_ListStyleNormal,
1.795     www      7398: .LC_ListStyleSpecial {
1.911     bisitz   7399:   /* display:block; */
                   7400:   list-style-position: inside;
                   7401:   list-style-type: none;
                   7402:   overflow: hidden;
                   7403:   padding: 0;
1.693     droeschl 7404: }
                   7405: 
1.721     harmsja  7406: .LC_ListStyleSimple li,
                   7407: .LC_ListStyleSimple dd,
                   7408: .LC_ListStyleNormal li,
                   7409: .LC_ListStyleNormal dd,
                   7410: .LC_ListStyleSpecial li,
1.795     www      7411: .LC_ListStyleSpecial dd {
1.911     bisitz   7412:   margin: 0;
                   7413:   padding: 5px 5px 5px 10px;
                   7414:   clear: both;
1.693     droeschl 7415: }
                   7416: 
1.721     harmsja  7417: .LC_ListStyleClean li,
                   7418: .LC_ListStyleClean dd {
1.911     bisitz   7419:   padding-top: 0;
                   7420:   padding-bottom: 0;
1.693     droeschl 7421: }
                   7422: 
1.721     harmsja  7423: .LC_ListStyleSimple dd,
1.795     www      7424: .LC_ListStyleSimple li {
1.911     bisitz   7425:   border-bottom: solid 1px $lg_border_color;
1.693     droeschl 7426: }
                   7427: 
1.721     harmsja  7428: .LC_ListStyleSpecial li,
                   7429: .LC_ListStyleSpecial dd {
1.911     bisitz   7430:   list-style-type: none;
                   7431:   background-color: RGB(220, 220, 220);
                   7432:   margin-bottom: 4px;
1.693     droeschl 7433: }
                   7434: 
1.721     harmsja  7435: table.LC_SimpleTable {
1.911     bisitz   7436:   margin:5px;
                   7437:   border:solid 1px $lg_border_color;
1.795     www      7438: }
1.693     droeschl 7439: 
1.721     harmsja  7440: table.LC_SimpleTable tr {
1.911     bisitz   7441:   padding: 0;
                   7442:   border:solid 1px $lg_border_color;
1.693     droeschl 7443: }
1.795     www      7444: 
                   7445: table.LC_SimpleTable thead {
1.911     bisitz   7446:   background:rgb(220,220,220);
1.693     droeschl 7447: }
                   7448: 
1.721     harmsja  7449: div.LC_columnSection {
1.911     bisitz   7450:   display: block;
                   7451:   clear: both;
                   7452:   overflow: hidden;
                   7453:   margin: 0;
1.693     droeschl 7454: }
                   7455: 
1.721     harmsja  7456: div.LC_columnSection>* {
1.911     bisitz   7457:   float: left;
                   7458:   margin: 10px 20px 10px 0;
                   7459:   overflow:hidden;
1.693     droeschl 7460: }
1.721     harmsja  7461: 
1.795     www      7462: table em {
1.911     bisitz   7463:   font-weight: bold;
                   7464:   font-style: normal;
1.748     schulted 7465: }
1.795     www      7466: 
1.779     bisitz   7467: table.LC_tableBrowseRes,
1.795     www      7468: table.LC_tableOfContent {
1.911     bisitz   7469:   border:none;
                   7470:   border-spacing: 1px;
                   7471:   padding: 3px;
                   7472:   background-color: #FFFFFF;
                   7473:   font-size: 90%;
1.753     droeschl 7474: }
1.789     droeschl 7475: 
1.911     bisitz   7476: table.LC_tableOfContent {
                   7477:   border-collapse: collapse;
1.789     droeschl 7478: }
                   7479: 
1.771     droeschl 7480: table.LC_tableBrowseRes a,
1.768     schulted 7481: table.LC_tableOfContent a {
1.911     bisitz   7482:   background-color: transparent;
                   7483:   text-decoration: none;
1.753     droeschl 7484: }
                   7485: 
1.795     www      7486: table.LC_tableOfContent img {
1.911     bisitz   7487:   border: none;
                   7488:   height: 1.3em;
                   7489:   vertical-align: text-bottom;
                   7490:   margin-right: 0.3em;
1.753     droeschl 7491: }
1.757     schulted 7492: 
1.795     www      7493: a#LC_content_toolbar_firsthomework {
1.911     bisitz   7494:   background-image:url(/res/adm/pages/open-first-problem.gif);
1.774     ehlerst  7495: }
                   7496: 
1.795     www      7497: a#LC_content_toolbar_everything {
1.911     bisitz   7498:   background-image:url(/res/adm/pages/show-all.gif);
1.774     ehlerst  7499: }
                   7500: 
1.795     www      7501: a#LC_content_toolbar_uncompleted {
1.911     bisitz   7502:   background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774     ehlerst  7503: }
                   7504: 
1.795     www      7505: #LC_content_toolbar_clearbubbles {
1.911     bisitz   7506:   background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774     ehlerst  7507: }
                   7508: 
1.795     www      7509: a#LC_content_toolbar_changefolder {
1.911     bisitz   7510:   background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757     schulted 7511: }
                   7512: 
1.795     www      7513: a#LC_content_toolbar_changefolder_toggled {
1.911     bisitz   7514:   background-image:url(/res/adm/pages/open-all-folders.gif);
1.757     schulted 7515: }
                   7516: 
1.1043    raeburn  7517: a#LC_content_toolbar_edittoplevel {
                   7518:   background-image:url(/res/adm/pages/edittoplevel.gif);
                   7519: }
                   7520: 
1.795     www      7521: ul#LC_toolbar li a:hover {
1.911     bisitz   7522:   background-position: bottom center;
1.757     schulted 7523: }
                   7524: 
1.795     www      7525: ul#LC_toolbar {
1.911     bisitz   7526:   padding: 0;
                   7527:   margin: 2px;
                   7528:   list-style:none;
                   7529:   position:relative;
                   7530:   background-color:white;
1.1075.2.9  raeburn  7531:   overflow: auto;
1.757     schulted 7532: }
                   7533: 
1.795     www      7534: ul#LC_toolbar li {
1.911     bisitz   7535:   border:1px solid white;
                   7536:   padding: 0;
                   7537:   margin: 0;
                   7538:   float: left;
                   7539:   display:inline;
                   7540:   vertical-align:middle;
1.1075.2.9  raeburn  7541:   white-space: nowrap;
1.911     bisitz   7542: }
1.757     schulted 7543: 
1.783     amueller 7544: 
1.795     www      7545: a.LC_toolbarItem {
1.911     bisitz   7546:   display:block;
                   7547:   padding: 0;
                   7548:   margin: 0;
                   7549:   height: 32px;
                   7550:   width: 32px;
                   7551:   color:white;
                   7552:   border: none;
                   7553:   background-repeat:no-repeat;
                   7554:   background-color:transparent;
1.757     schulted 7555: }
                   7556: 
1.915     droeschl 7557: ul.LC_funclist {
                   7558:     margin: 0;
                   7559:     padding: 0.5em 1em 0.5em 0;
                   7560: }
                   7561: 
1.933     droeschl 7562: ul.LC_funclist > li:first-child {
                   7563:     font-weight:bold; 
                   7564:     margin-left:0.8em;
                   7565: }
                   7566: 
1.915     droeschl 7567: ul.LC_funclist + ul.LC_funclist {
                   7568:     /* 
                   7569:        left border as a seperator if we have more than
                   7570:        one list 
                   7571:     */
                   7572:     border-left: 1px solid $sidebg;
                   7573:     /* 
                   7574:        this hides the left border behind the border of the 
                   7575:        outer box if element is wrapped to the next 'line' 
                   7576:     */
                   7577:     margin-left: -1px;
                   7578: }
                   7579: 
1.843     bisitz   7580: ul.LC_funclist li {
1.915     droeschl 7581:   display: inline;
1.782     bisitz   7582:   white-space: nowrap;
1.915     droeschl 7583:   margin: 0 0 0 25px;
                   7584:   line-height: 150%;
1.782     bisitz   7585: }
                   7586: 
1.974     wenzelju 7587: .LC_hidden {
                   7588:   display: none;
                   7589: }
                   7590: 
1.1030    www      7591: .LCmodal-overlay {
                   7592: 		position:fixed;
                   7593: 		top:0;
                   7594: 		right:0;
                   7595: 		bottom:0;
                   7596: 		left:0;
                   7597: 		height:100%;
                   7598: 		width:100%;
                   7599: 		margin:0;
                   7600: 		padding:0;
                   7601: 		background:#999;
                   7602: 		opacity:.75;
                   7603: 		filter: alpha(opacity=75);
                   7604: 		-moz-opacity: 0.75;
                   7605: 		z-index:101;
                   7606: }
                   7607: 
                   7608: * html .LCmodal-overlay {   
                   7609: 		position: absolute;
                   7610: 		height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
                   7611: }
                   7612: 
                   7613: .LCmodal-window {
                   7614: 		position:fixed;
                   7615: 		top:50%;
                   7616: 		left:50%;
                   7617: 		margin:0;
                   7618: 		padding:0;
                   7619: 		z-index:102;
                   7620: 	}
                   7621: 
                   7622: * html .LCmodal-window {
                   7623: 		position:absolute;
                   7624: }
                   7625: 
                   7626: .LCclose-window {
                   7627: 		position:absolute;
                   7628: 		width:32px;
                   7629: 		height:32px;
                   7630: 		right:8px;
                   7631: 		top:8px;
                   7632: 		background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
                   7633: 		text-indent:-99999px;
                   7634: 		overflow:hidden;
                   7635: 		cursor:pointer;
                   7636: }
                   7637: 
1.1075.2.17  raeburn  7638: /*
                   7639:   styles used by TTH when "Default set of options to pass to tth/m
                   7640:   when converting TeX" in course settings has been set
                   7641: 
                   7642:   option passed: -t
                   7643: 
                   7644: */
                   7645: 
                   7646: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
                   7647: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
                   7648: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
                   7649: td div.norm {line-height:normal;}
                   7650: 
                   7651: /*
                   7652:   option passed -y3
                   7653: */
                   7654: 
                   7655: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
                   7656: span.overacc2 {position: relative;  left: .8em; top: -1.2ex;}
                   7657: span.overacc1 {position: relative;  left: .6em; top: -1.2ex;}
                   7658: 
1.343     albertel 7659: END
                   7660: }
                   7661: 
1.306     albertel 7662: =pod
                   7663: 
                   7664: =item * &headtag()
                   7665: 
                   7666: Returns a uniform footer for LON-CAPA web pages.
                   7667: 
1.307     albertel 7668: Inputs: $title - optional title for the head
                   7669:         $head_extra - optional extra HTML to put inside the <head>
1.315     albertel 7670:         $args - optional arguments
1.319     albertel 7671:             force_register - if is true call registerurl so the remote is 
                   7672:                              informed
1.415     albertel 7673:             redirect       -> array ref of
                   7674:                                    1- seconds before redirect occurs
                   7675:                                    2- url to redirect to
                   7676:                                    3- whether the side effect should occur
1.315     albertel 7677:                            (side effect of setting 
                   7678:                                $env{'internal.head.redirect'} to the url 
                   7679:                                redirected too)
1.352     albertel 7680:             domain         -> force to color decorate a page for a specific
                   7681:                                domain
                   7682:             function       -> force usage of a specific rolish color scheme
                   7683:             bgcolor        -> override the default page bgcolor
1.460     albertel 7684:             no_auto_mt_title
                   7685:                            -> prevent &mt()ing the title arg
1.464     albertel 7686: 
1.306     albertel 7687: =cut
                   7688: 
                   7689: sub headtag {
1.313     albertel 7690:     my ($title,$head_extra,$args) = @_;
1.306     albertel 7691:     
1.363     albertel 7692:     my $function = $args->{'function'} || &get_users_function();
                   7693:     my $domain   = $args->{'domain'}   || &determinedomain();
                   7694:     my $bgcolor  = $args->{'bgcolor'}  || &designparm($function.'.pgbg',$domain);
1.1075.2.52  raeburn  7695:     my $httphost = $args->{'use_absolute'};
1.418     albertel 7696:     my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458     albertel 7697: 		   $Apache::lonnet::perlvar{'lonVersion'},
1.531     albertel 7698: 		   #time(),
1.418     albertel 7699: 		   $env{'environment.color.timestamp'},
1.363     albertel 7700: 		   $function,$domain,$bgcolor);
                   7701: 
1.369     www      7702:     $url = '/adm/css/'.&escape($url).'.css';
1.363     albertel 7703: 
1.308     albertel 7704:     my $result =
                   7705: 	'<head>'.
1.1075.2.56  raeburn  7706: 	&font_settings($args);
1.319     albertel 7707: 
1.1075.2.72  raeburn  7708:     my $inhibitprint;
                   7709:     if ($args->{'print_suppress'}) {
                   7710:         $inhibitprint = &print_suppression();
                   7711:     }
1.1064    raeburn  7712: 
1.461     albertel 7713:     if (!$args->{'frameset'}) {
                   7714: 	$result .= &Apache::lonhtmlcommon::htmlareaheaders();
                   7715:     }
1.1075.2.12  raeburn  7716:     if ($args->{'force_register'}) {
                   7717:         $result .= &Apache::lonmenu::registerurl(1);
1.319     albertel 7718:     }
1.436     albertel 7719:     if (!$args->{'no_nav_bar'} 
                   7720: 	&& !$args->{'only_body'}
                   7721: 	&& !$args->{'frameset'}) {
1.1075.2.52  raeburn  7722: 	$result .= &help_menu_js($httphost);
1.1032    www      7723:         $result.=&modal_window();
1.1038    www      7724:         $result.=&togglebox_script();
1.1034    www      7725:         $result.=&wishlist_window();
1.1041    www      7726:         $result.=&LCprogressbarUpdate_script();
1.1034    www      7727:     } else {
                   7728:         if ($args->{'add_modal'}) {
                   7729:            $result.=&modal_window();
                   7730:         }
                   7731:         if ($args->{'add_wishlist'}) {
                   7732:            $result.=&wishlist_window();
                   7733:         }
1.1038    www      7734:         if ($args->{'add_togglebox'}) {
                   7735:            $result.=&togglebox_script();
                   7736:         }
1.1041    www      7737:         if ($args->{'add_progressbar'}) {
                   7738:            $result.=&LCprogressbarUpdate_script();
                   7739:         }
1.436     albertel 7740:     }
1.314     albertel 7741:     if (ref($args->{'redirect'})) {
1.414     albertel 7742: 	my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315     albertel 7743: 	$url = &Apache::lonenc::check_encrypt($url);
1.414     albertel 7744: 	if (!$inhibit_continue) {
                   7745: 	    $env{'internal.head.redirect'} = $url;
                   7746: 	}
1.313     albertel 7747: 	$result.=<<ADDMETA
                   7748: <meta http-equiv="pragma" content="no-cache" />
1.344     albertel 7749: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313     albertel 7750: ADDMETA
1.1075.2.89  raeburn  7751:     } else {
                   7752:         unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
                   7753:             my $requrl = $env{'request.uri'};
                   7754:             if ($requrl eq '') {
                   7755:                 $requrl = $ENV{'REQUEST_URI'};
                   7756:                 $requrl =~ s/\?.+$//;
                   7757:             }
                   7758:             unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
                   7759:                     (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
                   7760:                      ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
                   7761:                 my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
                   7762:                 unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
                   7763:                     my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
                   7764:                     if (ref($domdefs{'offloadnow'}) eq 'HASH') {
                   7765:                         my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
                   7766:                         if ($domdefs{'offloadnow'}{$lonhost}) {
                   7767:                             my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
                   7768:                             if (($newserver) && ($newserver ne $lonhost)) {
                   7769:                                 my $numsec = 5;
                   7770:                                 my $timeout = $numsec * 1000;
                   7771:                                 my ($newurl,$locknum,%locks,$msg);
                   7772:                                 if ($env{'request.role.adv'}) {
                   7773:                                     ($locknum,%locks) = &Apache::lonnet::get_locks();
                   7774:                                 }
                   7775:                                 my $disable_submit = 0;
                   7776:                                 if ($requrl =~ /$LONCAPA::assess_re/) {
                   7777:                                     $disable_submit = 1;
                   7778:                                 }
                   7779:                                 if ($locknum) {
                   7780:                                     my @lockinfo = sort(values(%locks));
                   7781:                                     $msg = &mt('Once the following tasks are complete: ')."\\n".
                   7782:                                            join(", ",sort(values(%locks)))."\\n".
                   7783:                                            &mt('your session will be transferred to a different server, after you click "Roles".');
                   7784:                                 } else {
                   7785:                                     if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
                   7786:                                         $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
                   7787:                                     }
                   7788:                                     $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
                   7789:                                     $newurl = '/adm/switchserver?otherserver='.$newserver;
                   7790:                                     if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
                   7791:                                         $newurl .= '&role='.$env{'request.role'};
                   7792:                                     }
                   7793:                                     if ($env{'request.symb'}) {
                   7794:                                         $newurl .= '&symb='.$env{'request.symb'};
                   7795:                                     } else {
                   7796:                                         $newurl .= '&origurl='.$requrl;
                   7797:                                     }
                   7798:                                 }
1.1075.2.98  raeburn  7799:                                 &js_escape(\$msg);
1.1075.2.89  raeburn  7800:                                 $result.=<<OFFLOAD
                   7801: <meta http-equiv="pragma" content="no-cache" />
                   7802: <script type="text/javascript">
1.1075.2.92  raeburn  7803: // <![CDATA[
1.1075.2.89  raeburn  7804: function LC_Offload_Now() {
                   7805:     var dest = "$newurl";
                   7806:     if (dest != '') {
                   7807:         window.location.href="$newurl";
                   7808:     }
                   7809: }
1.1075.2.92  raeburn  7810: \$(document).ready(function () {
                   7811:     window.alert('$msg');
                   7812:     if ($disable_submit) {
1.1075.2.89  raeburn  7813:         \$(".LC_hwk_submit").prop("disabled", true);
                   7814:         \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1075.2.92  raeburn  7815:     }
                   7816:     setTimeout('LC_Offload_Now()', $timeout);
                   7817: });
                   7818: // ]]>
1.1075.2.89  raeburn  7819: </script>
                   7820: OFFLOAD
                   7821:                             }
                   7822:                         }
                   7823:                     }
                   7824:                 }
                   7825:             }
                   7826:         }
1.313     albertel 7827:     }
1.306     albertel 7828:     if (!defined($title)) {
                   7829: 	$title = 'The LearningOnline Network with CAPA';
                   7830:     }
1.460     albertel 7831:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
                   7832:     $result .= '<title> LON-CAPA '.$title.'</title>'
1.1075.2.61  raeburn  7833: 	.'<link rel="stylesheet" type="text/css" href="'.$url.'"';
                   7834:     if (!$args->{'frameset'}) {
                   7835:         $result .= ' /';
                   7836:     }
                   7837:     $result .= '>'
1.1064    raeburn  7838:         .$inhibitprint
1.414     albertel 7839: 	.$head_extra;
1.1075.2.108  raeburn  7840:     my $clientmobile;
                   7841:     if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
                   7842:         (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
                   7843:     } else {
                   7844:         $clientmobile = $env{'browser.mobile'};
                   7845:     }
                   7846:     if ($clientmobile) {
1.1075.2.42  raeburn  7847:         $result .= '
                   7848: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
                   7849: <meta name="apple-mobile-web-app-capable" content="yes" />';
                   7850:     }
1.962     droeschl 7851:     return $result.'</head>';
1.306     albertel 7852: }
                   7853: 
                   7854: =pod
                   7855: 
1.340     albertel 7856: =item * &font_settings()
                   7857: 
                   7858: Returns neccessary <meta> to set the proper encoding
                   7859: 
1.1075.2.56  raeburn  7860: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340     albertel 7861: 
                   7862: =cut
                   7863: 
                   7864: sub font_settings {
1.1075.2.56  raeburn  7865:     my ($args) = @_;
1.340     albertel 7866:     my $headerstring='';
1.1075.2.56  raeburn  7867:     if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
                   7868:         ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340     albertel 7869: 	$headerstring.=
1.1075.2.61  raeburn  7870: 	    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
                   7871:         if (!$args->{'frameset'}) {
                   7872:             $headerstring.= ' /';
                   7873:         }
                   7874:         $headerstring .= '>'."\n";
1.340     albertel 7875:     }
                   7876:     return $headerstring;
                   7877: }
                   7878: 
1.341     albertel 7879: =pod
                   7880: 
1.1064    raeburn  7881: =item * &print_suppression()
                   7882: 
                   7883: In course context returns css which causes the body to be blank when media="print",
                   7884: if printout generation is unavailable for the current resource.
                   7885: 
                   7886: This could be because:
                   7887: 
                   7888: (a) printstartdate is in the future
                   7889: 
                   7890: (b) printenddate is in the past
                   7891: 
                   7892: (c) there is an active exam block with "printout"
                   7893: functionality blocked
                   7894: 
                   7895: Users with pav, pfo or evb privileges are exempt.
                   7896: 
                   7897: Inputs: none
                   7898: 
                   7899: =cut
                   7900: 
                   7901: 
                   7902: sub print_suppression {
                   7903:     my $noprint;
                   7904:     if ($env{'request.course.id'}) {
                   7905:         my $scope = $env{'request.course.id'};
                   7906:         if ((&Apache::lonnet::allowed('pav',$scope)) ||
                   7907:             (&Apache::lonnet::allowed('pfo',$scope))) {
                   7908:             return;
                   7909:         }
                   7910:         if ($env{'request.course.sec'} ne '') {
                   7911:             $scope .= "/$env{'request.course.sec'}";
                   7912:             if ((&Apache::lonnet::allowed('pav',$scope)) ||
                   7913:                 (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065    raeburn  7914:                 return;
1.1064    raeburn  7915:             }
                   7916:         }
                   7917:         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   7918:         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.73  raeburn  7919:         my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064    raeburn  7920:         if ($blocked) {
                   7921:             my $checkrole = "cm./$cdom/$cnum";
                   7922:             if ($env{'request.course.sec'} ne '') {
                   7923:                 $checkrole .= "/$env{'request.course.sec'}";
                   7924:             }
                   7925:             unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
                   7926:                     ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
                   7927:                 $noprint = 1;
                   7928:             }
                   7929:         }
                   7930:         unless ($noprint) {
                   7931:             my $symb = &Apache::lonnet::symbread();
                   7932:             if ($symb ne '') {
                   7933:                 my $navmap = Apache::lonnavmaps::navmap->new();
                   7934:                 if (ref($navmap)) {
                   7935:                     my $res = $navmap->getBySymb($symb);
                   7936:                     if (ref($res)) {
                   7937:                         if (!$res->resprintable()) {
                   7938:                             $noprint = 1;
                   7939:                         }
                   7940:                     }
                   7941:                 }
                   7942:             }
                   7943:         }
                   7944:         if ($noprint) {
                   7945:             return <<"ENDSTYLE";
                   7946: <style type="text/css" media="print">
                   7947:     body { display:none }
                   7948: </style>
                   7949: ENDSTYLE
                   7950:         }
                   7951:     }
                   7952:     return;
                   7953: }
                   7954: 
                   7955: =pod
                   7956: 
1.341     albertel 7957: =item * &xml_begin()
                   7958: 
                   7959: Returns the needed doctype and <html>
                   7960: 
                   7961: Inputs: none
                   7962: 
                   7963: =cut
                   7964: 
                   7965: sub xml_begin {
1.1075.2.61  raeburn  7966:     my ($is_frameset) = @_;
1.341     albertel 7967:     my $output='';
                   7968: 
                   7969:     if ($env{'browser.mathml'}) {
                   7970: 	$output='<?xml version="1.0"?>'
                   7971:             #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
                   7972: #            .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
                   7973:             
                   7974: #	    .'<!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">] >'
                   7975: 	    .'<!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">'
                   7976:             .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" ' 
                   7977: 	    .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61  raeburn  7978:     } elsif ($is_frameset) {
                   7979:         $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
                   7980:                 '<html>'."\n";
1.341     albertel 7981:     } else {
1.1075.2.61  raeburn  7982: 	$output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
                   7983:                 '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341     albertel 7984:     }
                   7985:     return $output;
                   7986: }
1.340     albertel 7987: 
                   7988: =pod
                   7989: 
1.306     albertel 7990: =item * &start_page()
                   7991: 
                   7992: Returns a complete <html> .. <body> section for LON-CAPA web pages.
                   7993: 
1.648     raeburn  7994: Inputs:
                   7995: 
                   7996: =over 4
                   7997: 
                   7998: $title - optional title for the page
                   7999: 
                   8000: $head_extra - optional extra HTML to incude inside the <head>
                   8001: 
                   8002: $args - additional optional args supported are:
                   8003: 
                   8004: =over 8
                   8005: 
                   8006:              only_body      -> is true will set &bodytag() onlybodytag
1.317     albertel 8007:                                     arg on
1.814     bisitz   8008:              no_nav_bar     -> is true will set &bodytag() no_nav_bar arg on
1.648     raeburn  8009:              add_entries    -> additional attributes to add to the  <body>
                   8010:              domain         -> force to color decorate a page for a 
1.317     albertel 8011:                                     specific domain
1.648     raeburn  8012:              function       -> force usage of a specific rolish color
1.317     albertel 8013:                                     scheme
1.648     raeburn  8014:              redirect       -> see &headtag()
                   8015:              bgcolor        -> override the default page bg color
                   8016:              js_ready       -> return a string ready for being used in 
1.317     albertel 8017:                                     a javascript writeln
1.648     raeburn  8018:              html_encode    -> return a string ready for being used in 
1.320     albertel 8019:                                     a html attribute
1.648     raeburn  8020:              force_register -> if is true will turn on the &bodytag()
1.317     albertel 8021:                                     $forcereg arg
1.648     raeburn  8022:              frameset       -> if true will start with a <frameset>
1.330     albertel 8023:                                     rather than <body>
1.648     raeburn  8024:              skip_phases    -> hash ref of 
1.338     albertel 8025:                                     head -> skip the <html><head> generation
                   8026:                                     body -> skip all <body> generation
1.1075.2.12  raeburn  8027:              no_inline_link -> if true and in remote mode, don't show the
                   8028:                                     'Switch To Inline Menu' link
1.648     raeburn  8029:              no_auto_mt_title -> prevent &mt()ing the title arg
1.867     kalberla 8030:              bread_crumbs ->             Array containing breadcrumbs
1.983     raeburn  8031:              bread_crumbs_component ->  if exists show it as headline else show only the breadcrumbs
1.1075.2.15  raeburn  8032:              group          -> includes the current group, if page is for a
                   8033:                                specific group
1.361     albertel 8034: 
1.648     raeburn  8035: =back
1.460     albertel 8036: 
1.648     raeburn  8037: =back
1.562     albertel 8038: 
1.306     albertel 8039: =cut
                   8040: 
                   8041: sub start_page {
1.309     albertel 8042:     my ($title,$head_extra,$args) = @_;
1.318     albertel 8043:     #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319     albertel 8044: 
1.315     albertel 8045:     $env{'internal.start_page'}++;
1.1075.2.15  raeburn  8046:     my ($result,@advtools);
1.964     droeschl 8047: 
1.338     albertel 8048:     if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62  raeburn  8049:         $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338     albertel 8050:     }
                   8051:     
                   8052:     if (! exists($args->{'skip_phases'}{'body'}) ) {
                   8053: 	if ($args->{'frameset'}) {
                   8054: 	    my $attr_string = &make_attr_string($args->{'force_register'},
                   8055: 						$args->{'add_entries'});
                   8056: 	    $result .= "\n<frameset $attr_string>\n";
1.831     bisitz   8057:         } else {
                   8058:             $result .=
                   8059:                 &bodytag($title, 
                   8060:                          $args->{'function'},       $args->{'add_entries'},
                   8061:                          $args->{'only_body'},      $args->{'domain'},
                   8062:                          $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12  raeburn  8063:                          $args->{'bgcolor'},        $args->{'no_inline_link'},
1.1075.2.15  raeburn  8064:                          $args,                     \@advtools);
1.831     bisitz   8065:         }
1.330     albertel 8066:     }
1.338     albertel 8067: 
1.315     albertel 8068:     if ($args->{'js_ready'}) {
1.713     kaisler  8069: 		$result = &js_ready($result);
1.315     albertel 8070:     }
1.320     albertel 8071:     if ($args->{'html_encode'}) {
1.713     kaisler  8072: 		$result = &html_encode($result);
                   8073:     }
                   8074: 
1.813     bisitz   8075:     # Preparation for new and consistent functionlist at top of screen
                   8076:     # if ($args->{'functionlist'}) {
                   8077:     #            $result .= &build_functionlist();
                   8078:     #}
                   8079: 
1.964     droeschl 8080:     # Don't add anything more if only_body wanted or in const space
                   8081:     return $result if    $args->{'only_body'} 
                   8082:                       || $env{'request.state'} eq 'construct';
1.813     bisitz   8083: 
                   8084:     #Breadcrumbs
1.758     kaisler  8085:     if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
                   8086: 		&Apache::lonhtmlcommon::clear_breadcrumbs();
                   8087: 		#if any br links exists, add them to the breadcrumbs
                   8088: 		if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {         
                   8089: 			foreach my $crumb (@{$args->{'bread_crumbs'}}){
                   8090: 				&Apache::lonhtmlcommon::add_breadcrumb($crumb);
                   8091: 			}
                   8092: 		}
1.1075.2.19  raeburn  8093:                 # if @advtools array contains items add then to the breadcrumbs
                   8094:                 if (@advtools > 0) {
                   8095:                     &Apache::lonmenu::advtools_crumbs(@advtools);
                   8096:                 }
1.758     kaisler  8097: 
                   8098: 		#if bread_crumbs_component exists show it as headline else show only the breadcrumbs
                   8099: 		if(exists($args->{'bread_crumbs_component'})){
                   8100: 			$result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
                   8101: 		}else{
                   8102: 			$result .= &Apache::lonhtmlcommon::breadcrumbs();
                   8103: 		}
1.1075.2.24  raeburn  8104:     } elsif (($env{'environment.remote'} eq 'on') &&
                   8105:              ($env{'form.inhibitmenu'} ne 'yes') &&
                   8106:              ($env{'request.noversionuri'} =~ m{^/res/}) &&
                   8107:              ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21  raeburn  8108:         $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320     albertel 8109:     }
1.315     albertel 8110:     return $result;
1.306     albertel 8111: }
                   8112: 
                   8113: sub end_page {
1.315     albertel 8114:     my ($args) = @_;
                   8115:     $env{'internal.end_page'}++;
1.330     albertel 8116:     my $result;
1.335     albertel 8117:     if ($args->{'discussion'}) {
                   8118: 	my ($target,$parser);
                   8119: 	if (ref($args->{'discussion'})) {
                   8120: 	    ($target,$parser) =($args->{'discussion'}{'target'},
                   8121: 				$args->{'discussion'}{'parser'});
                   8122: 	}
                   8123: 	$result .= &Apache::lonxml::xmlend($target,$parser);
                   8124:     }
1.330     albertel 8125:     if ($args->{'frameset'}) {
                   8126: 	$result .= '</frameset>';
                   8127:     } else {
1.635     raeburn  8128: 	$result .= &endbodytag($args);
1.330     albertel 8129:     }
1.1075.2.6  raeburn  8130:     unless ($args->{'notbody'}) {
                   8131:         $result .= "\n</html>";
                   8132:     }
1.330     albertel 8133: 
1.315     albertel 8134:     if ($args->{'js_ready'}) {
1.317     albertel 8135: 	$result = &js_ready($result);
1.315     albertel 8136:     }
1.335     albertel 8137: 
1.320     albertel 8138:     if ($args->{'html_encode'}) {
                   8139: 	$result = &html_encode($result);
                   8140:     }
1.335     albertel 8141: 
1.315     albertel 8142:     return $result;
                   8143: }
                   8144: 
1.1034    www      8145: sub wishlist_window {
                   8146:     return(<<'ENDWISHLIST');
1.1046    raeburn  8147: <script type="text/javascript">
1.1034    www      8148: // <![CDATA[
                   8149: // <!-- BEGIN LON-CAPA Internal
                   8150: function set_wishlistlink(title, path) {
                   8151:     if (!title) {
                   8152:         title = document.title;
                   8153:         title = title.replace(/^LON-CAPA /,'');
                   8154:     }
1.1075.2.65  raeburn  8155:     title = encodeURIComponent(title);
1.1075.2.83  raeburn  8156:     title = title.replace("'","\\\'");
1.1034    www      8157:     if (!path) {
                   8158:         path = location.pathname;
                   8159:     }
1.1075.2.65  raeburn  8160:     path = encodeURIComponent(path);
1.1075.2.83  raeburn  8161:     path = path.replace("'","\\\'");
1.1034    www      8162:     Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
                   8163:                       'wishlistNewLink','width=560,height=350,scrollbars=0');
                   8164: }
                   8165: // END LON-CAPA Internal -->
                   8166: // ]]>
                   8167: </script>
                   8168: ENDWISHLIST
                   8169: }
                   8170: 
1.1030    www      8171: sub modal_window {
                   8172:     return(<<'ENDMODAL');
1.1046    raeburn  8173: <script type="text/javascript">
1.1030    www      8174: // <![CDATA[
                   8175: // <!-- BEGIN LON-CAPA Internal
                   8176: var modalWindow = {
                   8177: 	parent:"body",
                   8178: 	windowId:null,
                   8179: 	content:null,
                   8180: 	width:null,
                   8181: 	height:null,
                   8182: 	close:function()
                   8183: 	{
                   8184: 	        $(".LCmodal-window").remove();
                   8185: 	        $(".LCmodal-overlay").remove();
                   8186: 	},
                   8187: 	open:function()
                   8188: 	{
                   8189: 		var modal = "";
                   8190: 		modal += "<div class=\"LCmodal-overlay\"></div>";
                   8191: 		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;\">";
                   8192: 		modal += this.content;
                   8193: 		modal += "</div>";	
                   8194: 
                   8195: 		$(this.parent).append(modal);
                   8196: 
                   8197: 		$(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
                   8198: 		$(".LCclose-window").click(function(){modalWindow.close();});
                   8199: 		$(".LCmodal-overlay").click(function(){modalWindow.close();});
                   8200: 	}
                   8201: };
1.1075.2.42  raeburn  8202: 	var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030    www      8203: 	{
1.1075.2.83  raeburn  8204:                 source = source.replace("'","&#39;");
1.1030    www      8205: 		modalWindow.windowId = "myModal";
                   8206: 		modalWindow.width = width;
                   8207: 		modalWindow.height = height;
1.1075.2.80  raeburn  8208: 		modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030    www      8209: 		modalWindow.open();
1.1075.2.87  raeburn  8210: 	};
1.1030    www      8211: // END LON-CAPA Internal -->
                   8212: // ]]>
                   8213: </script>
                   8214: ENDMODAL
                   8215: }
                   8216: 
                   8217: sub modal_link {
1.1075.2.42  raeburn  8218:     my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030    www      8219:     unless ($width) { $width=480; }
                   8220:     unless ($height) { $height=400; }
1.1031    www      8221:     unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42  raeburn  8222:     unless ($transparency) { $transparency='true'; }
                   8223: 
1.1074    raeburn  8224:     my $target_attr;
                   8225:     if (defined($target)) {
                   8226:         $target_attr = 'target="'.$target.'"';
                   8227:     }
                   8228:     return <<"ENDLINK";
1.1075.2.42  raeburn  8229: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074    raeburn  8230:            $linktext</a>
                   8231: ENDLINK
1.1030    www      8232: }
                   8233: 
1.1032    www      8234: sub modal_adhoc_script {
                   8235:     my ($funcname,$width,$height,$content)=@_;
                   8236:     return (<<ENDADHOC);
1.1046    raeburn  8237: <script type="text/javascript">
1.1032    www      8238: // <![CDATA[
                   8239:         var $funcname = function()
                   8240:         {
                   8241:                 modalWindow.windowId = "myModal";
                   8242:                 modalWindow.width = $width;
                   8243:                 modalWindow.height = $height;
                   8244:                 modalWindow.content = '$content';
                   8245:                 modalWindow.open();
                   8246:         };  
                   8247: // ]]>
                   8248: </script>
                   8249: ENDADHOC
                   8250: }
                   8251: 
1.1041    www      8252: sub modal_adhoc_inner {
                   8253:     my ($funcname,$width,$height,$content)=@_;
                   8254:     my $innerwidth=$width-20;
                   8255:     $content=&js_ready(
1.1042    www      8256:                &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42  raeburn  8257:                  &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
                   8258:                  $content.
1.1041    www      8259:                  &end_scrollbox().
1.1075.2.42  raeburn  8260:                  &end_page()
1.1041    www      8261:              );
                   8262:     return &modal_adhoc_script($funcname,$width,$height,$content);
                   8263: }
                   8264: 
                   8265: sub modal_adhoc_window {
                   8266:     my ($funcname,$width,$height,$content,$linktext)=@_;
                   8267:     return &modal_adhoc_inner($funcname,$width,$height,$content).
                   8268:            "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
                   8269: }
                   8270: 
                   8271: sub modal_adhoc_launch {
                   8272:     my ($funcname,$width,$height,$content)=@_;
                   8273:     return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
                   8274: <script type="text/javascript">
                   8275: // <![CDATA[
                   8276: $funcname();
                   8277: // ]]>
                   8278: </script>
                   8279: ENDLAUNCH
                   8280: }
                   8281: 
                   8282: sub modal_adhoc_close {
                   8283:     return (<<ENDCLOSE);
                   8284: <script type="text/javascript">
                   8285: // <![CDATA[
                   8286: modalWindow.close();
                   8287: // ]]>
                   8288: </script>
                   8289: ENDCLOSE
                   8290: }
                   8291: 
1.1038    www      8292: sub togglebox_script {
                   8293:    return(<<ENDTOGGLE);
                   8294: <script type="text/javascript"> 
                   8295: // <![CDATA[
                   8296: function LCtoggleDisplay(id,hidetext,showtext) {
                   8297:    link = document.getElementById(id + "link").childNodes[0];
                   8298:    with (document.getElementById(id).style) {
                   8299:       if (display == "none" ) {
                   8300:           display = "inline";
                   8301:           link.nodeValue = hidetext;
                   8302:         } else {
                   8303:           display = "none";
                   8304:           link.nodeValue = showtext;
                   8305:        }
                   8306:    }
                   8307: }
                   8308: // ]]>
                   8309: </script>
                   8310: ENDTOGGLE
                   8311: }
                   8312: 
1.1039    www      8313: sub start_togglebox {
                   8314:     my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
                   8315:     unless ($heading) { $heading=''; } else { $heading.=' '; }
                   8316:     unless ($showtext) { $showtext=&mt('show'); }
                   8317:     unless ($hidetext) { $hidetext=&mt('hide'); }
                   8318:     unless ($headerbg) { $headerbg='#FFFFFF'; }
                   8319:     return &start_data_table().
                   8320:            &start_data_table_header_row().
                   8321:            '<td bgcolor="'.$headerbg.'">'.$heading.
                   8322:            '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
                   8323:            $showtext.'\')">'.$showtext.'</a>]</td>'.
                   8324:            &end_data_table_header_row().
                   8325:            '<tr id="'.$id.'" style="display:none""><td>';
                   8326: }
                   8327: 
                   8328: sub end_togglebox {
                   8329:     return '</td></tr>'.&end_data_table();
                   8330: }
                   8331: 
1.1041    www      8332: sub LCprogressbar_script {
1.1045    www      8333:    my ($id)=@_;
1.1041    www      8334:    return(<<ENDPROGRESS);
                   8335: <script type="text/javascript">
                   8336: // <![CDATA[
1.1045    www      8337: \$('#progressbar$id').progressbar({
1.1041    www      8338:   value: 0,
                   8339:   change: function(event, ui) {
                   8340:     var newVal = \$(this).progressbar('option', 'value');
                   8341:     \$('.pblabel', this).text(LCprogressTxt);
                   8342:   }
                   8343: });
                   8344: // ]]>
                   8345: </script>
                   8346: ENDPROGRESS
                   8347: }
                   8348: 
                   8349: sub LCprogressbarUpdate_script {
                   8350:    return(<<ENDPROGRESSUPDATE);
                   8351: <style type="text/css">
                   8352: .ui-progressbar { position:relative; }
                   8353: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
                   8354: </style>
                   8355: <script type="text/javascript">
                   8356: // <![CDATA[
1.1045    www      8357: var LCprogressTxt='---';
                   8358: 
                   8359: function LCupdateProgress(percent,progresstext,id) {
1.1041    www      8360:    LCprogressTxt=progresstext;
1.1045    www      8361:    \$('#progressbar'+id).progressbar('value',percent);
1.1041    www      8362: }
                   8363: // ]]>
                   8364: </script>
                   8365: ENDPROGRESSUPDATE
                   8366: }
                   8367: 
1.1042    www      8368: my $LClastpercent;
1.1045    www      8369: my $LCidcnt;
                   8370: my $LCcurrentid;
1.1042    www      8371: 
1.1041    www      8372: sub LCprogressbar {
1.1042    www      8373:     my ($r)=(@_);
                   8374:     $LClastpercent=0;
1.1045    www      8375:     $LCidcnt++;
                   8376:     $LCcurrentid=$$.'_'.$LCidcnt;
1.1041    www      8377:     my $starting=&mt('Starting');
                   8378:     my $content=(<<ENDPROGBAR);
1.1045    www      8379:   <div id="progressbar$LCcurrentid">
1.1041    www      8380:     <span class="pblabel">$starting</span>
                   8381:   </div>
                   8382: ENDPROGBAR
1.1045    www      8383:     &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041    www      8384: }
                   8385: 
                   8386: sub LCprogressbarUpdate {
1.1042    www      8387:     my ($r,$val,$text)=@_;
                   8388:     unless ($val) { 
                   8389:        if ($LClastpercent) {
                   8390:            $val=$LClastpercent;
                   8391:        } else {
                   8392:            $val=0;
                   8393:        }
                   8394:     }
1.1041    www      8395:     if ($val<0) { $val=0; }
                   8396:     if ($val>100) { $val=0; }
1.1042    www      8397:     $LClastpercent=$val;
1.1041    www      8398:     unless ($text) { $text=$val.'%'; }
                   8399:     $text=&js_ready($text);
1.1044    www      8400:     &r_print($r,<<ENDUPDATE);
1.1041    www      8401: <script type="text/javascript">
                   8402: // <![CDATA[
1.1045    www      8403: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041    www      8404: // ]]>
                   8405: </script>
                   8406: ENDUPDATE
1.1035    www      8407: }
                   8408: 
1.1042    www      8409: sub LCprogressbarClose {
                   8410:     my ($r)=@_;
                   8411:     $LClastpercent=0;
1.1044    www      8412:     &r_print($r,<<ENDCLOSE);
1.1042    www      8413: <script type="text/javascript">
                   8414: // <![CDATA[
1.1045    www      8415: \$("#progressbar$LCcurrentid").hide('slow'); 
1.1042    www      8416: // ]]>
                   8417: </script>
                   8418: ENDCLOSE
1.1044    www      8419: }
                   8420: 
                   8421: sub r_print {
                   8422:     my ($r,$to_print)=@_;
                   8423:     if ($r) {
                   8424:       $r->print($to_print);
                   8425:       $r->rflush();
                   8426:     } else {
                   8427:       print($to_print);
                   8428:     }
1.1042    www      8429: }
                   8430: 
1.320     albertel 8431: sub html_encode {
                   8432:     my ($result) = @_;
                   8433: 
1.322     albertel 8434:     $result = &HTML::Entities::encode($result,'<>&"');
1.320     albertel 8435:     
                   8436:     return $result;
                   8437: }
1.1044    www      8438: 
1.317     albertel 8439: sub js_ready {
                   8440:     my ($result) = @_;
                   8441: 
1.323     albertel 8442:     $result =~ s/[\n\r]/ /xmsg;
                   8443:     $result =~ s/\\/\\\\/xmsg;
                   8444:     $result =~ s/'/\\'/xmsg;
1.372     albertel 8445:     $result =~ s{</}{<\\/}xmsg;
1.317     albertel 8446:     
                   8447:     return $result;
                   8448: }
                   8449: 
1.315     albertel 8450: sub validate_page {
                   8451:     if (  exists($env{'internal.start_page'})
1.316     albertel 8452: 	  &&     $env{'internal.start_page'} > 1) {
                   8453: 	&Apache::lonnet::logthis('start_page called multiple times '.
1.318     albertel 8454: 				 $env{'internal.start_page'}.' '.
1.316     albertel 8455: 				 $ENV{'request.filename'});
1.315     albertel 8456:     }
                   8457:     if (  exists($env{'internal.end_page'})
1.316     albertel 8458: 	  &&     $env{'internal.end_page'} > 1) {
                   8459: 	&Apache::lonnet::logthis('end_page called multiple times '.
1.318     albertel 8460: 				 $env{'internal.end_page'}.' '.
1.316     albertel 8461: 				 $env{'request.filename'});
1.315     albertel 8462:     }
                   8463:     if (     exists($env{'internal.start_page'})
                   8464: 	&& ! exists($env{'internal.end_page'})) {
1.316     albertel 8465: 	&Apache::lonnet::logthis('start_page called without end_page '.
                   8466: 				 $env{'request.filename'});
1.315     albertel 8467:     }
                   8468:     if (   ! exists($env{'internal.start_page'})
                   8469: 	&&   exists($env{'internal.end_page'})) {
1.316     albertel 8470: 	&Apache::lonnet::logthis('end_page called without start_page'.
                   8471: 				 $env{'request.filename'});
1.315     albertel 8472:     }
1.306     albertel 8473: }
1.315     albertel 8474: 
1.996     www      8475: 
                   8476: sub start_scrollbox {
1.1075.2.56  raeburn  8477:     my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998     raeburn  8478:     unless ($outerwidth) { $outerwidth='520px'; }
                   8479:     unless ($width) { $width='500px'; }
                   8480:     unless ($height) { $height='200px'; }
1.1075    raeburn  8481:     my ($table_id,$div_id,$tdcol);
1.1018    raeburn  8482:     if ($id ne '') {
1.1075.2.42  raeburn  8483:         $table_id = ' id="table_'.$id.'"';
                   8484:         $div_id = ' id="div_'.$id.'"';
1.1018    raeburn  8485:     }
1.1075    raeburn  8486:     if ($bgcolor ne '') {
                   8487:         $tdcol = "background-color: $bgcolor;";
                   8488:     }
1.1075.2.42  raeburn  8489:     my $nicescroll_js;
                   8490:     if ($env{'browser.mobile'}) {
                   8491:         $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
                   8492:     }
1.1075    raeburn  8493:     return <<"END";
1.1075.2.42  raeburn  8494: $nicescroll_js
                   8495: 
                   8496: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56  raeburn  8497: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075    raeburn  8498: END
1.996     www      8499: }
                   8500: 
                   8501: sub end_scrollbox {
1.1036    www      8502:     return '</div></td></tr></table>';
1.996     www      8503: }
                   8504: 
1.1075.2.42  raeburn  8505: sub nicescroll_javascript {
                   8506:     my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
                   8507:     my %options;
                   8508:     if (ref($cursor) eq 'HASH') {
                   8509:         %options = %{$cursor};
                   8510:     }
                   8511:     unless ($options{'railalign'} =~ /^left|right$/) {
                   8512:         $options{'railalign'} = 'left';
                   8513:     }
                   8514:     unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
                   8515:         my $function  = &get_users_function();
                   8516:         $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
                   8517:         unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
                   8518:             $options{'cursorcolor'} = '#00F';
                   8519:         }
                   8520:     }
                   8521:     if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
                   8522:         unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
                   8523:             $options{'cursoropacity'}='1.0';
                   8524:         }
                   8525:     } else {
                   8526:         $options{'cursoropacity'}='1.0';
                   8527:     }
                   8528:     if ($options{'cursorfixedheight'} eq 'none') {
                   8529:         delete($options{'cursorfixedheight'});
                   8530:     } else {
                   8531:         unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
                   8532:     }
                   8533:     unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
                   8534:         delete($options{'railoffset'});
                   8535:     }
                   8536:     my @niceoptions;
                   8537:     while (my($key,$value) = each(%options)) {
                   8538:         if ($value =~ /^\{.+\}$/) {
                   8539:             push(@niceoptions,$key.':'.$value);
                   8540:         } else {
                   8541:             push(@niceoptions,$key.':"'.$value.'"');
                   8542:         }
                   8543:     }
                   8544:     my $nicescroll_js = '
                   8545: $(document).ready(
                   8546:       function() {
                   8547:           $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
                   8548:       }
                   8549: );
                   8550: ';
                   8551:     if ($framecheck) {
                   8552:         $nicescroll_js .= '
                   8553: function expand_div(caller) {
                   8554:     if (top === self) {
                   8555:         document.getElementById("'.$id.'").style.width = "auto";
                   8556:         document.getElementById("'.$id.'").style.height = "auto";
                   8557:     } else {
                   8558:         try {
                   8559:             if (parent.frames) {
                   8560:                 if (parent.frames.length > 1) {
                   8561:                     var framesrc = parent.frames[1].location.href;
                   8562:                     var currsrc = framesrc.replace(/\#.*$/,"");
                   8563:                     if ((caller == "search") || (currsrc == "'.$location.'")) {
                   8564:                         document.getElementById("'.$id.'").style.width = "auto";
                   8565:                         document.getElementById("'.$id.'").style.height = "auto";
                   8566:                     }
                   8567:                 }
                   8568:             }
                   8569:         } catch (e) {
                   8570:             return;
                   8571:         }
                   8572:     }
                   8573:     return;
                   8574: }
                   8575: ';
                   8576:     }
                   8577:     if ($needjsready) {
                   8578:         $nicescroll_js = '
                   8579: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
                   8580:     } else {
                   8581:         $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
                   8582:     }
                   8583:     return $nicescroll_js;
                   8584: }
                   8585: 
1.318     albertel 8586: sub simple_error_page {
1.1075.2.49  raeburn  8587:     my ($r,$title,$msg,$args) = @_;
                   8588:     if (ref($args) eq 'HASH') {
                   8589:         if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
                   8590:     } else {
                   8591:         $msg = &mt($msg);
                   8592:     }
                   8593: 
1.318     albertel 8594:     my $page =
                   8595: 	&Apache::loncommon::start_page($title).
1.1075.2.49  raeburn  8596: 	'<p class="LC_error">'.$msg.'</p>'.
1.318     albertel 8597: 	&Apache::loncommon::end_page();
                   8598:     if (ref($r)) {
                   8599: 	$r->print($page);
1.327     albertel 8600: 	return;
1.318     albertel 8601:     }
                   8602:     return $page;
                   8603: }
1.347     albertel 8604: 
                   8605: {
1.610     albertel 8606:     my @row_count;
1.961     onken    8607: 
                   8608:     sub start_data_table_count {
                   8609:         unshift(@row_count, 0);
                   8610:         return;
                   8611:     }
                   8612: 
                   8613:     sub end_data_table_count {
                   8614:         shift(@row_count);
                   8615:         return;
                   8616:     }
                   8617: 
1.347     albertel 8618:     sub start_data_table {
1.1018    raeburn  8619: 	my ($add_class,$id) = @_;
1.422     albertel 8620: 	my $css_class = (join(' ','LC_data_table',$add_class));
1.1018    raeburn  8621:         my $table_id;
                   8622:         if (defined($id)) {
                   8623:             $table_id = ' id="'.$id.'"';
                   8624:         }
1.961     onken    8625: 	&start_data_table_count();
1.1018    raeburn  8626: 	return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347     albertel 8627:     }
                   8628: 
                   8629:     sub end_data_table {
1.961     onken    8630: 	&end_data_table_count();
1.389     albertel 8631: 	return '</table>'."\n";;
1.347     albertel 8632:     }
                   8633: 
                   8634:     sub start_data_table_row {
1.974     wenzelju 8635: 	my ($add_class, $id) = @_;
1.610     albertel 8636: 	$row_count[0]++;
                   8637: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900     bisitz   8638: 	$css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974     wenzelju 8639:         $id = (' id="'.$id.'"') unless ($id eq '');
                   8640:         return  '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347     albertel 8641:     }
1.471     banghart 8642:     
                   8643:     sub continue_data_table_row {
1.974     wenzelju 8644: 	my ($add_class, $id) = @_;
1.610     albertel 8645: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974     wenzelju 8646: 	$css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
                   8647:         $id = (' id="'.$id.'"') unless ($id eq '');
                   8648:         return  '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471     banghart 8649:     }
1.347     albertel 8650: 
                   8651:     sub end_data_table_row {
1.389     albertel 8652: 	return '</tr>'."\n";;
1.347     albertel 8653:     }
1.367     www      8654: 
1.421     albertel 8655:     sub start_data_table_empty_row {
1.707     bisitz   8656: #	$row_count[0]++;
1.421     albertel 8657: 	return  '<tr class="LC_empty_row" >'."\n";;
                   8658:     }
                   8659: 
                   8660:     sub end_data_table_empty_row {
                   8661: 	return '</tr>'."\n";;
                   8662:     }
                   8663: 
1.367     www      8664:     sub start_data_table_header_row {
1.389     albertel 8665: 	return  '<tr class="LC_header_row">'."\n";;
1.367     www      8666:     }
                   8667: 
                   8668:     sub end_data_table_header_row {
1.389     albertel 8669: 	return '</tr>'."\n";;
1.367     www      8670:     }
1.890     droeschl 8671: 
                   8672:     sub data_table_caption {
                   8673:         my $caption = shift;
                   8674:         return "<caption class=\"LC_caption\">$caption</caption>";
                   8675:     }
1.347     albertel 8676: }
                   8677: 
1.548     albertel 8678: =pod
                   8679: 
                   8680: =item * &inhibit_menu_check($arg)
                   8681: 
                   8682: Checks for a inhibitmenu state and generates output to preserve it
                   8683: 
                   8684: Inputs:         $arg - can be any of
                   8685:                      - undef - in which case the return value is a string 
                   8686:                                to add  into arguments list of a uri
                   8687:                      - 'input' - in which case the return value is a HTML
                   8688:                                  <form> <input> field of type hidden to
                   8689:                                  preserve the value
                   8690:                      - a url - in which case the return value is the url with
                   8691:                                the neccesary cgi args added to preserve the
                   8692:                                inhibitmenu state
                   8693:                      - a ref to a url - no return value, but the string is
                   8694:                                         updated to include the neccessary cgi
                   8695:                                         args to preserve the inhibitmenu state
                   8696: 
                   8697: =cut
                   8698: 
                   8699: sub inhibit_menu_check {
                   8700:     my ($arg) = @_;
                   8701:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   8702:     if ($arg eq 'input') {
                   8703: 	if ($env{'form.inhibitmenu'}) {
                   8704: 	    return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
                   8705: 	} else {
                   8706: 	    return
                   8707: 	}
                   8708:     }
                   8709:     if ($env{'form.inhibitmenu'}) {
                   8710: 	if (ref($arg)) {
                   8711: 	    $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   8712: 	} elsif ($arg eq '') {
                   8713: 	    $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
                   8714: 	} else {
                   8715: 	    $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   8716: 	}
                   8717:     }
                   8718:     if (!ref($arg)) {
                   8719: 	return $arg;
                   8720:     }
                   8721: }
                   8722: 
1.251     albertel 8723: ###############################################
1.182     matthew  8724: 
                   8725: =pod
                   8726: 
1.549     albertel 8727: =back
                   8728: 
                   8729: =head1 User Information Routines
                   8730: 
                   8731: =over 4
                   8732: 
1.405     albertel 8733: =item * &get_users_function()
1.182     matthew  8734: 
                   8735: Used by &bodytag to determine the current users primary role.
                   8736: Returns either 'student','coordinator','admin', or 'author'.
                   8737: 
                   8738: =cut
                   8739: 
                   8740: ###############################################
                   8741: sub get_users_function {
1.815     tempelho 8742:     my $function = 'norole';
1.818     tempelho 8743:     if ($env{'request.role'}=~/^(st)/) {
                   8744:         $function='student';
                   8745:     }
1.907     raeburn  8746:     if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182     matthew  8747:         $function='coordinator';
                   8748:     }
1.258     albertel 8749:     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182     matthew  8750:         $function='admin';
                   8751:     }
1.826     bisitz   8752:     if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025    raeburn  8753:         ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182     matthew  8754:         $function='author';
                   8755:     }
                   8756:     return $function;
1.54      www      8757: }
1.99      www      8758: 
                   8759: ###############################################
                   8760: 
1.233     raeburn  8761: =pod
                   8762: 
1.821     raeburn  8763: =item * &show_course()
                   8764: 
                   8765: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
                   8766: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
                   8767: 
                   8768: Inputs:
                   8769: None
                   8770: 
                   8771: Outputs:
                   8772: Scalar: 1 if 'Course' to be used, 0 otherwise.
                   8773: 
                   8774: =cut
                   8775: 
                   8776: ###############################################
                   8777: sub show_course {
                   8778:     my $course = !$env{'user.adv'};
                   8779:     if (!$env{'user.adv'}) {
                   8780:         foreach my $env (keys(%env)) {
                   8781:             next if ($env !~ m/^user\.priv\./);
                   8782:             if ($env !~ m/^user\.priv\.(?:st|cm)/) {
                   8783:                 $course = 0;
                   8784:                 last;
                   8785:             }
                   8786:         }
                   8787:     }
                   8788:     return $course;
                   8789: }
                   8790: 
                   8791: ###############################################
                   8792: 
                   8793: =pod
                   8794: 
1.542     raeburn  8795: =item * &check_user_status()
1.274     raeburn  8796: 
                   8797: Determines current status of supplied role for a
                   8798: specific user. Roles can be active, previous or future.
                   8799: 
                   8800: Inputs: 
                   8801: user's domain, user's username, course's domain,
1.375     raeburn  8802: course's number, optional section ID.
1.274     raeburn  8803: 
                   8804: Outputs:
                   8805: role status: active, previous or future. 
                   8806: 
                   8807: =cut
                   8808: 
                   8809: sub check_user_status {
1.412     raeburn  8810:     my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073    raeburn  8811:     my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85  raeburn  8812:     my @uroles = keys(%userinfo);
1.274     raeburn  8813:     my $srchstr;
                   8814:     my $active_chk = 'none';
1.412     raeburn  8815:     my $now = time;
1.274     raeburn  8816:     if (@uroles > 0) {
1.908     raeburn  8817:         if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274     raeburn  8818:             $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
                   8819:         } else {
1.412     raeburn  8820:             $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
                   8821:         }
                   8822:         if (grep/^\Q$srchstr\E$/,@uroles) {
1.274     raeburn  8823:             my $role_end = 0;
                   8824:             my $role_start = 0;
                   8825:             $active_chk = 'active';
1.412     raeburn  8826:             if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
                   8827:                 $role_end = $1;
                   8828:                 if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
                   8829:                     $role_start = $1;
1.274     raeburn  8830:                 }
                   8831:             }
                   8832:             if ($role_start > 0) {
1.412     raeburn  8833:                 if ($now < $role_start) {
1.274     raeburn  8834:                     $active_chk = 'future';
                   8835:                 }
                   8836:             }
                   8837:             if ($role_end > 0) {
1.412     raeburn  8838:                 if ($now > $role_end) {
1.274     raeburn  8839:                     $active_chk = 'previous';
                   8840:                 }
                   8841:             }
                   8842:         }
                   8843:     }
                   8844:     return $active_chk;
                   8845: }
                   8846: 
                   8847: ###############################################
                   8848: 
                   8849: =pod
                   8850: 
1.405     albertel 8851: =item * &get_sections()
1.233     raeburn  8852: 
                   8853: Determines all the sections for a course including
                   8854: sections with students and sections containing other roles.
1.419     raeburn  8855: Incoming parameters: 
                   8856: 
                   8857: 1. domain
                   8858: 2. course number 
                   8859: 3. reference to array containing roles for which sections should 
                   8860: be gathered (optional).
                   8861: 4. reference to array containing status types for which sections 
                   8862: should be gathered (optional).
                   8863: 
                   8864: If the third argument is undefined, sections are gathered for any role. 
                   8865: If the fourth argument is undefined, sections are gathered for any status.
                   8866: Permissible values are 'active' or 'future' or 'previous'.
1.233     raeburn  8867:  
1.374     raeburn  8868: Returns section hash (keys are section IDs, values are
                   8869: number of users in each section), subject to the
1.419     raeburn  8870: optional roles filter, optional status filter 
1.233     raeburn  8871: 
                   8872: =cut
                   8873: 
                   8874: ###############################################
                   8875: sub get_sections {
1.419     raeburn  8876:     my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366     albertel 8877:     if (!defined($cdom) || !defined($cnum)) {
                   8878:         my $cid =  $env{'request.course.id'};
                   8879: 
                   8880: 	return if (!defined($cid));
                   8881: 
                   8882:         $cdom = $env{'course.'.$cid.'.domain'};
                   8883:         $cnum = $env{'course.'.$cid.'.num'};
                   8884:     }
                   8885: 
                   8886:     my %sectioncount;
1.419     raeburn  8887:     my $now = time;
1.240     albertel 8888: 
1.1075.2.33  raeburn  8889:     my $check_students = 1;
                   8890:     my $only_students = 0;
                   8891:     if (ref($possible_roles) eq 'ARRAY') {
                   8892:         if (grep(/^st$/,@{$possible_roles})) {
                   8893:             if (@{$possible_roles} == 1) {
                   8894:                 $only_students = 1;
                   8895:             }
                   8896:         } else {
                   8897:             $check_students = 0;
                   8898:         }
                   8899:     }
                   8900: 
                   8901:     if ($check_students) {
1.276     albertel 8902: 	my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240     albertel 8903: 	my $sec_index = &Apache::loncoursedata::CL_SECTION();
                   8904: 	my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419     raeburn  8905:         my $start_index = &Apache::loncoursedata::CL_START();
                   8906:         my $end_index = &Apache::loncoursedata::CL_END();
                   8907:         my $status;
1.366     albertel 8908: 	while (my ($student,$data) = each(%$classlist)) {
1.419     raeburn  8909: 	    my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
                   8910: 				                     $data->[$status_index],
                   8911:                                                      $data->[$start_index],
                   8912:                                                      $data->[$end_index]);
                   8913:             if ($stu_status eq 'Active') {
                   8914:                 $status = 'active';
                   8915:             } elsif ($end < $now) {
                   8916:                 $status = 'previous';
                   8917:             } elsif ($start > $now) {
                   8918:                 $status = 'future';
                   8919:             } 
                   8920: 	    if ($section ne '-1' && $section !~ /^\s*$/) {
                   8921:                 if ((!defined($possible_status)) || (($status ne '') && 
                   8922:                     (grep/^\Q$status\E$/,@{$possible_status}))) { 
                   8923: 		    $sectioncount{$section}++;
                   8924:                 }
1.240     albertel 8925: 	    }
                   8926: 	}
                   8927:     }
1.1075.2.33  raeburn  8928:     if ($only_students) {
                   8929:         return %sectioncount;
                   8930:     }
1.240     albertel 8931:     my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   8932:     foreach my $user (sort(keys(%courseroles))) {
                   8933: 	if ($user !~ /^(\w{2})/) { next; }
                   8934: 	my ($role) = ($user =~ /^(\w{2})/);
                   8935: 	if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419     raeburn  8936: 	my ($section,$status);
1.240     albertel 8937: 	if ($role eq 'cr' &&
                   8938: 	    $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
                   8939: 	    $section=$1;
                   8940: 	}
                   8941: 	if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
                   8942: 	if (!defined($section) || $section eq '-1') { next; }
1.419     raeburn  8943:         my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
                   8944:         if ($end == -1 && $start == -1) {
                   8945:             next; #deleted role
                   8946:         }
                   8947:         if (!defined($possible_status)) { 
                   8948:             $sectioncount{$section}++;
                   8949:         } else {
                   8950:             if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
                   8951:                 $status = 'active';
                   8952:             } elsif ($end < $now) {
                   8953:                 $status = 'future';
                   8954:             } elsif ($start > $now) {
                   8955:                 $status = 'previous';
                   8956:             }
                   8957:             if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
                   8958:                 $sectioncount{$section}++;
                   8959:             }
                   8960:         }
1.233     raeburn  8961:     }
1.366     albertel 8962:     return %sectioncount;
1.233     raeburn  8963: }
                   8964: 
1.274     raeburn  8965: ###############################################
1.294     raeburn  8966: 
                   8967: =pod
1.405     albertel 8968: 
                   8969: =item * &get_course_users()
                   8970: 
1.275     raeburn  8971: Retrieves usernames:domains for users in the specified course
                   8972: with specific role(s), and access status. 
                   8973: 
                   8974: Incoming parameters:
1.277     albertel 8975: 1. course domain
                   8976: 2. course number
                   8977: 3. access status: users must have - either active, 
1.275     raeburn  8978: previous, future, or all.
1.277     albertel 8979: 4. reference to array of permissible roles
1.288     raeburn  8980: 5. reference to array of section restrictions (optional)
                   8981: 6. reference to results object (hash of hashes).
                   8982: 7. reference to optional userdata hash
1.609     raeburn  8983: 8. reference to optional statushash
1.630     raeburn  8984: 9. flag if privileged users (except those set to unhide in
                   8985:    course settings) should be excluded    
1.609     raeburn  8986: Keys of top level results hash are roles.
1.275     raeburn  8987: Keys of inner hashes are username:domain, with 
                   8988: values set to access type.
1.288     raeburn  8989: Optional userdata hash returns an array with arguments in the 
                   8990: same order as loncoursedata::get_classlist() for student data.
                   8991: 
1.609     raeburn  8992: Optional statushash returns
                   8993: 
1.288     raeburn  8994: Entries for end, start, section and status are blank because
                   8995: of the possibility of multiple values for non-student roles.
                   8996: 
1.275     raeburn  8997: =cut
1.405     albertel 8998: 
1.275     raeburn  8999: ###############################################
1.405     albertel 9000: 
1.275     raeburn  9001: sub get_course_users {
1.630     raeburn  9002:     my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288     raeburn  9003:     my %idx = ();
1.419     raeburn  9004:     my %seclists;
1.288     raeburn  9005: 
                   9006:     $idx{udom} = &Apache::loncoursedata::CL_SDOM();
                   9007:     $idx{uname} =  &Apache::loncoursedata::CL_SNAME();
                   9008:     $idx{end} = &Apache::loncoursedata::CL_END();
                   9009:     $idx{start} = &Apache::loncoursedata::CL_START();
                   9010:     $idx{id} = &Apache::loncoursedata::CL_ID();
                   9011:     $idx{section} = &Apache::loncoursedata::CL_SECTION();
                   9012:     $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
                   9013:     $idx{status} = &Apache::loncoursedata::CL_STATUS();
                   9014: 
1.290     albertel 9015:     if (grep(/^st$/,@{$roles})) {
1.276     albertel 9016:         my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278     raeburn  9017:         my $now = time;
1.277     albertel 9018:         foreach my $student (keys(%{$classlist})) {
1.288     raeburn  9019:             my $match = 0;
1.412     raeburn  9020:             my $secmatch = 0;
1.419     raeburn  9021:             my $section = $$classlist{$student}[$idx{section}];
1.609     raeburn  9022:             my $status = $$classlist{$student}[$idx{status}];
1.419     raeburn  9023:             if ($section eq '') {
                   9024:                 $section = 'none';
                   9025:             }
1.291     albertel 9026:             if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 9027:                 if (grep(/^all$/,@{$sections})) {
1.412     raeburn  9028:                     $secmatch = 1;
                   9029:                 } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420     albertel 9030:                     if (grep(/^none$/,@{$sections})) {
1.412     raeburn  9031:                         $secmatch = 1;
                   9032:                     }
                   9033:                 } else {  
1.419     raeburn  9034: 		    if (grep(/^\Q$section\E$/,@{$sections})) {
1.412     raeburn  9035: 		        $secmatch = 1;
                   9036:                     }
1.290     albertel 9037: 		}
1.412     raeburn  9038:                 if (!$secmatch) {
                   9039:                     next;
                   9040:                 }
1.419     raeburn  9041:             }
1.275     raeburn  9042:             if (defined($$types{'active'})) {
1.288     raeburn  9043:                 if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275     raeburn  9044:                     push(@{$$users{st}{$student}},'active');
1.288     raeburn  9045:                     $match = 1;
1.275     raeburn  9046:                 }
                   9047:             }
                   9048:             if (defined($$types{'previous'})) {
1.609     raeburn  9049:                 if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275     raeburn  9050:                     push(@{$$users{st}{$student}},'previous');
1.288     raeburn  9051:                     $match = 1;
1.275     raeburn  9052:                 }
                   9053:             }
                   9054:             if (defined($$types{'future'})) {
1.609     raeburn  9055:                 if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275     raeburn  9056:                     push(@{$$users{st}{$student}},'future');
1.288     raeburn  9057:                     $match = 1;
1.275     raeburn  9058:                 }
                   9059:             }
1.609     raeburn  9060:             if ($match) {
                   9061:                 push(@{$seclists{$student}},$section);
                   9062:                 if (ref($userdata) eq 'HASH') {
                   9063:                     $$userdata{$student} = $$classlist{$student};
                   9064:                 }
                   9065:                 if (ref($statushash) eq 'HASH') {
                   9066:                     $statushash->{$student}{'st'}{$section} = $status;
                   9067:                 }
1.288     raeburn  9068:             }
1.275     raeburn  9069:         }
                   9070:     }
1.412     raeburn  9071:     if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439     raeburn  9072:         my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   9073:         my $now = time;
1.609     raeburn  9074:         my %displaystatus = ( previous => 'Expired',
                   9075:                               active   => 'Active',
                   9076:                               future   => 'Future',
                   9077:                             );
1.1075.2.36  raeburn  9078:         my (%nothide,@possdoms);
1.630     raeburn  9079:         if ($hidepriv) {
                   9080:             my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
                   9081:             foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
                   9082:                 if ($user !~ /:/) {
                   9083:                     $nothide{join(':',split(/[\@]/,$user))}=1;
                   9084:                 } else {
                   9085:                     $nothide{$user} = 1;
                   9086:                 }
                   9087:             }
1.1075.2.36  raeburn  9088:             my @possdoms = ($cdom);
                   9089:             if ($coursehash{'checkforpriv'}) {
                   9090:                 push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
                   9091:             }
1.630     raeburn  9092:         }
1.439     raeburn  9093:         foreach my $person (sort(keys(%coursepersonnel))) {
1.288     raeburn  9094:             my $match = 0;
1.412     raeburn  9095:             my $secmatch = 0;
1.439     raeburn  9096:             my $status;
1.412     raeburn  9097:             my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275     raeburn  9098:             $user =~ s/:$//;
1.439     raeburn  9099:             my ($end,$start) = split(/:/,$coursepersonnel{$person});
                   9100:             if ($end == -1 || $start == -1) {
                   9101:                 next;
                   9102:             }
                   9103:             if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
                   9104:                 (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412     raeburn  9105:                 my ($uname,$udom) = split(/:/,$user);
                   9106:                 if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 9107:                     if (grep(/^all$/,@{$sections})) {
1.412     raeburn  9108:                         $secmatch = 1;
                   9109:                     } elsif ($usec eq '') {
1.420     albertel 9110:                         if (grep(/^none$/,@{$sections})) {
1.412     raeburn  9111:                             $secmatch = 1;
                   9112:                         }
                   9113:                     } else {
                   9114:                         if (grep(/^\Q$usec\E$/,@{$sections})) {
                   9115:                             $secmatch = 1;
                   9116:                         }
                   9117:                     }
                   9118:                     if (!$secmatch) {
                   9119:                         next;
                   9120:                     }
1.288     raeburn  9121:                 }
1.419     raeburn  9122:                 if ($usec eq '') {
                   9123:                     $usec = 'none';
                   9124:                 }
1.275     raeburn  9125:                 if ($uname ne '' && $udom ne '') {
1.630     raeburn  9126:                     if ($hidepriv) {
1.1075.2.36  raeburn  9127:                         if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630     raeburn  9128:                             (!$nothide{$uname.':'.$udom})) {
                   9129:                             next;
                   9130:                         }
                   9131:                     }
1.503     raeburn  9132:                     if ($end > 0 && $end < $now) {
1.439     raeburn  9133:                         $status = 'previous';
                   9134:                     } elsif ($start > $now) {
                   9135:                         $status = 'future';
                   9136:                     } else {
                   9137:                         $status = 'active';
                   9138:                     }
1.277     albertel 9139:                     foreach my $type (keys(%{$types})) { 
1.275     raeburn  9140:                         if ($status eq $type) {
1.420     albertel 9141:                             if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419     raeburn  9142:                                 push(@{$$users{$role}{$user}},$type);
                   9143:                             }
1.288     raeburn  9144:                             $match = 1;
                   9145:                         }
                   9146:                     }
1.419     raeburn  9147:                     if (($match) && (ref($userdata) eq 'HASH')) {
                   9148:                         if (!exists($$userdata{$uname.':'.$udom})) {
                   9149: 			    &get_user_info($udom,$uname,\%idx,$userdata);
                   9150:                         }
1.420     albertel 9151:                         if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419     raeburn  9152:                             push(@{$seclists{$uname.':'.$udom}},$usec);
                   9153:                         }
1.609     raeburn  9154:                         if (ref($statushash) eq 'HASH') {
                   9155:                             $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
                   9156:                         }
1.275     raeburn  9157:                     }
                   9158:                 }
                   9159:             }
                   9160:         }
1.290     albertel 9161:         if (grep(/^ow$/,@{$roles})) {
1.279     raeburn  9162:             if ((defined($cdom)) && (defined($cnum))) {
                   9163:                 my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
                   9164:                 if ( defined($csettings{'internal.courseowner'}) ) {
                   9165:                     my $owner = $csettings{'internal.courseowner'};
1.609     raeburn  9166:                     next if ($owner eq '');
                   9167:                     my ($ownername,$ownerdom);
                   9168:                     if ($owner =~ /^([^:]+):([^:]+)$/) {
                   9169:                         $ownername = $1;
                   9170:                         $ownerdom = $2;
                   9171:                     } else {
                   9172:                         $ownername = $owner;
                   9173:                         $ownerdom = $cdom;
                   9174:                         $owner = $ownername.':'.$ownerdom;
1.439     raeburn  9175:                     }
                   9176:                     @{$$users{'ow'}{$owner}} = 'any';
1.290     albertel 9177:                     if (defined($userdata) && 
1.609     raeburn  9178: 			!exists($$userdata{$owner})) {
                   9179: 			&get_user_info($ownerdom,$ownername,\%idx,$userdata);
                   9180:                         if (!grep(/^none$/,@{$seclists{$owner}})) {
                   9181:                             push(@{$seclists{$owner}},'none');
                   9182:                         }
                   9183:                         if (ref($statushash) eq 'HASH') {
                   9184:                             $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419     raeburn  9185:                         }
1.290     albertel 9186: 		    }
1.279     raeburn  9187:                 }
                   9188:             }
                   9189:         }
1.419     raeburn  9190:         foreach my $user (keys(%seclists)) {
                   9191:             @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
                   9192:             $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
                   9193:         }
1.275     raeburn  9194:     }
                   9195:     return;
                   9196: }
                   9197: 
1.288     raeburn  9198: sub get_user_info {
                   9199:     my ($udom,$uname,$idx,$userdata) = @_;
1.289     albertel 9200:     $$userdata{$uname.':'.$udom}[$$idx{fullname}] = 
                   9201: 	&plainname($uname,$udom,'lastname');
1.291     albertel 9202:     $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297     raeburn  9203:     $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609     raeburn  9204:     my %idhash =  &Apache::lonnet::idrget($udom,($uname));
                   9205:     $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname}; 
1.288     raeburn  9206:     return;
                   9207: }
1.275     raeburn  9208: 
1.472     raeburn  9209: ###############################################
                   9210: 
                   9211: =pod
                   9212: 
                   9213: =item * &get_user_quota()
                   9214: 
1.1075.2.41  raeburn  9215: Retrieves quota assigned for storage of user files.
                   9216: Default is to report quota for portfolio files.
1.472     raeburn  9217: 
                   9218: Incoming parameters:
                   9219: 1. user's username
                   9220: 2. user's domain
1.1075.2.41  raeburn  9221: 3. quota name - portfolio, author, or course
                   9222:    (if no quota name provided, defaults to portfolio).
1.1075.2.59  raeburn  9223: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42  raeburn  9224:    course
1.472     raeburn  9225: 
                   9226: Returns:
1.1075.2.58  raeburn  9227: 1. Disk quota (in MB) assigned to student.
1.536     raeburn  9228: 2. (Optional) Type of setting: custom or default
                   9229:    (individually assigned or default for user's 
                   9230:    institutional status).
                   9231: 3. (Optional) - User's institutional status (e.g., faculty, staff
                   9232:    or student - types as defined in localenroll::inst_usertypes 
                   9233:    for user's domain, which determines default quota for user.
                   9234: 4. (Optional) - Default quota which would apply to the user.
1.472     raeburn  9235: 
                   9236: If a value has been stored in the user's environment, 
1.536     raeburn  9237: it will return that, otherwise it returns the maximal default
1.1075.2.41  raeburn  9238: defined for the user's institutional status(es) in the domain.
1.472     raeburn  9239: 
                   9240: =cut
                   9241: 
                   9242: ###############################################
                   9243: 
                   9244: 
                   9245: sub get_user_quota {
1.1075.2.42  raeburn  9246:     my ($uname,$udom,$quotaname,$crstype) = @_;
1.536     raeburn  9247:     my ($quota,$quotatype,$settingstatus,$defquota);
1.472     raeburn  9248:     if (!defined($udom)) {
                   9249:         $udom = $env{'user.domain'};
                   9250:     }
                   9251:     if (!defined($uname)) {
                   9252:         $uname = $env{'user.name'};
                   9253:     }
                   9254:     if (($udom eq '' || $uname eq '') ||
                   9255:         ($udom eq 'public') && ($uname eq 'public')) {
                   9256:         $quota = 0;
1.536     raeburn  9257:         $quotatype = 'default';
                   9258:         $defquota = 0; 
1.472     raeburn  9259:     } else {
1.536     raeburn  9260:         my $inststatus;
1.1075.2.41  raeburn  9261:         if ($quotaname eq 'course') {
                   9262:             if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
                   9263:                 ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
                   9264:                 $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
                   9265:             } else {
                   9266:                 my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
                   9267:                 $quota = $cenv{'internal.uploadquota'};
                   9268:             }
1.536     raeburn  9269:         } else {
1.1075.2.41  raeburn  9270:             if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
                   9271:                 if ($quotaname eq 'author') {
                   9272:                     $quota = $env{'environment.authorquota'};
                   9273:                 } else {
                   9274:                     $quota = $env{'environment.portfolioquota'};
                   9275:                 }
                   9276:                 $inststatus = $env{'environment.inststatus'};
                   9277:             } else {
                   9278:                 my %userenv = 
                   9279:                     &Apache::lonnet::get('environment',['portfolioquota',
                   9280:                                          'authorquota','inststatus'],$udom,$uname);
                   9281:                 my ($tmp) = keys(%userenv);
                   9282:                 if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   9283:                     if ($quotaname eq 'author') {
                   9284:                         $quota = $userenv{'authorquota'};
                   9285:                     } else {
                   9286:                         $quota = $userenv{'portfolioquota'};
                   9287:                     }
                   9288:                     $inststatus = $userenv{'inststatus'};
                   9289:                 } else {
                   9290:                     undef(%userenv);
                   9291:                 }
                   9292:             }
                   9293:         }
                   9294:         if ($quota eq '' || wantarray) {
                   9295:             if ($quotaname eq 'course') {
                   9296:                 my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59  raeburn  9297:                 if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
                   9298:                     ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42  raeburn  9299:                     $defquota = $domdefs{$crstype.'quota'};
                   9300:                 }
                   9301:                 if ($defquota eq '') {
                   9302:                     $defquota = 500;
                   9303:                 }
1.1075.2.41  raeburn  9304:             } else {
                   9305:                 ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
                   9306:             }
                   9307:             if ($quota eq '') {
                   9308:                 $quota = $defquota;
                   9309:                 $quotatype = 'default';
                   9310:             } else {
                   9311:                 $quotatype = 'custom';
                   9312:             }
1.472     raeburn  9313:         }
                   9314:     }
1.536     raeburn  9315:     if (wantarray) {
                   9316:         return ($quota,$quotatype,$settingstatus,$defquota);
                   9317:     } else {
                   9318:         return $quota;
                   9319:     }
1.472     raeburn  9320: }
                   9321: 
                   9322: ###############################################
                   9323: 
                   9324: =pod
                   9325: 
                   9326: =item * &default_quota()
                   9327: 
1.536     raeburn  9328: Retrieves default quota assigned for storage of user portfolio files,
                   9329: given an (optional) user's institutional status.
1.472     raeburn  9330: 
                   9331: Incoming parameters:
1.1075.2.42  raeburn  9332: 
1.472     raeburn  9333: 1. domain
1.536     raeburn  9334: 2. (Optional) institutional status(es).  This is a : separated list of 
                   9335:    status types (e.g., faculty, staff, student etc.)
                   9336:    which apply to the user for whom the default is being retrieved.
                   9337:    If the institutional status string in undefined, the domain
1.1075.2.41  raeburn  9338:    default quota will be returned.
                   9339: 3.  quota name - portfolio, author, or course
                   9340:    (if no quota name provided, defaults to portfolio).
1.472     raeburn  9341: 
                   9342: Returns:
1.1075.2.42  raeburn  9343: 
1.1075.2.58  raeburn  9344: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536     raeburn  9345: 2. (Optional) institutional type which determined the value of the
                   9346:    default quota.
1.472     raeburn  9347: 
                   9348: If a value has been stored in the domain's configuration db,
                   9349: it will return that, otherwise it returns 20 (for backwards 
                   9350: compatibility with domains which have not set up a configuration
1.1075.2.58  raeburn  9351: db file; the original statically defined portfolio quota was 20 MB). 
1.472     raeburn  9352: 
1.536     raeburn  9353: If the user's status includes multiple types (e.g., staff and student),
                   9354: the largest default quota which applies to the user determines the
                   9355: default quota returned.
                   9356: 
1.472     raeburn  9357: =cut
                   9358: 
                   9359: ###############################################
                   9360: 
                   9361: 
                   9362: sub default_quota {
1.1075.2.41  raeburn  9363:     my ($udom,$inststatus,$quotaname) = @_;
1.536     raeburn  9364:     my ($defquota,$settingstatus);
                   9365:     my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622     raeburn  9366:                                             ['quotas'],$udom);
1.1075.2.41  raeburn  9367:     my $key = 'defaultquota';
                   9368:     if ($quotaname eq 'author') {
                   9369:         $key = 'authorquota';
                   9370:     }
1.622     raeburn  9371:     if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536     raeburn  9372:         if ($inststatus ne '') {
1.765     raeburn  9373:             my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536     raeburn  9374:             foreach my $item (@statuses) {
1.1075.2.41  raeburn  9375:                 if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
                   9376:                     if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711     raeburn  9377:                         if ($defquota eq '') {
1.1075.2.41  raeburn  9378:                             $defquota = $quotahash{'quotas'}{$key}{$item};
1.711     raeburn  9379:                             $settingstatus = $item;
1.1075.2.41  raeburn  9380:                         } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
                   9381:                             $defquota = $quotahash{'quotas'}{$key}{$item};
1.711     raeburn  9382:                             $settingstatus = $item;
                   9383:                         }
                   9384:                     }
1.1075.2.41  raeburn  9385:                 } elsif ($key eq 'defaultquota') {
1.711     raeburn  9386:                     if ($quotahash{'quotas'}{$item} ne '') {
                   9387:                         if ($defquota eq '') {
                   9388:                             $defquota = $quotahash{'quotas'}{$item};
                   9389:                             $settingstatus = $item;
                   9390:                         } elsif ($quotahash{'quotas'}{$item} > $defquota) {
                   9391:                             $defquota = $quotahash{'quotas'}{$item};
                   9392:                             $settingstatus = $item;
                   9393:                         }
1.536     raeburn  9394:                     }
                   9395:                 }
                   9396:             }
                   9397:         }
                   9398:         if ($defquota eq '') {
1.1075.2.41  raeburn  9399:             if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
                   9400:                 $defquota = $quotahash{'quotas'}{$key}{'default'};
                   9401:             } elsif ($key eq 'defaultquota') {
1.711     raeburn  9402:                 $defquota = $quotahash{'quotas'}{'default'};
                   9403:             }
1.536     raeburn  9404:             $settingstatus = 'default';
1.1075.2.42  raeburn  9405:             if ($defquota eq '') {
                   9406:                 if ($quotaname eq 'author') {
                   9407:                     $defquota = 500;
                   9408:                 }
                   9409:             }
1.536     raeburn  9410:         }
                   9411:     } else {
                   9412:         $settingstatus = 'default';
1.1075.2.41  raeburn  9413:         if ($quotaname eq 'author') {
                   9414:             $defquota = 500;
                   9415:         } else {
                   9416:             $defquota = 20;
                   9417:         }
1.536     raeburn  9418:     }
                   9419:     if (wantarray) {
                   9420:         return ($defquota,$settingstatus);
1.472     raeburn  9421:     } else {
1.536     raeburn  9422:         return $defquota;
1.472     raeburn  9423:     }
                   9424: }
                   9425: 
1.1075.2.41  raeburn  9426: ###############################################
                   9427: 
                   9428: =pod
                   9429: 
1.1075.2.42  raeburn  9430: =item * &excess_filesize_warning()
1.1075.2.41  raeburn  9431: 
                   9432: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42  raeburn  9433: of existing file within authoring space will cause quota for the authoring
                   9434: space to be exceeded.
                   9435: 
                   9436: Same, if upload of a file directly to a course/community via Course Editor
                   9437: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41  raeburn  9438: 
1.1075.2.61  raeburn  9439: Inputs: 7 
1.1075.2.42  raeburn  9440: 1. username or coursenum
1.1075.2.41  raeburn  9441: 2. domain
1.1075.2.42  raeburn  9442: 3. context ('author' or 'course')
1.1075.2.41  raeburn  9443: 4. filename of file for which action is being requested
                   9444: 5. filesize (kB) of file
                   9445: 6. action being taken: copy or upload.
1.1075.2.59  raeburn  9446: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41  raeburn  9447: 
                   9448: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
                   9449:          otherwise return null.
                   9450: 
1.1075.2.42  raeburn  9451: =back
                   9452: 
1.1075.2.41  raeburn  9453: =cut
                   9454: 
1.1075.2.42  raeburn  9455: sub excess_filesize_warning {
1.1075.2.59  raeburn  9456:     my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42  raeburn  9457:     my $current_disk_usage = 0;
1.1075.2.59  raeburn  9458:     my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42  raeburn  9459:     if ($context eq 'author') {
                   9460:         my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
                   9461:         $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
                   9462:     } else {
                   9463:         foreach my $subdir ('docs','supplemental') {
                   9464:             $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
                   9465:         }
                   9466:     }
1.1075.2.41  raeburn  9467:     $disk_quota = int($disk_quota * 1000);
                   9468:     if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69  raeburn  9469:         return '<p class="LC_warning">'.
1.1075.2.41  raeburn  9470:                 &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69  raeburn  9471:                     '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
                   9472:                '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41  raeburn  9473:                             $disk_quota,$current_disk_usage).
                   9474:                '</p>';
                   9475:     }
                   9476:     return;
                   9477: }
                   9478: 
                   9479: ###############################################
                   9480: 
                   9481: 
1.384     raeburn  9482: sub get_secgrprole_info {
                   9483:     my ($cdom,$cnum,$needroles,$type)  = @_;
                   9484:     my %sections_count = &get_sections($cdom,$cnum);
                   9485:     my @sections =  (sort {$a <=> $b} keys(%sections_count));
                   9486:     my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
                   9487:     my @groups = sort(keys(%curr_groups));
                   9488:     my $allroles = [];
                   9489:     my $rolehash;
                   9490:     my $accesshash = {
                   9491:                      active => 'Currently has access',
                   9492:                      future => 'Will have future access',
                   9493:                      previous => 'Previously had access',
                   9494:                   };
                   9495:     if ($needroles) {
                   9496:         $rolehash = {'all' => 'all'};
1.385     albertel 9497:         my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   9498: 	if (&Apache::lonnet::error(%user_roles)) {
                   9499: 	    undef(%user_roles);
                   9500: 	}
                   9501:         foreach my $item (keys(%user_roles)) {
1.384     raeburn  9502:             my ($role)=split(/\:/,$item,2);
                   9503:             if ($role eq 'cr') { next; }
                   9504:             if ($role =~ /^cr/) {
                   9505:                 $$rolehash{$role} = (split('/',$role))[3];
                   9506:             } else {
                   9507:                 $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
                   9508:             }
                   9509:         }
                   9510:         foreach my $key (sort(keys(%{$rolehash}))) {
                   9511:             push(@{$allroles},$key);
                   9512:         }
                   9513:         push (@{$allroles},'st');
                   9514:         $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
                   9515:     }
                   9516:     return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
                   9517: }
                   9518: 
1.555     raeburn  9519: sub user_picker {
1.1075.2.115  raeburn  9520:     my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom) = @_;
1.555     raeburn  9521:     my $currdom = $dom;
1.1075.2.114  raeburn  9522:     my @alldoms = &Apache::lonnet::all_domains();
                   9523:     if (@alldoms == 1) {
                   9524:         my %domsrch = &Apache::lonnet::get_dom('configuration',
                   9525:                                                ['directorysrch'],$alldoms[0]);
                   9526:         my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
                   9527:         my $showdom = $domdesc;
                   9528:         if ($showdom eq '') {
                   9529:             $showdom = $dom;
                   9530:         }
                   9531:         if (ref($domsrch{'directorysrch'}) eq 'HASH') {
                   9532:             if ((!$domsrch{'directorysrch'}{'available'}) &&
                   9533:                 ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
                   9534:                 return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
                   9535:             }
                   9536:         }
                   9537:     }
1.555     raeburn  9538:     my %curr_selected = (
                   9539:                         srchin => 'dom',
1.580     raeburn  9540:                         srchby => 'lastname',
1.555     raeburn  9541:                       );
                   9542:     my $srchterm;
1.625     raeburn  9543:     if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555     raeburn  9544:         if ($srch->{'srchby'} ne '') {
                   9545:             $curr_selected{'srchby'} = $srch->{'srchby'};
                   9546:         }
                   9547:         if ($srch->{'srchin'} ne '') {
                   9548:             $curr_selected{'srchin'} = $srch->{'srchin'};
                   9549:         }
                   9550:         if ($srch->{'srchtype'} ne '') {
                   9551:             $curr_selected{'srchtype'} = $srch->{'srchtype'};
                   9552:         }
                   9553:         if ($srch->{'srchdomain'} ne '') {
                   9554:             $currdom = $srch->{'srchdomain'};
                   9555:         }
                   9556:         $srchterm = $srch->{'srchterm'};
                   9557:     }
1.1075.2.98  raeburn  9558:     my %html_lt=&Apache::lonlocal::texthash(
1.573     raeburn  9559:                     'usr'       => 'Search criteria',
1.563     raeburn  9560:                     'doma'      => 'Domain/institution to search',
1.558     albertel 9561:                     'uname'     => 'username',
                   9562:                     'lastname'  => 'last name',
1.555     raeburn  9563:                     'lastfirst' => 'last name, first name',
1.558     albertel 9564:                     'crs'       => 'in this course',
1.576     raeburn  9565:                     'dom'       => 'in selected LON-CAPA domain', 
1.558     albertel 9566:                     'alc'       => 'all LON-CAPA',
1.573     raeburn  9567:                     'instd'     => 'in institutional directory for selected domain',
1.558     albertel 9568:                     'exact'     => 'is',
                   9569:                     'contains'  => 'contains',
1.569     raeburn  9570:                     'begins'    => 'begins with',
1.1075.2.98  raeburn  9571:                                        );
                   9572:     my %js_lt=&Apache::lonlocal::texthash(
1.571     raeburn  9573:                     'youm'      => "You must include some text to search for.",
                   9574:                     'thte'      => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
                   9575:                     'thet'      => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
                   9576:                     'yomc'      => "You must choose a domain when using an institutional directory search.",
                   9577:                     'ymcd'      => "You must choose a domain when using a domain search.",
                   9578:                     'whus'      => "When using searching by last,first you must include a comma as separator between last name and first name.",
                   9579:                     'whse'      => "When searching by last,first you must include at least one character in the first name.",
                   9580:                      'thfo'     => "The following need to be corrected before the search can be run:",
1.555     raeburn  9581:                                        );
1.1075.2.98  raeburn  9582:     &html_escape(\%html_lt);
                   9583:     &js_escape(\%js_lt);
1.1075.2.115  raeburn  9584:     my $domform;
                   9585:     if ($fixeddom) {
                   9586:         $domform = &select_dom_form($currdom,'srchdomain',1,1,undef,[$currdom]);
                   9587:     } else {
                   9588:         $domform = &select_dom_form($currdom,'srchdomain',1,1);
                   9589:     }
1.563     raeburn  9590:     my $srchinsel = ' <select name="srchin">';
1.555     raeburn  9591: 
                   9592:     my @srchins = ('crs','dom','alc','instd');
                   9593: 
                   9594:     foreach my $option (@srchins) {
                   9595:         # FIXME 'alc' option unavailable until 
                   9596:         #       loncreateuser::print_user_query_page()
                   9597:         #       has been completed.
                   9598:         next if ($option eq 'alc');
1.880     raeburn  9599:         next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));  
1.555     raeburn  9600:         next if ($option eq 'crs' && !$env{'request.course.id'});
1.563     raeburn  9601:         if ($curr_selected{'srchin'} eq $option) {
                   9602:             $srchinsel .= ' 
1.1075.2.98  raeburn  9603:    <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563     raeburn  9604:         } else {
                   9605:             $srchinsel .= '
1.1075.2.98  raeburn  9606:    <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563     raeburn  9607:         }
1.555     raeburn  9608:     }
1.563     raeburn  9609:     $srchinsel .= "\n  </select>\n";
1.555     raeburn  9610: 
                   9611:     my $srchbysel =  ' <select name="srchby">';
1.580     raeburn  9612:     foreach my $option ('lastname','lastfirst','uname') {
1.555     raeburn  9613:         if ($curr_selected{'srchby'} eq $option) {
                   9614:             $srchbysel .= '
1.1075.2.98  raeburn  9615:    <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555     raeburn  9616:         } else {
                   9617:             $srchbysel .= '
1.1075.2.98  raeburn  9618:    <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555     raeburn  9619:          }
                   9620:     }
                   9621:     $srchbysel .= "\n  </select>\n";
                   9622: 
                   9623:     my $srchtypesel = ' <select name="srchtype">';
1.580     raeburn  9624:     foreach my $option ('begins','contains','exact') {
1.555     raeburn  9625:         if ($curr_selected{'srchtype'} eq $option) {
                   9626:             $srchtypesel .= '
1.1075.2.98  raeburn  9627:    <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555     raeburn  9628:         } else {
                   9629:             $srchtypesel .= '
1.1075.2.98  raeburn  9630:    <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555     raeburn  9631:         }
                   9632:     }
                   9633:     $srchtypesel .= "\n  </select>\n";
                   9634: 
1.558     albertel 9635:     my ($newuserscript,$new_user_create);
1.994     raeburn  9636:     my $context_dom = $env{'request.role.domain'};
                   9637:     if ($context eq 'requestcrs') {
                   9638:         if ($env{'form.coursedom'} ne '') { 
                   9639:             $context_dom = $env{'form.coursedom'};
                   9640:         }
                   9641:     }
1.556     raeburn  9642:     if ($forcenewuser) {
1.576     raeburn  9643:         if (ref($srch) eq 'HASH') {
1.994     raeburn  9644:             if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627     raeburn  9645:                 if ($cancreate) {
                   9646:                     $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>';
                   9647:                 } else {
1.799     bisitz   9648:                     my $helplink = 'javascript:helpMenu('."'display'".')';
1.627     raeburn  9649:                     my %usertypetext = (
                   9650:                         official   => 'institutional',
                   9651:                         unofficial => 'non-institutional',
                   9652:                     );
1.799     bisitz   9653:                     $new_user_create = '<p class="LC_warning">'
                   9654:                                       .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
                   9655:                                       .' '
                   9656:                                       .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
                   9657:                                           ,'<a href="'.$helplink.'">','</a>')
                   9658:                                       .'</p><br />';
1.627     raeburn  9659:                 }
1.576     raeburn  9660:             }
                   9661:         }
                   9662: 
1.556     raeburn  9663:         $newuserscript = <<"ENDSCRIPT";
                   9664: 
1.570     raeburn  9665: function setSearch(createnew,callingForm) {
1.556     raeburn  9666:     if (createnew == 1) {
1.570     raeburn  9667:         for (var i=0; i<callingForm.srchby.length; i++) {
                   9668:             if (callingForm.srchby.options[i].value == 'uname') {
                   9669:                 callingForm.srchby.selectedIndex = i;
1.556     raeburn  9670:             }
                   9671:         }
1.570     raeburn  9672:         for (var i=0; i<callingForm.srchin.length; i++) {
                   9673:             if ( callingForm.srchin.options[i].value == 'dom') {
                   9674: 		callingForm.srchin.selectedIndex = i;
1.556     raeburn  9675:             }
                   9676:         }
1.570     raeburn  9677:         for (var i=0; i<callingForm.srchtype.length; i++) {
                   9678:             if (callingForm.srchtype.options[i].value == 'exact') {
                   9679:                 callingForm.srchtype.selectedIndex = i;
1.556     raeburn  9680:             }
                   9681:         }
1.570     raeburn  9682:         for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994     raeburn  9683:             if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570     raeburn  9684:                 callingForm.srchdomain.selectedIndex = i;
1.556     raeburn  9685:             }
                   9686:         }
                   9687:     }
                   9688: }
                   9689: ENDSCRIPT
1.558     albertel 9690: 
1.556     raeburn  9691:     }
                   9692: 
1.555     raeburn  9693:     my $output = <<"END_BLOCK";
1.556     raeburn  9694: <script type="text/javascript">
1.824     bisitz   9695: // <![CDATA[
1.570     raeburn  9696: function validateEntry(callingForm) {
1.558     albertel 9697: 
1.556     raeburn  9698:     var checkok = 1;
1.558     albertel 9699:     var srchin;
1.570     raeburn  9700:     for (var i=0; i<callingForm.srchin.length; i++) {
                   9701: 	if ( callingForm.srchin[i].checked ) {
                   9702: 	    srchin = callingForm.srchin[i].value;
1.558     albertel 9703: 	}
                   9704:     }
                   9705: 
1.570     raeburn  9706:     var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
                   9707:     var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
                   9708:     var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
                   9709:     var srchterm =  callingForm.srchterm.value;
                   9710:     var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556     raeburn  9711:     var msg = "";
                   9712: 
                   9713:     if (srchterm == "") {
                   9714:         checkok = 0;
1.1075.2.98  raeburn  9715:         msg += "$js_lt{'youm'}\\n";
1.556     raeburn  9716:     }
                   9717: 
1.569     raeburn  9718:     if (srchtype== 'begins') {
                   9719:         if (srchterm.length < 2) {
                   9720:             checkok = 0;
1.1075.2.98  raeburn  9721:             msg += "$js_lt{'thte'}\\n";
1.569     raeburn  9722:         }
                   9723:     }
                   9724: 
1.556     raeburn  9725:     if (srchtype== 'contains') {
                   9726:         if (srchterm.length < 3) {
                   9727:             checkok = 0;
1.1075.2.98  raeburn  9728:             msg += "$js_lt{'thet'}\\n";
1.556     raeburn  9729:         }
                   9730:     }
                   9731:     if (srchin == 'instd') {
                   9732:         if (srchdomain == '') {
                   9733:             checkok = 0;
1.1075.2.98  raeburn  9734:             msg += "$js_lt{'yomc'}\\n";
1.556     raeburn  9735:         }
                   9736:     }
                   9737:     if (srchin == 'dom') {
                   9738:         if (srchdomain == '') {
                   9739:             checkok = 0;
1.1075.2.98  raeburn  9740:             msg += "$js_lt{'ymcd'}\\n";
1.556     raeburn  9741:         }
                   9742:     }
                   9743:     if (srchby == 'lastfirst') {
                   9744:         if (srchterm.indexOf(",") == -1) {
                   9745:             checkok = 0;
1.1075.2.98  raeburn  9746:             msg += "$js_lt{'whus'}\\n";
1.556     raeburn  9747:         }
                   9748:         if (srchterm.indexOf(",") == srchterm.length -1) {
                   9749:             checkok = 0;
1.1075.2.98  raeburn  9750:             msg += "$js_lt{'whse'}\\n";
1.556     raeburn  9751:         }
                   9752:     }
                   9753:     if (checkok == 0) {
1.1075.2.98  raeburn  9754:         alert("$js_lt{'thfo'}\\n"+msg);
1.556     raeburn  9755:         return;
                   9756:     }
                   9757:     if (checkok == 1) {
1.570     raeburn  9758:         callingForm.submit();
1.556     raeburn  9759:     }
                   9760: }
                   9761: 
                   9762: $newuserscript
                   9763: 
1.824     bisitz   9764: // ]]>
1.556     raeburn  9765: </script>
1.558     albertel 9766: 
                   9767: $new_user_create
                   9768: 
1.555     raeburn  9769: END_BLOCK
1.558     albertel 9770: 
1.876     raeburn  9771:     $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1075.2.98  raeburn  9772:                &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876     raeburn  9773:                $domform.
                   9774:                &Apache::lonhtmlcommon::row_closure().
1.1075.2.98  raeburn  9775:                &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876     raeburn  9776:                $srchbysel.
                   9777:                $srchtypesel. 
                   9778:                '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
                   9779:                $srchinsel.
                   9780:                &Apache::lonhtmlcommon::row_closure(1). 
                   9781:                &Apache::lonhtmlcommon::end_pick_box().
                   9782:                '<br />';
1.1075.2.114  raeburn  9783:     return ($output,1);
1.555     raeburn  9784: }
                   9785: 
1.612     raeburn  9786: sub user_rule_check {
1.615     raeburn  9787:     my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1075.2.99  raeburn  9788:     my ($response,%inst_response);
1.612     raeburn  9789:     if (ref($usershash) eq 'HASH') {
1.1075.2.99  raeburn  9790:         if (keys(%{$usershash}) > 1) {
                   9791:             my (%by_username,%by_id,%userdoms);
                   9792:             my $checkid;
1.612     raeburn  9793:             if (ref($checks) eq 'HASH') {
1.1075.2.99  raeburn  9794:                 if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
                   9795:                     $checkid = 1;
                   9796:                 }
                   9797:             }
                   9798:             foreach my $user (keys(%{$usershash})) {
                   9799:                 my ($uname,$udom) = split(/:/,$user);
                   9800:                 if ($checkid) {
                   9801:                     if (ref($usershash->{$user}) eq 'HASH') {
                   9802:                         if ($usershash->{$user}->{'id'} ne '') {
                   9803:                             $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
                   9804:                             $userdoms{$udom} = 1;
                   9805:                             if (ref($inst_results) eq 'HASH') {
                   9806:                                 $inst_results->{$uname.':'.$udom} = {};
                   9807:                             }
                   9808:                         }
                   9809:                     }
                   9810:                 } else {
                   9811:                     $by_username{$udom}{$uname} = 1;
                   9812:                     $userdoms{$udom} = 1;
                   9813:                     if (ref($inst_results) eq 'HASH') {
                   9814:                         $inst_results->{$uname.':'.$udom} = {};
                   9815:                     }
                   9816:                 }
                   9817:             }
                   9818:             foreach my $udom (keys(%userdoms)) {
                   9819:                 if (!$got_rules->{$udom}) {
                   9820:                     my %domconfig = &Apache::lonnet::get_dom('configuration',
                   9821:                                                              ['usercreation'],$udom);
                   9822:                     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   9823:                         foreach my $item ('username','id') {
                   9824:                             if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
                   9825:                                 $$curr_rules{$udom}{$item} =
                   9826:                                     $domconfig{'usercreation'}{$item.'_rule'};
                   9827:                             }
                   9828:                         }
                   9829:                     }
                   9830:                     $got_rules->{$udom} = 1;
                   9831:                 }
                   9832:             }
                   9833:             if ($checkid) {
                   9834:                 foreach my $udom (keys(%by_id)) {
                   9835:                     my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
                   9836:                     if ($outcome eq 'ok') {
                   9837:                         foreach my $id (keys(%{$by_id{$udom}})) {
                   9838:                             my $uname = $by_id{$udom}{$id};
                   9839:                             $inst_response{$uname.':'.$udom} = $outcome;
                   9840:                         }
                   9841:                         if (ref($results) eq 'HASH') {
                   9842:                             foreach my $uname (keys(%{$results})) {
                   9843:                                 if (exists($inst_response{$uname.':'.$udom})) {
                   9844:                                     $inst_response{$uname.':'.$udom} = $outcome;
                   9845:                                     $inst_results->{$uname.':'.$udom} = $results->{$uname};
                   9846:                                 }
                   9847:                             }
                   9848:                         }
                   9849:                     }
1.612     raeburn  9850:                 }
1.615     raeburn  9851:             } else {
1.1075.2.99  raeburn  9852:                 foreach my $udom (keys(%by_username)) {
                   9853:                     my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
                   9854:                     if ($outcome eq 'ok') {
                   9855:                         foreach my $uname (keys(%{$by_username{$udom}})) {
                   9856:                             $inst_response{$uname.':'.$udom} = $outcome;
                   9857:                         }
                   9858:                         if (ref($results) eq 'HASH') {
                   9859:                             foreach my $uname (keys(%{$results})) {
                   9860:                                 $inst_results->{$uname.':'.$udom} = $results->{$uname};
                   9861:                             }
                   9862:                         }
                   9863:                     }
                   9864:                 }
1.612     raeburn  9865:             }
1.1075.2.99  raeburn  9866:         } elsif (keys(%{$usershash}) == 1) {
                   9867:             my $user = (keys(%{$usershash}))[0];
                   9868:             my ($uname,$udom) = split(/:/,$user);
                   9869:             if (($udom ne '') && ($uname ne '')) {
                   9870:                 if (ref($usershash->{$user}) eq 'HASH') {
                   9871:                     if (ref($checks) eq 'HASH') {
                   9872:                         if (defined($checks->{'username'})) {
                   9873:                             ($inst_response{$user},%{$inst_results->{$user}}) =
                   9874:                                 &Apache::lonnet::get_instuser($udom,$uname);
                   9875:                         } elsif (defined($checks->{'id'})) {
                   9876:                             if ($usershash->{$user}->{'id'} ne '') {
                   9877:                                 ($inst_response{$user},%{$inst_results->{$user}}) =
                   9878:                                     &Apache::lonnet::get_instuser($udom,undef,
                   9879:                                                                   $usershash->{$user}->{'id'});
                   9880:                             } else {
                   9881:                                 ($inst_response{$user},%{$inst_results->{$user}}) =
                   9882:                                     &Apache::lonnet::get_instuser($udom,$uname);
                   9883:                             }
                   9884:                         }
                   9885:                     } else {
                   9886:                        ($inst_response{$user},%{$inst_results->{$user}}) =
                   9887:                             &Apache::lonnet::get_instuser($udom,$uname);
                   9888:                        return;
                   9889:                     }
                   9890:                     if (!$got_rules->{$udom}) {
                   9891:                         my %domconfig = &Apache::lonnet::get_dom('configuration',
                   9892:                                                                  ['usercreation'],$udom);
                   9893:                         if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   9894:                             foreach my $item ('username','id') {
                   9895:                                 if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
                   9896:                                    $$curr_rules{$udom}{$item} =
                   9897:                                        $domconfig{'usercreation'}{$item.'_rule'};
                   9898:                                 }
                   9899:                             }
1.585     raeburn  9900:                         }
1.1075.2.99  raeburn  9901:                         $got_rules->{$udom} = 1;
1.585     raeburn  9902:                     }
                   9903:                 }
1.1075.2.99  raeburn  9904:             } else {
                   9905:                 return;
                   9906:             }
                   9907:         } else {
                   9908:             return;
                   9909:         }
                   9910:         foreach my $user (keys(%{$usershash})) {
                   9911:             my ($uname,$udom) = split(/:/,$user);
                   9912:             next if (($udom eq '') || ($uname eq ''));
                   9913:             my $id;
                   9914:             if (ref($inst_results) eq 'HASH') {
                   9915:                 if (ref($inst_results->{$user}) eq 'HASH') {
                   9916:                     $id = $inst_results->{$user}->{'id'};
                   9917:                 }
                   9918:             }
                   9919:             if ($id eq '') {
                   9920:                 if (ref($usershash->{$user})) {
                   9921:                     $id = $usershash->{$user}->{'id'};
                   9922:                 }
1.585     raeburn  9923:             }
1.612     raeburn  9924:             foreach my $item (keys(%{$checks})) {
                   9925:                 if (ref($$curr_rules{$udom}) eq 'HASH') {
                   9926:                     if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
                   9927:                         if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1075.2.99  raeburn  9928:                             my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
                   9929:                                                                              $$curr_rules{$udom}{$item});
1.612     raeburn  9930:                             foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
                   9931:                                 if ($rule_check{$rule}) {
                   9932:                                     $$rulematch{$user}{$item} = $rule;
1.1075.2.99  raeburn  9933:                                     if ($inst_response{$user} eq 'ok') {
1.615     raeburn  9934:                                         if (ref($inst_results) eq 'HASH') {
                   9935:                                             if (ref($inst_results->{$user}) eq 'HASH') {
                   9936:                                                 if (keys(%{$inst_results->{$user}}) == 0) {
                   9937:                                                     $$alerts{$item}{$udom}{$uname} = 1;
1.1075.2.99  raeburn  9938:                                                 } elsif ($item eq 'id') {
                   9939:                                                     if ($inst_results->{$user}->{'id'} eq '') {
                   9940:                                                         $$alerts{$item}{$udom}{$uname} = 1;
                   9941:                                                     }
1.615     raeburn  9942:                                                 }
1.612     raeburn  9943:                                             }
                   9944:                                         }
1.615     raeburn  9945:                                     }
                   9946:                                     last;
1.585     raeburn  9947:                                 }
                   9948:                             }
                   9949:                         }
                   9950:                     }
                   9951:                 }
                   9952:             }
                   9953:         }
                   9954:     }
1.612     raeburn  9955:     return;
                   9956: }
                   9957: 
                   9958: sub user_rule_formats {
                   9959:     my ($domain,$domdesc,$curr_rules,$check) = @_;
                   9960:     my %text = ( 
                   9961:                  'username' => 'Usernames',
                   9962:                  'id'       => 'IDs',
                   9963:                );
                   9964:     my $output;
                   9965:     my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
                   9966:     if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
                   9967:         if (@{$ruleorder} > 0) {
1.1075.2.20  raeburn  9968:             $output = '<br />'.
                   9969:                       &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
                   9970:                           '<span class="LC_cusr_emph">','</span>',$domdesc).
                   9971:                       ' <ul>';
1.612     raeburn  9972:             foreach my $rule (@{$ruleorder}) {
                   9973:                 if (ref($curr_rules) eq 'ARRAY') {
                   9974:                     if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
                   9975:                         if (ref($rules->{$rule}) eq 'HASH') {
                   9976:                             $output .= '<li>'.$rules->{$rule}{'name'}.': '.
                   9977:                                         $rules->{$rule}{'desc'}.'</li>';
                   9978:                         }
                   9979:                     }
                   9980:                 }
                   9981:             }
                   9982:             $output .= '</ul>';
                   9983:         }
                   9984:     }
                   9985:     return $output;
                   9986: }
                   9987: 
                   9988: sub instrule_disallow_msg {
1.615     raeburn  9989:     my ($checkitem,$domdesc,$count,$mode) = @_;
1.612     raeburn  9990:     my $response;
                   9991:     my %text = (
                   9992:                   item   => 'username',
                   9993:                   items  => 'usernames',
                   9994:                   match  => 'matches',
                   9995:                   do     => 'does',
                   9996:                   action => 'a username',
                   9997:                   one    => 'one',
                   9998:                );
                   9999:     if ($count > 1) {
                   10000:         $text{'item'} = 'usernames';
                   10001:         $text{'match'} ='match';
                   10002:         $text{'do'} = 'do';
                   10003:         $text{'action'} = 'usernames',
                   10004:         $text{'one'} = 'ones';
                   10005:     }
                   10006:     if ($checkitem eq 'id') {
                   10007:         $text{'items'} = 'IDs';
                   10008:         $text{'item'} = 'ID';
                   10009:         $text{'action'} = 'an ID';
1.615     raeburn  10010:         if ($count > 1) {
                   10011:             $text{'item'} = 'IDs';
                   10012:             $text{'action'} = 'IDs';
                   10013:         }
1.612     raeburn  10014:     }
1.674     bisitz   10015:     $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  10016:     if ($mode eq 'upload') {
                   10017:         if ($checkitem eq 'username') {
                   10018:             $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'}.");
                   10019:         } elsif ($checkitem eq 'id') {
1.674     bisitz   10020:             $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  10021:         }
1.669     raeburn  10022:     } elsif ($mode eq 'selfcreate') {
                   10023:         if ($checkitem eq 'id') {
                   10024:             $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.");
                   10025:         }
1.615     raeburn  10026:     } else {
                   10027:         if ($checkitem eq 'username') {
                   10028:             $response .= &mt("You must choose $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
                   10029:         } elsif ($checkitem eq 'id') {
                   10030:             $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.");
                   10031:         }
1.612     raeburn  10032:     }
                   10033:     return $response;
1.585     raeburn  10034: }
                   10035: 
1.624     raeburn  10036: sub personal_data_fieldtitles {
                   10037:     my %fieldtitles = &Apache::lonlocal::texthash (
                   10038:                         id => 'Student/Employee ID',
                   10039:                         permanentemail => 'E-mail address',
                   10040:                         lastname => 'Last Name',
                   10041:                         firstname => 'First Name',
                   10042:                         middlename => 'Middle Name',
                   10043:                         generation => 'Generation',
                   10044:                         gen => 'Generation',
1.765     raeburn  10045:                         inststatus => 'Affiliation',
1.624     raeburn  10046:                    );
                   10047:     return %fieldtitles;
                   10048: }
                   10049: 
1.642     raeburn  10050: sub sorted_inst_types {
                   10051:     my ($dom) = @_;
1.1075.2.70  raeburn  10052:     my ($usertypes,$order);
                   10053:     my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
                   10054:     if (ref($domdefaults{'inststatus'}) eq 'HASH') {
                   10055:         $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
                   10056:         $order = $domdefaults{'inststatus'}{'inststatusorder'};
                   10057:     } else {
                   10058:         ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
                   10059:     }
1.642     raeburn  10060:     my $othertitle = &mt('All users');
                   10061:     if ($env{'request.course.id'}) {
1.668     raeburn  10062:         $othertitle  = &mt('Any users');
1.642     raeburn  10063:     }
                   10064:     my @types;
                   10065:     if (ref($order) eq 'ARRAY') {
                   10066:         @types = @{$order};
                   10067:     }
                   10068:     if (@types == 0) {
                   10069:         if (ref($usertypes) eq 'HASH') {
                   10070:             @types = sort(keys(%{$usertypes}));
                   10071:         }
                   10072:     }
                   10073:     if (keys(%{$usertypes}) > 0) {
                   10074:         $othertitle = &mt('Other users');
                   10075:     }
                   10076:     return ($othertitle,$usertypes,\@types);
                   10077: }
                   10078: 
1.645     raeburn  10079: sub get_institutional_codes {
                   10080:     my ($settings,$allcourses,$LC_code) = @_;
                   10081: # Get complete list of course sections to update
                   10082:     my @currsections = ();
                   10083:     my @currxlists = ();
                   10084:     my $coursecode = $$settings{'internal.coursecode'};
                   10085: 
                   10086:     if ($$settings{'internal.sectionnums'} ne '') {
                   10087:         @currsections = split(/,/,$$settings{'internal.sectionnums'});
                   10088:     }
                   10089: 
                   10090:     if ($$settings{'internal.crosslistings'} ne '') {
                   10091:         @currxlists = split(/,/,$$settings{'internal.crosslistings'});
                   10092:     }
                   10093: 
                   10094:     if (@currxlists > 0) {
                   10095:         foreach (@currxlists) {
                   10096:             if (m/^([^:]+):(\w*)$/) {
                   10097:                 unless (grep/^$1$/,@{$allcourses}) {
                   10098:                     push @{$allcourses},$1;
                   10099:                     $$LC_code{$1} = $2;
                   10100:                 }
                   10101:             }
                   10102:         }
                   10103:     }
                   10104:  
                   10105:     if (@currsections > 0) {
                   10106:         foreach (@currsections) {
                   10107:             if (m/^(\w+):(\w*)$/) {
                   10108:                 my $sec = $coursecode.$1;
                   10109:                 my $lc_sec = $2;
                   10110:                 unless (grep/^$sec$/,@{$allcourses}) {
                   10111:                     push @{$allcourses},$sec;
                   10112:                     $$LC_code{$sec} = $lc_sec;
                   10113:                 }
                   10114:             }
                   10115:         }
                   10116:     }
                   10117:     return;
                   10118: }
                   10119: 
1.971     raeburn  10120: sub get_standard_codeitems {
                   10121:     return ('Year','Semester','Department','Number','Section');
                   10122: }
                   10123: 
1.112     bowersj2 10124: =pod
                   10125: 
1.780     raeburn  10126: =head1 Slot Helpers
                   10127: 
                   10128: =over 4
                   10129: 
                   10130: =item * sorted_slots()
                   10131: 
1.1040    raeburn  10132: Sorts an array of slot names in order of an optional sort key,
                   10133: default sort is by slot start time (earliest first). 
1.780     raeburn  10134: 
                   10135: Inputs:
                   10136: 
                   10137: =over 4
                   10138: 
                   10139: slotsarr  - Reference to array of unsorted slot names.
                   10140: 
                   10141: slots     - Reference to hash of hash, where outer hash keys are slot names.
                   10142: 
1.1040    raeburn  10143: sortkey   - Name of key in inner hash to be sorted on (e.g., starttime).
                   10144: 
1.549     albertel 10145: =back
                   10146: 
1.780     raeburn  10147: Returns:
                   10148: 
                   10149: =over 4
                   10150: 
1.1040    raeburn  10151: sorted   - An array of slot names sorted by a specified sort key 
                   10152:            (default sort key is start time of the slot).
1.780     raeburn  10153: 
                   10154: =back
                   10155: 
                   10156: =cut
                   10157: 
                   10158: 
                   10159: sub sorted_slots {
1.1040    raeburn  10160:     my ($slotsarr,$slots,$sortkey) = @_;
                   10161:     if ($sortkey eq '') {
                   10162:         $sortkey = 'starttime';
                   10163:     }
1.780     raeburn  10164:     my @sorted;
                   10165:     if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
                   10166:         @sorted =
                   10167:             sort {
                   10168:                      if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040    raeburn  10169:                          return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780     raeburn  10170:                      }
                   10171:                      if (ref($slots->{$a})) { return -1;}
                   10172:                      if (ref($slots->{$b})) { return 1;}
                   10173:                      return 0;
                   10174:                  } @{$slotsarr};
                   10175:     }
                   10176:     return @sorted;
                   10177: }
                   10178: 
1.1040    raeburn  10179: =pod
                   10180: 
                   10181: =item * get_future_slots()
                   10182: 
                   10183: Inputs:
                   10184: 
                   10185: =over 4
                   10186: 
                   10187: cnum - course number
                   10188: 
                   10189: cdom - course domain
                   10190: 
                   10191: now - current UNIX time
                   10192: 
                   10193: symb - optional symb
                   10194: 
                   10195: =back
                   10196: 
                   10197: Returns:
                   10198: 
                   10199: =over 4
                   10200: 
                   10201: sorted_reservable - ref to array of student_schedulable slots currently 
                   10202:                     reservable, ordered by end date of reservation period.
                   10203: 
                   10204: reservable_now - ref to hash of student_schedulable slots currently
                   10205:                  reservable.
                   10206: 
                   10207:     Keys in inner hash are:
                   10208:     (a) symb: either blank or symb to which slot use is restricted.
1.1075.2.104  raeburn  10209:     (b) endreserve: end date of reservation period.
                   10210:     (c) uniqueperiod: start,end dates when slot is to be uniquely
                   10211:         selected.
1.1040    raeburn  10212: 
                   10213: sorted_future - ref to array of student_schedulable slots reservable in
                   10214:                 the future, ordered by start date of reservation period.
                   10215: 
                   10216: future_reservable - ref to hash of student_schedulable slots reservable
                   10217:                     in the future.
                   10218: 
                   10219:     Keys in inner hash are:
                   10220:     (a) symb: either blank or symb to which slot use is restricted.
                   10221:     (b) startreserve:  start date of reservation period.
1.1075.2.104  raeburn  10222:     (c) uniqueperiod: start,end dates when slot is to be uniquely
                   10223:         selected.
1.1040    raeburn  10224: 
                   10225: =back
                   10226: 
                   10227: =cut
                   10228: 
                   10229: sub get_future_slots {
                   10230:     my ($cnum,$cdom,$now,$symb) = @_;
                   10231:     my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
                   10232:     my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
                   10233:     foreach my $slot (keys(%slots)) {
                   10234:         next unless($slots{$slot}->{'type'} eq 'schedulable_student');
                   10235:         if ($symb) {
                   10236:             next if (($slots{$slot}->{'symb'} ne '') && 
                   10237:                      ($slots{$slot}->{'symb'} ne $symb));
                   10238:         }
                   10239:         if (($slots{$slot}->{'starttime'} > $now) &&
                   10240:             ($slots{$slot}->{'endtime'} > $now)) {
                   10241:             if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
                   10242:                 my $userallowed = 0;
                   10243:                 if ($slots{$slot}->{'allowedsections'}) {
                   10244:                     my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
                   10245:                     if (!defined($env{'request.role.sec'})
                   10246:                         && grep(/^No section assigned$/,@allowed_sec)) {
                   10247:                         $userallowed=1;
                   10248:                     } else {
                   10249:                         if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
                   10250:                             $userallowed=1;
                   10251:                         }
                   10252:                     }
                   10253:                     unless ($userallowed) {
                   10254:                         if (defined($env{'request.course.groups'})) {
                   10255:                             my @groups = split(/:/,$env{'request.course.groups'});
                   10256:                             foreach my $group (@groups) {
                   10257:                                 if (grep(/^\Q$group\E$/,@allowed_sec)) {
                   10258:                                     $userallowed=1;
                   10259:                                     last;
                   10260:                                 }
                   10261:                             }
                   10262:                         }
                   10263:                     }
                   10264:                 }
                   10265:                 if ($slots{$slot}->{'allowedusers'}) {
                   10266:                     my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
                   10267:                     my $user = $env{'user.name'}.':'.$env{'user.domain'};
                   10268:                     if (grep(/^\Q$user\E$/,@allowed_users)) {
                   10269:                         $userallowed = 1;
                   10270:                     }
                   10271:                 }
                   10272:                 next unless($userallowed);
                   10273:             }
                   10274:             my $startreserve = $slots{$slot}->{'startreserve'};
                   10275:             my $endreserve = $slots{$slot}->{'endreserve'};
                   10276:             my $symb = $slots{$slot}->{'symb'};
1.1075.2.104  raeburn  10277:             my $uniqueperiod;
                   10278:             if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
                   10279:                 $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
                   10280:             }
1.1040    raeburn  10281:             if (($startreserve < $now) &&
                   10282:                 (!$endreserve || $endreserve > $now)) {
                   10283:                 my $lastres = $endreserve;
                   10284:                 if (!$lastres) {
                   10285:                     $lastres = $slots{$slot}->{'starttime'};
                   10286:                 }
                   10287:                 $reservable_now{$slot} = {
                   10288:                                            symb       => $symb,
1.1075.2.104  raeburn  10289:                                            endreserve => $lastres,
                   10290:                                            uniqueperiod => $uniqueperiod,   
1.1040    raeburn  10291:                                          };
                   10292:             } elsif (($startreserve > $now) &&
                   10293:                      (!$endreserve || $endreserve > $startreserve)) {
                   10294:                 $future_reservable{$slot} = {
                   10295:                                               symb         => $symb,
1.1075.2.104  raeburn  10296:                                               startreserve => $startreserve,
                   10297:                                               uniqueperiod => $uniqueperiod,
1.1040    raeburn  10298:                                             };
                   10299:             }
                   10300:         }
                   10301:     }
                   10302:     my @unsorted_reservable = keys(%reservable_now);
                   10303:     if (@unsorted_reservable > 0) {
                   10304:         @sorted_reservable = 
                   10305:             &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
                   10306:     }
                   10307:     my @unsorted_future = keys(%future_reservable);
                   10308:     if (@unsorted_future > 0) {
                   10309:         @sorted_future =
                   10310:             &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
                   10311:     }
                   10312:     return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
                   10313: }
1.780     raeburn  10314: 
                   10315: =pod
                   10316: 
1.1057    foxr     10317: =back
                   10318: 
1.549     albertel 10319: =head1 HTTP Helpers
                   10320: 
                   10321: =over 4
                   10322: 
1.648     raeburn  10323: =item * &get_unprocessed_cgi($query,$possible_names)
1.112     bowersj2 10324: 
1.258     albertel 10325: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112     bowersj2 10326: $query.  The parameters listed in $possible_names (an array reference),
1.258     albertel 10327: will be set in $env{'form.name'} if they do not already exist.
1.112     bowersj2 10328: 
                   10329: Typically called with $ENV{'QUERY_STRING'} as the first parameter.  
                   10330: $possible_names is an ref to an array of form element names.  As an example:
                   10331: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258     albertel 10332: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112     bowersj2 10333: 
                   10334: =cut
1.1       albertel 10335: 
1.6       albertel 10336: sub get_unprocessed_cgi {
1.25      albertel 10337:   my ($query,$possible_names)= @_;
1.26      matthew  10338:   # $Apache::lonxml::debug=1;
1.356     albertel 10339:   foreach my $pair (split(/&/,$query)) {
                   10340:     my ($name, $value) = split(/=/,$pair);
1.369     www      10341:     $name = &unescape($name);
1.25      albertel 10342:     if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
                   10343:       $value =~ tr/+/ /;
                   10344:       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258     albertel 10345:       unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25      albertel 10346:     }
1.16      harris41 10347:   }
1.6       albertel 10348: }
                   10349: 
1.112     bowersj2 10350: =pod
                   10351: 
1.648     raeburn  10352: =item * &cacheheader() 
1.112     bowersj2 10353: 
                   10354: returns cache-controlling header code
                   10355: 
                   10356: =cut
                   10357: 
1.7       albertel 10358: sub cacheheader {
1.258     albertel 10359:     unless ($env{'request.method'} eq 'GET') { return ''; }
1.216     albertel 10360:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
                   10361:     my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7       albertel 10362:                 <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
                   10363:                 <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216     albertel 10364:     return $output;
1.7       albertel 10365: }
                   10366: 
1.112     bowersj2 10367: =pod
                   10368: 
1.648     raeburn  10369: =item * &no_cache($r) 
1.112     bowersj2 10370: 
                   10371: specifies header code to not have cache
                   10372: 
                   10373: =cut
                   10374: 
1.9       albertel 10375: sub no_cache {
1.216     albertel 10376:     my ($r) = @_;
                   10377:     if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258     albertel 10378: 	$env{'request.method'} ne 'GET') { return ''; }
1.216     albertel 10379:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
                   10380:     $r->no_cache(1);
                   10381:     $r->header_out("Expires" => $date);
                   10382:     $r->header_out("Pragma" => "no-cache");
1.123     www      10383: }
                   10384: 
                   10385: sub content_type {
1.181     albertel 10386:     my ($r,$type,$charset) = @_;
1.299     foxr     10387:     if ($r) {
                   10388: 	#  Note that printout.pl calls this with undef for $r.
                   10389: 	&no_cache($r);
                   10390:     }
1.258     albertel 10391:     if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181     albertel 10392:     unless ($charset) {
                   10393: 	$charset=&Apache::lonlocal::current_encoding;
                   10394:     }
                   10395:     if ($charset) { $type.='; charset='.$charset; }
                   10396:     if ($r) {
                   10397: 	$r->content_type($type);
                   10398:     } else {
                   10399: 	print("Content-type: $type\n\n");
                   10400:     }
1.9       albertel 10401: }
1.25      albertel 10402: 
1.112     bowersj2 10403: =pod
                   10404: 
1.648     raeburn  10405: =item * &add_to_env($name,$value) 
1.112     bowersj2 10406: 
1.258     albertel 10407: adds $name to the %env hash with value
1.112     bowersj2 10408: $value, if $name already exists, the entry is converted to an array
                   10409: reference and $value is added to the array.
                   10410: 
                   10411: =cut
                   10412: 
1.25      albertel 10413: sub add_to_env {
                   10414:   my ($name,$value)=@_;
1.258     albertel 10415:   if (defined($env{$name})) {
                   10416:     if (ref($env{$name})) {
1.25      albertel 10417:       #already have multiple values
1.258     albertel 10418:       push(@{ $env{$name} },$value);
1.25      albertel 10419:     } else {
                   10420:       #first time seeing multiple values, convert hash entry to an arrayref
1.258     albertel 10421:       my $first=$env{$name};
                   10422:       undef($env{$name});
                   10423:       push(@{ $env{$name} },$first,$value);
1.25      albertel 10424:     }
                   10425:   } else {
1.258     albertel 10426:     $env{$name}=$value;
1.25      albertel 10427:   }
1.31      albertel 10428: }
1.149     albertel 10429: 
                   10430: =pod
                   10431: 
1.648     raeburn  10432: =item * &get_env_multiple($name) 
1.149     albertel 10433: 
1.258     albertel 10434: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149     albertel 10435: values may be defined and end up as an array ref.
                   10436: 
                   10437: returns an array of values
                   10438: 
                   10439: =cut
                   10440: 
                   10441: sub get_env_multiple {
                   10442:     my ($name) = @_;
                   10443:     my @values;
1.258     albertel 10444:     if (defined($env{$name})) {
1.149     albertel 10445:         # exists is it an array
1.258     albertel 10446:         if (ref($env{$name})) {
                   10447:             @values=@{ $env{$name} };
1.149     albertel 10448:         } else {
1.258     albertel 10449:             $values[0]=$env{$name};
1.149     albertel 10450:         }
                   10451:     }
                   10452:     return(@values);
                   10453: }
                   10454: 
1.660     raeburn  10455: sub ask_for_embedded_content {
                   10456:     my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071    raeburn  10457:     my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11  raeburn  10458:         %currsubfile,%unused,$rem);
1.1071    raeburn  10459:     my $counter = 0;
                   10460:     my $numnew = 0;
1.987     raeburn  10461:     my $numremref = 0;
                   10462:     my $numinvalid = 0;
                   10463:     my $numpathchg = 0;
                   10464:     my $numexisting = 0;
1.1071    raeburn  10465:     my $numunused = 0;
                   10466:     my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53  raeburn  10467:         $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071    raeburn  10468:     my $heading = &mt('Upload embedded files');
                   10469:     my $buttontext = &mt('Upload');
                   10470: 
1.1075.2.11  raeburn  10471:     if ($env{'request.course.id'}) {
1.1075.2.35  raeburn  10472:         if ($actionurl eq '/adm/dependencies') {
                   10473:             $navmap = Apache::lonnavmaps::navmap->new();
                   10474:         }
                   10475:         $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   10476:         $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11  raeburn  10477:     }
1.1075.2.35  raeburn  10478:     if (($actionurl eq '/adm/portfolio') ||
                   10479:         ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984     raeburn  10480:         my $current_path='/';
                   10481:         if ($env{'form.currentpath'}) {
                   10482:             $current_path = $env{'form.currentpath'};
                   10483:         }
                   10484:         if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35  raeburn  10485:             $udom = $cdom;
                   10486:             $uname = $cnum;
1.984     raeburn  10487:             $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
                   10488:         } else {
                   10489:             $udom = $env{'user.domain'};
                   10490:             $uname = $env{'user.name'};
                   10491:             $url = '/userfiles/portfolio';
                   10492:         }
1.987     raeburn  10493:         $toplevel = $url.'/';
1.984     raeburn  10494:         $url .= $current_path;
                   10495:         $getpropath = 1;
1.987     raeburn  10496:     } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
                   10497:              ($actionurl eq '/adm/imsimport')) { 
1.1022    www      10498:         my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026    raeburn  10499:         $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987     raeburn  10500:         $toplevel = $url;
1.984     raeburn  10501:         if ($rest ne '') {
1.987     raeburn  10502:             $url .= $rest;
                   10503:         }
                   10504:     } elsif ($actionurl eq '/adm/coursedocs') {
                   10505:         if (ref($args) eq 'HASH') {
1.1071    raeburn  10506:             $url = $args->{'docs_url'};
                   10507:             $toplevel = $url;
1.1075.2.11  raeburn  10508:             if ($args->{'context'} eq 'paste') {
                   10509:                 ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
                   10510:                 ($path) =
                   10511:                     ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
                   10512:                 $fileloc = &Apache::lonnet::filelocation('',$toplevel);
                   10513:                 $fileloc =~ s{^/}{};
                   10514:             }
1.1071    raeburn  10515:         }
                   10516:     } elsif ($actionurl eq '/adm/dependencies') {
                   10517:         if ($env{'request.course.id'} ne '') {
                   10518:             if (ref($args) eq 'HASH') {
                   10519:                 $url = $args->{'docs_url'};
                   10520:                 $title = $args->{'docs_title'};
1.1075.2.35  raeburn  10521:                 $toplevel = $url;
                   10522:                 unless ($toplevel =~ m{^/}) {
                   10523:                     $toplevel = "/$url";
                   10524:                 }
1.1075.2.11  raeburn  10525:                 ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35  raeburn  10526:                 if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
                   10527:                     $path = $1;
                   10528:                 } else {
                   10529:                     ($path) =
                   10530:                         ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
                   10531:                 }
1.1075.2.79  raeburn  10532:                 if ($toplevel=~/^\/*(uploaded|editupload)/) {
                   10533:                     $fileloc = $toplevel;
                   10534:                     $fileloc=~ s/^\s*(\S+)\s*$/$1/;
                   10535:                     my ($udom,$uname,$fname) =
                   10536:                         ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
                   10537:                     $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
                   10538:                 } else {
                   10539:                     $fileloc = &Apache::lonnet::filelocation('',$toplevel);
                   10540:                 }
1.1071    raeburn  10541:                 $fileloc =~ s{^/}{};
                   10542:                 ($filename) = ($fileloc =~ m{.+/([^/]+)$});
                   10543:                 $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
                   10544:             }
1.987     raeburn  10545:         }
1.1075.2.35  raeburn  10546:     } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
                   10547:         $udom = $cdom;
                   10548:         $uname = $cnum;
                   10549:         $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
                   10550:         $toplevel = $url;
                   10551:         $path = $url;
                   10552:         $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
                   10553:         $fileloc =~ s{^/}{};
                   10554:     }
                   10555:     foreach my $file (keys(%{$allfiles})) {
                   10556:         my $embed_file;
                   10557:         if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
                   10558:             $embed_file = $1;
                   10559:         } else {
                   10560:             $embed_file = $file;
                   10561:         }
1.1075.2.55  raeburn  10562:         my ($absolutepath,$cleaned_file);
                   10563:         if ($embed_file =~ m{^\w+://}) {
                   10564:             $cleaned_file = $embed_file;
1.1075.2.47  raeburn  10565:             $newfiles{$cleaned_file} = 1;
                   10566:             $mapping{$cleaned_file} = $embed_file;
1.987     raeburn  10567:         } else {
1.1075.2.55  raeburn  10568:             $cleaned_file = &clean_path($embed_file);
1.987     raeburn  10569:             if ($embed_file =~ m{^/}) {
                   10570:                 $absolutepath = $embed_file;
                   10571:             }
1.1075.2.47  raeburn  10572:             if ($cleaned_file =~ m{/}) {
                   10573:                 my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987     raeburn  10574:                 $path = &check_for_traversal($path,$url,$toplevel);
                   10575:                 my $item = $fname;
                   10576:                 if ($path ne '') {
                   10577:                     $item = $path.'/'.$fname;
                   10578:                     $subdependencies{$path}{$fname} = 1;
                   10579:                 } else {
                   10580:                     $dependencies{$item} = 1;
                   10581:                 }
                   10582:                 if ($absolutepath) {
                   10583:                     $mapping{$item} = $absolutepath;
                   10584:                 } else {
                   10585:                     $mapping{$item} = $embed_file;
                   10586:                 }
                   10587:             } else {
                   10588:                 $dependencies{$embed_file} = 1;
                   10589:                 if ($absolutepath) {
1.1075.2.47  raeburn  10590:                     $mapping{$cleaned_file} = $absolutepath;
1.987     raeburn  10591:                 } else {
1.1075.2.47  raeburn  10592:                     $mapping{$cleaned_file} = $embed_file;
1.987     raeburn  10593:                 }
                   10594:             }
1.984     raeburn  10595:         }
                   10596:     }
1.1071    raeburn  10597:     my $dirptr = 16384;
1.984     raeburn  10598:     foreach my $path (keys(%subdependencies)) {
1.1071    raeburn  10599:         $currsubfile{$path} = {};
1.1075.2.35  raeburn  10600:         if (($actionurl eq '/adm/portfolio') ||
                   10601:             ($actionurl eq '/adm/coursegrp_portfolio')) { 
1.1021    raeburn  10602:             my ($sublistref,$listerror) =
                   10603:                 &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
                   10604:             if (ref($sublistref) eq 'ARRAY') {
                   10605:                 foreach my $line (@{$sublistref}) {
                   10606:                     my ($file_name,$rest) = split(/\&/,$line,2);
1.1071    raeburn  10607:                     $currsubfile{$path}{$file_name} = 1;
1.1021    raeburn  10608:                 }
1.984     raeburn  10609:             }
1.987     raeburn  10610:         } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984     raeburn  10611:             if (opendir(my $dir,$url.'/'.$path)) {
                   10612:                 my @subdir_list = grep(!/^\./,readdir($dir));
1.1071    raeburn  10613:                 map {$currsubfile{$path}{$_} = 1;} @subdir_list;
                   10614:             }
1.1075.2.11  raeburn  10615:         } elsif (($actionurl eq '/adm/dependencies') ||
                   10616:                  (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35  raeburn  10617:                   ($args->{'context'} eq 'paste')) ||
                   10618:                  ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071    raeburn  10619:             if ($env{'request.course.id'} ne '') {
1.1075.2.35  raeburn  10620:                 my $dir;
                   10621:                 if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
                   10622:                     $dir = $fileloc;
                   10623:                 } else {
                   10624:                     ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
                   10625:                 }
1.1071    raeburn  10626:                 if ($dir ne '') {
                   10627:                     my ($sublistref,$listerror) =
                   10628:                         &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
                   10629:                     if (ref($sublistref) eq 'ARRAY') {
                   10630:                         foreach my $line (@{$sublistref}) {
                   10631:                             my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
                   10632:                                 undef,$mtime)=split(/\&/,$line,12);
                   10633:                             unless (($testdir&$dirptr) ||
                   10634:                                     ($file_name =~ /^\.\.?$/)) {
                   10635:                                 $currsubfile{$path}{$file_name} = [$size,$mtime];
                   10636:                             }
                   10637:                         }
                   10638:                     }
                   10639:                 }
1.984     raeburn  10640:             }
                   10641:         }
                   10642:         foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071    raeburn  10643:             if (exists($currsubfile{$path}{$file})) {
1.987     raeburn  10644:                 my $item = $path.'/'.$file;
                   10645:                 unless ($mapping{$item} eq $item) {
                   10646:                     $pathchanges{$item} = 1;
                   10647:                 }
                   10648:                 $existing{$item} = 1;
                   10649:                 $numexisting ++;
                   10650:             } else {
                   10651:                 $newfiles{$path.'/'.$file} = 1;
1.984     raeburn  10652:             }
                   10653:         }
1.1071    raeburn  10654:         if ($actionurl eq '/adm/dependencies') {
                   10655:             foreach my $path (keys(%currsubfile)) {
                   10656:                 if (ref($currsubfile{$path}) eq 'HASH') {
                   10657:                     foreach my $file (keys(%{$currsubfile{$path}})) {
                   10658:                          unless ($subdependencies{$path}{$file}) {
1.1075.2.11  raeburn  10659:                              next if (($rem ne '') &&
                   10660:                                       (($env{"httpref.$rem"."$path/$file"} ne '') ||
                   10661:                                        (ref($navmap) &&
                   10662:                                        (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
                   10663:                                         (($file =~ /^(.*\.s?html?)\.bak$/i) &&
                   10664:                                          ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071    raeburn  10665:                              $unused{$path.'/'.$file} = 1; 
                   10666:                          }
                   10667:                     }
                   10668:                 }
                   10669:             }
                   10670:         }
1.984     raeburn  10671:     }
1.987     raeburn  10672:     my %currfile;
1.1075.2.35  raeburn  10673:     if (($actionurl eq '/adm/portfolio') ||
                   10674:         ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021    raeburn  10675:         my ($dirlistref,$listerror) =
                   10676:             &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
                   10677:         if (ref($dirlistref) eq 'ARRAY') {
                   10678:             foreach my $line (@{$dirlistref}) {
                   10679:                 my ($file_name,$rest) = split(/\&/,$line,2);
                   10680:                 $currfile{$file_name} = 1;
                   10681:             }
1.984     raeburn  10682:         }
1.987     raeburn  10683:     } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984     raeburn  10684:         if (opendir(my $dir,$url)) {
1.987     raeburn  10685:             my @dir_list = grep(!/^\./,readdir($dir));
1.984     raeburn  10686:             map {$currfile{$_} = 1;} @dir_list;
                   10687:         }
1.1075.2.11  raeburn  10688:     } elsif (($actionurl eq '/adm/dependencies') ||
                   10689:              (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35  raeburn  10690:               ($args->{'context'} eq 'paste')) ||
                   10691:              ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071    raeburn  10692:         if ($env{'request.course.id'} ne '') {
                   10693:             my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
                   10694:             if ($dir ne '') {
                   10695:                 my ($dirlistref,$listerror) =
                   10696:                     &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
                   10697:                 if (ref($dirlistref) eq 'ARRAY') {
                   10698:                     foreach my $line (@{$dirlistref}) {
                   10699:                         my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
                   10700:                             $size,undef,$mtime)=split(/\&/,$line,12);
                   10701:                         unless (($testdir&$dirptr) ||
                   10702:                                 ($file_name =~ /^\.\.?$/)) {
                   10703:                             $currfile{$file_name} = [$size,$mtime];
                   10704:                         }
                   10705:                     }
                   10706:                 }
                   10707:             }
                   10708:         }
1.984     raeburn  10709:     }
                   10710:     foreach my $file (keys(%dependencies)) {
1.1071    raeburn  10711:         if (exists($currfile{$file})) {
1.987     raeburn  10712:             unless ($mapping{$file} eq $file) {
                   10713:                 $pathchanges{$file} = 1;
                   10714:             }
                   10715:             $existing{$file} = 1;
                   10716:             $numexisting ++;
                   10717:         } else {
1.984     raeburn  10718:             $newfiles{$file} = 1;
                   10719:         }
                   10720:     }
1.1071    raeburn  10721:     foreach my $file (keys(%currfile)) {
                   10722:         unless (($file eq $filename) ||
                   10723:                 ($file eq $filename.'.bak') ||
                   10724:                 ($dependencies{$file})) {
1.1075.2.11  raeburn  10725:             if ($actionurl eq '/adm/dependencies') {
1.1075.2.35  raeburn  10726:                 unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
                   10727:                     next if (($rem ne '') &&
                   10728:                              (($env{"httpref.$rem".$file} ne '') ||
                   10729:                               (ref($navmap) &&
                   10730:                               (($navmap->getResourceByUrl($rem.$file) ne '') ||
                   10731:                                (($file =~ /^(.*\.s?html?)\.bak$/i) &&
                   10732:                                 ($navmap->getResourceByUrl($rem.$1)))))));
                   10733:                 }
1.1075.2.11  raeburn  10734:             }
1.1071    raeburn  10735:             $unused{$file} = 1;
                   10736:         }
                   10737:     }
1.1075.2.11  raeburn  10738:     if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
                   10739:         ($args->{'context'} eq 'paste')) {
                   10740:         $counter = scalar(keys(%existing));
                   10741:         $numpathchg = scalar(keys(%pathchanges));
                   10742:         return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35  raeburn  10743:     } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
                   10744:              (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
                   10745:         $counter = scalar(keys(%existing));
                   10746:         $numpathchg = scalar(keys(%pathchanges));
                   10747:         return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11  raeburn  10748:     }
1.984     raeburn  10749:     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071    raeburn  10750:         if ($actionurl eq '/adm/dependencies') {
                   10751:             next if ($embed_file =~ m{^\w+://});
                   10752:         }
1.660     raeburn  10753:         $upload_output .= &start_data_table_row().
1.1075.2.35  raeburn  10754:                           '<td valign="top"><img src="'.&icon($embed_file).'" />&nbsp;'.
1.1071    raeburn  10755:                           '<span class="LC_filename">'.$embed_file.'</span>';
1.987     raeburn  10756:         unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35  raeburn  10757:             $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
                   10758:                               &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987     raeburn  10759:         }
1.1075.2.35  raeburn  10760:         $upload_output .= '</td>';
1.1071    raeburn  10761:         if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) { 
1.1075.2.35  raeburn  10762:             $upload_output.='<td align="right">'.
                   10763:                             '<span class="LC_info LC_fontsize_medium">'.
                   10764:                             &mt("URL points to web address").'</span>';
1.987     raeburn  10765:             $numremref++;
1.660     raeburn  10766:         } elsif ($args->{'error_on_invalid_names'}
                   10767:             && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35  raeburn  10768:             $upload_output.='<td align="right"><span class="LC_warning">'.
                   10769:                             &mt('Invalid characters').'</span>';
1.987     raeburn  10770:             $numinvalid++;
1.660     raeburn  10771:         } else {
1.1075.2.35  raeburn  10772:             $upload_output .= '<td>'.
                   10773:                               &embedded_file_element('upload_embedded',$counter,
1.987     raeburn  10774:                                                      $embed_file,\%mapping,
1.1071    raeburn  10775:                                                      $allfiles,$codebase,'upload');
                   10776:             $counter ++;
                   10777:             $numnew ++;
1.987     raeburn  10778:         }
                   10779:         $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
                   10780:     }
                   10781:     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071    raeburn  10782:         if ($actionurl eq '/adm/dependencies') {
                   10783:             my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
                   10784:             $modify_output .= &start_data_table_row().
                   10785:                               '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
                   10786:                               '<img src="'.&icon($embed_file).'" border="0" />'.
                   10787:                               '&nbsp;<span class="LC_filename">'.$embed_file.'</span></a></td>'.
                   10788:                               '<td>'.$size.'</td>'.
                   10789:                               '<td>'.$mtime.'</td>'.
                   10790:                               '<td><label><input type="checkbox" name="mod_upload_dep" '.
                   10791:                               'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
                   10792:                               $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
                   10793:                               '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
                   10794:                               &embedded_file_element('upload_embedded',$counter,
                   10795:                                                      $embed_file,\%mapping,
                   10796:                                                      $allfiles,$codebase,'modify').
                   10797:                               '</div></td>'.
                   10798:                               &end_data_table_row()."\n";
                   10799:             $counter ++;
                   10800:         } else {
                   10801:             $upload_output .= &start_data_table_row().
1.1075.2.35  raeburn  10802:                               '<td valign="top"><img src="'.&icon($embed_file).'" />&nbsp;'.
                   10803:                               '<span class="LC_filename">'.$embed_file.'</span></td>'.
                   10804:                               '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071    raeburn  10805:                               &Apache::loncommon::end_data_table_row()."\n";
                   10806:         }
                   10807:     }
                   10808:     my $delidx = $counter;
                   10809:     foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
                   10810:         my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
                   10811:         $delete_output .= &start_data_table_row().
                   10812:                           '<td><img src="'.&icon($oldfile).'" />'.
                   10813:                           '&nbsp;<span class="LC_filename">'.$oldfile.'</span></td>'.
                   10814:                           '<td>'.$size.'</td>'.
                   10815:                           '<td>'.$mtime.'</td>'.
                   10816:                           '<td><label><input type="checkbox" name="del_upload_dep" '.
                   10817:                           ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
                   10818:                           &embedded_file_element('upload_embedded',$delidx,
                   10819:                                                  $oldfile,\%mapping,$allfiles,
                   10820:                                                  $codebase,'delete').'</td>'.
                   10821:                           &end_data_table_row()."\n"; 
                   10822:         $numunused ++;
                   10823:         $delidx ++;
1.987     raeburn  10824:     }
                   10825:     if ($upload_output) {
                   10826:         $upload_output = &start_data_table().
                   10827:                          $upload_output.
                   10828:                          &end_data_table()."\n";
                   10829:     }
1.1071    raeburn  10830:     if ($modify_output) {
                   10831:         $modify_output = &start_data_table().
                   10832:                          &start_data_table_header_row().
                   10833:                          '<th>'.&mt('File').'</th>'.
                   10834:                          '<th>'.&mt('Size (KB)').'</th>'.
                   10835:                          '<th>'.&mt('Modified').'</th>'.
                   10836:                          '<th>'.&mt('Upload replacement?').'</th>'.
                   10837:                          &end_data_table_header_row().
                   10838:                          $modify_output.
                   10839:                          &end_data_table()."\n";
                   10840:     }
                   10841:     if ($delete_output) {
                   10842:         $delete_output = &start_data_table().
                   10843:                          &start_data_table_header_row().
                   10844:                          '<th>'.&mt('File').'</th>'.
                   10845:                          '<th>'.&mt('Size (KB)').'</th>'.
                   10846:                          '<th>'.&mt('Modified').'</th>'.
                   10847:                          '<th>'.&mt('Delete?').'</th>'.
                   10848:                          &end_data_table_header_row().
                   10849:                          $delete_output.
                   10850:                          &end_data_table()."\n";
                   10851:     }
1.987     raeburn  10852:     my $applies = 0;
                   10853:     if ($numremref) {
                   10854:         $applies ++;
                   10855:     }
                   10856:     if ($numinvalid) {
                   10857:         $applies ++;
                   10858:     }
                   10859:     if ($numexisting) {
                   10860:         $applies ++;
                   10861:     }
1.1071    raeburn  10862:     if ($counter || $numunused) {
1.987     raeburn  10863:         $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
                   10864:                   ' method="post" enctype="multipart/form-data">'."\n".
1.1071    raeburn  10865:                   $state.'<h3>'.$heading.'</h3>'; 
                   10866:         if ($actionurl eq '/adm/dependencies') {
                   10867:             if ($numnew) {
                   10868:                 $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
                   10869:                            '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
                   10870:                            $upload_output.'<br />'."\n";
                   10871:             }
                   10872:             if ($numexisting) {
                   10873:                 $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
                   10874:                            '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
                   10875:                            $modify_output.'<br />'."\n";
                   10876:                            $buttontext = &mt('Save changes');
                   10877:             }
                   10878:             if ($numunused) {
                   10879:                 $output .= '<h4>'.&mt('Unused files').'</h4>'.
                   10880:                            '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
                   10881:                            $delete_output.'<br />'."\n";
                   10882:                            $buttontext = &mt('Save changes');
                   10883:             }
                   10884:         } else {
                   10885:             $output .= $upload_output.'<br />'."\n";
                   10886:         }
                   10887:         $output .= '<input type ="hidden" name="number_embedded_items" value="'.
                   10888:                    $counter.'" />'."\n";
                   10889:         if ($actionurl eq '/adm/dependencies') { 
                   10890:             $output .= '<input type ="hidden" name="number_newemb_items" value="'.
                   10891:                        $numnew.'" />'."\n";
                   10892:         } elsif ($actionurl eq '') {
1.987     raeburn  10893:             $output .=  '<input type="hidden" name="phase" value="three" />';
                   10894:         }
                   10895:     } elsif ($applies) {
                   10896:         $output = '<b>'.&mt('Referenced files').'</b>:<br />';
                   10897:         if ($applies > 1) {
                   10898:             $output .=  
1.1075.2.35  raeburn  10899:                 &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987     raeburn  10900:             if ($numremref) {
                   10901:                 $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
                   10902:             }
                   10903:             if ($numinvalid) {
                   10904:                 $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
                   10905:             }
                   10906:             if ($numexisting) {
                   10907:                 $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
                   10908:             }
                   10909:             $output .= '</ul><br />';
                   10910:         } elsif ($numremref) {
                   10911:             $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
                   10912:         } elsif ($numinvalid) {
                   10913:             $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
                   10914:         } elsif ($numexisting) {
                   10915:             $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
                   10916:         }
                   10917:         $output .= $upload_output.'<br />';
                   10918:     }
                   10919:     my ($pathchange_output,$chgcount);
1.1071    raeburn  10920:     $chgcount = $counter;
1.987     raeburn  10921:     if (keys(%pathchanges) > 0) {
                   10922:         foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071    raeburn  10923:             if ($counter) {
1.987     raeburn  10924:                 $output .= &embedded_file_element('pathchange',$chgcount,
                   10925:                                                   $embed_file,\%mapping,
1.1071    raeburn  10926:                                                   $allfiles,$codebase,'change');
1.987     raeburn  10927:             } else {
                   10928:                 $pathchange_output .= 
                   10929:                     &start_data_table_row().
                   10930:                     '<td><input type ="checkbox" name="namechange" value="'.
                   10931:                     $chgcount.'" checked="checked" /></td>'.
                   10932:                     '<td>'.$mapping{$embed_file}.'</td>'.
                   10933:                     '<td>'.$embed_file.
                   10934:                     &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071    raeburn  10935:                                            \%mapping,$allfiles,$codebase,'change').
1.987     raeburn  10936:                     '</td>'.&end_data_table_row();
1.660     raeburn  10937:             }
1.987     raeburn  10938:             $numpathchg ++;
                   10939:             $chgcount ++;
1.660     raeburn  10940:         }
                   10941:     }
1.1075.2.35  raeburn  10942:     if (($counter) || ($numunused)) {
1.987     raeburn  10943:         if ($numpathchg) {
                   10944:             $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
                   10945:                        $numpathchg.'" />'."\n";
                   10946:         }
                   10947:         if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') || 
                   10948:             ($actionurl eq '/adm/imsimport')) {
                   10949:             $output .= '<input type="hidden" name="phase" value="three" />'."\n";
                   10950:         } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
                   10951:             $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071    raeburn  10952:         } elsif ($actionurl eq '/adm/dependencies') {
                   10953:             $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987     raeburn  10954:         }
1.1075.2.35  raeburn  10955:         $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987     raeburn  10956:     } elsif ($numpathchg) {
                   10957:         my %pathchange = ();
                   10958:         $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
                   10959:         if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
                   10960:             $output .= '<p>'.&mt('or').'</p>'; 
1.1075.2.35  raeburn  10961:         }
1.987     raeburn  10962:     }
1.1071    raeburn  10963:     return ($output,$counter,$numpathchg);
1.987     raeburn  10964: }
                   10965: 
1.1075.2.47  raeburn  10966: =pod
                   10967: 
                   10968: =item * clean_path($name)
                   10969: 
                   10970: Performs clean-up of directories, subdirectories and filename in an
                   10971: embedded object, referenced in an HTML file which is being uploaded
                   10972: to a course or portfolio, where
                   10973: "Upload embedded images/multimedia files if HTML file" checkbox was
                   10974: checked.
                   10975: 
                   10976: Clean-up is similar to replacements in lonnet::clean_filename()
                   10977: except each / between sub-directory and next level is preserved.
                   10978: 
                   10979: =cut
                   10980: 
                   10981: sub clean_path {
                   10982:     my ($embed_file) = @_;
                   10983:     $embed_file =~s{^/+}{};
                   10984:     my @contents;
                   10985:     if ($embed_file =~ m{/}) {
                   10986:         @contents = split(/\//,$embed_file);
                   10987:     } else {
                   10988:         @contents = ($embed_file);
                   10989:     }
                   10990:     my $lastidx = scalar(@contents)-1;
                   10991:     for (my $i=0; $i<=$lastidx; $i++) {
                   10992:         $contents[$i]=~s{\\}{/}g;
                   10993:         $contents[$i]=~s/\s+/\_/g;
                   10994:         $contents[$i]=~s{[^/\w\.\-]}{}g;
                   10995:         if ($i == $lastidx) {
                   10996:             $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
                   10997:         }
                   10998:     }
                   10999:     if ($lastidx > 0) {
                   11000:         return join('/',@contents);
                   11001:     } else {
                   11002:         return $contents[0];
                   11003:     }
                   11004: }
                   11005: 
1.987     raeburn  11006: sub embedded_file_element {
1.1071    raeburn  11007:     my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987     raeburn  11008:     return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
                   11009:                    (ref($codebase) eq 'HASH'));
                   11010:     my $output;
1.1071    raeburn  11011:     if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987     raeburn  11012:        $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
                   11013:     }
                   11014:     $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
                   11015:                &escape($embed_file).'" />';
                   11016:     unless (($context eq 'upload_embedded') && 
                   11017:             ($mapping->{$embed_file} eq $embed_file)) {
                   11018:         $output .='
                   11019:         <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
                   11020:     }
                   11021:     my $attrib;
                   11022:     if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
                   11023:         $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
                   11024:     }
                   11025:     $output .=
                   11026:         "\n\t\t".
                   11027:         '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
                   11028:         $attrib.'" />';
                   11029:     if (exists($codebase->{$mapping->{$embed_file}})) {
                   11030:         $output .=
                   11031:             "\n\t\t".
                   11032:             '<input name="codebase_'.$num.'" type="hidden" value="'.
                   11033:             &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984     raeburn  11034:     }
1.987     raeburn  11035:     return $output;
1.660     raeburn  11036: }
                   11037: 
1.1071    raeburn  11038: sub get_dependency_details {
                   11039:     my ($currfile,$currsubfile,$embed_file) = @_;
                   11040:     my ($size,$mtime,$showsize,$showmtime);
                   11041:     if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
                   11042:         if ($embed_file =~ m{/}) {
                   11043:             my ($path,$fname) = split(/\//,$embed_file);
                   11044:             if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
                   11045:                 ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
                   11046:             }
                   11047:         } else {
                   11048:             if (ref($currfile->{$embed_file}) eq 'ARRAY') {
                   11049:                 ($size,$mtime) = @{$currfile->{$embed_file}};
                   11050:             }
                   11051:         }
                   11052:         $showsize = $size/1024.0;
                   11053:         $showsize = sprintf("%.1f",$showsize);
                   11054:         if ($mtime > 0) {
                   11055:             $showmtime = &Apache::lonlocal::locallocaltime($mtime);
                   11056:         }
                   11057:     }
                   11058:     return ($showsize,$showmtime);
                   11059: }
                   11060: 
                   11061: sub ask_embedded_js {
                   11062:     return <<"END";
                   11063: <script type="text/javascript"">
                   11064: // <![CDATA[
                   11065: function toggleBrowse(counter) {
                   11066:     var chkboxid = document.getElementById('mod_upload_dep_'+counter);
                   11067:     var fileid = document.getElementById('embedded_item_'+counter);
                   11068:     var uploaddivid = document.getElementById('moduploaddep_'+counter);
                   11069:     if (chkboxid.checked == true) {
                   11070:         uploaddivid.style.display='block';
                   11071:     } else {
                   11072:         uploaddivid.style.display='none';
                   11073:         fileid.value = '';
                   11074:     }
                   11075: }
                   11076: // ]]>
                   11077: </script>
                   11078: 
                   11079: END
                   11080: }
                   11081: 
1.661     raeburn  11082: sub upload_embedded {
                   11083:     my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987     raeburn  11084:         $current_disk_usage,$hiddenstate,$actionurl) = @_;
                   11085:     my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661     raeburn  11086:     for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
                   11087:         next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
                   11088:         my $orig_uploaded_filename =
                   11089:             $env{'form.embedded_item_'.$i.'.filename'};
1.987     raeburn  11090:         foreach my $type ('orig','ref','attrib','codebase') {
                   11091:             if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
                   11092:                 $env{'form.embedded_'.$type.'_'.$i} =
                   11093:                     &unescape($env{'form.embedded_'.$type.'_'.$i});
                   11094:             }
                   11095:         }
1.661     raeburn  11096:         my ($path,$fname) =
                   11097:             ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
                   11098:         # no path, whole string is fname
                   11099:         if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
                   11100:         $fname = &Apache::lonnet::clean_filename($fname);
                   11101:         # See if there is anything left
                   11102:         next if ($fname eq '');
                   11103: 
                   11104:         # Check if file already exists as a file or directory.
                   11105:         my ($state,$msg);
                   11106:         if ($context eq 'portfolio') {
                   11107:             my $port_path = $dirpath;
                   11108:             if ($group ne '') {
                   11109:                 $port_path = "groups/$group/$port_path";
                   11110:             }
1.987     raeburn  11111:             ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
                   11112:                                               $fname,$group,'embedded_item_'.$i,
1.661     raeburn  11113:                                               $dir_root,$port_path,$disk_quota,
                   11114:                                               $current_disk_usage,$uname,$udom);
                   11115:             if ($state eq 'will_exceed_quota'
1.984     raeburn  11116:                 || $state eq 'file_locked') {
1.661     raeburn  11117:                 $output .= $msg;
                   11118:                 next;
                   11119:             }
                   11120:         } elsif (($context eq 'author') || ($context eq 'testbank')) {
                   11121:             ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
                   11122:             if ($state eq 'exists') {
                   11123:                 $output .= $msg;
                   11124:                 next;
                   11125:             }
                   11126:         }
                   11127:         # Check if extension is valid
                   11128:         if (($fname =~ /\.(\w+)$/) &&
                   11129:             (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53  raeburn  11130:             $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
                   11131:                       .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661     raeburn  11132:             next;
                   11133:         } elsif (($fname =~ /\.(\w+)$/) &&
                   11134:                  (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987     raeburn  11135:             $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661     raeburn  11136:             next;
                   11137:         } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34  raeburn  11138:             $output .= &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2).'<br />';
1.661     raeburn  11139:             next;
                   11140:         }
                   11141:         $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35  raeburn  11142:         my $subdir = $path;
                   11143:         $subdir =~ s{/+$}{};
1.661     raeburn  11144:         if ($context eq 'portfolio') {
1.984     raeburn  11145:             my $result;
                   11146:             if ($state eq 'existingfile') {
                   11147:                 $result=
                   11148:                     &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35  raeburn  11149:                                                     $dirpath.$env{'form.currentpath'}.$subdir);
1.661     raeburn  11150:             } else {
1.984     raeburn  11151:                 $result=
                   11152:                     &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987     raeburn  11153:                                                     $dirpath.
1.1075.2.35  raeburn  11154:                                                     $env{'form.currentpath'}.$subdir);
1.984     raeburn  11155:                 if ($result !~ m|^/uploaded/|) {
                   11156:                     $output .= '<span class="LC_error">'
                   11157:                                .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
                   11158:                                ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
                   11159:                                .'</span><br />';
                   11160:                     next;
                   11161:                 } else {
1.987     raeburn  11162:                     $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
                   11163:                                $path.$fname.'</span>').'<br />';     
1.984     raeburn  11164:                 }
1.661     raeburn  11165:             }
1.1075.2.35  raeburn  11166:         } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
                   11167:             my $extendedsubdir = $dirpath.'/'.$subdir;
                   11168:             $extendedsubdir =~ s{/+$}{};
1.987     raeburn  11169:             my $result =
1.1075.2.35  raeburn  11170:                 &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987     raeburn  11171:             if ($result !~ m|^/uploaded/|) {
                   11172:                 $output .= '<span class="LC_error">'
                   11173:                            .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
                   11174:                            ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
                   11175:                            .'</span><br />';
                   11176:                     next;
                   11177:             } else {
                   11178:                 $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
                   11179:                            $path.$fname.'</span>').'<br />';
1.1075.2.35  raeburn  11180:                 if ($context eq 'syllabus') {
                   11181:                     &Apache::lonnet::make_public_indefinitely($result);
                   11182:                 }
1.987     raeburn  11183:             }
1.661     raeburn  11184:         } else {
                   11185: # Save the file
                   11186:             my $target = $env{'form.embedded_item_'.$i};
                   11187:             my $fullpath = $dir_root.$dirpath.'/'.$path;
                   11188:             my $dest = $fullpath.$fname;
                   11189:             my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027    raeburn  11190:             my @parts=split(/\//,"$dirpath/$path");
1.661     raeburn  11191:             my $count;
                   11192:             my $filepath = $dir_root;
1.1027    raeburn  11193:             foreach my $subdir (@parts) {
                   11194:                 $filepath .= "/$subdir";
                   11195:                 if (!-e $filepath) {
1.661     raeburn  11196:                     mkdir($filepath,0770);
                   11197:                 }
                   11198:             }
                   11199:             my $fh;
                   11200:             if (!open($fh,'>'.$dest)) {
                   11201:                 &Apache::lonnet::logthis('Failed to create '.$dest);
                   11202:                 $output .= '<span class="LC_error">'.
1.1071    raeburn  11203:                            &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
                   11204:                                $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661     raeburn  11205:                            '</span><br />';
                   11206:             } else {
                   11207:                 if (!print $fh $env{'form.embedded_item_'.$i}) {
                   11208:                     &Apache::lonnet::logthis('Failed to write to '.$dest);
                   11209:                     $output .= '<span class="LC_error">'.
1.1071    raeburn  11210:                               &mt('An error occurred while writing the file [_1] for embedded element [_2].',
                   11211:                                   $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661     raeburn  11212:                               '</span><br />';
                   11213:                 } else {
1.987     raeburn  11214:                     $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
                   11215:                                $url.'</span>').'<br />';
                   11216:                     unless ($context eq 'testbank') {
                   11217:                         $footer .= &mt('View embedded file: [_1]',
                   11218:                                        '<a href="'.$url.'">'.$fname.'</a>').'<br />';
                   11219:                     }
                   11220:                 }
                   11221:                 close($fh);
                   11222:             }
                   11223:         }
                   11224:         if ($env{'form.embedded_ref_'.$i}) {
                   11225:             $pathchange{$i} = 1;
                   11226:         }
                   11227:     }
                   11228:     if ($output) {
                   11229:         $output = '<p>'.$output.'</p>';
                   11230:     }
                   11231:     $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
                   11232:     $returnflag = 'ok';
1.1071    raeburn  11233:     my $numpathchgs = scalar(keys(%pathchange));
                   11234:     if ($numpathchgs > 0) {
1.987     raeburn  11235:         if ($context eq 'portfolio') {
                   11236:             $output .= '<p>'.&mt('or').'</p>';
                   11237:         } elsif ($context eq 'testbank') {
1.1071    raeburn  11238:             $output .=  '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
                   11239:                                   '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987     raeburn  11240:             $returnflag = 'modify_orightml';
                   11241:         }
                   11242:     }
1.1071    raeburn  11243:     return ($output.$footer,$returnflag,$numpathchgs);
1.987     raeburn  11244: }
                   11245: 
                   11246: sub modify_html_form {
                   11247:     my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
                   11248:     my $end = 0;
                   11249:     my $modifyform;
                   11250:     if ($context eq 'upload_embedded') {
                   11251:         return unless (ref($pathchange) eq 'HASH');
                   11252:         if ($env{'form.number_embedded_items'}) {
                   11253:             $end += $env{'form.number_embedded_items'};
                   11254:         }
                   11255:         if ($env{'form.number_pathchange_items'}) {
                   11256:             $end += $env{'form.number_pathchange_items'};
                   11257:         }
                   11258:         if ($end) {
                   11259:             for (my $i=0; $i<$end; $i++) {
                   11260:                 if ($i < $env{'form.number_embedded_items'}) {
                   11261:                     next unless($pathchange->{$i});
                   11262:                 }
                   11263:                 $modifyform .=
                   11264:                     &start_data_table_row().
                   11265:                     '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
                   11266:                     'checked="checked" /></td>'.
                   11267:                     '<td>'.$env{'form.embedded_ref_'.$i}.
                   11268:                     '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
                   11269:                     &escape($env{'form.embedded_ref_'.$i}).'" />'.
                   11270:                     '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
                   11271:                     &escape($env{'form.embedded_codebase_'.$i}).'" />'.
                   11272:                     '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
                   11273:                     &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
                   11274:                     '<td>'.$env{'form.embedded_orig_'.$i}.
                   11275:                     '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
                   11276:                     &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
                   11277:                     &end_data_table_row();
1.1071    raeburn  11278:             }
1.987     raeburn  11279:         }
                   11280:     } else {
                   11281:         $modifyform = $pathchgtable;
                   11282:         if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
                   11283:             $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
                   11284:         } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
                   11285:             $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
                   11286:         }
                   11287:     }
                   11288:     if ($modifyform) {
1.1071    raeburn  11289:         if ($actionurl eq '/adm/dependencies') {
                   11290:             $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
                   11291:         }
1.987     raeburn  11292:         return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
                   11293:                '<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".
                   11294:                '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
                   11295:                '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
                   11296:                '</ol></p>'."\n".'<p>'.
                   11297:                &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
                   11298:                '<form method="post" name="refchanger" action="'.$actionurl.'">'.
                   11299:                &start_data_table()."\n".
                   11300:                &start_data_table_header_row().
                   11301:                '<th>'.&mt('Change?').'</th>'.
                   11302:                '<th>'.&mt('Current reference').'</th>'.
                   11303:                '<th>'.&mt('Required reference').'</th>'.
                   11304:                &end_data_table_header_row()."\n".
                   11305:                $modifyform.
                   11306:                &end_data_table().'<br />'."\n".$hiddenstate.
                   11307:                '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
                   11308:                '</form>'."\n";
                   11309:     }
                   11310:     return;
                   11311: }
                   11312: 
                   11313: sub modify_html_refs {
1.1075.2.35  raeburn  11314:     my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987     raeburn  11315:     my $container;
                   11316:     if ($context eq 'portfolio') {
                   11317:         $container = $env{'form.container'};
                   11318:     } elsif ($context eq 'coursedoc') {
                   11319:         $container = $env{'form.primaryurl'};
1.1071    raeburn  11320:     } elsif ($context eq 'manage_dependencies') {
                   11321:         (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
                   11322:         $container = "/$container";
1.1075.2.35  raeburn  11323:     } elsif ($context eq 'syllabus') {
                   11324:         $container = $url;
1.987     raeburn  11325:     } else {
1.1027    raeburn  11326:         $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987     raeburn  11327:     }
                   11328:     my (%allfiles,%codebase,$output,$content);
                   11329:     my @changes = &get_env_multiple('form.namechange');
1.1075.2.35  raeburn  11330:     unless ((@changes > 0)  || ($context eq 'syllabus')) {
1.1071    raeburn  11331:         if (wantarray) {
                   11332:             return ('',0,0); 
                   11333:         } else {
                   11334:             return;
                   11335:         }
                   11336:     }
                   11337:     if (($context eq 'portfolio') || ($context eq 'coursedoc') || 
1.1075.2.35  raeburn  11338:         ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071    raeburn  11339:         unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
                   11340:             if (wantarray) {
                   11341:                 return ('',0,0);
                   11342:             } else {
                   11343:                 return;
                   11344:             }
                   11345:         } 
1.987     raeburn  11346:         $content = &Apache::lonnet::getfile($container);
1.1071    raeburn  11347:         if ($content eq '-1') {
                   11348:             if (wantarray) {
                   11349:                 return ('',0,0);
                   11350:             } else {
                   11351:                 return;
                   11352:             }
                   11353:         }
1.987     raeburn  11354:     } else {
1.1071    raeburn  11355:         unless ($container =~ /^\Q$dir_root\E/) {
                   11356:             if (wantarray) {
                   11357:                 return ('',0,0);
                   11358:             } else {
                   11359:                 return;
                   11360:             }
                   11361:         } 
1.987     raeburn  11362:         if (open(my $fh,"<$container")) {
                   11363:             $content = join('', <$fh>);
                   11364:             close($fh);
                   11365:         } else {
1.1071    raeburn  11366:             if (wantarray) {
                   11367:                 return ('',0,0);
                   11368:             } else {
                   11369:                 return;
                   11370:             }
1.987     raeburn  11371:         }
                   11372:     }
                   11373:     my ($count,$codebasecount) = (0,0);
                   11374:     my $mm = new File::MMagic;
                   11375:     my $mime_type = $mm->checktype_contents($content);
                   11376:     if ($mime_type eq 'text/html') {
                   11377:         my $parse_result = 
                   11378:             &Apache::lonnet::extract_embedded_items($container,\%allfiles,
                   11379:                                                     \%codebase,\$content);
                   11380:         if ($parse_result eq 'ok') {
                   11381:             foreach my $i (@changes) {
                   11382:                 my $orig = &unescape($env{'form.embedded_orig_'.$i});
                   11383:                 my $ref = &unescape($env{'form.embedded_ref_'.$i});
                   11384:                 if ($allfiles{$ref}) {
                   11385:                     my $newname =  $orig;
                   11386:                     my ($attrib_regexp,$codebase);
1.1006    raeburn  11387:                     $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987     raeburn  11388:                     if ($attrib_regexp =~ /:/) {
                   11389:                         $attrib_regexp =~ s/\:/|/g;
                   11390:                     }
                   11391:                     if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
                   11392:                         my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
                   11393:                         $count += $numchg;
1.1075.2.35  raeburn  11394:                         $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48  raeburn  11395:                         delete($allfiles{$ref});
1.987     raeburn  11396:                     }
                   11397:                     if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006    raeburn  11398:                         $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987     raeburn  11399:                         my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
                   11400:                         $codebasecount ++;
                   11401:                     }
                   11402:                 }
                   11403:             }
1.1075.2.35  raeburn  11404:             my $skiprewrites;
1.987     raeburn  11405:             if ($count || $codebasecount) {
                   11406:                 my $saveresult;
1.1071    raeburn  11407:                 if (($context eq 'portfolio') || ($context eq 'coursedoc') || 
1.1075.2.35  raeburn  11408:                     ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987     raeburn  11409:                     my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
                   11410:                     if ($url eq $container) {
                   11411:                         my ($fname) = ($container =~ m{/([^/]+)$});
                   11412:                         $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
                   11413:                                             $count,'<span class="LC_filename">'.
1.1071    raeburn  11414:                                             $fname.'</span>').'</p>';
1.987     raeburn  11415:                     } else {
                   11416:                          $output = '<p class="LC_error">'.
                   11417:                                    &mt('Error: update failed for: [_1].',
                   11418:                                    '<span class="LC_filename">'.
                   11419:                                    $container.'</span>').'</p>';
                   11420:                     }
1.1075.2.35  raeburn  11421:                     if ($context eq 'syllabus') {
                   11422:                         unless ($saveresult eq 'ok') {
                   11423:                             $skiprewrites = 1;
                   11424:                         }
                   11425:                     }
1.987     raeburn  11426:                 } else {
                   11427:                     if (open(my $fh,">$container")) {
                   11428:                         print $fh $content;
                   11429:                         close($fh);
                   11430:                         $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
                   11431:                                   $count,'<span class="LC_filename">'.
                   11432:                                   $container.'</span>').'</p>';
1.661     raeburn  11433:                     } else {
1.987     raeburn  11434:                          $output = '<p class="LC_error">'.
                   11435:                                    &mt('Error: could not update [_1].',
                   11436:                                    '<span class="LC_filename">'.
                   11437:                                    $container.'</span>').'</p>';
1.661     raeburn  11438:                     }
                   11439:                 }
                   11440:             }
1.1075.2.35  raeburn  11441:             if (($context eq 'syllabus') && (!$skiprewrites)) {
                   11442:                 my ($actionurl,$state);
                   11443:                 $actionurl = "/public/$udom/$uname/syllabus";
                   11444:                 my ($ignore,$num,$numpathchanges,$existing,$mapping) =
                   11445:                     &ask_for_embedded_content($actionurl,$state,\%allfiles,
                   11446:                                               \%codebase,
                   11447:                                               {'context' => 'rewrites',
                   11448:                                                'ignore_remote_references' => 1,});
                   11449:                 if (ref($mapping) eq 'HASH') {
                   11450:                     my $rewrites = 0;
                   11451:                     foreach my $key (keys(%{$mapping})) {
                   11452:                         next if ($key =~ m{^https?://});
                   11453:                         my $ref = $mapping->{$key};
                   11454:                         my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
                   11455:                         my $attrib;
                   11456:                         if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
                   11457:                             $attrib = join('|',@{$allfiles{$mapping->{$key}}});
                   11458:                         }
                   11459:                         if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
                   11460:                             my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
                   11461:                             $rewrites += $numchg;
                   11462:                         }
                   11463:                     }
                   11464:                     if ($rewrites) {
                   11465:                         my $saveresult;
                   11466:                         my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
                   11467:                         if ($url eq $container) {
                   11468:                             my ($fname) = ($container =~ m{/([^/]+)$});
                   11469:                             $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
                   11470:                                             $count,'<span class="LC_filename">'.
                   11471:                                             $fname.'</span>').'</p>';
                   11472:                         } else {
                   11473:                             $output .= '<p class="LC_error">'.
                   11474:                                        &mt('Error: could not update links in [_1].',
                   11475:                                        '<span class="LC_filename">'.
                   11476:                                        $container.'</span>').'</p>';
                   11477: 
                   11478:                         }
                   11479:                     }
                   11480:                 }
                   11481:             }
1.987     raeburn  11482:         } else {
                   11483:             &logthis('Failed to parse '.$container.
                   11484:                      ' to modify references: '.$parse_result);
1.661     raeburn  11485:         }
                   11486:     }
1.1071    raeburn  11487:     if (wantarray) {
                   11488:         return ($output,$count,$codebasecount);
                   11489:     } else {
                   11490:         return $output;
                   11491:     }
1.661     raeburn  11492: }
                   11493: 
                   11494: sub check_for_existing {
                   11495:     my ($path,$fname,$element) = @_;
                   11496:     my ($state,$msg);
                   11497:     if (-d $path.'/'.$fname) {
                   11498:         $state = 'exists';
                   11499:         $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   11500:     } elsif (-e $path.'/'.$fname) {
                   11501:         $state = 'exists';
                   11502:         $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   11503:     }
                   11504:     if ($state eq 'exists') {
                   11505:         $msg = '<span class="LC_error">'.$msg.'</span><br />';
                   11506:     }
                   11507:     return ($state,$msg);
                   11508: }
                   11509: 
                   11510: sub check_for_upload {
                   11511:     my ($path,$fname,$group,$element,$portfolio_root,$port_path,
                   11512:         $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985     raeburn  11513:     my $filesize = length($env{'form.'.$element});
                   11514:     if (!$filesize) {
                   11515:         my $msg = '<span class="LC_error">'.
                   11516:                   &mt('Unable to upload [_1]. (size = [_2] bytes)', 
                   11517:                       '<span class="LC_filename">'.$fname.'</span>',
                   11518:                       $filesize).'<br />'.
1.1007    raeburn  11519:                   &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985     raeburn  11520:                   '</span>';
                   11521:         return ('zero_bytes',$msg);
                   11522:     }
                   11523:     $filesize =  $filesize/1000; #express in k (1024?)
1.661     raeburn  11524:     my $getpropath = 1;
1.1021    raeburn  11525:     my ($dirlistref,$listerror) =
                   11526:          &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661     raeburn  11527:     my $found_file = 0;
                   11528:     my $locked_file = 0;
1.991     raeburn  11529:     my @lockers;
                   11530:     my $navmap;
                   11531:     if ($env{'request.course.id'}) {
                   11532:         $navmap = Apache::lonnavmaps::navmap->new();
                   11533:     }
1.1021    raeburn  11534:     if (ref($dirlistref) eq 'ARRAY') {
                   11535:         foreach my $line (@{$dirlistref}) {
                   11536:             my ($file_name,$rest)=split(/\&/,$line,2);
                   11537:             if ($file_name eq $fname){
                   11538:                 $file_name = $path.$file_name;
                   11539:                 if ($group ne '') {
                   11540:                     $file_name = $group.$file_name;
                   11541:                 }
                   11542:                 $found_file = 1;
                   11543:                 if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
                   11544:                     foreach my $lock (@lockers) {
                   11545:                         if (ref($lock) eq 'ARRAY') {
                   11546:                             my ($symb,$crsid) = @{$lock};
                   11547:                             if ($crsid eq $env{'request.course.id'}) {
                   11548:                                 if (ref($navmap)) {
                   11549:                                     my $res = $navmap->getBySymb($symb);
                   11550:                                     foreach my $part (@{$res->parts()}) { 
                   11551:                                         my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
                   11552:                                         unless (($slot_status == $res->RESERVED) ||
                   11553:                                                 ($slot_status == $res->RESERVED_LOCATION)) {
                   11554:                                             $locked_file = 1;
                   11555:                                         }
1.991     raeburn  11556:                                     }
1.1021    raeburn  11557:                                 } else {
                   11558:                                     $locked_file = 1;
1.991     raeburn  11559:                                 }
                   11560:                             } else {
                   11561:                                 $locked_file = 1;
                   11562:                             }
                   11563:                         }
1.1021    raeburn  11564:                    }
                   11565:                 } else {
                   11566:                     my @info = split(/\&/,$rest);
                   11567:                     my $currsize = $info[6]/1000;
                   11568:                     if ($currsize < $filesize) {
                   11569:                         my $extra = $filesize - $currsize;
                   11570:                         if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69  raeburn  11571:                             my $msg = '<p class="LC_warning">'.
1.1021    raeburn  11572:                                       &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.',
1.1075.2.69  raeburn  11573:                                           '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
                   11574:                                       '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
                   11575:                                                    $disk_quota,$current_disk_usage).'</p>';
1.1021    raeburn  11576:                             return ('will_exceed_quota',$msg);
                   11577:                         }
1.984     raeburn  11578:                     }
                   11579:                 }
1.661     raeburn  11580:             }
                   11581:         }
                   11582:     }
                   11583:     if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69  raeburn  11584:         my $msg = '<p class="LC_warning">'.
                   11585:                 &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
                   11586:                   '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661     raeburn  11587:         return ('will_exceed_quota',$msg);
                   11588:     } elsif ($found_file) {
                   11589:         if ($locked_file) {
1.1075.2.69  raeburn  11590:             my $msg = '<p class="LC_warning">';
1.661     raeburn  11591:             $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>');
1.1075.2.69  raeburn  11592:             $msg .= '</p>';
1.661     raeburn  11593:             $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
                   11594:             return ('file_locked',$msg);
                   11595:         } else {
1.1075.2.69  raeburn  11596:             my $msg = '<p class="LC_error">';
1.984     raeburn  11597:             $msg .= &mt(' A file by that name: [_1] was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
1.1075.2.69  raeburn  11598:             $msg .= '</p>';
1.984     raeburn  11599:             return ('existingfile',$msg);
1.661     raeburn  11600:         }
                   11601:     }
                   11602: }
                   11603: 
1.987     raeburn  11604: sub check_for_traversal {
                   11605:     my ($path,$url,$toplevel) = @_;
                   11606:     my @parts=split(/\//,$path);
                   11607:     my $cleanpath;
                   11608:     my $fullpath = $url;
                   11609:     for (my $i=0;$i<@parts;$i++) {
                   11610:         next if ($parts[$i] eq '.');
                   11611:         if ($parts[$i] eq '..') {
                   11612:             $fullpath =~ s{([^/]+/)$}{};
                   11613:         } else {
                   11614:             $fullpath .= $parts[$i].'/';
                   11615:         }
                   11616:     }
                   11617:     if ($fullpath =~ /^\Q$url\E(.*)$/) {
                   11618:         $cleanpath = $1;
                   11619:     } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
                   11620:         my $curr_toprel = $1;
                   11621:         my @parts = split(/\//,$curr_toprel);
                   11622:         my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
                   11623:         my @urlparts = split(/\//,$url_toprel);
                   11624:         my $doubledots;
                   11625:         my $startdiff = -1;
                   11626:         for (my $i=0; $i<@urlparts; $i++) {
                   11627:             if ($startdiff == -1) {
                   11628:                 unless ($urlparts[$i] eq $parts[$i]) {
                   11629:                     $startdiff = $i;
                   11630:                     $doubledots .= '../';
                   11631:                 }
                   11632:             } else {
                   11633:                 $doubledots .= '../';
                   11634:             }
                   11635:         }
                   11636:         if ($startdiff > -1) {
                   11637:             $cleanpath = $doubledots;
                   11638:             for (my $i=$startdiff; $i<@parts; $i++) {
                   11639:                 $cleanpath .= $parts[$i].'/';
                   11640:             }
                   11641:         }
                   11642:     }
                   11643:     $cleanpath =~ s{(/)$}{};
                   11644:     return $cleanpath;
                   11645: }
1.31      albertel 11646: 
1.1053    raeburn  11647: sub is_archive_file {
                   11648:     my ($mimetype) = @_;
                   11649:     if (($mimetype eq 'application/octet-stream') ||
                   11650:         ($mimetype eq 'application/x-stuffit') ||
                   11651:         ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
                   11652:         return 1;
                   11653:     }
                   11654:     return;
                   11655: }
                   11656: 
                   11657: sub decompress_form {
1.1065    raeburn  11658:     my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053    raeburn  11659:     my %lt = &Apache::lonlocal::texthash (
                   11660:         this => 'This file is an archive file.',
1.1067    raeburn  11661:         camt => 'This file is a Camtasia archive file.',
1.1065    raeburn  11662:         itsc => 'Its contents are as follows:',
1.1053    raeburn  11663:         youm => 'You may wish to extract its contents.',
                   11664:         extr => 'Extract contents',
1.1067    raeburn  11665:         auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
                   11666:         proa => 'Process automatically?',
1.1053    raeburn  11667:         yes  => 'Yes',
                   11668:         no   => 'No',
1.1067    raeburn  11669:         fold => 'Title for folder containing movie',
                   11670:         movi => 'Title for page containing embedded movie', 
1.1053    raeburn  11671:     );
1.1065    raeburn  11672:     my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067    raeburn  11673:     my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065    raeburn  11674:     my $info = &list_archive_contents($fileloc,\@paths);
                   11675:     if (@paths) {
                   11676:         foreach my $path (@paths) {
                   11677:             $path =~ s{^/}{};
1.1067    raeburn  11678:             if ($path =~ m{^([^/]+)/$}) {
                   11679:                 $topdir = $1;
                   11680:             }
1.1065    raeburn  11681:             if ($path =~ m{^([^/]+)/}) {
                   11682:                 $toplevel{$1} = $path;
                   11683:             } else {
                   11684:                 $toplevel{$path} = $path;
                   11685:             }
                   11686:         }
                   11687:     }
1.1067    raeburn  11688:     if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59  raeburn  11689:         my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067    raeburn  11690:                         "$topdir/media/",
                   11691:                         "$topdir/media/$topdir.mp4",
                   11692:                         "$topdir/media/FirstFrame.png",
                   11693:                         "$topdir/media/player.swf",
                   11694:                         "$topdir/media/swfobject.js",
                   11695:                         "$topdir/media/expressInstall.swf");
1.1075.2.81  raeburn  11696:         my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59  raeburn  11697:                          "$topdir/$topdir.mp4",
                   11698:                          "$topdir/$topdir\_config.xml",
                   11699:                          "$topdir/$topdir\_controller.swf",
                   11700:                          "$topdir/$topdir\_embed.css",
                   11701:                          "$topdir/$topdir\_First_Frame.png",
                   11702:                          "$topdir/$topdir\_player.html",
                   11703:                          "$topdir/$topdir\_Thumbnails.png",
                   11704:                          "$topdir/playerProductInstall.swf",
                   11705:                          "$topdir/scripts/",
                   11706:                          "$topdir/scripts/config_xml.js",
                   11707:                          "$topdir/scripts/handlebars.js",
                   11708:                          "$topdir/scripts/jquery-1.7.1.min.js",
                   11709:                          "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
                   11710:                          "$topdir/scripts/modernizr.js",
                   11711:                          "$topdir/scripts/player-min.js",
                   11712:                          "$topdir/scripts/swfobject.js",
                   11713:                          "$topdir/skins/",
                   11714:                          "$topdir/skins/configuration_express.xml",
                   11715:                          "$topdir/skins/express_show/",
                   11716:                          "$topdir/skins/express_show/player-min.css",
                   11717:                          "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81  raeburn  11718:         my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
                   11719:                          "$topdir/$topdir.mp4",
                   11720:                          "$topdir/$topdir\_config.xml",
                   11721:                          "$topdir/$topdir\_controller.swf",
                   11722:                          "$topdir/$topdir\_embed.css",
                   11723:                          "$topdir/$topdir\_First_Frame.png",
                   11724:                          "$topdir/$topdir\_player.html",
                   11725:                          "$topdir/$topdir\_Thumbnails.png",
                   11726:                          "$topdir/playerProductInstall.swf",
                   11727:                          "$topdir/scripts/",
                   11728:                          "$topdir/scripts/config_xml.js",
                   11729:                          "$topdir/scripts/techsmith-smart-player.min.js",
                   11730:                          "$topdir/skins/",
                   11731:                          "$topdir/skins/configuration_express.xml",
                   11732:                          "$topdir/skins/express_show/",
                   11733:                          "$topdir/skins/express_show/spritesheet.min.css",
                   11734:                          "$topdir/skins/express_show/spritesheet.png",
                   11735:                          "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59  raeburn  11736:         my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067    raeburn  11737:         if (@diffs == 0) {
1.1075.2.59  raeburn  11738:             $is_camtasia = 6;
                   11739:         } else {
1.1075.2.81  raeburn  11740:             @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59  raeburn  11741:             if (@diffs == 0) {
                   11742:                 $is_camtasia = 8;
1.1075.2.81  raeburn  11743:             } else {
                   11744:                 @diffs = &compare_arrays(\@paths,\@camtasia8_4);
                   11745:                 if (@diffs == 0) {
                   11746:                     $is_camtasia = 8;
                   11747:                 }
1.1075.2.59  raeburn  11748:             }
1.1067    raeburn  11749:         }
                   11750:     }
                   11751:     my $output;
                   11752:     if ($is_camtasia) {
                   11753:         $output = <<"ENDCAM";
                   11754: <script type="text/javascript" language="Javascript">
                   11755: // <![CDATA[
                   11756: 
                   11757: function camtasiaToggle() {
                   11758:     for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
                   11759:         if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59  raeburn  11760:             if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067    raeburn  11761:                 document.getElementById('camtasia_titles').style.display='block';
                   11762:             } else {
                   11763:                 document.getElementById('camtasia_titles').style.display='none';
                   11764:             }
                   11765:         }
                   11766:     }
                   11767:     return;
                   11768: }
                   11769: 
                   11770: // ]]>
                   11771: </script>
                   11772: <p>$lt{'camt'}</p>
                   11773: ENDCAM
1.1065    raeburn  11774:     } else {
1.1067    raeburn  11775:         $output = '<p>'.$lt{'this'};
                   11776:         if ($info eq '') {
                   11777:             $output .= ' '.$lt{'youm'}.'</p>'."\n";
                   11778:         } else {
                   11779:             $output .= ' '.$lt{'itsc'}.'</p>'."\n".
                   11780:                        '<div><pre>'.$info.'</pre></div>';
                   11781:         }
1.1065    raeburn  11782:     }
1.1067    raeburn  11783:     $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065    raeburn  11784:     my $duplicates;
                   11785:     my $num = 0;
                   11786:     if (ref($dirlist) eq 'ARRAY') {
                   11787:         foreach my $item (@{$dirlist}) {
                   11788:             if (ref($item) eq 'ARRAY') {
                   11789:                 if (exists($toplevel{$item->[0]})) {
                   11790:                     $duplicates .= 
                   11791:                         &start_data_table_row().
                   11792:                         '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
                   11793:                         'value="0" checked="checked" />'.&mt('No').'</label>'.
                   11794:                         '&nbsp;<label><input type="radio" name="archive_overwrite_'.$num.'" '.
                   11795:                         'value="1" />'.&mt('Yes').'</label>'.
                   11796:                         '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
                   11797:                         '<td>'.$item->[0].'</td>';
                   11798:                     if ($item->[2]) {
                   11799:                         $duplicates .= '<td>'.&mt('Directory').'</td>';
                   11800:                     } else {
                   11801:                         $duplicates .= '<td>'.&mt('File').'</td>';
                   11802:                     }
                   11803:                     $duplicates .= '<td>'.$item->[3].'</td>'.
                   11804:                                    '<td>'.
                   11805:                                    &Apache::lonlocal::locallocaltime($item->[4]).
                   11806:                                    '</td>'.
                   11807:                                    &end_data_table_row();
                   11808:                     $num ++;
                   11809:                 }
                   11810:             }
                   11811:         }
                   11812:     }
                   11813:     my $itemcount;
                   11814:     if (@paths > 0) {
                   11815:         $itemcount = scalar(@paths);
                   11816:     } else {
                   11817:         $itemcount = 1;
                   11818:     }
1.1067    raeburn  11819:     if ($is_camtasia) {
                   11820:         $output .= $lt{'auto'}.'<br />'.
                   11821:                    '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59  raeburn  11822:                    '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067    raeburn  11823:                    $lt{'yes'}.'</label>&nbsp;<label>'.
                   11824:                    '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
                   11825:                    $lt{'no'}.'</label></span><br />'.
                   11826:                    '<div id="camtasia_titles" style="display:block">'.
                   11827:                    &Apache::lonhtmlcommon::start_pick_box().
                   11828:                    &Apache::lonhtmlcommon::row_title($lt{'fold'}).
                   11829:                    '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
                   11830:                    &Apache::lonhtmlcommon::row_closure().
                   11831:                    &Apache::lonhtmlcommon::row_title($lt{'movi'}).
                   11832:                    '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
                   11833:                    &Apache::lonhtmlcommon::row_closure(1).
                   11834:                    &Apache::lonhtmlcommon::end_pick_box().
                   11835:                    '</div>';
                   11836:     }
1.1065    raeburn  11837:     $output .= 
                   11838:         '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067    raeburn  11839:         '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
                   11840:         "\n";
1.1065    raeburn  11841:     if ($duplicates ne '') {
                   11842:         $output .= '<p><span class="LC_warning">'.
                   11843:                    &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.  
                   11844:                    &start_data_table().
                   11845:                    &start_data_table_header_row().
                   11846:                    '<th>'.&mt('Overwrite?').'</th>'.
                   11847:                    '<th>'.&mt('Name').'</th>'.
                   11848:                    '<th>'.&mt('Type').'</th>'.
                   11849:                    '<th>'.&mt('Size').'</th>'.
                   11850:                    '<th>'.&mt('Last modified').'</th>'.
                   11851:                    &end_data_table_header_row().
                   11852:                    $duplicates.
                   11853:                    &end_data_table().
                   11854:                    '</p>';
                   11855:     }
1.1067    raeburn  11856:     $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053    raeburn  11857:     if (ref($hiddenelements) eq 'HASH') {
                   11858:         foreach my $hidden (sort(keys(%{$hiddenelements}))) {
                   11859:             $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
                   11860:         }
                   11861:     }
                   11862:     $output .= <<"END";
1.1067    raeburn  11863: <br />
1.1053    raeburn  11864: <input type="submit" name="decompress" value="$lt{'extr'}" />
                   11865: </form>
                   11866: $noextract
                   11867: END
                   11868:     return $output;
                   11869: }
                   11870: 
1.1065    raeburn  11871: sub decompression_utility {
                   11872:     my ($program) = @_;
                   11873:     my @utilities = ('tar','gunzip','bunzip2','unzip'); 
                   11874:     my $location;
                   11875:     if (grep(/^\Q$program\E$/,@utilities)) { 
                   11876:         foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
                   11877:                          '/usr/sbin/') {
                   11878:             if (-x $dir.$program) {
                   11879:                 $location = $dir.$program;
                   11880:                 last;
                   11881:             }
                   11882:         }
                   11883:     }
                   11884:     return $location;
                   11885: }
                   11886: 
                   11887: sub list_archive_contents {
                   11888:     my ($file,$pathsref) = @_;
                   11889:     my (@cmd,$output);
                   11890:     my $needsregexp;
                   11891:     if ($file =~ /\.zip$/) {
                   11892:         @cmd = (&decompression_utility('unzip'),"-l");
                   11893:         $needsregexp = 1;
                   11894:     } elsif (($file =~ m/\.tar\.gz$/) ||
                   11895:              ($file =~ /\.tgz$/)) {
                   11896:         @cmd = (&decompression_utility('tar'),"-ztf");
                   11897:     } elsif ($file =~ /\.tar\.bz2$/) {
                   11898:         @cmd = (&decompression_utility('tar'),"-jtf");
                   11899:     } elsif ($file =~ m|\.tar$|) {
                   11900:         @cmd = (&decompression_utility('tar'),"-tf");
                   11901:     }
                   11902:     if (@cmd) {
                   11903:         undef($!);
                   11904:         undef($@);
                   11905:         if (open(my $fh,"-|", @cmd, $file)) {
                   11906:             while (my $line = <$fh>) {
                   11907:                 $output .= $line;
                   11908:                 chomp($line);
                   11909:                 my $item;
                   11910:                 if ($needsregexp) {
                   11911:                     ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/); 
                   11912:                 } else {
                   11913:                     $item = $line;
                   11914:                 }
                   11915:                 if ($item ne '') {
                   11916:                     unless (grep(/^\Q$item\E$/,@{$pathsref})) {
                   11917:                         push(@{$pathsref},$item);
                   11918:                     } 
                   11919:                 }
                   11920:             }
                   11921:             close($fh);
                   11922:         }
                   11923:     }
                   11924:     return $output;
                   11925: }
                   11926: 
1.1053    raeburn  11927: sub decompress_uploaded_file {
                   11928:     my ($file,$dir) = @_;
                   11929:     &Apache::lonnet::appenv({'cgi.file' => $file});
                   11930:     &Apache::lonnet::appenv({'cgi.dir' => $dir});
                   11931:     my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
                   11932:     my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
                   11933:     my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
                   11934:     &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
                   11935:     my $decompressed = $env{'cgi.decompressed'};
                   11936:     &Apache::lonnet::delenv('cgi.file');
                   11937:     &Apache::lonnet::delenv('cgi.dir');
                   11938:     &Apache::lonnet::delenv('cgi.decompressed');
                   11939:     return ($decompressed,$result);
                   11940: }
                   11941: 
1.1055    raeburn  11942: sub process_decompression {
                   11943:     my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
                   11944:     my ($dir,$error,$warning,$output);
1.1075.2.69  raeburn  11945:     if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34  raeburn  11946:         $error = &mt('Filename not a supported archive file type.').
                   11947:                  '<br />'.&mt('Filename should end with one of: [_1].',
1.1055    raeburn  11948:                               '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
                   11949:     } else {
                   11950:         my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
                   11951:         if ($docuhome eq 'no_host') {
                   11952:             $error = &mt('Could not determine home server for course.');
                   11953:         } else {
                   11954:             my @ids=&Apache::lonnet::current_machine_ids();
                   11955:             my $currdir = "$dir_root/$destination";
                   11956:             if (grep(/^\Q$docuhome\E$/,@ids)) {
                   11957:                 $dir = &LONCAPA::propath($docudom,$docuname).
                   11958:                        "$dir_root/$destination";
                   11959:             } else {
                   11960:                 $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
                   11961:                        "$dir_root/$docudom/$docuname/$destination";
                   11962:                 unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
                   11963:                     $error = &mt('Archive file not found.');
                   11964:                 }
                   11965:             }
1.1065    raeburn  11966:             my (@to_overwrite,@to_skip);
                   11967:             if ($env{'form.archive_overwrite_total'} > 0) {
                   11968:                 my $total = $env{'form.archive_overwrite_total'};
                   11969:                 for (my $i=0; $i<$total; $i++) {
                   11970:                     if ($env{'form.archive_overwrite_'.$i} == 1) {
                   11971:                         push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
                   11972:                     } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
                   11973:                         push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
                   11974:                     }
                   11975:                 }
                   11976:             }
                   11977:             my $numskip = scalar(@to_skip);
                   11978:             if (($numskip > 0) && 
                   11979:                 ($numskip == $env{'form.archive_itemcount'})) {
                   11980:                 $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');         
                   11981:             } elsif ($dir eq '') {
1.1055    raeburn  11982:                 $error = &mt('Directory containing archive file unavailable.');
                   11983:             } elsif (!$error) {
1.1065    raeburn  11984:                 my ($decompressed,$display);
                   11985:                 if ($numskip > 0) {
                   11986:                     my $tempdir = time.'_'.$$.int(rand(10000));
                   11987:                     mkdir("$dir/$tempdir",0755);
                   11988:                     system("mv $dir/$file $dir/$tempdir/$file");
                   11989:                     ($decompressed,$display) = 
                   11990:                         &decompress_uploaded_file($file,"$dir/$tempdir");
                   11991:                     foreach my $item (@to_skip) {
                   11992:                         if (($item ne '') && ($item !~ /\.\./)) {
                   11993:                             if (-f "$dir/$tempdir/$item") { 
                   11994:                                 unlink("$dir/$tempdir/$item");
                   11995:                             } elsif (-d "$dir/$tempdir/$item") {
                   11996:                                 system("rm -rf $dir/$tempdir/$item");
                   11997:                             }
                   11998:                         }
                   11999:                     }
                   12000:                     system("mv $dir/$tempdir/* $dir");
                   12001:                     rmdir("$dir/$tempdir");   
                   12002:                 } else {
                   12003:                     ($decompressed,$display) = 
                   12004:                         &decompress_uploaded_file($file,$dir);
                   12005:                 }
1.1055    raeburn  12006:                 if ($decompressed eq 'ok') {
1.1065    raeburn  12007:                     $output = '<p class="LC_info">'.
                   12008:                               &mt('Files extracted successfully from archive.').
                   12009:                               '</p>'."\n";
1.1055    raeburn  12010:                     my ($warning,$result,@contents);
                   12011:                     my ($newdirlistref,$newlisterror) =
                   12012:                         &Apache::lonnet::dirlist($currdir,$docudom,
                   12013:                                                  $docuname,1);
                   12014:                     my (%is_dir,%changes,@newitems);
                   12015:                     my $dirptr = 16384;
1.1065    raeburn  12016:                     if (ref($newdirlistref) eq 'ARRAY') {
1.1055    raeburn  12017:                         foreach my $dir_line (@{$newdirlistref}) {
                   12018:                             my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065    raeburn  12019:                             unless (($item =~ /^\.+$/) || ($item eq $file) || 
                   12020:                                     ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055    raeburn  12021:                                 push(@newitems,$item);
                   12022:                                 if ($dirptr&$testdir) {
                   12023:                                     $is_dir{$item} = 1;
                   12024:                                 }
                   12025:                                 $changes{$item} = 1;
                   12026:                             }
                   12027:                         }
                   12028:                     }
                   12029:                     if (keys(%changes) > 0) {
                   12030:                         foreach my $item (sort(@newitems)) {
                   12031:                             if ($changes{$item}) {
                   12032:                                 push(@contents,$item);
                   12033:                             }
                   12034:                         }
                   12035:                     }
                   12036:                     if (@contents > 0) {
1.1067    raeburn  12037:                         my $wantform;
                   12038:                         unless ($env{'form.autoextract_camtasia'}) {
                   12039:                             $wantform = 1;
                   12040:                         }
1.1056    raeburn  12041:                         my (%children,%parent,%dirorder,%titles);
1.1055    raeburn  12042:                         my ($count,$datatable) = &get_extracted($docudom,$docuname,
                   12043:                                                                 $currdir,\%is_dir,
                   12044:                                                                 \%children,\%parent,
1.1056    raeburn  12045:                                                                 \@contents,\%dirorder,
                   12046:                                                                 \%titles,$wantform);
1.1055    raeburn  12047:                         if ($datatable ne '') {
                   12048:                             $output .= &archive_options_form('decompressed',$datatable,
                   12049:                                                              $count,$hiddenelem);
1.1065    raeburn  12050:                             my $startcount = 6;
1.1055    raeburn  12051:                             $output .= &archive_javascript($startcount,$count,
1.1056    raeburn  12052:                                                            \%titles,\%children);
1.1055    raeburn  12053:                         }
1.1067    raeburn  12054:                         if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59  raeburn  12055:                             my $version = $env{'form.autoextract_camtasia'};
1.1067    raeburn  12056:                             my %displayed;
                   12057:                             my $total = 1;
                   12058:                             $env{'form.archive_directory'} = [];
                   12059:                             foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
                   12060:                                 my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
                   12061:                                 $path =~ s{/$}{};
                   12062:                                 my $item;
                   12063:                                 if ($path ne '') {
                   12064:                                     $item = "$path/$titles{$i}";
                   12065:                                 } else {
                   12066:                                     $item = $titles{$i};
                   12067:                                 }
                   12068:                                 $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
                   12069:                                 if ($item eq $contents[0]) {
                   12070:                                     push(@{$env{'form.archive_directory'}},$i);
                   12071:                                     $env{'form.archive_'.$i} = 'display';
                   12072:                                     $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
                   12073:                                     $displayed{'folder'} = $i;
1.1075.2.59  raeburn  12074:                                 } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
                   12075:                                          (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067    raeburn  12076:                                     $env{'form.archive_'.$i} = 'display';
                   12077:                                     $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
                   12078:                                     $displayed{'web'} = $i;
                   12079:                                 } else {
1.1075.2.59  raeburn  12080:                                     if ((($item eq "$contents[0]/media") && ($version == 6)) ||
                   12081:                                         ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
                   12082:                                              ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067    raeburn  12083:                                         push(@{$env{'form.archive_directory'}},$i);
                   12084:                                     }
                   12085:                                     $env{'form.archive_'.$i} = 'dependency';
                   12086:                                 }
                   12087:                                 $total ++;
                   12088:                             }
                   12089:                             for (my $i=1; $i<$total; $i++) {
                   12090:                                 next if ($i == $displayed{'web'});
                   12091:                                 next if ($i == $displayed{'folder'});
                   12092:                                 $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
                   12093:                             }
                   12094:                             $env{'form.phase'} = 'decompress_cleanup';
                   12095:                             $env{'form.archivedelete'} = 1;
                   12096:                             $env{'form.archive_count'} = $total-1;
                   12097:                             $output .=
                   12098:                                 &process_extracted_files('coursedocs',$docudom,
                   12099:                                                          $docuname,$destination,
                   12100:                                                          $dir_root,$hiddenelem);
                   12101:                         }
1.1055    raeburn  12102:                     } else {
                   12103:                         $warning = &mt('No new items extracted from archive file.');
                   12104:                     }
                   12105:                 } else {
                   12106:                     $output = $display;
                   12107:                     $error = &mt('An error occurred during extraction from the archive file.');
                   12108:                 }
                   12109:             }
                   12110:         }
                   12111:     }
                   12112:     if ($error) {
                   12113:         $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
                   12114:                    $error.'</p>'."\n";
                   12115:     }
                   12116:     if ($warning) {
                   12117:         $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
                   12118:     }
                   12119:     return $output;
                   12120: }
                   12121: 
                   12122: sub get_extracted {
1.1056    raeburn  12123:     my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
                   12124:         $titles,$wantform) = @_;
1.1055    raeburn  12125:     my $count = 0;
                   12126:     my $depth = 0;
                   12127:     my $datatable;
1.1056    raeburn  12128:     my @hierarchy;
1.1055    raeburn  12129:     return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056    raeburn  12130:                    (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
                   12131:                    (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055    raeburn  12132:     foreach my $item (@{$contents}) {
                   12133:         $count ++;
1.1056    raeburn  12134:         @{$dirorder->{$count}} = @hierarchy;
                   12135:         $titles->{$count} = $item;
1.1055    raeburn  12136:         &archive_hierarchy($depth,$count,$parent,$children);
                   12137:         if ($wantform) {
                   12138:             $datatable .= &archive_row($is_dir->{$item},$item,
                   12139:                                        $currdir,$depth,$count);
                   12140:         }
                   12141:         if ($is_dir->{$item}) {
                   12142:             $depth ++;
1.1056    raeburn  12143:             push(@hierarchy,$count);
                   12144:             $parent->{$depth} = $count;
1.1055    raeburn  12145:             $datatable .=
                   12146:                 &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056    raeburn  12147:                                            \$depth,\$count,\@hierarchy,$dirorder,
                   12148:                                            $children,$parent,$titles,$wantform);
1.1055    raeburn  12149:             $depth --;
1.1056    raeburn  12150:             pop(@hierarchy);
1.1055    raeburn  12151:         }
                   12152:     }
                   12153:     return ($count,$datatable);
                   12154: }
                   12155: 
                   12156: sub recurse_extracted_archive {
1.1056    raeburn  12157:     my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
                   12158:         $children,$parent,$titles,$wantform) = @_;
1.1055    raeburn  12159:     my $result='';
1.1056    raeburn  12160:     unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
                   12161:             (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
                   12162:             (ref($dirorder) eq 'HASH')) {
1.1055    raeburn  12163:         return $result;
                   12164:     }
                   12165:     my $dirptr = 16384;
                   12166:     my ($newdirlistref,$newlisterror) =
                   12167:         &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
                   12168:     if (ref($newdirlistref) eq 'ARRAY') {
                   12169:         foreach my $dir_line (@{$newdirlistref}) {
                   12170:             my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
                   12171:             unless ($item =~ /^\.+$/) {
                   12172:                 $$count ++;
1.1056    raeburn  12173:                 @{$dirorder->{$$count}} = @{$hierarchy};
                   12174:                 $titles->{$$count} = $item;
1.1055    raeburn  12175:                 &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056    raeburn  12176: 
1.1055    raeburn  12177:                 my $is_dir;
                   12178:                 if ($dirptr&$testdir) {
                   12179:                     $is_dir = 1;
                   12180:                 }
                   12181:                 if ($wantform) {
                   12182:                     $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
                   12183:                 }
                   12184:                 if ($is_dir) {
                   12185:                     $$depth ++;
1.1056    raeburn  12186:                     push(@{$hierarchy},$$count);
                   12187:                     $parent->{$$depth} = $$count;
1.1055    raeburn  12188:                     $result .=
                   12189:                         &recurse_extracted_archive("$currdir/$item",$docudom,
                   12190:                                                    $docuname,$depth,$count,
1.1056    raeburn  12191:                                                    $hierarchy,$dirorder,$children,
                   12192:                                                    $parent,$titles,$wantform);
1.1055    raeburn  12193:                     $$depth --;
1.1056    raeburn  12194:                     pop(@{$hierarchy});
1.1055    raeburn  12195:                 }
                   12196:             }
                   12197:         }
                   12198:     }
                   12199:     return $result;
                   12200: }
                   12201: 
                   12202: sub archive_hierarchy {
                   12203:     my ($depth,$count,$parent,$children) =@_;
                   12204:     if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
                   12205:         if (exists($parent->{$depth})) {
                   12206:              $children->{$parent->{$depth}} .= $count.':';
                   12207:         }
                   12208:     }
                   12209:     return;
                   12210: }
                   12211: 
                   12212: sub archive_row {
                   12213:     my ($is_dir,$item,$currdir,$depth,$count) = @_;
                   12214:     my ($name) = ($item =~ m{([^/]+)$});
                   12215:     my %choices = &Apache::lonlocal::texthash (
1.1059    raeburn  12216:                                        'display'    => 'Add as file',
1.1055    raeburn  12217:                                        'dependency' => 'Include as dependency',
                   12218:                                        'discard'    => 'Discard',
                   12219:                                       );
                   12220:     if ($is_dir) {
1.1059    raeburn  12221:         $choices{'display'} = &mt('Add as folder'); 
1.1055    raeburn  12222:     }
1.1056    raeburn  12223:     my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
                   12224:     my $offset = 0;
1.1055    raeburn  12225:     foreach my $action ('display','dependency','discard') {
1.1056    raeburn  12226:         $offset ++;
1.1065    raeburn  12227:         if ($action ne 'display') {
                   12228:             $offset ++;
                   12229:         }  
1.1055    raeburn  12230:         $output .= '<td><span class="LC_nobreak">'.
                   12231:                    '<label><input type="radio" name="archive_'.$count.
                   12232:                    '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
                   12233:         my $text = $choices{$action};
                   12234:         if ($is_dir) {
                   12235:             $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
                   12236:             if ($action eq 'display') {
1.1059    raeburn  12237:                 $text = &mt('Add as folder');
1.1055    raeburn  12238:             }
1.1056    raeburn  12239:         } else {
                   12240:             $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
                   12241: 
                   12242:         }
                   12243:         $output .= ' />&nbsp;'.$choices{$action}.'</label></span>';
                   12244:         if ($action eq 'dependency') {
                   12245:             $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
                   12246:                        &mt('Used by:').'&nbsp;<select name="archive_dependent_on_'.$count.'" '.
                   12247:                        'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
                   12248:                        '<option value=""></option>'."\n".
                   12249:                        '</select>'."\n".
                   12250:                        '</div>';
1.1059    raeburn  12251:         } elsif ($action eq 'display') {
                   12252:             $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
                   12253:                        &mt('Title:').'&nbsp;<input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
                   12254:                        '</div>';
1.1055    raeburn  12255:         }
1.1056    raeburn  12256:         $output .= '</td>';
1.1055    raeburn  12257:     }
                   12258:     $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
                   12259:                &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.('&nbsp;' x 2);
                   12260:     for (my $i=0; $i<$depth; $i++) {
                   12261:         $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
                   12262:     }
                   12263:     if ($is_dir) {
                   12264:         $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" />&nbsp;'."\n".
                   12265:                    '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
                   12266:     } else {
                   12267:         $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
                   12268:     }
                   12269:     $output .= '&nbsp;'.$name.'</td>'."\n".
                   12270:                &end_data_table_row();
                   12271:     return $output;
                   12272: }
                   12273: 
                   12274: sub archive_options_form {
1.1065    raeburn  12275:     my ($form,$display,$count,$hiddenelem) = @_;
                   12276:     my %lt = &Apache::lonlocal::texthash(
                   12277:                perm => 'Permanently remove archive file?',
                   12278:                hows => 'How should each extracted item be incorporated in the course?',
                   12279:                cont => 'Content actions for all',
                   12280:                addf => 'Add as folder/file',
                   12281:                incd => 'Include as dependency for a displayed file',
                   12282:                disc => 'Discard',
                   12283:                no   => 'No',
                   12284:                yes  => 'Yes',
                   12285:                save => 'Save',
                   12286:     );
                   12287:     my $output = <<"END";
                   12288: <form name="$form" method="post" action="">
                   12289: <p><span class="LC_nobreak">$lt{'perm'}&nbsp;
                   12290: <label>
                   12291:   <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
                   12292: </label>
                   12293: &nbsp;
                   12294: <label>
                   12295:   <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
                   12296: </span>
                   12297: </p>
                   12298: <input type="hidden" name="phase" value="decompress_cleanup" />
                   12299: <br />$lt{'hows'}
                   12300: <div class="LC_columnSection">
                   12301:   <fieldset>
                   12302:     <legend>$lt{'cont'}</legend>
                   12303:     <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" /> 
                   12304:     &nbsp;&nbsp;<input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
                   12305:     &nbsp;&nbsp;<input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
                   12306:   </fieldset>
                   12307: </div>
                   12308: END
                   12309:     return $output.
1.1055    raeburn  12310:            &start_data_table()."\n".
1.1065    raeburn  12311:            $display."\n".
1.1055    raeburn  12312:            &end_data_table()."\n".
                   12313:            '<input type="hidden" name="archive_count" value="'.$count.'" />'.
                   12314:            $hiddenelem.
1.1065    raeburn  12315:            '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055    raeburn  12316:            '</form>';
                   12317: }
                   12318: 
                   12319: sub archive_javascript {
1.1056    raeburn  12320:     my ($startcount,$numitems,$titles,$children) = @_;
                   12321:     return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059    raeburn  12322:     my $maintitle = $env{'form.comment'};
1.1055    raeburn  12323:     my $scripttag = <<START;
                   12324: <script type="text/javascript">
                   12325: // <![CDATA[
                   12326: 
                   12327: function checkAll(form,prefix) {
                   12328:     var idstr =  new RegExp("^archive_"+prefix+"_\\\\d+\$");
                   12329:     for (var i=0; i < form.elements.length; i++) {
                   12330:         var id = form.elements[i].id;
                   12331:         if ((id != '') && (id != undefined)) {
                   12332:             if (idstr.test(id)) {
                   12333:                 if (form.elements[i].type == 'radio') {
                   12334:                     form.elements[i].checked = true;
1.1056    raeburn  12335:                     var nostart = i-$startcount;
1.1059    raeburn  12336:                     var offset = nostart%7;
                   12337:                     var count = (nostart-offset)/7;    
1.1056    raeburn  12338:                     dependencyCheck(form,count,offset);
1.1055    raeburn  12339:                 }
                   12340:             }
                   12341:         }
                   12342:     }
                   12343: }
                   12344: 
                   12345: function propagateCheck(form,count) {
                   12346:     if (count > 0) {
1.1059    raeburn  12347:         var startelement = $startcount + ((count-1) * 7);
                   12348:         for (var j=1; j<6; j++) {
                   12349:             if ((j != 2) && (j != 4)) {
1.1056    raeburn  12350:                 var item = startelement + j; 
                   12351:                 if (form.elements[item].type == 'radio') {
                   12352:                     if (form.elements[item].checked) {
                   12353:                         containerCheck(form,count,j);
                   12354:                         break;
                   12355:                     }
1.1055    raeburn  12356:                 }
                   12357:             }
                   12358:         }
                   12359:     }
                   12360: }
                   12361: 
                   12362: numitems = $numitems
1.1056    raeburn  12363: var titles = new Array(numitems);
                   12364: var parents = new Array(numitems);
1.1055    raeburn  12365: for (var i=0; i<numitems; i++) {
1.1056    raeburn  12366:     parents[i] = new Array;
1.1055    raeburn  12367: }
1.1059    raeburn  12368: var maintitle = '$maintitle';
1.1055    raeburn  12369: 
                   12370: START
                   12371: 
1.1056    raeburn  12372:     foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
                   12373:         my @contents = split(/:/,$children->{$container});
1.1055    raeburn  12374:         for (my $i=0; $i<@contents; $i ++) {
                   12375:             $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
                   12376:         }
                   12377:     }
                   12378: 
1.1056    raeburn  12379:     foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
                   12380:         $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
                   12381:     }
                   12382: 
1.1055    raeburn  12383:     $scripttag .= <<END;
                   12384: 
                   12385: function containerCheck(form,count,offset) {
                   12386:     if (count > 0) {
1.1056    raeburn  12387:         dependencyCheck(form,count,offset);
1.1059    raeburn  12388:         var item = (offset+$startcount)+7*(count-1);
1.1055    raeburn  12389:         form.elements[item].checked = true;
                   12390:         if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
                   12391:             if (parents[count].length > 0) {
                   12392:                 for (var j=0; j<parents[count].length; j++) {
1.1056    raeburn  12393:                     containerCheck(form,parents[count][j],offset);
                   12394:                 }
                   12395:             }
                   12396:         }
                   12397:     }
                   12398: }
                   12399: 
                   12400: function dependencyCheck(form,count,offset) {
                   12401:     if (count > 0) {
1.1059    raeburn  12402:         var chosen = (offset+$startcount)+7*(count-1);
                   12403:         var depitem = $startcount + ((count-1) * 7) + 4;
1.1056    raeburn  12404:         var currtype = form.elements[depitem].type;
                   12405:         if (form.elements[chosen].value == 'dependency') {
                   12406:             document.getElementById('arc_depon_'+count).style.display='block'; 
                   12407:             form.elements[depitem].options.length = 0;
                   12408:             form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11  raeburn  12409:             for (var i=1; i<=numitems; i++) {
                   12410:                 if (i == count) {
                   12411:                     continue;
                   12412:                 }
1.1059    raeburn  12413:                 var startelement = $startcount + (i-1) * 7;
                   12414:                 for (var j=1; j<6; j++) {
                   12415:                     if ((j != 2) && (j!= 4)) {
1.1056    raeburn  12416:                         var item = startelement + j;
                   12417:                         if (form.elements[item].type == 'radio') {
                   12418:                             if (form.elements[item].checked) {
                   12419:                                 if (form.elements[item].value == 'display') {
                   12420:                                     var n = form.elements[depitem].options.length;
                   12421:                                     form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
                   12422:                                 }
                   12423:                             }
                   12424:                         }
                   12425:                     }
                   12426:                 }
                   12427:             }
                   12428:         } else {
                   12429:             document.getElementById('arc_depon_'+count).style.display='none';
                   12430:             form.elements[depitem].options.length = 0;
                   12431:             form.elements[depitem].options[0] = new Option('Select','',true,true);
                   12432:         }
1.1059    raeburn  12433:         titleCheck(form,count,offset);
1.1056    raeburn  12434:     }
                   12435: }
                   12436: 
                   12437: function propagateSelect(form,count,offset) {
                   12438:     if (count > 0) {
1.1065    raeburn  12439:         var item = (1+offset+$startcount)+7*(count-1);
1.1056    raeburn  12440:         var picked = form.elements[item].options[form.elements[item].selectedIndex].value; 
                   12441:         if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
                   12442:             if (parents[count].length > 0) {
                   12443:                 for (var j=0; j<parents[count].length; j++) {
                   12444:                     containerSelect(form,parents[count][j],offset,picked);
1.1055    raeburn  12445:                 }
                   12446:             }
                   12447:         }
                   12448:     }
                   12449: }
1.1056    raeburn  12450: 
                   12451: function containerSelect(form,count,offset,picked) {
                   12452:     if (count > 0) {
1.1065    raeburn  12453:         var item = (offset+$startcount)+7*(count-1);
1.1056    raeburn  12454:         if (form.elements[item].type == 'radio') {
                   12455:             if (form.elements[item].value == 'dependency') {
                   12456:                 if (form.elements[item+1].type == 'select-one') {
                   12457:                     for (var i=0; i<form.elements[item+1].options.length; i++) {
                   12458:                         if (form.elements[item+1].options[i].value == picked) {
                   12459:                             form.elements[item+1].selectedIndex = i;
                   12460:                             break;
                   12461:                         }
                   12462:                     }
                   12463:                 }
                   12464:                 if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
                   12465:                     if (parents[count].length > 0) {
                   12466:                         for (var j=0; j<parents[count].length; j++) {
                   12467:                             containerSelect(form,parents[count][j],offset,picked);
                   12468:                         }
                   12469:                     }
                   12470:                 }
                   12471:             }
                   12472:         }
                   12473:     }
                   12474: }
                   12475: 
1.1059    raeburn  12476: function titleCheck(form,count,offset) {
                   12477:     if (count > 0) {
                   12478:         var chosen = (offset+$startcount)+7*(count-1);
                   12479:         var depitem = $startcount + ((count-1) * 7) + 2;
                   12480:         var currtype = form.elements[depitem].type;
                   12481:         if (form.elements[chosen].value == 'display') {
                   12482:             document.getElementById('arc_title_'+count).style.display='block';
                   12483:             if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
                   12484:                 document.getElementById('archive_title_'+count).value=maintitle;
                   12485:             }
                   12486:         } else {
                   12487:             document.getElementById('arc_title_'+count).style.display='none';
                   12488:             if (currtype == 'text') { 
                   12489:                 document.getElementById('archive_title_'+count).value='';
                   12490:             }
                   12491:         }
                   12492:     }
                   12493:     return;
                   12494: }
                   12495: 
1.1055    raeburn  12496: // ]]>
                   12497: </script>
                   12498: END
                   12499:     return $scripttag;
                   12500: }
                   12501: 
                   12502: sub process_extracted_files {
1.1067    raeburn  12503:     my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055    raeburn  12504:     my $numitems = $env{'form.archive_count'};
                   12505:     return unless ($numitems);
                   12506:     my @ids=&Apache::lonnet::current_machine_ids();
                   12507:     my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067    raeburn  12508:         %folders,%containers,%mapinner,%prompttofetch);
1.1055    raeburn  12509:     my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
                   12510:     if (grep(/^\Q$docuhome\E$/,@ids)) {
                   12511:         $prefix = &LONCAPA::propath($docudom,$docuname);
                   12512:         $pathtocheck = "$dir_root/$destination";
                   12513:         $dir = $dir_root;
                   12514:         $ishome = 1;
                   12515:     } else {
                   12516:         $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
                   12517:         $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
                   12518:         $dir = "$dir_root/$docudom/$docuname";    
                   12519:     }
                   12520:     my $currdir = "$dir_root/$destination";
                   12521:     (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
                   12522:     if ($env{'form.folderpath'}) {
                   12523:         my @items = split('&',$env{'form.folderpath'});
                   12524:         $folders{'0'} = $items[-2];
1.1075.2.17  raeburn  12525:         if ($env{'form.folderpath'} =~ /\:1$/) {
                   12526:             $containers{'0'}='page';
                   12527:         } else {
                   12528:             $containers{'0'}='sequence';
                   12529:         }
1.1055    raeburn  12530:     }
                   12531:     my @archdirs = &get_env_multiple('form.archive_directory');
                   12532:     if ($numitems) {
                   12533:         for (my $i=1; $i<=$numitems; $i++) {
                   12534:             my $path = $env{'form.archive_content_'.$i};
                   12535:             if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
                   12536:                 my $item = $1;
                   12537:                 $toplevelitems{$item} = $i;
                   12538:                 if (grep(/^\Q$i\E$/,@archdirs)) {
                   12539:                     $is_dir{$item} = 1;
                   12540:                 }
                   12541:             }
                   12542:         }
                   12543:     }
1.1067    raeburn  12544:     my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055    raeburn  12545:     if (keys(%toplevelitems) > 0) {
                   12546:         my @contents = sort(keys(%toplevelitems));
1.1056    raeburn  12547:         (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
                   12548:                                            \%parent,\@contents,\%dirorder,\%titles);
1.1055    raeburn  12549:     }
1.1066    raeburn  12550:     my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055    raeburn  12551:     if ($numitems) {
                   12552:         for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11  raeburn  12553:             next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055    raeburn  12554:             my $path = $env{'form.archive_content_'.$i};
                   12555:             if ($path =~ /^\Q$pathtocheck\E/) {
                   12556:                 if ($env{'form.archive_'.$i} eq 'discard') {
                   12557:                     if ($prefix ne '' && $path ne '') {
                   12558:                         if (-e $prefix.$path) {
1.1066    raeburn  12559:                             if ((@archdirs > 0) && 
                   12560:                                 (grep(/^\Q$i\E$/,@archdirs))) {
                   12561:                                 $todeletedir{$prefix.$path} = 1;
                   12562:                             } else {
                   12563:                                 $todelete{$prefix.$path} = 1;
                   12564:                             }
1.1055    raeburn  12565:                         }
                   12566:                     }
                   12567:                 } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059    raeburn  12568:                     my ($docstitle,$title,$url,$outer);
1.1055    raeburn  12569:                     ($title) = ($path =~ m{/([^/]+)$});
1.1059    raeburn  12570:                     $docstitle = $env{'form.archive_title_'.$i};
                   12571:                     if ($docstitle eq '') {
                   12572:                         $docstitle = $title;
                   12573:                     }
1.1055    raeburn  12574:                     $outer = 0;
1.1056    raeburn  12575:                     if (ref($dirorder{$i}) eq 'ARRAY') {
                   12576:                         if (@{$dirorder{$i}} > 0) {
                   12577:                             foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055    raeburn  12578:                                 if ($env{'form.archive_'.$item} eq 'display') {
                   12579:                                     $outer = $item;
                   12580:                                     last;
                   12581:                                 }
                   12582:                             }
                   12583:                         }
                   12584:                     }
                   12585:                     my ($errtext,$fatal) = 
                   12586:                         &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
                   12587:                                                '/'.$folders{$outer}.'.'.
                   12588:                                                $containers{$outer});
                   12589:                     next if ($fatal);
                   12590:                     if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
                   12591:                         if ($context eq 'coursedocs') {
1.1056    raeburn  12592:                             $mapinner{$i} = time;
1.1055    raeburn  12593:                             $folders{$i} = 'default_'.$mapinner{$i};
                   12594:                             $containers{$i} = 'sequence';
                   12595:                             my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
                   12596:                                       $folders{$i}.'.'.$containers{$i};
                   12597:                             my $newidx = &LONCAPA::map::getresidx();
                   12598:                             $LONCAPA::map::resources[$newidx]=
1.1059    raeburn  12599:                                 $docstitle.':'.$url.':false:normal:res';
1.1055    raeburn  12600:                             push(@LONCAPA::map::order,$newidx);
                   12601:                             my ($outtext,$errtext) =
                   12602:                                 &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
                   12603:                                                         $docuname.'/'.$folders{$outer}.
1.1075.2.11  raeburn  12604:                                                         '.'.$containers{$outer},1,1);
1.1056    raeburn  12605:                             $newseqid{$i} = $newidx;
1.1067    raeburn  12606:                             unless ($errtext) {
                   12607:                                 $result .=  '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
                   12608:                             }
1.1055    raeburn  12609:                         }
                   12610:                     } else {
                   12611:                         if ($context eq 'coursedocs') {
                   12612:                             my $newidx=&LONCAPA::map::getresidx();
                   12613:                             my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
                   12614:                                       $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
                   12615:                                       $title;
                   12616:                             if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
                   12617:                                 mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
                   12618:                             }
                   12619:                             if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
                   12620:                                 mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
                   12621:                             }
                   12622:                             if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
                   12623:                                 system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056    raeburn  12624:                                 $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067    raeburn  12625:                                 unless ($ishome) {
                   12626:                                     my $fetch = "$newdest{$i}/$title";
                   12627:                                     $fetch =~ s/^\Q$prefix$dir\E//;
                   12628:                                     $prompttofetch{$fetch} = 1;
                   12629:                                 }
1.1055    raeburn  12630:                             }
                   12631:                             $LONCAPA::map::resources[$newidx]=
1.1059    raeburn  12632:                                 $docstitle.':'.$url.':false:normal:res';
1.1055    raeburn  12633:                             push(@LONCAPA::map::order, $newidx);
                   12634:                             my ($outtext,$errtext)=
                   12635:                                 &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
                   12636:                                                         $docuname.'/'.$folders{$outer}.
1.1075.2.11  raeburn  12637:                                                         '.'.$containers{$outer},1,1);
1.1067    raeburn  12638:                             unless ($errtext) {
                   12639:                                 if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
                   12640:                                     $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
                   12641:                                 }
                   12642:                             }
1.1055    raeburn  12643:                         }
                   12644:                     }
1.1075.2.11  raeburn  12645:                 }
                   12646:             } else {
                   12647:                 $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
                   12648:             }
                   12649:         }
                   12650:         for (my $i=1; $i<=$numitems; $i++) {
                   12651:             next unless ($env{'form.archive_'.$i} eq 'dependency');
                   12652:             my $path = $env{'form.archive_content_'.$i};
                   12653:             if ($path =~ /^\Q$pathtocheck\E/) {
                   12654:                 my ($title) = ($path =~ m{/([^/]+)$});
                   12655:                 $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
                   12656:                 if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
                   12657:                     if (ref($dirorder{$i}) eq 'ARRAY') {
                   12658:                         my ($itemidx,$fullpath,$relpath);
                   12659:                         if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
                   12660:                             my $container = $dirorder{$referrer{$i}}->[-1];
1.1056    raeburn  12661:                             for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11  raeburn  12662:                                 if ($dirorder{$i}->[$j] eq $container) {
                   12663:                                     $itemidx = $j;
1.1056    raeburn  12664:                                 }
                   12665:                             }
1.1075.2.11  raeburn  12666:                         }
                   12667:                         if ($itemidx eq '') {
                   12668:                             $itemidx =  0;
                   12669:                         }
                   12670:                         if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
                   12671:                             if ($mapinner{$referrer{$i}}) {
                   12672:                                 $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
                   12673:                                 for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
                   12674:                                     if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
                   12675:                                         unless (defined($newseqid{$dirorder{$i}->[$j]})) {
                   12676:                                             $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
                   12677:                                             $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
                   12678:                                             if (!-e $fullpath) {
                   12679:                                                 mkdir($fullpath,0755);
1.1056    raeburn  12680:                                             }
                   12681:                                         }
1.1075.2.11  raeburn  12682:                                     } else {
                   12683:                                         last;
1.1056    raeburn  12684:                                     }
1.1075.2.11  raeburn  12685:                                 }
                   12686:                             }
                   12687:                         } elsif ($newdest{$referrer{$i}}) {
                   12688:                             $fullpath = $newdest{$referrer{$i}};
                   12689:                             for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
                   12690:                                 if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
                   12691:                                     $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
                   12692:                                     last;
                   12693:                                 } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
                   12694:                                     unless (defined($newseqid{$dirorder{$i}->[$j]})) {
                   12695:                                         $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
                   12696:                                         $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
                   12697:                                         if (!-e $fullpath) {
                   12698:                                             mkdir($fullpath,0755);
1.1056    raeburn  12699:                                         }
                   12700:                                     }
1.1075.2.11  raeburn  12701:                                 } else {
                   12702:                                     last;
1.1056    raeburn  12703:                                 }
1.1075.2.11  raeburn  12704:                             }
                   12705:                         }
                   12706:                         if ($fullpath ne '') {
                   12707:                             if (-e "$prefix$path") {
                   12708:                                 system("mv $prefix$path $fullpath/$title");
                   12709:                             }
                   12710:                             if (-e "$fullpath/$title") {
                   12711:                                 my $showpath;
                   12712:                                 if ($relpath ne '') {
                   12713:                                     $showpath = "$relpath/$title";
                   12714:                                 } else {
                   12715:                                     $showpath = "/$title";
1.1056    raeburn  12716:                                 }
1.1075.2.11  raeburn  12717:                                 $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
                   12718:                             }
                   12719:                             unless ($ishome) {
                   12720:                                 my $fetch = "$fullpath/$title";
                   12721:                                 $fetch =~ s/^\Q$prefix$dir\E//;
                   12722:                                 $prompttofetch{$fetch} = 1;
1.1055    raeburn  12723:                             }
                   12724:                         }
                   12725:                     }
1.1075.2.11  raeburn  12726:                 } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
                   12727:                     $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
                   12728:                                     $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055    raeburn  12729:                 }
                   12730:             } else {
1.1075.2.11  raeburn  12731:                 $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
1.1055    raeburn  12732:             }
                   12733:         }
                   12734:         if (keys(%todelete)) {
                   12735:             foreach my $key (keys(%todelete)) {
                   12736:                 unlink($key);
1.1066    raeburn  12737:             }
                   12738:         }
                   12739:         if (keys(%todeletedir)) {
                   12740:             foreach my $key (keys(%todeletedir)) {
                   12741:                 rmdir($key);
                   12742:             }
                   12743:         }
                   12744:         foreach my $dir (sort(keys(%is_dir))) {
                   12745:             if (($pathtocheck ne '') && ($dir ne ''))  {
                   12746:                 &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055    raeburn  12747:             }
                   12748:         }
1.1067    raeburn  12749:         if ($result ne '') {
                   12750:             $output .= '<ul>'."\n".
                   12751:                        $result."\n".
                   12752:                        '</ul>';
                   12753:         }
                   12754:         unless ($ishome) {
                   12755:             my $replicationfail;
                   12756:             foreach my $item (keys(%prompttofetch)) {
                   12757:                 my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
                   12758:                 unless ($fetchresult eq 'ok') {
                   12759:                     $replicationfail .= '<li>'.$item.'</li>'."\n";
                   12760:                 }
                   12761:             }
                   12762:             if ($replicationfail) {
                   12763:                 $output .= '<p class="LC_error">'.
                   12764:                            &mt('Course home server failed to retrieve:').'<ul>'.
                   12765:                            $replicationfail.
                   12766:                            '</ul></p>';
                   12767:             }
                   12768:         }
1.1055    raeburn  12769:     } else {
                   12770:         $warning = &mt('No items found in archive.');
                   12771:     }
                   12772:     if ($error) {
                   12773:         $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
                   12774:                    $error.'</p>'."\n";
                   12775:     }
                   12776:     if ($warning) {
                   12777:         $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
                   12778:     }
                   12779:     return $output;
                   12780: }
                   12781: 
1.1066    raeburn  12782: sub cleanup_empty_dirs {
                   12783:     my ($path) = @_;
                   12784:     if (($path ne '') && (-d $path)) {
                   12785:         if (opendir(my $dirh,$path)) {
                   12786:             my @dircontents = grep(!/^\./,readdir($dirh));
                   12787:             my $numitems = 0;
                   12788:             foreach my $item (@dircontents) {
                   12789:                 if (-d "$path/$item") {
1.1075.2.28  raeburn  12790:                     &cleanup_empty_dirs("$path/$item");
1.1066    raeburn  12791:                     if (-e "$path/$item") {
                   12792:                         $numitems ++;
                   12793:                     }
                   12794:                 } else {
                   12795:                     $numitems ++;
                   12796:                 }
                   12797:             }
                   12798:             if ($numitems == 0) {
                   12799:                 rmdir($path);
                   12800:             }
                   12801:             closedir($dirh);
                   12802:         }
                   12803:     }
                   12804:     return;
                   12805: }
                   12806: 
1.41      ng       12807: =pod
1.45      matthew  12808: 
1.1075.2.56  raeburn  12809: =item * &get_folder_hierarchy()
1.1068    raeburn  12810: 
                   12811: Provides hierarchy of names of folders/sub-folders containing the current
                   12812: item,
                   12813: 
                   12814: Inputs: 3
                   12815:      - $navmap - navmaps object
                   12816: 
                   12817:      - $map - url for map (either the trigger itself, or map containing
                   12818:                            the resource, which is the trigger).
                   12819: 
                   12820:      - $showitem - 1 => show title for map itself; 0 => do not show.
                   12821: 
                   12822: Outputs: 1 @pathitems - array of folder/subfolder names.
                   12823: 
                   12824: =cut
                   12825: 
                   12826: sub get_folder_hierarchy {
                   12827:     my ($navmap,$map,$showitem) = @_;
                   12828:     my @pathitems;
                   12829:     if (ref($navmap)) {
                   12830:         my $mapres = $navmap->getResourceByUrl($map);
                   12831:         if (ref($mapres)) {
                   12832:             my $pcslist = $mapres->map_hierarchy();
                   12833:             if ($pcslist ne '') {
                   12834:                 my @pcs = split(/,/,$pcslist);
                   12835:                 foreach my $pc (@pcs) {
                   12836:                     if ($pc == 1) {
1.1075.2.38  raeburn  12837:                         push(@pathitems,&mt('Main Content'));
1.1068    raeburn  12838:                     } else {
                   12839:                         my $res = $navmap->getByMapPc($pc);
                   12840:                         if (ref($res)) {
                   12841:                             my $title = $res->compTitle();
                   12842:                             $title =~ s/\W+/_/g;
                   12843:                             if ($title ne '') {
                   12844:                                 push(@pathitems,$title);
                   12845:                             }
                   12846:                         }
                   12847:                     }
                   12848:                 }
                   12849:             }
1.1071    raeburn  12850:             if ($showitem) {
                   12851:                 if ($mapres->{ID} eq '0.0') {
1.1075.2.38  raeburn  12852:                     push(@pathitems,&mt('Main Content'));
1.1071    raeburn  12853:                 } else {
                   12854:                     my $maptitle = $mapres->compTitle();
                   12855:                     $maptitle =~ s/\W+/_/g;
                   12856:                     if ($maptitle ne '') {
                   12857:                         push(@pathitems,$maptitle);
                   12858:                     }
1.1068    raeburn  12859:                 }
                   12860:             }
                   12861:         }
                   12862:     }
                   12863:     return @pathitems;
                   12864: }
                   12865: 
                   12866: =pod
                   12867: 
1.1015    raeburn  12868: =item * &get_turnedin_filepath()
                   12869: 
                   12870: Determines path in a user's portfolio file for storage of files uploaded
                   12871: to a specific essayresponse or dropbox item.
                   12872: 
                   12873: Inputs: 3 required + 1 optional.
                   12874: $symb is symb for resource, $uname and $udom are for current user (required).
                   12875: $caller is optional (can be "submission", if routine is called when storing
                   12876: an upoaded file when "Submit Answer" button was pressed).
                   12877: 
                   12878: Returns array containing $path and $multiresp. 
                   12879: $path is path in portfolio.  $multiresp is 1 if this resource contains more
                   12880: than one file upload item.  Callers of routine should append partid as a 
                   12881: subdirectory to $path in cases where $multiresp is 1.
                   12882: 
                   12883: Called by: homework/essayresponse.pm and homework/structuretags.pm
                   12884: 
                   12885: =cut
                   12886: 
                   12887: sub get_turnedin_filepath {
                   12888:     my ($symb,$uname,$udom,$caller) = @_;
                   12889:     my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
                   12890:     my $turnindir;
                   12891:     my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
                   12892:     $turnindir = $userhash{'turnindir'};
                   12893:     my ($path,$multiresp);
                   12894:     if ($turnindir eq '') {
                   12895:         if ($caller eq 'submission') {
                   12896:             $turnindir = &mt('turned in');
                   12897:             $turnindir =~ s/\W+/_/g;
                   12898:             my %newhash = (
                   12899:                             'turnindir' => $turnindir,
                   12900:                           );
                   12901:             &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
                   12902:         }
                   12903:     }
                   12904:     if ($turnindir ne '') {
                   12905:         $path = '/'.$turnindir.'/';
                   12906:         my ($multipart,$turnin,@pathitems);
                   12907:         my $navmap = Apache::lonnavmaps::navmap->new();
                   12908:         if (defined($navmap)) {
                   12909:             my $mapres = $navmap->getResourceByUrl($map);
                   12910:             if (ref($mapres)) {
                   12911:                 my $pcslist = $mapres->map_hierarchy();
                   12912:                 if ($pcslist ne '') {
                   12913:                     foreach my $pc (split(/,/,$pcslist)) {
                   12914:                         my $res = $navmap->getByMapPc($pc);
                   12915:                         if (ref($res)) {
                   12916:                             my $title = $res->compTitle();
                   12917:                             $title =~ s/\W+/_/g;
                   12918:                             if ($title ne '') {
1.1075.2.48  raeburn  12919:                                 if (($pc > 1) && (length($title) > 12)) {
                   12920:                                     $title = substr($title,0,12);
                   12921:                                 }
1.1015    raeburn  12922:                                 push(@pathitems,$title);
                   12923:                             }
                   12924:                         }
                   12925:                     }
                   12926:                 }
                   12927:                 my $maptitle = $mapres->compTitle();
                   12928:                 $maptitle =~ s/\W+/_/g;
                   12929:                 if ($maptitle ne '') {
1.1075.2.48  raeburn  12930:                     if (length($maptitle) > 12) {
                   12931:                         $maptitle = substr($maptitle,0,12);
                   12932:                     }
1.1015    raeburn  12933:                     push(@pathitems,$maptitle);
                   12934:                 }
                   12935:                 unless ($env{'request.state'} eq 'construct') {
                   12936:                     my $res = $navmap->getBySymb($symb);
                   12937:                     if (ref($res)) {
                   12938:                         my $partlist = $res->parts();
                   12939:                         my $totaluploads = 0;
                   12940:                         if (ref($partlist) eq 'ARRAY') {
                   12941:                             foreach my $part (@{$partlist}) {
                   12942:                                 my @types = $res->responseType($part);
                   12943:                                 my @ids = $res->responseIds($part);
                   12944:                                 for (my $i=0; $i < scalar(@ids); $i++) {
                   12945:                                     if ($types[$i] eq 'essay') {
                   12946:                                         my $partid = $part.'_'.$ids[$i];
                   12947:                                         if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
                   12948:                                             $totaluploads ++;
                   12949:                                         }
                   12950:                                     }
                   12951:                                 }
                   12952:                             }
                   12953:                             if ($totaluploads > 1) {
                   12954:                                 $multiresp = 1;
                   12955:                             }
                   12956:                         }
                   12957:                     }
                   12958:                 }
                   12959:             } else {
                   12960:                 return;
                   12961:             }
                   12962:         } else {
                   12963:             return;
                   12964:         }
                   12965:         my $restitle=&Apache::lonnet::gettitle($symb);
                   12966:         $restitle =~ s/\W+/_/g;
                   12967:         if ($restitle eq '') {
                   12968:             $restitle = ($resurl =~ m{/[^/]+$});
                   12969:             if ($restitle eq '') {
                   12970:                 $restitle = time;
                   12971:             }
                   12972:         }
1.1075.2.48  raeburn  12973:         if (length($restitle) > 12) {
                   12974:             $restitle = substr($restitle,0,12);
                   12975:         }
1.1015    raeburn  12976:         push(@pathitems,$restitle);
                   12977:         $path .= join('/',@pathitems);
                   12978:     }
                   12979:     return ($path,$multiresp);
                   12980: }
                   12981: 
                   12982: =pod
                   12983: 
1.464     albertel 12984: =back
1.41      ng       12985: 
1.112     bowersj2 12986: =head1 CSV Upload/Handling functions
1.38      albertel 12987: 
1.41      ng       12988: =over 4
                   12989: 
1.648     raeburn  12990: =item * &upfile_store($r)
1.41      ng       12991: 
                   12992: Store uploaded file, $r should be the HTTP Request object,
1.258     albertel 12993: needs $env{'form.upfile'}
1.41      ng       12994: returns $datatoken to be put into hidden field
                   12995: 
                   12996: =cut
1.31      albertel 12997: 
                   12998: sub upfile_store {
                   12999:     my $r=shift;
1.258     albertel 13000:     $env{'form.upfile'}=~s/\r/\n/gs;
                   13001:     $env{'form.upfile'}=~s/\f/\n/gs;
                   13002:     $env{'form.upfile'}=~s/\n+/\n/gs;
                   13003:     $env{'form.upfile'}=~s/\n+$//gs;
1.31      albertel 13004: 
1.258     albertel 13005:     my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
                   13006: 	'_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31      albertel 13007:     {
1.158     raeburn  13008:         my $datafile = $r->dir_config('lonDaemons').
                   13009:                            '/tmp/'.$datatoken.'.tmp';
                   13010:         if ( open(my $fh,">$datafile") ) {
1.258     albertel 13011:             print $fh $env{'form.upfile'};
1.158     raeburn  13012:             close($fh);
                   13013:         }
1.31      albertel 13014:     }
                   13015:     return $datatoken;
                   13016: }
                   13017: 
1.56      matthew  13018: =pod
                   13019: 
1.648     raeburn  13020: =item * &load_tmp_file($r)
1.41      ng       13021: 
                   13022: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258     albertel 13023: needs $env{'form.datatoken'},
                   13024: sets $env{'form.upfile'} to the contents of the file
1.41      ng       13025: 
                   13026: =cut
1.31      albertel 13027: 
                   13028: sub load_tmp_file {
                   13029:     my $r=shift;
                   13030:     my @studentdata=();
                   13031:     {
1.158     raeburn  13032:         my $studentfile = $r->dir_config('lonDaemons').
1.258     albertel 13033:                               '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158     raeburn  13034:         if ( open(my $fh,"<$studentfile") ) {
                   13035:             @studentdata=<$fh>;
                   13036:             close($fh);
                   13037:         }
1.31      albertel 13038:     }
1.258     albertel 13039:     $env{'form.upfile'}=join('',@studentdata);
1.31      albertel 13040: }
                   13041: 
1.56      matthew  13042: =pod
                   13043: 
1.648     raeburn  13044: =item * &upfile_record_sep()
1.41      ng       13045: 
                   13046: Separate uploaded file into records
                   13047: returns array of records,
1.258     albertel 13048: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41      ng       13049: 
                   13050: =cut
1.31      albertel 13051: 
                   13052: sub upfile_record_sep {
1.258     albertel 13053:     if ($env{'form.upfiletype'} eq 'xml') {
1.31      albertel 13054:     } else {
1.248     albertel 13055: 	my @records;
1.258     albertel 13056: 	foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248     albertel 13057: 	    if ($line=~/^\s*$/) { next; }
                   13058: 	    push(@records,$line);
                   13059: 	}
                   13060: 	return @records;
1.31      albertel 13061:     }
                   13062: }
                   13063: 
1.56      matthew  13064: =pod
                   13065: 
1.648     raeburn  13066: =item * &record_sep($record)
1.41      ng       13067: 
1.258     albertel 13068: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41      ng       13069: 
                   13070: =cut
                   13071: 
1.263     www      13072: sub takeleft {
                   13073:     my $index=shift;
                   13074:     return substr('0000'.$index,-4,4);
                   13075: }
                   13076: 
1.31      albertel 13077: sub record_sep {
                   13078:     my $record=shift;
                   13079:     my %components=();
1.258     albertel 13080:     if ($env{'form.upfiletype'} eq 'xml') {
                   13081:     } elsif ($env{'form.upfiletype'} eq 'space') {
1.31      albertel 13082:         my $i=0;
1.356     albertel 13083:         foreach my $field (split(/\s+/,$record)) {
1.31      albertel 13084:             $field=~s/^(\"|\')//;
                   13085:             $field=~s/(\"|\')$//;
1.263     www      13086:             $components{&takeleft($i)}=$field;
1.31      albertel 13087:             $i++;
                   13088:         }
1.258     albertel 13089:     } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31      albertel 13090:         my $i=0;
1.356     albertel 13091:         foreach my $field (split(/\t/,$record)) {
1.31      albertel 13092:             $field=~s/^(\"|\')//;
                   13093:             $field=~s/(\"|\')$//;
1.263     www      13094:             $components{&takeleft($i)}=$field;
1.31      albertel 13095:             $i++;
                   13096:         }
                   13097:     } else {
1.561     www      13098:         my $separator=',';
1.480     banghart 13099:         if ($env{'form.upfiletype'} eq 'semisv') {
1.561     www      13100:             $separator=';';
1.480     banghart 13101:         }
1.31      albertel 13102:         my $i=0;
1.561     www      13103: # the character we are looking for to indicate the end of a quote or a record 
                   13104:         my $looking_for=$separator;
                   13105: # do not add the characters to the fields
                   13106:         my $ignore=0;
                   13107: # we just encountered a separator (or the beginning of the record)
                   13108:         my $just_found_separator=1;
                   13109: # store the field we are working on here
                   13110:         my $field='';
                   13111: # work our way through all characters in record
                   13112:         foreach my $character ($record=~/(.)/g) {
                   13113:             if ($character eq $looking_for) {
                   13114:                if ($character ne $separator) {
                   13115: # Found the end of a quote, again looking for separator
                   13116:                   $looking_for=$separator;
                   13117:                   $ignore=1;
                   13118:                } else {
                   13119: # Found a separator, store away what we got
                   13120:                   $components{&takeleft($i)}=$field;
                   13121: 	          $i++;
                   13122:                   $just_found_separator=1;
                   13123:                   $ignore=0;
                   13124:                   $field='';
                   13125:                }
                   13126:                next;
                   13127:             }
                   13128: # single or double quotation marks after a separator indicate beginning of a quote
                   13129: # we are now looking for the end of the quote and need to ignore separators
                   13130:             if ((($character eq '"') || ($character eq "'")) && ($just_found_separator))  {
                   13131:                $looking_for=$character;
                   13132:                next;
                   13133:             }
                   13134: # ignore would be true after we reached the end of a quote
                   13135:             if ($ignore) { next; }
                   13136:             if (($just_found_separator) && ($character=~/\s/)) { next; }
                   13137:             $field.=$character;
                   13138:             $just_found_separator=0; 
1.31      albertel 13139:         }
1.561     www      13140: # catch the very last entry, since we never encountered the separator
                   13141:         $components{&takeleft($i)}=$field;
1.31      albertel 13142:     }
                   13143:     return %components;
                   13144: }
                   13145: 
1.144     matthew  13146: ######################################################
                   13147: ######################################################
                   13148: 
1.56      matthew  13149: =pod
                   13150: 
1.648     raeburn  13151: =item * &upfile_select_html()
1.41      ng       13152: 
1.144     matthew  13153: Return HTML code to select a file from the users machine and specify 
                   13154: the file type.
1.41      ng       13155: 
                   13156: =cut
                   13157: 
1.144     matthew  13158: ######################################################
                   13159: ######################################################
1.31      albertel 13160: sub upfile_select_html {
1.144     matthew  13161:     my %Types = (
                   13162:                  csv   => &mt('CSV (comma separated values, spreadsheet)'),
1.480     banghart 13163:                  semisv => &mt('Semicolon separated values'),
1.144     matthew  13164:                  space => &mt('Space separated'),
                   13165:                  tab   => &mt('Tabulator separated'),
                   13166: #                 xml   => &mt('HTML/XML'),
                   13167:                  );
                   13168:     my $Str = '<input type="file" name="upfile" size="50" />'.
1.727     riegler  13169:         '<br />'.&mt('Type').': <select name="upfiletype">';
1.144     matthew  13170:     foreach my $type (sort(keys(%Types))) {
                   13171:         $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
                   13172:     }
                   13173:     $Str .= "</select>\n";
                   13174:     return $Str;
1.31      albertel 13175: }
                   13176: 
1.301     albertel 13177: sub get_samples {
                   13178:     my ($records,$toget) = @_;
                   13179:     my @samples=({});
                   13180:     my $got=0;
                   13181:     foreach my $rec (@$records) {
                   13182: 	my %temp = &record_sep($rec);
                   13183: 	if (! grep(/\S/, values(%temp))) { next; }
                   13184: 	if (%temp) {
                   13185: 	    $samples[$got]=\%temp;
                   13186: 	    $got++;
                   13187: 	    if ($got == $toget) { last; }
                   13188: 	}
                   13189:     }
                   13190:     return \@samples;
                   13191: }
                   13192: 
1.144     matthew  13193: ######################################################
                   13194: ######################################################
                   13195: 
1.56      matthew  13196: =pod
                   13197: 
1.648     raeburn  13198: =item * &csv_print_samples($r,$records)
1.41      ng       13199: 
                   13200: Prints a table of sample values from each column uploaded $r is an
                   13201: Apache Request ref, $records is an arrayref from
                   13202: &Apache::loncommon::upfile_record_sep
                   13203: 
                   13204: =cut
                   13205: 
1.144     matthew  13206: ######################################################
                   13207: ######################################################
1.31      albertel 13208: sub csv_print_samples {
                   13209:     my ($r,$records) = @_;
1.662     bisitz   13210:     my $samples = &get_samples($records,5);
1.301     albertel 13211: 
1.594     raeburn  13212:     $r->print(&mt('Samples').'<br />'.&start_data_table().
                   13213:               &start_data_table_header_row());
1.356     albertel 13214:     foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) { 
1.845     bisitz   13215:         $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594     raeburn  13216:     $r->print(&end_data_table_header_row());
1.301     albertel 13217:     foreach my $hash (@$samples) {
1.594     raeburn  13218: 	$r->print(&start_data_table_row());
1.356     albertel 13219: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31      albertel 13220: 	    $r->print('<td>');
1.356     albertel 13221: 	    if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31      albertel 13222: 	    $r->print('</td>');
                   13223: 	}
1.594     raeburn  13224: 	$r->print(&end_data_table_row());
1.31      albertel 13225:     }
1.594     raeburn  13226:     $r->print(&end_data_table().'<br />'."\n");
1.31      albertel 13227: }
                   13228: 
1.144     matthew  13229: ######################################################
                   13230: ######################################################
                   13231: 
1.56      matthew  13232: =pod
                   13233: 
1.648     raeburn  13234: =item * &csv_print_select_table($r,$records,$d)
1.41      ng       13235: 
                   13236: Prints a table to create associations between values and table columns.
1.144     matthew  13237: 
1.41      ng       13238: $r is an Apache Request ref,
                   13239: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174     matthew  13240: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41      ng       13241: 
                   13242: =cut
                   13243: 
1.144     matthew  13244: ######################################################
                   13245: ######################################################
1.31      albertel 13246: sub csv_print_select_table {
                   13247:     my ($r,$records,$d) = @_;
1.301     albertel 13248:     my $i=0;
                   13249:     my $samples = &get_samples($records,1);
1.144     matthew  13250:     $r->print(&mt('Associate columns with student attributes.')."\n".
1.594     raeburn  13251: 	      &start_data_table().&start_data_table_header_row().
1.144     matthew  13252:               '<th>'.&mt('Attribute').'</th>'.
1.594     raeburn  13253:               '<th>'.&mt('Column').'</th>'.
                   13254:               &end_data_table_header_row()."\n");
1.356     albertel 13255:     foreach my $array_ref (@$d) {
                   13256: 	my ($value,$display,$defaultcol)=@{ $array_ref };
1.729     raeburn  13257: 	$r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31      albertel 13258: 
1.875     bisitz   13259: 	$r->print('<td><select name="f'.$i.'"'.
1.32      matthew  13260: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.31      albertel 13261: 	$r->print('<option value="none"></option>');
1.356     albertel 13262: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
                   13263: 	    $r->print('<option value="'.$sample.'"'.
                   13264:                       ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662     bisitz   13265:                       '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31      albertel 13266: 	}
1.594     raeburn  13267: 	$r->print('</select></td>'.&end_data_table_row()."\n");
1.31      albertel 13268: 	$i++;
                   13269:     }
1.594     raeburn  13270:     $r->print(&end_data_table());
1.31      albertel 13271:     $i--;
                   13272:     return $i;
                   13273: }
1.56      matthew  13274: 
1.144     matthew  13275: ######################################################
                   13276: ######################################################
                   13277: 
1.56      matthew  13278: =pod
1.31      albertel 13279: 
1.648     raeburn  13280: =item * &csv_samples_select_table($r,$records,$d)
1.41      ng       13281: 
                   13282: Prints a table of sample values from the upload and can make associate samples to internal names.
                   13283: 
                   13284: $r is an Apache Request ref,
                   13285: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
                   13286: $d is an array of 2 element arrays (internal name, displayed name)
                   13287: 
                   13288: =cut
                   13289: 
1.144     matthew  13290: ######################################################
                   13291: ######################################################
1.31      albertel 13292: sub csv_samples_select_table {
                   13293:     my ($r,$records,$d) = @_;
                   13294:     my $i=0;
1.144     matthew  13295:     #
1.662     bisitz   13296:     my $max_samples = 5;
                   13297:     my $samples = &get_samples($records,$max_samples);
1.594     raeburn  13298:     $r->print(&start_data_table().
                   13299:               &start_data_table_header_row().'<th>'.
                   13300:               &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
                   13301:               &end_data_table_header_row());
1.301     albertel 13302: 
                   13303:     foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594     raeburn  13304: 	$r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32      matthew  13305: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.301     albertel 13306: 	foreach my $option (@$d) {
                   13307: 	    my ($value,$display,$defaultcol)=@{ $option };
1.174     matthew  13308: 	    $r->print('<option value="'.$value.'"'.
1.253     albertel 13309:                       ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174     matthew  13310:                       $display.'</option>');
1.31      albertel 13311: 	}
                   13312: 	$r->print('</select></td><td>');
1.662     bisitz   13313: 	foreach my $line (0..($max_samples-1)) {
1.301     albertel 13314: 	    if (defined($samples->[$line]{$key})) { 
                   13315: 		$r->print($samples->[$line]{$key}."<br />\n"); 
                   13316: 	    }
                   13317: 	}
1.594     raeburn  13318: 	$r->print('</td>'.&end_data_table_row());
1.31      albertel 13319: 	$i++;
                   13320:     }
1.594     raeburn  13321:     $r->print(&end_data_table());
1.31      albertel 13322:     $i--;
                   13323:     return($i);
1.115     matthew  13324: }
                   13325: 
1.144     matthew  13326: ######################################################
                   13327: ######################################################
                   13328: 
1.115     matthew  13329: =pod
                   13330: 
1.648     raeburn  13331: =item * &clean_excel_name($name)
1.115     matthew  13332: 
                   13333: Returns a replacement for $name which does not contain any illegal characters.
                   13334: 
                   13335: =cut
                   13336: 
1.144     matthew  13337: ######################################################
                   13338: ######################################################
1.115     matthew  13339: sub clean_excel_name {
                   13340:     my ($name) = @_;
                   13341:     $name =~ s/[:\*\?\/\\]//g;
                   13342:     if (length($name) > 31) {
                   13343:         $name = substr($name,0,31);
                   13344:     }
                   13345:     return $name;
1.25      albertel 13346: }
1.84      albertel 13347: 
1.85      albertel 13348: =pod
                   13349: 
1.648     raeburn  13350: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85      albertel 13351: 
                   13352: Returns either 1 or undef
                   13353: 
                   13354: 1 if the part is to be hidden, undef if it is to be shown
                   13355: 
                   13356: Arguments are:
                   13357: 
                   13358: $id the id of the part to be checked
                   13359: $symb, optional the symb of the resource to check
                   13360: $udom, optional the domain of the user to check for
                   13361: $uname, optional the username of the user to check for
                   13362: 
                   13363: =cut
1.84      albertel 13364: 
                   13365: sub check_if_partid_hidden {
                   13366:     my ($id,$symb,$udom,$uname) = @_;
1.133     albertel 13367:     my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84      albertel 13368: 					 $symb,$udom,$uname);
1.141     albertel 13369:     my $truth=1;
                   13370:     #if the string starts with !, then the list is the list to show not hide
                   13371:     if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84      albertel 13372:     my @hiddenlist=split(/,/,$hiddenparts);
                   13373:     foreach my $checkid (@hiddenlist) {
1.141     albertel 13374: 	if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84      albertel 13375:     }
1.141     albertel 13376:     return !$truth;
1.84      albertel 13377: }
1.127     matthew  13378: 
1.138     matthew  13379: 
                   13380: ############################################################
                   13381: ############################################################
                   13382: 
                   13383: =pod
                   13384: 
1.157     matthew  13385: =back 
                   13386: 
1.138     matthew  13387: =head1 cgi-bin script and graphing routines
                   13388: 
1.157     matthew  13389: =over 4
                   13390: 
1.648     raeburn  13391: =item * &get_cgi_id()
1.138     matthew  13392: 
                   13393: Inputs: none
                   13394: 
                   13395: Returns an id which can be used to pass environment variables
                   13396: to various cgi-bin scripts.  These environment variables will
                   13397: be removed from the users environment after a given time by
                   13398: the routine &Apache::lonnet::transfer_profile_to_env.
                   13399: 
                   13400: =cut
                   13401: 
                   13402: ############################################################
                   13403: ############################################################
1.152     albertel 13404: my $uniq=0;
1.136     matthew  13405: sub get_cgi_id {
1.154     albertel 13406:     $uniq=($uniq+1)%100000;
1.280     albertel 13407:     return (time.'_'.$$.'_'.$uniq);
1.136     matthew  13408: }
                   13409: 
1.127     matthew  13410: ############################################################
                   13411: ############################################################
                   13412: 
                   13413: =pod
                   13414: 
1.648     raeburn  13415: =item * &DrawBarGraph()
1.127     matthew  13416: 
1.138     matthew  13417: Facilitates the plotting of data in a (stacked) bar graph.
                   13418: Puts plot definition data into the users environment in order for 
                   13419: graph.png to plot it.  Returns an <img> tag for the plot.
                   13420: The bars on the plot are labeled '1','2',...,'n'.
                   13421: 
                   13422: Inputs:
                   13423: 
                   13424: =over 4
                   13425: 
                   13426: =item $Title: string, the title of the plot
                   13427: 
                   13428: =item $xlabel: string, text describing the X-axis of the plot
                   13429: 
                   13430: =item $ylabel: string, text describing the Y-axis of the plot
                   13431: 
                   13432: =item $Max: scalar, the maximum Y value to use in the plot
                   13433: If $Max is < any data point, the graph will not be rendered.
                   13434: 
1.140     matthew  13435: =item $colors: array ref holding the colors to be used for the data sets when
1.138     matthew  13436: they are plotted.  If undefined, default values will be used.
                   13437: 
1.178     matthew  13438: =item $labels: array ref holding the labels to use on the x-axis for the bars.
                   13439: 
1.138     matthew  13440: =item @Values: An array of array references.  Each array reference holds data
                   13441: to be plotted in a stacked bar chart.
                   13442: 
1.239     matthew  13443: =item If the final element of @Values is a hash reference the key/value
                   13444: pairs will be added to the graph definition.
                   13445: 
1.138     matthew  13446: =back
                   13447: 
                   13448: Returns:
                   13449: 
                   13450: An <img> tag which references graph.png and the appropriate identifying
                   13451: information for the plot.
                   13452: 
1.127     matthew  13453: =cut
                   13454: 
                   13455: ############################################################
                   13456: ############################################################
1.134     matthew  13457: sub DrawBarGraph {
1.178     matthew  13458:     my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134     matthew  13459:     #
                   13460:     if (! defined($colors)) {
                   13461:         $colors = ['#33ff00', 
                   13462:                   '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
                   13463:                   '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
                   13464:                   ]; 
                   13465:     }
1.228     matthew  13466:     my $extra_settings = {};
                   13467:     if (ref($Values[-1]) eq 'HASH') {
                   13468:         $extra_settings = pop(@Values);
                   13469:     }
1.127     matthew  13470:     #
1.136     matthew  13471:     my $identifier = &get_cgi_id();
                   13472:     my $id = 'cgi.'.$identifier;        
1.129     matthew  13473:     if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127     matthew  13474:         return '';
                   13475:     }
1.225     matthew  13476:     #
                   13477:     my @Labels;
                   13478:     if (defined($labels)) {
                   13479:         @Labels = @$labels;
                   13480:     } else {
                   13481:         for (my $i=0;$i<@{$Values[0]};$i++) {
                   13482:             push (@Labels,$i+1);
                   13483:         }
                   13484:     }
                   13485:     #
1.129     matthew  13486:     my $NumBars = scalar(@{$Values[0]});
1.225     matthew  13487:     if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129     matthew  13488:     my %ValuesHash;
                   13489:     my $NumSets=1;
                   13490:     foreach my $array (@Values) {
                   13491:         next if (! ref($array));
1.136     matthew  13492:         $ValuesHash{$id.'.data.'.$NumSets++} = 
1.132     matthew  13493:             join(',',@$array);
1.129     matthew  13494:     }
1.127     matthew  13495:     #
1.136     matthew  13496:     my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225     matthew  13497:     if ($NumBars < 3) {
                   13498:         $width = 120+$NumBars*32;
1.220     matthew  13499:         $xskip = 1;
1.225     matthew  13500:         $bar_width = 30;
                   13501:     } elsif ($NumBars < 5) {
                   13502:         $width = 120+$NumBars*20;
                   13503:         $xskip = 1;
                   13504:         $bar_width = 20;
1.220     matthew  13505:     } elsif ($NumBars < 10) {
1.136     matthew  13506:         $width = 120+$NumBars*15;
                   13507:         $xskip = 1;
                   13508:         $bar_width = 15;
                   13509:     } elsif ($NumBars <= 25) {
                   13510:         $width = 120+$NumBars*11;
                   13511:         $xskip = 5;
                   13512:         $bar_width = 8;
                   13513:     } elsif ($NumBars <= 50) {
                   13514:         $width = 120+$NumBars*8;
                   13515:         $xskip = 5;
                   13516:         $bar_width = 4;
                   13517:     } else {
                   13518:         $width = 120+$NumBars*8;
                   13519:         $xskip = 5;
                   13520:         $bar_width = 4;
                   13521:     }
                   13522:     #
1.137     matthew  13523:     $Max = 1 if ($Max < 1);
                   13524:     if ( int($Max) < $Max ) {
                   13525:         $Max++;
                   13526:         $Max = int($Max);
                   13527:     }
1.127     matthew  13528:     $Title  = '' if (! defined($Title));
                   13529:     $xlabel = '' if (! defined($xlabel));
                   13530:     $ylabel = '' if (! defined($ylabel));
1.369     www      13531:     $ValuesHash{$id.'.title'}    = &escape($Title);
                   13532:     $ValuesHash{$id.'.xlabel'}   = &escape($xlabel);
                   13533:     $ValuesHash{$id.'.ylabel'}   = &escape($ylabel);
1.137     matthew  13534:     $ValuesHash{$id.'.y_max_value'} = $Max;
1.136     matthew  13535:     $ValuesHash{$id.'.NumBars'}  = $NumBars;
                   13536:     $ValuesHash{$id.'.NumSets'}  = $NumSets;
                   13537:     $ValuesHash{$id.'.PlotType'} = 'bar';
                   13538:     $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   13539:     $ValuesHash{$id.'.height'}   = $height;
                   13540:     $ValuesHash{$id.'.width'}    = $width;
                   13541:     $ValuesHash{$id.'.xskip'}    = $xskip;
                   13542:     $ValuesHash{$id.'.bar_width'} = $bar_width;
                   13543:     $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127     matthew  13544:     #
1.228     matthew  13545:     # Deal with other parameters
                   13546:     while (my ($key,$value) = each(%$extra_settings)) {
                   13547:         $ValuesHash{$id.'.'.$key} = $value;
                   13548:     }
                   13549:     #
1.646     raeburn  13550:     &Apache::lonnet::appenv(\%ValuesHash);
1.137     matthew  13551:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   13552: }
                   13553: 
                   13554: ############################################################
                   13555: ############################################################
                   13556: 
                   13557: =pod
                   13558: 
1.648     raeburn  13559: =item * &DrawXYGraph()
1.137     matthew  13560: 
1.138     matthew  13561: Facilitates the plotting of data in an XY graph.
                   13562: Puts plot definition data into the users environment in order for 
                   13563: graph.png to plot it.  Returns an <img> tag for the plot.
                   13564: 
                   13565: Inputs:
                   13566: 
                   13567: =over 4
                   13568: 
                   13569: =item $Title: string, the title of the plot
                   13570: 
                   13571: =item $xlabel: string, text describing the X-axis of the plot
                   13572: 
                   13573: =item $ylabel: string, text describing the Y-axis of the plot
                   13574: 
                   13575: =item $Max: scalar, the maximum Y value to use in the plot
                   13576: If $Max is < any data point, the graph will not be rendered.
                   13577: 
                   13578: =item $colors: Array ref containing the hex color codes for the data to be 
                   13579: plotted in.  If undefined, default values will be used.
                   13580: 
                   13581: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   13582: 
                   13583: =item $Ydata: Array ref containing Array refs.  
1.185     www      13584: Each of the contained arrays will be plotted as a separate curve.
1.138     matthew  13585: 
                   13586: =item %Values: hash indicating or overriding any default values which are 
                   13587: passed to graph.png.  
                   13588: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   13589: 
                   13590: =back
                   13591: 
                   13592: Returns:
                   13593: 
                   13594: An <img> tag which references graph.png and the appropriate identifying
                   13595: information for the plot.
                   13596: 
1.137     matthew  13597: =cut
                   13598: 
                   13599: ############################################################
                   13600: ############################################################
                   13601: sub DrawXYGraph {
                   13602:     my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
                   13603:     #
                   13604:     # Create the identifier for the graph
                   13605:     my $identifier = &get_cgi_id();
                   13606:     my $id = 'cgi.'.$identifier;
                   13607:     #
                   13608:     $Title  = '' if (! defined($Title));
                   13609:     $xlabel = '' if (! defined($xlabel));
                   13610:     $ylabel = '' if (! defined($ylabel));
                   13611:     my %ValuesHash = 
                   13612:         (
1.369     www      13613:          $id.'.title'  => &escape($Title),
                   13614:          $id.'.xlabel' => &escape($xlabel),
                   13615:          $id.'.ylabel' => &escape($ylabel),
1.137     matthew  13616:          $id.'.y_max_value'=> $Max,
                   13617:          $id.'.labels'     => join(',',@$Xlabels),
                   13618:          $id.'.PlotType'   => 'XY',
                   13619:          );
                   13620:     #
                   13621:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   13622:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   13623:     }
                   13624:     #
                   13625:     if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
                   13626:         return '';
                   13627:     }
                   13628:     my $NumSets=1;
1.138     matthew  13629:     foreach my $array (@{$Ydata}){
1.137     matthew  13630:         next if (! ref($array));
                   13631:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
                   13632:     }
1.138     matthew  13633:     $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137     matthew  13634:     #
                   13635:     # Deal with other parameters
                   13636:     while (my ($key,$value) = each(%Values)) {
                   13637:         $ValuesHash{$id.'.'.$key} = $value;
1.127     matthew  13638:     }
                   13639:     #
1.646     raeburn  13640:     &Apache::lonnet::appenv(\%ValuesHash);
1.136     matthew  13641:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   13642: }
                   13643: 
                   13644: ############################################################
                   13645: ############################################################
                   13646: 
                   13647: =pod
                   13648: 
1.648     raeburn  13649: =item * &DrawXYYGraph()
1.138     matthew  13650: 
                   13651: Facilitates the plotting of data in an XY graph with two Y axes.
                   13652: Puts plot definition data into the users environment in order for 
                   13653: graph.png to plot it.  Returns an <img> tag for the plot.
                   13654: 
                   13655: Inputs:
                   13656: 
                   13657: =over 4
                   13658: 
                   13659: =item $Title: string, the title of the plot
                   13660: 
                   13661: =item $xlabel: string, text describing the X-axis of the plot
                   13662: 
                   13663: =item $ylabel: string, text describing the Y-axis of the plot
                   13664: 
                   13665: =item $colors: Array ref containing the hex color codes for the data to be 
                   13666: plotted in.  If undefined, default values will be used.
                   13667: 
                   13668: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   13669: 
                   13670: =item $Ydata1: The first data set
                   13671: 
                   13672: =item $Min1: The minimum value of the left Y-axis
                   13673: 
                   13674: =item $Max1: The maximum value of the left Y-axis
                   13675: 
                   13676: =item $Ydata2: The second data set
                   13677: 
                   13678: =item $Min2: The minimum value of the right Y-axis
                   13679: 
                   13680: =item $Max2: The maximum value of the left Y-axis
                   13681: 
                   13682: =item %Values: hash indicating or overriding any default values which are 
                   13683: passed to graph.png.  
                   13684: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   13685: 
                   13686: =back
                   13687: 
                   13688: Returns:
                   13689: 
                   13690: An <img> tag which references graph.png and the appropriate identifying
                   13691: information for the plot.
1.136     matthew  13692: 
                   13693: =cut
                   13694: 
                   13695: ############################################################
                   13696: ############################################################
1.137     matthew  13697: sub DrawXYYGraph {
                   13698:     my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
                   13699:                                         $Ydata2,$Min2,$Max2,%Values)=@_;
1.136     matthew  13700:     #
                   13701:     # Create the identifier for the graph
                   13702:     my $identifier = &get_cgi_id();
                   13703:     my $id = 'cgi.'.$identifier;
                   13704:     #
                   13705:     $Title  = '' if (! defined($Title));
                   13706:     $xlabel = '' if (! defined($xlabel));
                   13707:     $ylabel = '' if (! defined($ylabel));
                   13708:     my %ValuesHash = 
                   13709:         (
1.369     www      13710:          $id.'.title'  => &escape($Title),
                   13711:          $id.'.xlabel' => &escape($xlabel),
                   13712:          $id.'.ylabel' => &escape($ylabel),
1.136     matthew  13713:          $id.'.labels' => join(',',@$Xlabels),
                   13714:          $id.'.PlotType' => 'XY',
                   13715:          $id.'.NumSets' => 2,
1.137     matthew  13716:          $id.'.two_axes' => 1,
                   13717:          $id.'.y1_max_value' => $Max1,
                   13718:          $id.'.y1_min_value' => $Min1,
                   13719:          $id.'.y2_max_value' => $Max2,
                   13720:          $id.'.y2_min_value' => $Min2,
1.136     matthew  13721:          );
                   13722:     #
1.137     matthew  13723:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   13724:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   13725:     }
                   13726:     #
                   13727:     if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
                   13728:         ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136     matthew  13729:         return '';
                   13730:     }
                   13731:     my $NumSets=1;
1.137     matthew  13732:     foreach my $array ($Ydata1,$Ydata2){
1.136     matthew  13733:         next if (! ref($array));
                   13734:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137     matthew  13735:     }
                   13736:     #
                   13737:     # Deal with other parameters
                   13738:     while (my ($key,$value) = each(%Values)) {
                   13739:         $ValuesHash{$id.'.'.$key} = $value;
1.136     matthew  13740:     }
                   13741:     #
1.646     raeburn  13742:     &Apache::lonnet::appenv(\%ValuesHash);
1.130     albertel 13743:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139     matthew  13744: }
                   13745: 
                   13746: ############################################################
                   13747: ############################################################
                   13748: 
                   13749: =pod
                   13750: 
1.157     matthew  13751: =back 
                   13752: 
1.139     matthew  13753: =head1 Statistics helper routines?  
                   13754: 
                   13755: Bad place for them but what the hell.
                   13756: 
1.157     matthew  13757: =over 4
                   13758: 
1.648     raeburn  13759: =item * &chartlink()
1.139     matthew  13760: 
                   13761: Returns a link to the chart for a specific student.  
                   13762: 
                   13763: Inputs:
                   13764: 
                   13765: =over 4
                   13766: 
                   13767: =item $linktext: The text of the link
                   13768: 
                   13769: =item $sname: The students username
                   13770: 
                   13771: =item $sdomain: The students domain
                   13772: 
                   13773: =back
                   13774: 
1.157     matthew  13775: =back
                   13776: 
1.139     matthew  13777: =cut
                   13778: 
                   13779: ############################################################
                   13780: ############################################################
                   13781: sub chartlink {
                   13782:     my ($linktext, $sname, $sdomain) = @_;
                   13783:     my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369     www      13784:         '&amp;SelectedStudent='.&escape($sname.':'.$sdomain).
1.219     albertel 13785:         '&amp;chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139     matthew  13786:        '">'.$linktext.'</a>';
1.153     matthew  13787: }
                   13788: 
                   13789: #######################################################
                   13790: #######################################################
                   13791: 
                   13792: =pod
                   13793: 
                   13794: =head1 Course Environment Routines
1.157     matthew  13795: 
                   13796: =over 4
1.153     matthew  13797: 
1.648     raeburn  13798: =item * &restore_course_settings()
1.153     matthew  13799: 
1.648     raeburn  13800: =item * &store_course_settings()
1.153     matthew  13801: 
                   13802: Restores/Store indicated form parameters from the course environment.
                   13803: Will not overwrite existing values of the form parameters.
                   13804: 
                   13805: Inputs: 
                   13806: a scalar describing the data (e.g. 'chart', 'problem_analysis')
                   13807: 
                   13808: a hash ref describing the data to be stored.  For example:
                   13809:    
                   13810: %Save_Parameters = ('Status' => 'scalar',
                   13811:     'chartoutputmode' => 'scalar',
                   13812:     'chartoutputdata' => 'scalar',
                   13813:     'Section' => 'array',
1.373     raeburn  13814:     'Group' => 'array',
1.153     matthew  13815:     'StudentData' => 'array',
                   13816:     'Maps' => 'array');
                   13817: 
                   13818: Returns: both routines return nothing
                   13819: 
1.631     raeburn  13820: =back
                   13821: 
1.153     matthew  13822: =cut
                   13823: 
                   13824: #######################################################
                   13825: #######################################################
                   13826: sub store_course_settings {
1.496     albertel 13827:     return &store_settings($env{'request.course.id'},@_);
                   13828: }
                   13829: 
                   13830: sub store_settings {
1.153     matthew  13831:     # save to the environment
                   13832:     # appenv the same items, just to be safe
1.300     albertel 13833:     my $udom  = $env{'user.domain'};
                   13834:     my $uname = $env{'user.name'};
1.496     albertel 13835:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  13836:     my %SaveHash;
                   13837:     my %AppHash;
                   13838:     while (my ($setting,$type) = each(%$Settings)) {
1.496     albertel 13839:         my $basename = join('.','internal',$context,$prefix,$setting);
1.300     albertel 13840:         my $envname = 'environment.'.$basename;
1.258     albertel 13841:         if (exists($env{'form.'.$setting})) {
1.153     matthew  13842:             # Save this value away
                   13843:             if ($type eq 'scalar' &&
1.258     albertel 13844:                 (! exists($env{$envname}) || 
                   13845:                  $env{$envname} ne $env{'form.'.$setting})) {
                   13846:                 $SaveHash{$basename} = $env{'form.'.$setting};
                   13847:                 $AppHash{$envname}   = $env{'form.'.$setting};
1.153     matthew  13848:             } elsif ($type eq 'array') {
                   13849:                 my $stored_form;
1.258     albertel 13850:                 if (ref($env{'form.'.$setting})) {
1.153     matthew  13851:                     $stored_form = join(',',
                   13852:                                         map {
1.369     www      13853:                                             &escape($_);
1.258     albertel 13854:                                         } sort(@{$env{'form.'.$setting}}));
1.153     matthew  13855:                 } else {
                   13856:                     $stored_form = 
1.369     www      13857:                         &escape($env{'form.'.$setting});
1.153     matthew  13858:                 }
                   13859:                 # Determine if the array contents are the same.
1.258     albertel 13860:                 if ($stored_form ne $env{$envname}) {
1.153     matthew  13861:                     $SaveHash{$basename} = $stored_form;
                   13862:                     $AppHash{$envname}   = $stored_form;
                   13863:                 }
                   13864:             }
                   13865:         }
                   13866:     }
                   13867:     my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300     albertel 13868:                                           $udom,$uname);
1.153     matthew  13869:     if ($put_result !~ /^(ok|delayed)/) {
                   13870:         &Apache::lonnet::logthis('unable to save form parameters, '.
                   13871:                                  'got error:'.$put_result);
                   13872:     }
                   13873:     # Make sure these settings stick around in this session, too
1.646     raeburn  13874:     &Apache::lonnet::appenv(\%AppHash);
1.153     matthew  13875:     return;
                   13876: }
                   13877: 
                   13878: sub restore_course_settings {
1.499     albertel 13879:     return &restore_settings($env{'request.course.id'},@_);
1.496     albertel 13880: }
                   13881: 
                   13882: sub restore_settings {
                   13883:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  13884:     while (my ($setting,$type) = each(%$Settings)) {
1.258     albertel 13885:         next if (exists($env{'form.'.$setting}));
1.496     albertel 13886:         my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153     matthew  13887:             '.'.$setting;
1.258     albertel 13888:         if (exists($env{$envname})) {
1.153     matthew  13889:             if ($type eq 'scalar') {
1.258     albertel 13890:                 $env{'form.'.$setting} = $env{$envname};
1.153     matthew  13891:             } elsif ($type eq 'array') {
1.258     albertel 13892:                 $env{'form.'.$setting} = [ 
1.153     matthew  13893:                                            map { 
1.369     www      13894:                                                &unescape($_); 
1.258     albertel 13895:                                            } split(',',$env{$envname})
1.153     matthew  13896:                                            ];
                   13897:             }
                   13898:         }
                   13899:     }
1.127     matthew  13900: }
                   13901: 
1.618     raeburn  13902: #######################################################
                   13903: #######################################################
                   13904: 
                   13905: =pod
                   13906: 
                   13907: =head1 Domain E-mail Routines  
                   13908: 
                   13909: =over 4
                   13910: 
1.648     raeburn  13911: =item * &build_recipient_list()
1.618     raeburn  13912: 
1.1075.2.44  raeburn  13913: Build recipient lists for following types of e-mail:
1.766     raeburn  13914: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44  raeburn  13915: (d) Help requests, (e) Course requests needing approval, (f) loncapa
                   13916: module change checking, student/employee ID conflict checks, as
                   13917: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
                   13918: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618     raeburn  13919: 
                   13920: Inputs:
1.1075.2.44  raeburn  13921: defmail (scalar - email address of default recipient),
                   13922: mailing type (scalar: errormail, packagesmail, helpdeskmail,
                   13923: requestsmail, updatesmail, or idconflictsmail).
                   13924: 
1.619     raeburn  13925: defdom (domain for which to retrieve configuration settings),
1.1075.2.44  raeburn  13926: 
                   13927: origmail (scalar - email address of recipient from loncapa.conf,
                   13928: i.e., predates configuration by DC via domainprefs.pm
1.618     raeburn  13929: 
1.655     raeburn  13930: Returns: comma separated list of addresses to which to send e-mail.
                   13931: 
                   13932: =back
1.618     raeburn  13933: 
                   13934: =cut
                   13935: 
                   13936: ############################################################
                   13937: ############################################################
                   13938: sub build_recipient_list {
1.619     raeburn  13939:     my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618     raeburn  13940:     my @recipients;
                   13941:     my $otheremails;
                   13942:     my %domconfig =
                   13943:          &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
                   13944:     if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766     raeburn  13945:         if (exists($domconfig{'contacts'}{$mailing})) {
                   13946:             if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
                   13947:                 my @contacts = ('adminemail','supportemail');
                   13948:                 foreach my $item (@contacts) {
                   13949:                     if ($domconfig{'contacts'}{$mailing}{$item}) {
                   13950:                         my $addr = $domconfig{'contacts'}{$item}; 
                   13951:                         if (!grep(/^\Q$addr\E$/,@recipients)) {
                   13952:                             push(@recipients,$addr);
                   13953:                         }
1.619     raeburn  13954:                     }
1.766     raeburn  13955:                     $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618     raeburn  13956:                 }
                   13957:             }
1.766     raeburn  13958:         } elsif ($origmail ne '') {
                   13959:             push(@recipients,$origmail);
1.618     raeburn  13960:         }
1.619     raeburn  13961:     } elsif ($origmail ne '') {
                   13962:         push(@recipients,$origmail);
1.618     raeburn  13963:     }
1.688     raeburn  13964:     if (defined($defmail)) {
                   13965:         if ($defmail ne '') {
                   13966:             push(@recipients,$defmail);
                   13967:         }
1.618     raeburn  13968:     }
                   13969:     if ($otheremails) {
1.619     raeburn  13970:         my @others;
                   13971:         if ($otheremails =~ /,/) {
                   13972:             @others = split(/,/,$otheremails);
1.618     raeburn  13973:         } else {
1.619     raeburn  13974:             push(@others,$otheremails);
                   13975:         }
                   13976:         foreach my $addr (@others) {
                   13977:             if (!grep(/^\Q$addr\E$/,@recipients)) {
                   13978:                 push(@recipients,$addr);
                   13979:             }
1.618     raeburn  13980:         }
                   13981:     }
1.619     raeburn  13982:     my $recipientlist = join(',',@recipients); 
1.618     raeburn  13983:     return $recipientlist;
                   13984: }
                   13985: 
1.127     matthew  13986: ############################################################
                   13987: ############################################################
1.154     albertel 13988: 
1.655     raeburn  13989: =pod
                   13990: 
                   13991: =head1 Course Catalog Routines
                   13992: 
                   13993: =over 4
                   13994: 
                   13995: =item * &gather_categories()
                   13996: 
                   13997: Converts category definitions - keys of categories hash stored in  
                   13998: coursecategories in configuration.db on the primary library server in a 
                   13999: domain - to an array.  Also generates javascript and idx hash used to 
                   14000: generate Domain Coordinator interface for editing Course Categories.
                   14001: 
                   14002: Inputs:
1.663     raeburn  14003: 
1.655     raeburn  14004: categories (reference to hash of category definitions).
1.663     raeburn  14005: 
1.655     raeburn  14006: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   14007:       categories and subcategories).
1.663     raeburn  14008: 
1.655     raeburn  14009: idx (reference to hash of counters used in Domain Coordinator interface for 
                   14010:       editing Course Categories).
1.663     raeburn  14011: 
1.655     raeburn  14012: jsarray (reference to array of categories used to create Javascript arrays for
                   14013:          Domain Coordinator interface for editing Course Categories).
                   14014: 
                   14015: Returns: nothing
                   14016: 
                   14017: Side effects: populates cats, idx and jsarray. 
                   14018: 
                   14019: =cut
                   14020: 
                   14021: sub gather_categories {
                   14022:     my ($categories,$cats,$idx,$jsarray) = @_;
                   14023:     my %counters;
                   14024:     my $num = 0;
                   14025:     foreach my $item (keys(%{$categories})) {
                   14026:         my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   14027:         if ($container eq '' && $depth == 0) {
                   14028:             $cats->[$depth][$categories->{$item}] = $cat;
                   14029:         } else {
                   14030:             $cats->[$depth]{$container}[$categories->{$item}] = $cat;
                   14031:         }
                   14032:         my ($escitem,$tail) = split(/:/,$item,2);
                   14033:         if ($counters{$tail} eq '') {
                   14034:             $counters{$tail} = $num;
                   14035:             $num ++;
                   14036:         }
                   14037:         if (ref($idx) eq 'HASH') {
                   14038:             $idx->{$item} = $counters{$tail};
                   14039:         }
                   14040:         if (ref($jsarray) eq 'ARRAY') {
                   14041:             push(@{$jsarray->[$counters{$tail}]},$item);
                   14042:         }
                   14043:     }
                   14044:     return;
                   14045: }
                   14046: 
                   14047: =pod
                   14048: 
                   14049: =item * &extract_categories()
                   14050: 
                   14051: Used to generate breadcrumb trails for course categories.
                   14052: 
                   14053: Inputs:
1.663     raeburn  14054: 
1.655     raeburn  14055: categories (reference to hash of category definitions).
1.663     raeburn  14056: 
1.655     raeburn  14057: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   14058:       categories and subcategories).
1.663     raeburn  14059: 
1.655     raeburn  14060: trails (reference to array of breacrumb trails for each category).
1.663     raeburn  14061: 
1.655     raeburn  14062: allitems (reference to hash - key is category key 
                   14063:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  14064: 
1.655     raeburn  14065: idx (reference to hash of counters used in Domain Coordinator interface for
                   14066:       editing Course Categories).
1.663     raeburn  14067: 
1.655     raeburn  14068: jsarray (reference to array of categories used to create Javascript arrays for
                   14069:          Domain Coordinator interface for editing Course Categories).
                   14070: 
1.665     raeburn  14071: subcats (reference to hash of arrays containing all subcategories within each 
                   14072:          category, -recursive)
                   14073: 
1.655     raeburn  14074: Returns: nothing
                   14075: 
                   14076: Side effects: populates trails and allitems hash references.
                   14077: 
                   14078: =cut
                   14079: 
                   14080: sub extract_categories {
1.665     raeburn  14081:     my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655     raeburn  14082:     if (ref($categories) eq 'HASH') {
                   14083:         &gather_categories($categories,$cats,$idx,$jsarray);
                   14084:         if (ref($cats->[0]) eq 'ARRAY') {
                   14085:             for (my $i=0; $i<@{$cats->[0]}; $i++) {
                   14086:                 my $name = $cats->[0][$i];
                   14087:                 my $item = &escape($name).'::0';
                   14088:                 my $trailstr;
                   14089:                 if ($name eq 'instcode') {
                   14090:                     $trailstr = &mt('Official courses (with institutional codes)');
1.919     raeburn  14091:                 } elsif ($name eq 'communities') {
                   14092:                     $trailstr = &mt('Communities');
1.655     raeburn  14093:                 } else {
                   14094:                     $trailstr = $name;
                   14095:                 }
                   14096:                 if ($allitems->{$item} eq '') {
                   14097:                     push(@{$trails},$trailstr);
                   14098:                     $allitems->{$item} = scalar(@{$trails})-1;
                   14099:                 }
                   14100:                 my @parents = ($name);
                   14101:                 if (ref($cats->[1]{$name}) eq 'ARRAY') {
                   14102:                     for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
                   14103:                         my $category = $cats->[1]{$name}[$j];
1.665     raeburn  14104:                         if (ref($subcats) eq 'HASH') {
                   14105:                             push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
                   14106:                         }
                   14107:                         &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
                   14108:                     }
                   14109:                 } else {
                   14110:                     if (ref($subcats) eq 'HASH') {
                   14111:                         $subcats->{$item} = [];
1.655     raeburn  14112:                     }
                   14113:                 }
                   14114:             }
                   14115:         }
                   14116:     }
                   14117:     return;
                   14118: }
                   14119: 
                   14120: =pod
                   14121: 
1.1075.2.56  raeburn  14122: =item * &recurse_categories()
1.655     raeburn  14123: 
                   14124: Recursively used to generate breadcrumb trails for course categories.
                   14125: 
                   14126: Inputs:
1.663     raeburn  14127: 
1.655     raeburn  14128: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   14129:       categories and subcategories).
1.663     raeburn  14130: 
1.655     raeburn  14131: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663     raeburn  14132: 
                   14133: category (current course category, for which breadcrumb trail is being generated).
                   14134: 
                   14135: trails (reference to array of breadcrumb trails for each category).
                   14136: 
1.655     raeburn  14137: allitems (reference to hash - key is category key
                   14138:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  14139: 
1.655     raeburn  14140: parents (array containing containers directories for current category, 
                   14141:          back to top level). 
                   14142: 
                   14143: Returns: nothing
                   14144: 
                   14145: Side effects: populates trails and allitems hash references
                   14146: 
                   14147: =cut
                   14148: 
                   14149: sub recurse_categories {
1.665     raeburn  14150:     my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655     raeburn  14151:     my $shallower = $depth - 1;
                   14152:     if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
                   14153:         for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
                   14154:             my $name = $cats->[$depth]{$category}[$k];
                   14155:             my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   14156:             my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   14157:             if ($allitems->{$item} eq '') {
                   14158:                 push(@{$trails},$trailstr);
                   14159:                 $allitems->{$item} = scalar(@{$trails})-1;
                   14160:             }
                   14161:             my $deeper = $depth+1;
                   14162:             push(@{$parents},$category);
1.665     raeburn  14163:             if (ref($subcats) eq 'HASH') {
                   14164:                 my $subcat = &escape($name).':'.$category.':'.$depth;
                   14165:                 for (my $j=@{$parents}; $j>=0; $j--) {
                   14166:                     my $higher;
                   14167:                     if ($j > 0) {
                   14168:                         $higher = &escape($parents->[$j]).':'.
                   14169:                                   &escape($parents->[$j-1]).':'.$j;
                   14170:                     } else {
                   14171:                         $higher = &escape($parents->[$j]).'::'.$j;
                   14172:                     }
                   14173:                     push(@{$subcats->{$higher}},$subcat);
                   14174:                 }
                   14175:             }
                   14176:             &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
                   14177:                                 $subcats);
1.655     raeburn  14178:             pop(@{$parents});
                   14179:         }
                   14180:     } else {
                   14181:         my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   14182:         my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   14183:         if ($allitems->{$item} eq '') {
                   14184:             push(@{$trails},$trailstr);
                   14185:             $allitems->{$item} = scalar(@{$trails})-1;
                   14186:         }
                   14187:     }
                   14188:     return;
                   14189: }
                   14190: 
1.663     raeburn  14191: =pod
                   14192: 
1.1075.2.56  raeburn  14193: =item * &assign_categories_table()
1.663     raeburn  14194: 
                   14195: Create a datatable for display of hierarchical categories in a domain,
                   14196: with checkboxes to allow a course to be categorized. 
                   14197: 
                   14198: Inputs:
                   14199: 
                   14200: cathash - reference to hash of categories defined for the domain (from
                   14201:           configuration.db)
                   14202: 
                   14203: currcat - scalar with an & separated list of categories assigned to a course. 
                   14204: 
1.919     raeburn  14205: type    - scalar contains course type (Course or Community).
                   14206: 
1.663     raeburn  14207: Returns: $output (markup to be displayed) 
                   14208: 
                   14209: =cut
                   14210: 
                   14211: sub assign_categories_table {
1.919     raeburn  14212:     my ($cathash,$currcat,$type) = @_;
1.663     raeburn  14213:     my $output;
                   14214:     if (ref($cathash) eq 'HASH') {
                   14215:         my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
                   14216:         &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
                   14217:         $maxdepth = scalar(@cats);
                   14218:         if (@cats > 0) {
                   14219:             my $itemcount = 0;
                   14220:             if (ref($cats[0]) eq 'ARRAY') {
                   14221:                 my @currcategories;
                   14222:                 if ($currcat ne '') {
                   14223:                     @currcategories = split('&',$currcat);
                   14224:                 }
1.919     raeburn  14225:                 my $table;
1.663     raeburn  14226:                 for (my $i=0; $i<@{$cats[0]}; $i++) {
                   14227:                     my $parent = $cats[0][$i];
1.919     raeburn  14228:                     next if ($parent eq 'instcode');
                   14229:                     if ($type eq 'Community') {
                   14230:                         next unless ($parent eq 'communities');
                   14231:                     } else {
                   14232:                         next if ($parent eq 'communities');
                   14233:                     }
1.663     raeburn  14234:                     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   14235:                     my $item = &escape($parent).'::0';
                   14236:                     my $checked = '';
                   14237:                     if (@currcategories > 0) {
                   14238:                         if (grep(/^\Q$item\E$/,@currcategories)) {
1.772     bisitz   14239:                             $checked = ' checked="checked"';
1.663     raeburn  14240:                         }
                   14241:                     }
1.919     raeburn  14242:                     my $parent_title = $parent;
                   14243:                     if ($parent eq 'communities') {
                   14244:                         $parent_title = &mt('Communities');
                   14245:                     }
                   14246:                     $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
                   14247:                               '<input type="checkbox" name="usecategory" value="'.
                   14248:                               $item.'"'.$checked.' />'.$parent_title.'</span>'.
                   14249:                               '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663     raeburn  14250:                     my $depth = 1;
                   14251:                     push(@path,$parent);
1.919     raeburn  14252:                     $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663     raeburn  14253:                     pop(@path);
1.919     raeburn  14254:                     $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663     raeburn  14255:                     $itemcount ++;
                   14256:                 }
1.919     raeburn  14257:                 if ($itemcount) {
                   14258:                     $output = &Apache::loncommon::start_data_table().
                   14259:                               $table.
                   14260:                               &Apache::loncommon::end_data_table();
                   14261:                 }
1.663     raeburn  14262:             }
                   14263:         }
                   14264:     }
                   14265:     return $output;
                   14266: }
                   14267: 
                   14268: =pod
                   14269: 
1.1075.2.56  raeburn  14270: =item * &assign_category_rows()
1.663     raeburn  14271: 
                   14272: Create a datatable row for display of nested categories in a domain,
                   14273: with checkboxes to allow a course to be categorized,called recursively.
                   14274: 
                   14275: Inputs:
                   14276: 
                   14277: itemcount - track row number for alternating colors
                   14278: 
                   14279: cats - reference to array of arrays/hashes which encapsulates hierarchy of
                   14280:       categories and subcategories.
                   14281: 
                   14282: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
                   14283: 
                   14284: parent - parent of current category item
                   14285: 
                   14286: path - Array containing all categories back up through the hierarchy from the
                   14287:        current category to the top level.
                   14288: 
                   14289: currcategories - reference to array of current categories assigned to the course
                   14290: 
                   14291: Returns: $output (markup to be displayed).
                   14292: 
                   14293: =cut
                   14294: 
                   14295: sub assign_category_rows {
                   14296:     my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
                   14297:     my ($text,$name,$item,$chgstr);
                   14298:     if (ref($cats) eq 'ARRAY') {
                   14299:         my $maxdepth = scalar(@{$cats});
                   14300:         if (ref($cats->[$depth]) eq 'HASH') {
                   14301:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   14302:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   14303:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45  raeburn  14304:                 $text .= '<td><table class="LC_data_table">';
1.663     raeburn  14305:                 for (my $j=0; $j<$numchildren; $j++) {
                   14306:                     $name = $cats->[$depth]{$parent}[$j];
                   14307:                     $item = &escape($name).':'.&escape($parent).':'.$depth;
                   14308:                     my $deeper = $depth+1;
                   14309:                     my $checked = '';
                   14310:                     if (ref($currcategories) eq 'ARRAY') {
                   14311:                         if (@{$currcategories} > 0) {
                   14312:                             if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772     bisitz   14313:                                 $checked = ' checked="checked"';
1.663     raeburn  14314:                             }
                   14315:                         }
                   14316:                     }
1.664     raeburn  14317:                     $text .= '<tr><td><span class="LC_nobreak"><label>'.
                   14318:                              '<input type="checkbox" name="usecategory" value="'.
1.675     raeburn  14319:                              $item.'"'.$checked.' />'.$name.'</label></span>'.
                   14320:                              '<input type="hidden" name="catname" value="'.$name.'" />'.
                   14321:                              '</td><td>';
1.663     raeburn  14322:                     if (ref($path) eq 'ARRAY') {
                   14323:                         push(@{$path},$name);
                   14324:                         $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
                   14325:                         pop(@{$path});
                   14326:                     }
                   14327:                     $text .= '</td></tr>';
                   14328:                 }
                   14329:                 $text .= '</table></td>';
                   14330:             }
                   14331:         }
                   14332:     }
                   14333:     return $text;
                   14334: }
                   14335: 
1.1075.2.69  raeburn  14336: =pod
                   14337: 
                   14338: =back
                   14339: 
                   14340: =cut
                   14341: 
1.655     raeburn  14342: ############################################################
                   14343: ############################################################
                   14344: 
                   14345: 
1.443     albertel 14346: sub commit_customrole {
1.664     raeburn  14347:     my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630     raeburn  14348:     my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443     albertel 14349:                          ($start?', '.&mt('starting').' '.localtime($start):'').
                   14350:                          ($end?', ending '.localtime($end):'').': <b>'.
                   14351:               &Apache::lonnet::assigncustomrole(
1.664     raeburn  14352:                  $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443     albertel 14353:                  '</b><br />';
                   14354:     return $output;
                   14355: }
                   14356: 
                   14357: sub commit_standardrole {
1.1075.2.31  raeburn  14358:     my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541     raeburn  14359:     my ($output,$logmsg,$linefeed);
                   14360:     if ($context eq 'auto') {
                   14361:         $linefeed = "\n";
                   14362:     } else {
                   14363:         $linefeed = "<br />\n";
                   14364:     }  
1.443     albertel 14365:     if ($three eq 'st') {
1.541     raeburn  14366:         my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31  raeburn  14367:                                          $one,$two,$sec,$context,$credits);
1.541     raeburn  14368:         if (($result =~ /^error/) || ($result eq 'not_in_class') || 
1.626     raeburn  14369:             ($result eq 'unknown_course') || ($result eq 'refused')) {
                   14370:             $output = $logmsg.' '.&mt('Error: ').$result."\n"; 
1.443     albertel 14371:         } else {
1.541     raeburn  14372:             $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443     albertel 14373:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  14374:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
                   14375:             if ($context eq 'auto') {
                   14376:                 $output .= $result.$linefeed.&mt('Add to classlist').': ok';
                   14377:             } else {
                   14378:                $output .= '<b>'.$result.'</b>'.$linefeed.
                   14379:                &mt('Add to classlist').': <b>ok</b>';
                   14380:             }
                   14381:             $output .= $linefeed;
1.443     albertel 14382:         }
                   14383:     } else {
                   14384:         $output = &mt('Assigning').' '.$three.' in '.$url.
                   14385:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  14386:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652     raeburn  14387:         my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541     raeburn  14388:         if ($context eq 'auto') {
                   14389:             $output .= $result.$linefeed;
                   14390:         } else {
                   14391:             $output .= '<b>'.$result.'</b>'.$linefeed;
                   14392:         }
1.443     albertel 14393:     }
                   14394:     return $output;
                   14395: }
                   14396: 
                   14397: sub commit_studentrole {
1.1075.2.31  raeburn  14398:     my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
                   14399:         $credits) = @_;
1.626     raeburn  14400:     my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541     raeburn  14401:     if ($context eq 'auto') {
                   14402:         $linefeed = "\n";
                   14403:     } else {
                   14404:         $linefeed = '<br />'."\n";
                   14405:     }
1.443     albertel 14406:     if (defined($one) && defined($two)) {
                   14407:         my $cid=$one.'_'.$two;
                   14408:         my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
                   14409:         my $secchange = 0;
                   14410:         my $expire_role_result;
                   14411:         my $modify_section_result;
1.628     raeburn  14412:         if ($oldsec ne '-1') { 
                   14413:             if ($oldsec ne $sec) {
1.443     albertel 14414:                 $secchange = 1;
1.628     raeburn  14415:                 my $now = time;
1.443     albertel 14416:                 my $uurl='/'.$cid;
                   14417:                 $uurl=~s/\_/\//g;
                   14418:                 if ($oldsec) {
                   14419:                     $uurl.='/'.$oldsec;
                   14420:                 }
1.626     raeburn  14421:                 $oldsecurl = $uurl;
1.628     raeburn  14422:                 $expire_role_result = 
1.652     raeburn  14423:                     &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628     raeburn  14424:                 if ($env{'request.course.sec'} ne '') { 
                   14425:                     if ($expire_role_result eq 'refused') {
                   14426:                         my @roles = ('st');
                   14427:                         my @statuses = ('previous');
                   14428:                         my @roledoms = ($one);
                   14429:                         my $withsec = 1;
                   14430:                         my %roleshash = 
                   14431:                             &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
                   14432:                                               \@statuses,\@roles,\@roledoms,$withsec);
                   14433:                         if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
                   14434:                             my ($oldstart,$oldend) = 
                   14435:                                 split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
                   14436:                             if ($oldend > 0 && $oldend <= $now) {
                   14437:                                 $expire_role_result = 'ok';
                   14438:                             }
                   14439:                         }
                   14440:                     }
                   14441:                 }
1.443     albertel 14442:                 $result = $expire_role_result;
                   14443:             }
                   14444:         }
                   14445:         if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31  raeburn  14446:             $modify_section_result = 
                   14447:                 &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
                   14448:                                                            undef,undef,undef,$sec,
                   14449:                                                            $end,$start,'','',$cid,
                   14450:                                                            '',$context,$credits);
1.443     albertel 14451:             if ($modify_section_result =~ /^ok/) {
                   14452:                 if ($secchange == 1) {
1.628     raeburn  14453:                     if ($sec eq '') {
                   14454:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
                   14455:                     } else {
                   14456:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
                   14457:                     }
1.443     albertel 14458:                 } elsif ($oldsec eq '-1') {
1.628     raeburn  14459:                     if ($sec eq '') {
                   14460:                         $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
                   14461:                     } else {
                   14462:                         $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   14463:                     }
1.443     albertel 14464:                 } else {
1.628     raeburn  14465:                     if ($sec eq '') {
                   14466:                         $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
                   14467:                     } else {
                   14468:                         $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   14469:                     }
1.443     albertel 14470:                 }
                   14471:             } else {
1.628     raeburn  14472:                 if ($secchange) {       
                   14473:                     $$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;
                   14474:                 } else {
                   14475:                     $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
                   14476:                 }
1.443     albertel 14477:             }
                   14478:             $result = $modify_section_result;
                   14479:         } elsif ($secchange == 1) {
1.628     raeburn  14480:             if ($oldsec eq '') {
1.1075.2.20  raeburn  14481:                 $$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  14482:             } else {
                   14483:                 $$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;
                   14484:             }
1.626     raeburn  14485:             if ($expire_role_result eq 'refused') {
                   14486:                 my $newsecurl = '/'.$cid;
                   14487:                 $newsecurl =~ s/\_/\//g;
                   14488:                 if ($sec ne '') {
                   14489:                     $newsecurl.='/'.$sec;
                   14490:                 }
                   14491:                 if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
                   14492:                     if ($sec eq '') {
                   14493:                         $$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;
                   14494:                     } else {
                   14495:                         $$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;
                   14496:                     }
                   14497:                 }
                   14498:             }
1.443     albertel 14499:         }
                   14500:     } else {
1.626     raeburn  14501:         $$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 14502:         $result = "error: incomplete course id\n";
                   14503:     }
                   14504:     return $result;
                   14505: }
                   14506: 
1.1075.2.25  raeburn  14507: sub show_role_extent {
                   14508:     my ($scope,$context,$role) = @_;
                   14509:     $scope =~ s{^/}{};
                   14510:     my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
                   14511:     push(@courseroles,'co');
                   14512:     my @authorroles = &Apache::lonuserutils::roles_by_context('author');
                   14513:     if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
                   14514:         $scope =~ s{/}{_};
                   14515:         return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
                   14516:     } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
                   14517:         my ($audom,$auname) = split(/\//,$scope);
                   14518:         return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
                   14519:                    &Apache::loncommon::plainname($auname,$audom).'</span>');
                   14520:     } else {
                   14521:         $scope =~ s{/$}{};
                   14522:         return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
                   14523:                    &Apache::lonnet::domain($scope,'description').'</span>');
                   14524:     }
                   14525: }
                   14526: 
1.443     albertel 14527: ############################################################
                   14528: ############################################################
                   14529: 
1.566     albertel 14530: sub check_clone {
1.578     raeburn  14531:     my ($args,$linefeed) = @_;
1.566     albertel 14532:     my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
                   14533:     my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
                   14534:     my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
                   14535:     my $clonemsg;
                   14536:     my $can_clone = 0;
1.944     raeburn  14537:     my $lctype = lc($args->{'crstype'});
1.908     raeburn  14538:     if ($lctype ne 'community') {
                   14539:         $lctype = 'course';
                   14540:     }
1.566     albertel 14541:     if ($clonehome eq 'no_host') {
1.944     raeburn  14542:         if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  14543:             $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'});
                   14544:         } else {
                   14545:             $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'});
                   14546:         }     
1.566     albertel 14547:     } else {
                   14548: 	my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944     raeburn  14549:         if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  14550:             if ($clonedesc{'type'} ne 'Community') {
                   14551:                  $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'});
                   14552:                 return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   14553:             }
                   14554:         }
1.882     raeburn  14555: 	if (($env{'request.role.domain'} eq $args->{'clonedomain'}) && 
                   14556:             (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566     albertel 14557: 	    $can_clone = 1;
                   14558: 	} else {
1.1075.2.95  raeburn  14559: 	    my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566     albertel 14560: 						 $args->{'clonedomain'},$args->{'clonecourse'});
1.1075.2.95  raeburn  14561:             if ($clonehash{'cloners'} eq '') {
                   14562:                 my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
                   14563:                 if ($domdefs{'canclone'}) {
                   14564:                     unless ($domdefs{'canclone'} eq 'none') {
                   14565:                         if ($domdefs{'canclone'} eq 'domain') {
                   14566:                             if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
                   14567:                                 $can_clone = 1;
                   14568:                             }
                   14569:                         } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
                   14570:                                  ($args->{'clonedomain'} eq  $args->{'course_domain'})) {
                   14571:                             if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
                   14572:                                                                           $clonehash{'internal.coursecode'},$args->{'crscode'})) {
                   14573:                                 $can_clone = 1;
                   14574:                             }
                   14575:                         }
                   14576:                     }
1.908     raeburn  14577:                 }
1.1075.2.95  raeburn  14578:             } else {
                   14579: 	        my @cloners = split(/,/,$clonehash{'cloners'});
                   14580:                 if (grep(/^\*$/,@cloners)) {
1.942     raeburn  14581:                     $can_clone = 1;
1.1075.2.95  raeburn  14582:                 } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942     raeburn  14583:                     $can_clone = 1;
1.1075.2.96  raeburn  14584:                 } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
                   14585:                     $can_clone = 1;
1.1075.2.95  raeburn  14586:                 }
                   14587:                 unless ($can_clone) {
1.1075.2.96  raeburn  14588:                     if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
                   14589:                         ($args->{'clonedomain'} eq  $args->{'course_domain'})) {
1.1075.2.95  raeburn  14590:                         my (%gotdomdefaults,%gotcodedefaults);
                   14591:                         foreach my $cloner (@cloners) {
                   14592:                             if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
                   14593:                                 ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
                   14594:                                 my (%codedefaults,@code_order);
                   14595:                                 if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
                   14596:                                     if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
                   14597:                                         %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
                   14598:                                     }
                   14599:                                     if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
                   14600:                                         @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
                   14601:                                     }
                   14602:                                 } else {
                   14603:                                     &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
                   14604:                                                                             \%codedefaults,
                   14605:                                                                             \@code_order);
                   14606:                                     $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
                   14607:                                     $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
                   14608:                                 }
                   14609:                                 if (@code_order > 0) {
                   14610:                                     if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
                   14611:                                                                                 $cloner,$clonehash{'internal.coursecode'},
                   14612:                                                                                 $args->{'crscode'})) {
                   14613:                                         $can_clone = 1;
                   14614:                                         last;
                   14615:                                     }
                   14616:                                 }
                   14617:                             }
                   14618:                         }
                   14619:                     }
1.1075.2.96  raeburn  14620:                 }
                   14621:             }
                   14622:             unless ($can_clone) {
                   14623:                 my $ccrole = 'cc';
                   14624:                 if ($args->{'crstype'} eq 'Community') {
                   14625:                     $ccrole = 'co';
                   14626:                 }
                   14627:                 my %roleshash =
                   14628:                     &Apache::lonnet::get_my_roles($args->{'ccuname'},
                   14629:                                                   $args->{'ccdomain'},
                   14630:                                                   'userroles',['active'],[$ccrole],
                   14631:                                                   [$args->{'clonedomain'}]);
                   14632:                 if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
                   14633:                     $can_clone = 1;
                   14634:                 } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
                   14635:                                                           $args->{'ccuname'},$args->{'ccdomain'})) {
                   14636:                     $can_clone = 1;
1.1075.2.95  raeburn  14637:                 }
                   14638:             }
                   14639:             unless ($can_clone) {
                   14640:                 if ($args->{'crstype'} eq 'Community') {
                   14641:                     $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'});
                   14642:                 } else {
                   14643:                     $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'});
1.578     raeburn  14644: 	        }
1.566     albertel 14645: 	    }
1.578     raeburn  14646:         }
1.566     albertel 14647:     }
                   14648:     return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   14649: }
                   14650: 
1.444     albertel 14651: sub construct_course {
1.1075.2.59  raeburn  14652:     my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category,$coderef) = @_;
1.444     albertel 14653:     my $outcome;
1.541     raeburn  14654:     my $linefeed =  '<br />'."\n";
                   14655:     if ($context eq 'auto') {
                   14656:         $linefeed = "\n";
                   14657:     }
1.566     albertel 14658: 
                   14659: #
                   14660: # Are we cloning?
                   14661: #
                   14662:     my ($can_clone, $clonemsg, $cloneid, $clonehome);
                   14663:     if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578     raeburn  14664: 	($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566     albertel 14665: 	if ($context ne 'auto') {
1.578     raeburn  14666:             if ($clonemsg ne '') {
                   14667: 	        $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
                   14668:             }
1.566     albertel 14669: 	}
                   14670: 	$outcome .= $clonemsg.$linefeed;
                   14671: 
                   14672:         if (!$can_clone) {
                   14673: 	    return (0,$outcome);
                   14674: 	}
                   14675:     }
                   14676: 
1.444     albertel 14677: #
                   14678: # Open course
                   14679: #
                   14680:     my $crstype = lc($args->{'crstype'});
                   14681:     my %cenv=();
                   14682:     $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
                   14683:                                              $args->{'cdescr'},
                   14684:                                              $args->{'curl'},
                   14685:                                              $args->{'course_home'},
                   14686:                                              $args->{'nonstandard'},
                   14687:                                              $args->{'crscode'},
                   14688:                                              $args->{'ccuname'}.':'.
                   14689:                                              $args->{'ccdomain'},
1.882     raeburn  14690:                                              $args->{'crstype'},
1.885     raeburn  14691:                                              $cnum,$context,$category);
1.444     albertel 14692: 
                   14693:     # Note: The testing routines depend on this being output; see 
                   14694:     # Utils::Course. This needs to at least be output as a comment
                   14695:     # if anyone ever decides to not show this, and Utils::Course::new
                   14696:     # will need to be suitably modified.
1.541     raeburn  14697:     $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943     raeburn  14698:     if ($$courseid =~ /^error:/) {
                   14699:         return (0,$outcome);
                   14700:     }
                   14701: 
1.444     albertel 14702: #
                   14703: # Check if created correctly
                   14704: #
1.479     albertel 14705:     ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444     albertel 14706:     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943     raeburn  14707:     if ($crsuhome eq 'no_host') {
                   14708:         $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
                   14709:         return (0,$outcome);
                   14710:     }
1.541     raeburn  14711:     $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566     albertel 14712: 
1.444     albertel 14713: #
1.566     albertel 14714: # Do the cloning
                   14715: #   
                   14716:     if ($can_clone && $cloneid) {
                   14717: 	$clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
                   14718: 	if ($context ne 'auto') {
                   14719: 	    $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
                   14720: 	}
                   14721: 	$outcome .= $clonemsg.$linefeed;
                   14722: 	my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444     albertel 14723: # Copy all files
1.637     www      14724: 	&Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444     albertel 14725: # Restore URL
1.566     albertel 14726: 	$cenv{'url'}=$oldcenv{'url'};
1.444     albertel 14727: # Restore title
1.566     albertel 14728: 	$cenv{'description'}=$oldcenv{'description'};
1.955     raeburn  14729: # Restore creation date, creator and creation context.
                   14730:         $cenv{'internal.created'}=$oldcenv{'internal.created'};
                   14731:         $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
                   14732:         $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444     albertel 14733: # Mark as cloned
1.566     albertel 14734: 	$cenv{'clonedfrom'}=$cloneid;
1.638     www      14735: # Need to clone grading mode
                   14736:         my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
                   14737:         $cenv{'grading'}=$newenv{'grading'};
                   14738: # Do not clone these environment entries
                   14739:         &Apache::lonnet::del('environment',
                   14740:                   ['default_enrollment_start_date',
                   14741:                    'default_enrollment_end_date',
                   14742:                    'question.email',
                   14743:                    'policy.email',
                   14744:                    'comment.email',
                   14745:                    'pch.users.denied',
1.725     raeburn  14746:                    'plc.users.denied',
                   14747:                    'hidefromcat',
1.1075.2.36  raeburn  14748:                    'checkforpriv',
1.1075.2.59  raeburn  14749:                    'categories',
                   14750:                    'internal.uniquecode'],
1.638     www      14751:                    $$crsudom,$$crsunum);
1.1075.2.63  raeburn  14752:         if ($args->{'textbook'}) {
                   14753:             $cenv{'internal.textbook'} = $args->{'textbook'};
                   14754:         }
1.444     albertel 14755:     }
1.566     albertel 14756: 
1.444     albertel 14757: #
                   14758: # Set environment (will override cloned, if existing)
                   14759: #
                   14760:     my @sections = ();
                   14761:     my @xlists = ();
                   14762:     if ($args->{'crstype'}) {
                   14763:         $cenv{'type'}=$args->{'crstype'};
                   14764:     }
                   14765:     if ($args->{'crsid'}) {
                   14766:         $cenv{'courseid'}=$args->{'crsid'};
                   14767:     }
                   14768:     if ($args->{'crscode'}) {
                   14769:         $cenv{'internal.coursecode'}=$args->{'crscode'};
                   14770:     }
                   14771:     if ($args->{'crsquota'} ne '') {
                   14772:         $cenv{'internal.coursequota'}=$args->{'crsquota'};
                   14773:     } else {
                   14774:         $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
                   14775:     }
                   14776:     if ($args->{'ccuname'}) {
                   14777:         $cenv{'internal.courseowner'} = $args->{'ccuname'}.
                   14778:                                         ':'.$args->{'ccdomain'};
                   14779:     } else {
                   14780:         $cenv{'internal.courseowner'} = $args->{'curruser'};
                   14781:     }
1.1075.2.31  raeburn  14782:     if ($args->{'defaultcredits'}) {
                   14783:         $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
                   14784:     }
1.444     albertel 14785:     my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
                   14786:     if ($args->{'crssections'}) {
                   14787:         $cenv{'internal.sectionnums'} = '';
                   14788:         if ($args->{'crssections'} =~ m/,/) {
                   14789:             @sections = split/,/,$args->{'crssections'};
                   14790:         } else {
                   14791:             $sections[0] = $args->{'crssections'};
                   14792:         }
                   14793:         if (@sections > 0) {
                   14794:             foreach my $item (@sections) {
                   14795:                 my ($sec,$gp) = split/:/,$item;
                   14796:                 my $class = $args->{'crscode'}.$sec;
                   14797:                 my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
                   14798:                 $cenv{'internal.sectionnums'} .= $item.',';
                   14799:                 unless ($addcheck eq 'ok') {
                   14800:                     push @badclasses, $class;
                   14801:                 }
                   14802:             }
                   14803:             $cenv{'internal.sectionnums'} =~ s/,$//;
                   14804:         }
                   14805:     }
                   14806: # do not hide course coordinator from staff listing, 
                   14807: # even if privileged
                   14808:     $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36  raeburn  14809: # add course coordinator's domain to domains to check for privileged users
                   14810: # if different to course domain
                   14811:     if ($$crsudom ne $args->{'ccdomain'}) {
                   14812:         $cenv{'checkforpriv'} = $args->{'ccdomain'};
                   14813:     }
1.444     albertel 14814: # add crosslistings
                   14815:     if ($args->{'crsxlist'}) {
                   14816:         $cenv{'internal.crosslistings'}='';
                   14817:         if ($args->{'crsxlist'} =~ m/,/) {
                   14818:             @xlists = split/,/,$args->{'crsxlist'};
                   14819:         } else {
                   14820:             $xlists[0] = $args->{'crsxlist'};
                   14821:         }
                   14822:         if (@xlists > 0) {
                   14823:             foreach my $item (@xlists) {
                   14824:                 my ($xl,$gp) = split/:/,$item;
                   14825:                 my $addcheck =  &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
                   14826:                 $cenv{'internal.crosslistings'} .= $item.',';
                   14827:                 unless ($addcheck eq 'ok') {
                   14828:                     push @badclasses, $xl;
                   14829:                 }
                   14830:             }
                   14831:             $cenv{'internal.crosslistings'} =~ s/,$//;
                   14832:         }
                   14833:     }
                   14834:     if ($args->{'autoadds'}) {
                   14835:         $cenv{'internal.autoadds'}=$args->{'autoadds'};
                   14836:     }
                   14837:     if ($args->{'autodrops'}) {
                   14838:         $cenv{'internal.autodrops'}=$args->{'autodrops'};
                   14839:     }
                   14840: # check for notification of enrollment changes
                   14841:     my @notified = ();
                   14842:     if ($args->{'notify_owner'}) {
                   14843:         if ($args->{'ccuname'} ne '') {
                   14844:             push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
                   14845:         }
                   14846:     }
                   14847:     if ($args->{'notify_dc'}) {
                   14848:         if ($uname ne '') { 
1.630     raeburn  14849:             push(@notified,$uname.':'.$udom);
1.444     albertel 14850:         }
                   14851:     }
                   14852:     if (@notified > 0) {
                   14853:         my $notifylist;
                   14854:         if (@notified > 1) {
                   14855:             $notifylist = join(',',@notified);
                   14856:         } else {
                   14857:             $notifylist = $notified[0];
                   14858:         }
                   14859:         $cenv{'internal.notifylist'} = $notifylist;
                   14860:     }
                   14861:     if (@badclasses > 0) {
                   14862:         my %lt=&Apache::lonlocal::texthash(
                   14863:                 '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',
                   14864:                 'dnhr' => 'does not have rights to access enrollment in these classes',
                   14865:                 'adby' => 'as determined by the policies of your institution on access to official classlists'
                   14866:         );
1.541     raeburn  14867:         my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
                   14868:                            ' ('.$lt{'adby'}.')';
                   14869:         if ($context eq 'auto') {
                   14870:             $outcome .= $badclass_msg.$linefeed;
1.566     albertel 14871:             $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541     raeburn  14872:             foreach my $item (@badclasses) {
                   14873:                 if ($context eq 'auto') {
                   14874:                     $outcome .= " - $item\n";
                   14875:                 } else {
                   14876:                     $outcome .= "<li>$item</li>\n";
                   14877:                 }
                   14878:             }
                   14879:             if ($context eq 'auto') {
                   14880:                 $outcome .= $linefeed;
                   14881:             } else {
1.566     albertel 14882:                 $outcome .= "</ul><br /><br /></div>\n";
1.541     raeburn  14883:             }
                   14884:         } 
1.444     albertel 14885:     }
                   14886:     if ($args->{'no_end_date'}) {
                   14887:         $args->{'endaccess'} = 0;
                   14888:     }
                   14889:     $cenv{'internal.autostart'}=$args->{'enrollstart'};
                   14890:     $cenv{'internal.autoend'}=$args->{'enrollend'};
                   14891:     $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
                   14892:     $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
                   14893:     if ($args->{'showphotos'}) {
                   14894:       $cenv{'internal.showphotos'}=$args->{'showphotos'};
                   14895:     }
                   14896:     $cenv{'internal.authtype'} = $args->{'authtype'};
                   14897:     $cenv{'internal.autharg'} = $args->{'autharg'}; 
                   14898:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
                   14899:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
1.541     raeburn  14900:             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'); 
                   14901:             if ($context eq 'auto') {
                   14902:                 $outcome .= $krb_msg;
                   14903:             } else {
1.566     albertel 14904:                 $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541     raeburn  14905:             }
                   14906:             $outcome .= $linefeed;
1.444     albertel 14907:         }
                   14908:     }
                   14909:     if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
                   14910:        if ($args->{'setpolicy'}) {
                   14911:            $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   14912:        }
                   14913:        if ($args->{'setcontent'}) {
                   14914:            $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   14915:        }
1.1075.2.110  raeburn  14916:        if ($args->{'setcomment'}) {
                   14917:            $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   14918:        }
1.444     albertel 14919:     }
                   14920:     if ($args->{'reshome'}) {
                   14921: 	$cenv{'reshome'}=$args->{'reshome'}.'/';
                   14922: 	$cenv{'reshome'}=~s/\/+$/\//;
                   14923:     }
                   14924: #
                   14925: # course has keyed access
                   14926: #
                   14927:     if ($args->{'setkeys'}) {
                   14928:        $cenv{'keyaccess'}='yes';
                   14929:     }
                   14930: # if specified, key authority is not course, but user
                   14931: # only active if keyaccess is yes
                   14932:     if ($args->{'keyauth'}) {
1.487     albertel 14933: 	my ($user,$domain) = split(':',$args->{'keyauth'});
                   14934: 	$user = &LONCAPA::clean_username($user);
                   14935: 	$domain = &LONCAPA::clean_username($domain);
1.488     foxr     14936: 	if ($user ne '' && $domain ne '') {
1.487     albertel 14937: 	    $cenv{'keyauth'}=$user.':'.$domain;
1.444     albertel 14938: 	}
                   14939:     }
                   14940: 
1.1075.2.59  raeburn  14941: #
                   14942: #  generate and store uniquecode (available to course requester), if course should have one.
                   14943: #
                   14944:     if ($args->{'uniquecode'}) {
                   14945:         my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
                   14946:         if ($code) {
                   14947:             $cenv{'internal.uniquecode'} = $code;
                   14948:             my %crsinfo =
                   14949:                 &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
                   14950:             if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
                   14951:                 $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
                   14952:                 my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
                   14953:             }
                   14954:             if (ref($coderef)) {
                   14955:                 $$coderef = $code;
                   14956:             }
                   14957:         }
                   14958:     }
                   14959: 
1.444     albertel 14960:     if ($args->{'disresdis'}) {
                   14961:         $cenv{'pch.roles.denied'}='st';
                   14962:     }
                   14963:     if ($args->{'disablechat'}) {
                   14964:         $cenv{'plc.roles.denied'}='st';
                   14965:     }
                   14966: 
                   14967:     # Record we've not yet viewed the Course Initialization Helper for this 
                   14968:     # course
                   14969:     $cenv{'course.helper.not.run'} = 1;
                   14970:     #
                   14971:     # Use new Randomseed
                   14972:     #
                   14973:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
                   14974:     $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
                   14975:     #
                   14976:     # The encryption code and receipt prefix for this course
                   14977:     #
                   14978:     $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
                   14979:     $cenv{'internal.encpref'}=100+int(9*rand(99));
                   14980:     #
                   14981:     # By default, use standard grading
                   14982:     if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
                   14983: 
1.541     raeburn  14984:     $outcome .= $linefeed.&mt('Setting environment').': '.                 
                   14985:           &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 14986: #
                   14987: # Open all assignments
                   14988: #
                   14989:     if ($args->{'openall'}) {
                   14990:        my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
                   14991:        my %storecontent = ($storeunder         => time,
                   14992:                            $storeunder.'.type' => 'date_start');
                   14993:        
                   14994:        $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541     raeburn  14995:                  ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 14996:    }
                   14997: #
                   14998: # Set first page
                   14999: #
                   15000:     unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
                   15001: 	    || ($cloneid)) {
1.445     albertel 15002: 	use LONCAPA::map;
1.444     albertel 15003: 	$outcome .= &mt('Setting first resource').': ';
1.445     albertel 15004: 
                   15005: 	my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
                   15006:         my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
                   15007: 
1.444     albertel 15008:         $outcome .= ($fatal?$errtext:'read ok').' - ';
                   15009:         my $title; my $url;
                   15010:         if ($args->{'firstres'} eq 'syl') {
1.690     bisitz   15011: 	    $title=&mt('Syllabus');
1.444     albertel 15012:             $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
                   15013:         } else {
1.963     raeburn  15014:             $title=&mt('Table of Contents');
1.444     albertel 15015:             $url='/adm/navmaps';
                   15016:         }
1.445     albertel 15017: 
                   15018:         $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
                   15019: 	(my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
                   15020: 
                   15021: 	if ($errtext) { $fatal=2; }
1.541     raeburn  15022:         $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444     albertel 15023:     }
1.566     albertel 15024: 
                   15025:     return (1,$outcome);
1.444     albertel 15026: }
                   15027: 
1.1075.2.59  raeburn  15028: sub make_unique_code {
                   15029:     my ($cdom,$cnum) = @_;
                   15030:     # get lock on uniquecodes db
                   15031:     my $lockhash = {
                   15032:                       $cnum."\0".'uniquecodes' => $env{'user.name'}.
                   15033:                                                   ':'.$env{'user.domain'},
                   15034:                    };
                   15035:     my $tries = 0;
                   15036:     my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
                   15037:     my ($code,$error);
                   15038: 
                   15039:     while (($gotlock ne 'ok') && ($tries<3)) {
                   15040:         $tries ++;
                   15041:         sleep 1;
                   15042:         $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
                   15043:     }
                   15044:     if ($gotlock eq 'ok') {
                   15045:         my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
                   15046:         my $gotcode;
                   15047:         my $attempts = 0;
                   15048:         while ((!$gotcode) && ($attempts < 100)) {
                   15049:             $code = &generate_code();
                   15050:             if (!exists($currcodes{$code})) {
                   15051:                 $gotcode = 1;
                   15052:                 unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
                   15053:                     $error = 'nostore';
                   15054:                 }
                   15055:             }
                   15056:             $attempts ++;
                   15057:         }
                   15058:         my @del_lock = ($cnum."\0".'uniquecodes');
                   15059:         my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
                   15060:     } else {
                   15061:         $error = 'nolock';
                   15062:     }
                   15063:     return ($code,$error);
                   15064: }
                   15065: 
                   15066: sub generate_code {
                   15067:     my $code;
                   15068:     my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
                   15069:     for (my $i=0; $i<6; $i++) {
                   15070:         my $lettnum = int (rand 2);
                   15071:         my $item = '';
                   15072:         if ($lettnum) {
                   15073:             $item = $letts[int( rand(18) )];
                   15074:         } else {
                   15075:             $item = 1+int( rand(8) );
                   15076:         }
                   15077:         $code .= $item;
                   15078:     }
                   15079:     return $code;
                   15080: }
                   15081: 
1.444     albertel 15082: ############################################################
                   15083: ############################################################
                   15084: 
1.953     droeschl 15085: #SD
                   15086: # only Community and Course, or anything else?
1.378     raeburn  15087: sub course_type {
                   15088:     my ($cid) = @_;
                   15089:     if (!defined($cid)) {
                   15090:         $cid = $env{'request.course.id'};
                   15091:     }
1.404     albertel 15092:     if (defined($env{'course.'.$cid.'.type'})) {
                   15093:         return $env{'course.'.$cid.'.type'};
1.378     raeburn  15094:     } else {
                   15095:         return 'Course';
1.377     raeburn  15096:     }
                   15097: }
1.156     albertel 15098: 
1.406     raeburn  15099: sub group_term {
                   15100:     my $crstype = &course_type();
                   15101:     my %names = (
                   15102:                   'Course' => 'group',
1.865     raeburn  15103:                   'Community' => 'group',
1.406     raeburn  15104:                 );
                   15105:     return $names{$crstype};
                   15106: }
                   15107: 
1.902     raeburn  15108: sub course_types {
1.1075.2.59  raeburn  15109:     my @types = ('official','unofficial','community','textbook');
1.902     raeburn  15110:     my %typename = (
                   15111:                          official   => 'Official course',
                   15112:                          unofficial => 'Unofficial course',
                   15113:                          community  => 'Community',
1.1075.2.59  raeburn  15114:                          textbook   => 'Textbook course',
1.902     raeburn  15115:                    );
                   15116:     return (\@types,\%typename);
                   15117: }
                   15118: 
1.156     albertel 15119: sub icon {
                   15120:     my ($file)=@_;
1.505     albertel 15121:     my $curfext = lc((split(/\./,$file))[-1]);
1.168     albertel 15122:     my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156     albertel 15123:     my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168     albertel 15124:     if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
                   15125: 	if (-e  $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
                   15126: 	          $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   15127: 	            $curfext.".gif") {
                   15128: 	    $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   15129: 		$curfext.".gif";
                   15130: 	}
                   15131:     }
1.249     albertel 15132:     return &lonhttpdurl($iconname);
1.154     albertel 15133: } 
1.84      albertel 15134: 
1.575     albertel 15135: sub lonhttpdurl {
1.692     www      15136: #
                   15137: # Had been used for "small fry" static images on separate port 8080.
                   15138: # Modify here if lightweight http functionality desired again.
                   15139: # Currently eliminated due to increasing firewall issues.
                   15140: #
1.575     albertel 15141:     my ($url)=@_;
1.692     www      15142:     return $url;
1.215     albertel 15143: }
                   15144: 
1.213     albertel 15145: sub connection_aborted {
                   15146:     my ($r)=@_;
                   15147:     $r->print(" ");$r->rflush();
                   15148:     my $c = $r->connection;
                   15149:     return $c->aborted();
                   15150: }
                   15151: 
1.221     foxr     15152: #    Escapes strings that may have embedded 's that will be put into
1.222     foxr     15153: #    strings as 'strings'.
                   15154: sub escape_single {
1.221     foxr     15155:     my ($input) = @_;
1.223     albertel 15156:     $input =~ s/\\/\\\\/g;	# Escape the \'s..(must be first)>
1.221     foxr     15157:     $input =~ s/\'/\\\'/g;	# Esacpe the 's....
                   15158:     return $input;
                   15159: }
1.223     albertel 15160: 
1.222     foxr     15161: #  Same as escape_single, but escape's "'s  This 
                   15162: #  can be used for  "strings"
                   15163: sub escape_double {
                   15164:     my ($input) = @_;
                   15165:     $input =~ s/\\/\\\\/g;	# Escape the /'s..(must be first)>
                   15166:     $input =~ s/\"/\\\"/g;	# Esacpe the "s....
                   15167:     return $input;
                   15168: }
1.223     albertel 15169:  
1.222     foxr     15170: #   Escapes the last element of a full URL.
                   15171: sub escape_url {
                   15172:     my ($url)   = @_;
1.238     raeburn  15173:     my @urlslices = split(/\//, $url,-1);
1.369     www      15174:     my $lastitem = &escape(pop(@urlslices));
1.1075.2.83  raeburn  15175:     return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222     foxr     15176: }
1.462     albertel 15177: 
1.820     raeburn  15178: sub compare_arrays {
                   15179:     my ($arrayref1,$arrayref2) = @_;
                   15180:     my (@difference,%count);
                   15181:     @difference = ();
                   15182:     %count = ();
                   15183:     if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
                   15184:         foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
                   15185:         foreach my $element (keys(%count)) {
                   15186:             if ($count{$element} == 1) {
                   15187:                 push(@difference,$element);
                   15188:             }
                   15189:         }
                   15190:     }
                   15191:     return @difference;
                   15192: }
                   15193: 
1.817     bisitz   15194: # -------------------------------------------------------- Initialize user login
1.462     albertel 15195: sub init_user_environment {
1.463     albertel 15196:     my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462     albertel 15197:     my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
                   15198: 
                   15199:     my $public=($username eq 'public' && $domain eq 'public');
                   15200: 
                   15201: # See if old ID present, if so, remove
                   15202: 
1.1062    raeburn  15203:     my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462     albertel 15204:     my $now=time;
                   15205: 
                   15206:     if ($public) {
                   15207: 	my $max_public=100;
                   15208: 	my $oldest;
                   15209: 	my $oldest_time=0;
                   15210: 	for(my $next=1;$next<=$max_public;$next++) {
                   15211: 	    if (-e $lonids."/publicuser_$next.id") {
                   15212: 		my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
                   15213: 		if ($mtime<$oldest_time || !$oldest_time) {
                   15214: 		    $oldest_time=$mtime;
                   15215: 		    $oldest=$next;
                   15216: 		}
                   15217: 	    } else {
                   15218: 		$cookie="publicuser_$next";
                   15219: 		last;
                   15220: 	    }
                   15221: 	}
                   15222: 	if (!$cookie) { $cookie="publicuser_$oldest"; }
                   15223:     } else {
1.463     albertel 15224: 	# if this isn't a robot, kill any existing non-robot sessions
                   15225: 	if (!$args->{'robot'}) {
                   15226: 	    opendir(DIR,$lonids);
                   15227: 	    while ($filename=readdir(DIR)) {
                   15228: 		if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
                   15229: 		    unlink($lonids.'/'.$filename);
                   15230: 		}
1.462     albertel 15231: 	    }
1.463     albertel 15232: 	    closedir(DIR);
1.1075.2.84  raeburn  15233: # If there is a undeleted lockfile for the user's paste buffer remove it.
                   15234:             my $namespace = 'nohist_courseeditor';
                   15235:             my $lockingkey = 'paste'."\0".'locked_num';
                   15236:             my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
                   15237:                                                 $domain,$username);
                   15238:             if (exists($lockhash{$lockingkey})) {
                   15239:                 my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
                   15240:                 unless ($delresult eq 'ok') {
                   15241:                     &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
                   15242:                 }
                   15243:             }
1.462     albertel 15244: 	}
                   15245: # Give them a new cookie
1.463     albertel 15246: 	my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684     www      15247: 		                   : $now.$$.int(rand(10000)));
1.463     albertel 15248: 	$cookie="$username\_$id\_$domain\_$authhost";
1.462     albertel 15249:     
                   15250: # Initialize roles
                   15251: 
1.1062    raeburn  15252: 	($userroles,$firstaccenv,$timerintenv) = 
                   15253:             &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462     albertel 15254:     }
                   15255: # ------------------------------------ Check browser type and MathML capability
                   15256: 
1.1075.2.77  raeburn  15257:     my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
                   15258:         $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462     albertel 15259: 
                   15260: # ------------------------------------------------------------- Get environment
                   15261: 
                   15262:     my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
                   15263:     my ($tmp) = keys(%userenv);
                   15264:     if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   15265:     } else {
                   15266: 	undef(%userenv);
                   15267:     }
                   15268:     if (($userenv{'interface'}) && (!$form->{'interface'})) {
                   15269: 	$form->{'interface'}=$userenv{'interface'};
                   15270:     }
                   15271:     if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
                   15272: 
                   15273: # --------------- Do not trust query string to be put directly into environment
1.817     bisitz   15274:     foreach my $option ('interface','localpath','localres') {
                   15275:         $form->{$option}=~s/[\n\r\=]//gs;
1.462     albertel 15276:     }
                   15277: # --------------------------------------------------------- Write first profile
                   15278: 
                   15279:     {
                   15280: 	my %initial_env = 
                   15281: 	    ("user.name"          => $username,
                   15282: 	     "user.domain"        => $domain,
                   15283: 	     "user.home"          => $authhost,
                   15284: 	     "browser.type"       => $clientbrowser,
                   15285: 	     "browser.version"    => $clientversion,
                   15286: 	     "browser.mathml"     => $clientmathml,
                   15287: 	     "browser.unicode"    => $clientunicode,
                   15288: 	     "browser.os"         => $clientos,
1.1075.2.42  raeburn  15289:              "browser.mobile"     => $clientmobile,
                   15290:              "browser.info"       => $clientinfo,
1.1075.2.77  raeburn  15291:              "browser.osversion"  => $clientosversion,
1.462     albertel 15292: 	     "server.domain"      => $Apache::lonnet::perlvar{'lonDefDomain'},
                   15293: 	     "request.course.fn"  => '',
                   15294: 	     "request.course.uri" => '',
                   15295: 	     "request.course.sec" => '',
                   15296: 	     "request.role"       => 'cm',
                   15297: 	     "request.role.adv"   => $env{'user.adv'},
                   15298: 	     "request.host"       => $ENV{'REMOTE_ADDR'},);
                   15299: 
                   15300:         if ($form->{'localpath'}) {
                   15301: 	    $initial_env{"browser.localpath"}  = $form->{'localpath'};
                   15302: 	    $initial_env{"browser.localres"}   = $form->{'localres'};
                   15303:         }
                   15304: 	
                   15305: 	if ($form->{'interface'}) {
                   15306: 	    $form->{'interface'}=~s/\W//gs;
                   15307: 	    $initial_env{"browser.interface"} = $form->{'interface'};
                   15308: 	    $env{'browser.interface'}=$form->{'interface'};
                   15309: 	}
                   15310: 
1.1075.2.54  raeburn  15311:         if ($form->{'iptoken'}) {
                   15312:             my $lonhost = $r->dir_config('lonHostID');
                   15313:             $initial_env{"user.noloadbalance"} = $lonhost;
                   15314:             $env{'user.noloadbalance'} = $lonhost;
                   15315:         }
                   15316: 
1.981     raeburn  15317:         my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016    raeburn  15318:         my %domdef;
                   15319:         unless ($domain eq 'public') {
                   15320:             %domdef = &Apache::lonnet::get_domain_defaults($domain);
                   15321:         }
1.980     raeburn  15322: 
1.1075.2.7  raeburn  15323:         foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724     raeburn  15324:             $userenv{'availabletools.'.$tool} = 
1.980     raeburn  15325:                 &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
                   15326:                                                   undef,\%userenv,\%domdef,\%is_adv);
1.724     raeburn  15327:         }
                   15328: 
1.1075.2.59  raeburn  15329:         foreach my $crstype ('official','unofficial','community','textbook') {
1.765     raeburn  15330:             $userenv{'canrequest.'.$crstype} =
                   15331:                 &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980     raeburn  15332:                                                   'reload','requestcourses',
                   15333:                                                   \%userenv,\%domdef,\%is_adv);
1.765     raeburn  15334:         }
                   15335: 
1.1075.2.14  raeburn  15336:         $userenv{'canrequest.author'} =
                   15337:             &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
                   15338:                                         'reload','requestauthor',
                   15339:                                         \%userenv,\%domdef,\%is_adv);
                   15340:         my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
                   15341:                                              $domain,$username);
                   15342:         my $reqstatus = $reqauthor{'author_status'};
                   15343:         if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
                   15344:             if (ref($reqauthor{'author'}) eq 'HASH') {
                   15345:                 $userenv{'requestauthorqueued'} = $reqstatus.':'.
                   15346:                                                   $reqauthor{'author'}{'timestamp'};
                   15347:             }
                   15348:         }
                   15349: 
1.462     albertel 15350: 	$env{'user.environment'} = "$lonids/$cookie.id";
1.1062    raeburn  15351: 
1.462     albertel 15352: 	if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
                   15353: 		 &GDBM_WRCREAT(),0640)) {
                   15354: 	    &_add_to_env(\%disk_env,\%initial_env);
                   15355: 	    &_add_to_env(\%disk_env,\%userenv,'environment.');
                   15356: 	    &_add_to_env(\%disk_env,$userroles);
1.1062    raeburn  15357:             if (ref($firstaccenv) eq 'HASH') {
                   15358:                 &_add_to_env(\%disk_env,$firstaccenv);
                   15359:             }
                   15360:             if (ref($timerintenv) eq 'HASH') {
                   15361:                 &_add_to_env(\%disk_env,$timerintenv);
                   15362:             }
1.463     albertel 15363: 	    if (ref($args->{'extra_env'})) {
                   15364: 		&_add_to_env(\%disk_env,$args->{'extra_env'});
                   15365: 	    }
1.462     albertel 15366: 	    untie(%disk_env);
                   15367: 	} else {
1.705     tempelho 15368: 	    &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
                   15369: 			   'Could not create environment storage in lonauth: '.$!.'</span>');
1.462     albertel 15370: 	    return 'error: '.$!;
                   15371: 	}
                   15372:     }
                   15373:     $env{'request.role'}='cm';
                   15374:     $env{'request.role.adv'}=$env{'user.adv'};
                   15375:     $env{'browser.type'}=$clientbrowser;
                   15376: 
                   15377:     return $cookie;
                   15378: 
                   15379: }
                   15380: 
                   15381: sub _add_to_env {
                   15382:     my ($idf,$env_data,$prefix) = @_;
1.676     raeburn  15383:     if (ref($env_data) eq 'HASH') {
                   15384:         while (my ($key,$value) = each(%$env_data)) {
                   15385: 	    $idf->{$prefix.$key} = $value;
                   15386: 	    $env{$prefix.$key}   = $value;
                   15387:         }
1.462     albertel 15388:     }
                   15389: }
                   15390: 
1.685     tempelho 15391: # --- Get the symbolic name of a problem and the url
                   15392: sub get_symb {
                   15393:     my ($request,$silent) = @_;
1.726     raeburn  15394:     (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685     tempelho 15395:     my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
                   15396:     if ($symb eq '') {
                   15397:         if (!$silent) {
1.1071    raeburn  15398:             if (ref($request)) { 
                   15399:                 $request->print("Unable to handle ambiguous references:$url:.");
                   15400:             }
1.685     tempelho 15401:             return ();
                   15402:         }
                   15403:     }
                   15404:     &Apache::lonenc::check_decrypt(\$symb);
                   15405:     return ($symb);
                   15406: }
                   15407: 
                   15408: # --------------------------------------------------------------Get annotation
                   15409: 
                   15410: sub get_annotation {
                   15411:     my ($symb,$enc) = @_;
                   15412: 
                   15413:     my $key = $symb;
                   15414:     if (!$enc) {
                   15415:         $key =
                   15416:             &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
                   15417:     }
                   15418:     my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
                   15419:     return $annotation{$key};
                   15420: }
                   15421: 
                   15422: sub clean_symb {
1.731     raeburn  15423:     my ($symb,$delete_enc) = @_;
1.685     tempelho 15424: 
                   15425:     &Apache::lonenc::check_decrypt(\$symb);
                   15426:     my $enc = $env{'request.enc'};
1.731     raeburn  15427:     if ($delete_enc) {
1.730     raeburn  15428:         delete($env{'request.enc'});
                   15429:     }
1.685     tempelho 15430: 
                   15431:     return ($symb,$enc);
                   15432: }
1.462     albertel 15433: 
1.1075.2.69  raeburn  15434: ############################################################
                   15435: ############################################################
                   15436: 
                   15437: =pod
                   15438: 
                   15439: =head1 Routines for building display used to search for courses
                   15440: 
                   15441: 
                   15442: =over 4
                   15443: 
                   15444: =item * &build_filters()
                   15445: 
                   15446: Create markup for a table used to set filters to use when selecting
                   15447: courses in a domain.  Used by lonpickcourse.pm, lonmodifycourse.pm
                   15448: and quotacheck.pl
                   15449: 
                   15450: 
                   15451: Inputs:
                   15452: 
                   15453: filterlist - anonymous array of fields to include as potential filters
                   15454: 
                   15455: crstype - course type
                   15456: 
                   15457: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
                   15458:               to pop-open a course selector (will contain "extra element").
                   15459: 
                   15460: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
                   15461: 
                   15462: filter - anonymous hash of criteria and their values
                   15463: 
                   15464: action - form action
                   15465: 
                   15466: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
                   15467: 
                   15468: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
                   15469: 
                   15470: cloneruname - username of owner of new course who wants to clone
                   15471: 
                   15472: clonerudom - domain of owner of new course who wants to clone
                   15473: 
                   15474: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
                   15475: 
                   15476: codetitlesref - reference to array of titles of components in institutional codes (official courses)
                   15477: 
                   15478: codedom - domain
                   15479: 
                   15480: formname - value of form element named "form".
                   15481: 
                   15482: fixeddom - domain, if fixed.
                   15483: 
                   15484: prevphase - value to assign to form element named "phase" when going back to the previous screen
                   15485: 
                   15486: cnameelement - name of form element in form on opener page which will receive title of selected course
                   15487: 
                   15488: cnumelement - name of form element in form on opener page which will receive courseID  of selected course
                   15489: 
                   15490: cdomelement - name of form element in form on opener page which will receive domain of selected course
                   15491: 
                   15492: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
                   15493: 
                   15494: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
                   15495: 
                   15496: clonewarning - warning message about missing information for intended course owner when DC creates a course
                   15497: 
                   15498: 
                   15499: Returns: $output - HTML for display of search criteria, and hidden form elements.
                   15500: 
                   15501: 
                   15502: Side Effects: None
                   15503: 
                   15504: =cut
                   15505: 
                   15506: # ---------------------------------------------- search for courses based on last activity etc.
                   15507: 
                   15508: sub build_filters {
                   15509:     my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
                   15510:         $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
                   15511:         $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
                   15512:         $cnameelement,$cnumelement,$cdomelement,$setroles,
                   15513:         $clonetext,$clonewarning) = @_;
                   15514:     my ($list,$jscript);
                   15515:     my $onchange = 'javascript:updateFilters(this)';
                   15516:     my ($domainselectform,$sincefilterform,$createdfilterform,
                   15517:         $ownerdomselectform,$persondomselectform,$instcodeform,
                   15518:         $typeselectform,$instcodetitle);
                   15519:     if ($formname eq '') {
                   15520:         $formname = $caller;
                   15521:     }
                   15522:     foreach my $item (@{$filterlist}) {
                   15523:         unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
                   15524:                 ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
                   15525:             if ($item eq 'domainfilter') {
                   15526:                 $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
                   15527:             } elsif ($item eq 'coursefilter') {
                   15528:                 $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
                   15529:             } elsif ($item eq 'ownerfilter') {
                   15530:                 $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
                   15531:             } elsif ($item eq 'ownerdomfilter') {
                   15532:                 $filter->{'ownerdomfilter'} =
                   15533:                     &LONCAPA::clean_domain($filter->{$item});
                   15534:                 $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
                   15535:                                                        'ownerdomfilter',1);
                   15536:             } elsif ($item eq 'personfilter') {
                   15537:                 $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
                   15538:             } elsif ($item eq 'persondomfilter') {
                   15539:                 $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
                   15540:                                                         'persondomfilter',1);
                   15541:             } else {
                   15542:                 $filter->{$item} =~ s/\W//g;
                   15543:             }
                   15544:             if (!$filter->{$item}) {
                   15545:                 $filter->{$item} = '';
                   15546:             }
                   15547:         }
                   15548:         if ($item eq 'domainfilter') {
                   15549:             my $allow_blank = 1;
                   15550:             if ($formname eq 'portform') {
                   15551:                 $allow_blank=0;
                   15552:             } elsif ($formname eq 'studentform') {
                   15553:                 $allow_blank=0;
                   15554:             }
                   15555:             if ($fixeddom) {
                   15556:                 $domainselectform = '<input type="hidden" name="domainfilter"'.
                   15557:                                     ' value="'.$codedom.'" />'.
                   15558:                                     &Apache::lonnet::domain($codedom,'description');
                   15559:             } else {
                   15560:                 $domainselectform = &select_dom_form($filter->{$item},
                   15561:                                                      'domainfilter',
                   15562:                                                       $allow_blank,'',$onchange);
                   15563:             }
                   15564:         } else {
                   15565:             $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
                   15566:         }
                   15567:     }
                   15568: 
                   15569:     # last course activity filter and selection
                   15570:     $sincefilterform = &timebased_select_form('sincefilter',$filter);
                   15571: 
                   15572:     # course created filter and selection
                   15573:     if (exists($filter->{'createdfilter'})) {
                   15574:         $createdfilterform = &timebased_select_form('createdfilter',$filter);
                   15575:     }
                   15576: 
                   15577:     my %lt = &Apache::lonlocal::texthash(
                   15578:                 'cac' => "$crstype Activity",
                   15579:                 'ccr' => "$crstype Created",
                   15580:                 'cde' => "$crstype Title",
                   15581:                 'cdo' => "$crstype Domain",
                   15582:                 'ins' => 'Institutional Code',
                   15583:                 'inc' => 'Institutional Categorization',
                   15584:                 'cow' => "$crstype Owner/Co-owner",
                   15585:                 'cop' => "$crstype Personnel Includes",
                   15586:                 'cog' => 'Type',
                   15587:              );
                   15588: 
                   15589:     if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
                   15590:         my $typeval = 'Course';
                   15591:         if ($crstype eq 'Community') {
                   15592:             $typeval = 'Community';
                   15593:         }
                   15594:         $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
                   15595:     } else {
                   15596:         $typeselectform =  '<select name="type" size="1"';
                   15597:         if ($onchange) {
                   15598:             $typeselectform .= ' onchange="'.$onchange.'"';
                   15599:         }
                   15600:         $typeselectform .= '>'."\n";
                   15601:         foreach my $posstype ('Course','Community') {
                   15602:             $typeselectform.='<option value="'.$posstype.'"'.
                   15603:                 ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
                   15604:         }
                   15605:         $typeselectform.="</select>";
                   15606:     }
                   15607: 
                   15608:     my ($cloneableonlyform,$cloneabletitle);
                   15609:     if (exists($filter->{'cloneableonly'})) {
                   15610:         my $cloneableon = '';
                   15611:         my $cloneableoff = ' checked="checked"';
                   15612:         if ($filter->{'cloneableonly'}) {
                   15613:             $cloneableon = $cloneableoff;
                   15614:             $cloneableoff = '';
                   15615:         }
                   15616:         $cloneableonlyform = '<span class="LC_nobreak"><label><input type="radio" name="cloneableonly" value="1" '.$cloneableon.'/>&nbsp;'.&mt('Required').'</label>'.('&nbsp;'x3).'<label><input type="radio" name="cloneableonly" value="" '.$cloneableoff.' />&nbsp;'.&mt('No restriction').'</label></span>';
                   15617:         if ($formname eq 'ccrs') {
1.1075.2.71  raeburn  15618:             $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69  raeburn  15619:         } else {
                   15620:             $cloneabletitle = &mt('Cloneable by you');
                   15621:         }
                   15622:     }
                   15623:     my $officialjs;
                   15624:     if ($crstype eq 'Course') {
                   15625:         if (exists($filter->{'instcodefilter'})) {
                   15626: #            if (($fixeddom) || ($formname eq 'requestcrs') ||
                   15627: #                ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
                   15628:             if ($codedom) {
                   15629:                 $officialjs = 1;
                   15630:                 ($instcodeform,$jscript,$$numtitlesref) =
                   15631:                     &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
                   15632:                                                                   $officialjs,$codetitlesref);
                   15633:                 if ($jscript) {
                   15634:                     $jscript = '<script type="text/javascript">'."\n".
                   15635:                                '// <![CDATA['."\n".
                   15636:                                $jscript."\n".
                   15637:                                '// ]]>'."\n".
                   15638:                                '</script>'."\n";
                   15639:                 }
                   15640:             }
                   15641:             if ($instcodeform eq '') {
                   15642:                 $instcodeform =
                   15643:                     '<input type="text" name="instcodefilter" size="10" value="'.
                   15644:                     $list->{'instcodefilter'}.'" />';
                   15645:                 $instcodetitle = $lt{'ins'};
                   15646:             } else {
                   15647:                 $instcodetitle = $lt{'inc'};
                   15648:             }
                   15649:             if ($fixeddom) {
                   15650:                 $instcodetitle .= '<br />('.$codedom.')';
                   15651:             }
                   15652:         }
                   15653:     }
                   15654:     my $output = qq|
                   15655: <form method="post" name="filterpicker" action="$action">
                   15656: <input type="hidden" name="form" value="$formname" />
                   15657: |;
                   15658:     if ($formname eq 'modifycourse') {
                   15659:         $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
                   15660:                    '<input type="hidden" name="prevphase" value="'.
                   15661:                    $prevphase.'" />'."\n";
1.1075.2.82  raeburn  15662:     } elsif ($formname eq 'quotacheck') {
                   15663:         $output .= qq|
                   15664: <input type="hidden" name="sortby" value="" />
                   15665: <input type="hidden" name="sortorder" value="" />
                   15666: |;
                   15667:     } else {
1.1075.2.69  raeburn  15668:         my $name_input;
                   15669:         if ($cnameelement ne '') {
                   15670:             $name_input = '<input type="hidden" name="cnameelement" value="'.
                   15671:                           $cnameelement.'" />';
                   15672:         }
                   15673:         $output .= qq|
                   15674: <input type="hidden" name="cnumelement" value="$cnumelement" />
                   15675: <input type="hidden" name="cdomelement" value="$cdomelement" />
                   15676: $name_input
                   15677: $roleelement
                   15678: $multelement
                   15679: $typeelement
                   15680: |;
                   15681:         if ($formname eq 'portform') {
                   15682:             $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
                   15683:         }
                   15684:     }
                   15685:     if ($fixeddom) {
                   15686:         $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
                   15687:     }
                   15688:     $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
                   15689:     if ($sincefilterform) {
                   15690:         $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
                   15691:                   .$sincefilterform
                   15692:                   .&Apache::lonhtmlcommon::row_closure();
                   15693:     }
                   15694:     if ($createdfilterform) {
                   15695:         $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
                   15696:                   .$createdfilterform
                   15697:                   .&Apache::lonhtmlcommon::row_closure();
                   15698:     }
                   15699:     if ($domainselectform) {
                   15700:         $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
                   15701:                   .$domainselectform
                   15702:                   .&Apache::lonhtmlcommon::row_closure();
                   15703:     }
                   15704:     if ($typeselectform) {
                   15705:         if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
                   15706:             $output .= $typeselectform;
                   15707:         } else {
                   15708:             $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
                   15709:                       .$typeselectform
                   15710:                       .&Apache::lonhtmlcommon::row_closure();
                   15711:         }
                   15712:     }
                   15713:     if ($instcodeform) {
                   15714:         $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
                   15715:                   .$instcodeform
                   15716:                   .&Apache::lonhtmlcommon::row_closure();
                   15717:     }
                   15718:     if (exists($filter->{'ownerfilter'})) {
                   15719:         $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
                   15720:                    '<table><tr><td>'.&mt('Username').'<br />'.
                   15721:                    '<input type="text" name="ownerfilter" size="20" value="'.
                   15722:                    $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
                   15723:                    $ownerdomselectform.'</td></tr></table>'.
                   15724:                    &Apache::lonhtmlcommon::row_closure();
                   15725:     }
                   15726:     if (exists($filter->{'personfilter'})) {
                   15727:         $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
                   15728:                    '<table><tr><td>'.&mt('Username').'<br />'.
                   15729:                    '<input type="text" name="personfilter" size="20" value="'.
                   15730:                    $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
                   15731:                    $persondomselectform.'</td></tr></table>'.
                   15732:                    &Apache::lonhtmlcommon::row_closure();
                   15733:     }
                   15734:     if (exists($filter->{'coursefilter'})) {
                   15735:         $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
                   15736:                   .'<input type="text" name="coursefilter" size="25" value="'
                   15737:                   .$list->{'coursefilter'}.'" />'
                   15738:                   .&Apache::lonhtmlcommon::row_closure();
                   15739:     }
                   15740:     if ($cloneableonlyform) {
                   15741:         $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
                   15742:                    $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
                   15743:     }
                   15744:     if (exists($filter->{'descriptfilter'})) {
                   15745:         $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
                   15746:                   .'<input type="text" name="descriptfilter" size="40" value="'
                   15747:                   .$list->{'descriptfilter'}.'" />'
                   15748:                   .&Apache::lonhtmlcommon::row_closure(1);
                   15749:     }
                   15750:     $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
                   15751:                '<input type="hidden" name="updater" value="" />'."\n".
                   15752:                '<input type="submit" name="gosearch" value="'.
                   15753:                &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
                   15754:     return $jscript.$clonewarning.$output;
                   15755: }
                   15756: 
                   15757: =pod
                   15758: 
                   15759: =item * &timebased_select_form()
                   15760: 
                   15761: Create markup for a dropdown list used to select a time-based
                   15762: filter e.g., Course Activity, Course Created, when searching for courses
                   15763: or communities
                   15764: 
                   15765: Inputs:
                   15766: 
                   15767: item - name of form element (sincefilter or createdfilter)
                   15768: 
                   15769: filter - anonymous hash of criteria and their values
                   15770: 
                   15771: Returns: HTML for a select box contained a blank, then six time selections,
                   15772:          with value set in incoming form variables currently selected.
                   15773: 
                   15774: Side Effects: None
                   15775: 
                   15776: =cut
                   15777: 
                   15778: sub timebased_select_form {
                   15779:     my ($item,$filter) = @_;
                   15780:     if (ref($filter) eq 'HASH') {
                   15781:         $filter->{$item} =~ s/[^\d-]//g;
                   15782:         if (!$filter->{$item}) { $filter->{$item}=-1; }
                   15783:         return &select_form(
                   15784:                             $filter->{$item},
                   15785:                             $item,
                   15786:                             {      '-1' => '',
                   15787:                                 '86400' => &mt('today'),
                   15788:                                '604800' => &mt('last week'),
                   15789:                               '2592000' => &mt('last month'),
                   15790:                               '7776000' => &mt('last three months'),
                   15791:                              '15552000' => &mt('last six months'),
                   15792:                              '31104000' => &mt('last year'),
                   15793:                     'select_form_order' =>
                   15794:                            ['-1','86400','604800','2592000','7776000',
                   15795:                             '15552000','31104000']});
                   15796:     }
                   15797: }
                   15798: 
                   15799: =pod
                   15800: 
                   15801: =item * &js_changer()
                   15802: 
                   15803: Create script tag containing Javascript used to submit course search form
                   15804: when course type or domain is changed, and also to hide 'Searching ...' on
                   15805: page load completion for page showing search result.
                   15806: 
                   15807: Inputs: None
                   15808: 
                   15809: Returns: markup containing updateFilters() and hideSearching() javascript functions.
                   15810: 
                   15811: Side Effects: None
                   15812: 
                   15813: =cut
                   15814: 
                   15815: sub js_changer {
                   15816:     return <<ENDJS;
                   15817: <script type="text/javascript">
                   15818: // <![CDATA[
                   15819: function updateFilters(caller) {
                   15820:     if (typeof(caller) != "undefined") {
                   15821:         document.filterpicker.updater.value = caller.name;
                   15822:     }
                   15823:     document.filterpicker.submit();
                   15824: }
                   15825: 
                   15826: function hideSearching() {
                   15827:     if (document.getElementById('searching')) {
                   15828:         document.getElementById('searching').style.display = 'none';
                   15829:     }
                   15830:     return;
                   15831: }
                   15832: 
                   15833: // ]]>
                   15834: </script>
                   15835: 
                   15836: ENDJS
                   15837: }
                   15838: 
                   15839: =pod
                   15840: 
                   15841: =item * &search_courses()
                   15842: 
                   15843: Process selected filters form course search form and pass to lonnet::courseiddump
                   15844: to retrieve a hash for which keys are courseIDs which match the selected filters.
                   15845: 
                   15846: Inputs:
                   15847: 
                   15848: dom - domain being searched
                   15849: 
                   15850: type - course type ('Course' or 'Community' or '.' if any).
                   15851: 
                   15852: filter - anonymous hash of criteria and their values
                   15853: 
                   15854: numtitles - for institutional codes - number of categories
                   15855: 
                   15856: cloneruname - optional username of new course owner
                   15857: 
                   15858: clonerudom - optional domain of new course owner
                   15859: 
1.1075.2.95  raeburn  15860: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1075.2.69  raeburn  15861:             (used when DC is using course creation form)
                   15862: 
                   15863: codetitles - reference to array of titles of components in institutional codes (official courses).
                   15864: 
1.1075.2.95  raeburn  15865: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
                   15866:            (and so can clone automatically)
                   15867: 
                   15868: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
                   15869: 
                   15870: reqinstcode - institutional code of new course, where search_courses is used to identify potential
                   15871:               courses to clone
1.1075.2.69  raeburn  15872: 
                   15873: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
                   15874: 
                   15875: 
                   15876: Side Effects: None
                   15877: 
                   15878: =cut
                   15879: 
                   15880: 
                   15881: sub search_courses {
1.1075.2.95  raeburn  15882:     my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
                   15883:         $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1075.2.69  raeburn  15884:     my (%courses,%showcourses,$cloner);
                   15885:     if (($filter->{'ownerfilter'} ne '') ||
                   15886:         ($filter->{'ownerdomfilter'} ne '')) {
                   15887:         $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
                   15888:                                        $filter->{'ownerdomfilter'};
                   15889:     }
                   15890:     foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
                   15891:         if (!$filter->{$item}) {
                   15892:             $filter->{$item}='.';
                   15893:         }
                   15894:     }
                   15895:     my $now = time;
                   15896:     my $timefilter =
                   15897:        ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
                   15898:     my ($createdbefore,$createdafter);
                   15899:     if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
                   15900:         $createdbefore = $now;
                   15901:         $createdafter = $now-$filter->{'createdfilter'};
                   15902:     }
                   15903:     my ($instcodefilter,$regexpok);
                   15904:     if ($numtitles) {
                   15905:         if ($env{'form.official'} eq 'on') {
                   15906:             $instcodefilter =
                   15907:                 &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
                   15908:             $regexpok = 1;
                   15909:         } elsif ($env{'form.official'} eq 'off') {
                   15910:             $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
                   15911:             unless ($instcodefilter eq '') {
                   15912:                 $regexpok = -1;
                   15913:             }
                   15914:         }
                   15915:     } else {
                   15916:         $instcodefilter = $filter->{'instcodefilter'};
                   15917:     }
                   15918:     if ($instcodefilter eq '') { $instcodefilter = '.'; }
                   15919:     if ($type eq '') { $type = '.'; }
                   15920: 
                   15921:     if (($clonerudom ne '') && ($cloneruname ne '')) {
                   15922:         $cloner = $cloneruname.':'.$clonerudom;
                   15923:     }
                   15924:     %courses = &Apache::lonnet::courseiddump($dom,
                   15925:                                              $filter->{'descriptfilter'},
                   15926:                                              $timefilter,
                   15927:                                              $instcodefilter,
                   15928:                                              $filter->{'combownerfilter'},
                   15929:                                              $filter->{'coursefilter'},
                   15930:                                              undef,undef,$type,$regexpok,undef,undef,
1.1075.2.95  raeburn  15931:                                              undef,undef,$cloner,$cc_clone,
1.1075.2.69  raeburn  15932:                                              $filter->{'cloneableonly'},
                   15933:                                              $createdbefore,$createdafter,undef,
1.1075.2.95  raeburn  15934:                                              $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1075.2.69  raeburn  15935:     if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
                   15936:         my $ccrole;
                   15937:         if ($type eq 'Community') {
                   15938:             $ccrole = 'co';
                   15939:         } else {
                   15940:             $ccrole = 'cc';
                   15941:         }
                   15942:         my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
                   15943:                                                      $filter->{'persondomfilter'},
                   15944:                                                      'userroles',undef,
                   15945:                                                      [$ccrole,'in','ad','ep','ta','cr'],
                   15946:                                                      $dom);
                   15947:         foreach my $role (keys(%rolehash)) {
                   15948:             my ($cnum,$cdom,$courserole) = split(':',$role);
                   15949:             my $cid = $cdom.'_'.$cnum;
                   15950:             if (exists($courses{$cid})) {
                   15951:                 if (ref($courses{$cid}) eq 'HASH') {
                   15952:                     if (ref($courses{$cid}{roles}) eq 'ARRAY') {
                   15953:                         if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
                   15954:                             push (@{$courses{$cid}{roles}},$courserole);
                   15955:                         }
                   15956:                     } else {
                   15957:                         $courses{$cid}{roles} = [$courserole];
                   15958:                     }
                   15959:                     $showcourses{$cid} = $courses{$cid};
                   15960:                 }
                   15961:             }
                   15962:         }
                   15963:         %courses = %showcourses;
                   15964:     }
                   15965:     return %courses;
                   15966: }
                   15967: 
                   15968: =pod
                   15969: 
                   15970: =back
                   15971: 
1.1075.2.88  raeburn  15972: =head1 Routines for version requirements for current course.
                   15973: 
                   15974: =over 4
                   15975: 
                   15976: =item * &check_release_required()
                   15977: 
                   15978: Compares required LON-CAPA version with version on server, and
                   15979: if required version is newer looks for a server with the required version.
                   15980: 
                   15981: Looks first at servers in user's owen domain; if none suitable, looks at
                   15982: servers in course's domain are permitted to host sessions for user's domain.
                   15983: 
                   15984: Inputs:
                   15985: 
                   15986: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
                   15987: 
                   15988: $courseid - Course ID of current course
                   15989: 
                   15990: $rolecode - User's current role in course (for switchserver query string).
                   15991: 
                   15992: $required - LON-CAPA version needed by course (format: Major.Minor).
                   15993: 
                   15994: 
                   15995: Returns:
                   15996: 
                   15997: $switchserver - query string tp append to /adm/switchserver call (if
                   15998:                 current server's LON-CAPA version is too old.
                   15999: 
                   16000: $warning - Message is displayed if no suitable server could be found.
                   16001: 
                   16002: =cut
                   16003: 
                   16004: sub check_release_required {
                   16005:     my ($loncaparev,$courseid,$rolecode,$required) = @_;
                   16006:     my ($switchserver,$warning);
                   16007:     if ($required ne '') {
                   16008:         my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
                   16009:         my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
                   16010:         if ($reqdmajor ne '' && $reqdminor ne '') {
                   16011:             my $otherserver;
                   16012:             if (($major eq '' && $minor eq '') ||
                   16013:                 (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
                   16014:                 my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
                   16015:                 my $switchlcrev =
                   16016:                     &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
                   16017:                                                            $userdomserver);
                   16018:                 my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
                   16019:                 if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
                   16020:                     (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
                   16021:                     my $cdom = $env{'course.'.$courseid.'.domain'};
                   16022:                     if ($cdom ne $env{'user.domain'}) {
                   16023:                         my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
                   16024:                         my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
                   16025:                         my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
                   16026:                         my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
                   16027:                         my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
                   16028:                         my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
                   16029:                         my $canhost =
                   16030:                             &Apache::lonnet::can_host_session($env{'user.domain'},
                   16031:                                                               $coursedomserver,
                   16032:                                                               $remoterev,
                   16033:                                                               $udomdefaults{'remotesessions'},
                   16034:                                                               $defdomdefaults{'hostedsessions'});
                   16035: 
                   16036:                         if ($canhost) {
                   16037:                             $otherserver = $coursedomserver;
                   16038:                         } else {
                   16039:                             $warning = &mt('Requires LON-CAPA version [_1].',$env{'course.'.$courseid.'.internal.releaserequired'}).'<br />'. &mt("No suitable server could be found amongst servers in either your own domain or in the course's domain.");
                   16040:                         }
                   16041:                     } else {
                   16042:                         $warning = &mt('Requires LON-CAPA version [_1].',$env{'course.'.$courseid.'.internal.releaserequired'}).'<br />'.&mt("No suitable server could be found amongst servers in your own domain (which is also the course's domain).");
                   16043:                     }
                   16044:                 } else {
                   16045:                     $otherserver = $userdomserver;
                   16046:                 }
                   16047:             }
                   16048:             if ($otherserver ne '') {
                   16049:                 $switchserver = 'otherserver='.$otherserver.'&amp;role='.$rolecode;
                   16050:             }
                   16051:         }
                   16052:     }
                   16053:     return ($switchserver,$warning);
                   16054: }
                   16055: 
                   16056: =pod
                   16057: 
                   16058: =item * &check_release_result()
                   16059: 
                   16060: Inputs:
                   16061: 
                   16062: $switchwarning - Warning message if no suitable server found to host session.
                   16063: 
                   16064: $switchserver - query string to append to /adm/switchserver containing lonHostID
                   16065:                 and current role.
                   16066: 
                   16067: Returns: HTML to display with information about requirement to switch server.
                   16068:          Either displaying warning with link to Roles/Courses screen or
                   16069:          display link to switchserver.
                   16070: 
1.1075.2.69  raeburn  16071: =cut
                   16072: 
1.1075.2.88  raeburn  16073: sub check_release_result {
                   16074:     my ($switchwarning,$switchserver) = @_;
                   16075:     my $output = &start_page('Selected course unavailable on this server').
                   16076:                  '<p class="LC_warning">';
                   16077:     if ($switchwarning) {
                   16078:         $output .= $switchwarning.'<br /><a href="/adm/roles">';
                   16079:         if (&show_course()) {
                   16080:             $output .= &mt('Display courses');
                   16081:         } else {
                   16082:             $output .= &mt('Display roles');
                   16083:         }
                   16084:         $output .= '</a>';
                   16085:     } elsif ($switchserver) {
                   16086:         $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
                   16087:                    '<br />'.
                   16088:                    '<a href="/adm/switchserver?'.$switchserver.'">'.
                   16089:                    &mt('Switch Server').
                   16090:                    '</a>';
                   16091:     }
                   16092:     $output .= '</p>'.&end_page();
                   16093:     return $output;
                   16094: }
                   16095: 
                   16096: =pod
                   16097: 
                   16098: =item * &needs_coursereinit()
                   16099: 
                   16100: Determine if course contents stored for user's session needs to be
                   16101: refreshed, because content has changed since "Big Hash" last tied.
                   16102: 
                   16103: Check for change is made if time last checked is more than 10 minutes ago
                   16104: (by default).
                   16105: 
                   16106: Inputs:
                   16107: 
                   16108: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
                   16109: 
                   16110: $interval (optional) - Time which may elapse (in s) between last check for content
                   16111:                        change in current course. (default: 600 s).
                   16112: 
                   16113: Returns: an array; first element is:
                   16114: 
                   16115: =over 4
                   16116: 
                   16117: 'switch' - if content updates mean user's session
                   16118:            needs to be switched to a server running a newer LON-CAPA version
                   16119: 
                   16120: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
                   16121:            on current server hosting user's session
                   16122: 
                   16123: ''       - if no action required.
                   16124: 
                   16125: =back
                   16126: 
                   16127: If first item element is 'switch':
                   16128: 
                   16129: second item is $switchwarning - Warning message if no suitable server found to host session.
                   16130: 
                   16131: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
                   16132:                               and current role.
                   16133: 
                   16134: otherwise: no other elements returned.
                   16135: 
                   16136: =back
                   16137: 
                   16138: =cut
                   16139: 
                   16140: sub needs_coursereinit {
                   16141:     my ($loncaparev,$interval) = @_;
                   16142:     return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
                   16143:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   16144:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                   16145:     my $now = time;
                   16146:     if ($interval eq '') {
                   16147:         $interval = 600;
                   16148:     }
                   16149:     if (($now-$env{'request.course.timechecked'})>$interval) {
                   16150:         my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
                   16151:         &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
                   16152:         if ($lastchange > $env{'request.course.tied'}) {
                   16153:             my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
                   16154:             if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
                   16155:                 my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
                   16156:                 if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
                   16157:                     &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
                   16158:                                              $curr_reqd_hash{'internal.releaserequired'}});
                   16159:                     my ($switchserver,$switchwarning) =
                   16160:                         &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
                   16161:                                                 $curr_reqd_hash{'internal.releaserequired'});
                   16162:                     if ($switchwarning ne '' || $switchserver ne '') {
                   16163:                         return ('switch',$switchwarning,$switchserver);
                   16164:                     }
                   16165:                 }
                   16166:             }
                   16167:             return ('update');
                   16168:         }
                   16169:     }
                   16170:     return ();
                   16171: }
1.1075.2.69  raeburn  16172: 
1.1075.2.11  raeburn  16173: sub update_content_constraints {
                   16174:     my ($cdom,$cnum,$chome,$cid) = @_;
                   16175:     my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
                   16176:     my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
                   16177:     my %checkresponsetypes;
                   16178:     foreach my $key (keys(%Apache::lonnet::needsrelease)) {
                   16179:         my ($item,$name,$value) = split(/:/,$key);
                   16180:         if ($item eq 'resourcetag') {
                   16181:             if ($name eq 'responsetype') {
                   16182:                 $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
                   16183:             }
                   16184:         }
                   16185:     }
                   16186:     my $navmap = Apache::lonnavmaps::navmap->new();
                   16187:     if (defined($navmap)) {
                   16188:         my %allresponses;
                   16189:         foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
                   16190:             my %responses = $res->responseTypes();
                   16191:             foreach my $key (keys(%responses)) {
                   16192:                 next unless(exists($checkresponsetypes{$key}));
                   16193:                 $allresponses{$key} += $responses{$key};
                   16194:             }
                   16195:         }
                   16196:         foreach my $key (keys(%allresponses)) {
                   16197:             my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
                   16198:             if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
                   16199:                 ($reqdmajor,$reqdminor) = ($major,$minor);
                   16200:             }
                   16201:         }
                   16202:         undef($navmap);
                   16203:     }
                   16204:     unless (($reqdmajor eq '') && ($reqdminor eq '')) {
                   16205:         &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
                   16206:     }
                   16207:     return;
                   16208: }
                   16209: 
1.1075.2.27  raeburn  16210: sub allmaps_incourse {
                   16211:     my ($cdom,$cnum,$chome,$cid) = @_;
                   16212:     if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
                   16213:         $cid = $env{'request.course.id'};
                   16214:         $cdom = $env{'course.'.$cid.'.domain'};
                   16215:         $cnum = $env{'course.'.$cid.'.num'};
                   16216:         $chome = $env{'course.'.$cid.'.home'};
                   16217:     }
                   16218:     my %allmaps = ();
                   16219:     my $lastchange =
                   16220:         &Apache::lonnet::get_coursechange($cdom,$cnum);
                   16221:     if ($lastchange > $env{'request.course.tied'}) {
                   16222:         my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
                   16223:         unless ($ferr) {
                   16224:             &update_content_constraints($cdom,$cnum,$chome,$cid);
                   16225:         }
                   16226:     }
                   16227:     my $navmap = Apache::lonnavmaps::navmap->new();
                   16228:     if (defined($navmap)) {
                   16229:         foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
                   16230:             $allmaps{$res->src()} = 1;
                   16231:         }
                   16232:     }
                   16233:     return \%allmaps;
                   16234: }
                   16235: 
1.1075.2.11  raeburn  16236: sub parse_supplemental_title {
                   16237:     my ($title) = @_;
                   16238: 
                   16239:     my ($foldertitle,$renametitle);
                   16240:     if ($title =~ /&amp;&amp;&amp;/) {
                   16241:         $title = &HTML::Entites::decode($title);
                   16242:     }
                   16243:     if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
                   16244:         $renametitle=$4;
                   16245:         my ($time,$uname,$udom) = ($1,$2,$3);
                   16246:         $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
                   16247:         my $name =  &plainname($uname,$udom);
                   16248:         $name = &HTML::Entities::encode($name,'"<>&\'');
                   16249:         $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
                   16250:         $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
                   16251:             $name.': <br />'.$foldertitle;
                   16252:     }
                   16253:     if (wantarray) {
                   16254:         return ($title,$foldertitle,$renametitle);
                   16255:     }
                   16256:     return $title;
                   16257: }
                   16258: 
1.1075.2.43  raeburn  16259: sub recurse_supplemental {
                   16260:     my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
                   16261:     if ($suppmap) {
                   16262:         my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
                   16263:         if ($fatal) {
                   16264:             $errors ++;
                   16265:         } else {
                   16266:             if ($#LONCAPA::map::resources > 0) {
                   16267:                 foreach my $res (@LONCAPA::map::resources) {
                   16268:                     my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
                   16269:                     if (($src ne '') && ($status eq 'res')) {
1.1075.2.46  raeburn  16270:                         if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
                   16271:                             ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43  raeburn  16272:                         } else {
                   16273:                             $numfiles ++;
                   16274:                         }
                   16275:                     }
                   16276:                 }
                   16277:             }
                   16278:         }
                   16279:     }
                   16280:     return ($numfiles,$errors);
                   16281: }
                   16282: 
1.1075.2.18  raeburn  16283: sub symb_to_docspath {
                   16284:     my ($symb) = @_;
                   16285:     return unless ($symb);
                   16286:     my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
                   16287:     if ($resurl=~/\.(sequence|page)$/) {
                   16288:         $mapurl=$resurl;
                   16289:     } elsif ($resurl eq 'adm/navmaps') {
                   16290:         $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
                   16291:     }
                   16292:     my $mapresobj;
                   16293:     my $navmap = Apache::lonnavmaps::navmap->new();
                   16294:     if (ref($navmap)) {
                   16295:         $mapresobj = $navmap->getResourceByUrl($mapurl);
                   16296:     }
                   16297:     $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
                   16298:     my $type=$2;
                   16299:     my $path;
                   16300:     if (ref($mapresobj)) {
                   16301:         my $pcslist = $mapresobj->map_hierarchy();
                   16302:         if ($pcslist ne '') {
                   16303:             foreach my $pc (split(/,/,$pcslist)) {
                   16304:                 next if ($pc <= 1);
                   16305:                 my $res = $navmap->getByMapPc($pc);
                   16306:                 if (ref($res)) {
                   16307:                     my $thisurl = $res->src();
                   16308:                     $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
                   16309:                     my $thistitle = $res->title();
                   16310:                     $path .= '&'.
                   16311:                              &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46  raeburn  16312:                              &escape($thistitle).
1.1075.2.18  raeburn  16313:                              ':'.$res->randompick().
                   16314:                              ':'.$res->randomout().
                   16315:                              ':'.$res->encrypted().
                   16316:                              ':'.$res->randomorder().
                   16317:                              ':'.$res->is_page();
                   16318:                 }
                   16319:             }
                   16320:         }
                   16321:         $path =~ s/^\&//;
                   16322:         my $maptitle = $mapresobj->title();
                   16323:         if ($mapurl eq 'default') {
1.1075.2.38  raeburn  16324:             $maptitle = 'Main Content';
1.1075.2.18  raeburn  16325:         }
                   16326:         $path .= (($path ne '')? '&' : '').
                   16327:                  &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46  raeburn  16328:                  &escape($maptitle).
1.1075.2.18  raeburn  16329:                  ':'.$mapresobj->randompick().
                   16330:                  ':'.$mapresobj->randomout().
                   16331:                  ':'.$mapresobj->encrypted().
                   16332:                  ':'.$mapresobj->randomorder().
                   16333:                  ':'.$mapresobj->is_page();
                   16334:     } else {
                   16335:         my $maptitle = &Apache::lonnet::gettitle($mapurl);
                   16336:         my $ispage = (($type eq 'page')? 1 : '');
                   16337:         if ($mapurl eq 'default') {
1.1075.2.38  raeburn  16338:             $maptitle = 'Main Content';
1.1075.2.18  raeburn  16339:         }
                   16340:         $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46  raeburn  16341:                 &escape($maptitle).':::::'.$ispage;
1.1075.2.18  raeburn  16342:     }
                   16343:     unless ($mapurl eq 'default') {
                   16344:         $path = 'default&'.
1.1075.2.46  raeburn  16345:                 &escape('Main Content').
1.1075.2.18  raeburn  16346:                 ':::::&'.$path;
                   16347:     }
                   16348:     return $path;
                   16349: }
                   16350: 
1.1075.2.14  raeburn  16351: sub captcha_display {
                   16352:     my ($context,$lonhost) = @_;
                   16353:     my ($output,$error);
1.1075.2.107  raeburn  16354:     my ($captcha,$pubkey,$privkey,$version) =
                   16355:         &get_captcha_config($context,$lonhost);
1.1075.2.14  raeburn  16356:     if ($captcha eq 'original') {
                   16357:         $output = &create_captcha();
                   16358:         unless ($output) {
                   16359:             $error = 'captcha';
                   16360:         }
                   16361:     } elsif ($captcha eq 'recaptcha') {
1.1075.2.107  raeburn  16362:         $output = &create_recaptcha($pubkey,$version);
1.1075.2.14  raeburn  16363:         unless ($output) {
                   16364:             $error = 'recaptcha';
                   16365:         }
                   16366:     }
1.1075.2.107  raeburn  16367:     return ($output,$error,$captcha,$version);
1.1075.2.14  raeburn  16368: }
                   16369: 
                   16370: sub captcha_response {
                   16371:     my ($context,$lonhost) = @_;
                   16372:     my ($captcha_chk,$captcha_error);
1.1075.2.109  raeburn  16373:     my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost);
1.1075.2.14  raeburn  16374:     if ($captcha eq 'original') {
                   16375:         ($captcha_chk,$captcha_error) = &check_captcha();
                   16376:     } elsif ($captcha eq 'recaptcha') {
1.1075.2.107  raeburn  16377:         $captcha_chk = &check_recaptcha($privkey,$version);
1.1075.2.14  raeburn  16378:     } else {
                   16379:         $captcha_chk = 1;
                   16380:     }
                   16381:     return ($captcha_chk,$captcha_error);
                   16382: }
                   16383: 
                   16384: sub get_captcha_config {
                   16385:     my ($context,$lonhost) = @_;
1.1075.2.107  raeburn  16386:     my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1075.2.14  raeburn  16387:     my $hostname = &Apache::lonnet::hostname($lonhost);
                   16388:     my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
                   16389:     my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
                   16390:     if ($context eq 'usercreation') {
                   16391:         my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
                   16392:         if (ref($domconfig{$context}) eq 'HASH') {
                   16393:             $hashtocheck = $domconfig{$context}{'cancreate'};
                   16394:             if (ref($hashtocheck) eq 'HASH') {
                   16395:                 if ($hashtocheck->{'captcha'} eq 'recaptcha') {
                   16396:                     if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
                   16397:                         $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
                   16398:                         $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
                   16399:                     }
                   16400:                     if ($privkey && $pubkey) {
                   16401:                         $captcha = 'recaptcha';
1.1075.2.107  raeburn  16402:                         $version = $hashtocheck->{'recaptchaversion'};
                   16403:                         if ($version ne '2') {
                   16404:                             $version = 1;
                   16405:                         }
1.1075.2.14  raeburn  16406:                     } else {
                   16407:                         $captcha = 'original';
                   16408:                     }
                   16409:                 } elsif ($hashtocheck->{'captcha'} ne 'notused') {
                   16410:                     $captcha = 'original';
                   16411:                 }
                   16412:             }
                   16413:         } else {
                   16414:             $captcha = 'captcha';
                   16415:         }
                   16416:     } elsif ($context eq 'login') {
                   16417:         my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
                   16418:         if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
                   16419:             $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
                   16420:             $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
                   16421:             if ($privkey && $pubkey) {
                   16422:                 $captcha = 'recaptcha';
1.1075.2.107  raeburn  16423:                 $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
                   16424:                 if ($version ne '2') {
                   16425:                     $version = 1;
                   16426:                 }
1.1075.2.14  raeburn  16427:             } else {
                   16428:                 $captcha = 'original';
                   16429:             }
                   16430:         } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
                   16431:             $captcha = 'original';
                   16432:         }
                   16433:     }
1.1075.2.107  raeburn  16434:     return ($captcha,$pubkey,$privkey,$version);
1.1075.2.14  raeburn  16435: }
                   16436: 
                   16437: sub create_captcha {
                   16438:     my %captcha_params = &captcha_settings();
                   16439:     my ($output,$maxtries,$tries) = ('',10,0);
                   16440:     while ($tries < $maxtries) {
                   16441:         $tries ++;
                   16442:         my $captcha = Authen::Captcha->new (
                   16443:                                            output_folder => $captcha_params{'output_dir'},
                   16444:                                            data_folder   => $captcha_params{'db_dir'},
                   16445:                                           );
                   16446:         my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
                   16447: 
                   16448:         if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
                   16449:             $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
                   16450:                       &mt('Type in the letters/numbers shown below').'&nbsp;'.
1.1075.2.66  raeburn  16451:                       '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
                   16452:                       '<br />'.
                   16453:                       '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14  raeburn  16454:             last;
                   16455:         }
                   16456:     }
                   16457:     return $output;
                   16458: }
                   16459: 
                   16460: sub captcha_settings {
                   16461:     my %captcha_params = (
                   16462:                            output_dir     => $Apache::lonnet::perlvar{'lonCaptchaDir'},
                   16463:                            www_output_dir => "/captchaspool",
                   16464:                            db_dir         => $Apache::lonnet::perlvar{'lonCaptchaDb'},
                   16465:                            numchars       => '5',
                   16466:                          );
                   16467:     return %captcha_params;
                   16468: }
                   16469: 
                   16470: sub check_captcha {
                   16471:     my ($captcha_chk,$captcha_error);
                   16472:     my $code = $env{'form.code'};
                   16473:     my $md5sum = $env{'form.crypt'};
                   16474:     my %captcha_params = &captcha_settings();
                   16475:     my $captcha = Authen::Captcha->new(
                   16476:                       output_folder => $captcha_params{'output_dir'},
                   16477:                       data_folder   => $captcha_params{'db_dir'},
                   16478:                   );
1.1075.2.26  raeburn  16479:     $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14  raeburn  16480:     my %captcha_hash = (
                   16481:                         0       => 'Code not checked (file error)',
                   16482:                        -1      => 'Failed: code expired',
                   16483:                        -2      => 'Failed: invalid code (not in database)',
                   16484:                        -3      => 'Failed: invalid code (code does not match crypt)',
                   16485:     );
                   16486:     if ($captcha_chk != 1) {
                   16487:         $captcha_error = $captcha_hash{$captcha_chk}
                   16488:     }
                   16489:     return ($captcha_chk,$captcha_error);
                   16490: }
                   16491: 
                   16492: sub create_recaptcha {
1.1075.2.107  raeburn  16493:     my ($pubkey,$version) = @_;
                   16494:     if ($version >= 2) {
                   16495:         return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
                   16496:     } else {
                   16497:         my $use_ssl;
                   16498:         if ($ENV{'SERVER_PORT'} == 443) {
                   16499:             $use_ssl = 1;
                   16500:         }
                   16501:         my $captcha = Captcha::reCAPTCHA->new;
                   16502:         return $captcha->get_options_setter({theme => 'white'})."\n".
                   16503:                $captcha->get_html($pubkey,undef,$use_ssl).
                   16504:                &mt('If the text is hard to read, [_1] will replace them.',
                   16505:                    '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
                   16506:                '<br /><br />';
                   16507:      }
1.1075.2.14  raeburn  16508: }
                   16509: 
                   16510: sub check_recaptcha {
1.1075.2.107  raeburn  16511:     my ($privkey,$version) = @_;
1.1075.2.14  raeburn  16512:     my $captcha_chk;
1.1075.2.107  raeburn  16513:     if ($version >= 2) {
                   16514:         my $ua = LWP::UserAgent->new;
                   16515:         $ua->timeout(10);
                   16516:         my %info = (
                   16517:                      secret   => $privkey,
                   16518:                      response => $env{'form.g-recaptcha-response'},
                   16519:                      remoteip => $ENV{'REMOTE_ADDR'},
                   16520:                    );
                   16521:         my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
                   16522:         if ($response->is_success)  {
                   16523:             my $data = JSON::DWIW->from_json($response->decoded_content);
                   16524:             if (ref($data) eq 'HASH') {
                   16525:                 if ($data->{'success'}) {
                   16526:                     $captcha_chk = 1;
                   16527:                 }
                   16528:             }
                   16529:         }
                   16530:     } else {
                   16531:         my $captcha = Captcha::reCAPTCHA->new;
                   16532:         my $captcha_result =
                   16533:             $captcha->check_answer(
                   16534:                                     $privkey,
                   16535:                                     $ENV{'REMOTE_ADDR'},
                   16536:                                     $env{'form.recaptcha_challenge_field'},
                   16537:                                     $env{'form.recaptcha_response_field'},
                   16538:                                   );
                   16539:         if ($captcha_result->{is_valid}) {
                   16540:             $captcha_chk = 1;
                   16541:         }
1.1075.2.14  raeburn  16542:     }
                   16543:     return $captcha_chk;
                   16544: }
                   16545: 
1.1075.2.64  raeburn  16546: sub emailusername_info {
1.1075.2.103  raeburn  16547:     my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1075.2.64  raeburn  16548:     my %titles = &Apache::lonlocal::texthash (
                   16549:                      lastname      => 'Last Name',
                   16550:                      firstname     => 'First Name',
                   16551:                      institution   => 'School/college/university',
                   16552:                      location      => "School's city, state/province, country",
                   16553:                      web           => "School's web address",
                   16554:                      officialemail => 'E-mail address at institution (if different)',
1.1075.2.103  raeburn  16555:                      id            => 'Student/Employee ID',
1.1075.2.64  raeburn  16556:                  );
                   16557:     return (\@fields,\%titles);
                   16558: }
                   16559: 
1.1075.2.56  raeburn  16560: sub cleanup_html {
                   16561:     my ($incoming) = @_;
                   16562:     my $outgoing;
                   16563:     if ($incoming ne '') {
                   16564:         $outgoing = $incoming;
                   16565:         $outgoing =~ s/;/&#059;/g;
                   16566:         $outgoing =~ s/\#/&#035;/g;
                   16567:         $outgoing =~ s/\&/&#038;/g;
                   16568:         $outgoing =~ s/</&#060;/g;
                   16569:         $outgoing =~ s/>/&#062;/g;
                   16570:         $outgoing =~ s/\(/&#040/g;
                   16571:         $outgoing =~ s/\)/&#041;/g;
                   16572:         $outgoing =~ s/"/&#034;/g;
                   16573:         $outgoing =~ s/'/&#039;/g;
                   16574:         $outgoing =~ s/\$/&#036;/g;
                   16575:         $outgoing =~ s{/}{&#047;}g;
                   16576:         $outgoing =~ s/=/&#061;/g;
                   16577:         $outgoing =~ s/\\/&#092;/g
                   16578:     }
                   16579:     return $outgoing;
                   16580: }
                   16581: 
1.1075.2.74  raeburn  16582: # Checks for critical messages and returns a redirect url if one exists.
                   16583: # $interval indicates how often to check for messages.
                   16584: sub critical_redirect {
                   16585:     my ($interval) = @_;
                   16586:     if ((time-$env{'user.criticalcheck.time'})>$interval) {
                   16587:         my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
                   16588:                                         $env{'user.name'});
                   16589:         &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
                   16590:         my $redirecturl;
                   16591:         if ($what[0]) {
                   16592:             if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
                   16593:                 $redirecturl='/adm/email?critical=display';
                   16594:                 my $url=&Apache::lonnet::absolute_url().$redirecturl;
                   16595:                 return (1, $url);
                   16596:             }
                   16597:         }
                   16598:     }
                   16599:     return ();
                   16600: }
                   16601: 
1.1075.2.64  raeburn  16602: # Use:
                   16603: #   my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
                   16604: #
                   16605: ##################################################
                   16606: #          password associated functions         #
                   16607: ##################################################
                   16608: sub des_keys {
                   16609:     # Make a new key for DES encryption.
                   16610:     # Each key has two parts which are returned separately.
                   16611:     # Please note:  Each key must be passed through the &hex function
                   16612:     # before it is output to the web browser.  The hex versions cannot
                   16613:     # be used to decrypt.
                   16614:     my @hexstr=('0','1','2','3','4','5','6','7',
                   16615:                 '8','9','a','b','c','d','e','f');
                   16616:     my $lkey='';
                   16617:     for (0..7) {
                   16618:         $lkey.=$hexstr[rand(15)];
                   16619:     }
                   16620:     my $ukey='';
                   16621:     for (0..7) {
                   16622:         $ukey.=$hexstr[rand(15)];
                   16623:     }
                   16624:     return ($lkey,$ukey);
                   16625: }
                   16626: 
                   16627: sub des_decrypt {
                   16628:     my ($key,$cyphertext) = @_;
                   16629:     my $keybin=pack("H16",$key);
                   16630:     my $cypher;
                   16631:     if ($Crypt::DES::VERSION>=2.03) {
                   16632:         $cypher=new Crypt::DES $keybin;
                   16633:     } else {
                   16634:         $cypher=new DES $keybin;
                   16635:     }
1.1075.2.106  raeburn  16636:     my $plaintext='';
                   16637:     my $cypherlength = length($cyphertext);
                   16638:     my $numchunks = int($cypherlength/32);
                   16639:     for (my $j=0; $j<$numchunks; $j++) {
                   16640:         my $start = $j*32;
                   16641:         my $cypherblock = substr($cyphertext,$start,32);
                   16642:         my $chunk =
                   16643:             $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
                   16644:         $chunk .=
                   16645:             $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
                   16646:         $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
                   16647:         $plaintext .= $chunk;
                   16648:     }
1.1075.2.64  raeburn  16649:     return $plaintext;
                   16650: }
                   16651: 
1.112     bowersj2 16652: 1;
                   16653: __END__;
1.41      ng       16654: 

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