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

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.8! raeburn     4: # $Id: loncommon.pm,v 1.1075.2.7 2012/06/01 12:02:10 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.479     albertel   70: use LONCAPA qw(:DEFAULT :match);
1.657     raeburn    71: use DateTime::TimeZone;
1.687     raeburn    72: use DateTime::Locale::Catalog;
1.117     www        73: 
1.517     raeburn    74: # ---------------------------------------------- Designs
                     75: use vars qw(%defaultdesign);
                     76: 
1.22      www        77: my $readit;
                     78: 
1.517     raeburn    79: 
1.157     matthew    80: ##
                     81: ## Global Variables
                     82: ##
1.46      matthew    83: 
1.643     foxr       84: 
                     85: # ----------------------------------------------- SSI with retries:
                     86: #
                     87: 
                     88: =pod
                     89: 
1.648     raeburn    90: =head1 Server Side include with retries:
1.643     foxr       91: 
                     92: =over 4
                     93: 
1.648     raeburn    94: =item * &ssi_with_retries(resource,retries form)
1.643     foxr       95: 
                     96: Performs an ssi with some number of retries.  Retries continue either
                     97: until the result is ok or until the retry count supplied by the
                     98: caller is exhausted.  
                     99: 
                    100: Inputs:
1.648     raeburn   101: 
                    102: =over 4
                    103: 
1.643     foxr      104: resource   - Identifies the resource to insert.
1.648     raeburn   105: 
1.643     foxr      106: retries    - Count of the number of retries allowed.
1.648     raeburn   107: 
1.643     foxr      108: form       - Hash that identifies the rendering options.
                    109: 
1.648     raeburn   110: =back
                    111: 
                    112: Returns:
                    113: 
                    114: =over 4
                    115: 
1.643     foxr      116: content    - The content of the response.  If retries were exhausted this is empty.
1.648     raeburn   117: 
1.643     foxr      118: response   - The response from the last attempt (which may or may not have been successful.
                    119: 
1.648     raeburn   120: =back
                    121: 
                    122: =back
                    123: 
1.643     foxr      124: =cut
                    125: 
                    126: sub ssi_with_retries {
                    127:     my ($resource, $retries, %form) = @_;
                    128: 
                    129: 
                    130:     my $ok = 0;			# True if we got a good response.
                    131:     my $content;
                    132:     my $response;
                    133: 
                    134:     # Try to get the ssi done. within the retries count:
                    135: 
                    136:     do {
                    137: 	($content, $response) = &Apache::lonnet::ssi($resource, %form);
                    138: 	$ok      = $response->is_success;
1.650     www       139:         if (!$ok) {
                    140:             &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
                    141:         }
1.643     foxr      142: 	$retries--;
                    143:     } while (!$ok && ($retries > 0));
                    144: 
                    145:     if (!$ok) {
                    146: 	$content = '';		# On error return an empty content.
                    147:     }
                    148:     return ($content, $response);
                    149: 
                    150: }
                    151: 
                    152: 
                    153: 
1.20      www       154: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12      harris41  155: my %language;
1.124     www       156: my %supported_language;
1.1048    foxr      157: my %latex_language;		# For choosing hyphenation in <transl..>
                    158: my %latex_language_bykey;	# for choosing hyphenation from metadata
1.12      harris41  159: my %cprtag;
1.192     taceyjo1  160: my %scprtag;
1.351     www       161: my %fe; my %fd; my %fm;
1.41      ng        162: my %category_extensions;
1.12      harris41  163: 
1.46      matthew   164: # ---------------------------------------------- Thesaurus variables
1.144     matthew   165: #
                    166: # %Keywords:
                    167: #      A hash used by &keyword to determine if a word is considered a keyword.
                    168: # $thesaurus_db_file 
                    169: #      Scalar containing the full path to the thesaurus database.
1.46      matthew   170: 
                    171: my %Keywords;
                    172: my $thesaurus_db_file;
                    173: 
1.144     matthew   174: #
                    175: # Initialize values from language.tab, copyright.tab, filetypes.tab,
                    176: # thesaurus.tab, and filecategories.tab.
                    177: #
1.18      www       178: BEGIN {
1.46      matthew   179:     # Variable initialization
                    180:     $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
                    181:     #
1.22      www       182:     unless ($readit) {
1.12      harris41  183: # ------------------------------------------------------------------- languages
                    184:     {
1.158     raeburn   185:         my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    186:                                    '/language.tab';
                    187:         if ( open(my $fh,"<$langtabfile") ) {
1.356     albertel  188:             while (my $line = <$fh>) {
                    189:                 next if ($line=~/^\#/);
                    190:                 chomp($line);
1.1048    foxr      191:                 my ($key,$two,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158     raeburn   192:                 $language{$key}=$val.' - '.$enc;
                    193:                 if ($sup) {
                    194:                     $supported_language{$key}=$sup;
                    195:                 }
1.1048    foxr      196: 		if ($latex) {
                    197: 		    $latex_language_bykey{$key} = $latex;
                    198: 		    $latex_language{$two} = $latex;
                    199: 		}
1.158     raeburn   200:             }
                    201:             close($fh);
                    202:         }
1.12      harris41  203:     }
                    204: # ------------------------------------------------------------------ copyrights
                    205:     {
1.158     raeburn   206:         my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
                    207:                                   '/copyright.tab';
                    208:         if ( open (my $fh,"<$copyrightfile") ) {
1.356     albertel  209:             while (my $line = <$fh>) {
                    210:                 next if ($line=~/^\#/);
                    211:                 chomp($line);
                    212:                 my ($key,$val)=(split(/\s+/,$line,2));
1.158     raeburn   213:                 $cprtag{$key}=$val;
                    214:             }
                    215:             close($fh);
                    216:         }
1.12      harris41  217:     }
1.351     www       218: # ----------------------------------------------------------- source copyrights
1.192     taceyjo1  219:     {
                    220:         my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
                    221:                                   '/source_copyright.tab';
                    222:         if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356     albertel  223:             while (my $line = <$fh>) {
                    224:                 next if ($line =~ /^\#/);
                    225:                 chomp($line);
                    226:                 my ($key,$val)=(split(/\s+/,$line,2));
1.192     taceyjo1  227:                 $scprtag{$key}=$val;
                    228:             }
                    229:             close($fh);
                    230:         }
                    231:     }
1.63      www       232: 
1.517     raeburn   233: # -------------------------------------------------------------- default domain designs
1.63      www       234:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517     raeburn   235:     my $designfile = $designdir.'/default.tab';
                    236:     if ( open (my $fh,"<$designfile") ) {
                    237:         while (my $line = <$fh>) {
                    238:             next if ($line =~ /^\#/);
                    239:             chomp($line);
                    240:             my ($key,$val)=(split(/\=/,$line));
                    241:             if ($val) { $defaultdesign{$key}=$val; }
                    242:         }
                    243:         close($fh);
1.63      www       244:     }
                    245: 
1.15      harris41  246: # ------------------------------------------------------------- file categories
                    247:     {
1.158     raeburn   248:         my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    249:                                   '/filecategories.tab';
                    250:         if ( open (my $fh,"<$categoryfile") ) {
1.356     albertel  251: 	    while (my $line = <$fh>) {
                    252: 		next if ($line =~ /^\#/);
                    253: 		chomp($line);
                    254:                 my ($extension,$category)=(split(/\s+/,$line,2));
1.158     raeburn   255:                 push @{$category_extensions{lc($category)}},$extension;
                    256:             }
                    257:             close($fh);
                    258:         }
                    259: 
1.15      harris41  260:     }
1.12      harris41  261: # ------------------------------------------------------------------ file types
                    262:     {
1.158     raeburn   263:         my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    264:                '/filetypes.tab';
                    265:         if ( open (my $fh,"<$typesfile") ) {
1.356     albertel  266:             while (my $line = <$fh>) {
                    267: 		next if ($line =~ /^\#/);
                    268: 		chomp($line);
                    269:                 my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158     raeburn   270:                 if ($descr ne '') {
                    271:                     $fe{$ending}=lc($emb);
                    272:                     $fd{$ending}=$descr;
1.351     www       273:                     if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158     raeburn   274:                 }
                    275:             }
                    276:             close($fh);
                    277:         }
1.12      harris41  278:     }
1.22      www       279:     &Apache::lonnet::logthis(
1.705     tempelho  280:              "<span style='color:yellow;'>INFO: Read file types</span>");
1.22      www       281:     $readit=1;
1.46      matthew   282:     }  # end of unless($readit) 
1.32      matthew   283:     
                    284: }
1.112     bowersj2  285: 
1.42      matthew   286: ###############################################################
                    287: ##           HTML and Javascript Helper Functions            ##
                    288: ###############################################################
                    289: 
                    290: =pod 
                    291: 
1.112     bowersj2  292: =head1 HTML and Javascript Functions
1.42      matthew   293: 
1.112     bowersj2  294: =over 4
                    295: 
1.648     raeburn   296: =item * &browser_and_searcher_javascript()
1.112     bowersj2  297: 
                    298: X<browsing, javascript>X<searching, javascript>Returns a string
                    299: containing javascript with two functions, C<openbrowser> and
                    300: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
                    301: tags.
1.42      matthew   302: 
1.648     raeburn   303: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42      matthew   304: 
                    305: inputs: formname, elementname, only, omit
                    306: 
                    307: formname and elementname indicate the name of the html form and name of
                    308: the element that the results of the browsing selection are to be placed in. 
                    309: 
                    310: Specifying 'only' will restrict the browser to displaying only files
1.185     www       311: with the given extension.  Can be a comma separated list.
1.42      matthew   312: 
                    313: Specifying 'omit' will restrict the browser to NOT displaying files
1.185     www       314: with the given extension.  Can be a comma separated list.
1.42      matthew   315: 
1.648     raeburn   316: =item * &opensearcher(formname,elementname) [javascript]
1.42      matthew   317: 
                    318: Inputs: formname, elementname
                    319: 
                    320: formname and elementname specify the name of the html form and the name
                    321: of the element the selection from the search results will be placed in.
1.542     raeburn   322: 
1.42      matthew   323: =cut
                    324: 
                    325: sub browser_and_searcher_javascript {
1.199     albertel  326:     my ($mode)=@_;
                    327:     if (!defined($mode)) { $mode='edit'; }
1.453     albertel  328:     my $resurl=&escape_single(&lastresurl());
1.42      matthew   329:     return <<END;
1.219     albertel  330: // <!-- BEGIN LON-CAPA Internal
1.50      matthew   331:     var editbrowser = null;
1.135     albertel  332:     function openbrowser(formname,elementname,only,omit,titleelement) {
1.170     www       333:         var url = '$resurl/?';
1.42      matthew   334:         if (editbrowser == null) {
                    335:             url += 'launch=1&';
                    336:         }
                    337:         url += 'catalogmode=interactive&';
1.199     albertel  338:         url += 'mode=$mode&';
1.611     albertel  339:         url += 'inhibitmenu=yes&';
1.42      matthew   340:         url += 'form=' + formname + '&';
                    341:         if (only != null) {
                    342:             url += 'only=' + only + '&';
1.217     albertel  343:         } else {
                    344:             url += 'only=&';
                    345: 	}
1.42      matthew   346:         if (omit != null) {
                    347:             url += 'omit=' + omit + '&';
1.217     albertel  348:         } else {
                    349:             url += 'omit=&';
                    350: 	}
1.135     albertel  351:         if (titleelement != null) {
                    352:             url += 'titleelement=' + titleelement + '&';
1.217     albertel  353:         } else {
                    354: 	    url += 'titleelement=&';
                    355: 	}
1.42      matthew   356:         url += 'element=' + elementname + '';
                    357:         var title = 'Browser';
1.435     albertel  358:         var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42      matthew   359:         options += ',width=700,height=600';
                    360:         editbrowser = open(url,title,options,'1');
                    361:         editbrowser.focus();
                    362:     }
                    363:     var editsearcher;
1.135     albertel  364:     function opensearcher(formname,elementname,titleelement) {
1.42      matthew   365:         var url = '/adm/searchcat?';
                    366:         if (editsearcher == null) {
                    367:             url += 'launch=1&';
                    368:         }
                    369:         url += 'catalogmode=interactive&';
1.199     albertel  370:         url += 'mode=$mode&';
1.42      matthew   371:         url += 'form=' + formname + '&';
1.135     albertel  372:         if (titleelement != null) {
                    373:             url += 'titleelement=' + titleelement + '&';
1.217     albertel  374:         } else {
                    375: 	    url += 'titleelement=&';
                    376: 	}
1.42      matthew   377:         url += 'element=' + elementname + '';
                    378:         var title = 'Search';
1.435     albertel  379:         var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42      matthew   380:         options += ',width=700,height=600';
                    381:         editsearcher = open(url,title,options,'1');
                    382:         editsearcher.focus();
                    383:     }
1.219     albertel  384: // END LON-CAPA Internal -->
1.42      matthew   385: END
1.170     www       386: }
                    387: 
                    388: sub lastresurl {
1.258     albertel  389:     if ($env{'environment.lastresurl'}) {
                    390: 	return $env{'environment.lastresurl'}
1.170     www       391:     } else {
                    392: 	return '/res';
                    393:     }
                    394: }
                    395: 
                    396: sub storeresurl {
                    397:     my $resurl=&Apache::lonnet::clutter(shift);
                    398:     unless ($resurl=~/^\/res/) { return 0; }
                    399:     $resurl=~s/\/$//;
                    400:     &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646     raeburn   401:     &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170     www       402:     return 1;
1.42      matthew   403: }
                    404: 
1.74      www       405: sub studentbrowser_javascript {
1.111     www       406:    unless (
1.258     albertel  407:             (($env{'request.course.id'}) && 
1.302     albertel  408:              (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    409: 	      || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                    410: 					  '/'.$env{'request.course.sec'})
                    411: 	      ))
1.258     albertel  412:          || ($env{'request.role'}=~/^(au|dc|su)/)
1.111     www       413:           ) { return ''; }  
1.74      www       414:    return (<<'ENDSTDBRW');
1.776     bisitz    415: <script type="text/javascript" language="Javascript">
1.824     bisitz    416: // <![CDATA[
1.74      www       417:     var stdeditbrowser;
1.999     www       418:     function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74      www       419:         var url = '/adm/pickstudent?';
                    420:         var filter;
1.558     albertel  421: 	if (!ignorefilter) {
                    422: 	    eval('filter=document.'+formname+'.'+uname+'.value;');
                    423: 	}
1.74      www       424:         if (filter != null) {
                    425:            if (filter != '') {
                    426:                url += 'filter='+filter+'&';
                    427: 	   }
                    428:         }
                    429:         url += 'form=' + formname + '&unameelement='+uname+
1.999     www       430:                                     '&udomelement='+udom+
                    431:                                     '&clicker='+clicker;
1.111     www       432: 	if (roleflag) { url+="&roles=1"; }
1.793     raeburn   433:         if (courseadvonly) { url+="&courseadvonly=1"; }
1.102     www       434:         var title = 'Student_Browser';
1.74      www       435:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    436:         options += ',width=700,height=600';
                    437:         stdeditbrowser = open(url,title,options,'1');
                    438:         stdeditbrowser.focus();
                    439:     }
1.824     bisitz    440: // ]]>
1.74      www       441: </script>
                    442: ENDSTDBRW
                    443: }
1.42      matthew   444: 
1.1003    www       445: sub resourcebrowser_javascript {
                    446:    unless ($env{'request.course.id'}) { return ''; }
1.1004    www       447:    return (<<'ENDRESBRW');
1.1003    www       448: <script type="text/javascript" language="Javascript">
                    449: // <![CDATA[
                    450:     var reseditbrowser;
1.1004    www       451:     function openresbrowser(formname,reslink) {
1.1005    www       452:         var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003    www       453:         var title = 'Resource_Browser';
                    454:         var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005    www       455:         options += ',width=700,height=500';
1.1004    www       456:         reseditbrowser = open(url,title,options,'1');
                    457:         reseditbrowser.focus();
1.1003    www       458:     }
                    459: // ]]>
                    460: </script>
1.1004    www       461: ENDRESBRW
1.1003    www       462: }
                    463: 
1.74      www       464: sub selectstudent_link {
1.999     www       465:    my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
                    466:    my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
                    467:                       &Apache::lonhtmlcommon::entity_encode($unameele)."','".
                    468:                       &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258     albertel  469:    if ($env{'request.course.id'}) {  
1.302     albertel  470:        if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    471: 	   && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                    472: 					'/'.$env{'request.course.sec'})) {
1.111     www       473: 	   return '';
                    474:        }
1.999     www       475:        $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793     raeburn   476:        if ($courseadvonly)  {
                    477:            $callargs .= ",'',1,1";
                    478:        }
                    479:        return '<span class="LC_nobreak">'.
                    480:               '<a href="javascript:openstdbrowser('.$callargs.');">'.
                    481:               &mt('Select User').'</a></span>';
1.74      www       482:    }
1.258     albertel  483:    if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012    www       484:        $callargs .= ",'',1"; 
1.793     raeburn   485:        return '<span class="LC_nobreak">'.
                    486:               '<a href="javascript:openstdbrowser('.$callargs.');">'.
                    487:               &mt('Select User').'</a></span>';
1.111     www       488:    }
                    489:    return '';
1.91      www       490: }
                    491: 
1.1004    www       492: sub selectresource_link {
                    493:    my ($form,$reslink,$arg)=@_;
                    494:    
                    495:    my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
                    496:                       &Apache::lonhtmlcommon::entity_encode($reslink)."'";
                    497:    unless ($env{'request.course.id'}) { return $arg; }
                    498:    return '<span class="LC_nobreak">'.
                    499:               '<a href="javascript:openresbrowser('.$callargs.');">'.
                    500:               $arg.'</a></span>';
                    501: }
                    502: 
                    503: 
                    504: 
1.653     raeburn   505: sub authorbrowser_javascript {
                    506:     return <<"ENDAUTHORBRW";
1.776     bisitz    507: <script type="text/javascript" language="JavaScript">
1.824     bisitz    508: // <![CDATA[
1.653     raeburn   509: var stdeditbrowser;
                    510: 
                    511: function openauthorbrowser(formname,udom) {
                    512:     var url = '/adm/pickauthor?';
                    513:     url += 'form='+formname+'&roledom='+udom;
                    514:     var title = 'Author_Browser';
                    515:     var options = 'scrollbars=1,resizable=1,menubar=0';
                    516:     options += ',width=700,height=600';
                    517:     stdeditbrowser = open(url,title,options,'1');
                    518:     stdeditbrowser.focus();
                    519: }
                    520: 
1.824     bisitz    521: // ]]>
1.653     raeburn   522: </script>
                    523: ENDAUTHORBRW
                    524: }
                    525: 
1.91      www       526: sub coursebrowser_javascript {
1.909     raeburn   527:     my ($domainfilter,$sec_element,$formname,$role_element,$crstype) = @_;
1.932     raeburn   528:     my $wintitle = 'Course_Browser';
1.931     raeburn   529:     if ($crstype eq 'Community') {
1.932     raeburn   530:         $wintitle = 'Community_Browser';
1.909     raeburn   531:     }
1.876     raeburn   532:     my $id_functions = &javascript_index_functions();
                    533:     my $output = '
1.776     bisitz    534: <script type="text/javascript" language="JavaScript">
1.824     bisitz    535: // <![CDATA[
1.468     raeburn   536:     var stdeditbrowser;'."\n";
1.876     raeburn   537: 
                    538:     $output .= <<"ENDSTDBRW";
1.909     raeburn   539:     function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91      www       540:         var url = '/adm/pickcourse?';
1.895     raeburn   541:         var formid = getFormIdByName(formname);
1.876     raeburn   542:         var domainfilter = getDomainFromSelectbox(formname,udom);
1.128     albertel  543:         if (domainfilter != null) {
                    544:            if (domainfilter != '') {
                    545:                url += 'domainfilter='+domainfilter+'&';
                    546: 	   }
                    547:         }
1.91      www       548:         url += 'form=' + formname + '&cnumelement='+uname+
1.187     albertel  549: 	                            '&cdomelement='+udom+
                    550:                                     '&cnameelement='+desc;
1.468     raeburn   551:         if (extra_element !=null && extra_element != '') {
1.594     raeburn   552:             if (formname == 'rolechoice' || formname == 'studentform') {
1.468     raeburn   553:                 url += '&roleelement='+extra_element;
                    554:                 if (domainfilter == null || domainfilter == '') {
                    555:                     url += '&domainfilter='+extra_element;
                    556:                 }
1.234     raeburn   557:             }
1.468     raeburn   558:             else {
                    559:                 if (formname == 'portform') {
                    560:                     url += '&setroles='+extra_element;
1.800     raeburn   561:                 } else {
                    562:                     if (formname == 'rules') {
                    563:                         url += '&fixeddom='+extra_element; 
                    564:                     }
1.468     raeburn   565:                 }
                    566:             }     
1.230     raeburn   567:         }
1.909     raeburn   568:         if (type != null && type != '') {
                    569:             url += '&type='+type;
                    570:         }
                    571:         if (type_elem != null && type_elem != '') {
                    572:             url += '&typeelement='+type_elem;
                    573:         }
1.872     raeburn   574:         if (formname == 'ccrs') {
                    575:             var ownername = document.forms[formid].ccuname.value;
                    576:             var ownerdom =  document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
                    577:             url += '&cloner='+ownername+':'+ownerdom;
                    578:         }
1.293     raeburn   579:         if (multflag !=null && multflag != '') {
                    580:             url += '&multiple='+multflag;
                    581:         }
1.909     raeburn   582:         var title = '$wintitle';
1.91      www       583:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    584:         options += ',width=700,height=600';
                    585:         stdeditbrowser = open(url,title,options,'1');
                    586:         stdeditbrowser.focus();
                    587:     }
1.876     raeburn   588: $id_functions
                    589: ENDSTDBRW
1.905     raeburn   590:     if (($sec_element ne '') || ($role_element ne '')) {
                    591:         $output .= &setsec_javascript($sec_element,$formname,$role_element);
1.876     raeburn   592:     }
                    593:     $output .= '
                    594: // ]]>
                    595: </script>';
                    596:     return $output;
                    597: }
                    598: 
                    599: sub javascript_index_functions {
                    600:     return <<"ENDJS";
                    601: 
                    602: function getFormIdByName(formname) {
                    603:     for (var i=0;i<document.forms.length;i++) {
                    604:         if (document.forms[i].name == formname) {
                    605:             return i;
                    606:         }
                    607:     }
                    608:     return -1;
                    609: }
                    610: 
                    611: function getIndexByName(formid,item) {
                    612:     for (var i=0;i<document.forms[formid].elements.length;i++) {
                    613:         if (document.forms[formid].elements[i].name == item) {
                    614:             return i;
                    615:         }
                    616:     }
                    617:     return -1;
                    618: }
1.468     raeburn   619: 
1.876     raeburn   620: function getDomainFromSelectbox(formname,udom) {
                    621:     var userdom;
                    622:     var formid = getFormIdByName(formname);
                    623:     if (formid > -1) {
                    624:         var domid = getIndexByName(formid,udom);
                    625:         if (domid > -1) {
                    626:             if (document.forms[formid].elements[domid].type == 'select-one') {
                    627:                 userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
                    628:             }
                    629:             if (document.forms[formid].elements[domid].type == 'hidden') {
                    630:                 userdom=document.forms[formid].elements[domid].value;
1.468     raeburn   631:             }
                    632:         }
                    633:     }
1.876     raeburn   634:     return userdom;
                    635: }
                    636: 
                    637: ENDJS
1.468     raeburn   638: 
1.876     raeburn   639: }
                    640: 
1.1017    raeburn   641: sub javascript_array_indexof {
1.1018    raeburn   642:     return <<ENDJS;
1.1017    raeburn   643: <script type="text/javascript" language="JavaScript">
                    644: // <![CDATA[
                    645: 
                    646: if (!Array.prototype.indexOf) {
                    647:     Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
                    648:         "use strict";
                    649:         if (this === void 0 || this === null) {
                    650:             throw new TypeError();
                    651:         }
                    652:         var t = Object(this);
                    653:         var len = t.length >>> 0;
                    654:         if (len === 0) {
                    655:             return -1;
                    656:         }
                    657:         var n = 0;
                    658:         if (arguments.length > 0) {
                    659:             n = Number(arguments[1]);
                    660:             if (n !== n) { // shortcut for verifying if it's NaN
                    661:                 n = 0;
                    662:             } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
                    663:                 n = (n > 0 || -1) * Math.floor(Math.abs(n));
                    664:             }
                    665:         }
                    666:         if (n >= len) {
                    667:             return -1;
                    668:         }
                    669:         var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
                    670:         for (; k < len; k++) {
                    671:             if (k in t && t[k] === searchElement) {
                    672:                 return k;
                    673:             }
                    674:         }
                    675:         return -1;
                    676:     }
                    677: }
                    678: 
                    679: // ]]>
                    680: </script>
                    681: 
                    682: ENDJS
                    683: 
                    684: }
                    685: 
1.876     raeburn   686: sub userbrowser_javascript {
                    687:     my $id_functions = &javascript_index_functions();
                    688:     return <<"ENDUSERBRW";
                    689: 
1.888     raeburn   690: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876     raeburn   691:     var url = '/adm/pickuser?';
                    692:     var userdom = getDomainFromSelectbox(formname,udom);
                    693:     if (userdom != null) {
                    694:        if (userdom != '') {
                    695:            url += 'srchdom='+userdom+'&';
                    696:        }
                    697:     }
                    698:     url += 'form=' + formname + '&unameelement='+uname+
                    699:                                 '&udomelement='+udom+
                    700:                                 '&ulastelement='+ulast+
                    701:                                 '&ufirstelement='+ufirst+
                    702:                                 '&uemailelement='+uemail+
1.881     raeburn   703:                                 '&hideudomelement='+hideudom+
                    704:                                 '&coursedom='+crsdom;
1.888     raeburn   705:     if ((caller != null) && (caller != undefined)) {
                    706:         url += '&caller='+caller;
                    707:     }
1.876     raeburn   708:     var title = 'User_Browser';
                    709:     var options = 'scrollbars=1,resizable=1,menubar=0';
                    710:     options += ',width=700,height=600';
                    711:     var stdeditbrowser = open(url,title,options,'1');
                    712:     stdeditbrowser.focus();
                    713: }
                    714: 
1.888     raeburn   715: function fix_domain (formname,udom,origdom,uname) {
1.876     raeburn   716:     var formid = getFormIdByName(formname);
                    717:     if (formid > -1) {
1.888     raeburn   718:         var unameid = getIndexByName(formid,uname);
1.876     raeburn   719:         var domid = getIndexByName(formid,udom);
                    720:         var hidedomid = getIndexByName(formid,origdom);
                    721:         if (hidedomid > -1) {
                    722:             var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888     raeburn   723:             var unameval = document.forms[formid].elements[unameid].value;
                    724:             if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
                    725:                 if (domid > -1) {
                    726:                     var slct = document.forms[formid].elements[domid];
                    727:                     if (slct.type == 'select-one') {
                    728:                         var i;
                    729:                         for (i=0;i<slct.length;i++) {
                    730:                             if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
                    731:                         }
                    732:                     }
                    733:                     if (slct.type == 'hidden') {
                    734:                         slct.value = fixeddom;
1.876     raeburn   735:                     }
                    736:                 }
1.468     raeburn   737:             }
                    738:         }
                    739:     }
1.876     raeburn   740:     return;
                    741: }
                    742: 
                    743: $id_functions
                    744: ENDUSERBRW
1.468     raeburn   745: }
                    746: 
                    747: sub setsec_javascript {
1.905     raeburn   748:     my ($sec_element,$formname,$role_element) = @_;
                    749:     my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
                    750:         $communityrolestr);
                    751:     if ($role_element ne '') {
                    752:         my @allroles = ('st','ta','ep','in','ad');
                    753:         foreach my $crstype ('Course','Community') {
                    754:             if ($crstype eq 'Community') {
                    755:                 foreach my $role (@allroles) {
                    756:                     push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
                    757:                 }
                    758:                 push(@communityrolenames,&Apache::lonnet::plaintext('co'));
                    759:             } else {
                    760:                 foreach my $role (@allroles) {
                    761:                     push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
                    762:                 }
                    763:                 push(@courserolenames,&Apache::lonnet::plaintext('cc'));
                    764:             }
                    765:         }
                    766:         $rolestr = '"'.join('","',@allroles).'"';
                    767:         $courserolestr = '"'.join('","',@courserolenames).'"';
                    768:         $communityrolestr = '"'.join('","',@communityrolenames).'"';
                    769:     }
1.468     raeburn   770:     my $setsections = qq|
                    771: function setSect(sectionlist) {
1.629     raeburn   772:     var sectionsArray = new Array();
                    773:     if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
                    774:         sectionsArray = sectionlist.split(",");
                    775:     }
1.468     raeburn   776:     var numSections = sectionsArray.length;
                    777:     document.$formname.$sec_element.length = 0;
                    778:     if (numSections == 0) {
                    779:         document.$formname.$sec_element.multiple=false;
                    780:         document.$formname.$sec_element.size=1;
                    781:         document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
                    782:     } else {
                    783:         if (numSections == 1) {
                    784:             document.$formname.$sec_element.multiple=false;
                    785:             document.$formname.$sec_element.size=1;
                    786:             document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
                    787:             document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
                    788:             document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
                    789:         } else {
                    790:             for (var i=0; i<numSections; i++) {
                    791:                 document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
                    792:             }
                    793:             document.$formname.$sec_element.multiple=true
                    794:             if (numSections < 3) {
                    795:                 document.$formname.$sec_element.size=numSections;
                    796:             } else {
                    797:                 document.$formname.$sec_element.size=3;
                    798:             }
                    799:             document.$formname.$sec_element.options[0].selected = false
                    800:         }
                    801:     }
1.91      www       802: }
1.905     raeburn   803: 
                    804: function setRole(crstype) {
1.468     raeburn   805: |;
1.905     raeburn   806:     if ($role_element eq '') {
                    807:         $setsections .= '    return;
                    808: }
                    809: ';
                    810:     } else {
                    811:         $setsections .= qq|
                    812:     var elementLength = document.$formname.$role_element.length;
                    813:     var allroles = Array($rolestr);
                    814:     var courserolenames = Array($courserolestr);
                    815:     var communityrolenames = Array($communityrolestr);
                    816:     if (elementLength != undefined) {
                    817:         if (document.$formname.$role_element.options[5].value == 'cc') {
                    818:             if (crstype == 'Course') {
                    819:                 return;
                    820:             } else {
                    821:                 allroles[5] = 'co';
                    822:                 for (var i=0; i<6; i++) {
                    823:                     document.$formname.$role_element.options[i].value = allroles[i];
                    824:                     document.$formname.$role_element.options[i].text = communityrolenames[i];
                    825:                 }
                    826:             }
                    827:         } else {
                    828:             if (crstype == 'Community') {
                    829:                 return;
                    830:             } else {
                    831:                 allroles[5] = 'cc';
                    832:                 for (var i=0; i<6; i++) {
                    833:                     document.$formname.$role_element.options[i].value = allroles[i];
                    834:                     document.$formname.$role_element.options[i].text = courserolenames[i];
                    835:                 }
                    836:             }
                    837:         }
                    838:     }
                    839:     return;
                    840: }
                    841: |;
                    842:     }
1.468     raeburn   843:     return $setsections;
                    844: }
                    845: 
1.91      www       846: sub selectcourse_link {
1.909     raeburn   847:    my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
                    848:        $typeelement) = @_;
                    849:    my $type = $selecttype;
1.871     raeburn   850:    my $linktext = &mt('Select Course');
                    851:    if ($selecttype eq 'Community') {
1.909     raeburn   852:        $linktext = &mt('Select Community');
1.906     raeburn   853:    } elsif ($selecttype eq 'Course/Community') {
                    854:        $linktext = &mt('Select Course/Community');
1.909     raeburn   855:        $type = '';
1.1019    raeburn   856:    } elsif ($selecttype eq 'Select') {
                    857:        $linktext = &mt('Select');
                    858:        $type = '';
1.871     raeburn   859:    }
1.787     bisitz    860:    return '<span class="LC_nobreak">'
                    861:          ."<a href='"
                    862:          .'javascript:opencrsbrowser("'.$form.'","'.$unameele
                    863:          .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909     raeburn   864:          .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871     raeburn   865:          ."'>".$linktext.'</a>'
1.787     bisitz    866:          .'</span>';
1.74      www       867: }
1.42      matthew   868: 
1.653     raeburn   869: sub selectauthor_link {
                    870:    my ($form,$udom)=@_;
                    871:    return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
                    872:           &mt('Select Author').'</a>';
                    873: }
                    874: 
1.876     raeburn   875: sub selectuser_link {
1.881     raeburn   876:     my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888     raeburn   877:         $coursedom,$linktext,$caller) = @_;
1.876     raeburn   878:     return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888     raeburn   879:            "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881     raeburn   880:            ');">'.$linktext.'</a>';
1.876     raeburn   881: }
                    882: 
1.273     raeburn   883: sub check_uncheck_jscript {
                    884:     my $jscript = <<"ENDSCRT";
                    885: function checkAll(field) {
                    886:     if (field.length > 0) {
                    887:         for (i = 0; i < field.length; i++) {
                    888:             field[i].checked = true ;
                    889:         }
                    890:     } else {
                    891:         field.checked = true
                    892:     }
                    893: }
                    894:  
                    895: function uncheckAll(field) {
                    896:     if (field.length > 0) {
                    897:         for (i = 0; i < field.length; i++) {
                    898:             field[i].checked = false ;
1.543     albertel  899:         }
                    900:     } else {
1.273     raeburn   901:         field.checked = false ;
                    902:     }
                    903: }
                    904: ENDSCRT
                    905:     return $jscript;
                    906: }
                    907: 
1.656     www       908: sub select_timezone {
1.659     raeburn   909:    my ($name,$selected,$onchange,$includeempty)=@_;
                    910:    my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    911:    if ($includeempty) {
                    912:        $output .= '<option value=""';
                    913:        if (($selected eq '') || ($selected eq 'local')) {
                    914:            $output .= ' selected="selected" ';
                    915:        }
                    916:        $output .= '> </option>';
                    917:    }
1.657     raeburn   918:    my @timezones = DateTime::TimeZone->all_names;
                    919:    foreach my $tzone (@timezones) {
                    920:        $output.= '<option value="'.$tzone.'"';
                    921:        if ($tzone eq $selected) {
                    922:            $output.=' selected="selected"';
                    923:        }
                    924:        $output.=">$tzone</option>\n";
1.656     www       925:    }
                    926:    $output.="</select>";
                    927:    return $output;
                    928: }
1.273     raeburn   929: 
1.687     raeburn   930: sub select_datelocale {
                    931:     my ($name,$selected,$onchange,$includeempty)=@_;
                    932:     my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    933:     if ($includeempty) {
                    934:         $output .= '<option value=""';
                    935:         if ($selected eq '') {
                    936:             $output .= ' selected="selected" ';
                    937:         }
                    938:         $output .= '> </option>';
                    939:     }
                    940:     my (@possibles,%locale_names);
                    941:     my @locales = DateTime::Locale::Catalog::Locales;
                    942:     foreach my $locale (@locales) {
                    943:         if (ref($locale) eq 'HASH') {
                    944:             my $id = $locale->{'id'};
                    945:             if ($id ne '') {
                    946:                 my $en_terr = $locale->{'en_territory'};
                    947:                 my $native_terr = $locale->{'native_territory'};
1.695     raeburn   948:                 my @languages = &Apache::lonlocal::preferred_languages();
1.687     raeburn   949:                 if (grep(/^en$/,@languages) || !@languages) {
                    950:                     if ($en_terr ne '') {
                    951:                         $locale_names{$id} = '('.$en_terr.')';
                    952:                     } elsif ($native_terr ne '') {
                    953:                         $locale_names{$id} = $native_terr;
                    954:                     }
                    955:                 } else {
                    956:                     if ($native_terr ne '') {
                    957:                         $locale_names{$id} = $native_terr.' ';
                    958:                     } elsif ($en_terr ne '') {
                    959:                         $locale_names{$id} = '('.$en_terr.')';
                    960:                     }
                    961:                 }
                    962:                 push (@possibles,$id);
                    963:             }
                    964:         }
                    965:     }
                    966:     foreach my $item (sort(@possibles)) {
                    967:         $output.= '<option value="'.$item.'"';
                    968:         if ($item eq $selected) {
                    969:             $output.=' selected="selected"';
                    970:         }
                    971:         $output.=">$item";
                    972:         if ($locale_names{$item} ne '') {
                    973:             $output.="  $locale_names{$item}</option>\n";
                    974:         }
                    975:         $output.="</option>\n";
                    976:     }
                    977:     $output.="</select>";
                    978:     return $output;
                    979: }
                    980: 
1.792     raeburn   981: sub select_language {
                    982:     my ($name,$selected,$includeempty) = @_;
                    983:     my %langchoices;
                    984:     if ($includeempty) {
                    985:         %langchoices = ('' => 'No language preference');
                    986:     }
                    987:     foreach my $id (&languageids()) {
                    988:         my $code = &supportedlanguagecode($id);
                    989:         if ($code) {
                    990:             $langchoices{$code} = &plainlanguagedescription($id);
                    991:         }
                    992:     }
1.970     raeburn   993:     return &select_form($selected,$name,\%langchoices);
1.792     raeburn   994: }
                    995: 
1.42      matthew   996: =pod
1.36      matthew   997: 
1.648     raeburn   998: =item * &linked_select_forms(...)
1.36      matthew   999: 
                   1000: linked_select_forms returns a string containing a <script></script> block
                   1001: and html for two <select> menus.  The select menus will be linked in that
                   1002: changing the value of the first menu will result in new values being placed
                   1003: in the second menu.  The values in the select menu will appear in alphabetical
1.609     raeburn  1004: order unless a defined order is provided.
1.36      matthew  1005: 
                   1006: linked_select_forms takes the following ordered inputs:
                   1007: 
                   1008: =over 4
                   1009: 
1.112     bowersj2 1010: =item * $formname, the name of the <form> tag
1.36      matthew  1011: 
1.112     bowersj2 1012: =item * $middletext, the text which appears between the <select> tags
1.36      matthew  1013: 
1.112     bowersj2 1014: =item * $firstdefault, the default value for the first menu
1.36      matthew  1015: 
1.112     bowersj2 1016: =item * $firstselectname, the name of the first <select> tag
1.36      matthew  1017: 
1.112     bowersj2 1018: =item * $secondselectname, the name of the second <select> tag
1.36      matthew  1019: 
1.112     bowersj2 1020: =item * $hashref, a reference to a hash containing the data for the menus.
1.36      matthew  1021: 
1.609     raeburn  1022: =item * $menuorder, the order of values in the first menu
                   1023: 
1.41      ng       1024: =back 
                   1025: 
1.36      matthew  1026: Below is an example of such a hash.  Only the 'text', 'default', and 
                   1027: 'select2' keys must appear as stated.  keys(%menu) are the possible 
                   1028: values for the first select menu.  The text that coincides with the 
1.41      ng       1029: first menu value is given in $menu{$choice1}->{'text'}.  The values 
1.36      matthew  1030: and text for the second menu are given in the hash pointed to by 
                   1031: $menu{$choice1}->{'select2'}.  
                   1032: 
1.112     bowersj2 1033:  my %menu = ( A1 => { text =>"Choice A1" ,
                   1034:                        default => "B3",
                   1035:                        select2 => { 
                   1036:                            B1 => "Choice B1",
                   1037:                            B2 => "Choice B2",
                   1038:                            B3 => "Choice B3",
                   1039:                            B4 => "Choice B4"
1.609     raeburn  1040:                            },
                   1041:                        order => ['B4','B3','B1','B2'],
1.112     bowersj2 1042:                    },
                   1043:                A2 => { text =>"Choice A2" ,
                   1044:                        default => "C2",
                   1045:                        select2 => { 
                   1046:                            C1 => "Choice C1",
                   1047:                            C2 => "Choice C2",
                   1048:                            C3 => "Choice C3"
1.609     raeburn  1049:                            },
                   1050:                        order => ['C2','C1','C3'],
1.112     bowersj2 1051:                    },
                   1052:                A3 => { text =>"Choice A3" ,
                   1053:                        default => "D6",
                   1054:                        select2 => { 
                   1055:                            D1 => "Choice D1",
                   1056:                            D2 => "Choice D2",
                   1057:                            D3 => "Choice D3",
                   1058:                            D4 => "Choice D4",
                   1059:                            D5 => "Choice D5",
                   1060:                            D6 => "Choice D6",
                   1061:                            D7 => "Choice D7"
1.609     raeburn  1062:                            },
                   1063:                        order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112     bowersj2 1064:                    }
                   1065:                );
1.36      matthew  1066: 
                   1067: =cut
                   1068: 
                   1069: sub linked_select_forms {
                   1070:     my ($formname,
                   1071:         $middletext,
                   1072:         $firstdefault,
                   1073:         $firstselectname,
                   1074:         $secondselectname, 
1.609     raeburn  1075:         $hashref,
                   1076:         $menuorder,
1.36      matthew  1077:         ) = @_;
                   1078:     my $second = "document.$formname.$secondselectname";
                   1079:     my $first = "document.$formname.$firstselectname";
                   1080:     # output the javascript to do the changing
                   1081:     my $result = '';
1.776     bisitz   1082:     $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824     bisitz   1083:     $result.="// <![CDATA[\n";
1.36      matthew  1084:     $result.="var select2data = new Object();\n";
                   1085:     $" = '","';
                   1086:     my $debug = '';
                   1087:     foreach my $s1 (sort(keys(%$hashref))) {
                   1088:         $result.="select2data.d_$s1 = new Object();\n";        
                   1089:         $result.="select2data.d_$s1.def = new String('".
                   1090:             $hashref->{$s1}->{'default'}."');\n";
1.609     raeburn  1091:         $result.="select2data.d_$s1.values = new Array(";
1.36      matthew  1092:         my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609     raeburn  1093:         if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
                   1094:             @s2values = @{$hashref->{$s1}->{'order'}};
                   1095:         }
1.36      matthew  1096:         $result.="\"@s2values\");\n";
                   1097:         $result.="select2data.d_$s1.texts = new Array(";        
                   1098:         my @s2texts;
                   1099:         foreach my $value (@s2values) {
                   1100:             push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
                   1101:         }
                   1102:         $result.="\"@s2texts\");\n";
                   1103:     }
                   1104:     $"=' ';
                   1105:     $result.= <<"END";
                   1106: 
                   1107: function select1_changed() {
                   1108:     // Determine new choice
                   1109:     var newvalue = "d_" + $first.value;
                   1110:     // update select2
                   1111:     var values     = select2data[newvalue].values;
                   1112:     var texts      = select2data[newvalue].texts;
                   1113:     var select2def = select2data[newvalue].def;
                   1114:     var i;
                   1115:     // out with the old
                   1116:     for (i = 0; i < $second.options.length; i++) {
                   1117:         $second.options[i] = null;
                   1118:     }
                   1119:     // in with the nuclear
                   1120:     for (i=0;i<values.length; i++) {
                   1121:         $second.options[i] = new Option(values[i]);
1.143     matthew  1122:         $second.options[i].value = values[i];
1.36      matthew  1123:         $second.options[i].text = texts[i];
                   1124:         if (values[i] == select2def) {
                   1125:             $second.options[i].selected = true;
                   1126:         }
                   1127:     }
                   1128: }
1.824     bisitz   1129: // ]]>
1.36      matthew  1130: </script>
                   1131: END
                   1132:     # output the initial values for the selection lists
                   1133:     $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609     raeburn  1134:     my @order = sort(keys(%{$hashref}));
                   1135:     if (ref($menuorder) eq 'ARRAY') {
                   1136:         @order = @{$menuorder};
                   1137:     }
                   1138:     foreach my $value (@order) {
1.36      matthew  1139:         $result.="    <option value=\"$value\" ";
1.253     albertel 1140:         $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119     www      1141:         $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36      matthew  1142:     }
                   1143:     $result .= "</select>\n";
                   1144:     my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
                   1145:     $result .= $middletext;
                   1146:     $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
                   1147:     my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609     raeburn  1148:     
                   1149:     my @secondorder = sort(keys(%select2));
                   1150:     if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
                   1151:         @secondorder = @{$hashref->{$firstdefault}->{'order'}};
                   1152:     }
                   1153:     foreach my $value (@secondorder) {
1.36      matthew  1154:         $result.="    <option value=\"$value\" ";        
1.253     albertel 1155:         $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119     www      1156:         $result.=">".&mt($select2{$value})."</option>\n";
1.36      matthew  1157:     }
                   1158:     $result .= "</select>\n";
                   1159:     #    return $debug;
                   1160:     return $result;
                   1161: }   #  end of sub linked_select_forms {
                   1162: 
1.45      matthew  1163: =pod
1.44      bowersj2 1164: 
1.973     raeburn  1165: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44      bowersj2 1166: 
1.112     bowersj2 1167: Returns a string corresponding to an HTML link to the given help
                   1168: $topic, where $topic corresponds to the name of a .tex file in
                   1169: /home/httpd/html/adm/help/tex, with underscores replaced by
                   1170: spaces. 
                   1171: 
                   1172: $text will optionally be linked to the same topic, allowing you to
                   1173: link text in addition to the graphic. If you do not want to link
                   1174: text, but wish to specify one of the later parameters, pass an
                   1175: empty string. 
                   1176: 
                   1177: $stayOnPage is a value that will be interpreted as a boolean. If true,
                   1178: the link will not open a new window. If false, the link will open
                   1179: a new window using Javascript. (Default is false.) 
                   1180: 
                   1181: $width and $height are optional numerical parameters that will
                   1182: override the width and height of the popped up window, which may
1.973     raeburn  1183: be useful for certain help topics with big pictures included.
                   1184: 
                   1185: $imgid is the id of the img tag used for the help icon. This may be
                   1186: used in a javascript call to switch the image src.  See 
                   1187: lonhtmlcommon::htmlareaselectactive() for an example.
1.44      bowersj2 1188: 
                   1189: =cut
                   1190: 
                   1191: sub help_open_topic {
1.973     raeburn  1192:     my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48      bowersj2 1193:     $text = "" if (not defined $text);
1.44      bowersj2 1194:     $stayOnPage = 0 if (not defined $stayOnPage);
1.1033    www      1195:     $width = 500 if (not defined $width);
1.44      bowersj2 1196:     $height = 400 if (not defined $height);
                   1197:     my $filename = $topic;
                   1198:     $filename =~ s/ /_/g;
                   1199: 
1.48      bowersj2 1200:     my $template = "";
                   1201:     my $link;
1.572     banghart 1202:     
1.159     www      1203:     $topic=~s/\W/\_/g;
1.44      bowersj2 1204: 
1.572     banghart 1205:     if (!$stayOnPage) {
1.1033    www      1206: 	$link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037    www      1207:     } elsif ($stayOnPage eq 'popup') {
                   1208:         $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 1209:     } else {
1.48      bowersj2 1210: 	$link = "/adm/help/${filename}.hlp";
                   1211:     }
                   1212: 
                   1213:     # Add the text
1.755     neumanie 1214:     if ($text ne "") {	
1.763     bisitz   1215: 	$template.='<span class="LC_help_open_topic">'
                   1216:                   .'<a target="_top" href="'.$link.'">'
                   1217:                   .$text.'</a>';
1.48      bowersj2 1218:     }
                   1219: 
1.763     bisitz   1220:     # (Always) Add the graphic
1.179     matthew  1221:     my $title = &mt('Online Help');
1.667     raeburn  1222:     my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973     raeburn  1223:     if ($imgid ne '') {
                   1224:         $imgid = ' id="'.$imgid.'"';
                   1225:     }
1.763     bisitz   1226:     $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
                   1227:               .'<img src="'.$helpicon.'" border="0"'
                   1228:               .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973     raeburn  1229:               .' title="'.$title.'" style="vertical-align:middle;"'.$imgid 
1.763     bisitz   1230:               .' /></a>';
                   1231:     if ($text ne "") {	
                   1232:         $template.='</span>';
                   1233:     }
1.44      bowersj2 1234:     return $template;
                   1235: 
1.106     bowersj2 1236: }
                   1237: 
                   1238: # This is a quicky function for Latex cheatsheet editing, since it 
                   1239: # appears in at least four places
                   1240: sub helpLatexCheatsheet {
1.1037    www      1241:     my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732     raeburn  1242:     my $out;
1.106     bowersj2 1243:     my $addOther = '';
1.732     raeburn  1244:     if ($topic) {
1.1037    www      1245: 	$addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763     bisitz   1246:     }
                   1247:     $out = '<span>' # Start cheatsheet
                   1248: 	  .$addOther
                   1249:           .'<span>'
1.1037    www      1250: 	  .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763     bisitz   1251: 	  .'</span> <span>'
1.1037    www      1252: 	  .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763     bisitz   1253: 	  .'</span>';
1.732     raeburn  1254:     unless ($not_author) {
1.763     bisitz   1255:         $out .= ' <span>'
1.1037    www      1256: 	       .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1.763     bisitz   1257: 	       .'</span>';
1.732     raeburn  1258:     }
1.763     bisitz   1259:     $out .= '</span>'; # End cheatsheet
1.732     raeburn  1260:     return $out;
1.172     www      1261: }
                   1262: 
1.430     albertel 1263: sub general_help {
                   1264:     my $helptopic='Student_Intro';
                   1265:     if ($env{'request.role'}=~/^(ca|au)/) {
                   1266: 	$helptopic='Authoring_Intro';
1.907     raeburn  1267:     } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430     albertel 1268: 	$helptopic='Course_Coordination_Intro';
1.672     raeburn  1269:     } elsif ($env{'request.role'}=~/^dc/) {
                   1270:         $helptopic='Domain_Coordination_Intro';
1.430     albertel 1271:     }
                   1272:     return $helptopic;
                   1273: }
                   1274: 
                   1275: sub update_help_link {
                   1276:     my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
                   1277:     my $origurl = $ENV{'REQUEST_URI'};
                   1278:     $origurl=~s|^/~|/priv/|;
                   1279:     my $timestamp = time;
                   1280:     foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
                   1281:         $$datum = &escape($$datum);
                   1282:     }
                   1283: 
                   1284:     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";
                   1285:     my $output .= <<"ENDOUTPUT";
                   1286: <script type="text/javascript">
1.824     bisitz   1287: // <![CDATA[
1.430     albertel 1288: banner_link = '$banner_link';
1.824     bisitz   1289: // ]]>
1.430     albertel 1290: </script>
                   1291: ENDOUTPUT
                   1292:     return $output;
                   1293: }
                   1294: 
                   1295: # now just updates the help link and generates a blue icon
1.193     raeburn  1296: sub help_open_menu {
1.430     albertel 1297:     my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text) 
1.552     banghart 1298: 	= @_;    
1.949     droeschl 1299:     $stayOnPage = 1;
1.430     albertel 1300:     my $output;
                   1301:     if ($component_help) {
                   1302: 	if (!$text) {
                   1303: 	    $output=&help_open_topic($component_help,undef,$stayOnPage,
                   1304: 				       $width,$height);
                   1305: 	} else {
                   1306: 	    my $help_text;
                   1307: 	    $help_text=&unescape($topic);
                   1308: 	    $output='<table><tr><td>'.
                   1309: 		&help_open_topic($component_help,$help_text,$stayOnPage,
                   1310: 				 $width,$height).'</td></tr></table>';
                   1311: 	}
                   1312:     }
                   1313:     my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
                   1314:     return $output.$banner_link;
                   1315: }
                   1316: 
                   1317: sub top_nav_help {
                   1318:     my ($text) = @_;
1.436     albertel 1319:     $text = &mt($text);
1.949     droeschl 1320:     my $stay_on_page = 1;
                   1321: 
1.572     banghart 1322:     my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436     albertel 1323: 	                     : "javascript:helpMenu('open')";
1.572     banghart 1324:     my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436     albertel 1325: 
1.201     raeburn  1326:     my $title = &mt('Get help');
1.436     albertel 1327: 
                   1328:     return <<"END";
                   1329: $banner_link
                   1330:  <a href="$link" title="$title">$text</a>
                   1331: END
                   1332: }
                   1333: 
                   1334: sub help_menu_js {
                   1335:     my ($text) = @_;
1.949     droeschl 1336:     my $stayOnPage = 1;
1.436     albertel 1337:     my $width = 620;
                   1338:     my $height = 600;
1.430     albertel 1339:     my $helptopic=&general_help();
                   1340:     my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261     albertel 1341:     my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331     albertel 1342:     my $start_page =
                   1343:         &Apache::loncommon::start_page('Help Menu', undef,
                   1344: 				       {'frameset'    => 1,
                   1345: 					'js_ready'    => 1,
                   1346: 					'add_entries' => {
                   1347: 					    'border' => '0',
1.579     raeburn  1348: 					    'rows'   => "110,*",},});
1.331     albertel 1349:     my $end_page =
                   1350:         &Apache::loncommon::end_page({'frameset' => 1,
                   1351: 				      'js_ready' => 1,});
                   1352: 
1.436     albertel 1353:     my $template .= <<"ENDTEMPLATE";
                   1354: <script type="text/javascript">
1.877     bisitz   1355: // <![CDATA[
1.253     albertel 1356: // <!-- BEGIN LON-CAPA Internal
1.430     albertel 1357: var banner_link = '';
1.243     raeburn  1358: function helpMenu(target) {
                   1359:     var caller = this;
                   1360:     if (target == 'open') {
                   1361:         var newWindow = null;
                   1362:         try {
1.262     albertel 1363:             newWindow =  window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243     raeburn  1364:         }
                   1365:         catch(error) {
                   1366:             writeHelp(caller);
                   1367:             return;
                   1368:         }
                   1369:         if (newWindow) {
                   1370:             caller = newWindow;
                   1371:         }
1.193     raeburn  1372:     }
1.243     raeburn  1373:     writeHelp(caller);
                   1374:     return;
                   1375: }
                   1376: function writeHelp(caller) {
1.1072    raeburn  1377:     caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" />\\n<frame name="bodyframe" src="$details_link" />\\n$end_page')
1.243     raeburn  1378:     caller.document.close()
                   1379:     caller.focus()
1.193     raeburn  1380: }
1.877     bisitz   1381: // END LON-CAPA Internal -->
1.253     albertel 1382: // ]]>
1.436     albertel 1383: </script>
1.193     raeburn  1384: ENDTEMPLATE
                   1385:     return $template;
                   1386: }
                   1387: 
1.172     www      1388: sub help_open_bug {
                   1389:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1390:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1391:     unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
                   1392:     $text = "" if (not defined $text);
                   1393: 	$stayOnPage=1;
1.184     albertel 1394:     $width = 600 if (not defined $width);
                   1395:     $height = 600 if (not defined $height);
1.172     www      1396: 
                   1397:     $topic=~s/\W+/\+/g;
                   1398:     my $link='';
                   1399:     my $template='';
1.379     albertel 1400:     my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&amp;bug_file_loc='.
                   1401: 	&escape($ENV{'REQUEST_URI'}).'&amp;component='.$topic;
1.172     www      1402:     if (!$stayOnPage)
                   1403:     {
                   1404: 	$link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1405:     }
                   1406:     else
                   1407:     {
                   1408: 	$link = $url;
                   1409:     }
                   1410:     # Add the text
                   1411:     if ($text ne "")
                   1412:     {
                   1413: 	$template .= 
                   1414:   "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1415:   "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172     www      1416:     }
                   1417: 
                   1418:     # Add the graphic
1.179     matthew  1419:     my $title = &mt('Report a Bug');
1.215     albertel 1420:     my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172     www      1421:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1422:  <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172     www      1423: ENDTEMPLATE
                   1424:     if ($text ne '') { $template.='</td></tr></table>' };
                   1425:     return $template;
                   1426: 
                   1427: }
                   1428: 
                   1429: sub help_open_faq {
                   1430:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1431:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1432:     unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
                   1433:     $text = "" if (not defined $text);
                   1434: 	$stayOnPage=1;
                   1435:     $width = 350 if (not defined $width);
                   1436:     $height = 400 if (not defined $height);
                   1437: 
                   1438:     $topic=~s/\W+/\+/g;
                   1439:     my $link='';
                   1440:     my $template='';
                   1441:     my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
                   1442:     if (!$stayOnPage)
                   1443:     {
                   1444: 	$link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1445:     }
                   1446:     else
                   1447:     {
                   1448: 	$link = $url;
                   1449:     }
                   1450: 
                   1451:     # Add the text
                   1452:     if ($text ne "")
                   1453:     {
                   1454: 	$template .= 
1.173     www      1455:   "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1456:   "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172     www      1457:     }
                   1458: 
                   1459:     # Add the graphic
1.179     matthew  1460:     my $title = &mt('View the FAQ');
1.215     albertel 1461:     my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172     www      1462:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1463:  <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172     www      1464: ENDTEMPLATE
                   1465:     if ($text ne '') { $template.='</td></tr></table>' };
                   1466:     return $template;
                   1467: 
1.44      bowersj2 1468: }
1.37      matthew  1469: 
1.180     matthew  1470: ###############################################################
                   1471: ###############################################################
                   1472: 
1.45      matthew  1473: =pod
                   1474: 
1.648     raeburn  1475: =item * &change_content_javascript():
1.256     matthew  1476: 
                   1477: This and the next function allow you to create small sections of an
                   1478: otherwise static HTML page that you can update on the fly with
                   1479: Javascript, even in Netscape 4.
                   1480: 
                   1481: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
                   1482: must be written to the HTML page once. It will prove the Javascript
                   1483: function "change(name, content)". Calling the change function with the
                   1484: name of the section 
                   1485: you want to update, matching the name passed to C<changable_area>, and
                   1486: the new content you want to put in there, will put the content into
                   1487: that area.
                   1488: 
                   1489: B<Note>: Netscape 4 only reserves enough space for the changable area
                   1490: to contain room for the original contents. You need to "make space"
                   1491: for whatever changes you wish to make, and be B<sure> to check your
                   1492: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
                   1493: it's adequate for updating a one-line status display, but little more.
                   1494: This script will set the space to 100% width, so you only need to
                   1495: worry about height in Netscape 4.
                   1496: 
                   1497: Modern browsers are much less limiting, and if you can commit to the
                   1498: user not using Netscape 4, this feature may be used freely with
                   1499: pretty much any HTML.
                   1500: 
                   1501: =cut
                   1502: 
                   1503: sub change_content_javascript {
                   1504:     # If we're on Netscape 4, we need to use Layer-based code
1.258     albertel 1505:     if ($env{'browser.type'} eq 'netscape' &&
                   1506: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1507: 	return (<<NETSCAPE4);
                   1508: 	function change(name, content) {
                   1509: 	    doc = document.layers[name+"___escape"].layers[0].document;
                   1510: 	    doc.open();
                   1511: 	    doc.write(content);
                   1512: 	    doc.close();
                   1513: 	}
                   1514: NETSCAPE4
                   1515:     } else {
                   1516: 	# Otherwise, we need to use semi-standards-compliant code
                   1517: 	# (technically, "innerHTML" isn't standard but the equivalent
                   1518: 	# is really scary, and every useful browser supports it
                   1519: 	return (<<DOMBASED);
                   1520: 	function change(name, content) {
                   1521: 	    element = document.getElementById(name);
                   1522: 	    element.innerHTML = content;
                   1523: 	}
                   1524: DOMBASED
                   1525:     }
                   1526: }
                   1527: 
                   1528: =pod
                   1529: 
1.648     raeburn  1530: =item * &changable_area($name,$origContent):
1.256     matthew  1531: 
                   1532: This provides a "changable area" that can be modified on the fly via
                   1533: the Javascript code provided in C<change_content_javascript>. $name is
                   1534: the name you will use to reference the area later; do not repeat the
                   1535: same name on a given HTML page more then once. $origContent is what
                   1536: the area will originally contain, which can be left blank.
                   1537: 
                   1538: =cut
                   1539: 
                   1540: sub changable_area {
                   1541:     my ($name, $origContent) = @_;
                   1542: 
1.258     albertel 1543:     if ($env{'browser.type'} eq 'netscape' &&
                   1544: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1545: 	# If this is netscape 4, we need to use the Layer tag
                   1546: 	return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
                   1547:     } else {
                   1548: 	return "<span id='$name'>$origContent</span>";
                   1549:     }
                   1550: }
                   1551: 
                   1552: =pod
                   1553: 
1.648     raeburn  1554: =item * &viewport_geometry_js 
1.590     raeburn  1555: 
                   1556: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
                   1557: 
                   1558: =cut
                   1559: 
                   1560: 
                   1561: sub viewport_geometry_js { 
                   1562:     return <<"GEOMETRY";
                   1563: var Geometry = {};
                   1564: function init_geometry() {
                   1565:     if (Geometry.init) { return };
                   1566:     Geometry.init=1;
                   1567:     if (window.innerHeight) {
                   1568:         Geometry.getViewportHeight   = function() { return window.innerHeight; };
                   1569:         Geometry.getViewportWidth   = function() { return window.innerWidth; };
                   1570:         Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
                   1571:         Geometry.getVerticalScroll   = function() { return window.pageYOffset; };
                   1572:     }
                   1573:     else if (document.documentElement && document.documentElement.clientHeight) {
                   1574:         Geometry.getViewportHeight =
                   1575:             function() { return document.documentElement.clientHeight; };
                   1576:         Geometry.getViewportWidth =
                   1577:             function() { return document.documentElement.clientWidth; };
                   1578: 
                   1579:         Geometry.getHorizontalScroll =
                   1580:             function() { return document.documentElement.scrollLeft; };
                   1581:         Geometry.getVerticalScroll =
                   1582:             function() { return document.documentElement.scrollTop; };
                   1583:     }
                   1584:     else if (document.body.clientHeight) {
                   1585:         Geometry.getViewportHeight =
                   1586:             function() { return document.body.clientHeight; };
                   1587:         Geometry.getViewportWidth =
                   1588:             function() { return document.body.clientWidth; };
                   1589:         Geometry.getHorizontalScroll =
                   1590:             function() { return document.body.scrollLeft; };
                   1591:         Geometry.getVerticalScroll =
                   1592:             function() { return document.body.scrollTop; };
                   1593:     }
                   1594: }
                   1595: 
                   1596: GEOMETRY
                   1597: }
                   1598: 
                   1599: =pod
                   1600: 
1.648     raeburn  1601: =item * &viewport_size_js()
1.590     raeburn  1602: 
                   1603: 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. 
                   1604: 
                   1605: =cut
                   1606: 
                   1607: sub viewport_size_js {
                   1608:     my $geometry = &viewport_geometry_js();
                   1609:     return <<"DIMS";
                   1610: 
                   1611: $geometry
                   1612: 
                   1613: function getViewportDims(width,height) {
                   1614:     init_geometry();
                   1615:     width.value = Geometry.getViewportWidth();
                   1616:     height.value = Geometry.getViewportHeight();
                   1617:     return;
                   1618: }
                   1619: 
                   1620: DIMS
                   1621: }
                   1622: 
                   1623: =pod
                   1624: 
1.648     raeburn  1625: =item * &resize_textarea_js()
1.565     albertel 1626: 
                   1627: emits the needed javascript to resize a textarea to be as big as possible
                   1628: 
                   1629: creates a function resize_textrea that takes two IDs first should be
                   1630: the id of the element to resize, second should be the id of a div that
                   1631: surrounds everything that comes after the textarea, this routine needs
                   1632: to be attached to the <body> for the onload and onresize events.
                   1633: 
1.648     raeburn  1634: =back
1.565     albertel 1635: 
                   1636: =cut
                   1637: 
                   1638: sub resize_textarea_js {
1.590     raeburn  1639:     my $geometry = &viewport_geometry_js();
1.565     albertel 1640:     return <<"RESIZE";
                   1641:     <script type="text/javascript">
1.824     bisitz   1642: // <![CDATA[
1.590     raeburn  1643: $geometry
1.565     albertel 1644: 
1.588     albertel 1645: function getX(element) {
                   1646:     var x = 0;
                   1647:     while (element) {
                   1648: 	x += element.offsetLeft;
                   1649: 	element = element.offsetParent;
                   1650:     }
                   1651:     return x;
                   1652: }
                   1653: function getY(element) {
                   1654:     var y = 0;
                   1655:     while (element) {
                   1656: 	y += element.offsetTop;
                   1657: 	element = element.offsetParent;
                   1658:     }
                   1659:     return y;
                   1660: }
                   1661: 
                   1662: 
1.565     albertel 1663: function resize_textarea(textarea_id,bottom_id) {
                   1664:     init_geometry();
                   1665:     var textarea        = document.getElementById(textarea_id);
                   1666:     //alert(textarea);
                   1667: 
1.588     albertel 1668:     var textarea_top    = getY(textarea);
1.565     albertel 1669:     var textarea_height = textarea.offsetHeight;
                   1670:     var bottom          = document.getElementById(bottom_id);
1.588     albertel 1671:     var bottom_top      = getY(bottom);
1.565     albertel 1672:     var bottom_height   = bottom.offsetHeight;
                   1673:     var window_height   = Geometry.getViewportHeight();
1.588     albertel 1674:     var fudge           = 23;
1.565     albertel 1675:     var new_height      = window_height-fudge-textarea_top-bottom_height;
                   1676:     if (new_height < 300) {
                   1677: 	new_height = 300;
                   1678:     }
                   1679:     textarea.style.height=new_height+'px';
                   1680: }
1.824     bisitz   1681: // ]]>
1.565     albertel 1682: </script>
                   1683: RESIZE
                   1684: 
                   1685: }
                   1686: 
                   1687: =pod
                   1688: 
1.256     matthew  1689: =head1 Excel and CSV file utility routines
                   1690: 
                   1691: =over 4
                   1692: 
                   1693: =cut
                   1694: 
                   1695: ###############################################################
                   1696: ###############################################################
                   1697: 
                   1698: =pod
                   1699: 
1.648     raeburn  1700: =item * &csv_translate($text) 
1.37      matthew  1701: 
1.185     www      1702: Translate $text to allow it to be output as a 'comma separated values' 
1.37      matthew  1703: format.
                   1704: 
                   1705: =cut
                   1706: 
1.180     matthew  1707: ###############################################################
                   1708: ###############################################################
1.37      matthew  1709: sub csv_translate {
                   1710:     my $text = shift;
                   1711:     $text =~ s/\"/\"\"/g;
1.209     albertel 1712:     $text =~ s/\n/ /g;
1.37      matthew  1713:     return $text;
                   1714: }
1.180     matthew  1715: 
                   1716: ###############################################################
                   1717: ###############################################################
                   1718: 
                   1719: =pod
                   1720: 
1.648     raeburn  1721: =item * &define_excel_formats()
1.180     matthew  1722: 
                   1723: Define some commonly used Excel cell formats.
                   1724: 
                   1725: Currently supported formats:
                   1726: 
                   1727: =over 4
                   1728: 
                   1729: =item header
                   1730: 
                   1731: =item bold
                   1732: 
                   1733: =item h1
                   1734: 
                   1735: =item h2
                   1736: 
                   1737: =item h3
                   1738: 
1.256     matthew  1739: =item h4
                   1740: 
                   1741: =item i
                   1742: 
1.180     matthew  1743: =item date
                   1744: 
                   1745: =back
                   1746: 
                   1747: Inputs: $workbook
                   1748: 
                   1749: Returns: $format, a hash reference.
                   1750: 
1.1057    foxr     1751: 
1.180     matthew  1752: =cut
                   1753: 
                   1754: ###############################################################
                   1755: ###############################################################
                   1756: sub define_excel_formats {
                   1757:     my ($workbook) = @_;
                   1758:     my $format;
                   1759:     $format->{'header'} = $workbook->add_format(bold      => 1, 
                   1760:                                                 bottom    => 1,
                   1761:                                                 align     => 'center');
                   1762:     $format->{'bold'} = $workbook->add_format(bold=>1);
                   1763:     $format->{'h1'}   = $workbook->add_format(bold=>1, size=>18);
                   1764:     $format->{'h2'}   = $workbook->add_format(bold=>1, size=>16);
                   1765:     $format->{'h3'}   = $workbook->add_format(bold=>1, size=>14);
1.255     matthew  1766:     $format->{'h4'}   = $workbook->add_format(bold=>1, size=>12);
1.246     matthew  1767:     $format->{'i'}    = $workbook->add_format(italic=>1);
1.180     matthew  1768:     $format->{'date'} = $workbook->add_format(num_format=>
1.207     matthew  1769:                                             'mm/dd/yyyy hh:mm:ss');
1.180     matthew  1770:     return $format;
                   1771: }
                   1772: 
                   1773: ###############################################################
                   1774: ###############################################################
1.113     bowersj2 1775: 
                   1776: =pod
                   1777: 
1.648     raeburn  1778: =item * &create_workbook()
1.255     matthew  1779: 
                   1780: Create an Excel worksheet.  If it fails, output message on the
                   1781: request object and return undefs.
                   1782: 
                   1783: Inputs: Apache request object
                   1784: 
                   1785: Returns (undef) on failure, 
                   1786:     Excel worksheet object, scalar with filename, and formats 
                   1787:     from &Apache::loncommon::define_excel_formats on success
                   1788: 
                   1789: =cut
                   1790: 
                   1791: ###############################################################
                   1792: ###############################################################
                   1793: sub create_workbook {
                   1794:     my ($r) = @_;
                   1795:         #
                   1796:     # Create the excel spreadsheet
                   1797:     my $filename = '/prtspool/'.
1.258     albertel 1798:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255     matthew  1799:         time.'_'.rand(1000000000).'.xls';
                   1800:     my $workbook  = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
                   1801:     if (! defined($workbook)) {
                   1802:         $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928     bisitz   1803:         $r->print(
                   1804:             '<p class="LC_error">'
                   1805:            .&mt('Problems occurred in creating the new Excel file.')
                   1806:            .' '.&mt('This error has been logged.')
                   1807:            .' '.&mt('Please alert your LON-CAPA administrator.')
                   1808:            .'</p>'
                   1809:         );
1.255     matthew  1810:         return (undef);
                   1811:     }
                   1812:     #
1.1014    foxr     1813:     $workbook->set_tempdir(LONCAPA::tempdir());
1.255     matthew  1814:     #
                   1815:     my $format = &Apache::loncommon::define_excel_formats($workbook);
                   1816:     return ($workbook,$filename,$format);
                   1817: }
                   1818: 
                   1819: ###############################################################
                   1820: ###############################################################
                   1821: 
                   1822: =pod
                   1823: 
1.648     raeburn  1824: =item * &create_text_file()
1.113     bowersj2 1825: 
1.542     raeburn  1826: Create a file to write to and eventually make available to the user.
1.256     matthew  1827: If file creation fails, outputs an error message on the request object and 
                   1828: return undefs.
1.113     bowersj2 1829: 
1.256     matthew  1830: Inputs: Apache request object, and file suffix
1.113     bowersj2 1831: 
1.256     matthew  1832: Returns (undef) on failure, 
                   1833:     Filehandle and filename on success.
1.113     bowersj2 1834: 
                   1835: =cut
                   1836: 
1.256     matthew  1837: ###############################################################
                   1838: ###############################################################
                   1839: sub create_text_file {
                   1840:     my ($r,$suffix) = @_;
                   1841:     if (! defined($suffix)) { $suffix = 'txt'; };
                   1842:     my $fh;
                   1843:     my $filename = '/prtspool/'.
1.258     albertel 1844:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256     matthew  1845:         time.'_'.rand(1000000000).'.'.$suffix;
                   1846:     $fh = Apache::File->new('>/home/httpd'.$filename);
                   1847:     if (! defined($fh)) {
                   1848:         $r->log_error("Couldn't open $filename for output $!");
1.928     bisitz   1849:         $r->print(
                   1850:             '<p class="LC_error">'
                   1851:            .&mt('Problems occurred in creating the output file.')
                   1852:            .' '.&mt('This error has been logged.')
                   1853:            .' '.&mt('Please alert your LON-CAPA administrator.')
                   1854:            .'</p>'
                   1855:         );
1.113     bowersj2 1856:     }
1.256     matthew  1857:     return ($fh,$filename)
1.113     bowersj2 1858: }
                   1859: 
                   1860: 
1.256     matthew  1861: =pod 
1.113     bowersj2 1862: 
                   1863: =back
                   1864: 
                   1865: =cut
1.37      matthew  1866: 
                   1867: ###############################################################
1.33      matthew  1868: ##        Home server <option> list generating code          ##
                   1869: ###############################################################
1.35      matthew  1870: 
1.169     www      1871: # ------------------------------------------
                   1872: 
                   1873: sub domain_select {
                   1874:     my ($name,$value,$multiple)=@_;
                   1875:     my %domains=map { 
1.514     albertel 1876: 	$_ => $_.' '. &Apache::lonnet::domain($_,'description') 
1.512     albertel 1877:     } &Apache::lonnet::all_domains();
1.169     www      1878:     if ($multiple) {
                   1879: 	$domains{''}=&mt('Any domain');
1.550     albertel 1880: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287     albertel 1881: 	return &multiple_select_form($name,$value,4,\%domains);
1.169     www      1882:     } else {
1.550     albertel 1883: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970     raeburn  1884: 	return &select_form($name,$value,\%domains);
1.169     www      1885:     }
                   1886: }
                   1887: 
1.282     albertel 1888: #-------------------------------------------
                   1889: 
                   1890: =pod
                   1891: 
1.519     raeburn  1892: =head1 Routines for form select boxes
                   1893: 
                   1894: =over 4
                   1895: 
1.648     raeburn  1896: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282     albertel 1897: 
                   1898: Returns a string containing a <select> element int multiple mode
                   1899: 
                   1900: 
                   1901: Args:
                   1902:   $name - name of the <select> element
1.506     raeburn  1903:   $value - scalar or array ref of values that should already be selected
1.282     albertel 1904:   $size - number of rows long the select element is
1.283     albertel 1905:   $hash - the elements should be 'option' => 'shown text'
1.282     albertel 1906:           (shown text should already have been &mt())
1.506     raeburn  1907:   $order - (optional) array ref of the order to show the elements in
1.283     albertel 1908: 
1.282     albertel 1909: =cut
                   1910: 
                   1911: #-------------------------------------------
1.169     www      1912: sub multiple_select_form {
1.284     albertel 1913:     my ($name,$value,$size,$hash,$order)=@_;
1.169     www      1914:     my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
                   1915:     my $output='';
1.191     matthew  1916:     if (! defined($size)) {
                   1917:         $size = 4;
1.283     albertel 1918:         if (scalar(keys(%$hash))<4) {
                   1919:             $size = scalar(keys(%$hash));
1.191     matthew  1920:         }
                   1921:     }
1.734     bisitz   1922:     $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501     banghart 1923:     my @order;
1.506     raeburn  1924:     if (ref($order) eq 'ARRAY')  {
                   1925:         @order = @{$order};
                   1926:     } else {
                   1927:         @order = sort(keys(%$hash));
1.501     banghart 1928:     }
                   1929:     if (exists($$hash{'select_form_order'})) {
                   1930:         @order = @{$$hash{'select_form_order'}};
                   1931:     }
                   1932:         
1.284     albertel 1933:     foreach my $key (@order) {
1.356     albertel 1934:         $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284     albertel 1935:         $output.='selected="selected" ' if ($selected{$key});
                   1936:         $output.='>'.$hash->{$key}."</option>\n";
1.169     www      1937:     }
                   1938:     $output.="</select>\n";
                   1939:     return $output;
                   1940: }
                   1941: 
1.88      www      1942: #-------------------------------------------
                   1943: 
                   1944: =pod
                   1945: 
1.970     raeburn  1946: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88      www      1947: 
                   1948: Returns a string containing a <select name='$name' size='1'> form to 
1.970     raeburn  1949: allow a user to select options from a ref to a hash containing:
                   1950: option_name => displayed text. An optional $onchange can include
                   1951: a javascript onchange item, e.g., onchange="this.form.submit();"  
                   1952: 
1.88      www      1953: See lonrights.pm for an example invocation and use.
                   1954: 
                   1955: =cut
                   1956: 
                   1957: #-------------------------------------------
                   1958: sub select_form {
1.970     raeburn  1959:     my ($def,$name,$hashref,$onchange) = @_;
                   1960:     return unless (ref($hashref) eq 'HASH');
                   1961:     if ($onchange) {
                   1962:         $onchange = ' onchange="'.$onchange.'"';
                   1963:     }
                   1964:     my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128     albertel 1965:     my @keys;
1.970     raeburn  1966:     if (exists($hashref->{'select_form_order'})) {
                   1967: 	@keys=@{$hashref->{'select_form_order'}};
1.128     albertel 1968:     } else {
1.970     raeburn  1969: 	@keys=sort(keys(%{$hashref}));
1.128     albertel 1970:     }
1.356     albertel 1971:     foreach my $key (@keys) {
                   1972:         $selectform.=
                   1973: 	    '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
                   1974:             ($key eq $def ? 'selected="selected" ' : '').
1.970     raeburn  1975:                 ">".$hashref->{$key}."</option>\n";
1.88      www      1976:     }
                   1977:     $selectform.="</select>";
                   1978:     return $selectform;
                   1979: }
                   1980: 
1.475     www      1981: # For display filters
                   1982: 
                   1983: sub display_filter {
1.1074    raeburn  1984:     my ($context) = @_;
1.475     www      1985:     if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477     www      1986:     if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074    raeburn  1987:     my $phraseinput = 'hidden';
                   1988:     my $includeinput = 'hidden';
                   1989:     my ($checked,$includetypestext);
                   1990:     if ($env{'form.displayfilter'} eq 'containing') {
                   1991:         $phraseinput = 'text'; 
                   1992:         if ($context eq 'parmslog') {
                   1993:             $includeinput = 'checkbox';
                   1994:             if ($env{'form.includetypes'}) {
                   1995:                 $checked = ' checked="checked"';
                   1996:             }
                   1997:             $includetypestext = &mt('Include parameter types');
                   1998:         }
                   1999:     } else {
                   2000:         $includetypestext = '&nbsp;';
                   2001:     }
                   2002:     my ($additional,$secondid,$thirdid);
                   2003:     if ($context eq 'parmslog') {
                   2004:         $additional = 
                   2005:             '<label><input type="'.$includeinput.'" name="includetypes"'. 
                   2006:             $checked.' name="includetypes" value="1" id="includetypes" />'.
                   2007:             '&nbsp;<span id="includetypestext">'.$includetypestext.'</span>'.
                   2008:             '</label>';
                   2009:         $secondid = 'includetypes';
                   2010:         $thirdid = 'includetypestext';
                   2011:     }
                   2012:     my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
                   2013:                                                     '$secondid','$thirdid')";
                   2014:     return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475     www      2015: 			       &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
                   2016: 							   (&mt('all'),10,20,50,100,1000,10000))).
1.714     bisitz   2017: 	   '</label></span> <span class="LC_nobreak">'.
1.1074    raeburn  2018:            &mt('Filter: [_1]',
1.477     www      2019: 	   &select_form($env{'form.displayfilter'},
                   2020: 			'displayfilter',
1.970     raeburn  2021: 			{'currentfolder' => 'Current folder/page',
1.477     www      2022: 			 'containing' => 'Containing phrase',
1.1074    raeburn  2023: 			 'none' => 'None'},$onchange)).'&nbsp;'.
                   2024: 			 '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
                   2025:                          &HTML::Entities::encode($env{'form.containingphrase'}).
                   2026:                          '" />'.$additional;
                   2027: }
                   2028: 
                   2029: sub display_filter_js {
                   2030:     my $includetext = &mt('Include parameter types');
                   2031:     return <<"ENDJS";
                   2032:   
                   2033: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
                   2034:     var firstType = 'hidden';
                   2035:     if (setter.options[setter.selectedIndex].value == 'containing') {
                   2036:         firstType = 'text';
                   2037:     }
                   2038:     firstObject = document.getElementById(firstid);
                   2039:     if (typeof(firstObject) == 'object') {
                   2040:         if (firstObject.type != firstType) {
                   2041:             changeInputType(firstObject,firstType);
                   2042:         }
                   2043:     }
                   2044:     if (context == 'parmslog') {
                   2045:         var secondType = 'hidden';
                   2046:         if (firstType == 'text') {
                   2047:             secondType = 'checkbox';
                   2048:         }
                   2049:         secondObject = document.getElementById(secondid);  
                   2050:         if (typeof(secondObject) == 'object') {
                   2051:             if (secondObject.type != secondType) {
                   2052:                 changeInputType(secondObject,secondType);
                   2053:             }
                   2054:         }
                   2055:         var textItem = document.getElementById(thirdid);
                   2056:         var currtext = textItem.innerHTML;
                   2057:         var newtext;
                   2058:         if (firstType == 'text') {
                   2059:             newtext = '$includetext';
                   2060:         } else {
                   2061:             newtext = '&nbsp;';
                   2062:         }
                   2063:         if (currtext != newtext) {
                   2064:             textItem.innerHTML = newtext;
                   2065:         }
                   2066:     }
                   2067:     return;
                   2068: }
                   2069: 
                   2070: function changeInputType(oldObject,newType) {
                   2071:     var newObject = document.createElement('input');
                   2072:     newObject.type = newType;
                   2073:     if (oldObject.size) {
                   2074:         newObject.size = oldObject.size;
                   2075:     }
                   2076:     if (oldObject.value) {
                   2077:         newObject.value = oldObject.value;
                   2078:     }
                   2079:     if (oldObject.name) {
                   2080:         newObject.name = oldObject.name;
                   2081:     }
                   2082:     if (oldObject.id) {
                   2083:         newObject.id = oldObject.id;
                   2084:     }
                   2085:     oldObject.parentNode.replaceChild(newObject,oldObject);
                   2086:     return;
                   2087: }
                   2088: 
                   2089: ENDJS
1.475     www      2090: }
                   2091: 
1.167     www      2092: sub gradeleveldescription {
                   2093:     my $gradelevel=shift;
                   2094:     my %gradelevels=(0 => 'Not specified',
                   2095: 		     1 => 'Grade 1',
                   2096: 		     2 => 'Grade 2',
                   2097: 		     3 => 'Grade 3',
                   2098: 		     4 => 'Grade 4',
                   2099: 		     5 => 'Grade 5',
                   2100: 		     6 => 'Grade 6',
                   2101: 		     7 => 'Grade 7',
                   2102: 		     8 => 'Grade 8',
                   2103: 		     9 => 'Grade 9',
                   2104: 		     10 => 'Grade 10',
                   2105: 		     11 => 'Grade 11',
                   2106: 		     12 => 'Grade 12',
                   2107: 		     13 => 'Grade 13',
                   2108: 		     14 => '100 Level',
                   2109: 		     15 => '200 Level',
                   2110: 		     16 => '300 Level',
                   2111: 		     17 => '400 Level',
                   2112: 		     18 => 'Graduate Level');
                   2113:     return &mt($gradelevels{$gradelevel});
                   2114: }
                   2115: 
1.163     www      2116: sub select_level_form {
                   2117:     my ($deflevel,$name)=@_;
                   2118:     unless ($deflevel) { $deflevel=0; }
1.167     www      2119:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
                   2120:     for (my $i=0; $i<=18; $i++) {
                   2121:         $selectform.="<option value=\"$i\" ".
1.253     albertel 2122:             ($i==$deflevel ? 'selected="selected" ' : '').
1.167     www      2123:                 ">".&gradeleveldescription($i)."</option>\n";
                   2124:     }
                   2125:     $selectform.="</select>";
                   2126:     return $selectform;
1.163     www      2127: }
1.167     www      2128: 
1.35      matthew  2129: #-------------------------------------------
                   2130: 
1.45      matthew  2131: =pod
                   2132: 
1.910     raeburn  2133: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms)
1.35      matthew  2134: 
                   2135: Returns a string containing a <select name='$name' size='1'> form to 
                   2136: allow a user to select the domain to preform an operation in.  
                   2137: See loncreateuser.pm for an example invocation and use.
                   2138: 
1.90      www      2139: If the $includeempty flag is set, it also includes an empty choice ("no domain
                   2140: selected");
                   2141: 
1.743     raeburn  2142: If the $showdomdesc flag is set, the domain name is followed by the domain description.
                   2143: 
1.910     raeburn  2144: 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.
                   2145: 
                   2146: The optional $incdoms is a reference to an array of domains which will be the only available options. 
1.563     raeburn  2147: 
1.35      matthew  2148: =cut
                   2149: 
                   2150: #-------------------------------------------
1.34      matthew  2151: sub select_dom_form {
1.910     raeburn  2152:     my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms) = @_;
1.872     raeburn  2153:     if ($onchange) {
1.874     raeburn  2154:         $onchange = ' onchange="'.$onchange.'"';
1.743     raeburn  2155:     }
1.910     raeburn  2156:     my @domains;
                   2157:     if (ref($incdoms) eq 'ARRAY') {
                   2158:         @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
                   2159:     } else {
                   2160:         @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
                   2161:     }
1.90      www      2162:     if ($includeempty) { @domains=('',@domains); }
1.743     raeburn  2163:     my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356     albertel 2164:     foreach my $dom (@domains) {
                   2165:         $selectdomain.="<option value=\"$dom\" ".
1.563     raeburn  2166:             ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
                   2167:         if ($showdomdesc) {
                   2168:             if ($dom ne '') {
                   2169:                 my $domdesc = &Apache::lonnet::domain($dom,'description');
                   2170:                 if ($domdesc ne '') {
                   2171:                     $selectdomain .= ' ('.$domdesc.')';
                   2172:                 }
                   2173:             } 
                   2174:         }
                   2175:         $selectdomain .= "</option>\n";
1.34      matthew  2176:     }
                   2177:     $selectdomain.="</select>";
                   2178:     return $selectdomain;
                   2179: }
                   2180: 
1.35      matthew  2181: #-------------------------------------------
                   2182: 
1.45      matthew  2183: =pod
                   2184: 
1.648     raeburn  2185: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35      matthew  2186: 
1.586     raeburn  2187: input: 4 arguments (two required, two optional) - 
                   2188:     $domain - domain of new user
                   2189:     $name - name of form element
                   2190:     $default - Value of 'default' causes a default item to be first 
                   2191:                             option, and selected by default. 
                   2192:     $hide - Value of 'hide' causes hiding of the name of the server, 
                   2193:                             if 1 server found, or default, if 0 found.
1.594     raeburn  2194: output: returns 2 items: 
1.586     raeburn  2195: (a) form element which contains either:
                   2196:    (i) <select name="$name">
                   2197:         <option value="$hostid1">$hostid $servers{$hostid}</option>
                   2198:         <option value="$hostid2">$hostid $servers{$hostid}</option>       
                   2199:        </select>
                   2200:        form item if there are multiple library servers in $domain, or
                   2201:    (ii) an <input type="hidden" name="$name" value="$hostid" /> form item 
                   2202:        if there is only one library server in $domain.
                   2203: 
                   2204: (b) number of library servers found.
                   2205: 
                   2206: See loncreateuser.pm for example of use.
1.35      matthew  2207: 
                   2208: =cut
                   2209: 
                   2210: #-------------------------------------------
1.586     raeburn  2211: sub home_server_form_item {
                   2212:     my ($domain,$name,$default,$hide) = @_;
1.513     albertel 2213:     my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586     raeburn  2214:     my $result;
                   2215:     my $numlib = keys(%servers);
                   2216:     if ($numlib > 1) {
                   2217:         $result .= '<select name="'.$name.'" />'."\n";
                   2218:         if ($default) {
1.804     bisitz   2219:             $result .= '<option value="default" selected="selected">'.&mt('default').
1.586     raeburn  2220:                        '</option>'."\n";
                   2221:         }
                   2222:         foreach my $hostid (sort(keys(%servers))) {
                   2223:             $result.= '<option value="'.$hostid.'">'.
                   2224: 	              $hostid.' '.$servers{$hostid}."</option>\n";
                   2225:         }
                   2226:         $result .= '</select>'."\n";
                   2227:     } elsif ($numlib == 1) {
                   2228:         my $hostid;
                   2229:         foreach my $item (keys(%servers)) {
                   2230:             $hostid = $item;
                   2231:         }
                   2232:         $result .= '<input type="hidden" name="'.$name.'" value="'.
                   2233:                    $hostid.'" />';
                   2234:                    if (!$hide) {
                   2235:                        $result .= $hostid.' '.$servers{$hostid};
                   2236:                    }
                   2237:                    $result .= "\n";
                   2238:     } elsif ($default) {
                   2239:         $result .= '<input type="hidden" name="'.$name.
                   2240:                    '" value="default" />';
                   2241:                    if (!$hide) {
                   2242:                        $result .= &mt('default');
                   2243:                    }
                   2244:                    $result .= "\n";
1.33      matthew  2245:     }
1.586     raeburn  2246:     return ($result,$numlib);
1.33      matthew  2247: }
1.112     bowersj2 2248: 
                   2249: =pod
                   2250: 
1.534     albertel 2251: =back 
                   2252: 
1.112     bowersj2 2253: =cut
1.87      matthew  2254: 
                   2255: ###############################################################
1.112     bowersj2 2256: ##                  Decoding User Agent                      ##
1.87      matthew  2257: ###############################################################
                   2258: 
                   2259: =pod
                   2260: 
1.112     bowersj2 2261: =head1 Decoding the User Agent
                   2262: 
                   2263: =over 4
                   2264: 
                   2265: =item * &decode_user_agent()
1.87      matthew  2266: 
                   2267: Inputs: $r
                   2268: 
                   2269: Outputs:
                   2270: 
                   2271: =over 4
                   2272: 
1.112     bowersj2 2273: =item * $httpbrowser
1.87      matthew  2274: 
1.112     bowersj2 2275: =item * $clientbrowser
1.87      matthew  2276: 
1.112     bowersj2 2277: =item * $clientversion
1.87      matthew  2278: 
1.112     bowersj2 2279: =item * $clientmathml
1.87      matthew  2280: 
1.112     bowersj2 2281: =item * $clientunicode
1.87      matthew  2282: 
1.112     bowersj2 2283: =item * $clientos
1.87      matthew  2284: 
                   2285: =back
                   2286: 
1.157     matthew  2287: =back 
                   2288: 
1.87      matthew  2289: =cut
                   2290: 
                   2291: ###############################################################
                   2292: ###############################################################
                   2293: sub decode_user_agent {
1.247     albertel 2294:     my ($r)=@_;
1.87      matthew  2295:     my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
                   2296:     my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
                   2297:     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247     albertel 2298:     if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87      matthew  2299:     my $clientbrowser='unknown';
                   2300:     my $clientversion='0';
                   2301:     my $clientmathml='';
                   2302:     my $clientunicode='0';
                   2303:     for (my $i=0;$i<=$#browsertype;$i++) {
                   2304:         my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
                   2305: 	if (($httpbrowser=~/$match/i)  && ($httpbrowser!~/$notmatch/i)) {
                   2306: 	    $clientbrowser=$bname;
                   2307:             $httpbrowser=~/$vreg/i;
                   2308: 	    $clientversion=$1;
                   2309:             $clientmathml=($clientversion>=$minv);
                   2310:             $clientunicode=($clientversion>=$univ);
                   2311: 	}
                   2312:     }
                   2313:     my $clientos='unknown';
                   2314:     if (($httpbrowser=~/linux/i) ||
                   2315:         ($httpbrowser=~/unix/i) ||
                   2316:         ($httpbrowser=~/ux/i) ||
                   2317:         ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
                   2318:     if (($httpbrowser=~/vax/i) ||
                   2319:         ($httpbrowser=~/vms/i)) { $clientos='vms'; }
                   2320:     if ($httpbrowser=~/next/i) { $clientos='next'; }
                   2321:     if (($httpbrowser=~/mac/i) ||
                   2322:         ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
                   2323:     if ($httpbrowser=~/win/i) { $clientos='win'; }
                   2324:     if ($httpbrowser=~/embed/i) { $clientos='pda'; }
                   2325:     return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   2326:             $clientunicode,$clientos,);
                   2327: }
                   2328: 
1.32      matthew  2329: ###############################################################
                   2330: ##    Authentication changing form generation subroutines    ##
                   2331: ###############################################################
                   2332: ##
                   2333: ## All of the authform_xxxxxxx subroutines take their inputs in a
                   2334: ## hash, and have reasonable default values.
                   2335: ##
                   2336: ##    formname = the name given in the <form> tag.
1.35      matthew  2337: #-------------------------------------------
                   2338: 
1.45      matthew  2339: =pod
                   2340: 
1.112     bowersj2 2341: =head1 Authentication Routines
                   2342: 
                   2343: =over 4
                   2344: 
1.648     raeburn  2345: =item * &authform_xxxxxx()
1.35      matthew  2346: 
                   2347: The authform_xxxxxx subroutines provide javascript and html forms which 
                   2348: handle some of the conveniences required for authentication forms.  
                   2349: This is not an optimal method, but it works.  
                   2350: 
                   2351: =over 4
                   2352: 
1.112     bowersj2 2353: =item * authform_header
1.35      matthew  2354: 
1.112     bowersj2 2355: =item * authform_authorwarning
1.35      matthew  2356: 
1.112     bowersj2 2357: =item * authform_nochange
1.35      matthew  2358: 
1.112     bowersj2 2359: =item * authform_kerberos
1.35      matthew  2360: 
1.112     bowersj2 2361: =item * authform_internal
1.35      matthew  2362: 
1.112     bowersj2 2363: =item * authform_filesystem
1.35      matthew  2364: 
                   2365: =back
                   2366: 
1.648     raeburn  2367: See loncreateuser.pm for invocation and use examples.
1.157     matthew  2368: 
1.35      matthew  2369: =cut
                   2370: 
                   2371: #-------------------------------------------
1.32      matthew  2372: sub authform_header{  
                   2373:     my %in = (
                   2374:         formname => 'cu',
1.80      albertel 2375:         kerb_def_dom => '',
1.32      matthew  2376:         @_,
                   2377:     );
                   2378:     $in{'formname'} = 'document.' . $in{'formname'};
                   2379:     my $result='';
1.80      albertel 2380: 
                   2381: #---------------------------------------------- Code for upper case translation
                   2382:     my $Javascript_toUpperCase;
                   2383:     unless ($in{kerb_def_dom}) {
                   2384:         $Javascript_toUpperCase =<<"END";
                   2385:         switch (choice) {
                   2386:            case 'krb': currentform.elements[choicearg].value =
                   2387:                currentform.elements[choicearg].value.toUpperCase();
                   2388:                break;
                   2389:            default:
                   2390:         }
                   2391: END
                   2392:     } else {
                   2393:         $Javascript_toUpperCase = "";
                   2394:     }
                   2395: 
1.165     raeburn  2396:     my $radioval = "'nochange'";
1.591     raeburn  2397:     if (defined($in{'curr_authtype'})) {
                   2398:         if ($in{'curr_authtype'} ne '') {
                   2399:             $radioval = "'".$in{'curr_authtype'}."arg'";
                   2400:         }
1.174     matthew  2401:     }
1.165     raeburn  2402:     my $argfield = 'null';
1.591     raeburn  2403:     if (defined($in{'mode'})) {
1.165     raeburn  2404:         if ($in{'mode'} eq 'modifycourse')  {
1.591     raeburn  2405:             if (defined($in{'curr_autharg'})) {
                   2406:                 if ($in{'curr_autharg'} ne '') {
1.165     raeburn  2407:                     $argfield = "'$in{'curr_autharg'}'";
                   2408:                 }
                   2409:             }
                   2410:         }
                   2411:     }
                   2412: 
1.32      matthew  2413:     $result.=<<"END";
                   2414: var current = new Object();
1.165     raeburn  2415: current.radiovalue = $radioval;
                   2416: current.argfield = $argfield;
1.32      matthew  2417: 
                   2418: function changed_radio(choice,currentform) {
                   2419:     var choicearg = choice + 'arg';
                   2420:     // If a radio button in changed, we need to change the argfield
                   2421:     if (current.radiovalue != choice) {
                   2422:         current.radiovalue = choice;
                   2423:         if (current.argfield != null) {
                   2424:             currentform.elements[current.argfield].value = '';
                   2425:         }
                   2426:         if (choice == 'nochange') {
                   2427:             current.argfield = null;
                   2428:         } else {
                   2429:             current.argfield = choicearg;
                   2430:             switch(choice) {
                   2431:                 case 'krb': 
                   2432:                     currentform.elements[current.argfield].value = 
                   2433:                         "$in{'kerb_def_dom'}";
                   2434:                 break;
                   2435:               default:
                   2436:                 break;
                   2437:             }
                   2438:         }
                   2439:     }
                   2440:     return;
                   2441: }
1.22      www      2442: 
1.32      matthew  2443: function changed_text(choice,currentform) {
                   2444:     var choicearg = choice + 'arg';
                   2445:     if (currentform.elements[choicearg].value !='') {
1.80      albertel 2446:         $Javascript_toUpperCase
1.32      matthew  2447:         // clear old field
                   2448:         if ((current.argfield != choicearg) && (current.argfield != null)) {
                   2449:             currentform.elements[current.argfield].value = '';
                   2450:         }
                   2451:         current.argfield = choicearg;
                   2452:     }
                   2453:     set_auth_radio_buttons(choice,currentform);
                   2454:     return;
1.20      www      2455: }
1.32      matthew  2456: 
                   2457: function set_auth_radio_buttons(newvalue,currentform) {
1.986     raeburn  2458:     var numauthchoices = currentform.login.length;
                   2459:     if (typeof numauthchoices  == "undefined") {
                   2460:         return;
                   2461:     } 
1.32      matthew  2462:     var i=0;
1.986     raeburn  2463:     while (i < numauthchoices) {
1.32      matthew  2464:         if (currentform.login[i].value == newvalue) { break; }
                   2465:         i++;
                   2466:     }
1.986     raeburn  2467:     if (i == numauthchoices) {
1.32      matthew  2468:         return;
                   2469:     }
                   2470:     current.radiovalue = newvalue;
                   2471:     currentform.login[i].checked = true;
                   2472:     return;
                   2473: }
                   2474: END
                   2475:     return $result;
                   2476: }
                   2477: 
                   2478: sub authform_authorwarning{
                   2479:     my $result='';
1.144     matthew  2480:     $result='<i>'.
                   2481:         &mt('As a general rule, only authors or co-authors should be '.
                   2482:             'filesystem authenticated '.
                   2483:             '(which allows access to the server filesystem).')."</i>\n";
1.32      matthew  2484:     return $result;
                   2485: }
                   2486: 
                   2487: sub authform_nochange{  
                   2488:     my %in = (
                   2489:               formname => 'document.cu',
                   2490:               kerb_def_dom => 'MSU.EDU',
                   2491:               @_,
                   2492:           );
1.586     raeburn  2493:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'}); 
                   2494:     my $result;
                   2495:     if (keys(%can_assign) == 0) {
                   2496:         $result = &mt('Under you current role you are not permitted to change login settings for this user');  
                   2497:     } else {
                   2498:         $result = '<label>'.&mt('[_1] Do not change login data',
                   2499:                   '<input type="radio" name="login" value="nochange" '.
                   2500:                   'checked="checked" onclick="'.
1.281     albertel 2501:             "javascript:changed_radio('nochange',$in{'formname'});".'" />').
                   2502: 	    '</label>';
1.586     raeburn  2503:     }
1.32      matthew  2504:     return $result;
                   2505: }
                   2506: 
1.591     raeburn  2507: sub authform_kerberos {
1.32      matthew  2508:     my %in = (
                   2509:               formname => 'document.cu',
                   2510:               kerb_def_dom => 'MSU.EDU',
1.80      albertel 2511:               kerb_def_auth => 'krb4',
1.32      matthew  2512:               @_,
                   2513:               );
1.586     raeburn  2514:     my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
                   2515:         $autharg,$jscall);
                   2516:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.80      albertel 2517:     if ($in{'kerb_def_auth'} eq 'krb5') {
1.772     bisitz   2518:        $check5 = ' checked="checked"';
1.80      albertel 2519:     } else {
1.772     bisitz   2520:        $check4 = ' checked="checked"';
1.80      albertel 2521:     }
1.165     raeburn  2522:     $krbarg = $in{'kerb_def_dom'};
1.591     raeburn  2523:     if (defined($in{'curr_authtype'})) {
                   2524:         if ($in{'curr_authtype'} eq 'krb') {
1.772     bisitz   2525:             $krbcheck = ' checked="checked"';
1.623     raeburn  2526:             if (defined($in{'mode'})) {
                   2527:                 if ($in{'mode'} eq 'modifyuser') {
                   2528:                     $krbcheck = '';
                   2529:                 }
                   2530:             }
1.591     raeburn  2531:             if (defined($in{'curr_kerb_ver'})) {
                   2532:                 if ($in{'curr_krb_ver'} eq '5') {
1.772     bisitz   2533:                     $check5 = ' checked="checked"';
1.591     raeburn  2534:                     $check4 = '';
                   2535:                 } else {
1.772     bisitz   2536:                     $check4 = ' checked="checked"';
1.591     raeburn  2537:                     $check5 = '';
                   2538:                 }
1.586     raeburn  2539:             }
1.591     raeburn  2540:             if (defined($in{'curr_autharg'})) {
1.165     raeburn  2541:                 $krbarg = $in{'curr_autharg'};
                   2542:             }
1.586     raeburn  2543:             if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591     raeburn  2544:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2545:                     $result = 
                   2546:     &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
                   2547:         $in{'curr_autharg'},$krbver);
                   2548:                 } else {
                   2549:                     $result =
                   2550:     &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
                   2551:                 }
                   2552:                 return $result; 
                   2553:             }
                   2554:         }
                   2555:     } else {
                   2556:         if ($authnum == 1) {
1.784     bisitz   2557:             $authtype = '<input type="hidden" name="login" value="krb" />';
1.165     raeburn  2558:         }
                   2559:     }
1.586     raeburn  2560:     if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
                   2561:         return;
1.587     raeburn  2562:     } elsif ($authtype eq '') {
1.591     raeburn  2563:         if (defined($in{'mode'})) {
1.587     raeburn  2564:             if ($in{'mode'} eq 'modifycourse') {
                   2565:                 if ($authnum == 1) {
1.784     bisitz   2566:                     $authtype = '<input type="hidden" name="login" value="krb" />';
1.587     raeburn  2567:                 }
                   2568:             }
                   2569:         }
1.586     raeburn  2570:     }
                   2571:     $jscall = "javascript:changed_radio('krb',$in{'formname'});";
                   2572:     if ($authtype eq '') {
                   2573:         $authtype = '<input type="radio" name="login" value="krb" '.
                   2574:                     'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
                   2575:                     $krbcheck.' />';
                   2576:     }
                   2577:     if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
                   2578:         ($can_assign{'krb4'} && !$can_assign{'krb5'} && 
                   2579:          $in{'curr_authtype'} eq 'krb5') ||
                   2580:         (!$can_assign{'krb4'} && $can_assign{'krb5'} && 
                   2581:          $in{'curr_authtype'} eq 'krb4')) {
                   2582:         $result .= &mt
1.144     matthew  2583:         ('[_1] Kerberos authenticated with domain [_2] '.
1.281     albertel 2584:          '[_3] Version 4 [_4] Version 5 [_5]',
1.586     raeburn  2585:          '<label>'.$authtype,
1.281     albertel 2586:          '</label><input type="text" size="10" name="krbarg" '.
1.165     raeburn  2587:              'value="'.$krbarg.'" '.
1.144     matthew  2588:              'onchange="'.$jscall.'" />',
1.281     albertel 2589:          '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
                   2590:          '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
                   2591: 	 '</label>');
1.586     raeburn  2592:     } elsif ($can_assign{'krb4'}) {
                   2593:         $result .= &mt
                   2594:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2595:          '[_3] Version 4 [_4]',
                   2596:          '<label>'.$authtype,
                   2597:          '</label><input type="text" size="10" name="krbarg" '.
                   2598:              'value="'.$krbarg.'" '.
                   2599:              'onchange="'.$jscall.'" />',
                   2600:          '<label><input type="hidden" name="krbver" value="4" />',
                   2601:          '</label>');
                   2602:     } elsif ($can_assign{'krb5'}) {
                   2603:         $result .= &mt
                   2604:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2605:          '[_3] Version 5 [_4]',
                   2606:          '<label>'.$authtype,
                   2607:          '</label><input type="text" size="10" name="krbarg" '.
                   2608:              'value="'.$krbarg.'" '.
                   2609:              'onchange="'.$jscall.'" />',
                   2610:          '<label><input type="hidden" name="krbver" value="5" />',
                   2611:          '</label>');
                   2612:     }
1.32      matthew  2613:     return $result;
                   2614: }
                   2615: 
                   2616: sub authform_internal{  
1.586     raeburn  2617:     my %in = (
1.32      matthew  2618:                 formname => 'document.cu',
                   2619:                 kerb_def_dom => 'MSU.EDU',
                   2620:                 @_,
                   2621:                 );
1.586     raeburn  2622:     my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
                   2623:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2624:     if (defined($in{'curr_authtype'})) {
                   2625:         if ($in{'curr_authtype'} eq 'int') {
1.586     raeburn  2626:             if ($can_assign{'int'}) {
1.772     bisitz   2627:                 $intcheck = 'checked="checked" ';
1.623     raeburn  2628:                 if (defined($in{'mode'})) {
                   2629:                     if ($in{'mode'} eq 'modifyuser') {
                   2630:                         $intcheck = '';
                   2631:                     }
                   2632:                 }
1.591     raeburn  2633:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2634:                     $intarg = $in{'curr_autharg'};
                   2635:                 }
                   2636:             } else {
                   2637:                 $result = &mt('Currently internally authenticated.');
                   2638:                 return $result;
1.165     raeburn  2639:             }
                   2640:         }
1.586     raeburn  2641:     } else {
                   2642:         if ($authnum == 1) {
1.784     bisitz   2643:             $authtype = '<input type="hidden" name="login" value="int" />';
1.586     raeburn  2644:         }
                   2645:     }
                   2646:     if (!$can_assign{'int'}) {
                   2647:         return;
1.587     raeburn  2648:     } elsif ($authtype eq '') {
1.591     raeburn  2649:         if (defined($in{'mode'})) {
1.587     raeburn  2650:             if ($in{'mode'} eq 'modifycourse') {
                   2651:                 if ($authnum == 1) {
1.784     bisitz   2652:                     $authtype = '<input type="hidden" name="login" value="int" />';
1.587     raeburn  2653:                 }
                   2654:             }
                   2655:         }
1.165     raeburn  2656:     }
1.586     raeburn  2657:     $jscall = "javascript:changed_radio('int',$in{'formname'});";
                   2658:     if ($authtype eq '') {
                   2659:         $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
                   2660:                     ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
                   2661:     }
1.605     bisitz   2662:     $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586     raeburn  2663:                $intarg.'" onchange="'.$jscall.'" />';
                   2664:     $result = &mt
1.144     matthew  2665:         ('[_1] Internally authenticated (with initial password [_2])',
1.586     raeburn  2666:          '<label>'.$authtype,'</label>'.$autharg);
1.824     bisitz   2667:     $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  2668:     return $result;
                   2669: }
                   2670: 
                   2671: sub authform_local{  
                   2672:     my %in = (
                   2673:               formname => 'document.cu',
                   2674:               kerb_def_dom => 'MSU.EDU',
                   2675:               @_,
                   2676:               );
1.586     raeburn  2677:     my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
                   2678:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2679:     if (defined($in{'curr_authtype'})) {
                   2680:         if ($in{'curr_authtype'} eq 'loc') {
1.586     raeburn  2681:             if ($can_assign{'loc'}) {
1.772     bisitz   2682:                 $loccheck = 'checked="checked" ';
1.623     raeburn  2683:                 if (defined($in{'mode'})) {
                   2684:                     if ($in{'mode'} eq 'modifyuser') {
                   2685:                         $loccheck = '';
                   2686:                     }
                   2687:                 }
1.591     raeburn  2688:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2689:                     $locarg = $in{'curr_autharg'};
                   2690:                 }
                   2691:             } else {
                   2692:                 $result = &mt('Currently using local (institutional) authentication.');
                   2693:                 return $result;
1.165     raeburn  2694:             }
                   2695:         }
1.586     raeburn  2696:     } else {
                   2697:         if ($authnum == 1) {
1.784     bisitz   2698:             $authtype = '<input type="hidden" name="login" value="loc" />';
1.586     raeburn  2699:         }
                   2700:     }
                   2701:     if (!$can_assign{'loc'}) {
                   2702:         return;
1.587     raeburn  2703:     } elsif ($authtype eq '') {
1.591     raeburn  2704:         if (defined($in{'mode'})) {
1.587     raeburn  2705:             if ($in{'mode'} eq 'modifycourse') {
                   2706:                 if ($authnum == 1) {
1.784     bisitz   2707:                     $authtype = '<input type="hidden" name="login" value="loc" />';
1.587     raeburn  2708:                 }
                   2709:             }
                   2710:         }
1.165     raeburn  2711:     }
1.586     raeburn  2712:     $jscall = "javascript:changed_radio('loc',$in{'formname'});";
                   2713:     if ($authtype eq '') {
                   2714:         $authtype = '<input type="radio" name="login" value="loc" '.
                   2715:                     $loccheck.' onchange="'.$jscall.'" onclick="'.
                   2716:                     $jscall.'" />';
                   2717:     }
                   2718:     $autharg = '<input type="text" size="10" name="locarg" value="'.
                   2719:                $locarg.'" onchange="'.$jscall.'" />';
                   2720:     $result = &mt('[_1] Local Authentication with argument [_2]',
                   2721:                   '<label>'.$authtype,'</label>'.$autharg);
1.32      matthew  2722:     return $result;
                   2723: }
                   2724: 
                   2725: sub authform_filesystem{  
                   2726:     my %in = (
                   2727:               formname => 'document.cu',
                   2728:               kerb_def_dom => 'MSU.EDU',
                   2729:               @_,
                   2730:               );
1.586     raeburn  2731:     my ($fsyscheck,$result,$authtype,$autharg,$jscall);
                   2732:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2733:     if (defined($in{'curr_authtype'})) {
                   2734:         if ($in{'curr_authtype'} eq 'fsys') {
1.586     raeburn  2735:             if ($can_assign{'fsys'}) {
1.772     bisitz   2736:                 $fsyscheck = 'checked="checked" ';
1.623     raeburn  2737:                 if (defined($in{'mode'})) {
                   2738:                     if ($in{'mode'} eq 'modifyuser') {
                   2739:                         $fsyscheck = '';
                   2740:                     }
                   2741:                 }
1.586     raeburn  2742:             } else {
                   2743:                 $result = &mt('Currently Filesystem Authenticated.');
                   2744:                 return $result;
                   2745:             }           
                   2746:         }
                   2747:     } else {
                   2748:         if ($authnum == 1) {
1.784     bisitz   2749:             $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586     raeburn  2750:         }
                   2751:     }
                   2752:     if (!$can_assign{'fsys'}) {
                   2753:         return;
1.587     raeburn  2754:     } elsif ($authtype eq '') {
1.591     raeburn  2755:         if (defined($in{'mode'})) {
1.587     raeburn  2756:             if ($in{'mode'} eq 'modifycourse') {
                   2757:                 if ($authnum == 1) {
1.784     bisitz   2758:                     $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587     raeburn  2759:                 }
                   2760:             }
                   2761:         }
1.586     raeburn  2762:     }
                   2763:     $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
                   2764:     if ($authtype eq '') {
                   2765:         $authtype = '<input type="radio" name="login" value="fsys" '.
                   2766:                     $fsyscheck.' onchange="'.$jscall.'" onclick="'.
                   2767:                     $jscall.'" />';
                   2768:     }
                   2769:     $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
                   2770:                ' onchange="'.$jscall.'" />';
                   2771:     $result = &mt
1.144     matthew  2772:         ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281     albertel 2773:          '<label><input type="radio" name="login" value="fsys" '.
1.586     raeburn  2774:          $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605     bisitz   2775:          '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144     matthew  2776:                   'onchange="'.$jscall.'" />');
1.32      matthew  2777:     return $result;
                   2778: }
                   2779: 
1.586     raeburn  2780: sub get_assignable_auth {
                   2781:     my ($dom) = @_;
                   2782:     if ($dom eq '') {
                   2783:         $dom = $env{'request.role.domain'};
                   2784:     }
                   2785:     my %can_assign = (
                   2786:                           krb4 => 1,
                   2787:                           krb5 => 1,
                   2788:                           int  => 1,
                   2789:                           loc  => 1,
                   2790:                      );
                   2791:     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
                   2792:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   2793:         if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
                   2794:             my $authhash = $domconfig{'usercreation'}{'authtypes'};
                   2795:             my $context;
                   2796:             if ($env{'request.role'} =~ /^au/) {
                   2797:                 $context = 'author';
                   2798:             } elsif ($env{'request.role'} =~ /^dc/) {
                   2799:                 $context = 'domain';
                   2800:             } elsif ($env{'request.course.id'}) {
                   2801:                 $context = 'course';
                   2802:             }
                   2803:             if ($context) {
                   2804:                 if (ref($authhash->{$context}) eq 'HASH') {
                   2805:                    %can_assign = %{$authhash->{$context}}; 
                   2806:                 }
                   2807:             }
                   2808:         }
                   2809:     }
                   2810:     my $authnum = 0;
                   2811:     foreach my $key (keys(%can_assign)) {
                   2812:         if ($can_assign{$key}) {
                   2813:             $authnum ++;
                   2814:         }
                   2815:     }
                   2816:     if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
                   2817:         $authnum --;
                   2818:     }
                   2819:     return ($authnum,%can_assign);
                   2820: }
                   2821: 
1.80      albertel 2822: ###############################################################
                   2823: ##    Get Kerberos Defaults for Domain                 ##
                   2824: ###############################################################
                   2825: ##
                   2826: ## Returns default kerberos version and an associated argument
                   2827: ## as listed in file domain.tab. If not listed, provides
                   2828: ## appropriate default domain and kerberos version.
                   2829: ##
                   2830: #-------------------------------------------
                   2831: 
                   2832: =pod
                   2833: 
1.648     raeburn  2834: =item * &get_kerberos_defaults()
1.80      albertel 2835: 
                   2836: get_kerberos_defaults($target_domain) returns the default kerberos
1.641     raeburn  2837: version and domain. If not found, it defaults to version 4 and the 
                   2838: domain of the server.
1.80      albertel 2839: 
1.648     raeburn  2840: =over 4
                   2841: 
1.80      albertel 2842: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
                   2843: 
1.648     raeburn  2844: =back
                   2845: 
                   2846: =back
                   2847: 
1.80      albertel 2848: =cut
                   2849: 
                   2850: #-------------------------------------------
                   2851: sub get_kerberos_defaults {
                   2852:     my $domain=shift;
1.641     raeburn  2853:     my ($krbdef,$krbdefdom);
                   2854:     my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
                   2855:     if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
                   2856:         $krbdef = $domdefaults{'auth_def'};
                   2857:         $krbdefdom = $domdefaults{'auth_arg_def'};
                   2858:     } else {
1.80      albertel 2859:         $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
                   2860:         my $krbdefdom=$1;
                   2861:         $krbdefdom=~tr/a-z/A-Z/;
                   2862:         $krbdef = "krb4";
                   2863:     }
                   2864:     return ($krbdef,$krbdefdom);
                   2865: }
1.112     bowersj2 2866: 
1.32      matthew  2867: 
1.46      matthew  2868: ###############################################################
                   2869: ##                Thesaurus Functions                        ##
                   2870: ###############################################################
1.20      www      2871: 
1.46      matthew  2872: =pod
1.20      www      2873: 
1.112     bowersj2 2874: =head1 Thesaurus Functions
                   2875: 
                   2876: =over 4
                   2877: 
1.648     raeburn  2878: =item * &initialize_keywords()
1.46      matthew  2879: 
                   2880: Initializes the package variable %Keywords if it is empty.  Uses the
                   2881: package variable $thesaurus_db_file.
                   2882: 
                   2883: =cut
                   2884: 
                   2885: ###################################################
                   2886: 
                   2887: sub initialize_keywords {
                   2888:     return 1 if (scalar keys(%Keywords));
                   2889:     # If we are here, %Keywords is empty, so fill it up
                   2890:     #   Make sure the file we need exists...
                   2891:     if (! -e $thesaurus_db_file) {
                   2892:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
                   2893:                                  " failed because it does not exist");
                   2894:         return 0;
                   2895:     }
                   2896:     #   Set up the hash as a database
                   2897:     my %thesaurus_db;
                   2898:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2899:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2900:         &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
                   2901:                                  $thesaurus_db_file);
                   2902:         return 0;
                   2903:     } 
                   2904:     #  Get the average number of appearances of a word.
                   2905:     my $avecount = $thesaurus_db{'average.count'};
                   2906:     #  Put keywords (those that appear > average) into %Keywords
                   2907:     while (my ($word,$data)=each (%thesaurus_db)) {
                   2908:         my ($count,undef) = split /:/,$data;
                   2909:         $Keywords{$word}++ if ($count > $avecount);
                   2910:     }
                   2911:     untie %thesaurus_db;
                   2912:     # Remove special values from %Keywords.
1.356     albertel 2913:     foreach my $value ('total.count','average.count') {
                   2914:         delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586     raeburn  2915:   }
1.46      matthew  2916:     return 1;
                   2917: }
                   2918: 
                   2919: ###################################################
                   2920: 
                   2921: =pod
                   2922: 
1.648     raeburn  2923: =item * &keyword($word)
1.46      matthew  2924: 
                   2925: Returns true if $word is a keyword.  A keyword is a word that appears more 
                   2926: than the average number of times in the thesaurus database.  Calls 
                   2927: &initialize_keywords
                   2928: 
                   2929: =cut
                   2930: 
                   2931: ###################################################
1.20      www      2932: 
                   2933: sub keyword {
1.46      matthew  2934:     return if (!&initialize_keywords());
                   2935:     my $word=lc(shift());
                   2936:     $word=~s/\W//g;
                   2937:     return exists($Keywords{$word});
1.20      www      2938: }
1.46      matthew  2939: 
                   2940: ###############################################################
                   2941: 
                   2942: =pod 
1.20      www      2943: 
1.648     raeburn  2944: =item * &get_related_words()
1.46      matthew  2945: 
1.160     matthew  2946: Look up a word in the thesaurus.  Takes a scalar argument and returns
1.46      matthew  2947: an array of words.  If the keyword is not in the thesaurus, an empty array
                   2948: will be returned.  The order of the words returned is determined by the
                   2949: database which holds them.
                   2950: 
                   2951: Uses global $thesaurus_db_file.
                   2952: 
1.1057    foxr     2953: 
1.46      matthew  2954: =cut
                   2955: 
                   2956: ###############################################################
                   2957: sub get_related_words {
                   2958:     my $keyword = shift;
                   2959:     my %thesaurus_db;
                   2960:     if (! -e $thesaurus_db_file) {
                   2961:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
                   2962:                                  "failed because the file does not exist");
                   2963:         return ();
                   2964:     }
                   2965:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2966:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2967:         return ();
                   2968:     } 
                   2969:     my @Words=();
1.429     www      2970:     my $count=0;
1.46      matthew  2971:     if (exists($thesaurus_db{$keyword})) {
1.356     albertel 2972: 	# The first element is the number of times
                   2973: 	# the word appears.  We do not need it now.
1.429     www      2974: 	my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
                   2975: 	my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
                   2976: 	my $threshold=$mostfrequentcount/10;
                   2977:         foreach my $possibleword (@RelatedWords) {
                   2978:             my ($word,$wordcount)=split(/\,/,$possibleword);
                   2979:             if ($wordcount>$threshold) {
                   2980: 		push(@Words,$word);
                   2981:                 $count++;
                   2982:                 if ($count>10) { last; }
                   2983: 	    }
1.20      www      2984:         }
                   2985:     }
1.46      matthew  2986:     untie %thesaurus_db;
                   2987:     return @Words;
1.14      harris41 2988: }
1.46      matthew  2989: 
1.112     bowersj2 2990: =pod
                   2991: 
                   2992: =back
                   2993: 
                   2994: =cut
1.61      www      2995: 
                   2996: # -------------------------------------------------------------- Plaintext name
1.81      albertel 2997: =pod
                   2998: 
1.112     bowersj2 2999: =head1 User Name Functions
                   3000: 
                   3001: =over 4
                   3002: 
1.648     raeburn  3003: =item * &plainname($uname,$udom,$first)
1.81      albertel 3004: 
1.112     bowersj2 3005: Takes a users logon name and returns it as a string in
1.226     albertel 3006: "first middle last generation" form 
                   3007: if $first is set to 'lastname' then it returns it as
                   3008: 'lastname generation, firstname middlename' if their is a lastname
1.81      albertel 3009: 
                   3010: =cut
1.61      www      3011: 
1.295     www      3012: 
1.81      albertel 3013: ###############################################################
1.61      www      3014: sub plainname {
1.226     albertel 3015:     my ($uname,$udom,$first)=@_;
1.537     albertel 3016:     return if (!defined($uname) || !defined($udom));
1.295     www      3017:     my %names=&getnames($uname,$udom);
1.226     albertel 3018:     my $name=&Apache::lonnet::format_name($names{'firstname'},
                   3019: 					  $names{'middlename'},
                   3020: 					  $names{'lastname'},
                   3021: 					  $names{'generation'},$first);
                   3022:     $name=~s/^\s+//;
1.62      www      3023:     $name=~s/\s+$//;
                   3024:     $name=~s/\s+/ /g;
1.353     albertel 3025:     if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62      www      3026:     return $name;
1.61      www      3027: }
1.66      www      3028: 
                   3029: # -------------------------------------------------------------------- Nickname
1.81      albertel 3030: =pod
                   3031: 
1.648     raeburn  3032: =item * &nickname($uname,$udom)
1.81      albertel 3033: 
                   3034: Gets a users name and returns it as a string as
                   3035: 
                   3036: "&quot;nickname&quot;"
1.66      www      3037: 
1.81      albertel 3038: if the user has a nickname or
                   3039: 
                   3040: "first middle last generation"
                   3041: 
                   3042: if the user does not
                   3043: 
                   3044: =cut
1.66      www      3045: 
                   3046: sub nickname {
                   3047:     my ($uname,$udom)=@_;
1.537     albertel 3048:     return if (!defined($uname) || !defined($udom));
1.295     www      3049:     my %names=&getnames($uname,$udom);
1.68      albertel 3050:     my $name=$names{'nickname'};
1.66      www      3051:     if ($name) {
                   3052:        $name='&quot;'.$name.'&quot;'; 
                   3053:     } else {
                   3054:        $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
                   3055: 	     $names{'lastname'}.' '.$names{'generation'};
                   3056:        $name=~s/\s+$//;
                   3057:        $name=~s/\s+/ /g;
                   3058:     }
                   3059:     return $name;
                   3060: }
                   3061: 
1.295     www      3062: sub getnames {
                   3063:     my ($uname,$udom)=@_;
1.537     albertel 3064:     return if (!defined($uname) || !defined($udom));
1.433     albertel 3065:     if ($udom eq 'public' && $uname eq 'public') {
                   3066: 	return ('lastname' => &mt('Public'));
                   3067:     }
1.295     www      3068:     my $id=$uname.':'.$udom;
                   3069:     my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
                   3070:     if ($cached) {
                   3071: 	return %{$names};
                   3072:     } else {
                   3073: 	my %loadnames=&Apache::lonnet::get('environment',
                   3074:                     ['firstname','middlename','lastname','generation','nickname'],
                   3075: 					 $udom,$uname);
                   3076: 	&Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
                   3077: 	return %loadnames;
                   3078:     }
                   3079: }
1.61      www      3080: 
1.542     raeburn  3081: # -------------------------------------------------------------------- getemails
1.648     raeburn  3082: 
1.542     raeburn  3083: =pod
                   3084: 
1.648     raeburn  3085: =item * &getemails($uname,$udom)
1.542     raeburn  3086: 
                   3087: Gets a user's email information and returns it as a hash with keys:
                   3088: notification, critnotification, permanentemail
                   3089: 
                   3090: For notification and critnotification, values are comma-separated lists 
1.648     raeburn  3091: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542     raeburn  3092:  
1.648     raeburn  3093: 
1.542     raeburn  3094: =cut
                   3095: 
1.648     raeburn  3096: 
1.466     albertel 3097: sub getemails {
                   3098:     my ($uname,$udom)=@_;
                   3099:     if ($udom eq 'public' && $uname eq 'public') {
                   3100: 	return;
                   3101:     }
1.467     www      3102:     if (!$udom) { $udom=$env{'user.domain'}; }
                   3103:     if (!$uname) { $uname=$env{'user.name'}; }
1.466     albertel 3104:     my $id=$uname.':'.$udom;
                   3105:     my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
                   3106:     if ($cached) {
                   3107: 	return %{$names};
                   3108:     } else {
                   3109: 	my %loadnames=&Apache::lonnet::get('environment',
                   3110:                     			   ['notification','critnotification',
                   3111: 					    'permanentemail'],
                   3112: 					   $udom,$uname);
                   3113: 	&Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
                   3114: 	return %loadnames;
                   3115:     }
                   3116: }
                   3117: 
1.551     albertel 3118: sub flush_email_cache {
                   3119:     my ($uname,$udom)=@_;
                   3120:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   3121:     if (!$uname) { $uname=$env{'user.name'};   }
                   3122:     return if ($udom eq 'public' && $uname eq 'public');
                   3123:     my $id=$uname.':'.$udom;
                   3124:     &Apache::lonnet::devalidate_cache_new('emailscache',$id);
                   3125: }
                   3126: 
1.728     raeburn  3127: # -------------------------------------------------------------------- getlangs
                   3128: 
                   3129: =pod
                   3130: 
                   3131: =item * &getlangs($uname,$udom)
                   3132: 
                   3133: Gets a user's language preference and returns it as a hash with key:
                   3134: language.
                   3135: 
                   3136: =cut
                   3137: 
                   3138: 
                   3139: sub getlangs {
                   3140:     my ($uname,$udom) = @_;
                   3141:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   3142:     if (!$uname) { $uname=$env{'user.name'};   }
                   3143:     my $id=$uname.':'.$udom;
                   3144:     my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
                   3145:     if ($cached) {
                   3146:         return %{$langs};
                   3147:     } else {
                   3148:         my %loadlangs=&Apache::lonnet::get('environment',['languages'],
                   3149:                                            $udom,$uname);
                   3150:         &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
                   3151:         return %loadlangs;
                   3152:     }
                   3153: }
                   3154: 
                   3155: sub flush_langs_cache {
                   3156:     my ($uname,$udom)=@_;
                   3157:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   3158:     if (!$uname) { $uname=$env{'user.name'};   }
                   3159:     return if ($udom eq 'public' && $uname eq 'public');
                   3160:     my $id=$uname.':'.$udom;
                   3161:     &Apache::lonnet::devalidate_cache_new('userlangs',$id);
                   3162: }
                   3163: 
1.61      www      3164: # ------------------------------------------------------------------ Screenname
1.81      albertel 3165: 
                   3166: =pod
                   3167: 
1.648     raeburn  3168: =item * &screenname($uname,$udom)
1.81      albertel 3169: 
                   3170: Gets a users screenname and returns it as a string
                   3171: 
                   3172: =cut
1.61      www      3173: 
                   3174: sub screenname {
                   3175:     my ($uname,$udom)=@_;
1.258     albertel 3176:     if ($uname eq $env{'user.name'} &&
                   3177: 	$udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212     albertel 3178:     my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68      albertel 3179:     return $names{'screenname'};
1.62      www      3180: }
                   3181: 
1.212     albertel 3182: 
1.802     bisitz   3183: # ------------------------------------------------------------- Confirm Wrapper
                   3184: =pod
                   3185: 
                   3186: =item confirmwrapper
                   3187: 
                   3188: Wrap messages about completion of operation in box
                   3189: 
                   3190: =cut
                   3191: 
                   3192: sub confirmwrapper {
                   3193:     my ($message)=@_;
                   3194:     if ($message) {
                   3195:         return "\n".'<div class="LC_confirm_box">'."\n"
                   3196:                .$message."\n"
                   3197:                .'</div>'."\n";
                   3198:     } else {
                   3199:         return $message;
                   3200:     }
                   3201: }
                   3202: 
1.62      www      3203: # ------------------------------------------------------------- Message Wrapper
                   3204: 
                   3205: sub messagewrapper {
1.369     www      3206:     my ($link,$username,$domain,$subject,$text)=@_;
1.62      www      3207:     return 
1.441     albertel 3208:         '<a href="/adm/email?compose=individual&amp;'.
                   3209:         'recname='.$username.'&amp;recdom='.$domain.
                   3210: 	'&amp;subject='.&escape($subject).'&amp;text='.&escape($text).'" '.
1.200     matthew  3211:         'title="'.&mt('Send message').'">'.$link.'</a>';
1.74      www      3212: }
1.802     bisitz   3213: 
1.74      www      3214: # --------------------------------------------------------------- Notes Wrapper
                   3215: 
                   3216: sub noteswrapper {
                   3217:     my ($link,$un,$do)=@_;
                   3218:     return 
1.896     amueller 3219: "<a href='/adm/email?recordftf=retrieve&amp;recname=$un&amp;recdom=$do'>$link</a>";
1.62      www      3220: }
1.802     bisitz   3221: 
1.62      www      3222: # ------------------------------------------------------------- Aboutme Wrapper
                   3223: 
                   3224: sub aboutmewrapper {
1.1070    raeburn  3225:     my ($link,$username,$domain,$target,$class)=@_;
1.447     raeburn  3226:     if (!defined($username)  && !defined($domain)) {
                   3227:         return;
                   3228:     }
1.892     amueller 3229:     return '<a href="/adm/'.$domain.'/'.$username.'/aboutme?forcestudent=1"'.
1.1070    raeburn  3230: 	($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62      www      3231: }
                   3232: 
                   3233: # ------------------------------------------------------------ Syllabus Wrapper
                   3234: 
                   3235: sub syllabuswrapper {
1.707     bisitz   3236:     my ($linktext,$coursedir,$domain)=@_;
1.208     matthew  3237:     return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61      www      3238: }
1.14      harris41 3239: 
1.802     bisitz   3240: # -----------------------------------------------------------------------------
                   3241: 
1.208     matthew  3242: sub track_student_link {
1.887     raeburn  3243:     my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268     albertel 3244:     my $link ="/adm/trackstudent?";
1.208     matthew  3245:     my $title = 'View recent activity';
                   3246:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   3247:         defined($sdom)  && $sdom  !~ /^\s*$/) {
1.268     albertel 3248:         $link .= "selected_student=$sname:$sdom";
1.208     matthew  3249:         $title .= ' of this student';
1.268     albertel 3250:     } 
1.208     matthew  3251:     if (defined($target) && $target !~ /^\s*$/) {
                   3252:         $target = qq{target="$target"};
                   3253:     } else {
                   3254:         $target = '';
                   3255:     }
1.268     albertel 3256:     if ($start) { $link.='&amp;start='.$start; }
1.887     raeburn  3257:     if ($only_body) { $link .= '&amp;only_body=1'; }
1.554     albertel 3258:     $title = &mt($title);
                   3259:     $linktext = &mt($linktext);
1.448     albertel 3260:     return qq{<a href="$link" title="$title" $target>$linktext</a>}.
                   3261: 	&help_open_topic('View_recent_activity');
1.208     matthew  3262: }
                   3263: 
1.781     raeburn  3264: sub slot_reservations_link {
                   3265:     my ($linktext,$sname,$sdom,$target) = @_;
                   3266:     my $link ="/adm/slotrequest?command=showresv&amp;origin=aboutme";
                   3267:     my $title = 'View slot reservation history';
                   3268:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   3269:         defined($sdom)  && $sdom  !~ /^\s*$/) {
                   3270:         $link .= "&amp;uname=$sname&amp;udom=$sdom";
                   3271:         $title .= ' of this student';
                   3272:     }
                   3273:     if (defined($target) && $target !~ /^\s*$/) {
                   3274:         $target = qq{target="$target"};
                   3275:     } else {
                   3276:         $target = '';
                   3277:     }
                   3278:     $title = &mt($title);
                   3279:     $linktext = &mt($linktext);
                   3280:     return qq{<a href="$link" title="$title" $target>$linktext</a>};
                   3281: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
                   3282: 
                   3283: }
                   3284: 
1.508     www      3285: # ===================================================== Display a student photo
                   3286: 
                   3287: 
1.509     albertel 3288: sub student_image_tag {
1.508     www      3289:     my ($domain,$user)=@_;
                   3290:     my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
                   3291:     if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
                   3292: 	return '<img src="'.$imgsrc.'" align="right" />';
                   3293:     } else {
                   3294: 	return '';
                   3295:     }
                   3296: }
                   3297: 
1.112     bowersj2 3298: =pod
                   3299: 
                   3300: =back
                   3301: 
                   3302: =head1 Access .tab File Data
                   3303: 
                   3304: =over 4
                   3305: 
1.648     raeburn  3306: =item * &languageids() 
1.112     bowersj2 3307: 
                   3308: returns list of all language ids
                   3309: 
                   3310: =cut
                   3311: 
1.14      harris41 3312: sub languageids {
1.16      harris41 3313:     return sort(keys(%language));
1.14      harris41 3314: }
                   3315: 
1.112     bowersj2 3316: =pod
                   3317: 
1.648     raeburn  3318: =item * &languagedescription() 
1.112     bowersj2 3319: 
                   3320: returns description of a specified language id
                   3321: 
                   3322: =cut
                   3323: 
1.14      harris41 3324: sub languagedescription {
1.125     www      3325:     my $code=shift;
                   3326:     return  ($supported_language{$code}?'* ':'').
                   3327:             $language{$code}.
1.126     www      3328: 	    ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145     www      3329: }
                   3330: 
1.1048    foxr     3331: =pod
                   3332: 
                   3333: =item * &plainlanguagedescription
                   3334: 
                   3335: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
                   3336: and the language character encoding (e.g. ISO) separated by a ' - ' string.
                   3337: 
                   3338: =cut
                   3339: 
1.145     www      3340: sub plainlanguagedescription {
                   3341:     my $code=shift;
                   3342:     return $language{$code};
                   3343: }
                   3344: 
1.1048    foxr     3345: =pod
                   3346: 
                   3347: =item * &supportedlanguagecode
                   3348: 
                   3349: Returns the supported language code (e.g. sptutf maps to pt) given a language
                   3350: code.
                   3351: 
                   3352: =cut
                   3353: 
1.145     www      3354: sub supportedlanguagecode {
                   3355:     my $code=shift;
                   3356:     return $supported_language{$code};
1.97      www      3357: }
                   3358: 
1.112     bowersj2 3359: =pod
                   3360: 
1.1048    foxr     3361: =item * &latexlanguage()
                   3362: 
                   3363: Given a language key code returns the correspondnig language to use
                   3364: to select the correct hyphenation on LaTeX printouts.  This is undef if there
                   3365: is no supported hyphenation for the language code.
                   3366: 
                   3367: =cut
                   3368: 
                   3369: sub latexlanguage {
                   3370:     my $code = shift;
                   3371:     return $latex_language{$code};
                   3372: }
                   3373: 
                   3374: =pod
                   3375: 
                   3376: =item * &latexhyphenation()
                   3377: 
                   3378: Same as above but what's supplied is the language as it might be stored
                   3379: in the metadata.
                   3380: 
                   3381: =cut
                   3382: 
                   3383: sub latexhyphenation {
                   3384:     my $key = shift;
                   3385:     return $latex_language_bykey{$key};
                   3386: }
                   3387: 
                   3388: =pod
                   3389: 
1.648     raeburn  3390: =item * &copyrightids() 
1.112     bowersj2 3391: 
                   3392: returns list of all copyrights
                   3393: 
                   3394: =cut
                   3395: 
                   3396: sub copyrightids {
                   3397:     return sort(keys(%cprtag));
                   3398: }
                   3399: 
                   3400: =pod
                   3401: 
1.648     raeburn  3402: =item * &copyrightdescription() 
1.112     bowersj2 3403: 
                   3404: returns description of a specified copyright id
                   3405: 
                   3406: =cut
                   3407: 
                   3408: sub copyrightdescription {
1.166     www      3409:     return &mt($cprtag{shift(@_)});
1.112     bowersj2 3410: }
1.197     matthew  3411: 
                   3412: =pod
                   3413: 
1.648     raeburn  3414: =item * &source_copyrightids() 
1.192     taceyjo1 3415: 
                   3416: returns list of all source copyrights
                   3417: 
                   3418: =cut
                   3419: 
                   3420: sub source_copyrightids {
                   3421:     return sort(keys(%scprtag));
                   3422: }
                   3423: 
                   3424: =pod
                   3425: 
1.648     raeburn  3426: =item * &source_copyrightdescription() 
1.192     taceyjo1 3427: 
                   3428: returns description of a specified source copyright id
                   3429: 
                   3430: =cut
                   3431: 
                   3432: sub source_copyrightdescription {
                   3433:     return &mt($scprtag{shift(@_)});
                   3434: }
1.112     bowersj2 3435: 
                   3436: =pod
                   3437: 
1.648     raeburn  3438: =item * &filecategories() 
1.112     bowersj2 3439: 
                   3440: returns list of all file categories
                   3441: 
                   3442: =cut
                   3443: 
                   3444: sub filecategories {
                   3445:     return sort(keys(%category_extensions));
                   3446: }
                   3447: 
                   3448: =pod
                   3449: 
1.648     raeburn  3450: =item * &filecategorytypes() 
1.112     bowersj2 3451: 
                   3452: returns list of file types belonging to a given file
                   3453: category
                   3454: 
                   3455: =cut
                   3456: 
                   3457: sub filecategorytypes {
1.356     albertel 3458:     my ($cat) = @_;
                   3459:     return @{$category_extensions{lc($cat)}};
1.112     bowersj2 3460: }
                   3461: 
                   3462: =pod
                   3463: 
1.648     raeburn  3464: =item * &fileembstyle() 
1.112     bowersj2 3465: 
                   3466: returns embedding style for a specified file type
                   3467: 
                   3468: =cut
                   3469: 
                   3470: sub fileembstyle {
                   3471:     return $fe{lc(shift(@_))};
1.169     www      3472: }
                   3473: 
1.351     www      3474: sub filemimetype {
                   3475:     return $fm{lc(shift(@_))};
                   3476: }
                   3477: 
1.169     www      3478: 
                   3479: sub filecategoryselect {
                   3480:     my ($name,$value)=@_;
1.189     matthew  3481:     return &select_form($value,$name,
1.970     raeburn  3482:                         {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112     bowersj2 3483: }
                   3484: 
                   3485: =pod
                   3486: 
1.648     raeburn  3487: =item * &filedescription() 
1.112     bowersj2 3488: 
                   3489: returns description for a specified file type
                   3490: 
                   3491: =cut
                   3492: 
                   3493: sub filedescription {
1.188     matthew  3494:     my $file_description = $fd{lc(shift())};
                   3495:     $file_description =~ s:([\[\]]):~$1:g;
                   3496:     return &mt($file_description);
1.112     bowersj2 3497: }
                   3498: 
                   3499: =pod
                   3500: 
1.648     raeburn  3501: =item * &filedescriptionex() 
1.112     bowersj2 3502: 
                   3503: returns description for a specified file type with
                   3504: extra formatting
                   3505: 
                   3506: =cut
                   3507: 
                   3508: sub filedescriptionex {
                   3509:     my $ex=shift;
1.188     matthew  3510:     my $file_description = $fd{lc($ex)};
                   3511:     $file_description =~ s:([\[\]]):~$1:g;
                   3512:     return '.'.$ex.' '.&mt($file_description);
1.112     bowersj2 3513: }
                   3514: 
                   3515: # End of .tab access
                   3516: =pod
                   3517: 
                   3518: =back
                   3519: 
                   3520: =cut
                   3521: 
                   3522: # ------------------------------------------------------------------ File Types
                   3523: sub fileextensions {
                   3524:     return sort(keys(%fe));
                   3525: }
                   3526: 
1.97      www      3527: # ----------------------------------------------------------- Display Languages
                   3528: # returns a hash with all desired display languages
                   3529: #
                   3530: 
                   3531: sub display_languages {
                   3532:     my %languages=();
1.695     raeburn  3533:     foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356     albertel 3534: 	$languages{$lang}=1;
1.97      www      3535:     }
                   3536:     &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258     albertel 3537:     if ($env{'form.displaylanguage'}) {
1.356     albertel 3538: 	foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
                   3539: 	    $languages{$lang}=1;
1.97      www      3540:         }
                   3541:     }
                   3542:     return %languages;
1.14      harris41 3543: }
                   3544: 
1.582     albertel 3545: sub languages {
                   3546:     my ($possible_langs) = @_;
1.695     raeburn  3547:     my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582     albertel 3548:     if (!ref($possible_langs)) {
                   3549: 	if( wantarray ) {
                   3550: 	    return @preferred_langs;
                   3551: 	} else {
                   3552: 	    return $preferred_langs[0];
                   3553: 	}
                   3554:     }
                   3555:     my %possibilities = map { $_ => 1 } (@$possible_langs);
                   3556:     my @preferred_possibilities;
                   3557:     foreach my $preferred_lang (@preferred_langs) {
                   3558: 	if (exists($possibilities{$preferred_lang})) {
                   3559: 	    push(@preferred_possibilities, $preferred_lang);
                   3560: 	}
                   3561:     }
                   3562:     if( wantarray ) {
                   3563: 	return @preferred_possibilities;
                   3564:     }
                   3565:     return $preferred_possibilities[0];
                   3566: }
                   3567: 
1.742     raeburn  3568: sub user_lang {
                   3569:     my ($touname,$toudom,$fromcid) = @_;
                   3570:     my @userlangs;
                   3571:     if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
                   3572:         @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
                   3573:                     $env{'course.'.$fromcid.'.languages'}));
                   3574:     } else {
                   3575:         my %langhash = &getlangs($touname,$toudom);
                   3576:         if ($langhash{'languages'} ne '') {
                   3577:             @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
                   3578:         } else {
                   3579:             my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
                   3580:             if ($domdefs{'lang_def'} ne '') {
                   3581:                 @userlangs = ($domdefs{'lang_def'});
                   3582:             }
                   3583:         }
                   3584:     }
                   3585:     my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
                   3586:     my $user_lh = Apache::localize->get_handle(@languages);
                   3587:     return $user_lh;
                   3588: }
                   3589: 
                   3590: 
1.112     bowersj2 3591: ###############################################################
                   3592: ##               Student Answer Attempts                     ##
                   3593: ###############################################################
                   3594: 
                   3595: =pod
                   3596: 
                   3597: =head1 Alternate Problem Views
                   3598: 
                   3599: =over 4
                   3600: 
1.648     raeburn  3601: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112     bowersj2 3602:     $getattempt, $regexp, $gradesub)
                   3603: 
                   3604: Return string with previous attempt on problem. Arguments:
                   3605: 
                   3606: =over 4
                   3607: 
                   3608: =item * $symb: Problem, including path
                   3609: 
                   3610: =item * $username: username of the desired student
                   3611: 
                   3612: =item * $domain: domain of the desired student
1.14      harris41 3613: 
1.112     bowersj2 3614: =item * $course: Course ID
1.14      harris41 3615: 
1.112     bowersj2 3616: =item * $getattempt: Leave blank for all attempts, otherwise put
                   3617:     something
1.14      harris41 3618: 
1.112     bowersj2 3619: =item * $regexp: if string matches this regexp, the string will be
                   3620:     sent to $gradesub
1.14      harris41 3621: 
1.112     bowersj2 3622: =item * $gradesub: routine that processes the string if it matches $regexp
1.14      harris41 3623: 
1.112     bowersj2 3624: =back
1.14      harris41 3625: 
1.112     bowersj2 3626: The output string is a table containing all desired attempts, if any.
1.16      harris41 3627: 
1.112     bowersj2 3628: =cut
1.1       albertel 3629: 
                   3630: sub get_previous_attempt {
1.43      ng       3631:   my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1       albertel 3632:   my $prevattempts='';
1.43      ng       3633:   no strict 'refs';
1.1       albertel 3634:   if ($symb) {
1.3       albertel 3635:     my (%returnhash)=
                   3636:       &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1       albertel 3637:     if ($returnhash{'version'}) {
                   3638:       my %lasthash=();
                   3639:       my $version;
                   3640:       for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356     albertel 3641:         foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
                   3642: 	  $lasthash{$key}=$returnhash{$version.':'.$key};
1.19      harris41 3643:         }
1.1       albertel 3644:       }
1.596     albertel 3645:       $prevattempts=&start_data_table().&start_data_table_header_row();
                   3646:       $prevattempts.='<th>'.&mt('History').'</th>';
1.978     raeburn  3647:       my (%typeparts,%lasthidden);
1.945     raeburn  3648:       my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356     albertel 3649:       foreach my $key (sort(keys(%lasthash))) {
                   3650: 	my ($ign,@parts) = split(/\./,$key);
1.41      ng       3651: 	if ($#parts > 0) {
1.31      albertel 3652: 	  my $data=$parts[-1];
1.989     raeburn  3653:           next if ($data eq 'foilorder');
1.31      albertel 3654: 	  pop(@parts);
1.1010    www      3655:           $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.'&nbsp;</th>';
1.945     raeburn  3656:           if ($data eq 'type') {
                   3657:               unless ($showsurv) {
                   3658:                   my $id = join(',',@parts);
                   3659:                   $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978     raeburn  3660:                   if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
                   3661:                       $lasthidden{$ign.'.'.$id} = 1;
                   3662:                   }
1.945     raeburn  3663:               }
1.1010    www      3664:           } 
1.31      albertel 3665: 	} else {
1.41      ng       3666: 	  if ($#parts == 0) {
                   3667: 	    $prevattempts.='<th>'.$parts[0].'</th>';
                   3668: 	  } else {
                   3669: 	    $prevattempts.='<th>'.$ign.'</th>';
                   3670: 	  }
1.31      albertel 3671: 	}
1.16      harris41 3672:       }
1.596     albertel 3673:       $prevattempts.=&end_data_table_header_row();
1.40      ng       3674:       if ($getattempt eq '') {
                   3675: 	for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945     raeburn  3676:             my @hidden;
                   3677:             if (%typeparts) {
                   3678:                 foreach my $id (keys(%typeparts)) {
                   3679:                     if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
                   3680:                         push(@hidden,$id);
                   3681:                     }
                   3682:                 }
                   3683:             }
                   3684:             $prevattempts.=&start_data_table_row().
                   3685:                            '<td>'.&mt('Transaction [_1]',$version).'</td>';
                   3686:             if (@hidden) {
                   3687:                 foreach my $key (sort(keys(%lasthash))) {
1.989     raeburn  3688:                     next if ($key =~ /\.foilorder$/);
1.945     raeburn  3689:                     my $hide;
                   3690:                     foreach my $id (@hidden) {
                   3691:                         if ($key =~ /^\Q$id\E/) {
                   3692:                             $hide = 1;
                   3693:                             last;
                   3694:                         }
                   3695:                     }
                   3696:                     if ($hide) {
                   3697:                         my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
                   3698:                         if (($data eq 'award') || ($data eq 'awarddetail')) {
                   3699:                             my $value = &format_previous_attempt_value($key,
                   3700:                                              $returnhash{$version.':'.$key});
                   3701:                             $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3702:                         } else {
                   3703:                             $prevattempts.='<td>&nbsp;</td>';
                   3704:                         }
                   3705:                     } else {
                   3706:                         if ($key =~ /\./) {
                   3707:                             my $value = &format_previous_attempt_value($key,
                   3708:                                               $returnhash{$version.':'.$key});
                   3709:                             $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3710:                         } else {
                   3711:                             $prevattempts.='<td>&nbsp;</td>';
                   3712:                         }
                   3713:                     }
                   3714:                 }
                   3715:             } else {
                   3716: 	        foreach my $key (sort(keys(%lasthash))) {
1.989     raeburn  3717:                     next if ($key =~ /\.foilorder$/);
1.945     raeburn  3718: 		    my $value = &format_previous_attempt_value($key,
                   3719: 			            $returnhash{$version.':'.$key});
                   3720: 		    $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3721: 	        }
                   3722:             }
                   3723: 	    $prevattempts.=&end_data_table_row();
1.40      ng       3724: 	 }
1.1       albertel 3725:       }
1.945     raeburn  3726:       my @currhidden = keys(%lasthidden);
1.596     albertel 3727:       $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356     albertel 3728:       foreach my $key (sort(keys(%lasthash))) {
1.989     raeburn  3729:           next if ($key =~ /\.foilorder$/);
1.945     raeburn  3730:           if (%typeparts) {
                   3731:               my $hidden;
                   3732:               foreach my $id (@currhidden) {
                   3733:                   if ($key =~ /^\Q$id\E/) {
                   3734:                       $hidden = 1;
                   3735:                       last;
                   3736:                   }
                   3737:               }
                   3738:               if ($hidden) {
                   3739:                   my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
                   3740:                   if (($data eq 'award') || ($data eq 'awarddetail')) {
                   3741:                       my $value = &format_previous_attempt_value($key,$lasthash{$key});
                   3742:                       if ($key =~/$regexp$/ && (defined &$gradesub)) {
                   3743:                           $value = &$gradesub($value);
                   3744:                       }
                   3745:                       $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3746:                   } else {
                   3747:                       $prevattempts.='<td>&nbsp;</td>';
                   3748:                   }
                   3749:               } else {
                   3750:                   my $value = &format_previous_attempt_value($key,$lasthash{$key});
                   3751:                   if ($key =~/$regexp$/ && (defined &$gradesub)) {
                   3752:                       $value = &$gradesub($value);
                   3753:                   }
                   3754:                   $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3755:               }
                   3756:           } else {
                   3757: 	      my $value = &format_previous_attempt_value($key,$lasthash{$key});
                   3758: 	      if ($key =~/$regexp$/ && (defined &$gradesub)) {
                   3759:                   $value = &$gradesub($value);
                   3760:               }
                   3761: 	      $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3762:           }
1.16      harris41 3763:       }
1.596     albertel 3764:       $prevattempts.= &end_data_table_row().&end_data_table();
1.1       albertel 3765:     } else {
1.596     albertel 3766:       $prevattempts=
                   3767: 	  &start_data_table().&start_data_table_row().
                   3768: 	  '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
                   3769: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3770:     }
                   3771:   } else {
1.596     albertel 3772:     $prevattempts=
                   3773: 	  &start_data_table().&start_data_table_row().
                   3774: 	  '<td>'.&mt('No data.').'</td>'.
                   3775: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3776:   }
1.10      albertel 3777: }
                   3778: 
1.581     albertel 3779: sub format_previous_attempt_value {
                   3780:     my ($key,$value) = @_;
1.1011    www      3781:     if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581     albertel 3782: 	$value = &Apache::lonlocal::locallocaltime($value);
                   3783:     } elsif (ref($value) eq 'ARRAY') {
                   3784: 	$value = '('.join(', ', @{ $value }).')';
1.988     raeburn  3785:     } elsif ($key =~ /answerstring$/) {
                   3786:         my %answers = &Apache::lonnet::str2hash($value);
                   3787:         my @anskeys = sort(keys(%answers));
                   3788:         if (@anskeys == 1) {
                   3789:             my $answer = $answers{$anskeys[0]};
1.1001    raeburn  3790:             if ($answer =~ m{\0}) {
                   3791:                 $answer =~ s{\0}{,}g;
1.988     raeburn  3792:             }
                   3793:             my $tag_internal_answer_name = 'INTERNAL';
                   3794:             if ($anskeys[0] eq $tag_internal_answer_name) {
                   3795:                 $value = $answer; 
                   3796:             } else {
                   3797:                 $value = $anskeys[0].'='.$answer;
                   3798:             }
                   3799:         } else {
                   3800:             foreach my $ans (@anskeys) {
                   3801:                 my $answer = $answers{$ans};
1.1001    raeburn  3802:                 if ($answer =~ m{\0}) {
                   3803:                     $answer =~ s{\0}{,}g;
1.988     raeburn  3804:                 }
                   3805:                 $value .=  $ans.'='.$answer.'<br />';;
                   3806:             } 
                   3807:         }
1.581     albertel 3808:     } else {
                   3809: 	$value = &unescape($value);
                   3810:     }
                   3811:     return $value;
                   3812: }
                   3813: 
                   3814: 
1.107     albertel 3815: sub relative_to_absolute {
                   3816:     my ($url,$output)=@_;
                   3817:     my $parser=HTML::TokeParser->new(\$output);
                   3818:     my $token;
                   3819:     my $thisdir=$url;
                   3820:     my @rlinks=();
                   3821:     while ($token=$parser->get_token) {
                   3822: 	if ($token->[0] eq 'S') {
                   3823: 	    if ($token->[1] eq 'a') {
                   3824: 		if ($token->[2]->{'href'}) {
                   3825: 		    $rlinks[$#rlinks+1]=$token->[2]->{'href'};
                   3826: 		}
                   3827: 	    } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
                   3828: 		$rlinks[$#rlinks+1]=$token->[2]->{'src'};
                   3829: 	    } elsif ($token->[1] eq 'base') {
                   3830: 		$thisdir=$token->[2]->{'href'};
                   3831: 	    }
                   3832: 	}
                   3833:     }
                   3834:     $thisdir=~s-/[^/]*$--;
1.356     albertel 3835:     foreach my $link (@rlinks) {
1.726     raeburn  3836: 	unless (($link=~/^https?\:\/\//i) ||
1.356     albertel 3837: 		($link=~/^\//) ||
                   3838: 		($link=~/^javascript:/i) ||
                   3839: 		($link=~/^mailto:/i) ||
                   3840: 		($link=~/^\#/)) {
                   3841: 	    my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
                   3842: 	    $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107     albertel 3843: 	}
                   3844:     }
                   3845: # -------------------------------------------------- Deal with Applet codebases
                   3846:     $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
                   3847:     return $output;
                   3848: }
                   3849: 
1.112     bowersj2 3850: =pod
                   3851: 
1.648     raeburn  3852: =item * &get_student_view()
1.112     bowersj2 3853: 
                   3854: show a snapshot of what student was looking at
                   3855: 
                   3856: =cut
                   3857: 
1.10      albertel 3858: sub get_student_view {
1.186     albertel 3859:   my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114     www      3860:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3861:   my (%form);
1.10      albertel 3862:   my @elements=('symb','courseid','domain','username');
                   3863:   foreach my $element (@elements) {
1.186     albertel 3864:       $form{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3865:   }
1.186     albertel 3866:   if (defined($moreenv)) {
                   3867:       %form=(%form,%{$moreenv});
                   3868:   }
1.236     albertel 3869:   if (defined($target)) { $form{'grade_target'} = $target; }
1.107     albertel 3870:   $feedurl=&Apache::lonnet::clutter($feedurl);
1.650     www      3871:   my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11      albertel 3872:   $userview=~s/\<body[^\>]*\>//gi;
                   3873:   $userview=~s/\<\/body\>//gi;
                   3874:   $userview=~s/\<html\>//gi;
                   3875:   $userview=~s/\<\/html\>//gi;
                   3876:   $userview=~s/\<head\>//gi;
                   3877:   $userview=~s/\<\/head\>//gi;
                   3878:   $userview=~s/action\s*\=/would_be_action\=/gi;
1.107     albertel 3879:   $userview=&relative_to_absolute($feedurl,$userview);
1.650     www      3880:   if (wantarray) {
                   3881:      return ($userview,$response);
                   3882:   } else {
                   3883:      return $userview;
                   3884:   }
                   3885: }
                   3886: 
                   3887: sub get_student_view_with_retries {
                   3888:   my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
                   3889: 
                   3890:     my $ok = 0;                 # True if we got a good response.
                   3891:     my $content;
                   3892:     my $response;
                   3893: 
                   3894:     # Try to get the student_view done. within the retries count:
                   3895:     
                   3896:     do {
                   3897:          ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
                   3898:          $ok      = $response->is_success;
                   3899:          if (!$ok) {
                   3900:             &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
                   3901:          }
                   3902:          $retries--;
                   3903:     } while (!$ok && ($retries > 0));
                   3904:     
                   3905:     if (!$ok) {
                   3906:        $content = '';          # On error return an empty content.
                   3907:     }
1.651     www      3908:     if (wantarray) {
                   3909:        return ($content, $response);
                   3910:     } else {
                   3911:        return $content;
                   3912:     }
1.11      albertel 3913: }
                   3914: 
1.112     bowersj2 3915: =pod
                   3916: 
1.648     raeburn  3917: =item * &get_student_answers() 
1.112     bowersj2 3918: 
                   3919: show a snapshot of how student was answering problem
                   3920: 
                   3921: =cut
                   3922: 
1.11      albertel 3923: sub get_student_answers {
1.100     sakharuk 3924:   my ($symb,$username,$domain,$courseid,%form) = @_;
1.114     www      3925:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3926:   my (%moreenv);
1.11      albertel 3927:   my @elements=('symb','courseid','domain','username');
                   3928:   foreach my $element (@elements) {
1.186     albertel 3929:     $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3930:   }
1.186     albertel 3931:   $moreenv{'grade_target'}='answer';
                   3932:   %moreenv=(%form,%moreenv);
1.497     raeburn  3933:   $feedurl = &Apache::lonnet::clutter($feedurl);
                   3934:   my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10      albertel 3935:   return $userview;
1.1       albertel 3936: }
1.116     albertel 3937: 
                   3938: =pod
                   3939: 
                   3940: =item * &submlink()
                   3941: 
1.242     albertel 3942: Inputs: $text $uname $udom $symb $target
1.116     albertel 3943: 
                   3944: Returns: A link to grades.pm such as to see the SUBM view of a student
                   3945: 
                   3946: =cut
                   3947: 
                   3948: ###############################################
                   3949: sub submlink {
1.242     albertel 3950:     my ($text,$uname,$udom,$symb,$target)=@_;
1.116     albertel 3951:     if (!($uname && $udom)) {
                   3952: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3953: 	    &Apache::lonnet::whichuser($symb);
1.116     albertel 3954: 	if (!$symb) { $symb=$cursymb; }
                   3955:     }
1.254     matthew  3956:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3957:     $symb=&escape($symb);
1.960     bisitz   3958:     if ($target) { $target=" target=\"$target\""; }
                   3959:     return
                   3960:         '<a href="/adm/grades?command=submission'.
                   3961:         '&amp;symb='.$symb.
                   3962:         '&amp;student='.$uname.
                   3963:         '&amp;userdom='.$udom.'"'.
                   3964:         $target.'>'.$text.'</a>';
1.242     albertel 3965: }
                   3966: ##############################################
                   3967: 
                   3968: =pod
                   3969: 
                   3970: =item * &pgrdlink()
                   3971: 
                   3972: Inputs: $text $uname $udom $symb $target
                   3973: 
                   3974: Returns: A link to grades.pm such as to see the PGRD view of a student
                   3975: 
                   3976: =cut
                   3977: 
                   3978: ###############################################
                   3979: sub pgrdlink {
                   3980:     my $link=&submlink(@_);
                   3981:     $link=~s/(&command=submission)/$1&showgrading=yes/;
                   3982:     return $link;
                   3983: }
                   3984: ##############################################
                   3985: 
                   3986: =pod
                   3987: 
                   3988: =item * &pprmlink()
                   3989: 
                   3990: Inputs: $text $uname $udom $symb $target
                   3991: 
                   3992: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283     albertel 3993: student and a specific resource
1.242     albertel 3994: 
                   3995: =cut
                   3996: 
                   3997: ###############################################
                   3998: sub pprmlink {
                   3999:     my ($text,$uname,$udom,$symb,$target)=@_;
                   4000:     if (!($uname && $udom)) {
                   4001: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 4002: 	    &Apache::lonnet::whichuser($symb);
1.242     albertel 4003: 	if (!$symb) { $symb=$cursymb; }
                   4004:     }
1.254     matthew  4005:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      4006:     $symb=&escape($symb);
1.242     albertel 4007:     if ($target) { $target="target=\"$target\""; }
1.595     albertel 4008:     return '<a href="/adm/parmset?command=set&amp;'.
                   4009: 	'symb='.$symb.'&amp;uname='.$uname.
                   4010: 	'&amp;udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116     albertel 4011: }
                   4012: ##############################################
1.37      matthew  4013: 
1.112     bowersj2 4014: =pod
                   4015: 
                   4016: =back
                   4017: 
                   4018: =cut
                   4019: 
1.37      matthew  4020: ###############################################
1.51      www      4021: 
                   4022: 
                   4023: sub timehash {
1.687     raeburn  4024:     my ($thistime) = @_;
                   4025:     my $timezone = &Apache::lonlocal::gettimezone();
                   4026:     my $dt = DateTime->from_epoch(epoch => $thistime)
                   4027:                      ->set_time_zone($timezone);
                   4028:     my $wday = $dt->day_of_week();
                   4029:     if ($wday == 7) { $wday = 0; }
                   4030:     return ( 'second' => $dt->second(),
                   4031:              'minute' => $dt->minute(),
                   4032:              'hour'   => $dt->hour(),
                   4033:              'day'     => $dt->day_of_month(),
                   4034:              'month'   => $dt->month(),
                   4035:              'year'    => $dt->year(),
                   4036:              'weekday' => $wday,
                   4037:              'dayyear' => $dt->day_of_year(),
                   4038:              'dlsav'   => $dt->is_dst() );
1.51      www      4039: }
                   4040: 
1.370     www      4041: sub utc_string {
                   4042:     my ($date)=@_;
1.371     www      4043:     return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370     www      4044: }
                   4045: 
1.51      www      4046: sub maketime {
                   4047:     my %th=@_;
1.687     raeburn  4048:     my ($epoch_time,$timezone,$dt);
                   4049:     $timezone = &Apache::lonlocal::gettimezone();
                   4050:     eval {
                   4051:         $dt = DateTime->new( year   => $th{'year'},
                   4052:                              month  => $th{'month'},
                   4053:                              day    => $th{'day'},
                   4054:                              hour   => $th{'hour'},
                   4055:                              minute => $th{'minute'},
                   4056:                              second => $th{'second'},
                   4057:                              time_zone => $timezone,
                   4058:                          );
                   4059:     };
                   4060:     if (!$@) {
                   4061:         $epoch_time = $dt->epoch;
                   4062:         if ($epoch_time) {
                   4063:             return $epoch_time;
                   4064:         }
                   4065:     }
1.51      www      4066:     return POSIX::mktime(
                   4067:         ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210     www      4068:          $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70      www      4069: }
                   4070: 
                   4071: #########################################
1.51      www      4072: 
                   4073: sub findallcourses {
1.482     raeburn  4074:     my ($roles,$uname,$udom) = @_;
1.355     albertel 4075:     my %roles;
                   4076:     if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348     albertel 4077:     my %courses;
1.51      www      4078:     my $now=time;
1.482     raeburn  4079:     if (!defined($uname)) {
                   4080:         $uname = $env{'user.name'};
                   4081:     }
                   4082:     if (!defined($udom)) {
                   4083:         $udom = $env{'user.domain'};
                   4084:     }
                   4085:     if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073    raeburn  4086:         my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482     raeburn  4087:         if (!%roles) {
                   4088:             %roles = (
                   4089:                        cc => 1,
1.907     raeburn  4090:                        co => 1,
1.482     raeburn  4091:                        in => 1,
                   4092:                        ep => 1,
                   4093:                        ta => 1,
                   4094:                        cr => 1,
                   4095:                        st => 1,
                   4096:              );
                   4097:         }
                   4098:         foreach my $entry (keys(%roleshash)) {
                   4099:             my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
                   4100:             if ($trole =~ /^cr/) { 
                   4101:                 next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
                   4102:             } else {
                   4103:                 next if (!exists($roles{$trole}));
                   4104:             }
                   4105:             if ($tend) {
                   4106:                 next if ($tend < $now);
                   4107:             }
                   4108:             if ($tstart) {
                   4109:                 next if ($tstart > $now);
                   4110:             }
1.1058    raeburn  4111:             my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482     raeburn  4112:             (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058    raeburn  4113:             my $value = $trole.'/'.$cdom.'/';
1.482     raeburn  4114:             if ($secpart eq '') {
                   4115:                 ($cnum,$role) = split(/_/,$cnumpart); 
                   4116:                 $sec = 'none';
1.1058    raeburn  4117:                 $value .= $cnum.'/';
1.482     raeburn  4118:             } else {
                   4119:                 $cnum = $cnumpart;
                   4120:                 ($sec,$role) = split(/_/,$secpart);
1.1058    raeburn  4121:                 $value .= $cnum.'/'.$sec;
                   4122:             }
                   4123:             if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
                   4124:                 unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
                   4125:                     push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
                   4126:                 }
                   4127:             } else {
                   4128:                 @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490     raeburn  4129:             }
1.482     raeburn  4130:         }
                   4131:     } else {
                   4132:         foreach my $key (keys(%env)) {
1.483     albertel 4133: 	    if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
                   4134:                  $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482     raeburn  4135: 	        my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
                   4136: 	        next if ($role eq 'ca' || $role eq 'aa');
                   4137: 	        next if (%roles && !exists($roles{$role}));
                   4138: 	        my ($starttime,$endtime)=split(/\./,$env{$key});
                   4139:                 my $active=1;
                   4140:                 if ($starttime) {
                   4141: 		    if ($now<$starttime) { $active=0; }
                   4142:                 }
                   4143:                 if ($endtime) {
                   4144:                     if ($now>$endtime) { $active=0; }
                   4145:                 }
                   4146:                 if ($active) {
1.1058    raeburn  4147:                     my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482     raeburn  4148:                     if ($sec eq '') {
                   4149:                         $sec = 'none';
1.1058    raeburn  4150:                     } else {
                   4151:                         $value .= $sec;
                   4152:                     }
                   4153:                     if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
                   4154:                         unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
                   4155:                             push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
                   4156:                         }
                   4157:                     } else {
                   4158:                         @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482     raeburn  4159:                     }
1.474     raeburn  4160:                 }
                   4161:             }
1.51      www      4162:         }
                   4163:     }
1.474     raeburn  4164:     return %courses;
1.51      www      4165: }
1.37      matthew  4166: 
1.54      www      4167: ###############################################
1.474     raeburn  4168: 
                   4169: sub blockcheck {
1.1062    raeburn  4170:     my ($setters,$activity,$uname,$udom,$url) = @_;
1.490     raeburn  4171: 
                   4172:     if (!defined($udom)) {
                   4173:         $udom = $env{'user.domain'};
                   4174:     }
                   4175:     if (!defined($uname)) {
                   4176:         $uname = $env{'user.name'};
                   4177:     }
                   4178: 
                   4179:     # If uname and udom are for a course, check for blocks in the course.
                   4180: 
                   4181:     if (&Apache::lonnet::is_course($udom,$uname)) {
1.1062    raeburn  4182:         my ($startblock,$endblock,$triggerblock) = 
                   4183:             &get_blocks($setters,$activity,$udom,$uname,$url);
                   4184:         return ($startblock,$endblock,$triggerblock);
1.490     raeburn  4185:     }
1.474     raeburn  4186: 
1.502     raeburn  4187:     my $startblock = 0;
                   4188:     my $endblock = 0;
1.1062    raeburn  4189:     my $triggerblock = '';
1.482     raeburn  4190:     my %live_courses = &findallcourses(undef,$uname,$udom);
1.474     raeburn  4191: 
1.490     raeburn  4192:     # If uname is for a user, and activity is course-specific, i.e.,
                   4193:     # boards, chat or groups, check for blocking in current course only.
1.474     raeburn  4194: 
1.490     raeburn  4195:     if (($activity eq 'boards' || $activity eq 'chat' ||
                   4196:          $activity eq 'groups') && ($env{'request.course.id'})) {
                   4197:         foreach my $key (keys(%live_courses)) {
                   4198:             if ($key ne $env{'request.course.id'}) {
                   4199:                 delete($live_courses{$key});
                   4200:             }
                   4201:         }
                   4202:     }
                   4203: 
                   4204:     my $otheruser = 0;
                   4205:     my %own_courses;
                   4206:     if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
                   4207:         # Resource belongs to user other than current user.
                   4208:         $otheruser = 1;
                   4209:         # Gather courses for current user
                   4210:         %own_courses = 
                   4211:             &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
                   4212:     }
                   4213: 
                   4214:     # Gather active course roles - course coordinator, instructor, 
                   4215:     # exam proctor, ta, student, or custom role.
1.474     raeburn  4216: 
                   4217:     foreach my $course (keys(%live_courses)) {
1.482     raeburn  4218:         my ($cdom,$cnum);
                   4219:         if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
                   4220:             $cdom = $env{'course.'.$course.'.domain'};
                   4221:             $cnum = $env{'course.'.$course.'.num'};
                   4222:         } else {
1.490     raeburn  4223:             ($cdom,$cnum) = split(/_/,$course); 
1.482     raeburn  4224:         }
                   4225:         my $no_ownblock = 0;
                   4226:         my $no_userblock = 0;
1.533     raeburn  4227:         if ($otheruser && $activity ne 'com') {
1.490     raeburn  4228:             # Check if current user has 'evb' priv for this
                   4229:             if (defined($own_courses{$course})) {
                   4230:                 foreach my $sec (keys(%{$own_courses{$course}})) {
                   4231:                     my $checkrole = 'cm./'.$cdom.'/'.$cnum;
                   4232:                     if ($sec ne 'none') {
                   4233:                         $checkrole .= '/'.$sec;
                   4234:                     }
                   4235:                     if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   4236:                         $no_ownblock = 1;
                   4237:                         last;
                   4238:                     }
                   4239:                 }
                   4240:             }
                   4241:             # if they have 'evb' priv and are currently not playing student
                   4242:             next if (($no_ownblock) &&
                   4243:                  ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
                   4244:         }
1.474     raeburn  4245:         foreach my $sec (keys(%{$live_courses{$course}})) {
1.482     raeburn  4246:             my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474     raeburn  4247:             if ($sec ne 'none') {
1.482     raeburn  4248:                 $checkrole .= '/'.$sec;
1.474     raeburn  4249:             }
1.490     raeburn  4250:             if ($otheruser) {
                   4251:                 # Resource belongs to user other than current user.
                   4252:                 # Assemble privs for that user, and check for 'evb' priv.
1.1058    raeburn  4253:                 my (%allroles,%userroles);
                   4254:                 if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
                   4255:                     foreach my $entry (@{$live_courses{$course}{$sec}}) { 
                   4256:                         my ($trole,$tdom,$tnum,$tsec);
                   4257:                         if ($entry =~ /^cr/) {
                   4258:                             ($trole,$tdom,$tnum,$tsec) = 
                   4259:                                 ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
                   4260:                         } else {
                   4261:                            ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
                   4262:                         }
                   4263:                         my ($spec,$area,$trest);
                   4264:                         $area = '/'.$tdom.'/'.$tnum;
                   4265:                         $trest = $tnum;
                   4266:                         if ($tsec ne '') {
                   4267:                             $area .= '/'.$tsec;
                   4268:                             $trest .= '/'.$tsec;
                   4269:                         }
                   4270:                         $spec = $trole.'.'.$area;
                   4271:                         if ($trole =~ /^cr/) {
                   4272:                             &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
                   4273:                                                               $tdom,$spec,$trest,$area);
                   4274:                         } else {
                   4275:                             &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
                   4276:                                                                 $tdom,$spec,$trest,$area);
                   4277:                         }
                   4278:                     }
                   4279:                     my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
                   4280:                     if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
                   4281:                         if ($1) {
                   4282:                             $no_userblock = 1;
                   4283:                             last;
                   4284:                         }
1.486     raeburn  4285:                     }
                   4286:                 }
1.490     raeburn  4287:             } else {
                   4288:                 # Resource belongs to current user
                   4289:                 # Check for 'evb' priv via lonnet::allowed().
1.482     raeburn  4290:                 if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   4291:                     $no_ownblock = 1;
                   4292:                     last;
                   4293:                 }
1.474     raeburn  4294:             }
                   4295:         }
                   4296:         # if they have the evb priv and are currently not playing student
1.482     raeburn  4297:         next if (($no_ownblock) &&
1.491     albertel 4298:                  ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482     raeburn  4299:         next if ($no_userblock);
1.474     raeburn  4300: 
1.866     kalberla 4301:         # Retrieve blocking times and identity of locker for course
1.490     raeburn  4302:         # of specified user, unless user has 'evb' privilege.
1.502     raeburn  4303:         
1.1062    raeburn  4304:         my ($start,$end,$trigger) = 
                   4305:             &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502     raeburn  4306:         if (($start != 0) && 
                   4307:             (($startblock == 0) || ($startblock > $start))) {
                   4308:             $startblock = $start;
1.1062    raeburn  4309:             if ($trigger ne '') {
                   4310:                 $triggerblock = $trigger;
                   4311:             }
1.502     raeburn  4312:         }
                   4313:         if (($end != 0)  &&
                   4314:             (($endblock == 0) || ($endblock < $end))) {
                   4315:             $endblock = $end;
1.1062    raeburn  4316:             if ($trigger ne '') {
                   4317:                 $triggerblock = $trigger;
                   4318:             }
1.502     raeburn  4319:         }
1.490     raeburn  4320:     }
1.1062    raeburn  4321:     return ($startblock,$endblock,$triggerblock);
1.490     raeburn  4322: }
                   4323: 
                   4324: sub get_blocks {
1.1062    raeburn  4325:     my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490     raeburn  4326:     my $startblock = 0;
                   4327:     my $endblock = 0;
1.1062    raeburn  4328:     my $triggerblock = '';
1.490     raeburn  4329:     my $course = $cdom.'_'.$cnum;
                   4330:     $setters->{$course} = {};
                   4331:     $setters->{$course}{'staff'} = [];
                   4332:     $setters->{$course}{'times'} = [];
1.1062    raeburn  4333:     $setters->{$course}{'triggers'} = [];
                   4334:     my (@blockers,%triggered);
                   4335:     my $now = time;
                   4336:     my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
                   4337:     if ($activity eq 'docs') {
                   4338:         @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
                   4339:         foreach my $block (@blockers) {
                   4340:             if ($block =~ /^firstaccess____(.+)$/) {
                   4341:                 my $item = $1;
                   4342:                 my $type = 'map';
                   4343:                 my $timersymb = $item;
                   4344:                 if ($item eq 'course') {
                   4345:                     $type = 'course';
                   4346:                 } elsif ($item =~ /___\d+___/) {
                   4347:                     $type = 'resource';
                   4348:                 } else {
                   4349:                     $timersymb = &Apache::lonnet::symbread($item);
                   4350:                 }
                   4351:                 my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
                   4352:                 my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
                   4353:                 $triggered{$block} = {
                   4354:                                        start => $start,
                   4355:                                        end   => $end,
                   4356:                                        type  => $type,
                   4357:                                      };
                   4358:             }
                   4359:         }
                   4360:     } else {
                   4361:         foreach my $block (keys(%commblocks)) {
                   4362:             if ($block =~ m/^(\d+)____(\d+)$/) { 
                   4363:                 my ($start,$end) = ($1,$2);
                   4364:                 if ($start <= time && $end >= time) {
                   4365:                     if (ref($commblocks{$block}) eq 'HASH') {
                   4366:                         if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
                   4367:                             if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
                   4368:                                 unless(grep(/^\Q$block\E$/,@blockers)) {
                   4369:                                     push(@blockers,$block);
                   4370:                                 }
                   4371:                             }
                   4372:                         }
                   4373:                     }
                   4374:                 }
                   4375:             } elsif ($block =~ /^firstaccess____(.+)$/) {
                   4376:                 my $item = $1;
                   4377:                 my $timersymb = $item; 
                   4378:                 my $type = 'map';
                   4379:                 if ($item eq 'course') {
                   4380:                     $type = 'course';
                   4381:                 } elsif ($item =~ /___\d+___/) {
                   4382:                     $type = 'resource';
                   4383:                 } else {
                   4384:                     $timersymb = &Apache::lonnet::symbread($item);
                   4385:                 }
                   4386:                 my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
                   4387:                 my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb}; 
                   4388:                 if ($start && $end) {
                   4389:                     if (($start <= time) && ($end >= time)) {
                   4390:                         unless (grep(/^\Q$block\E$/,@blockers)) {
                   4391:                             push(@blockers,$block);
                   4392:                             $triggered{$block} = {
                   4393:                                                    start => $start,
                   4394:                                                    end   => $end,
                   4395:                                                    type  => $type,
                   4396:                                                  };
                   4397:                         }
                   4398:                     }
1.490     raeburn  4399:                 }
1.1062    raeburn  4400:             }
                   4401:         }
                   4402:     }
                   4403:     foreach my $blocker (@blockers) {
                   4404:         my ($staff_name,$staff_dom,$title,$blocks) =
                   4405:             &parse_block_record($commblocks{$blocker});
                   4406:         push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
                   4407:         my ($start,$end,$triggertype);
                   4408:         if ($blocker =~ m/^(\d+)____(\d+)$/) {
                   4409:             ($start,$end) = ($1,$2);
                   4410:         } elsif (ref($triggered{$blocker}) eq 'HASH') {
                   4411:             $start = $triggered{$blocker}{'start'};
                   4412:             $end = $triggered{$blocker}{'end'};
                   4413:             $triggertype = $triggered{$blocker}{'type'};
                   4414:         }
                   4415:         if ($start) {
                   4416:             push(@{$$setters{$course}{'times'}}, [$start,$end]);
                   4417:             if ($triggertype) {
                   4418:                 push(@{$$setters{$course}{'triggers'}},$triggertype);
                   4419:             } else {
                   4420:                 push(@{$$setters{$course}{'triggers'}},0);
                   4421:             }
                   4422:             if ( ($startblock == 0) || ($startblock > $start) ) {
                   4423:                 $startblock = $start;
                   4424:                 if ($triggertype) {
                   4425:                     $triggerblock = $blocker;
1.474     raeburn  4426:                 }
                   4427:             }
1.1062    raeburn  4428:             if ( ($endblock == 0) || ($endblock < $end) ) {
                   4429:                $endblock = $end;
                   4430:                if ($triggertype) {
                   4431:                    $triggerblock = $blocker;
                   4432:                }
                   4433:             }
1.474     raeburn  4434:         }
                   4435:     }
1.1062    raeburn  4436:     return ($startblock,$endblock,$triggerblock);
1.474     raeburn  4437: }
                   4438: 
                   4439: sub parse_block_record {
                   4440:     my ($record) = @_;
                   4441:     my ($setuname,$setudom,$title,$blocks);
                   4442:     if (ref($record) eq 'HASH') {
                   4443:         ($setuname,$setudom) = split(/:/,$record->{'setter'});
                   4444:         $title = &unescape($record->{'event'});
                   4445:         $blocks = $record->{'blocks'};
                   4446:     } else {
                   4447:         my @data = split(/:/,$record,3);
                   4448:         if (scalar(@data) eq 2) {
                   4449:             $title = $data[1];
                   4450:             ($setuname,$setudom) = split(/@/,$data[0]);
                   4451:         } else {
                   4452:             ($setuname,$setudom,$title) = @data;
                   4453:         }
                   4454:         $blocks = { 'com' => 'on' };
                   4455:     }
                   4456:     return ($setuname,$setudom,$title,$blocks);
                   4457: }
                   4458: 
1.854     kalberla 4459: sub blocking_status {
1.1062    raeburn  4460:     my ($activity,$uname,$udom,$url) = @_;
1.1061    raeburn  4461:     my %setters;
1.890     droeschl 4462: 
1.1061    raeburn  4463: # check for active blocking
1.1062    raeburn  4464:     my ($startblock,$endblock,$triggerblock) = 
                   4465:         &blockcheck(\%setters,$activity,$uname,$udom,$url);
                   4466:     my $blocked = 0;
                   4467:     if ($startblock && $endblock) {
                   4468:         $blocked = 1;
                   4469:     }
1.890     droeschl 4470: 
1.1061    raeburn  4471: # caller just wants to know whether a block is active
                   4472:     if (!wantarray) { return $blocked; }
                   4473: 
                   4474: # build a link to a popup window containing the details
                   4475:     my $querystring  = "?activity=$activity";
                   4476: # $uname and $udom decide whose portfolio the user is trying to look at
1.1062    raeburn  4477:     if ($activity eq 'port') {
                   4478:         $querystring .= "&amp;udom=$udom"      if $udom;
                   4479:         $querystring .= "&amp;uname=$uname"    if $uname;
                   4480:     } elsif ($activity eq 'docs') {
                   4481:         $querystring .= '&amp;url='.&HTML::Entities::encode($url,'&"');
                   4482:     }
1.1061    raeburn  4483: 
                   4484:     my $output .= <<'END_MYBLOCK';
                   4485: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
                   4486:     var options = "width=" + w + ",height=" + h + ",";
                   4487:     options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
                   4488:     options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
                   4489:     var newWin = window.open(url, wdwName, options);
                   4490:     newWin.focus();
                   4491: }
1.890     droeschl 4492: END_MYBLOCK
1.854     kalberla 4493: 
1.1061    raeburn  4494:     $output = Apache::lonhtmlcommon::scripttag($output);
1.890     droeschl 4495:   
1.1061    raeburn  4496:     my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062    raeburn  4497:     my $text = &mt('Communication Blocked');
                   4498:     if ($activity eq 'docs') {
                   4499:         $text = &mt('Content Access Blocked');
1.1063    raeburn  4500:     } elsif ($activity eq 'printout') {
                   4501:         $text = &mt('Printing Blocked');
1.1062    raeburn  4502:     }
1.1061    raeburn  4503:     $output .= <<"END_BLOCK";
1.867     kalberla 4504: <div class='LC_comblock'>
1.869     kalberla 4505:   <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890     droeschl 4506:   title='$text'>
                   4507:   <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869     kalberla 4508:   <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring' 
1.890     droeschl 4509:   title='$text'>$text</a>
1.867     kalberla 4510: </div>
                   4511: 
                   4512: END_BLOCK
1.474     raeburn  4513: 
1.1061    raeburn  4514:     return ($blocked, $output);
1.854     kalberla 4515: }
1.490     raeburn  4516: 
1.60      matthew  4517: ###############################################
                   4518: 
1.682     raeburn  4519: sub check_ip_acc {
                   4520:     my ($acc)=@_;
                   4521:     &Apache::lonxml::debug("acc is $acc");
                   4522:     if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
                   4523:         return 1;
                   4524:     }
                   4525:     my $allowed=0;
                   4526:     my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
                   4527: 
                   4528:     my $name;
                   4529:     foreach my $pattern (split(',',$acc)) {
                   4530:         $pattern =~ s/^\s*//;
                   4531:         $pattern =~ s/\s*$//;
                   4532:         if ($pattern =~ /\*$/) {
                   4533:             #35.8.*
                   4534:             $pattern=~s/\*//;
                   4535:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   4536:         } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
                   4537:             #35.8.3.[34-56]
                   4538:             my $low=$2;
                   4539:             my $high=$3;
                   4540:             $pattern=$1;
                   4541:             if ($ip =~ /^\Q$pattern\E/) {
                   4542:                 my $last=(split(/\./,$ip))[3];
                   4543:                 if ($last <=$high && $last >=$low) { $allowed=1; }
                   4544:             }
                   4545:         } elsif ($pattern =~ /^\*/) {
                   4546:             #*.msu.edu
                   4547:             $pattern=~s/\*//;
                   4548:             if (!defined($name)) {
                   4549:                 use Socket;
                   4550:                 my $netaddr=inet_aton($ip);
                   4551:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   4552:             }
                   4553:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   4554:         } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
                   4555:             #127.0.0.1
                   4556:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   4557:         } else {
                   4558:             #some.name.com
                   4559:             if (!defined($name)) {
                   4560:                 use Socket;
                   4561:                 my $netaddr=inet_aton($ip);
                   4562:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   4563:             }
                   4564:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   4565:         }
                   4566:         if ($allowed) { last; }
                   4567:     }
                   4568:     return $allowed;
                   4569: }
                   4570: 
                   4571: ###############################################
                   4572: 
1.60      matthew  4573: =pod
                   4574: 
1.112     bowersj2 4575: =head1 Domain Template Functions
                   4576: 
                   4577: =over 4
                   4578: 
                   4579: =item * &determinedomain()
1.60      matthew  4580: 
                   4581: Inputs: $domain (usually will be undef)
                   4582: 
1.63      www      4583: Returns: Determines which domain should be used for designs
1.60      matthew  4584: 
                   4585: =cut
1.54      www      4586: 
1.60      matthew  4587: ###############################################
1.63      www      4588: sub determinedomain {
                   4589:     my $domain=shift;
1.531     albertel 4590:     if (! $domain) {
1.60      matthew  4591:         # Determine domain if we have not been given one
1.893     raeburn  4592:         $domain = &Apache::lonnet::default_login_domain();
1.258     albertel 4593:         if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
                   4594:         if ($env{'request.role.domain'}) { 
                   4595:             $domain=$env{'request.role.domain'}; 
1.60      matthew  4596:         }
                   4597:     }
1.63      www      4598:     return $domain;
                   4599: }
                   4600: ###############################################
1.517     raeburn  4601: 
1.518     albertel 4602: sub devalidate_domconfig_cache {
                   4603:     my ($udom)=@_;
                   4604:     &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
                   4605: }
                   4606: 
                   4607: # ---------------------- Get domain configuration for a domain
                   4608: sub get_domainconf {
                   4609:     my ($udom) = @_;
                   4610:     my $cachetime=1800;
                   4611:     my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
                   4612:     if (defined($cached)) { return %{$result}; }
                   4613: 
                   4614:     my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948     raeburn  4615: 					     ['login','rolecolors','autoenroll'],$udom);
1.632     raeburn  4616:     my (%designhash,%legacy);
1.518     albertel 4617:     if (keys(%domconfig) > 0) {
                   4618:         if (ref($domconfig{'login'}) eq 'HASH') {
1.632     raeburn  4619:             if (keys(%{$domconfig{'login'}})) {
                   4620:                 foreach my $key (keys(%{$domconfig{'login'}})) {
1.699     raeburn  4621:                     if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946     raeburn  4622:                         if ($key eq 'loginvia') {
                   4623:                             if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
1.1013    raeburn  4624:                                 foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
1.948     raeburn  4625:                                     if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
                   4626:                                         if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
                   4627:                                             my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
                   4628:                                             $designhash{$udom.'.login.loginvia'} = $server;
                   4629:                                             if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
                   4630: 
                   4631:                                                 $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
                   4632:                                             } else {
1.1013    raeburn  4633:                                                 $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
1.948     raeburn  4634:                                             }
                   4635:                                             if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
                   4636:                                                 $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
                   4637:                                             }
1.946     raeburn  4638:                                         }
                   4639:                                     }
                   4640:                                 }
                   4641:                             }
                   4642:                         } else {
                   4643:                             foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
                   4644:                                 $designhash{$udom.'.login.'.$key.'_'.$img} = 
                   4645:                                     $domconfig{'login'}{$key}{$img};
                   4646:                             }
1.699     raeburn  4647:                         }
                   4648:                     } else {
                   4649:                         $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
                   4650:                     }
1.632     raeburn  4651:                 }
                   4652:             } else {
                   4653:                 $legacy{'login'} = 1;
1.518     albertel 4654:             }
1.632     raeburn  4655:         } else {
                   4656:             $legacy{'login'} = 1;
1.518     albertel 4657:         }
                   4658:         if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632     raeburn  4659:             if (keys(%{$domconfig{'rolecolors'}})) {
                   4660:                 foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
                   4661:                     if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
                   4662:                         foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
                   4663:                             $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
                   4664:                         }
1.518     albertel 4665:                     }
                   4666:                 }
1.632     raeburn  4667:             } else {
                   4668:                 $legacy{'rolecolors'} = 1;
1.518     albertel 4669:             }
1.632     raeburn  4670:         } else {
                   4671:             $legacy{'rolecolors'} = 1;
1.518     albertel 4672:         }
1.948     raeburn  4673:         if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   4674:             if ($domconfig{'autoenroll'}{'co-owners'}) {
                   4675:                 $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
                   4676:             }
                   4677:         }
1.632     raeburn  4678:         if (keys(%legacy) > 0) {
                   4679:             my %legacyhash = &get_legacy_domconf($udom);
                   4680:             foreach my $item (keys(%legacyhash)) {
                   4681:                 if ($item =~ /^\Q$udom\E\.login/) {
                   4682:                     if ($legacy{'login'}) { 
                   4683:                         $designhash{$item} = $legacyhash{$item};
                   4684:                     }
                   4685:                 } else {
                   4686:                     if ($legacy{'rolecolors'}) {
                   4687:                         $designhash{$item} = $legacyhash{$item};
                   4688:                     }
1.518     albertel 4689:                 }
                   4690:             }
                   4691:         }
1.632     raeburn  4692:     } else {
                   4693:         %designhash = &get_legacy_domconf($udom); 
1.518     albertel 4694:     }
                   4695:     &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
                   4696: 				  $cachetime);
                   4697:     return %designhash;
                   4698: }
                   4699: 
1.632     raeburn  4700: sub get_legacy_domconf {
                   4701:     my ($udom) = @_;
                   4702:     my %legacyhash;
                   4703:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
                   4704:     my $designfile =  $designdir.'/'.$udom.'.tab';
                   4705:     if (-e $designfile) {
                   4706:         if ( open (my $fh,"<$designfile") ) {
                   4707:             while (my $line = <$fh>) {
                   4708:                 next if ($line =~ /^\#/);
                   4709:                 chomp($line);
                   4710:                 my ($key,$val)=(split(/\=/,$line));
                   4711:                 if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
                   4712:             }
                   4713:             close($fh);
                   4714:         }
                   4715:     }
1.1026    raeburn  4716:     if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632     raeburn  4717:         $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
                   4718:     }
                   4719:     return %legacyhash;
                   4720: }
                   4721: 
1.63      www      4722: =pod
                   4723: 
1.112     bowersj2 4724: =item * &domainlogo()
1.63      www      4725: 
                   4726: Inputs: $domain (usually will be undef)
                   4727: 
                   4728: Returns: A link to a domain logo, if the domain logo exists.
                   4729: If the domain logo does not exist, a description of the domain.
                   4730: 
                   4731: =cut
1.112     bowersj2 4732: 
1.63      www      4733: ###############################################
                   4734: sub domainlogo {
1.517     raeburn  4735:     my $domain = &determinedomain(shift);
1.518     albertel 4736:     my %designhash = &get_domainconf($domain);    
1.517     raeburn  4737:     # See if there is a logo
                   4738:     if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519     raeburn  4739:         my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538     albertel 4740:         if ($imgsrc =~ m{^/(adm|res)/}) {
                   4741: 	    if ($imgsrc =~ m{^/res/}) {
                   4742: 		my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
                   4743: 		&Apache::lonnet::repcopy($local_name);
                   4744: 	    }
                   4745: 	   $imgsrc = &lonhttpdurl($imgsrc);
1.519     raeburn  4746:         } 
                   4747:         return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514     albertel 4748:     } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
                   4749:         return &Apache::lonnet::domain($domain,'description');
1.59      www      4750:     } else {
1.60      matthew  4751:         return '';
1.59      www      4752:     }
                   4753: }
1.63      www      4754: ##############################################
                   4755: 
                   4756: =pod
                   4757: 
1.112     bowersj2 4758: =item * &designparm()
1.63      www      4759: 
                   4760: Inputs: $which parameter; $domain (usually will be undef)
                   4761: 
                   4762: Returns: value of designparamter $which
                   4763: 
                   4764: =cut
1.112     bowersj2 4765: 
1.397     albertel 4766: 
1.400     albertel 4767: ##############################################
1.397     albertel 4768: sub designparm {
                   4769:     my ($which,$domain)=@_;
                   4770:     if (exists($env{'environment.color.'.$which})) {
1.817     bisitz   4771:         return $env{'environment.color.'.$which};
1.96      www      4772:     }
1.63      www      4773:     $domain=&determinedomain($domain);
1.1016    raeburn  4774:     my %domdesign;
                   4775:     unless ($domain eq 'public') {
                   4776:         %domdesign = &get_domainconf($domain);
                   4777:     }
1.520     raeburn  4778:     my $output;
1.517     raeburn  4779:     if ($domdesign{$domain.'.'.$which} ne '') {
1.817     bisitz   4780:         $output = $domdesign{$domain.'.'.$which};
1.63      www      4781:     } else {
1.520     raeburn  4782:         $output = $defaultdesign{$which};
                   4783:     }
                   4784:     if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635     raeburn  4785:         ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538     albertel 4786:         if ($output =~ m{^/(adm|res)/}) {
1.817     bisitz   4787:             if ($output =~ m{^/res/}) {
                   4788:                 my $local_name = &Apache::lonnet::filelocation('',$output);
                   4789:                 &Apache::lonnet::repcopy($local_name);
                   4790:             }
1.520     raeburn  4791:             $output = &lonhttpdurl($output);
                   4792:         }
1.63      www      4793:     }
1.520     raeburn  4794:     return $output;
1.63      www      4795: }
1.59      www      4796: 
1.822     bisitz   4797: ##############################################
                   4798: =pod
                   4799: 
1.832     bisitz   4800: =item * &authorspace()
                   4801: 
1.1028    raeburn  4802: Inputs: $url (usually will be undef).
1.832     bisitz   4803: 
1.1028    raeburn  4804: Returns: Path to Construction Space containing the resource or 
                   4805:          directory being viewed (or for which action is being taken). 
                   4806:          If $url is provided, and begins /priv/<domain>/<uname>
                   4807:          the path will be that portion of the $context argument.
                   4808:          Otherwise the path will be for the author space of the current
                   4809:          user when the current role is author, or for that of the 
                   4810:          co-author/assistant co-author space when the current role 
                   4811:          is co-author or assistant co-author.
1.832     bisitz   4812: 
                   4813: =cut
                   4814: 
                   4815: sub authorspace {
1.1028    raeburn  4816:     my ($url) = @_;
                   4817:     if ($url ne '') {
                   4818:         if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
                   4819:            return $1;
                   4820:         }
                   4821:     }
1.832     bisitz   4822:     my $caname = '';
1.1024    www      4823:     my $cadom = '';
1.1028    raeburn  4824:     if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024    www      4825:         ($cadom,$caname) =
1.832     bisitz   4826:             ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028    raeburn  4827:     } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832     bisitz   4828:         $caname = $env{'user.name'};
1.1024    www      4829:         $cadom = $env{'user.domain'};
1.832     bisitz   4830:     }
1.1028    raeburn  4831:     if (($caname ne '') && ($cadom ne '')) {
                   4832:         return "/priv/$cadom/$caname/";
                   4833:     }
                   4834:     return;
1.832     bisitz   4835: }
                   4836: 
                   4837: ##############################################
                   4838: =pod
                   4839: 
1.822     bisitz   4840: =item * &head_subbox()
                   4841: 
                   4842: Inputs: $content (contains HTML code with page functions, etc.)
                   4843: 
                   4844: Returns: HTML div with $content
                   4845:          To be included in page header
                   4846: 
                   4847: =cut
                   4848: 
                   4849: sub head_subbox {
                   4850:     my ($content)=@_;
                   4851:     my $output =
1.993     raeburn  4852:         '<div class="LC_head_subbox">'
1.822     bisitz   4853:        .$content
                   4854:        .'</div>'
                   4855: }
                   4856: 
                   4857: ##############################################
                   4858: =pod
                   4859: 
                   4860: =item * &CSTR_pageheader()
                   4861: 
1.1026    raeburn  4862: Input: (optional) filename from which breadcrumb trail is built.
                   4863:        In most cases no input as needed, as $env{'request.filename'}
                   4864:        is appropriate for use in building the breadcrumb trail.
1.822     bisitz   4865: 
                   4866: Returns: HTML div with CSTR path and recent box
                   4867:          To be included on Construction Space pages
                   4868: 
                   4869: =cut
                   4870: 
                   4871: sub CSTR_pageheader {
1.1026    raeburn  4872:     my ($trailfile) = @_;
                   4873:     if ($trailfile eq '') {
                   4874:         $trailfile = $env{'request.filename'};
                   4875:     }
                   4876: 
                   4877: # this is for resources; directories have customtitle, and crumbs
                   4878: # and select recent are created in lonpubdir.pm
                   4879: 
                   4880:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022    www      4881:     my ($udom,$uname,$thisdisfn)=
1.1026    raeburn  4882:         ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)/(.*)$});
                   4883:     my $formaction = "/priv/$udom/$uname/$thisdisfn";
                   4884:     $formaction =~ s{/+}{/}g;
1.822     bisitz   4885: 
                   4886:     my $parentpath = '';
                   4887:     my $lastitem = '';
                   4888:     if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
                   4889:         $parentpath = $1;
                   4890:         $lastitem = $2;
                   4891:     } else {
                   4892:         $lastitem = $thisdisfn;
                   4893:     }
1.921     bisitz   4894: 
                   4895:     my $output =
1.822     bisitz   4896:          '<div>'
                   4897:         .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
                   4898:         .'<b>'.&mt('Construction Space:').'</b> '
                   4899:         .'<form name="dirs" method="post" action="'.$formaction
1.921     bisitz   4900:         .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024    www      4901:         .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921     bisitz   4902: 
                   4903:     if ($lastitem) {
                   4904:         $output .=
                   4905:              '<span class="LC_filename">'
                   4906:             .$lastitem
                   4907:             .'</span>';
                   4908:     }
                   4909:     $output .=
                   4910:          '<br />'
1.822     bisitz   4911:         #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
                   4912:         .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
                   4913:         .'</form>'
                   4914:         .&Apache::lonmenu::constspaceform()
                   4915:         .'</div>';
1.921     bisitz   4916: 
                   4917:     return $output;
1.822     bisitz   4918: }
                   4919: 
1.60      matthew  4920: ###############################################
                   4921: ###############################################
                   4922: 
                   4923: =pod
                   4924: 
1.112     bowersj2 4925: =back
                   4926: 
1.549     albertel 4927: =head1 HTML Helpers
1.112     bowersj2 4928: 
                   4929: =over 4
                   4930: 
                   4931: =item * &bodytag()
1.60      matthew  4932: 
                   4933: Returns a uniform header for LON-CAPA web pages.
                   4934: 
                   4935: Inputs: 
                   4936: 
1.112     bowersj2 4937: =over 4
                   4938: 
                   4939: =item * $title, A title to be displayed on the page.
                   4940: 
                   4941: =item * $function, the current role (can be undef).
                   4942: 
                   4943: =item * $addentries, extra parameters for the <body> tag.
                   4944: 
                   4945: =item * $bodyonly, if defined, only return the <body> tag.
                   4946: 
                   4947: =item * $domain, if defined, force a given domain.
                   4948: 
                   4949: =item * $forcereg, if page should register as content page (relevant for 
1.86      www      4950:             text interface only)
1.60      matthew  4951: 
1.814     bisitz   4952: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
                   4953:                      navigational links
1.317     albertel 4954: 
1.338     albertel 4955: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
                   4956: 
1.460     albertel 4957: =item * $args, optional argument valid values are
                   4958:             no_auto_mt_title -> prevents &mt()ing the title arg
1.562     albertel 4959:             inherit_jsmath -> when creating popup window in a page,
                   4960:                               should it have jsmath forced on by the
                   4961:                               current page
1.460     albertel 4962: 
1.112     bowersj2 4963: =back
                   4964: 
1.60      matthew  4965: Returns: A uniform header for LON-CAPA web pages.  
                   4966: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
                   4967: If $bodyonly is undef or zero, an html string containing a <body> tag and 
                   4968: other decorations will be returned.
                   4969: 
                   4970: =cut
                   4971: 
1.54      www      4972: sub bodytag {
1.831     bisitz   4973:     my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.962     droeschl 4974:         $no_nav_bar,$bgcolor,$args)=@_;
1.339     albertel 4975: 
1.954     raeburn  4976:     my $public;
                   4977:     if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
                   4978:         || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
                   4979:         $public = 1;
                   4980:     }
1.460     albertel 4981:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339     albertel 4982: 
1.183     matthew  4983:     $function = &get_users_function() if (!$function);
1.339     albertel 4984:     my $img =    &designparm($function.'.img',$domain);
                   4985:     my $font =   &designparm($function.'.font',$domain);
                   4986:     my $pgbg   = $bgcolor || &designparm($function.'.pgbg',$domain);
                   4987: 
1.803     bisitz   4988:     my %design = ( 'style'   => 'margin-top: 0',
1.535     albertel 4989: 		   'bgcolor' => $pgbg,
1.339     albertel 4990: 		   'text'    => $font,
                   4991:                    'alink'   => &designparm($function.'.alink',$domain),
                   4992: 		   'vlink'   => &designparm($function.'.vlink',$domain),
                   4993: 		   'link'    => &designparm($function.'.link',$domain),);
1.438     albertel 4994:     @design{keys(%$addentries)} = @$addentries{keys(%$addentries)}; 
1.339     albertel 4995: 
1.63      www      4996:  # role and realm
1.378     raeburn  4997:     my ($role,$realm) = split(/\./,$env{'request.role'},2);
                   4998:     if ($role  eq 'ca') {
1.479     albertel 4999:         my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500     albertel 5000:         $realm = &plainname($rname,$rdom);
1.378     raeburn  5001:     } 
1.55      www      5002: # realm
1.258     albertel 5003:     if ($env{'request.course.id'}) {
1.378     raeburn  5004:         if ($env{'request.role'} !~ /^cr/) {
                   5005:             $role = &Apache::lonnet::plaintext($role,&course_type());
                   5006:         }
1.898     raeburn  5007:         if ($env{'request.course.sec'}) {
                   5008:             $role .= ('&nbsp;'x2).'-&nbsp;'.&mt('section:').'&nbsp;'.$env{'request.course.sec'};
                   5009:         }   
1.359     albertel 5010: 	$realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378     raeburn  5011:     } else {
                   5012:         $role = &Apache::lonnet::plaintext($role);
1.54      www      5013:     }
1.433     albertel 5014: 
1.359     albertel 5015:     if (!$realm) { $realm='&nbsp;'; }
1.330     albertel 5016: 
1.438     albertel 5017:     my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329     albertel 5018: 
1.101     www      5019: # construct main body tag
1.359     albertel 5020:     my $bodytag = "<body $extra_body_attr>".
1.562     albertel 5021: 	&Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252     albertel 5022: 
1.530     albertel 5023:     if ($bodyonly) {
1.60      matthew  5024:         return $bodytag;
1.798     tempelho 5025:     } 
1.359     albertel 5026: 
1.410     albertel 5027:     my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.954     raeburn  5028:     if ($public) {
1.433     albertel 5029: 	undef($role);
1.434     albertel 5030:     } else {
1.1070    raeburn  5031: 	$name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
                   5032:                                 undef,'LC_menubuttons_link');
1.433     albertel 5033:     }
1.359     albertel 5034:     
1.762     bisitz   5035:     my $titleinfo = '<h1>'.$title.'</h1>';
1.359     albertel 5036:     #
                   5037:     # Extra info if you are the DC
                   5038:     my $dc_info = '';
                   5039:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   5040:                         $env{'course.'.$env{'request.course.id'}.
                   5041:                                  '.domain'}.'/'})) {
                   5042:         my $cid = $env{'request.course.id'};
1.917     raeburn  5043:         $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380     www      5044:         $dc_info =~ s/\s+$//;
1.359     albertel 5045:     }
                   5046: 
1.898     raeburn  5047:     $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853     droeschl 5048:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   5049: 
1.916     droeschl 5050:         if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') { 
                   5051:             return $bodytag; 
                   5052:         } 
1.903     droeschl 5053: 
                   5054:         if ($env{'request.state'} eq 'construct') { $forcereg=1; }
                   5055: 
                   5056:         #    if ($env{'request.state'} eq 'construct') {
                   5057:         #        $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
                   5058:         #    }
                   5059: 
1.359     albertel 5060: 
1.1075.2.2  raeburn  5061: 
1.916     droeschl 5062:         if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.1  raeburn  5063:             unless ($env{'request.noversionuri'} =~ m{/res/adm/pages/bookmarkmenu/}) {
                   5064:                 if ($dc_info) {
                   5065:                      $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
                   5066:                 }
                   5067:                 $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
                   5068:                                <em>$realm</em> $dc_info</div>|;
                   5069:             }
1.903     droeschl 5070:             return $bodytag;
                   5071:         }
1.894     droeschl 5072: 
1.927     raeburn  5073:         unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
                   5074:             $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>|;
                   5075:         }
1.916     droeschl 5076: 
1.903     droeschl 5077:         $bodytag .= Apache::lonhtmlcommon::scripttag(
                   5078:             Apache::lonmenu::utilityfunctions(), 'start');
1.816     bisitz   5079: 
1.903     droeschl 5080:         $bodytag .= Apache::lonmenu::primary_menu();
1.852     droeschl 5081: 
1.917     raeburn  5082:         if ($dc_info) {
                   5083:             $dc_info = &dc_courseid_toggle($dc_info);
                   5084:         }
                   5085:         $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916     droeschl 5086: 
1.903     droeschl 5087:         #don't show menus for public users
1.954     raeburn  5088:         if (!$public){
1.903     droeschl 5089:             $bodytag .= Apache::lonmenu::secondary_menu();
                   5090:             $bodytag .= Apache::lonmenu::serverform();
1.920     raeburn  5091:             $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
                   5092:             if ($env{'request.state'} eq 'construct') {
1.962     droeschl 5093:                 $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920     raeburn  5094:                                 $args->{'bread_crumbs'});
                   5095:             } elsif ($forcereg) { 
                   5096:                 $bodytag .= &Apache::lonmenu::innerregister($forcereg);
                   5097:             }
1.903     droeschl 5098:         }else{
                   5099:             # this is to seperate menu from content when there's no secondary
                   5100:             # menu. Especially needed for public accessible ressources.
                   5101:             $bodytag .= '<hr style="clear:both" />';
                   5102:             $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end'); 
1.235     raeburn  5103:         }
1.903     droeschl 5104: 
1.235     raeburn  5105:         return $bodytag;
1.182     matthew  5106: }
                   5107: 
1.917     raeburn  5108: sub dc_courseid_toggle {
                   5109:     my ($dc_info) = @_;
1.980     raeburn  5110:     return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069    raeburn  5111:            '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917     raeburn  5112:            &mt('(More ...)').'</a></span>'.
                   5113:            '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
                   5114: }
                   5115: 
1.330     albertel 5116: sub make_attr_string {
                   5117:     my ($register,$attr_ref) = @_;
                   5118: 
                   5119:     if ($attr_ref && !ref($attr_ref)) {
                   5120: 	die("addentries Must be a hash ref ".
                   5121: 	    join(':',caller(1))." ".
                   5122: 	    join(':',caller(0))." ");
                   5123:     }
                   5124: 
                   5125:     if ($register) {
1.339     albertel 5126: 	my ($on_load,$on_unload);
                   5127: 	foreach my $key (keys(%{$attr_ref})) {
                   5128: 	    if      (lc($key) eq 'onload') {
                   5129: 		$on_load.=$attr_ref->{$key}.';';
                   5130: 		delete($attr_ref->{$key});
                   5131: 
                   5132: 	    } elsif (lc($key) eq 'onunload') {
                   5133: 		$on_unload.=$attr_ref->{$key}.';';
                   5134: 		delete($attr_ref->{$key});
                   5135: 	    }
                   5136: 	}
1.953     droeschl 5137: 	$attr_ref->{'onload'}  = $on_load;
                   5138: 	$attr_ref->{'onunload'}= $on_unload;
1.330     albertel 5139:     }
1.339     albertel 5140: 
1.330     albertel 5141:     my $attr_string;
                   5142:     foreach my $attr (keys(%$attr_ref)) {
                   5143: 	$attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
                   5144:     }
                   5145:     return $attr_string;
                   5146: }
                   5147: 
                   5148: 
1.182     matthew  5149: ###############################################
1.251     albertel 5150: ###############################################
                   5151: 
                   5152: =pod
                   5153: 
                   5154: =item * &endbodytag()
                   5155: 
                   5156: Returns a uniform footer for LON-CAPA web pages.
                   5157: 
1.635     raeburn  5158: Inputs: 1 - optional reference to an args hash
                   5159: If in the hash, key for noredirectlink has a value which evaluates to true,
                   5160: a 'Continue' link is not displayed if the page contains an
                   5161: internal redirect in the <head></head> section,
                   5162: i.e., $env{'internal.head.redirect'} exists   
1.251     albertel 5163: 
                   5164: =cut
                   5165: 
                   5166: sub endbodytag {
1.635     raeburn  5167:     my ($args) = @_;
1.1075.2.6  raeburn  5168:     my $endbodytag;
                   5169:     unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
                   5170:         $endbodytag='</body>';
                   5171:     }
1.269     albertel 5172:     $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315     albertel 5173:     if ( exists( $env{'internal.head.redirect'} ) ) {
1.635     raeburn  5174:         if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
                   5175: 	    $endbodytag=
                   5176: 	        "<br /><a href=\"$env{'internal.head.redirect'}\">".
                   5177: 	        &mt('Continue').'</a>'.
                   5178: 	        $endbodytag;
                   5179:         }
1.315     albertel 5180:     }
1.251     albertel 5181:     return $endbodytag;
                   5182: }
                   5183: 
1.352     albertel 5184: =pod
                   5185: 
                   5186: =item * &standard_css()
                   5187: 
                   5188: Returns a style sheet
                   5189: 
                   5190: Inputs: (all optional)
                   5191:             domain         -> force to color decorate a page for a specific
                   5192:                                domain
                   5193:             function       -> force usage of a specific rolish color scheme
                   5194:             bgcolor        -> override the default page bgcolor
                   5195: 
                   5196: =cut
                   5197: 
1.343     albertel 5198: sub standard_css {
1.345     albertel 5199:     my ($function,$domain,$bgcolor) = @_;
1.352     albertel 5200:     $function  = &get_users_function() if (!$function);
                   5201:     my $img    = &designparm($function.'.img',   $domain);
                   5202:     my $tabbg  = &designparm($function.'.tabbg', $domain);
                   5203:     my $font   = &designparm($function.'.font',  $domain);
1.801     tempelho 5204:     my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791     tempelho 5205: #second colour for later usage
1.345     albertel 5206:     my $sidebg = &designparm($function.'.sidebg',$domain);
1.382     albertel 5207:     my $pgbg_or_bgcolor =
                   5208: 	         $bgcolor ||
1.352     albertel 5209: 	         &designparm($function.'.pgbg',  $domain);
1.382     albertel 5210:     my $pgbg   = &designparm($function.'.pgbg',  $domain);
1.352     albertel 5211:     my $alink  = &designparm($function.'.alink', $domain);
                   5212:     my $vlink  = &designparm($function.'.vlink', $domain);
                   5213:     my $link   = &designparm($function.'.link',  $domain);
                   5214: 
1.602     albertel 5215:     my $sans                 = 'Verdana,Arial,Helvetica,sans-serif';
1.395     albertel 5216:     my $mono                 = 'monospace';
1.850     bisitz   5217:     my $data_table_head      = $sidebg;
                   5218:     my $data_table_light     = '#FAFAFA';
1.1060    bisitz   5219:     my $data_table_dark      = '#E0E0E0';
1.470     banghart 5220:     my $data_table_darker    = '#CCCCCC';
1.349     albertel 5221:     my $data_table_highlight = '#FFFF00';
1.352     albertel 5222:     my $mail_new             = '#FFBB77';
                   5223:     my $mail_new_hover       = '#DD9955';
                   5224:     my $mail_read            = '#BBBB77';
                   5225:     my $mail_read_hover      = '#999944';
                   5226:     my $mail_replied         = '#AAAA88';
                   5227:     my $mail_replied_hover   = '#888855';
                   5228:     my $mail_other           = '#99BBBB';
                   5229:     my $mail_other_hover     = '#669999';
1.391     albertel 5230:     my $table_header         = '#DDDDDD';
1.489     raeburn  5231:     my $feedback_link_bg     = '#BBBBBB';
1.911     bisitz   5232:     my $lg_border_color      = '#C8C8C8';
1.952     onken    5233:     my $button_hover         = '#BF2317';
1.392     albertel 5234: 
1.608     albertel 5235:     my $border = ($env{'browser.type'} eq 'explorer' ||
1.911     bisitz   5236:       $env{'browser.type'} eq 'safari'     ) ? '0 2px 0 2px'
                   5237:                                              : '0 3px 0 4px';
1.448     albertel 5238: 
1.523     albertel 5239: 
1.343     albertel 5240:     return <<END;
1.947     droeschl 5241: 
                   5242: /* needed for iframe to allow 100% height in FF */
                   5243: body, html { 
                   5244:     margin: 0;
                   5245:     padding: 0 0.5%;
                   5246:     height: 99%; /* to avoid scrollbars */
                   5247: }
                   5248: 
1.795     www      5249: body {
1.911     bisitz   5250:   font-family: $sans;
                   5251:   line-height:130%;
                   5252:   font-size:0.83em;
                   5253:   color:$font;
1.795     www      5254: }
                   5255: 
1.959     onken    5256: a:focus,
                   5257: a:focus img {
1.795     www      5258:   color: red;
                   5259: }
1.698     harmsja  5260: 
1.911     bisitz   5261: form, .inline {
                   5262:   display: inline;
1.795     www      5263: }
1.721     harmsja  5264: 
1.795     www      5265: .LC_right {
1.911     bisitz   5266:   text-align:right;
1.795     www      5267: }
                   5268: 
                   5269: .LC_middle {
1.911     bisitz   5270:   vertical-align:middle;
1.795     www      5271: }
1.721     harmsja  5272: 
1.911     bisitz   5273: .LC_400Box {
                   5274:   width:400px;
                   5275: }
1.721     harmsja  5276: 
1.947     droeschl 5277: .LC_iframecontainer {
                   5278:     width: 98%;
                   5279:     margin: 0;
                   5280:     position: fixed;
                   5281:     top: 8.5em;
                   5282:     bottom: 0;
                   5283: }
                   5284: 
                   5285: .LC_iframecontainer iframe{
                   5286:     border: none;
                   5287:     width: 100%;
                   5288:     height: 100%;
                   5289: }
                   5290: 
1.778     bisitz   5291: .LC_filename {
                   5292:   font-family: $mono;
                   5293:   white-space:pre;
1.921     bisitz   5294:   font-size: 120%;
1.778     bisitz   5295: }
                   5296: 
                   5297: .LC_fileicon {
                   5298:   border: none;
                   5299:   height: 1.3em;
                   5300:   vertical-align: text-bottom;
                   5301:   margin-right: 0.3em;
                   5302:   text-decoration:none;
                   5303: }
                   5304: 
1.1008    www      5305: .LC_setting {
                   5306:   text-decoration:underline;
                   5307: }
                   5308: 
1.350     albertel 5309: .LC_error {
                   5310:   color: red;
                   5311:   font-size: larger;
                   5312: }
1.795     www      5313: 
1.457     albertel 5314: .LC_warning,
                   5315: .LC_diff_removed {
1.733     bisitz   5316:   color: red;
1.394     albertel 5317: }
1.532     albertel 5318: 
                   5319: .LC_info,
1.457     albertel 5320: .LC_success,
                   5321: .LC_diff_added {
1.350     albertel 5322:   color: green;
                   5323: }
1.795     www      5324: 
1.802     bisitz   5325: div.LC_confirm_box {
                   5326:   background-color: #FAFAFA;
                   5327:   border: 1px solid $lg_border_color;
                   5328:   margin-right: 0;
                   5329:   padding: 5px;
                   5330: }
                   5331: 
                   5332: div.LC_confirm_box .LC_error img,
                   5333: div.LC_confirm_box .LC_success img {
                   5334:   vertical-align: middle;
                   5335: }
                   5336: 
1.440     albertel 5337: .LC_icon {
1.771     droeschl 5338:   border: none;
1.790     droeschl 5339:   vertical-align: middle;
1.771     droeschl 5340: }
                   5341: 
1.543     albertel 5342: .LC_docs_spacer {
                   5343:   width: 25px;
                   5344:   height: 1px;
1.771     droeschl 5345:   border: none;
1.543     albertel 5346: }
1.346     albertel 5347: 
1.532     albertel 5348: .LC_internal_info {
1.735     bisitz   5349:   color: #999999;
1.532     albertel 5350: }
                   5351: 
1.794     www      5352: .LC_discussion {
1.1050    www      5353:   background: $data_table_dark;
1.911     bisitz   5354:   border: 1px solid black;
                   5355:   margin: 2px;
1.794     www      5356: }
                   5357: 
                   5358: .LC_disc_action_left {
1.1050    www      5359:   background: $sidebg;
1.911     bisitz   5360:   text-align: left;
1.1050    www      5361:   padding: 4px;
                   5362:   margin: 2px;
1.794     www      5363: }
                   5364: 
                   5365: .LC_disc_action_right {
1.1050    www      5366:   background: $sidebg;
1.911     bisitz   5367:   text-align: right;
1.1050    www      5368:   padding: 4px;
                   5369:   margin: 2px;
1.794     www      5370: }
                   5371: 
                   5372: .LC_disc_new_item {
1.911     bisitz   5373:   background: white;
                   5374:   border: 2px solid red;
1.1050    www      5375:   margin: 4px;
                   5376:   padding: 4px;
1.794     www      5377: }
                   5378: 
                   5379: .LC_disc_old_item {
1.911     bisitz   5380:   background: white;
1.1050    www      5381:   margin: 4px;
                   5382:   padding: 4px;
1.794     www      5383: }
                   5384: 
1.458     albertel 5385: table.LC_pastsubmission {
                   5386:   border: 1px solid black;
                   5387:   margin: 2px;
                   5388: }
                   5389: 
1.924     bisitz   5390: table#LC_menubuttons {
1.345     albertel 5391:   width: 100%;
                   5392:   background: $pgbg;
1.392     albertel 5393:   border: 2px;
1.402     albertel 5394:   border-collapse: separate;
1.803     bisitz   5395:   padding: 0;
1.345     albertel 5396: }
1.392     albertel 5397: 
1.801     tempelho 5398: table#LC_title_bar a {
                   5399:   color: $fontmenu;
                   5400: }
1.836     bisitz   5401: 
1.807     droeschl 5402: table#LC_title_bar {
1.819     tempelho 5403:   clear: both;
1.836     bisitz   5404:   display: none;
1.807     droeschl 5405: }
                   5406: 
1.795     www      5407: table#LC_title_bar,
1.933     droeschl 5408: table.LC_breadcrumbs, /* obsolete? */
1.393     albertel 5409: table#LC_title_bar.LC_with_remote {
1.359     albertel 5410:   width: 100%;
1.392     albertel 5411:   border-color: $pgbg;
                   5412:   border-style: solid;
                   5413:   border-width: $border;
1.379     albertel 5414:   background: $pgbg;
1.801     tempelho 5415:   color: $fontmenu;
1.392     albertel 5416:   border-collapse: collapse;
1.803     bisitz   5417:   padding: 0;
1.819     tempelho 5418:   margin: 0;
1.359     albertel 5419: }
1.795     www      5420: 
1.933     droeschl 5421: ul.LC_breadcrumb_tools_outerlist {
1.913     droeschl 5422:     margin: 0;
                   5423:     padding: 0;
1.933     droeschl 5424:     position: relative;
                   5425:     list-style: none;
1.913     droeschl 5426: }
1.933     droeschl 5427: ul.LC_breadcrumb_tools_outerlist li {
1.913     droeschl 5428:     display: inline;
                   5429: }
1.933     droeschl 5430: 
                   5431: .LC_breadcrumb_tools_navigation {
1.913     droeschl 5432:     padding: 0;
1.933     droeschl 5433:     margin: 0;
                   5434:     float: left;
1.913     droeschl 5435: }
1.933     droeschl 5436: .LC_breadcrumb_tools_tools {
                   5437:     padding: 0;
                   5438:     margin: 0;
1.913     droeschl 5439:     float: right;
                   5440: }
                   5441: 
1.359     albertel 5442: table#LC_title_bar td {
                   5443:   background: $tabbg;
                   5444: }
1.795     www      5445: 
1.911     bisitz   5446: table#LC_menubuttons img {
1.803     bisitz   5447:   border: none;
1.346     albertel 5448: }
1.795     www      5449: 
1.842     droeschl 5450: .LC_breadcrumbs_component {
1.911     bisitz   5451:   float: right;
                   5452:   margin: 0 1em;
1.357     albertel 5453: }
1.842     droeschl 5454: .LC_breadcrumbs_component img {
1.911     bisitz   5455:   vertical-align: middle;
1.777     tempelho 5456: }
1.795     www      5457: 
1.383     albertel 5458: td.LC_table_cell_checkbox {
                   5459:   text-align: center;
                   5460: }
1.795     www      5461: 
                   5462: .LC_fontsize_small {
1.911     bisitz   5463:   font-size: 70%;
1.705     tempelho 5464: }
                   5465: 
1.844     bisitz   5466: #LC_breadcrumbs {
1.911     bisitz   5467:   clear:both;
                   5468:   background: $sidebg;
                   5469:   border-bottom: 1px solid $lg_border_color;
                   5470:   line-height: 2.5em;
1.933     droeschl 5471:   overflow: hidden;
1.911     bisitz   5472:   margin: 0;
                   5473:   padding: 0;
1.995     raeburn  5474:   text-align: left;
1.819     tempelho 5475: }
1.862     bisitz   5476: 
1.993     raeburn  5477: .LC_head_subbox {
1.911     bisitz   5478:   clear:both;
                   5479:   background: #F8F8F8; /* $sidebg; */
1.915     droeschl 5480:   border: 1px solid $sidebg;
                   5481:   margin: 0 0 10px 0;      
1.966     bisitz   5482:   padding: 3px;
1.995     raeburn  5483:   text-align: left;
1.822     bisitz   5484: }
                   5485: 
1.795     www      5486: .LC_fontsize_medium {
1.911     bisitz   5487:   font-size: 85%;
1.705     tempelho 5488: }
                   5489: 
1.795     www      5490: .LC_fontsize_large {
1.911     bisitz   5491:   font-size: 120%;
1.705     tempelho 5492: }
                   5493: 
1.346     albertel 5494: .LC_menubuttons_inline_text {
                   5495:   color: $font;
1.698     harmsja  5496:   font-size: 90%;
1.701     harmsja  5497:   padding-left:3px;
1.346     albertel 5498: }
                   5499: 
1.934     droeschl 5500: .LC_menubuttons_inline_text img{
                   5501:   vertical-align: middle;
                   5502: }
                   5503: 
1.1051    www      5504: li.LC_menubuttons_inline_text img {
1.951     onken    5505:   cursor:pointer;
1.1002    droeschl 5506:   text-decoration: none;
1.951     onken    5507: }
                   5508: 
1.526     www      5509: .LC_menubuttons_link {
                   5510:   text-decoration: none;
                   5511: }
1.795     www      5512: 
1.522     albertel 5513: .LC_menubuttons_category {
1.521     www      5514:   color: $font;
1.526     www      5515:   background: $pgbg;
1.521     www      5516:   font-size: larger;
                   5517:   font-weight: bold;
                   5518: }
                   5519: 
1.346     albertel 5520: td.LC_menubuttons_text {
1.911     bisitz   5521:   color: $font;
1.346     albertel 5522: }
1.706     harmsja  5523: 
1.346     albertel 5524: .LC_current_location {
                   5525:   background: $tabbg;
                   5526: }
1.795     www      5527: 
1.938     bisitz   5528: table.LC_data_table {
1.347     albertel 5529:   border: 1px solid #000000;
1.402     albertel 5530:   border-collapse: separate;
1.426     albertel 5531:   border-spacing: 1px;
1.610     albertel 5532:   background: $pgbg;
1.347     albertel 5533: }
1.795     www      5534: 
1.422     albertel 5535: .LC_data_table_dense {
                   5536:   font-size: small;
                   5537: }
1.795     www      5538: 
1.507     raeburn  5539: table.LC_nested_outer {
                   5540:   border: 1px solid #000000;
1.589     raeburn  5541:   border-collapse: collapse;
1.803     bisitz   5542:   border-spacing: 0;
1.507     raeburn  5543:   width: 100%;
                   5544: }
1.795     www      5545: 
1.879     raeburn  5546: table.LC_innerpickbox,
1.507     raeburn  5547: table.LC_nested {
1.803     bisitz   5548:   border: none;
1.589     raeburn  5549:   border-collapse: collapse;
1.803     bisitz   5550:   border-spacing: 0;
1.507     raeburn  5551:   width: 100%;
                   5552: }
1.795     www      5553: 
1.911     bisitz   5554: table.LC_data_table tr th,
                   5555: table.LC_calendar tr th,
1.879     raeburn  5556: table.LC_prior_tries tr th,
                   5557: table.LC_innerpickbox tr th {
1.349     albertel 5558:   font-weight: bold;
                   5559:   background-color: $data_table_head;
1.801     tempelho 5560:   color:$fontmenu;
1.701     harmsja  5561:   font-size:90%;
1.347     albertel 5562: }
1.795     www      5563: 
1.879     raeburn  5564: table.LC_innerpickbox tr th,
                   5565: table.LC_innerpickbox tr td {
                   5566:   vertical-align: top;
                   5567: }
                   5568: 
1.711     raeburn  5569: table.LC_data_table tr.LC_info_row > td {
1.735     bisitz   5570:   background-color: #CCCCCC;
1.711     raeburn  5571:   font-weight: bold;
                   5572:   text-align: left;
                   5573: }
1.795     www      5574: 
1.912     bisitz   5575: table.LC_data_table tr.LC_odd_row > td {
                   5576:   background-color: $data_table_light;
                   5577:   padding: 2px;
                   5578:   vertical-align: top;
                   5579: }
                   5580: 
1.809     bisitz   5581: table.LC_pick_box tr > td.LC_odd_row {
1.349     albertel 5582:   background-color: $data_table_light;
1.912     bisitz   5583:   vertical-align: top;
                   5584: }
                   5585: 
                   5586: table.LC_data_table tr.LC_even_row > td {
                   5587:   background-color: $data_table_dark;
1.425     albertel 5588:   padding: 2px;
1.900     bisitz   5589:   vertical-align: top;
1.347     albertel 5590: }
1.795     www      5591: 
1.809     bisitz   5592: table.LC_pick_box tr > td.LC_even_row {
1.349     albertel 5593:   background-color: $data_table_dark;
1.900     bisitz   5594:   vertical-align: top;
1.347     albertel 5595: }
1.795     www      5596: 
1.425     albertel 5597: table.LC_data_table tr.LC_data_table_highlight td {
                   5598:   background-color: $data_table_darker;
                   5599: }
1.795     www      5600: 
1.639     raeburn  5601: table.LC_data_table tr td.LC_leftcol_header {
                   5602:   background-color: $data_table_head;
                   5603:   font-weight: bold;
                   5604: }
1.795     www      5605: 
1.451     albertel 5606: table.LC_data_table tr.LC_empty_row td,
1.507     raeburn  5607: table.LC_nested tr.LC_empty_row td {
1.421     albertel 5608:   font-weight: bold;
                   5609:   font-style: italic;
                   5610:   text-align: center;
                   5611:   padding: 8px;
1.347     albertel 5612: }
1.795     www      5613: 
1.940     bisitz   5614: table.LC_data_table tr.LC_empty_row td {
                   5615:   background-color: $sidebg;
                   5616: }
                   5617: 
                   5618: table.LC_nested tr.LC_empty_row td {
                   5619:   background-color: #FFFFFF;
                   5620: }
                   5621: 
1.890     droeschl 5622: table.LC_caption {
                   5623: }
                   5624: 
1.507     raeburn  5625: table.LC_nested tr.LC_empty_row td {
1.465     albertel 5626:   padding: 4ex
                   5627: }
1.795     www      5628: 
1.507     raeburn  5629: table.LC_nested_outer tr th {
                   5630:   font-weight: bold;
1.801     tempelho 5631:   color:$fontmenu;
1.507     raeburn  5632:   background-color: $data_table_head;
1.701     harmsja  5633:   font-size: small;
1.507     raeburn  5634:   border-bottom: 1px solid #000000;
                   5635: }
1.795     www      5636: 
1.507     raeburn  5637: table.LC_nested_outer tr td.LC_subheader {
                   5638:   background-color: $data_table_head;
                   5639:   font-weight: bold;
                   5640:   font-size: small;
                   5641:   border-bottom: 1px solid #000000;
                   5642:   text-align: right;
1.451     albertel 5643: }
1.795     www      5644: 
1.507     raeburn  5645: table.LC_nested tr.LC_info_row td {
1.735     bisitz   5646:   background-color: #CCCCCC;
1.451     albertel 5647:   font-weight: bold;
                   5648:   font-size: small;
1.507     raeburn  5649:   text-align: center;
                   5650: }
1.795     www      5651: 
1.589     raeburn  5652: table.LC_nested tr.LC_info_row td.LC_left_item,
                   5653: table.LC_nested_outer tr th.LC_left_item {
1.507     raeburn  5654:   text-align: left;
1.451     albertel 5655: }
1.795     www      5656: 
1.507     raeburn  5657: table.LC_nested td {
1.735     bisitz   5658:   background-color: #FFFFFF;
1.451     albertel 5659:   font-size: small;
1.507     raeburn  5660: }
1.795     www      5661: 
1.507     raeburn  5662: table.LC_nested_outer tr th.LC_right_item,
                   5663: table.LC_nested tr.LC_info_row td.LC_right_item,
                   5664: table.LC_nested tr.LC_odd_row td.LC_right_item,
                   5665: table.LC_nested tr td.LC_right_item {
1.451     albertel 5666:   text-align: right;
                   5667: }
                   5668: 
1.507     raeburn  5669: table.LC_nested tr.LC_odd_row td {
1.735     bisitz   5670:   background-color: #EEEEEE;
1.451     albertel 5671: }
                   5672: 
1.473     raeburn  5673: table.LC_createuser {
                   5674: }
                   5675: 
                   5676: table.LC_createuser tr.LC_section_row td {
1.701     harmsja  5677:   font-size: small;
1.473     raeburn  5678: }
                   5679: 
                   5680: table.LC_createuser tr.LC_info_row td  {
1.735     bisitz   5681:   background-color: #CCCCCC;
1.473     raeburn  5682:   font-weight: bold;
                   5683:   text-align: center;
                   5684: }
                   5685: 
1.349     albertel 5686: table.LC_calendar {
                   5687:   border: 1px solid #000000;
                   5688:   border-collapse: collapse;
1.917     raeburn  5689:   width: 98%;
1.349     albertel 5690: }
1.795     www      5691: 
1.349     albertel 5692: table.LC_calendar_pickdate {
                   5693:   font-size: xx-small;
                   5694: }
1.795     www      5695: 
1.349     albertel 5696: table.LC_calendar tr td {
                   5697:   border: 1px solid #000000;
                   5698:   vertical-align: top;
1.917     raeburn  5699:   width: 14%;
1.349     albertel 5700: }
1.795     www      5701: 
1.349     albertel 5702: table.LC_calendar tr td.LC_calendar_day_empty {
                   5703:   background-color: $data_table_dark;
                   5704: }
1.795     www      5705: 
1.779     bisitz   5706: table.LC_calendar tr td.LC_calendar_day_current {
                   5707:   background-color: $data_table_highlight;
1.777     tempelho 5708: }
1.795     www      5709: 
1.938     bisitz   5710: table.LC_data_table tr td.LC_mail_new {
1.349     albertel 5711:   background-color: $mail_new;
                   5712: }
1.795     www      5713: 
1.938     bisitz   5714: table.LC_data_table tr.LC_mail_new:hover {
1.349     albertel 5715:   background-color: $mail_new_hover;
                   5716: }
1.795     www      5717: 
1.938     bisitz   5718: table.LC_data_table tr td.LC_mail_read {
1.349     albertel 5719:   background-color: $mail_read;
                   5720: }
1.795     www      5721: 
1.938     bisitz   5722: /*
                   5723: table.LC_data_table tr.LC_mail_read:hover {
1.349     albertel 5724:   background-color: $mail_read_hover;
                   5725: }
1.938     bisitz   5726: */
1.795     www      5727: 
1.938     bisitz   5728: table.LC_data_table tr td.LC_mail_replied {
1.349     albertel 5729:   background-color: $mail_replied;
                   5730: }
1.795     www      5731: 
1.938     bisitz   5732: /*
                   5733: table.LC_data_table tr.LC_mail_replied:hover {
1.349     albertel 5734:   background-color: $mail_replied_hover;
                   5735: }
1.938     bisitz   5736: */
1.795     www      5737: 
1.938     bisitz   5738: table.LC_data_table tr td.LC_mail_other {
1.349     albertel 5739:   background-color: $mail_other;
                   5740: }
1.795     www      5741: 
1.938     bisitz   5742: /*
                   5743: table.LC_data_table tr.LC_mail_other:hover {
1.349     albertel 5744:   background-color: $mail_other_hover;
                   5745: }
1.938     bisitz   5746: */
1.494     raeburn  5747: 
1.777     tempelho 5748: table.LC_data_table tr > td.LC_browser_file,
                   5749: table.LC_data_table tr > td.LC_browser_file_published {
1.899     bisitz   5750:   background: #AAEE77;
1.389     albertel 5751: }
1.795     www      5752: 
1.777     tempelho 5753: table.LC_data_table tr > td.LC_browser_file_locked,
                   5754: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389     albertel 5755:   background: #FFAA99;
1.387     albertel 5756: }
1.795     www      5757: 
1.777     tempelho 5758: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899     bisitz   5759:   background: #888888;
1.779     bisitz   5760: }
1.795     www      5761: 
1.777     tempelho 5762: table.LC_data_table tr > td.LC_browser_file_modified,
1.779     bisitz   5763: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899     bisitz   5764:   background: #F8F866;
1.777     tempelho 5765: }
1.795     www      5766: 
1.696     bisitz   5767: table.LC_data_table tr.LC_browser_folder > td {
1.899     bisitz   5768:   background: #E0E8FF;
1.387     albertel 5769: }
1.696     bisitz   5770: 
1.707     bisitz   5771: table.LC_data_table tr > td.LC_roles_is {
1.911     bisitz   5772:   /* background: #77FF77; */
1.707     bisitz   5773: }
1.795     www      5774: 
1.707     bisitz   5775: table.LC_data_table tr > td.LC_roles_future {
1.939     bisitz   5776:   border-right: 8px solid #FFFF77;
1.707     bisitz   5777: }
1.795     www      5778: 
1.707     bisitz   5779: table.LC_data_table tr > td.LC_roles_will {
1.939     bisitz   5780:   border-right: 8px solid #FFAA77;
1.707     bisitz   5781: }
1.795     www      5782: 
1.707     bisitz   5783: table.LC_data_table tr > td.LC_roles_expired {
1.939     bisitz   5784:   border-right: 8px solid #FF7777;
1.707     bisitz   5785: }
1.795     www      5786: 
1.707     bisitz   5787: table.LC_data_table tr > td.LC_roles_will_not {
1.939     bisitz   5788:   border-right: 8px solid #AAFF77;
1.707     bisitz   5789: }
1.795     www      5790: 
1.707     bisitz   5791: table.LC_data_table tr > td.LC_roles_selected {
1.939     bisitz   5792:   border-right: 8px solid #11CC55;
1.707     bisitz   5793: }
                   5794: 
1.388     albertel 5795: span.LC_current_location {
1.701     harmsja  5796:   font-size:larger;
1.388     albertel 5797:   background: $pgbg;
                   5798: }
1.387     albertel 5799: 
1.1029    www      5800: span.LC_current_nav_location {
                   5801:   font-weight:bold;
                   5802:   background: $sidebg;
                   5803: }
                   5804: 
1.395     albertel 5805: span.LC_parm_menu_item {
                   5806:   font-size: larger;
                   5807: }
1.795     www      5808: 
1.395     albertel 5809: span.LC_parm_scope_all {
                   5810:   color: red;
                   5811: }
1.795     www      5812: 
1.395     albertel 5813: span.LC_parm_scope_folder {
                   5814:   color: green;
                   5815: }
1.795     www      5816: 
1.395     albertel 5817: span.LC_parm_scope_resource {
                   5818:   color: orange;
                   5819: }
1.795     www      5820: 
1.395     albertel 5821: span.LC_parm_part {
                   5822:   color: blue;
                   5823: }
1.795     www      5824: 
1.911     bisitz   5825: span.LC_parm_folder,
                   5826: span.LC_parm_symb {
1.395     albertel 5827:   font-size: x-small;
                   5828:   font-family: $mono;
                   5829:   color: #AAAAAA;
                   5830: }
                   5831: 
1.977     bisitz   5832: ul.LC_parm_parmlist li {
                   5833:   display: inline-block;
                   5834:   padding: 0.3em 0.8em;
                   5835:   vertical-align: top;
                   5836:   width: 150px;
                   5837:   border-top:1px solid $lg_border_color;
                   5838: }
                   5839: 
1.795     www      5840: td.LC_parm_overview_level_menu,
                   5841: td.LC_parm_overview_map_menu,
                   5842: td.LC_parm_overview_parm_selectors,
                   5843: td.LC_parm_overview_restrictions  {
1.396     albertel 5844:   border: 1px solid black;
                   5845:   border-collapse: collapse;
                   5846: }
1.795     www      5847: 
1.396     albertel 5848: table.LC_parm_overview_restrictions td {
                   5849:   border-width: 1px 4px 1px 4px;
                   5850:   border-style: solid;
                   5851:   border-color: $pgbg;
                   5852:   text-align: center;
                   5853: }
1.795     www      5854: 
1.396     albertel 5855: table.LC_parm_overview_restrictions th {
                   5856:   background: $tabbg;
                   5857:   border-width: 1px 4px 1px 4px;
                   5858:   border-style: solid;
                   5859:   border-color: $pgbg;
                   5860: }
1.795     www      5861: 
1.398     albertel 5862: table#LC_helpmenu {
1.803     bisitz   5863:   border: none;
1.398     albertel 5864:   height: 55px;
1.803     bisitz   5865:   border-spacing: 0;
1.398     albertel 5866: }
                   5867: 
                   5868: table#LC_helpmenu fieldset legend {
                   5869:   font-size: larger;
                   5870: }
1.795     www      5871: 
1.397     albertel 5872: table#LC_helpmenu_links {
                   5873:   width: 100%;
                   5874:   border: 1px solid black;
                   5875:   background: $pgbg;
1.803     bisitz   5876:   padding: 0;
1.397     albertel 5877:   border-spacing: 1px;
                   5878: }
1.795     www      5879: 
1.397     albertel 5880: table#LC_helpmenu_links tr td {
                   5881:   padding: 1px;
                   5882:   background: $tabbg;
1.399     albertel 5883:   text-align: center;
                   5884:   font-weight: bold;
1.397     albertel 5885: }
1.396     albertel 5886: 
1.795     www      5887: table#LC_helpmenu_links a:link,
                   5888: table#LC_helpmenu_links a:visited,
1.397     albertel 5889: table#LC_helpmenu_links a:active {
                   5890:   text-decoration: none;
                   5891:   color: $font;
                   5892: }
1.795     www      5893: 
1.397     albertel 5894: table#LC_helpmenu_links a:hover {
                   5895:   text-decoration: underline;
                   5896:   color: $vlink;
                   5897: }
1.396     albertel 5898: 
1.417     albertel 5899: .LC_chrt_popup_exists {
                   5900:   border: 1px solid #339933;
                   5901:   margin: -1px;
                   5902: }
1.795     www      5903: 
1.417     albertel 5904: .LC_chrt_popup_up {
                   5905:   border: 1px solid yellow;
                   5906:   margin: -1px;
                   5907: }
1.795     www      5908: 
1.417     albertel 5909: .LC_chrt_popup {
                   5910:   border: 1px solid #8888FF;
                   5911:   background: #CCCCFF;
                   5912: }
1.795     www      5913: 
1.421     albertel 5914: table.LC_pick_box {
                   5915:   border-collapse: separate;
                   5916:   background: white;
                   5917:   border: 1px solid black;
                   5918:   border-spacing: 1px;
                   5919: }
1.795     www      5920: 
1.421     albertel 5921: table.LC_pick_box td.LC_pick_box_title {
1.850     bisitz   5922:   background: $sidebg;
1.421     albertel 5923:   font-weight: bold;
1.900     bisitz   5924:   text-align: left;
1.740     bisitz   5925:   vertical-align: top;
1.421     albertel 5926:   width: 184px;
                   5927:   padding: 8px;
                   5928: }
1.795     www      5929: 
1.579     raeburn  5930: table.LC_pick_box td.LC_pick_box_value {
                   5931:   text-align: left;
                   5932:   padding: 8px;
                   5933: }
1.795     www      5934: 
1.579     raeburn  5935: table.LC_pick_box td.LC_pick_box_select {
                   5936:   text-align: left;
                   5937:   padding: 8px;
                   5938: }
1.795     www      5939: 
1.424     albertel 5940: table.LC_pick_box td.LC_pick_box_separator {
1.803     bisitz   5941:   padding: 0;
1.421     albertel 5942:   height: 1px;
                   5943:   background: black;
                   5944: }
1.795     www      5945: 
1.421     albertel 5946: table.LC_pick_box td.LC_pick_box_submit {
                   5947:   text-align: right;
                   5948: }
1.795     www      5949: 
1.579     raeburn  5950: table.LC_pick_box td.LC_evenrow_value {
                   5951:   text-align: left;
                   5952:   padding: 8px;
                   5953:   background-color: $data_table_light;
                   5954: }
1.795     www      5955: 
1.579     raeburn  5956: table.LC_pick_box td.LC_oddrow_value {
                   5957:   text-align: left;
                   5958:   padding: 8px;
                   5959:   background-color: $data_table_light;
                   5960: }
1.795     www      5961: 
1.579     raeburn  5962: span.LC_helpform_receipt_cat {
                   5963:   font-weight: bold;
                   5964: }
1.795     www      5965: 
1.424     albertel 5966: table.LC_group_priv_box {
                   5967:   background: white;
                   5968:   border: 1px solid black;
                   5969:   border-spacing: 1px;
                   5970: }
1.795     www      5971: 
1.424     albertel 5972: table.LC_group_priv_box td.LC_pick_box_title {
                   5973:   background: $tabbg;
                   5974:   font-weight: bold;
                   5975:   text-align: right;
                   5976:   width: 184px;
                   5977: }
1.795     www      5978: 
1.424     albertel 5979: table.LC_group_priv_box td.LC_groups_fixed {
                   5980:   background: $data_table_light;
                   5981:   text-align: center;
                   5982: }
1.795     www      5983: 
1.424     albertel 5984: table.LC_group_priv_box td.LC_groups_optional {
                   5985:   background: $data_table_dark;
                   5986:   text-align: center;
                   5987: }
1.795     www      5988: 
1.424     albertel 5989: table.LC_group_priv_box td.LC_groups_functionality {
                   5990:   background: $data_table_darker;
                   5991:   text-align: center;
                   5992:   font-weight: bold;
                   5993: }
1.795     www      5994: 
1.424     albertel 5995: table.LC_group_priv td {
                   5996:   text-align: left;
1.803     bisitz   5997:   padding: 0;
1.424     albertel 5998: }
                   5999: 
                   6000: .LC_navbuttons {
                   6001:   margin: 2ex 0ex 2ex 0ex;
                   6002: }
1.795     www      6003: 
1.423     albertel 6004: .LC_topic_bar {
                   6005:   font-weight: bold;
                   6006:   background: $tabbg;
1.918     wenzelju 6007:   margin: 1em 0em 1em 2em;
1.805     bisitz   6008:   padding: 3px;
1.918     wenzelju 6009:   font-size: 1.2em;
1.423     albertel 6010: }
1.795     www      6011: 
1.423     albertel 6012: .LC_topic_bar span {
1.918     wenzelju 6013:   left: 0.5em;
                   6014:   position: absolute;
1.423     albertel 6015:   vertical-align: middle;
1.918     wenzelju 6016:   font-size: 1.2em;
1.423     albertel 6017: }
1.795     www      6018: 
1.423     albertel 6019: table.LC_course_group_status {
                   6020:   margin: 20px;
                   6021: }
1.795     www      6022: 
1.423     albertel 6023: table.LC_status_selector td {
                   6024:   vertical-align: top;
                   6025:   text-align: center;
1.424     albertel 6026:   padding: 4px;
                   6027: }
1.795     www      6028: 
1.599     albertel 6029: div.LC_feedback_link {
1.616     albertel 6030:   clear: both;
1.829     kalberla 6031:   background: $sidebg;
1.779     bisitz   6032:   width: 100%;
1.829     kalberla 6033:   padding-bottom: 10px;
                   6034:   border: 1px $tabbg solid;
1.833     kalberla 6035:   height: 22px;
                   6036:   line-height: 22px;
                   6037:   padding-top: 5px;
                   6038: }
                   6039: 
                   6040: div.LC_feedback_link img {
                   6041:   height: 22px;
1.867     kalberla 6042:   vertical-align:middle;
1.829     kalberla 6043: }
                   6044: 
1.911     bisitz   6045: div.LC_feedback_link a {
1.829     kalberla 6046:   text-decoration: none;
1.489     raeburn  6047: }
1.795     www      6048: 
1.867     kalberla 6049: div.LC_comblock {
1.911     bisitz   6050:   display:inline;
1.867     kalberla 6051:   color:$font;
                   6052:   font-size:90%;
                   6053: }
                   6054: 
                   6055: div.LC_feedback_link div.LC_comblock {
                   6056:   padding-left:5px;
                   6057: }
                   6058: 
                   6059: div.LC_feedback_link div.LC_comblock a {
                   6060:   color:$font;
                   6061: }
                   6062: 
1.489     raeburn  6063: span.LC_feedback_link {
1.858     bisitz   6064:   /* background: $feedback_link_bg; */
1.599     albertel 6065:   font-size: larger;
                   6066: }
1.795     www      6067: 
1.599     albertel 6068: span.LC_message_link {
1.858     bisitz   6069:   /* background: $feedback_link_bg; */
1.599     albertel 6070:   font-size: larger;
                   6071:   position: absolute;
                   6072:   right: 1em;
1.489     raeburn  6073: }
1.421     albertel 6074: 
1.515     albertel 6075: table.LC_prior_tries {
1.524     albertel 6076:   border: 1px solid #000000;
                   6077:   border-collapse: separate;
                   6078:   border-spacing: 1px;
1.515     albertel 6079: }
1.523     albertel 6080: 
1.515     albertel 6081: table.LC_prior_tries td {
1.524     albertel 6082:   padding: 2px;
1.515     albertel 6083: }
1.523     albertel 6084: 
                   6085: .LC_answer_correct {
1.795     www      6086:   background: lightgreen;
                   6087:   color: darkgreen;
                   6088:   padding: 6px;
1.523     albertel 6089: }
1.795     www      6090: 
1.523     albertel 6091: .LC_answer_charged_try {
1.797     www      6092:   background: #FFAAAA;
1.795     www      6093:   color: darkred;
                   6094:   padding: 6px;
1.523     albertel 6095: }
1.795     www      6096: 
1.779     bisitz   6097: .LC_answer_not_charged_try,
1.523     albertel 6098: .LC_answer_no_grade,
                   6099: .LC_answer_late {
1.795     www      6100:   background: lightyellow;
1.523     albertel 6101:   color: black;
1.795     www      6102:   padding: 6px;
1.523     albertel 6103: }
1.795     www      6104: 
1.523     albertel 6105: .LC_answer_previous {
1.795     www      6106:   background: lightblue;
                   6107:   color: darkblue;
                   6108:   padding: 6px;
1.523     albertel 6109: }
1.795     www      6110: 
1.779     bisitz   6111: .LC_answer_no_message {
1.777     tempelho 6112:   background: #FFFFFF;
                   6113:   color: black;
1.795     www      6114:   padding: 6px;
1.779     bisitz   6115: }
1.795     www      6116: 
1.779     bisitz   6117: .LC_answer_unknown {
                   6118:   background: orange;
                   6119:   color: black;
1.795     www      6120:   padding: 6px;
1.777     tempelho 6121: }
1.795     www      6122: 
1.529     albertel 6123: span.LC_prior_numerical,
                   6124: span.LC_prior_string,
                   6125: span.LC_prior_custom,
                   6126: span.LC_prior_reaction,
                   6127: span.LC_prior_math {
1.925     bisitz   6128:   font-family: $mono;
1.523     albertel 6129:   white-space: pre;
                   6130: }
                   6131: 
1.525     albertel 6132: span.LC_prior_string {
1.925     bisitz   6133:   font-family: $mono;
1.525     albertel 6134:   white-space: pre;
                   6135: }
                   6136: 
1.523     albertel 6137: table.LC_prior_option {
                   6138:   width: 100%;
                   6139:   border-collapse: collapse;
                   6140: }
1.795     www      6141: 
1.911     bisitz   6142: table.LC_prior_rank,
1.795     www      6143: table.LC_prior_match {
1.528     albertel 6144:   border-collapse: collapse;
                   6145: }
1.795     www      6146: 
1.528     albertel 6147: table.LC_prior_option tr td,
                   6148: table.LC_prior_rank tr td,
                   6149: table.LC_prior_match tr td {
1.524     albertel 6150:   border: 1px solid #000000;
1.515     albertel 6151: }
                   6152: 
1.855     bisitz   6153: .LC_nobreak {
1.544     albertel 6154:   white-space: nowrap;
1.519     raeburn  6155: }
                   6156: 
1.576     raeburn  6157: span.LC_cusr_emph {
                   6158:   font-style: italic;
                   6159: }
                   6160: 
1.633     raeburn  6161: span.LC_cusr_subheading {
                   6162:   font-weight: normal;
                   6163:   font-size: 85%;
                   6164: }
                   6165: 
1.861     bisitz   6166: div.LC_docs_entry_move {
1.859     bisitz   6167:   border: 1px solid #BBBBBB;
1.545     albertel 6168:   background: #DDDDDD;
1.861     bisitz   6169:   width: 22px;
1.859     bisitz   6170:   padding: 1px;
                   6171:   margin: 0;
1.545     albertel 6172: }
                   6173: 
1.861     bisitz   6174: table.LC_data_table tr > td.LC_docs_entry_commands,
                   6175: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545     albertel 6176:   background: #DDDDDD;
                   6177:   font-size: x-small;
                   6178: }
1.795     www      6179: 
1.861     bisitz   6180: .LC_docs_entry_parameter {
                   6181:   white-space: nowrap;
                   6182: }
                   6183: 
1.544     albertel 6184: .LC_docs_copy {
1.545     albertel 6185:   color: #000099;
1.544     albertel 6186: }
1.795     www      6187: 
1.544     albertel 6188: .LC_docs_cut {
1.545     albertel 6189:   color: #550044;
1.544     albertel 6190: }
1.795     www      6191: 
1.544     albertel 6192: .LC_docs_rename {
1.545     albertel 6193:   color: #009900;
1.544     albertel 6194: }
1.795     www      6195: 
1.544     albertel 6196: .LC_docs_remove {
1.545     albertel 6197:   color: #990000;
                   6198: }
                   6199: 
1.547     albertel 6200: .LC_docs_reinit_warn,
                   6201: .LC_docs_ext_edit {
                   6202:   font-size: x-small;
                   6203: }
                   6204: 
1.545     albertel 6205: table.LC_docs_adddocs td,
                   6206: table.LC_docs_adddocs th {
                   6207:   border: 1px solid #BBBBBB;
                   6208:   padding: 4px;
                   6209:   background: #DDDDDD;
1.543     albertel 6210: }
                   6211: 
1.584     albertel 6212: table.LC_sty_begin {
                   6213:   background: #BBFFBB;
                   6214: }
1.795     www      6215: 
1.584     albertel 6216: table.LC_sty_end {
                   6217:   background: #FFBBBB;
                   6218: }
                   6219: 
1.589     raeburn  6220: table.LC_double_column {
1.803     bisitz   6221:   border-width: 0;
1.589     raeburn  6222:   border-collapse: collapse;
                   6223:   width: 100%;
                   6224:   padding: 2px;
                   6225: }
                   6226: 
                   6227: table.LC_double_column tr td.LC_left_col {
1.590     raeburn  6228:   top: 2px;
1.589     raeburn  6229:   left: 2px;
                   6230:   width: 47%;
                   6231:   vertical-align: top;
                   6232: }
                   6233: 
                   6234: table.LC_double_column tr td.LC_right_col {
                   6235:   top: 2px;
1.779     bisitz   6236:   right: 2px;
1.589     raeburn  6237:   width: 47%;
                   6238:   vertical-align: top;
                   6239: }
                   6240: 
1.591     raeburn  6241: div.LC_left_float {
                   6242:   float: left;
                   6243:   padding-right: 5%;
1.597     albertel 6244:   padding-bottom: 4px;
1.591     raeburn  6245: }
                   6246: 
                   6247: div.LC_clear_float_header {
1.597     albertel 6248:   padding-bottom: 2px;
1.591     raeburn  6249: }
                   6250: 
                   6251: div.LC_clear_float_footer {
1.597     albertel 6252:   padding-top: 10px;
1.591     raeburn  6253:   clear: both;
                   6254: }
                   6255: 
1.597     albertel 6256: div.LC_grade_show_user {
1.941     bisitz   6257: /*  border-left: 5px solid $sidebg; */
                   6258:   border-top: 5px solid #000000;
                   6259:   margin: 50px 0 0 0;
1.936     bisitz   6260:   padding: 15px 0 5px 10px;
1.597     albertel 6261: }
1.795     www      6262: 
1.936     bisitz   6263: div.LC_grade_show_user_odd_row {
1.941     bisitz   6264: /*  border-left: 5px solid #000000; */
                   6265: }
                   6266: 
                   6267: div.LC_grade_show_user div.LC_Box {
                   6268:   margin-right: 50px;
1.597     albertel 6269: }
                   6270: 
                   6271: div.LC_grade_submissions,
                   6272: div.LC_grade_message_center,
1.936     bisitz   6273: div.LC_grade_info_links {
1.597     albertel 6274:   margin: 5px;
                   6275:   width: 99%;
                   6276:   background: #FFFFFF;
                   6277: }
1.795     www      6278: 
1.597     albertel 6279: div.LC_grade_submissions_header,
1.936     bisitz   6280: div.LC_grade_message_center_header {
1.705     tempelho 6281:   font-weight: bold;
                   6282:   font-size: large;
1.597     albertel 6283: }
1.795     www      6284: 
1.597     albertel 6285: div.LC_grade_submissions_body,
1.936     bisitz   6286: div.LC_grade_message_center_body {
1.597     albertel 6287:   border: 1px solid black;
                   6288:   width: 99%;
                   6289:   background: #FFFFFF;
                   6290: }
1.795     www      6291: 
1.613     albertel 6292: table.LC_scantron_action {
                   6293:   width: 100%;
                   6294: }
1.795     www      6295: 
1.613     albertel 6296: table.LC_scantron_action tr th {
1.698     harmsja  6297:   font-weight:bold;
                   6298:   font-style:normal;
1.613     albertel 6299: }
1.795     www      6300: 
1.779     bisitz   6301: .LC_edit_problem_header,
1.614     albertel 6302: div.LC_edit_problem_footer {
1.705     tempelho 6303:   font-weight: normal;
                   6304:   font-size:  medium;
1.602     albertel 6305:   margin: 2px;
1.1060    bisitz   6306:   background-color: $sidebg;
1.600     albertel 6307: }
1.795     www      6308: 
1.600     albertel 6309: div.LC_edit_problem_header,
1.602     albertel 6310: div.LC_edit_problem_header div,
1.614     albertel 6311: div.LC_edit_problem_footer,
                   6312: div.LC_edit_problem_footer div,
1.602     albertel 6313: div.LC_edit_problem_editxml_header,
                   6314: div.LC_edit_problem_editxml_header div {
1.600     albertel 6315:   margin-top: 5px;
                   6316: }
1.795     www      6317: 
1.600     albertel 6318: div.LC_edit_problem_header_title {
1.705     tempelho 6319:   font-weight: bold;
                   6320:   font-size: larger;
1.602     albertel 6321:   background: $tabbg;
                   6322:   padding: 3px;
1.1060    bisitz   6323:   margin: 0 0 5px 0;
1.602     albertel 6324: }
1.795     www      6325: 
1.602     albertel 6326: table.LC_edit_problem_header_title {
                   6327:   width: 100%;
1.600     albertel 6328:   background: $tabbg;
1.602     albertel 6329: }
                   6330: 
                   6331: div.LC_edit_problem_discards {
                   6332:   float: left;
                   6333:   padding-bottom: 5px;
                   6334: }
1.795     www      6335: 
1.602     albertel 6336: div.LC_edit_problem_saves {
                   6337:   float: right;
                   6338:   padding-bottom: 5px;
1.600     albertel 6339: }
1.795     www      6340: 
1.911     bisitz   6341: img.stift {
1.803     bisitz   6342:   border-width: 0;
                   6343:   vertical-align: middle;
1.677     riegler  6344: }
1.680     riegler  6345: 
1.923     bisitz   6346: table td.LC_mainmenu_col_fieldset {
1.680     riegler  6347:   vertical-align: top;
1.777     tempelho 6348: }
1.795     www      6349: 
1.716     raeburn  6350: div.LC_createcourse {
1.911     bisitz   6351:   margin: 10px 10px 10px 10px;
1.716     raeburn  6352: }
                   6353: 
1.917     raeburn  6354: .LC_dccid {
                   6355:   margin: 0.2em 0 0 0;
                   6356:   padding: 0;
                   6357:   font-size: 90%;
                   6358:   display:none;
                   6359: }
                   6360: 
1.897     wenzelju 6361: ol.LC_primary_menu a:hover,
1.721     harmsja  6362: ol#LC_MenuBreadcrumbs a:hover,
                   6363: ol#LC_PathBreadcrumbs a:hover,
1.897     wenzelju 6364: ul#LC_secondary_menu a:hover,
1.721     harmsja  6365: .LC_FormSectionClearButton input:hover
1.795     www      6366: ul.LC_TabContent   li:hover a {
1.952     onken    6367:   color:$button_hover;
1.911     bisitz   6368:   text-decoration:none;
1.693     droeschl 6369: }
                   6370: 
1.779     bisitz   6371: h1 {
1.911     bisitz   6372:   padding: 0;
                   6373:   line-height:130%;
1.693     droeschl 6374: }
1.698     harmsja  6375: 
1.911     bisitz   6376: h2,
                   6377: h3,
                   6378: h4,
                   6379: h5,
                   6380: h6 {
                   6381:   margin: 5px 0 5px 0;
                   6382:   padding: 0;
                   6383:   line-height:130%;
1.693     droeschl 6384: }
1.795     www      6385: 
                   6386: .LC_hcell {
1.911     bisitz   6387:   padding:3px 15px 3px 15px;
                   6388:   margin: 0;
                   6389:   background-color:$tabbg;
                   6390:   color:$fontmenu;
                   6391:   border-bottom:solid 1px $lg_border_color;
1.693     droeschl 6392: }
1.795     www      6393: 
1.840     bisitz   6394: .LC_Box > .LC_hcell {
1.911     bisitz   6395:   margin: 0 -10px 10px -10px;
1.835     bisitz   6396: }
                   6397: 
1.721     harmsja  6398: .LC_noBorder {
1.911     bisitz   6399:   border: 0;
1.698     harmsja  6400: }
1.693     droeschl 6401: 
1.721     harmsja  6402: .LC_FormSectionClearButton input {
1.911     bisitz   6403:   background-color:transparent;
                   6404:   border: none;
                   6405:   cursor:pointer;
                   6406:   text-decoration:underline;
1.693     droeschl 6407: }
1.763     bisitz   6408: 
                   6409: .LC_help_open_topic {
1.911     bisitz   6410:   color: #FFFFFF;
                   6411:   background-color: #EEEEFF;
                   6412:   margin: 1px;
                   6413:   padding: 4px;
                   6414:   border: 1px solid #000033;
                   6415:   white-space: nowrap;
                   6416:   /* vertical-align: middle; */
1.759     neumanie 6417: }
1.693     droeschl 6418: 
1.911     bisitz   6419: dl,
                   6420: ul,
                   6421: div,
                   6422: fieldset {
                   6423:   margin: 10px 10px 10px 0;
                   6424:   /* overflow: hidden; */
1.693     droeschl 6425: }
1.795     www      6426: 
1.838     bisitz   6427: fieldset > legend {
1.911     bisitz   6428:   font-weight: bold;
                   6429:   padding: 0 5px 0 5px;
1.838     bisitz   6430: }
                   6431: 
1.813     bisitz   6432: #LC_nav_bar {
1.911     bisitz   6433:   float: left;
1.995     raeburn  6434:   background-color: $pgbg_or_bgcolor;
1.966     bisitz   6435:   margin: 0 0 2px 0;
1.807     droeschl 6436: }
                   6437: 
1.916     droeschl 6438: #LC_realm {
                   6439:   margin: 0.2em 0 0 0;
                   6440:   padding: 0;
                   6441:   font-weight: bold;
                   6442:   text-align: center;
1.995     raeburn  6443:   background-color: $pgbg_or_bgcolor;
1.916     droeschl 6444: }
                   6445: 
1.911     bisitz   6446: #LC_nav_bar em {
                   6447:   font-weight: bold;
                   6448:   font-style: normal;
1.807     droeschl 6449: }
                   6450: 
1.897     wenzelju 6451: ol.LC_primary_menu {
1.911     bisitz   6452:   float: right;
1.934     droeschl 6453:   margin: 0;
1.1075.2.2  raeburn  6454:   padding: 0;
1.995     raeburn  6455:   background-color: $pgbg_or_bgcolor;
1.807     droeschl 6456: }
                   6457: 
1.852     droeschl 6458: ol#LC_PathBreadcrumbs {
1.911     bisitz   6459:   margin: 0;
1.693     droeschl 6460: }
                   6461: 
1.897     wenzelju 6462: ol.LC_primary_menu li {
1.1075.2.2  raeburn  6463:   color: RGB(80, 80, 80);
                   6464:   vertical-align: middle;
                   6465:   text-align: left;
                   6466:   list-style: none;
                   6467:   float: left;
                   6468: }
                   6469: 
                   6470: ol.LC_primary_menu li a {
                   6471:   display: block;
                   6472:   margin: 0;
                   6473:   padding: 0 5px 0 10px;
                   6474:   text-decoration: none;
                   6475: }
                   6476: 
                   6477: ol.LC_primary_menu li ul {
                   6478:   display: none;
                   6479:   width: 10em;
                   6480:   background-color: $data_table_light;
                   6481: }
                   6482: 
                   6483: ol.LC_primary_menu li:hover ul, ol.LC_primary_menu li.hover ul {
                   6484:   display: block;
                   6485:   position: absolute;
                   6486:   margin: 0;
                   6487:   padding: 0;
1.1075.2.5  raeburn  6488:   z-index: 2;
1.1075.2.2  raeburn  6489: }
                   6490: 
                   6491: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
                   6492:   font-size: 90%;
1.911     bisitz   6493:   vertical-align: top;
1.1075.2.2  raeburn  6494:   float: none;
1.1075.2.5  raeburn  6495:   border-left: 1px solid black;
                   6496:   border-right: 1px solid black;
1.1075.2.2  raeburn  6497: }
                   6498: 
                   6499: ol.LC_primary_menu li:hover li a, ol.LC_primary_menu li.hover li a {
1.1075.2.5  raeburn  6500:   background-color:$data_table_light;
1.1075.2.2  raeburn  6501: }
                   6502: 
                   6503: ol.LC_primary_menu li li a:hover {
                   6504:    color:$button_hover;
                   6505:    background-color:$data_table_dark;
1.693     droeschl 6506: }
                   6507: 
1.897     wenzelju 6508: ol.LC_primary_menu li img {
1.911     bisitz   6509:   vertical-align: bottom;
1.934     droeschl 6510:   height: 1.1em;
1.1075.2.3  raeburn  6511:   margin: 0.2em 0 0 0;
1.693     droeschl 6512: }
                   6513: 
1.897     wenzelju 6514: ol.LC_primary_menu a {
1.911     bisitz   6515:   color: RGB(80, 80, 80);
                   6516:   text-decoration: none;
1.693     droeschl 6517: }
1.795     www      6518: 
1.949     droeschl 6519: ol.LC_primary_menu a.LC_new_message {
                   6520:   font-weight:bold;
                   6521:   color: darkred;
                   6522: }
                   6523: 
1.975     raeburn  6524: ol.LC_docs_parameters {
                   6525:   margin-left: 0;
                   6526:   padding: 0;
                   6527:   list-style: none;
                   6528: }
                   6529: 
                   6530: ol.LC_docs_parameters li {
                   6531:   margin: 0;
                   6532:   padding-right: 20px;
                   6533:   display: inline;
                   6534: }
                   6535: 
1.976     raeburn  6536: ol.LC_docs_parameters li:before {
                   6537:   content: "\\002022 \\0020";
                   6538: }
                   6539: 
                   6540: li.LC_docs_parameters_title {
                   6541:   font-weight: bold;
                   6542: }
                   6543: 
                   6544: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
                   6545:   content: "";
                   6546: }
                   6547: 
1.897     wenzelju 6548: ul#LC_secondary_menu {
1.911     bisitz   6549:   clear: both;
                   6550:   color: $fontmenu;
                   6551:   background: $tabbg;
                   6552:   list-style: none;
                   6553:   padding: 0;
                   6554:   margin: 0;
                   6555:   width: 100%;
1.995     raeburn  6556:   text-align: left;
1.1075.2.4  raeburn  6557:   float: left;
1.808     droeschl 6558: }
                   6559: 
1.897     wenzelju 6560: ul#LC_secondary_menu li {
1.911     bisitz   6561:   font-weight: bold;
                   6562:   line-height: 1.8em;
                   6563:   border-right: 1px solid black;
                   6564:   vertical-align: middle;
1.1075.2.4  raeburn  6565:   float: left;
                   6566: }
                   6567: 
                   6568: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
                   6569:   background-color: $data_table_light;
                   6570: }
                   6571: 
                   6572: ul#LC_secondary_menu li a {
                   6573:   padding: 0 0.8em;
                   6574: }
                   6575: 
                   6576: ul#LC_secondary_menu li ul {
                   6577:   display: none;
                   6578: }
                   6579: 
                   6580: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
                   6581:   display: block;
                   6582:   position: absolute;
                   6583:   margin: 0;
                   6584:   padding: 0;
                   6585:   list-style:none;
                   6586:   float: none;
                   6587:   background-color: $data_table_light;
1.1075.2.5  raeburn  6588:   z-index: 2;
1.1075.2.4  raeburn  6589: }
                   6590: 
                   6591: ul#LC_secondary_menu li ul li {
                   6592:   font-size: 90%;
                   6593:   vertical-align: top;
                   6594:   border-left: 1px solid black;
                   6595:   border-right: 1px solid black;
                   6596:   background-color: $data_table_light
                   6597:   list-style:none;
                   6598:   float: none;
1.1075.2.8! raeburn  6599:   margin-left: -1px;
1.1075.2.4  raeburn  6600: }
                   6601: 
                   6602: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
                   6603:   background-color: $data_table_dark;
1.807     droeschl 6604: }
                   6605: 
1.847     tempelho 6606: ul.LC_TabContent {
1.911     bisitz   6607:   display:block;
                   6608:   background: $sidebg;
                   6609:   border-bottom: solid 1px $lg_border_color;
                   6610:   list-style:none;
1.1020    raeburn  6611:   margin: -1px -10px 0 -10px;
1.911     bisitz   6612:   padding: 0;
1.693     droeschl 6613: }
                   6614: 
1.795     www      6615: ul.LC_TabContent li,
                   6616: ul.LC_TabContentBigger li {
1.911     bisitz   6617:   float:left;
1.741     harmsja  6618: }
1.795     www      6619: 
1.897     wenzelju 6620: ul#LC_secondary_menu li a {
1.911     bisitz   6621:   color: $fontmenu;
                   6622:   text-decoration: none;
1.693     droeschl 6623: }
1.795     www      6624: 
1.721     harmsja  6625: ul.LC_TabContent {
1.952     onken    6626:   min-height:20px;
1.721     harmsja  6627: }
1.795     www      6628: 
                   6629: ul.LC_TabContent li {
1.911     bisitz   6630:   vertical-align:middle;
1.959     onken    6631:   padding: 0 16px 0 10px;
1.911     bisitz   6632:   background-color:$tabbg;
                   6633:   border-bottom:solid 1px $lg_border_color;
1.1020    raeburn  6634:   border-left: solid 1px $font;
1.721     harmsja  6635: }
1.795     www      6636: 
1.847     tempelho 6637: ul.LC_TabContent .right {
1.911     bisitz   6638:   float:right;
1.847     tempelho 6639: }
                   6640: 
1.911     bisitz   6641: ul.LC_TabContent li a,
                   6642: ul.LC_TabContent li {
                   6643:   color:rgb(47,47,47);
                   6644:   text-decoration:none;
                   6645:   font-size:95%;
                   6646:   font-weight:bold;
1.952     onken    6647:   min-height:20px;
                   6648: }
                   6649: 
1.959     onken    6650: ul.LC_TabContent li a:hover,
                   6651: ul.LC_TabContent li a:focus {
1.952     onken    6652:   color: $button_hover;
1.959     onken    6653:   background:none;
                   6654:   outline:none;
1.952     onken    6655: }
                   6656: 
                   6657: ul.LC_TabContent li:hover {
                   6658:   color: $button_hover;
                   6659:   cursor:pointer;
1.721     harmsja  6660: }
1.795     www      6661: 
1.911     bisitz   6662: ul.LC_TabContent li.active {
1.952     onken    6663:   color: $font;
1.911     bisitz   6664:   background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952     onken    6665:   border-bottom:solid 1px #FFFFFF;
                   6666:   cursor: default;
1.744     ehlerst  6667: }
1.795     www      6668: 
1.959     onken    6669: ul.LC_TabContent li.active a {
                   6670:   color:$font;
                   6671:   background:#FFFFFF;
                   6672:   outline: none;
                   6673: }
1.1047    raeburn  6674: 
                   6675: ul.LC_TabContent li.goback {
                   6676:   float: left;
                   6677:   border-left: none;
                   6678: }
                   6679: 
1.870     tempelho 6680: #maincoursedoc {
1.911     bisitz   6681:   clear:both;
1.870     tempelho 6682: }
                   6683: 
                   6684: ul.LC_TabContentBigger {
1.911     bisitz   6685:   display:block;
                   6686:   list-style:none;
                   6687:   padding: 0;
1.870     tempelho 6688: }
                   6689: 
1.795     www      6690: ul.LC_TabContentBigger li {
1.911     bisitz   6691:   vertical-align:bottom;
                   6692:   height: 30px;
                   6693:   font-size:110%;
                   6694:   font-weight:bold;
                   6695:   color: #737373;
1.841     tempelho 6696: }
                   6697: 
1.957     onken    6698: ul.LC_TabContentBigger li.active {
                   6699:   position: relative;
                   6700:   top: 1px;
                   6701: }
                   6702: 
1.870     tempelho 6703: ul.LC_TabContentBigger li a {
1.911     bisitz   6704:   background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
                   6705:   height: 30px;
                   6706:   line-height: 30px;
                   6707:   text-align: center;
                   6708:   display: block;
                   6709:   text-decoration: none;
1.958     onken    6710:   outline: none;  
1.741     harmsja  6711: }
1.795     www      6712: 
1.870     tempelho 6713: ul.LC_TabContentBigger li.active a {
1.911     bisitz   6714:   background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
                   6715:   color:$font;
1.744     ehlerst  6716: }
1.795     www      6717: 
1.870     tempelho 6718: ul.LC_TabContentBigger li b {
1.911     bisitz   6719:   background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
                   6720:   display: block;
                   6721:   float: left;
                   6722:   padding: 0 30px;
1.957     onken    6723:   border-bottom: 1px solid $lg_border_color;
1.870     tempelho 6724: }
                   6725: 
1.956     onken    6726: ul.LC_TabContentBigger li:hover b {
                   6727:   color:$button_hover;
                   6728: }
                   6729: 
1.870     tempelho 6730: ul.LC_TabContentBigger li.active b {
1.911     bisitz   6731:   background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
                   6732:   color:$font;
1.957     onken    6733:   border: 0;
1.741     harmsja  6734: }
1.693     droeschl 6735: 
1.870     tempelho 6736: 
1.862     bisitz   6737: ul.LC_CourseBreadcrumbs {
                   6738:   background: $sidebg;
1.1020    raeburn  6739:   height: 2em;
1.862     bisitz   6740:   padding-left: 10px;
1.1020    raeburn  6741:   margin: 0;
1.862     bisitz   6742:   list-style-position: inside;
                   6743: }
                   6744: 
1.911     bisitz   6745: ol#LC_MenuBreadcrumbs,
1.862     bisitz   6746: ol#LC_PathBreadcrumbs {
1.911     bisitz   6747:   padding-left: 10px;
                   6748:   margin: 0;
1.933     droeschl 6749:   height: 2.5em;  /* equal to #LC_breadcrumbs line-height */
1.693     droeschl 6750: }
                   6751: 
1.911     bisitz   6752: ol#LC_MenuBreadcrumbs li,
                   6753: ol#LC_PathBreadcrumbs li,
1.862     bisitz   6754: ul.LC_CourseBreadcrumbs li {
1.911     bisitz   6755:   display: inline;
1.933     droeschl 6756:   white-space: normal;  
1.693     droeschl 6757: }
                   6758: 
1.823     bisitz   6759: ol#LC_MenuBreadcrumbs li a,
1.862     bisitz   6760: ul.LC_CourseBreadcrumbs li a {
1.911     bisitz   6761:   text-decoration: none;
                   6762:   font-size:90%;
1.693     droeschl 6763: }
1.795     www      6764: 
1.969     droeschl 6765: ol#LC_MenuBreadcrumbs h1 {
                   6766:   display: inline;
                   6767:   font-size: 90%;
                   6768:   line-height: 2.5em;
                   6769:   margin: 0;
                   6770:   padding: 0;
                   6771: }
                   6772: 
1.795     www      6773: ol#LC_PathBreadcrumbs li a {
1.911     bisitz   6774:   text-decoration:none;
                   6775:   font-size:100%;
                   6776:   font-weight:bold;
1.693     droeschl 6777: }
1.795     www      6778: 
1.840     bisitz   6779: .LC_Box {
1.911     bisitz   6780:   border: solid 1px $lg_border_color;
                   6781:   padding: 0 10px 10px 10px;
1.746     neumanie 6782: }
1.795     www      6783: 
1.1020    raeburn  6784: .LC_DocsBox {
                   6785:   border: solid 1px $lg_border_color;
                   6786:   padding: 0 0 10px 10px;
                   6787: }
                   6788: 
1.795     www      6789: .LC_AboutMe_Image {
1.911     bisitz   6790:   float:left;
                   6791:   margin-right:10px;
1.747     neumanie 6792: }
1.795     www      6793: 
                   6794: .LC_Clear_AboutMe_Image {
1.911     bisitz   6795:   clear:left;
1.747     neumanie 6796: }
1.795     www      6797: 
1.721     harmsja  6798: dl.LC_ListStyleClean dt {
1.911     bisitz   6799:   padding-right: 5px;
                   6800:   display: table-header-group;
1.693     droeschl 6801: }
                   6802: 
1.721     harmsja  6803: dl.LC_ListStyleClean dd {
1.911     bisitz   6804:   display: table-row;
1.693     droeschl 6805: }
                   6806: 
1.721     harmsja  6807: .LC_ListStyleClean,
                   6808: .LC_ListStyleSimple,
                   6809: .LC_ListStyleNormal,
1.795     www      6810: .LC_ListStyleSpecial {
1.911     bisitz   6811:   /* display:block; */
                   6812:   list-style-position: inside;
                   6813:   list-style-type: none;
                   6814:   overflow: hidden;
                   6815:   padding: 0;
1.693     droeschl 6816: }
                   6817: 
1.721     harmsja  6818: .LC_ListStyleSimple li,
                   6819: .LC_ListStyleSimple dd,
                   6820: .LC_ListStyleNormal li,
                   6821: .LC_ListStyleNormal dd,
                   6822: .LC_ListStyleSpecial li,
1.795     www      6823: .LC_ListStyleSpecial dd {
1.911     bisitz   6824:   margin: 0;
                   6825:   padding: 5px 5px 5px 10px;
                   6826:   clear: both;
1.693     droeschl 6827: }
                   6828: 
1.721     harmsja  6829: .LC_ListStyleClean li,
                   6830: .LC_ListStyleClean dd {
1.911     bisitz   6831:   padding-top: 0;
                   6832:   padding-bottom: 0;
1.693     droeschl 6833: }
                   6834: 
1.721     harmsja  6835: .LC_ListStyleSimple dd,
1.795     www      6836: .LC_ListStyleSimple li {
1.911     bisitz   6837:   border-bottom: solid 1px $lg_border_color;
1.693     droeschl 6838: }
                   6839: 
1.721     harmsja  6840: .LC_ListStyleSpecial li,
                   6841: .LC_ListStyleSpecial dd {
1.911     bisitz   6842:   list-style-type: none;
                   6843:   background-color: RGB(220, 220, 220);
                   6844:   margin-bottom: 4px;
1.693     droeschl 6845: }
                   6846: 
1.721     harmsja  6847: table.LC_SimpleTable {
1.911     bisitz   6848:   margin:5px;
                   6849:   border:solid 1px $lg_border_color;
1.795     www      6850: }
1.693     droeschl 6851: 
1.721     harmsja  6852: table.LC_SimpleTable tr {
1.911     bisitz   6853:   padding: 0;
                   6854:   border:solid 1px $lg_border_color;
1.693     droeschl 6855: }
1.795     www      6856: 
                   6857: table.LC_SimpleTable thead {
1.911     bisitz   6858:   background:rgb(220,220,220);
1.693     droeschl 6859: }
                   6860: 
1.721     harmsja  6861: div.LC_columnSection {
1.911     bisitz   6862:   display: block;
                   6863:   clear: both;
                   6864:   overflow: hidden;
                   6865:   margin: 0;
1.693     droeschl 6866: }
                   6867: 
1.721     harmsja  6868: div.LC_columnSection>* {
1.911     bisitz   6869:   float: left;
                   6870:   margin: 10px 20px 10px 0;
                   6871:   overflow:hidden;
1.693     droeschl 6872: }
1.721     harmsja  6873: 
1.795     www      6874: table em {
1.911     bisitz   6875:   font-weight: bold;
                   6876:   font-style: normal;
1.748     schulted 6877: }
1.795     www      6878: 
1.779     bisitz   6879: table.LC_tableBrowseRes,
1.795     www      6880: table.LC_tableOfContent {
1.911     bisitz   6881:   border:none;
                   6882:   border-spacing: 1px;
                   6883:   padding: 3px;
                   6884:   background-color: #FFFFFF;
                   6885:   font-size: 90%;
1.753     droeschl 6886: }
1.789     droeschl 6887: 
1.911     bisitz   6888: table.LC_tableOfContent {
                   6889:   border-collapse: collapse;
1.789     droeschl 6890: }
                   6891: 
1.771     droeschl 6892: table.LC_tableBrowseRes a,
1.768     schulted 6893: table.LC_tableOfContent a {
1.911     bisitz   6894:   background-color: transparent;
                   6895:   text-decoration: none;
1.753     droeschl 6896: }
                   6897: 
1.795     www      6898: table.LC_tableOfContent img {
1.911     bisitz   6899:   border: none;
                   6900:   height: 1.3em;
                   6901:   vertical-align: text-bottom;
                   6902:   margin-right: 0.3em;
1.753     droeschl 6903: }
1.757     schulted 6904: 
1.795     www      6905: a#LC_content_toolbar_firsthomework {
1.911     bisitz   6906:   background-image:url(/res/adm/pages/open-first-problem.gif);
1.774     ehlerst  6907: }
                   6908: 
1.795     www      6909: a#LC_content_toolbar_everything {
1.911     bisitz   6910:   background-image:url(/res/adm/pages/show-all.gif);
1.774     ehlerst  6911: }
                   6912: 
1.795     www      6913: a#LC_content_toolbar_uncompleted {
1.911     bisitz   6914:   background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774     ehlerst  6915: }
                   6916: 
1.795     www      6917: #LC_content_toolbar_clearbubbles {
1.911     bisitz   6918:   background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774     ehlerst  6919: }
                   6920: 
1.795     www      6921: a#LC_content_toolbar_changefolder {
1.911     bisitz   6922:   background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757     schulted 6923: }
                   6924: 
1.795     www      6925: a#LC_content_toolbar_changefolder_toggled {
1.911     bisitz   6926:   background-image:url(/res/adm/pages/open-all-folders.gif);
1.757     schulted 6927: }
                   6928: 
1.1043    raeburn  6929: a#LC_content_toolbar_edittoplevel {
                   6930:   background-image:url(/res/adm/pages/edittoplevel.gif);
                   6931: }
                   6932: 
1.795     www      6933: ul#LC_toolbar li a:hover {
1.911     bisitz   6934:   background-position: bottom center;
1.757     schulted 6935: }
                   6936: 
1.795     www      6937: ul#LC_toolbar {
1.911     bisitz   6938:   padding: 0;
                   6939:   margin: 2px;
                   6940:   list-style:none;
                   6941:   position:relative;
                   6942:   background-color:white;
1.757     schulted 6943: }
                   6944: 
1.795     www      6945: ul#LC_toolbar li {
1.911     bisitz   6946:   border:1px solid white;
                   6947:   padding: 0;
                   6948:   margin: 0;
                   6949:   float: left;
                   6950:   display:inline;
                   6951:   vertical-align:middle;
                   6952: }
1.757     schulted 6953: 
1.783     amueller 6954: 
1.795     www      6955: a.LC_toolbarItem {
1.911     bisitz   6956:   display:block;
                   6957:   padding: 0;
                   6958:   margin: 0;
                   6959:   height: 32px;
                   6960:   width: 32px;
                   6961:   color:white;
                   6962:   border: none;
                   6963:   background-repeat:no-repeat;
                   6964:   background-color:transparent;
1.757     schulted 6965: }
                   6966: 
1.915     droeschl 6967: ul.LC_funclist {
                   6968:     margin: 0;
                   6969:     padding: 0.5em 1em 0.5em 0;
                   6970: }
                   6971: 
1.933     droeschl 6972: ul.LC_funclist > li:first-child {
                   6973:     font-weight:bold; 
                   6974:     margin-left:0.8em;
                   6975: }
                   6976: 
1.915     droeschl 6977: ul.LC_funclist + ul.LC_funclist {
                   6978:     /* 
                   6979:        left border as a seperator if we have more than
                   6980:        one list 
                   6981:     */
                   6982:     border-left: 1px solid $sidebg;
                   6983:     /* 
                   6984:        this hides the left border behind the border of the 
                   6985:        outer box if element is wrapped to the next 'line' 
                   6986:     */
                   6987:     margin-left: -1px;
                   6988: }
                   6989: 
1.843     bisitz   6990: ul.LC_funclist li {
1.915     droeschl 6991:   display: inline;
1.782     bisitz   6992:   white-space: nowrap;
1.915     droeschl 6993:   margin: 0 0 0 25px;
                   6994:   line-height: 150%;
1.782     bisitz   6995: }
                   6996: 
1.974     wenzelju 6997: .LC_hidden {
                   6998:   display: none;
                   6999: }
                   7000: 
1.1030    www      7001: .LCmodal-overlay {
                   7002: 		position:fixed;
                   7003: 		top:0;
                   7004: 		right:0;
                   7005: 		bottom:0;
                   7006: 		left:0;
                   7007: 		height:100%;
                   7008: 		width:100%;
                   7009: 		margin:0;
                   7010: 		padding:0;
                   7011: 		background:#999;
                   7012: 		opacity:.75;
                   7013: 		filter: alpha(opacity=75);
                   7014: 		-moz-opacity: 0.75;
                   7015: 		z-index:101;
                   7016: }
                   7017: 
                   7018: * html .LCmodal-overlay {   
                   7019: 		position: absolute;
                   7020: 		height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
                   7021: }
                   7022: 
                   7023: .LCmodal-window {
                   7024: 		position:fixed;
                   7025: 		top:50%;
                   7026: 		left:50%;
                   7027: 		margin:0;
                   7028: 		padding:0;
                   7029: 		z-index:102;
                   7030: 	}
                   7031: 
                   7032: * html .LCmodal-window {
                   7033: 		position:absolute;
                   7034: }
                   7035: 
                   7036: .LCclose-window {
                   7037: 		position:absolute;
                   7038: 		width:32px;
                   7039: 		height:32px;
                   7040: 		right:8px;
                   7041: 		top:8px;
                   7042: 		background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
                   7043: 		text-indent:-99999px;
                   7044: 		overflow:hidden;
                   7045: 		cursor:pointer;
                   7046: }
                   7047: 
1.343     albertel 7048: END
                   7049: }
                   7050: 
1.306     albertel 7051: =pod
                   7052: 
                   7053: =item * &headtag()
                   7054: 
                   7055: Returns a uniform footer for LON-CAPA web pages.
                   7056: 
1.307     albertel 7057: Inputs: $title - optional title for the head
                   7058:         $head_extra - optional extra HTML to put inside the <head>
1.315     albertel 7059:         $args - optional arguments
1.319     albertel 7060:             force_register - if is true call registerurl so the remote is 
                   7061:                              informed
1.415     albertel 7062:             redirect       -> array ref of
                   7063:                                    1- seconds before redirect occurs
                   7064:                                    2- url to redirect to
                   7065:                                    3- whether the side effect should occur
1.315     albertel 7066:                            (side effect of setting 
                   7067:                                $env{'internal.head.redirect'} to the url 
                   7068:                                redirected too)
1.352     albertel 7069:             domain         -> force to color decorate a page for a specific
                   7070:                                domain
                   7071:             function       -> force usage of a specific rolish color scheme
                   7072:             bgcolor        -> override the default page bgcolor
1.460     albertel 7073:             no_auto_mt_title
                   7074:                            -> prevent &mt()ing the title arg
1.464     albertel 7075: 
1.306     albertel 7076: =cut
                   7077: 
                   7078: sub headtag {
1.313     albertel 7079:     my ($title,$head_extra,$args) = @_;
1.306     albertel 7080:     
1.363     albertel 7081:     my $function = $args->{'function'} || &get_users_function();
                   7082:     my $domain   = $args->{'domain'}   || &determinedomain();
                   7083:     my $bgcolor  = $args->{'bgcolor'}  || &designparm($function.'.pgbg',$domain);
1.418     albertel 7084:     my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458     albertel 7085: 		   $Apache::lonnet::perlvar{'lonVersion'},
1.531     albertel 7086: 		   #time(),
1.418     albertel 7087: 		   $env{'environment.color.timestamp'},
1.363     albertel 7088: 		   $function,$domain,$bgcolor);
                   7089: 
1.369     www      7090:     $url = '/adm/css/'.&escape($url).'.css';
1.363     albertel 7091: 
1.308     albertel 7092:     my $result =
                   7093: 	'<head>'.
1.461     albertel 7094: 	&font_settings();
1.319     albertel 7095: 
1.1064    raeburn  7096:     my $inhibitprint = &print_suppression();
                   7097: 
1.461     albertel 7098:     if (!$args->{'frameset'}) {
                   7099: 	$result .= &Apache::lonhtmlcommon::htmlareaheaders();
                   7100:     }
1.962     droeschl 7101:     if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
                   7102:         $result .= Apache::lonxml::display_title();
1.319     albertel 7103:     }
1.436     albertel 7104:     if (!$args->{'no_nav_bar'} 
                   7105: 	&& !$args->{'only_body'}
                   7106: 	&& !$args->{'frameset'}) {
                   7107: 	$result .= &help_menu_js();
1.1032    www      7108:         $result.=&modal_window();
1.1038    www      7109:         $result.=&togglebox_script();
1.1034    www      7110:         $result.=&wishlist_window();
1.1041    www      7111:         $result.=&LCprogressbarUpdate_script();
1.1034    www      7112:     } else {
                   7113:         if ($args->{'add_modal'}) {
                   7114:            $result.=&modal_window();
                   7115:         }
                   7116:         if ($args->{'add_wishlist'}) {
                   7117:            $result.=&wishlist_window();
                   7118:         }
1.1038    www      7119:         if ($args->{'add_togglebox'}) {
                   7120:            $result.=&togglebox_script();
                   7121:         }
1.1041    www      7122:         if ($args->{'add_progressbar'}) {
                   7123:            $result.=&LCprogressbarUpdate_script();
                   7124:         }
1.436     albertel 7125:     }
1.314     albertel 7126:     if (ref($args->{'redirect'})) {
1.414     albertel 7127: 	my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315     albertel 7128: 	$url = &Apache::lonenc::check_encrypt($url);
1.414     albertel 7129: 	if (!$inhibit_continue) {
                   7130: 	    $env{'internal.head.redirect'} = $url;
                   7131: 	}
1.313     albertel 7132: 	$result.=<<ADDMETA
                   7133: <meta http-equiv="pragma" content="no-cache" />
1.344     albertel 7134: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313     albertel 7135: ADDMETA
                   7136:     }
1.306     albertel 7137:     if (!defined($title)) {
                   7138: 	$title = 'The LearningOnline Network with CAPA';
                   7139:     }
1.460     albertel 7140:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
                   7141:     $result .= '<title> LON-CAPA '.$title.'</title>'
1.414     albertel 7142: 	.'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
1.1064    raeburn  7143:         .$inhibitprint
1.414     albertel 7144: 	.$head_extra;
1.962     droeschl 7145:     return $result.'</head>';
1.306     albertel 7146: }
                   7147: 
                   7148: =pod
                   7149: 
1.340     albertel 7150: =item * &font_settings()
                   7151: 
                   7152: Returns neccessary <meta> to set the proper encoding
                   7153: 
                   7154: Inputs: none
                   7155: 
                   7156: =cut
                   7157: 
                   7158: sub font_settings {
                   7159:     my $headerstring='';
1.647     www      7160:     if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340     albertel 7161: 	$headerstring.=
                   7162: 	    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
                   7163:     }
                   7164:     return $headerstring;
                   7165: }
                   7166: 
1.341     albertel 7167: =pod
                   7168: 
1.1064    raeburn  7169: =item * &print_suppression()
                   7170: 
                   7171: In course context returns css which causes the body to be blank when media="print",
                   7172: if printout generation is unavailable for the current resource.
                   7173: 
                   7174: This could be because:
                   7175: 
                   7176: (a) printstartdate is in the future
                   7177: 
                   7178: (b) printenddate is in the past
                   7179: 
                   7180: (c) there is an active exam block with "printout"
                   7181: functionality blocked
                   7182: 
                   7183: Users with pav, pfo or evb privileges are exempt.
                   7184: 
                   7185: Inputs: none
                   7186: 
                   7187: =cut
                   7188: 
                   7189: 
                   7190: sub print_suppression {
                   7191:     my $noprint;
                   7192:     if ($env{'request.course.id'}) {
                   7193:         my $scope = $env{'request.course.id'};
                   7194:         if ((&Apache::lonnet::allowed('pav',$scope)) ||
                   7195:             (&Apache::lonnet::allowed('pfo',$scope))) {
                   7196:             return;
                   7197:         }
                   7198:         if ($env{'request.course.sec'} ne '') {
                   7199:             $scope .= "/$env{'request.course.sec'}";
                   7200:             if ((&Apache::lonnet::allowed('pav',$scope)) ||
                   7201:                 (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065    raeburn  7202:                 return;
1.1064    raeburn  7203:             }
                   7204:         }
                   7205:         my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   7206:         my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1065    raeburn  7207:         my $blocked = &blocking_status('printout',$cnum,$cdom);
1.1064    raeburn  7208:         if ($blocked) {
                   7209:             my $checkrole = "cm./$cdom/$cnum";
                   7210:             if ($env{'request.course.sec'} ne '') {
                   7211:                 $checkrole .= "/$env{'request.course.sec'}";
                   7212:             }
                   7213:             unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
                   7214:                     ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
                   7215:                 $noprint = 1;
                   7216:             }
                   7217:         }
                   7218:         unless ($noprint) {
                   7219:             my $symb = &Apache::lonnet::symbread();
                   7220:             if ($symb ne '') {
                   7221:                 my $navmap = Apache::lonnavmaps::navmap->new();
                   7222:                 if (ref($navmap)) {
                   7223:                     my $res = $navmap->getBySymb($symb);
                   7224:                     if (ref($res)) {
                   7225:                         if (!$res->resprintable()) {
                   7226:                             $noprint = 1;
                   7227:                         }
                   7228:                     }
                   7229:                 }
                   7230:             }
                   7231:         }
                   7232:         if ($noprint) {
                   7233:             return <<"ENDSTYLE";
                   7234: <style type="text/css" media="print">
                   7235:     body { display:none }
                   7236: </style>
                   7237: ENDSTYLE
                   7238:         }
                   7239:     }
                   7240:     return;
                   7241: }
                   7242: 
                   7243: =pod
                   7244: 
1.341     albertel 7245: =item * &xml_begin()
                   7246: 
                   7247: Returns the needed doctype and <html>
                   7248: 
                   7249: Inputs: none
                   7250: 
                   7251: =cut
                   7252: 
                   7253: sub xml_begin {
                   7254:     my $output='';
                   7255: 
                   7256:     if ($env{'browser.mathml'}) {
                   7257: 	$output='<?xml version="1.0"?>'
                   7258:             #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
                   7259: #            .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
                   7260:             
                   7261: #	    .'<!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">] >'
                   7262: 	    .'<!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">'
                   7263:             .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" ' 
                   7264: 	    .'xmlns="http://www.w3.org/1999/xhtml">';
                   7265:     } else {
1.849     bisitz   7266: 	$output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
                   7267:            .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341     albertel 7268:     }
                   7269:     return $output;
                   7270: }
1.340     albertel 7271: 
                   7272: =pod
                   7273: 
1.306     albertel 7274: =item * &start_page()
                   7275: 
                   7276: Returns a complete <html> .. <body> section for LON-CAPA web pages.
                   7277: 
1.648     raeburn  7278: Inputs:
                   7279: 
                   7280: =over 4
                   7281: 
                   7282: $title - optional title for the page
                   7283: 
                   7284: $head_extra - optional extra HTML to incude inside the <head>
                   7285: 
                   7286: $args - additional optional args supported are:
                   7287: 
                   7288: =over 8
                   7289: 
                   7290:              only_body      -> is true will set &bodytag() onlybodytag
1.317     albertel 7291:                                     arg on
1.814     bisitz   7292:              no_nav_bar     -> is true will set &bodytag() no_nav_bar arg on
1.648     raeburn  7293:              add_entries    -> additional attributes to add to the  <body>
                   7294:              domain         -> force to color decorate a page for a 
1.317     albertel 7295:                                     specific domain
1.648     raeburn  7296:              function       -> force usage of a specific rolish color
1.317     albertel 7297:                                     scheme
1.648     raeburn  7298:              redirect       -> see &headtag()
                   7299:              bgcolor        -> override the default page bg color
                   7300:              js_ready       -> return a string ready for being used in 
1.317     albertel 7301:                                     a javascript writeln
1.648     raeburn  7302:              html_encode    -> return a string ready for being used in 
1.320     albertel 7303:                                     a html attribute
1.648     raeburn  7304:              force_register -> if is true will turn on the &bodytag()
1.317     albertel 7305:                                     $forcereg arg
1.648     raeburn  7306:              frameset       -> if true will start with a <frameset>
1.330     albertel 7307:                                     rather than <body>
1.648     raeburn  7308:              skip_phases    -> hash ref of 
1.338     albertel 7309:                                     head -> skip the <html><head> generation
                   7310:                                     body -> skip all <body> generation
1.648     raeburn  7311:              no_auto_mt_title -> prevent &mt()ing the title arg
                   7312:              inherit_jsmath -> when creating popup window in a page,
                   7313:                                     should it have jsmath forced on by the
                   7314:                                     current page
1.867     kalberla 7315:              bread_crumbs ->             Array containing breadcrumbs
1.983     raeburn  7316:              bread_crumbs_component ->  if exists show it as headline else show only the breadcrumbs
1.361     albertel 7317: 
1.648     raeburn  7318: =back
1.460     albertel 7319: 
1.648     raeburn  7320: =back
1.562     albertel 7321: 
1.306     albertel 7322: =cut
                   7323: 
                   7324: sub start_page {
1.309     albertel 7325:     my ($title,$head_extra,$args) = @_;
1.318     albertel 7326:     #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319     albertel 7327: 
1.315     albertel 7328:     $env{'internal.start_page'}++;
1.338     albertel 7329:     my $result;
1.964     droeschl 7330: 
1.338     albertel 7331:     if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1030    www      7332:         $result .= &xml_begin() . &headtag($title, $head_extra, $args);
1.338     albertel 7333:     }
                   7334:     
                   7335:     if (! exists($args->{'skip_phases'}{'body'}) ) {
                   7336: 	if ($args->{'frameset'}) {
                   7337: 	    my $attr_string = &make_attr_string($args->{'force_register'},
                   7338: 						$args->{'add_entries'});
                   7339: 	    $result .= "\n<frameset $attr_string>\n";
1.831     bisitz   7340:         } else {
                   7341:             $result .=
                   7342:                 &bodytag($title, 
                   7343:                          $args->{'function'},       $args->{'add_entries'},
                   7344:                          $args->{'only_body'},      $args->{'domain'},
                   7345:                          $args->{'force_register'}, $args->{'no_nav_bar'},
1.962     droeschl 7346:                          $args->{'bgcolor'},        $args);
1.831     bisitz   7347:         }
1.330     albertel 7348:     }
1.338     albertel 7349: 
1.315     albertel 7350:     if ($args->{'js_ready'}) {
1.713     kaisler  7351: 		$result = &js_ready($result);
1.315     albertel 7352:     }
1.320     albertel 7353:     if ($args->{'html_encode'}) {
1.713     kaisler  7354: 		$result = &html_encode($result);
                   7355:     }
                   7356: 
1.813     bisitz   7357:     # Preparation for new and consistent functionlist at top of screen
                   7358:     # if ($args->{'functionlist'}) {
                   7359:     #            $result .= &build_functionlist();
                   7360:     #}
                   7361: 
1.964     droeschl 7362:     # Don't add anything more if only_body wanted or in const space
                   7363:     return $result if    $args->{'only_body'} 
                   7364:                       || $env{'request.state'} eq 'construct';
1.813     bisitz   7365: 
                   7366:     #Breadcrumbs
1.758     kaisler  7367:     if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
                   7368: 		&Apache::lonhtmlcommon::clear_breadcrumbs();
                   7369: 		#if any br links exists, add them to the breadcrumbs
                   7370: 		if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {         
                   7371: 			foreach my $crumb (@{$args->{'bread_crumbs'}}){
                   7372: 				&Apache::lonhtmlcommon::add_breadcrumb($crumb);
                   7373: 			}
                   7374: 		}
                   7375: 
                   7376: 		#if bread_crumbs_component exists show it as headline else show only the breadcrumbs
                   7377: 		if(exists($args->{'bread_crumbs_component'})){
                   7378: 			$result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
                   7379: 		}else{
                   7380: 			$result .= &Apache::lonhtmlcommon::breadcrumbs();
                   7381: 		}
1.320     albertel 7382:     }
1.315     albertel 7383:     return $result;
1.306     albertel 7384: }
                   7385: 
                   7386: sub end_page {
1.315     albertel 7387:     my ($args) = @_;
                   7388:     $env{'internal.end_page'}++;
1.330     albertel 7389:     my $result;
1.335     albertel 7390:     if ($args->{'discussion'}) {
                   7391: 	my ($target,$parser);
                   7392: 	if (ref($args->{'discussion'})) {
                   7393: 	    ($target,$parser) =($args->{'discussion'}{'target'},
                   7394: 				$args->{'discussion'}{'parser'});
                   7395: 	}
                   7396: 	$result .= &Apache::lonxml::xmlend($target,$parser);
                   7397:     }
1.330     albertel 7398:     if ($args->{'frameset'}) {
                   7399: 	$result .= '</frameset>';
                   7400:     } else {
1.635     raeburn  7401: 	$result .= &endbodytag($args);
1.330     albertel 7402:     }
1.1075.2.6  raeburn  7403:     unless ($args->{'notbody'}) {
                   7404:         $result .= "\n</html>";
                   7405:     }
1.330     albertel 7406: 
1.315     albertel 7407:     if ($args->{'js_ready'}) {
1.317     albertel 7408: 	$result = &js_ready($result);
1.315     albertel 7409:     }
1.335     albertel 7410: 
1.320     albertel 7411:     if ($args->{'html_encode'}) {
                   7412: 	$result = &html_encode($result);
                   7413:     }
1.335     albertel 7414: 
1.315     albertel 7415:     return $result;
                   7416: }
                   7417: 
1.1034    www      7418: sub wishlist_window {
                   7419:     return(<<'ENDWISHLIST');
1.1046    raeburn  7420: <script type="text/javascript">
1.1034    www      7421: // <![CDATA[
                   7422: // <!-- BEGIN LON-CAPA Internal
                   7423: function set_wishlistlink(title, path) {
                   7424:     if (!title) {
                   7425:         title = document.title;
                   7426:         title = title.replace(/^LON-CAPA /,'');
                   7427:     }
                   7428:     if (!path) {
                   7429:         path = location.pathname;
                   7430:     }
                   7431:     Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
                   7432:                       'wishlistNewLink','width=560,height=350,scrollbars=0');
                   7433: }
                   7434: // END LON-CAPA Internal -->
                   7435: // ]]>
                   7436: </script>
                   7437: ENDWISHLIST
                   7438: }
                   7439: 
1.1030    www      7440: sub modal_window {
                   7441:     return(<<'ENDMODAL');
1.1046    raeburn  7442: <script type="text/javascript">
1.1030    www      7443: // <![CDATA[
                   7444: // <!-- BEGIN LON-CAPA Internal
                   7445: var modalWindow = {
                   7446: 	parent:"body",
                   7447: 	windowId:null,
                   7448: 	content:null,
                   7449: 	width:null,
                   7450: 	height:null,
                   7451: 	close:function()
                   7452: 	{
                   7453: 	        $(".LCmodal-window").remove();
                   7454: 	        $(".LCmodal-overlay").remove();
                   7455: 	},
                   7456: 	open:function()
                   7457: 	{
                   7458: 		var modal = "";
                   7459: 		modal += "<div class=\"LCmodal-overlay\"></div>";
                   7460: 		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;\">";
                   7461: 		modal += this.content;
                   7462: 		modal += "</div>";	
                   7463: 
                   7464: 		$(this.parent).append(modal);
                   7465: 
                   7466: 		$(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
                   7467: 		$(".LCclose-window").click(function(){modalWindow.close();});
                   7468: 		$(".LCmodal-overlay").click(function(){modalWindow.close();});
                   7469: 	}
                   7470: };
1.1031    www      7471: 	var openMyModal = function(source,width,height,scrolling)
1.1030    www      7472: 	{
                   7473: 		modalWindow.windowId = "myModal";
                   7474: 		modalWindow.width = width;
                   7475: 		modalWindow.height = height;
1.1031    www      7476: 		modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='true' src='" + source + "'>&lt/iframe>";
1.1030    www      7477: 		modalWindow.open();
                   7478: 	};	
                   7479: // END LON-CAPA Internal -->
                   7480: // ]]>
                   7481: </script>
                   7482: ENDMODAL
                   7483: }
                   7484: 
                   7485: sub modal_link {
1.1052    www      7486:     my ($link,$linktext,$width,$height,$target,$scrolling,$title)=@_;
1.1030    www      7487:     unless ($width) { $width=480; }
                   7488:     unless ($height) { $height=400; }
1.1031    www      7489:     unless ($scrolling) { $scrolling='yes'; }
1.1074    raeburn  7490:     my $target_attr;
                   7491:     if (defined($target)) {
                   7492:         $target_attr = 'target="'.$target.'"';
                   7493:     }
                   7494:     return <<"ENDLINK";
                   7495: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling'); return false;">
                   7496:            $linktext</a>
                   7497: ENDLINK
1.1030    www      7498: }
                   7499: 
1.1032    www      7500: sub modal_adhoc_script {
                   7501:     my ($funcname,$width,$height,$content)=@_;
                   7502:     return (<<ENDADHOC);
1.1046    raeburn  7503: <script type="text/javascript">
1.1032    www      7504: // <![CDATA[
                   7505:         var $funcname = function()
                   7506:         {
                   7507:                 modalWindow.windowId = "myModal";
                   7508:                 modalWindow.width = $width;
                   7509:                 modalWindow.height = $height;
                   7510:                 modalWindow.content = '$content';
                   7511:                 modalWindow.open();
                   7512:         };  
                   7513: // ]]>
                   7514: </script>
                   7515: ENDADHOC
                   7516: }
                   7517: 
1.1041    www      7518: sub modal_adhoc_inner {
                   7519:     my ($funcname,$width,$height,$content)=@_;
                   7520:     my $innerwidth=$width-20;
                   7521:     $content=&js_ready(
1.1042    www      7522:                &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1041    www      7523:                  &start_scrollbox($width.'px',$innerwidth.'px',$height.'px').
                   7524:                     $content.
                   7525:                  &end_scrollbox().
                   7526:                &end_page()
                   7527:              );
                   7528:     return &modal_adhoc_script($funcname,$width,$height,$content);
                   7529: }
                   7530: 
                   7531: sub modal_adhoc_window {
                   7532:     my ($funcname,$width,$height,$content,$linktext)=@_;
                   7533:     return &modal_adhoc_inner($funcname,$width,$height,$content).
                   7534:            "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
                   7535: }
                   7536: 
                   7537: sub modal_adhoc_launch {
                   7538:     my ($funcname,$width,$height,$content)=@_;
                   7539:     return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
                   7540: <script type="text/javascript">
                   7541: // <![CDATA[
                   7542: $funcname();
                   7543: // ]]>
                   7544: </script>
                   7545: ENDLAUNCH
                   7546: }
                   7547: 
                   7548: sub modal_adhoc_close {
                   7549:     return (<<ENDCLOSE);
                   7550: <script type="text/javascript">
                   7551: // <![CDATA[
                   7552: modalWindow.close();
                   7553: // ]]>
                   7554: </script>
                   7555: ENDCLOSE
                   7556: }
                   7557: 
1.1038    www      7558: sub togglebox_script {
                   7559:    return(<<ENDTOGGLE);
                   7560: <script type="text/javascript"> 
                   7561: // <![CDATA[
                   7562: function LCtoggleDisplay(id,hidetext,showtext) {
                   7563:    link = document.getElementById(id + "link").childNodes[0];
                   7564:    with (document.getElementById(id).style) {
                   7565:       if (display == "none" ) {
                   7566:           display = "inline";
                   7567:           link.nodeValue = hidetext;
                   7568:         } else {
                   7569:           display = "none";
                   7570:           link.nodeValue = showtext;
                   7571:        }
                   7572:    }
                   7573: }
                   7574: // ]]>
                   7575: </script>
                   7576: ENDTOGGLE
                   7577: }
                   7578: 
1.1039    www      7579: sub start_togglebox {
                   7580:     my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
                   7581:     unless ($heading) { $heading=''; } else { $heading.=' '; }
                   7582:     unless ($showtext) { $showtext=&mt('show'); }
                   7583:     unless ($hidetext) { $hidetext=&mt('hide'); }
                   7584:     unless ($headerbg) { $headerbg='#FFFFFF'; }
                   7585:     return &start_data_table().
                   7586:            &start_data_table_header_row().
                   7587:            '<td bgcolor="'.$headerbg.'">'.$heading.
                   7588:            '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
                   7589:            $showtext.'\')">'.$showtext.'</a>]</td>'.
                   7590:            &end_data_table_header_row().
                   7591:            '<tr id="'.$id.'" style="display:none""><td>';
                   7592: }
                   7593: 
                   7594: sub end_togglebox {
                   7595:     return '</td></tr>'.&end_data_table();
                   7596: }
                   7597: 
1.1041    www      7598: sub LCprogressbar_script {
1.1045    www      7599:    my ($id)=@_;
1.1041    www      7600:    return(<<ENDPROGRESS);
                   7601: <script type="text/javascript">
                   7602: // <![CDATA[
1.1045    www      7603: \$('#progressbar$id').progressbar({
1.1041    www      7604:   value: 0,
                   7605:   change: function(event, ui) {
                   7606:     var newVal = \$(this).progressbar('option', 'value');
                   7607:     \$('.pblabel', this).text(LCprogressTxt);
                   7608:   }
                   7609: });
                   7610: // ]]>
                   7611: </script>
                   7612: ENDPROGRESS
                   7613: }
                   7614: 
                   7615: sub LCprogressbarUpdate_script {
                   7616:    return(<<ENDPROGRESSUPDATE);
                   7617: <style type="text/css">
                   7618: .ui-progressbar { position:relative; }
                   7619: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
                   7620: </style>
                   7621: <script type="text/javascript">
                   7622: // <![CDATA[
1.1045    www      7623: var LCprogressTxt='---';
                   7624: 
                   7625: function LCupdateProgress(percent,progresstext,id) {
1.1041    www      7626:    LCprogressTxt=progresstext;
1.1045    www      7627:    \$('#progressbar'+id).progressbar('value',percent);
1.1041    www      7628: }
                   7629: // ]]>
                   7630: </script>
                   7631: ENDPROGRESSUPDATE
                   7632: }
                   7633: 
1.1042    www      7634: my $LClastpercent;
1.1045    www      7635: my $LCidcnt;
                   7636: my $LCcurrentid;
1.1042    www      7637: 
1.1041    www      7638: sub LCprogressbar {
1.1042    www      7639:     my ($r)=(@_);
                   7640:     $LClastpercent=0;
1.1045    www      7641:     $LCidcnt++;
                   7642:     $LCcurrentid=$$.'_'.$LCidcnt;
1.1041    www      7643:     my $starting=&mt('Starting');
                   7644:     my $content=(<<ENDPROGBAR);
                   7645: <p>
1.1045    www      7646:   <div id="progressbar$LCcurrentid">
1.1041    www      7647:     <span class="pblabel">$starting</span>
                   7648:   </div>
                   7649: </p>
                   7650: ENDPROGBAR
1.1045    www      7651:     &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041    www      7652: }
                   7653: 
                   7654: sub LCprogressbarUpdate {
1.1042    www      7655:     my ($r,$val,$text)=@_;
                   7656:     unless ($val) { 
                   7657:        if ($LClastpercent) {
                   7658:            $val=$LClastpercent;
                   7659:        } else {
                   7660:            $val=0;
                   7661:        }
                   7662:     }
1.1041    www      7663:     if ($val<0) { $val=0; }
                   7664:     if ($val>100) { $val=0; }
1.1042    www      7665:     $LClastpercent=$val;
1.1041    www      7666:     unless ($text) { $text=$val.'%'; }
                   7667:     $text=&js_ready($text);
1.1044    www      7668:     &r_print($r,<<ENDUPDATE);
1.1041    www      7669: <script type="text/javascript">
                   7670: // <![CDATA[
1.1045    www      7671: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041    www      7672: // ]]>
                   7673: </script>
                   7674: ENDUPDATE
1.1035    www      7675: }
                   7676: 
1.1042    www      7677: sub LCprogressbarClose {
                   7678:     my ($r)=@_;
                   7679:     $LClastpercent=0;
1.1044    www      7680:     &r_print($r,<<ENDCLOSE);
1.1042    www      7681: <script type="text/javascript">
                   7682: // <![CDATA[
1.1045    www      7683: \$("#progressbar$LCcurrentid").hide('slow'); 
1.1042    www      7684: // ]]>
                   7685: </script>
                   7686: ENDCLOSE
1.1044    www      7687: }
                   7688: 
                   7689: sub r_print {
                   7690:     my ($r,$to_print)=@_;
                   7691:     if ($r) {
                   7692:       $r->print($to_print);
                   7693:       $r->rflush();
                   7694:     } else {
                   7695:       print($to_print);
                   7696:     }
1.1042    www      7697: }
                   7698: 
1.320     albertel 7699: sub html_encode {
                   7700:     my ($result) = @_;
                   7701: 
1.322     albertel 7702:     $result = &HTML::Entities::encode($result,'<>&"');
1.320     albertel 7703:     
                   7704:     return $result;
                   7705: }
1.1044    www      7706: 
1.317     albertel 7707: sub js_ready {
                   7708:     my ($result) = @_;
                   7709: 
1.323     albertel 7710:     $result =~ s/[\n\r]/ /xmsg;
                   7711:     $result =~ s/\\/\\\\/xmsg;
                   7712:     $result =~ s/'/\\'/xmsg;
1.372     albertel 7713:     $result =~ s{</}{<\\/}xmsg;
1.317     albertel 7714:     
                   7715:     return $result;
                   7716: }
                   7717: 
1.315     albertel 7718: sub validate_page {
                   7719:     if (  exists($env{'internal.start_page'})
1.316     albertel 7720: 	  &&     $env{'internal.start_page'} > 1) {
                   7721: 	&Apache::lonnet::logthis('start_page called multiple times '.
1.318     albertel 7722: 				 $env{'internal.start_page'}.' '.
1.316     albertel 7723: 				 $ENV{'request.filename'});
1.315     albertel 7724:     }
                   7725:     if (  exists($env{'internal.end_page'})
1.316     albertel 7726: 	  &&     $env{'internal.end_page'} > 1) {
                   7727: 	&Apache::lonnet::logthis('end_page called multiple times '.
1.318     albertel 7728: 				 $env{'internal.end_page'}.' '.
1.316     albertel 7729: 				 $env{'request.filename'});
1.315     albertel 7730:     }
                   7731:     if (     exists($env{'internal.start_page'})
                   7732: 	&& ! exists($env{'internal.end_page'})) {
1.316     albertel 7733: 	&Apache::lonnet::logthis('start_page called without end_page '.
                   7734: 				 $env{'request.filename'});
1.315     albertel 7735:     }
                   7736:     if (   ! exists($env{'internal.start_page'})
                   7737: 	&&   exists($env{'internal.end_page'})) {
1.316     albertel 7738: 	&Apache::lonnet::logthis('end_page called without start_page'.
                   7739: 				 $env{'request.filename'});
1.315     albertel 7740:     }
1.306     albertel 7741: }
1.315     albertel 7742: 
1.996     www      7743: 
                   7744: sub start_scrollbox {
1.1075    raeburn  7745:     my ($outerwidth,$width,$height,$id,$bgcolor)=@_;
1.998     raeburn  7746:     unless ($outerwidth) { $outerwidth='520px'; }
                   7747:     unless ($width) { $width='500px'; }
                   7748:     unless ($height) { $height='200px'; }
1.1075    raeburn  7749:     my ($table_id,$div_id,$tdcol);
1.1018    raeburn  7750:     if ($id ne '') {
1.1020    raeburn  7751:         $table_id = " id='table_$id'";
                   7752:         $div_id = " id='div_$id'";
1.1018    raeburn  7753:     }
1.1075    raeburn  7754:     if ($bgcolor ne '') {
                   7755:         $tdcol = "background-color: $bgcolor;";
                   7756:     }
                   7757:     return <<"END";
                   7758: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol"><div style="overflow:auto; width:$width; height: $height;"$div_id>
                   7759: END
1.996     www      7760: }
                   7761: 
                   7762: sub end_scrollbox {
1.1036    www      7763:     return '</div></td></tr></table>';
1.996     www      7764: }
                   7765: 
1.318     albertel 7766: sub simple_error_page {
                   7767:     my ($r,$title,$msg) = @_;
                   7768:     my $page =
                   7769: 	&Apache::loncommon::start_page($title).
                   7770: 	&mt($msg).
                   7771: 	&Apache::loncommon::end_page();
                   7772:     if (ref($r)) {
                   7773: 	$r->print($page);
1.327     albertel 7774: 	return;
1.318     albertel 7775:     }
                   7776:     return $page;
                   7777: }
1.347     albertel 7778: 
                   7779: {
1.610     albertel 7780:     my @row_count;
1.961     onken    7781: 
                   7782:     sub start_data_table_count {
                   7783:         unshift(@row_count, 0);
                   7784:         return;
                   7785:     }
                   7786: 
                   7787:     sub end_data_table_count {
                   7788:         shift(@row_count);
                   7789:         return;
                   7790:     }
                   7791: 
1.347     albertel 7792:     sub start_data_table {
1.1018    raeburn  7793: 	my ($add_class,$id) = @_;
1.422     albertel 7794: 	my $css_class = (join(' ','LC_data_table',$add_class));
1.1018    raeburn  7795:         my $table_id;
                   7796:         if (defined($id)) {
                   7797:             $table_id = ' id="'.$id.'"';
                   7798:         }
1.961     onken    7799: 	&start_data_table_count();
1.1018    raeburn  7800: 	return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347     albertel 7801:     }
                   7802: 
                   7803:     sub end_data_table {
1.961     onken    7804: 	&end_data_table_count();
1.389     albertel 7805: 	return '</table>'."\n";;
1.347     albertel 7806:     }
                   7807: 
                   7808:     sub start_data_table_row {
1.974     wenzelju 7809: 	my ($add_class, $id) = @_;
1.610     albertel 7810: 	$row_count[0]++;
                   7811: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900     bisitz   7812: 	$css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974     wenzelju 7813:         $id = (' id="'.$id.'"') unless ($id eq '');
                   7814:         return  '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347     albertel 7815:     }
1.471     banghart 7816:     
                   7817:     sub continue_data_table_row {
1.974     wenzelju 7818: 	my ($add_class, $id) = @_;
1.610     albertel 7819: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974     wenzelju 7820: 	$css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
                   7821:         $id = (' id="'.$id.'"') unless ($id eq '');
                   7822:         return  '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471     banghart 7823:     }
1.347     albertel 7824: 
                   7825:     sub end_data_table_row {
1.389     albertel 7826: 	return '</tr>'."\n";;
1.347     albertel 7827:     }
1.367     www      7828: 
1.421     albertel 7829:     sub start_data_table_empty_row {
1.707     bisitz   7830: #	$row_count[0]++;
1.421     albertel 7831: 	return  '<tr class="LC_empty_row" >'."\n";;
                   7832:     }
                   7833: 
                   7834:     sub end_data_table_empty_row {
                   7835: 	return '</tr>'."\n";;
                   7836:     }
                   7837: 
1.367     www      7838:     sub start_data_table_header_row {
1.389     albertel 7839: 	return  '<tr class="LC_header_row">'."\n";;
1.367     www      7840:     }
                   7841: 
                   7842:     sub end_data_table_header_row {
1.389     albertel 7843: 	return '</tr>'."\n";;
1.367     www      7844:     }
1.890     droeschl 7845: 
                   7846:     sub data_table_caption {
                   7847:         my $caption = shift;
                   7848:         return "<caption class=\"LC_caption\">$caption</caption>";
                   7849:     }
1.347     albertel 7850: }
                   7851: 
1.548     albertel 7852: =pod
                   7853: 
                   7854: =item * &inhibit_menu_check($arg)
                   7855: 
                   7856: Checks for a inhibitmenu state and generates output to preserve it
                   7857: 
                   7858: Inputs:         $arg - can be any of
                   7859:                      - undef - in which case the return value is a string 
                   7860:                                to add  into arguments list of a uri
                   7861:                      - 'input' - in which case the return value is a HTML
                   7862:                                  <form> <input> field of type hidden to
                   7863:                                  preserve the value
                   7864:                      - a url - in which case the return value is the url with
                   7865:                                the neccesary cgi args added to preserve the
                   7866:                                inhibitmenu state
                   7867:                      - a ref to a url - no return value, but the string is
                   7868:                                         updated to include the neccessary cgi
                   7869:                                         args to preserve the inhibitmenu state
                   7870: 
                   7871: =cut
                   7872: 
                   7873: sub inhibit_menu_check {
                   7874:     my ($arg) = @_;
                   7875:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   7876:     if ($arg eq 'input') {
                   7877: 	if ($env{'form.inhibitmenu'}) {
                   7878: 	    return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
                   7879: 	} else {
                   7880: 	    return
                   7881: 	}
                   7882:     }
                   7883:     if ($env{'form.inhibitmenu'}) {
                   7884: 	if (ref($arg)) {
                   7885: 	    $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   7886: 	} elsif ($arg eq '') {
                   7887: 	    $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
                   7888: 	} else {
                   7889: 	    $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   7890: 	}
                   7891:     }
                   7892:     if (!ref($arg)) {
                   7893: 	return $arg;
                   7894:     }
                   7895: }
                   7896: 
1.251     albertel 7897: ###############################################
1.182     matthew  7898: 
                   7899: =pod
                   7900: 
1.549     albertel 7901: =back
                   7902: 
                   7903: =head1 User Information Routines
                   7904: 
                   7905: =over 4
                   7906: 
1.405     albertel 7907: =item * &get_users_function()
1.182     matthew  7908: 
                   7909: Used by &bodytag to determine the current users primary role.
                   7910: Returns either 'student','coordinator','admin', or 'author'.
                   7911: 
                   7912: =cut
                   7913: 
                   7914: ###############################################
                   7915: sub get_users_function {
1.815     tempelho 7916:     my $function = 'norole';
1.818     tempelho 7917:     if ($env{'request.role'}=~/^(st)/) {
                   7918:         $function='student';
                   7919:     }
1.907     raeburn  7920:     if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182     matthew  7921:         $function='coordinator';
                   7922:     }
1.258     albertel 7923:     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182     matthew  7924:         $function='admin';
                   7925:     }
1.826     bisitz   7926:     if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025    raeburn  7927:         ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182     matthew  7928:         $function='author';
                   7929:     }
                   7930:     return $function;
1.54      www      7931: }
1.99      www      7932: 
                   7933: ###############################################
                   7934: 
1.233     raeburn  7935: =pod
                   7936: 
1.821     raeburn  7937: =item * &show_course()
                   7938: 
                   7939: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
                   7940: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
                   7941: 
                   7942: Inputs:
                   7943: None
                   7944: 
                   7945: Outputs:
                   7946: Scalar: 1 if 'Course' to be used, 0 otherwise.
                   7947: 
                   7948: =cut
                   7949: 
                   7950: ###############################################
                   7951: sub show_course {
                   7952:     my $course = !$env{'user.adv'};
                   7953:     if (!$env{'user.adv'}) {
                   7954:         foreach my $env (keys(%env)) {
                   7955:             next if ($env !~ m/^user\.priv\./);
                   7956:             if ($env !~ m/^user\.priv\.(?:st|cm)/) {
                   7957:                 $course = 0;
                   7958:                 last;
                   7959:             }
                   7960:         }
                   7961:     }
                   7962:     return $course;
                   7963: }
                   7964: 
                   7965: ###############################################
                   7966: 
                   7967: =pod
                   7968: 
1.542     raeburn  7969: =item * &check_user_status()
1.274     raeburn  7970: 
                   7971: Determines current status of supplied role for a
                   7972: specific user. Roles can be active, previous or future.
                   7973: 
                   7974: Inputs: 
                   7975: user's domain, user's username, course's domain,
1.375     raeburn  7976: course's number, optional section ID.
1.274     raeburn  7977: 
                   7978: Outputs:
                   7979: role status: active, previous or future. 
                   7980: 
                   7981: =cut
                   7982: 
                   7983: sub check_user_status {
1.412     raeburn  7984:     my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073    raeburn  7985:     my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.274     raeburn  7986:     my @uroles = keys %userinfo;
                   7987:     my $srchstr;
                   7988:     my $active_chk = 'none';
1.412     raeburn  7989:     my $now = time;
1.274     raeburn  7990:     if (@uroles > 0) {
1.908     raeburn  7991:         if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274     raeburn  7992:             $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
                   7993:         } else {
1.412     raeburn  7994:             $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
                   7995:         }
                   7996:         if (grep/^\Q$srchstr\E$/,@uroles) {
1.274     raeburn  7997:             my $role_end = 0;
                   7998:             my $role_start = 0;
                   7999:             $active_chk = 'active';
1.412     raeburn  8000:             if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
                   8001:                 $role_end = $1;
                   8002:                 if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
                   8003:                     $role_start = $1;
1.274     raeburn  8004:                 }
                   8005:             }
                   8006:             if ($role_start > 0) {
1.412     raeburn  8007:                 if ($now < $role_start) {
1.274     raeburn  8008:                     $active_chk = 'future';
                   8009:                 }
                   8010:             }
                   8011:             if ($role_end > 0) {
1.412     raeburn  8012:                 if ($now > $role_end) {
1.274     raeburn  8013:                     $active_chk = 'previous';
                   8014:                 }
                   8015:             }
                   8016:         }
                   8017:     }
                   8018:     return $active_chk;
                   8019: }
                   8020: 
                   8021: ###############################################
                   8022: 
                   8023: =pod
                   8024: 
1.405     albertel 8025: =item * &get_sections()
1.233     raeburn  8026: 
                   8027: Determines all the sections for a course including
                   8028: sections with students and sections containing other roles.
1.419     raeburn  8029: Incoming parameters: 
                   8030: 
                   8031: 1. domain
                   8032: 2. course number 
                   8033: 3. reference to array containing roles for which sections should 
                   8034: be gathered (optional).
                   8035: 4. reference to array containing status types for which sections 
                   8036: should be gathered (optional).
                   8037: 
                   8038: If the third argument is undefined, sections are gathered for any role. 
                   8039: If the fourth argument is undefined, sections are gathered for any status.
                   8040: Permissible values are 'active' or 'future' or 'previous'.
1.233     raeburn  8041:  
1.374     raeburn  8042: Returns section hash (keys are section IDs, values are
                   8043: number of users in each section), subject to the
1.419     raeburn  8044: optional roles filter, optional status filter 
1.233     raeburn  8045: 
                   8046: =cut
                   8047: 
                   8048: ###############################################
                   8049: sub get_sections {
1.419     raeburn  8050:     my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366     albertel 8051:     if (!defined($cdom) || !defined($cnum)) {
                   8052:         my $cid =  $env{'request.course.id'};
                   8053: 
                   8054: 	return if (!defined($cid));
                   8055: 
                   8056:         $cdom = $env{'course.'.$cid.'.domain'};
                   8057:         $cnum = $env{'course.'.$cid.'.num'};
                   8058:     }
                   8059: 
                   8060:     my %sectioncount;
1.419     raeburn  8061:     my $now = time;
1.240     albertel 8062: 
1.366     albertel 8063:     if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276     albertel 8064: 	my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240     albertel 8065: 	my $sec_index = &Apache::loncoursedata::CL_SECTION();
                   8066: 	my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419     raeburn  8067:         my $start_index = &Apache::loncoursedata::CL_START();
                   8068:         my $end_index = &Apache::loncoursedata::CL_END();
                   8069:         my $status;
1.366     albertel 8070: 	while (my ($student,$data) = each(%$classlist)) {
1.419     raeburn  8071: 	    my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
                   8072: 				                     $data->[$status_index],
                   8073:                                                      $data->[$start_index],
                   8074:                                                      $data->[$end_index]);
                   8075:             if ($stu_status eq 'Active') {
                   8076:                 $status = 'active';
                   8077:             } elsif ($end < $now) {
                   8078:                 $status = 'previous';
                   8079:             } elsif ($start > $now) {
                   8080:                 $status = 'future';
                   8081:             } 
                   8082: 	    if ($section ne '-1' && $section !~ /^\s*$/) {
                   8083:                 if ((!defined($possible_status)) || (($status ne '') && 
                   8084:                     (grep/^\Q$status\E$/,@{$possible_status}))) { 
                   8085: 		    $sectioncount{$section}++;
                   8086:                 }
1.240     albertel 8087: 	    }
                   8088: 	}
                   8089:     }
                   8090:     my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   8091:     foreach my $user (sort(keys(%courseroles))) {
                   8092: 	if ($user !~ /^(\w{2})/) { next; }
                   8093: 	my ($role) = ($user =~ /^(\w{2})/);
                   8094: 	if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419     raeburn  8095: 	my ($section,$status);
1.240     albertel 8096: 	if ($role eq 'cr' &&
                   8097: 	    $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
                   8098: 	    $section=$1;
                   8099: 	}
                   8100: 	if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
                   8101: 	if (!defined($section) || $section eq '-1') { next; }
1.419     raeburn  8102:         my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
                   8103:         if ($end == -1 && $start == -1) {
                   8104:             next; #deleted role
                   8105:         }
                   8106:         if (!defined($possible_status)) { 
                   8107:             $sectioncount{$section}++;
                   8108:         } else {
                   8109:             if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
                   8110:                 $status = 'active';
                   8111:             } elsif ($end < $now) {
                   8112:                 $status = 'future';
                   8113:             } elsif ($start > $now) {
                   8114:                 $status = 'previous';
                   8115:             }
                   8116:             if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
                   8117:                 $sectioncount{$section}++;
                   8118:             }
                   8119:         }
1.233     raeburn  8120:     }
1.366     albertel 8121:     return %sectioncount;
1.233     raeburn  8122: }
                   8123: 
1.274     raeburn  8124: ###############################################
1.294     raeburn  8125: 
                   8126: =pod
1.405     albertel 8127: 
                   8128: =item * &get_course_users()
                   8129: 
1.275     raeburn  8130: Retrieves usernames:domains for users in the specified course
                   8131: with specific role(s), and access status. 
                   8132: 
                   8133: Incoming parameters:
1.277     albertel 8134: 1. course domain
                   8135: 2. course number
                   8136: 3. access status: users must have - either active, 
1.275     raeburn  8137: previous, future, or all.
1.277     albertel 8138: 4. reference to array of permissible roles
1.288     raeburn  8139: 5. reference to array of section restrictions (optional)
                   8140: 6. reference to results object (hash of hashes).
                   8141: 7. reference to optional userdata hash
1.609     raeburn  8142: 8. reference to optional statushash
1.630     raeburn  8143: 9. flag if privileged users (except those set to unhide in
                   8144:    course settings) should be excluded    
1.609     raeburn  8145: Keys of top level results hash are roles.
1.275     raeburn  8146: Keys of inner hashes are username:domain, with 
                   8147: values set to access type.
1.288     raeburn  8148: Optional userdata hash returns an array with arguments in the 
                   8149: same order as loncoursedata::get_classlist() for student data.
                   8150: 
1.609     raeburn  8151: Optional statushash returns
                   8152: 
1.288     raeburn  8153: Entries for end, start, section and status are blank because
                   8154: of the possibility of multiple values for non-student roles.
                   8155: 
1.275     raeburn  8156: =cut
1.405     albertel 8157: 
1.275     raeburn  8158: ###############################################
1.405     albertel 8159: 
1.275     raeburn  8160: sub get_course_users {
1.630     raeburn  8161:     my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288     raeburn  8162:     my %idx = ();
1.419     raeburn  8163:     my %seclists;
1.288     raeburn  8164: 
                   8165:     $idx{udom} = &Apache::loncoursedata::CL_SDOM();
                   8166:     $idx{uname} =  &Apache::loncoursedata::CL_SNAME();
                   8167:     $idx{end} = &Apache::loncoursedata::CL_END();
                   8168:     $idx{start} = &Apache::loncoursedata::CL_START();
                   8169:     $idx{id} = &Apache::loncoursedata::CL_ID();
                   8170:     $idx{section} = &Apache::loncoursedata::CL_SECTION();
                   8171:     $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
                   8172:     $idx{status} = &Apache::loncoursedata::CL_STATUS();
                   8173: 
1.290     albertel 8174:     if (grep(/^st$/,@{$roles})) {
1.276     albertel 8175:         my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278     raeburn  8176:         my $now = time;
1.277     albertel 8177:         foreach my $student (keys(%{$classlist})) {
1.288     raeburn  8178:             my $match = 0;
1.412     raeburn  8179:             my $secmatch = 0;
1.419     raeburn  8180:             my $section = $$classlist{$student}[$idx{section}];
1.609     raeburn  8181:             my $status = $$classlist{$student}[$idx{status}];
1.419     raeburn  8182:             if ($section eq '') {
                   8183:                 $section = 'none';
                   8184:             }
1.291     albertel 8185:             if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 8186:                 if (grep(/^all$/,@{$sections})) {
1.412     raeburn  8187:                     $secmatch = 1;
                   8188:                 } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420     albertel 8189:                     if (grep(/^none$/,@{$sections})) {
1.412     raeburn  8190:                         $secmatch = 1;
                   8191:                     }
                   8192:                 } else {  
1.419     raeburn  8193: 		    if (grep(/^\Q$section\E$/,@{$sections})) {
1.412     raeburn  8194: 		        $secmatch = 1;
                   8195:                     }
1.290     albertel 8196: 		}
1.412     raeburn  8197:                 if (!$secmatch) {
                   8198:                     next;
                   8199:                 }
1.419     raeburn  8200:             }
1.275     raeburn  8201:             if (defined($$types{'active'})) {
1.288     raeburn  8202:                 if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275     raeburn  8203:                     push(@{$$users{st}{$student}},'active');
1.288     raeburn  8204:                     $match = 1;
1.275     raeburn  8205:                 }
                   8206:             }
                   8207:             if (defined($$types{'previous'})) {
1.609     raeburn  8208:                 if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275     raeburn  8209:                     push(@{$$users{st}{$student}},'previous');
1.288     raeburn  8210:                     $match = 1;
1.275     raeburn  8211:                 }
                   8212:             }
                   8213:             if (defined($$types{'future'})) {
1.609     raeburn  8214:                 if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275     raeburn  8215:                     push(@{$$users{st}{$student}},'future');
1.288     raeburn  8216:                     $match = 1;
1.275     raeburn  8217:                 }
                   8218:             }
1.609     raeburn  8219:             if ($match) {
                   8220:                 push(@{$seclists{$student}},$section);
                   8221:                 if (ref($userdata) eq 'HASH') {
                   8222:                     $$userdata{$student} = $$classlist{$student};
                   8223:                 }
                   8224:                 if (ref($statushash) eq 'HASH') {
                   8225:                     $statushash->{$student}{'st'}{$section} = $status;
                   8226:                 }
1.288     raeburn  8227:             }
1.275     raeburn  8228:         }
                   8229:     }
1.412     raeburn  8230:     if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439     raeburn  8231:         my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   8232:         my $now = time;
1.609     raeburn  8233:         my %displaystatus = ( previous => 'Expired',
                   8234:                               active   => 'Active',
                   8235:                               future   => 'Future',
                   8236:                             );
1.630     raeburn  8237:         my %nothide;
                   8238:         if ($hidepriv) {
                   8239:             my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
                   8240:             foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
                   8241:                 if ($user !~ /:/) {
                   8242:                     $nothide{join(':',split(/[\@]/,$user))}=1;
                   8243:                 } else {
                   8244:                     $nothide{$user} = 1;
                   8245:                 }
                   8246:             }
                   8247:         }
1.439     raeburn  8248:         foreach my $person (sort(keys(%coursepersonnel))) {
1.288     raeburn  8249:             my $match = 0;
1.412     raeburn  8250:             my $secmatch = 0;
1.439     raeburn  8251:             my $status;
1.412     raeburn  8252:             my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275     raeburn  8253:             $user =~ s/:$//;
1.439     raeburn  8254:             my ($end,$start) = split(/:/,$coursepersonnel{$person});
                   8255:             if ($end == -1 || $start == -1) {
                   8256:                 next;
                   8257:             }
                   8258:             if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
                   8259:                 (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412     raeburn  8260:                 my ($uname,$udom) = split(/:/,$user);
                   8261:                 if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 8262:                     if (grep(/^all$/,@{$sections})) {
1.412     raeburn  8263:                         $secmatch = 1;
                   8264:                     } elsif ($usec eq '') {
1.420     albertel 8265:                         if (grep(/^none$/,@{$sections})) {
1.412     raeburn  8266:                             $secmatch = 1;
                   8267:                         }
                   8268:                     } else {
                   8269:                         if (grep(/^\Q$usec\E$/,@{$sections})) {
                   8270:                             $secmatch = 1;
                   8271:                         }
                   8272:                     }
                   8273:                     if (!$secmatch) {
                   8274:                         next;
                   8275:                     }
1.288     raeburn  8276:                 }
1.419     raeburn  8277:                 if ($usec eq '') {
                   8278:                     $usec = 'none';
                   8279:                 }
1.275     raeburn  8280:                 if ($uname ne '' && $udom ne '') {
1.630     raeburn  8281:                     if ($hidepriv) {
                   8282:                         if ((&Apache::lonnet::privileged($uname,$udom)) &&
                   8283:                             (!$nothide{$uname.':'.$udom})) {
                   8284:                             next;
                   8285:                         }
                   8286:                     }
1.503     raeburn  8287:                     if ($end > 0 && $end < $now) {
1.439     raeburn  8288:                         $status = 'previous';
                   8289:                     } elsif ($start > $now) {
                   8290:                         $status = 'future';
                   8291:                     } else {
                   8292:                         $status = 'active';
                   8293:                     }
1.277     albertel 8294:                     foreach my $type (keys(%{$types})) { 
1.275     raeburn  8295:                         if ($status eq $type) {
1.420     albertel 8296:                             if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419     raeburn  8297:                                 push(@{$$users{$role}{$user}},$type);
                   8298:                             }
1.288     raeburn  8299:                             $match = 1;
                   8300:                         }
                   8301:                     }
1.419     raeburn  8302:                     if (($match) && (ref($userdata) eq 'HASH')) {
                   8303:                         if (!exists($$userdata{$uname.':'.$udom})) {
                   8304: 			    &get_user_info($udom,$uname,\%idx,$userdata);
                   8305:                         }
1.420     albertel 8306:                         if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419     raeburn  8307:                             push(@{$seclists{$uname.':'.$udom}},$usec);
                   8308:                         }
1.609     raeburn  8309:                         if (ref($statushash) eq 'HASH') {
                   8310:                             $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
                   8311:                         }
1.275     raeburn  8312:                     }
                   8313:                 }
                   8314:             }
                   8315:         }
1.290     albertel 8316:         if (grep(/^ow$/,@{$roles})) {
1.279     raeburn  8317:             if ((defined($cdom)) && (defined($cnum))) {
                   8318:                 my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
                   8319:                 if ( defined($csettings{'internal.courseowner'}) ) {
                   8320:                     my $owner = $csettings{'internal.courseowner'};
1.609     raeburn  8321:                     next if ($owner eq '');
                   8322:                     my ($ownername,$ownerdom);
                   8323:                     if ($owner =~ /^([^:]+):([^:]+)$/) {
                   8324:                         $ownername = $1;
                   8325:                         $ownerdom = $2;
                   8326:                     } else {
                   8327:                         $ownername = $owner;
                   8328:                         $ownerdom = $cdom;
                   8329:                         $owner = $ownername.':'.$ownerdom;
1.439     raeburn  8330:                     }
                   8331:                     @{$$users{'ow'}{$owner}} = 'any';
1.290     albertel 8332:                     if (defined($userdata) && 
1.609     raeburn  8333: 			!exists($$userdata{$owner})) {
                   8334: 			&get_user_info($ownerdom,$ownername,\%idx,$userdata);
                   8335:                         if (!grep(/^none$/,@{$seclists{$owner}})) {
                   8336:                             push(@{$seclists{$owner}},'none');
                   8337:                         }
                   8338:                         if (ref($statushash) eq 'HASH') {
                   8339:                             $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419     raeburn  8340:                         }
1.290     albertel 8341: 		    }
1.279     raeburn  8342:                 }
                   8343:             }
                   8344:         }
1.419     raeburn  8345:         foreach my $user (keys(%seclists)) {
                   8346:             @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
                   8347:             $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
                   8348:         }
1.275     raeburn  8349:     }
                   8350:     return;
                   8351: }
                   8352: 
1.288     raeburn  8353: sub get_user_info {
                   8354:     my ($udom,$uname,$idx,$userdata) = @_;
1.289     albertel 8355:     $$userdata{$uname.':'.$udom}[$$idx{fullname}] = 
                   8356: 	&plainname($uname,$udom,'lastname');
1.291     albertel 8357:     $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297     raeburn  8358:     $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609     raeburn  8359:     my %idhash =  &Apache::lonnet::idrget($udom,($uname));
                   8360:     $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname}; 
1.288     raeburn  8361:     return;
                   8362: }
1.275     raeburn  8363: 
1.472     raeburn  8364: ###############################################
                   8365: 
                   8366: =pod
                   8367: 
                   8368: =item * &get_user_quota()
                   8369: 
                   8370: Retrieves quota assigned for storage of portfolio files for a user  
                   8371: 
                   8372: Incoming parameters:
                   8373: 1. user's username
                   8374: 2. user's domain
                   8375: 
                   8376: Returns:
1.536     raeburn  8377: 1. Disk quota (in Mb) assigned to student.
                   8378: 2. (Optional) Type of setting: custom or default
                   8379:    (individually assigned or default for user's 
                   8380:    institutional status).
                   8381: 3. (Optional) - User's institutional status (e.g., faculty, staff
                   8382:    or student - types as defined in localenroll::inst_usertypes 
                   8383:    for user's domain, which determines default quota for user.
                   8384: 4. (Optional) - Default quota which would apply to the user.
1.472     raeburn  8385: 
                   8386: If a value has been stored in the user's environment, 
1.536     raeburn  8387: it will return that, otherwise it returns the maximal default
                   8388: defined for the user's instituional status(es) in the domain.
1.472     raeburn  8389: 
                   8390: =cut
                   8391: 
                   8392: ###############################################
                   8393: 
                   8394: 
                   8395: sub get_user_quota {
                   8396:     my ($uname,$udom) = @_;
1.536     raeburn  8397:     my ($quota,$quotatype,$settingstatus,$defquota);
1.472     raeburn  8398:     if (!defined($udom)) {
                   8399:         $udom = $env{'user.domain'};
                   8400:     }
                   8401:     if (!defined($uname)) {
                   8402:         $uname = $env{'user.name'};
                   8403:     }
                   8404:     if (($udom eq '' || $uname eq '') ||
                   8405:         ($udom eq 'public') && ($uname eq 'public')) {
                   8406:         $quota = 0;
1.536     raeburn  8407:         $quotatype = 'default';
                   8408:         $defquota = 0; 
1.472     raeburn  8409:     } else {
1.536     raeburn  8410:         my $inststatus;
1.472     raeburn  8411:         if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
                   8412:             $quota = $env{'environment.portfolioquota'};
1.536     raeburn  8413:             $inststatus = $env{'environment.inststatus'};
1.472     raeburn  8414:         } else {
1.536     raeburn  8415:             my %userenv = 
                   8416:                 &Apache::lonnet::get('environment',['portfolioquota',
                   8417:                                      'inststatus'],$udom,$uname);
1.472     raeburn  8418:             my ($tmp) = keys(%userenv);
                   8419:             if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   8420:                 $quota = $userenv{'portfolioquota'};
1.536     raeburn  8421:                 $inststatus = $userenv{'inststatus'};
1.472     raeburn  8422:             } else {
                   8423:                 undef(%userenv);
                   8424:             }
                   8425:         }
1.536     raeburn  8426:         ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472     raeburn  8427:         if ($quota eq '') {
1.536     raeburn  8428:             $quota = $defquota;
                   8429:             $quotatype = 'default';
                   8430:         } else {
                   8431:             $quotatype = 'custom';
1.472     raeburn  8432:         }
                   8433:     }
1.536     raeburn  8434:     if (wantarray) {
                   8435:         return ($quota,$quotatype,$settingstatus,$defquota);
                   8436:     } else {
                   8437:         return $quota;
                   8438:     }
1.472     raeburn  8439: }
                   8440: 
                   8441: ###############################################
                   8442: 
                   8443: =pod
                   8444: 
                   8445: =item * &default_quota()
                   8446: 
1.536     raeburn  8447: Retrieves default quota assigned for storage of user portfolio files,
                   8448: given an (optional) user's institutional status.
1.472     raeburn  8449: 
                   8450: Incoming parameters:
                   8451: 1. domain
1.536     raeburn  8452: 2. (Optional) institutional status(es).  This is a : separated list of 
                   8453:    status types (e.g., faculty, staff, student etc.)
                   8454:    which apply to the user for whom the default is being retrieved.
                   8455:    If the institutional status string in undefined, the domain
                   8456:    default quota will be returned. 
1.472     raeburn  8457: 
                   8458: Returns:
                   8459: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536     raeburn  8460: 2. (Optional) institutional type which determined the value of the
                   8461:    default quota.
1.472     raeburn  8462: 
                   8463: If a value has been stored in the domain's configuration db,
                   8464: it will return that, otherwise it returns 20 (for backwards 
                   8465: compatibility with domains which have not set up a configuration
                   8466: db file; the original statically defined portfolio quota was 20 Mb). 
                   8467: 
1.536     raeburn  8468: If the user's status includes multiple types (e.g., staff and student),
                   8469: the largest default quota which applies to the user determines the
                   8470: default quota returned.
                   8471: 
1.780     raeburn  8472: =back
                   8473: 
1.472     raeburn  8474: =cut
                   8475: 
                   8476: ###############################################
                   8477: 
                   8478: 
                   8479: sub default_quota {
1.536     raeburn  8480:     my ($udom,$inststatus) = @_;
                   8481:     my ($defquota,$settingstatus);
                   8482:     my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622     raeburn  8483:                                             ['quotas'],$udom);
                   8484:     if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536     raeburn  8485:         if ($inststatus ne '') {
1.765     raeburn  8486:             my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536     raeburn  8487:             foreach my $item (@statuses) {
1.711     raeburn  8488:                 if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   8489:                     if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
                   8490:                         if ($defquota eq '') {
                   8491:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   8492:                             $settingstatus = $item;
                   8493:                         } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
                   8494:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   8495:                             $settingstatus = $item;
                   8496:                         }
                   8497:                     }
                   8498:                 } else {
                   8499:                     if ($quotahash{'quotas'}{$item} ne '') {
                   8500:                         if ($defquota eq '') {
                   8501:                             $defquota = $quotahash{'quotas'}{$item};
                   8502:                             $settingstatus = $item;
                   8503:                         } elsif ($quotahash{'quotas'}{$item} > $defquota) {
                   8504:                             $defquota = $quotahash{'quotas'}{$item};
                   8505:                             $settingstatus = $item;
                   8506:                         }
1.536     raeburn  8507:                     }
                   8508:                 }
                   8509:             }
                   8510:         }
                   8511:         if ($defquota eq '') {
1.711     raeburn  8512:             if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   8513:                 $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
                   8514:             } else {
                   8515:                 $defquota = $quotahash{'quotas'}{'default'};
                   8516:             }
1.536     raeburn  8517:             $settingstatus = 'default';
                   8518:         }
                   8519:     } else {
                   8520:         $settingstatus = 'default';
                   8521:         $defquota = 20;
                   8522:     }
                   8523:     if (wantarray) {
                   8524:         return ($defquota,$settingstatus);
1.472     raeburn  8525:     } else {
1.536     raeburn  8526:         return $defquota;
1.472     raeburn  8527:     }
                   8528: }
                   8529: 
1.384     raeburn  8530: sub get_secgrprole_info {
                   8531:     my ($cdom,$cnum,$needroles,$type)  = @_;
                   8532:     my %sections_count = &get_sections($cdom,$cnum);
                   8533:     my @sections =  (sort {$a <=> $b} keys(%sections_count));
                   8534:     my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
                   8535:     my @groups = sort(keys(%curr_groups));
                   8536:     my $allroles = [];
                   8537:     my $rolehash;
                   8538:     my $accesshash = {
                   8539:                      active => 'Currently has access',
                   8540:                      future => 'Will have future access',
                   8541:                      previous => 'Previously had access',
                   8542:                   };
                   8543:     if ($needroles) {
                   8544:         $rolehash = {'all' => 'all'};
1.385     albertel 8545:         my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   8546: 	if (&Apache::lonnet::error(%user_roles)) {
                   8547: 	    undef(%user_roles);
                   8548: 	}
                   8549:         foreach my $item (keys(%user_roles)) {
1.384     raeburn  8550:             my ($role)=split(/\:/,$item,2);
                   8551:             if ($role eq 'cr') { next; }
                   8552:             if ($role =~ /^cr/) {
                   8553:                 $$rolehash{$role} = (split('/',$role))[3];
                   8554:             } else {
                   8555:                 $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
                   8556:             }
                   8557:         }
                   8558:         foreach my $key (sort(keys(%{$rolehash}))) {
                   8559:             push(@{$allroles},$key);
                   8560:         }
                   8561:         push (@{$allroles},'st');
                   8562:         $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
                   8563:     }
                   8564:     return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
                   8565: }
                   8566: 
1.555     raeburn  8567: sub user_picker {
1.994     raeburn  8568:     my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555     raeburn  8569:     my $currdom = $dom;
                   8570:     my %curr_selected = (
                   8571:                         srchin => 'dom',
1.580     raeburn  8572:                         srchby => 'lastname',
1.555     raeburn  8573:                       );
                   8574:     my $srchterm;
1.625     raeburn  8575:     if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555     raeburn  8576:         if ($srch->{'srchby'} ne '') {
                   8577:             $curr_selected{'srchby'} = $srch->{'srchby'};
                   8578:         }
                   8579:         if ($srch->{'srchin'} ne '') {
                   8580:             $curr_selected{'srchin'} = $srch->{'srchin'};
                   8581:         }
                   8582:         if ($srch->{'srchtype'} ne '') {
                   8583:             $curr_selected{'srchtype'} = $srch->{'srchtype'};
                   8584:         }
                   8585:         if ($srch->{'srchdomain'} ne '') {
                   8586:             $currdom = $srch->{'srchdomain'};
                   8587:         }
                   8588:         $srchterm = $srch->{'srchterm'};
                   8589:     }
                   8590:     my %lt=&Apache::lonlocal::texthash(
1.573     raeburn  8591:                     'usr'       => 'Search criteria',
1.563     raeburn  8592:                     'doma'      => 'Domain/institution to search',
1.558     albertel 8593:                     'uname'     => 'username',
                   8594:                     'lastname'  => 'last name',
1.555     raeburn  8595:                     'lastfirst' => 'last name, first name',
1.558     albertel 8596:                     'crs'       => 'in this course',
1.576     raeburn  8597:                     'dom'       => 'in selected LON-CAPA domain', 
1.558     albertel 8598:                     'alc'       => 'all LON-CAPA',
1.573     raeburn  8599:                     'instd'     => 'in institutional directory for selected domain',
1.558     albertel 8600:                     'exact'     => 'is',
                   8601:                     'contains'  => 'contains',
1.569     raeburn  8602:                     'begins'    => 'begins with',
1.571     raeburn  8603:                     'youm'      => "You must include some text to search for.",
                   8604:                     'thte'      => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
                   8605:                     'thet'      => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
                   8606:                     'yomc'      => "You must choose a domain when using an institutional directory search.",
                   8607:                     'ymcd'      => "You must choose a domain when using a domain search.",
                   8608:                     'whus'      => "When using searching by last,first you must include a comma as separator between last name and first name.",
                   8609:                     'whse'      => "When searching by last,first you must include at least one character in the first name.",
                   8610:                      'thfo'     => "The following need to be corrected before the search can be run:",
1.555     raeburn  8611:                                        );
1.563     raeburn  8612:     my $domform = &select_dom_form($currdom,'srchdomain',1,1);
                   8613:     my $srchinsel = ' <select name="srchin">';
1.555     raeburn  8614: 
                   8615:     my @srchins = ('crs','dom','alc','instd');
                   8616: 
                   8617:     foreach my $option (@srchins) {
                   8618:         # FIXME 'alc' option unavailable until 
                   8619:         #       loncreateuser::print_user_query_page()
                   8620:         #       has been completed.
                   8621:         next if ($option eq 'alc');
1.880     raeburn  8622:         next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));  
1.555     raeburn  8623:         next if ($option eq 'crs' && !$env{'request.course.id'});
1.563     raeburn  8624:         if ($curr_selected{'srchin'} eq $option) {
                   8625:             $srchinsel .= ' 
                   8626:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   8627:         } else {
                   8628:             $srchinsel .= '
                   8629:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   8630:         }
1.555     raeburn  8631:     }
1.563     raeburn  8632:     $srchinsel .= "\n  </select>\n";
1.555     raeburn  8633: 
                   8634:     my $srchbysel =  ' <select name="srchby">';
1.580     raeburn  8635:     foreach my $option ('lastname','lastfirst','uname') {
1.555     raeburn  8636:         if ($curr_selected{'srchby'} eq $option) {
                   8637:             $srchbysel .= '
                   8638:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   8639:         } else {
                   8640:             $srchbysel .= '
                   8641:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   8642:          }
                   8643:     }
                   8644:     $srchbysel .= "\n  </select>\n";
                   8645: 
                   8646:     my $srchtypesel = ' <select name="srchtype">';
1.580     raeburn  8647:     foreach my $option ('begins','contains','exact') {
1.555     raeburn  8648:         if ($curr_selected{'srchtype'} eq $option) {
                   8649:             $srchtypesel .= '
                   8650:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   8651:         } else {
                   8652:             $srchtypesel .= '
                   8653:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   8654:         }
                   8655:     }
                   8656:     $srchtypesel .= "\n  </select>\n";
                   8657: 
1.558     albertel 8658:     my ($newuserscript,$new_user_create);
1.994     raeburn  8659:     my $context_dom = $env{'request.role.domain'};
                   8660:     if ($context eq 'requestcrs') {
                   8661:         if ($env{'form.coursedom'} ne '') { 
                   8662:             $context_dom = $env{'form.coursedom'};
                   8663:         }
                   8664:     }
1.556     raeburn  8665:     if ($forcenewuser) {
1.576     raeburn  8666:         if (ref($srch) eq 'HASH') {
1.994     raeburn  8667:             if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627     raeburn  8668:                 if ($cancreate) {
                   8669:                     $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>';
                   8670:                 } else {
1.799     bisitz   8671:                     my $helplink = 'javascript:helpMenu('."'display'".')';
1.627     raeburn  8672:                     my %usertypetext = (
                   8673:                         official   => 'institutional',
                   8674:                         unofficial => 'non-institutional',
                   8675:                     );
1.799     bisitz   8676:                     $new_user_create = '<p class="LC_warning">'
                   8677:                                       .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
                   8678:                                       .' '
                   8679:                                       .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
                   8680:                                           ,'<a href="'.$helplink.'">','</a>')
                   8681:                                       .'</p><br />';
1.627     raeburn  8682:                 }
1.576     raeburn  8683:             }
                   8684:         }
                   8685: 
1.556     raeburn  8686:         $newuserscript = <<"ENDSCRIPT";
                   8687: 
1.570     raeburn  8688: function setSearch(createnew,callingForm) {
1.556     raeburn  8689:     if (createnew == 1) {
1.570     raeburn  8690:         for (var i=0; i<callingForm.srchby.length; i++) {
                   8691:             if (callingForm.srchby.options[i].value == 'uname') {
                   8692:                 callingForm.srchby.selectedIndex = i;
1.556     raeburn  8693:             }
                   8694:         }
1.570     raeburn  8695:         for (var i=0; i<callingForm.srchin.length; i++) {
                   8696:             if ( callingForm.srchin.options[i].value == 'dom') {
                   8697: 		callingForm.srchin.selectedIndex = i;
1.556     raeburn  8698:             }
                   8699:         }
1.570     raeburn  8700:         for (var i=0; i<callingForm.srchtype.length; i++) {
                   8701:             if (callingForm.srchtype.options[i].value == 'exact') {
                   8702:                 callingForm.srchtype.selectedIndex = i;
1.556     raeburn  8703:             }
                   8704:         }
1.570     raeburn  8705:         for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994     raeburn  8706:             if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570     raeburn  8707:                 callingForm.srchdomain.selectedIndex = i;
1.556     raeburn  8708:             }
                   8709:         }
                   8710:     }
                   8711: }
                   8712: ENDSCRIPT
1.558     albertel 8713: 
1.556     raeburn  8714:     }
                   8715: 
1.555     raeburn  8716:     my $output = <<"END_BLOCK";
1.556     raeburn  8717: <script type="text/javascript">
1.824     bisitz   8718: // <![CDATA[
1.570     raeburn  8719: function validateEntry(callingForm) {
1.558     albertel 8720: 
1.556     raeburn  8721:     var checkok = 1;
1.558     albertel 8722:     var srchin;
1.570     raeburn  8723:     for (var i=0; i<callingForm.srchin.length; i++) {
                   8724: 	if ( callingForm.srchin[i].checked ) {
                   8725: 	    srchin = callingForm.srchin[i].value;
1.558     albertel 8726: 	}
                   8727:     }
                   8728: 
1.570     raeburn  8729:     var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
                   8730:     var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
                   8731:     var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
                   8732:     var srchterm =  callingForm.srchterm.value;
                   8733:     var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556     raeburn  8734:     var msg = "";
                   8735: 
                   8736:     if (srchterm == "") {
                   8737:         checkok = 0;
1.571     raeburn  8738:         msg += "$lt{'youm'}\\n";
1.556     raeburn  8739:     }
                   8740: 
1.569     raeburn  8741:     if (srchtype== 'begins') {
                   8742:         if (srchterm.length < 2) {
                   8743:             checkok = 0;
1.571     raeburn  8744:             msg += "$lt{'thte'}\\n";
1.569     raeburn  8745:         }
                   8746:     }
                   8747: 
1.556     raeburn  8748:     if (srchtype== 'contains') {
                   8749:         if (srchterm.length < 3) {
                   8750:             checkok = 0;
1.571     raeburn  8751:             msg += "$lt{'thet'}\\n";
1.556     raeburn  8752:         }
                   8753:     }
                   8754:     if (srchin == 'instd') {
                   8755:         if (srchdomain == '') {
                   8756:             checkok = 0;
1.571     raeburn  8757:             msg += "$lt{'yomc'}\\n";
1.556     raeburn  8758:         }
                   8759:     }
                   8760:     if (srchin == 'dom') {
                   8761:         if (srchdomain == '') {
                   8762:             checkok = 0;
1.571     raeburn  8763:             msg += "$lt{'ymcd'}\\n";
1.556     raeburn  8764:         }
                   8765:     }
                   8766:     if (srchby == 'lastfirst') {
                   8767:         if (srchterm.indexOf(",") == -1) {
                   8768:             checkok = 0;
1.571     raeburn  8769:             msg += "$lt{'whus'}\\n";
1.556     raeburn  8770:         }
                   8771:         if (srchterm.indexOf(",") == srchterm.length -1) {
                   8772:             checkok = 0;
1.571     raeburn  8773:             msg += "$lt{'whse'}\\n";
1.556     raeburn  8774:         }
                   8775:     }
                   8776:     if (checkok == 0) {
1.571     raeburn  8777:         alert("$lt{'thfo'}\\n"+msg);
1.556     raeburn  8778:         return;
                   8779:     }
                   8780:     if (checkok == 1) {
1.570     raeburn  8781:         callingForm.submit();
1.556     raeburn  8782:     }
                   8783: }
                   8784: 
                   8785: $newuserscript
                   8786: 
1.824     bisitz   8787: // ]]>
1.556     raeburn  8788: </script>
1.558     albertel 8789: 
                   8790: $new_user_create
                   8791: 
1.555     raeburn  8792: END_BLOCK
1.558     albertel 8793: 
1.876     raeburn  8794:     $output .= &Apache::lonhtmlcommon::start_pick_box().
                   8795:                &Apache::lonhtmlcommon::row_title($lt{'doma'}).
                   8796:                $domform.
                   8797:                &Apache::lonhtmlcommon::row_closure().
                   8798:                &Apache::lonhtmlcommon::row_title($lt{'usr'}).
                   8799:                $srchbysel.
                   8800:                $srchtypesel. 
                   8801:                '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
                   8802:                $srchinsel.
                   8803:                &Apache::lonhtmlcommon::row_closure(1). 
                   8804:                &Apache::lonhtmlcommon::end_pick_box().
                   8805:                '<br />';
1.555     raeburn  8806:     return $output;
                   8807: }
                   8808: 
1.612     raeburn  8809: sub user_rule_check {
1.615     raeburn  8810:     my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612     raeburn  8811:     my $response;
                   8812:     if (ref($usershash) eq 'HASH') {
                   8813:         foreach my $user (keys(%{$usershash})) {
                   8814:             my ($uname,$udom) = split(/:/,$user);
                   8815:             next if ($udom eq '' || $uname eq '');
1.615     raeburn  8816:             my ($id,$newuser);
1.612     raeburn  8817:             if (ref($usershash->{$user}) eq 'HASH') {
1.615     raeburn  8818:                 $newuser = $usershash->{$user}->{'newuser'};
1.612     raeburn  8819:                 $id = $usershash->{$user}->{'id'};
                   8820:             }
                   8821:             my $inst_response;
                   8822:             if (ref($checks) eq 'HASH') {
                   8823:                 if (defined($checks->{'username'})) {
1.615     raeburn  8824:                     ($inst_response,%{$inst_results->{$user}}) = 
1.612     raeburn  8825:                         &Apache::lonnet::get_instuser($udom,$uname);
                   8826:                 } elsif (defined($checks->{'id'})) {
1.615     raeburn  8827:                     ($inst_response,%{$inst_results->{$user}}) =
1.612     raeburn  8828:                         &Apache::lonnet::get_instuser($udom,undef,$id);
                   8829:                 }
1.615     raeburn  8830:             } else {
                   8831:                 ($inst_response,%{$inst_results->{$user}}) =
                   8832:                     &Apache::lonnet::get_instuser($udom,$uname);
                   8833:                 return;
1.612     raeburn  8834:             }
1.615     raeburn  8835:             if (!$got_rules->{$udom}) {
1.612     raeburn  8836:                 my %domconfig = &Apache::lonnet::get_dom('configuration',
                   8837:                                                   ['usercreation'],$udom);
                   8838:                 if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615     raeburn  8839:                     foreach my $item ('username','id') {
1.612     raeburn  8840:                         if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
                   8841:                             $$curr_rules{$udom}{$item} = 
                   8842:                                 $domconfig{'usercreation'}{$item.'_rule'};
1.585     raeburn  8843:                         }
                   8844:                     }
                   8845:                 }
1.615     raeburn  8846:                 $got_rules->{$udom} = 1;  
1.585     raeburn  8847:             }
1.612     raeburn  8848:             foreach my $item (keys(%{$checks})) {
                   8849:                 if (ref($$curr_rules{$udom}) eq 'HASH') {
                   8850:                     if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
                   8851:                         if (@{$$curr_rules{$udom}{$item}} > 0) {
                   8852:                             my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
                   8853:                             foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
                   8854:                                 if ($rule_check{$rule}) {
                   8855:                                     $$rulematch{$user}{$item} = $rule;
                   8856:                                     if ($inst_response eq 'ok') {
1.615     raeburn  8857:                                         if (ref($inst_results) eq 'HASH') {
                   8858:                                             if (ref($inst_results->{$user}) eq 'HASH') {
                   8859:                                                 if (keys(%{$inst_results->{$user}}) == 0) {
                   8860:                                                     $$alerts{$item}{$udom}{$uname} = 1;
                   8861:                                                 }
1.612     raeburn  8862:                                             }
                   8863:                                         }
1.615     raeburn  8864:                                     }
                   8865:                                     last;
1.585     raeburn  8866:                                 }
                   8867:                             }
                   8868:                         }
                   8869:                     }
                   8870:                 }
                   8871:             }
                   8872:         }
                   8873:     }
1.612     raeburn  8874:     return;
                   8875: }
                   8876: 
                   8877: sub user_rule_formats {
                   8878:     my ($domain,$domdesc,$curr_rules,$check) = @_;
                   8879:     my %text = ( 
                   8880:                  'username' => 'Usernames',
                   8881:                  'id'       => 'IDs',
                   8882:                );
                   8883:     my $output;
                   8884:     my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
                   8885:     if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
                   8886:         if (@{$ruleorder} > 0) {
                   8887:             $output = '<br />'.&mt("$text{$check} with the following format(s) may <span class=\"LC_cusr_emph\">only</span> be used for verified users at [_1]:",$domdesc).' <ul>';
                   8888:             foreach my $rule (@{$ruleorder}) {
                   8889:                 if (ref($curr_rules) eq 'ARRAY') {
                   8890:                     if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
                   8891:                         if (ref($rules->{$rule}) eq 'HASH') {
                   8892:                             $output .= '<li>'.$rules->{$rule}{'name'}.': '.
                   8893:                                         $rules->{$rule}{'desc'}.'</li>';
                   8894:                         }
                   8895:                     }
                   8896:                 }
                   8897:             }
                   8898:             $output .= '</ul>';
                   8899:         }
                   8900:     }
                   8901:     return $output;
                   8902: }
                   8903: 
                   8904: sub instrule_disallow_msg {
1.615     raeburn  8905:     my ($checkitem,$domdesc,$count,$mode) = @_;
1.612     raeburn  8906:     my $response;
                   8907:     my %text = (
                   8908:                   item   => 'username',
                   8909:                   items  => 'usernames',
                   8910:                   match  => 'matches',
                   8911:                   do     => 'does',
                   8912:                   action => 'a username',
                   8913:                   one    => 'one',
                   8914:                );
                   8915:     if ($count > 1) {
                   8916:         $text{'item'} = 'usernames';
                   8917:         $text{'match'} ='match';
                   8918:         $text{'do'} = 'do';
                   8919:         $text{'action'} = 'usernames',
                   8920:         $text{'one'} = 'ones';
                   8921:     }
                   8922:     if ($checkitem eq 'id') {
                   8923:         $text{'items'} = 'IDs';
                   8924:         $text{'item'} = 'ID';
                   8925:         $text{'action'} = 'an ID';
1.615     raeburn  8926:         if ($count > 1) {
                   8927:             $text{'item'} = 'IDs';
                   8928:             $text{'action'} = 'IDs';
                   8929:         }
1.612     raeburn  8930:     }
1.674     bisitz   8931:     $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  8932:     if ($mode eq 'upload') {
                   8933:         if ($checkitem eq 'username') {
                   8934:             $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'}.");
                   8935:         } elsif ($checkitem eq 'id') {
1.674     bisitz   8936:             $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  8937:         }
1.669     raeburn  8938:     } elsif ($mode eq 'selfcreate') {
                   8939:         if ($checkitem eq 'id') {
                   8940:             $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.");
                   8941:         }
1.615     raeburn  8942:     } else {
                   8943:         if ($checkitem eq 'username') {
                   8944:             $response .= &mt("You must choose $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
                   8945:         } elsif ($checkitem eq 'id') {
                   8946:             $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.");
                   8947:         }
1.612     raeburn  8948:     }
                   8949:     return $response;
1.585     raeburn  8950: }
                   8951: 
1.624     raeburn  8952: sub personal_data_fieldtitles {
                   8953:     my %fieldtitles = &Apache::lonlocal::texthash (
                   8954:                         id => 'Student/Employee ID',
                   8955:                         permanentemail => 'E-mail address',
                   8956:                         lastname => 'Last Name',
                   8957:                         firstname => 'First Name',
                   8958:                         middlename => 'Middle Name',
                   8959:                         generation => 'Generation',
                   8960:                         gen => 'Generation',
1.765     raeburn  8961:                         inststatus => 'Affiliation',
1.624     raeburn  8962:                    );
                   8963:     return %fieldtitles;
                   8964: }
                   8965: 
1.642     raeburn  8966: sub sorted_inst_types {
                   8967:     my ($dom) = @_;
                   8968:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
                   8969:     my $othertitle = &mt('All users');
                   8970:     if ($env{'request.course.id'}) {
1.668     raeburn  8971:         $othertitle  = &mt('Any users');
1.642     raeburn  8972:     }
                   8973:     my @types;
                   8974:     if (ref($order) eq 'ARRAY') {
                   8975:         @types = @{$order};
                   8976:     }
                   8977:     if (@types == 0) {
                   8978:         if (ref($usertypes) eq 'HASH') {
                   8979:             @types = sort(keys(%{$usertypes}));
                   8980:         }
                   8981:     }
                   8982:     if (keys(%{$usertypes}) > 0) {
                   8983:         $othertitle = &mt('Other users');
                   8984:     }
                   8985:     return ($othertitle,$usertypes,\@types);
                   8986: }
                   8987: 
1.645     raeburn  8988: sub get_institutional_codes {
                   8989:     my ($settings,$allcourses,$LC_code) = @_;
                   8990: # Get complete list of course sections to update
                   8991:     my @currsections = ();
                   8992:     my @currxlists = ();
                   8993:     my $coursecode = $$settings{'internal.coursecode'};
                   8994: 
                   8995:     if ($$settings{'internal.sectionnums'} ne '') {
                   8996:         @currsections = split(/,/,$$settings{'internal.sectionnums'});
                   8997:     }
                   8998: 
                   8999:     if ($$settings{'internal.crosslistings'} ne '') {
                   9000:         @currxlists = split(/,/,$$settings{'internal.crosslistings'});
                   9001:     }
                   9002: 
                   9003:     if (@currxlists > 0) {
                   9004:         foreach (@currxlists) {
                   9005:             if (m/^([^:]+):(\w*)$/) {
                   9006:                 unless (grep/^$1$/,@{$allcourses}) {
                   9007:                     push @{$allcourses},$1;
                   9008:                     $$LC_code{$1} = $2;
                   9009:                 }
                   9010:             }
                   9011:         }
                   9012:     }
                   9013:  
                   9014:     if (@currsections > 0) {
                   9015:         foreach (@currsections) {
                   9016:             if (m/^(\w+):(\w*)$/) {
                   9017:                 my $sec = $coursecode.$1;
                   9018:                 my $lc_sec = $2;
                   9019:                 unless (grep/^$sec$/,@{$allcourses}) {
                   9020:                     push @{$allcourses},$sec;
                   9021:                     $$LC_code{$sec} = $lc_sec;
                   9022:                 }
                   9023:             }
                   9024:         }
                   9025:     }
                   9026:     return;
                   9027: }
                   9028: 
1.971     raeburn  9029: sub get_standard_codeitems {
                   9030:     return ('Year','Semester','Department','Number','Section');
                   9031: }
                   9032: 
1.112     bowersj2 9033: =pod
                   9034: 
1.780     raeburn  9035: =head1 Slot Helpers
                   9036: 
                   9037: =over 4
                   9038: 
                   9039: =item * sorted_slots()
                   9040: 
1.1040    raeburn  9041: Sorts an array of slot names in order of an optional sort key,
                   9042: default sort is by slot start time (earliest first). 
1.780     raeburn  9043: 
                   9044: Inputs:
                   9045: 
                   9046: =over 4
                   9047: 
                   9048: slotsarr  - Reference to array of unsorted slot names.
                   9049: 
                   9050: slots     - Reference to hash of hash, where outer hash keys are slot names.
                   9051: 
1.1040    raeburn  9052: sortkey   - Name of key in inner hash to be sorted on (e.g., starttime).
                   9053: 
1.549     albertel 9054: =back
                   9055: 
1.780     raeburn  9056: Returns:
                   9057: 
                   9058: =over 4
                   9059: 
1.1040    raeburn  9060: sorted   - An array of slot names sorted by a specified sort key 
                   9061:            (default sort key is start time of the slot).
1.780     raeburn  9062: 
                   9063: =back
                   9064: 
                   9065: =cut
                   9066: 
                   9067: 
                   9068: sub sorted_slots {
1.1040    raeburn  9069:     my ($slotsarr,$slots,$sortkey) = @_;
                   9070:     if ($sortkey eq '') {
                   9071:         $sortkey = 'starttime';
                   9072:     }
1.780     raeburn  9073:     my @sorted;
                   9074:     if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
                   9075:         @sorted =
                   9076:             sort {
                   9077:                      if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040    raeburn  9078:                          return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780     raeburn  9079:                      }
                   9080:                      if (ref($slots->{$a})) { return -1;}
                   9081:                      if (ref($slots->{$b})) { return 1;}
                   9082:                      return 0;
                   9083:                  } @{$slotsarr};
                   9084:     }
                   9085:     return @sorted;
                   9086: }
                   9087: 
1.1040    raeburn  9088: =pod
                   9089: 
                   9090: =item * get_future_slots()
                   9091: 
                   9092: Inputs:
                   9093: 
                   9094: =over 4
                   9095: 
                   9096: cnum - course number
                   9097: 
                   9098: cdom - course domain
                   9099: 
                   9100: now - current UNIX time
                   9101: 
                   9102: symb - optional symb
                   9103: 
                   9104: =back
                   9105: 
                   9106: Returns:
                   9107: 
                   9108: =over 4
                   9109: 
                   9110: sorted_reservable - ref to array of student_schedulable slots currently 
                   9111:                     reservable, ordered by end date of reservation period.
                   9112: 
                   9113: reservable_now - ref to hash of student_schedulable slots currently
                   9114:                  reservable.
                   9115: 
                   9116:     Keys in inner hash are:
                   9117:     (a) symb: either blank or symb to which slot use is restricted.
                   9118:     (b) endreserve: end date of reservation period. 
                   9119: 
                   9120: sorted_future - ref to array of student_schedulable slots reservable in
                   9121:                 the future, ordered by start date of reservation period.
                   9122: 
                   9123: future_reservable - ref to hash of student_schedulable slots reservable
                   9124:                     in the future.
                   9125: 
                   9126:     Keys in inner hash are:
                   9127:     (a) symb: either blank or symb to which slot use is restricted.
                   9128:     (b) startreserve:  start date of reservation period.
                   9129: 
                   9130: =back
                   9131: 
                   9132: =cut
                   9133: 
                   9134: sub get_future_slots {
                   9135:     my ($cnum,$cdom,$now,$symb) = @_;
                   9136:     my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
                   9137:     my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
                   9138:     foreach my $slot (keys(%slots)) {
                   9139:         next unless($slots{$slot}->{'type'} eq 'schedulable_student');
                   9140:         if ($symb) {
                   9141:             next if (($slots{$slot}->{'symb'} ne '') && 
                   9142:                      ($slots{$slot}->{'symb'} ne $symb));
                   9143:         }
                   9144:         if (($slots{$slot}->{'starttime'} > $now) &&
                   9145:             ($slots{$slot}->{'endtime'} > $now)) {
                   9146:             if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
                   9147:                 my $userallowed = 0;
                   9148:                 if ($slots{$slot}->{'allowedsections'}) {
                   9149:                     my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
                   9150:                     if (!defined($env{'request.role.sec'})
                   9151:                         && grep(/^No section assigned$/,@allowed_sec)) {
                   9152:                         $userallowed=1;
                   9153:                     } else {
                   9154:                         if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
                   9155:                             $userallowed=1;
                   9156:                         }
                   9157:                     }
                   9158:                     unless ($userallowed) {
                   9159:                         if (defined($env{'request.course.groups'})) {
                   9160:                             my @groups = split(/:/,$env{'request.course.groups'});
                   9161:                             foreach my $group (@groups) {
                   9162:                                 if (grep(/^\Q$group\E$/,@allowed_sec)) {
                   9163:                                     $userallowed=1;
                   9164:                                     last;
                   9165:                                 }
                   9166:                             }
                   9167:                         }
                   9168:                     }
                   9169:                 }
                   9170:                 if ($slots{$slot}->{'allowedusers'}) {
                   9171:                     my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
                   9172:                     my $user = $env{'user.name'}.':'.$env{'user.domain'};
                   9173:                     if (grep(/^\Q$user\E$/,@allowed_users)) {
                   9174:                         $userallowed = 1;
                   9175:                     }
                   9176:                 }
                   9177:                 next unless($userallowed);
                   9178:             }
                   9179:             my $startreserve = $slots{$slot}->{'startreserve'};
                   9180:             my $endreserve = $slots{$slot}->{'endreserve'};
                   9181:             my $symb = $slots{$slot}->{'symb'};
                   9182:             if (($startreserve < $now) &&
                   9183:                 (!$endreserve || $endreserve > $now)) {
                   9184:                 my $lastres = $endreserve;
                   9185:                 if (!$lastres) {
                   9186:                     $lastres = $slots{$slot}->{'starttime'};
                   9187:                 }
                   9188:                 $reservable_now{$slot} = {
                   9189:                                            symb       => $symb,
                   9190:                                            endreserve => $lastres
                   9191:                                          };
                   9192:             } elsif (($startreserve > $now) &&
                   9193:                      (!$endreserve || $endreserve > $startreserve)) {
                   9194:                 $future_reservable{$slot} = {
                   9195:                                               symb         => $symb,
                   9196:                                               startreserve => $startreserve
                   9197:                                             };
                   9198:             }
                   9199:         }
                   9200:     }
                   9201:     my @unsorted_reservable = keys(%reservable_now);
                   9202:     if (@unsorted_reservable > 0) {
                   9203:         @sorted_reservable = 
                   9204:             &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
                   9205:     }
                   9206:     my @unsorted_future = keys(%future_reservable);
                   9207:     if (@unsorted_future > 0) {
                   9208:         @sorted_future =
                   9209:             &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
                   9210:     }
                   9211:     return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
                   9212: }
1.780     raeburn  9213: 
                   9214: =pod
                   9215: 
1.1057    foxr     9216: =back
                   9217: 
1.549     albertel 9218: =head1 HTTP Helpers
                   9219: 
                   9220: =over 4
                   9221: 
1.648     raeburn  9222: =item * &get_unprocessed_cgi($query,$possible_names)
1.112     bowersj2 9223: 
1.258     albertel 9224: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112     bowersj2 9225: $query.  The parameters listed in $possible_names (an array reference),
1.258     albertel 9226: will be set in $env{'form.name'} if they do not already exist.
1.112     bowersj2 9227: 
                   9228: Typically called with $ENV{'QUERY_STRING'} as the first parameter.  
                   9229: $possible_names is an ref to an array of form element names.  As an example:
                   9230: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258     albertel 9231: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112     bowersj2 9232: 
                   9233: =cut
1.1       albertel 9234: 
1.6       albertel 9235: sub get_unprocessed_cgi {
1.25      albertel 9236:   my ($query,$possible_names)= @_;
1.26      matthew  9237:   # $Apache::lonxml::debug=1;
1.356     albertel 9238:   foreach my $pair (split(/&/,$query)) {
                   9239:     my ($name, $value) = split(/=/,$pair);
1.369     www      9240:     $name = &unescape($name);
1.25      albertel 9241:     if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
                   9242:       $value =~ tr/+/ /;
                   9243:       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258     albertel 9244:       unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25      albertel 9245:     }
1.16      harris41 9246:   }
1.6       albertel 9247: }
                   9248: 
1.112     bowersj2 9249: =pod
                   9250: 
1.648     raeburn  9251: =item * &cacheheader() 
1.112     bowersj2 9252: 
                   9253: returns cache-controlling header code
                   9254: 
                   9255: =cut
                   9256: 
1.7       albertel 9257: sub cacheheader {
1.258     albertel 9258:     unless ($env{'request.method'} eq 'GET') { return ''; }
1.216     albertel 9259:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
                   9260:     my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7       albertel 9261:                 <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
                   9262:                 <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216     albertel 9263:     return $output;
1.7       albertel 9264: }
                   9265: 
1.112     bowersj2 9266: =pod
                   9267: 
1.648     raeburn  9268: =item * &no_cache($r) 
1.112     bowersj2 9269: 
                   9270: specifies header code to not have cache
                   9271: 
                   9272: =cut
                   9273: 
1.9       albertel 9274: sub no_cache {
1.216     albertel 9275:     my ($r) = @_;
                   9276:     if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258     albertel 9277: 	$env{'request.method'} ne 'GET') { return ''; }
1.216     albertel 9278:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
                   9279:     $r->no_cache(1);
                   9280:     $r->header_out("Expires" => $date);
                   9281:     $r->header_out("Pragma" => "no-cache");
1.123     www      9282: }
                   9283: 
                   9284: sub content_type {
1.181     albertel 9285:     my ($r,$type,$charset) = @_;
1.299     foxr     9286:     if ($r) {
                   9287: 	#  Note that printout.pl calls this with undef for $r.
                   9288: 	&no_cache($r);
                   9289:     }
1.258     albertel 9290:     if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181     albertel 9291:     unless ($charset) {
                   9292: 	$charset=&Apache::lonlocal::current_encoding;
                   9293:     }
                   9294:     if ($charset) { $type.='; charset='.$charset; }
                   9295:     if ($r) {
                   9296: 	$r->content_type($type);
                   9297:     } else {
                   9298: 	print("Content-type: $type\n\n");
                   9299:     }
1.9       albertel 9300: }
1.25      albertel 9301: 
1.112     bowersj2 9302: =pod
                   9303: 
1.648     raeburn  9304: =item * &add_to_env($name,$value) 
1.112     bowersj2 9305: 
1.258     albertel 9306: adds $name to the %env hash with value
1.112     bowersj2 9307: $value, if $name already exists, the entry is converted to an array
                   9308: reference and $value is added to the array.
                   9309: 
                   9310: =cut
                   9311: 
1.25      albertel 9312: sub add_to_env {
                   9313:   my ($name,$value)=@_;
1.258     albertel 9314:   if (defined($env{$name})) {
                   9315:     if (ref($env{$name})) {
1.25      albertel 9316:       #already have multiple values
1.258     albertel 9317:       push(@{ $env{$name} },$value);
1.25      albertel 9318:     } else {
                   9319:       #first time seeing multiple values, convert hash entry to an arrayref
1.258     albertel 9320:       my $first=$env{$name};
                   9321:       undef($env{$name});
                   9322:       push(@{ $env{$name} },$first,$value);
1.25      albertel 9323:     }
                   9324:   } else {
1.258     albertel 9325:     $env{$name}=$value;
1.25      albertel 9326:   }
1.31      albertel 9327: }
1.149     albertel 9328: 
                   9329: =pod
                   9330: 
1.648     raeburn  9331: =item * &get_env_multiple($name) 
1.149     albertel 9332: 
1.258     albertel 9333: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149     albertel 9334: values may be defined and end up as an array ref.
                   9335: 
                   9336: returns an array of values
                   9337: 
                   9338: =cut
                   9339: 
                   9340: sub get_env_multiple {
                   9341:     my ($name) = @_;
                   9342:     my @values;
1.258     albertel 9343:     if (defined($env{$name})) {
1.149     albertel 9344:         # exists is it an array
1.258     albertel 9345:         if (ref($env{$name})) {
                   9346:             @values=@{ $env{$name} };
1.149     albertel 9347:         } else {
1.258     albertel 9348:             $values[0]=$env{$name};
1.149     albertel 9349:         }
                   9350:     }
                   9351:     return(@values);
                   9352: }
                   9353: 
1.660     raeburn  9354: sub ask_for_embedded_content {
                   9355:     my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071    raeburn  9356:     my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
                   9357:         %currsubfile,%unused);
                   9358:     my $counter = 0;
                   9359:     my $numnew = 0;
1.987     raeburn  9360:     my $numremref = 0;
                   9361:     my $numinvalid = 0;
                   9362:     my $numpathchg = 0;
                   9363:     my $numexisting = 0;
1.1071    raeburn  9364:     my $numunused = 0;
                   9365:     my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
                   9366:         $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path);
                   9367:     my $heading = &mt('Upload embedded files');
                   9368:     my $buttontext = &mt('Upload');
                   9369: 
1.984     raeburn  9370:     if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
                   9371:         my $current_path='/';
                   9372:         if ($env{'form.currentpath'}) {
                   9373:             $current_path = $env{'form.currentpath'};
                   9374:         }
                   9375:         if ($actionurl eq '/adm/coursegrp_portfolio') {
                   9376:             $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   9377:             $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
                   9378:             $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
                   9379:         } else {
                   9380:             $udom = $env{'user.domain'};
                   9381:             $uname = $env{'user.name'};
                   9382:             $url = '/userfiles/portfolio';
                   9383:         }
1.987     raeburn  9384:         $toplevel = $url.'/';
1.984     raeburn  9385:         $url .= $current_path;
                   9386:         $getpropath = 1;
1.987     raeburn  9387:     } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
                   9388:              ($actionurl eq '/adm/imsimport')) { 
1.1022    www      9389:         my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026    raeburn  9390:         $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987     raeburn  9391:         $toplevel = $url;
1.984     raeburn  9392:         if ($rest ne '') {
1.987     raeburn  9393:             $url .= $rest;
                   9394:         }
                   9395:     } elsif ($actionurl eq '/adm/coursedocs') {
                   9396:         if (ref($args) eq 'HASH') {
1.1071    raeburn  9397:             $url = $args->{'docs_url'};
                   9398:             $toplevel = $url;
                   9399:         }
                   9400:     } elsif ($actionurl eq '/adm/dependencies') {
                   9401:         if ($env{'request.course.id'} ne '') {
                   9402:             $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   9403:             $cnum =  $env{'course.'.$env{'request.course.id'}.'.num'};
                   9404:             if (ref($args) eq 'HASH') {
                   9405:                 $url = $args->{'docs_url'};
                   9406:                 $title = $args->{'docs_title'};
                   9407:                 $toplevel = "/$url";
                   9408:                 ($path) =  
                   9409:                     ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
                   9410:                 $fileloc = &Apache::lonnet::filelocation('',$toplevel);
                   9411:                 $fileloc =~ s{^/}{};
                   9412:                 ($filename) = ($fileloc =~ m{.+/([^/]+)$});
                   9413:                 $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
                   9414:             }
1.987     raeburn  9415:         }
                   9416:     }
                   9417:     my $now = time();
                   9418:     foreach my $embed_file (keys(%{$allfiles})) {
                   9419:         my $absolutepath;
                   9420:         if ($embed_file =~ m{^\w+://}) {
                   9421:             $newfiles{$embed_file} = 1;
                   9422:             $mapping{$embed_file} = $embed_file;
                   9423:         } else {
                   9424:             if ($embed_file =~ m{^/}) {
                   9425:                 $absolutepath = $embed_file;
                   9426:                 $embed_file =~ s{^(/+)}{};
                   9427:             }
                   9428:             if ($embed_file =~ m{/}) {
                   9429:                 my ($path,$fname) = ($embed_file =~ m{^(.+)/([^/]*)$});
                   9430:                 $path = &check_for_traversal($path,$url,$toplevel);
                   9431:                 my $item = $fname;
                   9432:                 if ($path ne '') {
                   9433:                     $item = $path.'/'.$fname;
                   9434:                     $subdependencies{$path}{$fname} = 1;
                   9435:                 } else {
                   9436:                     $dependencies{$item} = 1;
                   9437:                 }
                   9438:                 if ($absolutepath) {
                   9439:                     $mapping{$item} = $absolutepath;
                   9440:                 } else {
                   9441:                     $mapping{$item} = $embed_file;
                   9442:                 }
                   9443:             } else {
                   9444:                 $dependencies{$embed_file} = 1;
                   9445:                 if ($absolutepath) {
                   9446:                     $mapping{$embed_file} = $absolutepath;
                   9447:                 } else {
                   9448:                     $mapping{$embed_file} = $embed_file;
                   9449:                 }
                   9450:             }
1.984     raeburn  9451:         }
                   9452:     }
1.1071    raeburn  9453:     my $dirptr = 16384;
1.984     raeburn  9454:     foreach my $path (keys(%subdependencies)) {
1.1071    raeburn  9455:         $currsubfile{$path} = {};
1.984     raeburn  9456:         if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) { 
1.1021    raeburn  9457:             my ($sublistref,$listerror) =
                   9458:                 &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
                   9459:             if (ref($sublistref) eq 'ARRAY') {
                   9460:                 foreach my $line (@{$sublistref}) {
                   9461:                     my ($file_name,$rest) = split(/\&/,$line,2);
1.1071    raeburn  9462:                     $currsubfile{$path}{$file_name} = 1;
1.1021    raeburn  9463:                 }
1.984     raeburn  9464:             }
1.987     raeburn  9465:         } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984     raeburn  9466:             if (opendir(my $dir,$url.'/'.$path)) {
                   9467:                 my @subdir_list = grep(!/^\./,readdir($dir));
1.1071    raeburn  9468:                 map {$currsubfile{$path}{$_} = 1;} @subdir_list;
                   9469:             }
                   9470:         } elsif ($actionurl eq '/adm/dependencies') {
                   9471:             if ($env{'request.course.id'} ne '') {
                   9472:                 my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
                   9473:                 if ($dir ne '') {
                   9474:                     my ($sublistref,$listerror) =
                   9475:                         &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
                   9476:                     if (ref($sublistref) eq 'ARRAY') {
                   9477:                         foreach my $line (@{$sublistref}) {
                   9478:                             my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
                   9479:                                 undef,$mtime)=split(/\&/,$line,12);
                   9480:                             unless (($testdir&$dirptr) ||
                   9481:                                     ($file_name =~ /^\.\.?$/)) {
                   9482:                                 $currsubfile{$path}{$file_name} = [$size,$mtime];
                   9483:                             }
                   9484:                         }
                   9485:                     }
                   9486:                 }
1.984     raeburn  9487:             }
                   9488:         }
                   9489:         foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071    raeburn  9490:             if (exists($currsubfile{$path}{$file})) {
1.987     raeburn  9491:                 my $item = $path.'/'.$file;
                   9492:                 unless ($mapping{$item} eq $item) {
                   9493:                     $pathchanges{$item} = 1;
                   9494:                 }
                   9495:                 $existing{$item} = 1;
                   9496:                 $numexisting ++;
                   9497:             } else {
                   9498:                 $newfiles{$path.'/'.$file} = 1;
1.984     raeburn  9499:             }
                   9500:         }
1.1071    raeburn  9501:         if ($actionurl eq '/adm/dependencies') {
                   9502:             foreach my $path (keys(%currsubfile)) {
                   9503:                 if (ref($currsubfile{$path}) eq 'HASH') {
                   9504:                     foreach my $file (keys(%{$currsubfile{$path}})) {
                   9505:                          unless ($subdependencies{$path}{$file}) {
                   9506:                              $unused{$path.'/'.$file} = 1; 
                   9507:                          }
                   9508:                     }
                   9509:                 }
                   9510:             }
                   9511:         }
1.984     raeburn  9512:     }
1.987     raeburn  9513:     my %currfile;
1.984     raeburn  9514:     if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021    raeburn  9515:         my ($dirlistref,$listerror) =
                   9516:             &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
                   9517:         if (ref($dirlistref) eq 'ARRAY') {
                   9518:             foreach my $line (@{$dirlistref}) {
                   9519:                 my ($file_name,$rest) = split(/\&/,$line,2);
                   9520:                 $currfile{$file_name} = 1;
                   9521:             }
1.984     raeburn  9522:         }
1.987     raeburn  9523:     } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984     raeburn  9524:         if (opendir(my $dir,$url)) {
1.987     raeburn  9525:             my @dir_list = grep(!/^\./,readdir($dir));
1.984     raeburn  9526:             map {$currfile{$_} = 1;} @dir_list;
                   9527:         }
1.1071    raeburn  9528:     } elsif ($actionurl eq '/adm/dependencies') {
                   9529:         if ($env{'request.course.id'} ne '') {
                   9530:             my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
                   9531:             if ($dir ne '') {
                   9532:                 my ($dirlistref,$listerror) =
                   9533:                     &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
                   9534:                 if (ref($dirlistref) eq 'ARRAY') {
                   9535:                     foreach my $line (@{$dirlistref}) {
                   9536:                         my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
                   9537:                             $size,undef,$mtime)=split(/\&/,$line,12);
                   9538:                         unless (($testdir&$dirptr) ||
                   9539:                                 ($file_name =~ /^\.\.?$/)) {
                   9540:                             $currfile{$file_name} = [$size,$mtime];
                   9541:                         }
                   9542:                     }
                   9543:                 }
                   9544:             }
                   9545:         }
1.984     raeburn  9546:     }
                   9547:     foreach my $file (keys(%dependencies)) {
1.1071    raeburn  9548:         if (exists($currfile{$file})) {
1.987     raeburn  9549:             unless ($mapping{$file} eq $file) {
                   9550:                 $pathchanges{$file} = 1;
                   9551:             }
                   9552:             $existing{$file} = 1;
                   9553:             $numexisting ++;
                   9554:         } else {
1.984     raeburn  9555:             $newfiles{$file} = 1;
                   9556:         }
                   9557:     }
1.1071    raeburn  9558:     foreach my $file (keys(%currfile)) {
                   9559:         unless (($file eq $filename) ||
                   9560:                 ($file eq $filename.'.bak') ||
                   9561:                 ($dependencies{$file})) {
                   9562:             $unused{$file} = 1;
                   9563:         }
                   9564:     }
1.984     raeburn  9565:     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071    raeburn  9566:         if ($actionurl eq '/adm/dependencies') {
                   9567:             next if ($embed_file =~ m{^\w+://});
                   9568:         }
1.660     raeburn  9569:         $upload_output .= &start_data_table_row().
1.1071    raeburn  9570:                           '<td><img src="'.&icon($embed_file).'" />&nbsp;'.
                   9571:                           '<span class="LC_filename">'.$embed_file.'</span>';
1.987     raeburn  9572:         unless ($mapping{$embed_file} eq $embed_file) {
                   9573:             $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.&mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
                   9574:         }
                   9575:         $upload_output .= '</td><td>';
1.1071    raeburn  9576:         if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) { 
1.660     raeburn  9577:             $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
1.987     raeburn  9578:             $numremref++;
1.660     raeburn  9579:         } elsif ($args->{'error_on_invalid_names'}
                   9580:             && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
                   9581: 
1.987     raeburn  9582:             $upload_output.='<span class="LC_warning">'.&mt('Invalid characters').'</span>';
                   9583:             $numinvalid++;
1.660     raeburn  9584:         } else {
1.1071    raeburn  9585:             $upload_output .= &embedded_file_element('upload_embedded',$counter,
1.987     raeburn  9586:                                                      $embed_file,\%mapping,
1.1071    raeburn  9587:                                                      $allfiles,$codebase,'upload');
                   9588:             $counter ++;
                   9589:             $numnew ++;
1.987     raeburn  9590:         }
                   9591:         $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
                   9592:     }
                   9593:     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071    raeburn  9594:         if ($actionurl eq '/adm/dependencies') {
                   9595:             my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
                   9596:             $modify_output .= &start_data_table_row().
                   9597:                               '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
                   9598:                               '<img src="'.&icon($embed_file).'" border="0" />'.
                   9599:                               '&nbsp;<span class="LC_filename">'.$embed_file.'</span></a></td>'.
                   9600:                               '<td>'.$size.'</td>'.
                   9601:                               '<td>'.$mtime.'</td>'.
                   9602:                               '<td><label><input type="checkbox" name="mod_upload_dep" '.
                   9603:                               'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
                   9604:                               $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
                   9605:                               '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
                   9606:                               &embedded_file_element('upload_embedded',$counter,
                   9607:                                                      $embed_file,\%mapping,
                   9608:                                                      $allfiles,$codebase,'modify').
                   9609:                               '</div></td>'.
                   9610:                               &end_data_table_row()."\n";
                   9611:             $counter ++;
                   9612:         } else {
                   9613:             $upload_output .= &start_data_table_row().
                   9614:                               '<td><span class="LC_filename">'.$embed_file.'</span></td>';
                   9615:                               '<td><span class="LC_warning">'.&mt('Already exists').'</span></td>'.
                   9616:                               &Apache::loncommon::end_data_table_row()."\n";
                   9617:         }
                   9618:     }
                   9619:     my $delidx = $counter;
                   9620:     foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
                   9621:         my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
                   9622:         $delete_output .= &start_data_table_row().
                   9623:                           '<td><img src="'.&icon($oldfile).'" />'.
                   9624:                           '&nbsp;<span class="LC_filename">'.$oldfile.'</span></td>'.
                   9625:                           '<td>'.$size.'</td>'.
                   9626:                           '<td>'.$mtime.'</td>'.
                   9627:                           '<td><label><input type="checkbox" name="del_upload_dep" '.
                   9628:                           ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
                   9629:                           &embedded_file_element('upload_embedded',$delidx,
                   9630:                                                  $oldfile,\%mapping,$allfiles,
                   9631:                                                  $codebase,'delete').'</td>'.
                   9632:                           &end_data_table_row()."\n"; 
                   9633:         $numunused ++;
                   9634:         $delidx ++;
1.987     raeburn  9635:     }
                   9636:     if ($upload_output) {
                   9637:         $upload_output = &start_data_table().
                   9638:                          $upload_output.
                   9639:                          &end_data_table()."\n";
                   9640:     }
1.1071    raeburn  9641:     if ($modify_output) {
                   9642:         $modify_output = &start_data_table().
                   9643:                          &start_data_table_header_row().
                   9644:                          '<th>'.&mt('File').'</th>'.
                   9645:                          '<th>'.&mt('Size (KB)').'</th>'.
                   9646:                          '<th>'.&mt('Modified').'</th>'.
                   9647:                          '<th>'.&mt('Upload replacement?').'</th>'.
                   9648:                          &end_data_table_header_row().
                   9649:                          $modify_output.
                   9650:                          &end_data_table()."\n";
                   9651:     }
                   9652:     if ($delete_output) {
                   9653:         $delete_output = &start_data_table().
                   9654:                          &start_data_table_header_row().
                   9655:                          '<th>'.&mt('File').'</th>'.
                   9656:                          '<th>'.&mt('Size (KB)').'</th>'.
                   9657:                          '<th>'.&mt('Modified').'</th>'.
                   9658:                          '<th>'.&mt('Delete?').'</th>'.
                   9659:                          &end_data_table_header_row().
                   9660:                          $delete_output.
                   9661:                          &end_data_table()."\n";
                   9662:     }
1.987     raeburn  9663:     my $applies = 0;
                   9664:     if ($numremref) {
                   9665:         $applies ++;
                   9666:     }
                   9667:     if ($numinvalid) {
                   9668:         $applies ++;
                   9669:     }
                   9670:     if ($numexisting) {
                   9671:         $applies ++;
                   9672:     }
1.1071    raeburn  9673:     if ($counter || $numunused) {
1.987     raeburn  9674:         $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
                   9675:                   ' method="post" enctype="multipart/form-data">'."\n".
1.1071    raeburn  9676:                   $state.'<h3>'.$heading.'</h3>'; 
                   9677:         if ($actionurl eq '/adm/dependencies') {
                   9678:             if ($numnew) {
                   9679:                 $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
                   9680:                            '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
                   9681:                            $upload_output.'<br />'."\n";
                   9682:             }
                   9683:             if ($numexisting) {
                   9684:                 $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
                   9685:                            '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
                   9686:                            $modify_output.'<br />'."\n";
                   9687:                            $buttontext = &mt('Save changes');
                   9688:             }
                   9689:             if ($numunused) {
                   9690:                 $output .= '<h4>'.&mt('Unused files').'</h4>'.
                   9691:                            '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
                   9692:                            $delete_output.'<br />'."\n";
                   9693:                            $buttontext = &mt('Save changes');
                   9694:             }
                   9695:         } else {
                   9696:             $output .= $upload_output.'<br />'."\n";
                   9697:         }
                   9698:         $output .= '<input type ="hidden" name="number_embedded_items" value="'.
                   9699:                    $counter.'" />'."\n";
                   9700:         if ($actionurl eq '/adm/dependencies') { 
                   9701:             $output .= '<input type ="hidden" name="number_newemb_items" value="'.
                   9702:                        $numnew.'" />'."\n";
                   9703:         } elsif ($actionurl eq '') {
1.987     raeburn  9704:             $output .=  '<input type="hidden" name="phase" value="three" />';
                   9705:         }
                   9706:     } elsif ($applies) {
                   9707:         $output = '<b>'.&mt('Referenced files').'</b>:<br />';
                   9708:         if ($applies > 1) {
                   9709:             $output .=  
                   9710:                 &mt('No files need to be uploaded, as one of the following applies to each reference:').'<ul>';
                   9711:             if ($numremref) {
                   9712:                 $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
                   9713:             }
                   9714:             if ($numinvalid) {
                   9715:                 $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
                   9716:             }
                   9717:             if ($numexisting) {
                   9718:                 $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
                   9719:             }
                   9720:             $output .= '</ul><br />';
                   9721:         } elsif ($numremref) {
                   9722:             $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
                   9723:         } elsif ($numinvalid) {
                   9724:             $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
                   9725:         } elsif ($numexisting) {
                   9726:             $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
                   9727:         }
                   9728:         $output .= $upload_output.'<br />';
                   9729:     }
                   9730:     my ($pathchange_output,$chgcount);
1.1071    raeburn  9731:     $chgcount = $counter;
1.987     raeburn  9732:     if (keys(%pathchanges) > 0) {
                   9733:         foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071    raeburn  9734:             if ($counter) {
1.987     raeburn  9735:                 $output .= &embedded_file_element('pathchange',$chgcount,
                   9736:                                                   $embed_file,\%mapping,
1.1071    raeburn  9737:                                                   $allfiles,$codebase,'change');
1.987     raeburn  9738:             } else {
                   9739:                 $pathchange_output .= 
                   9740:                     &start_data_table_row().
                   9741:                     '<td><input type ="checkbox" name="namechange" value="'.
                   9742:                     $chgcount.'" checked="checked" /></td>'.
                   9743:                     '<td>'.$mapping{$embed_file}.'</td>'.
                   9744:                     '<td>'.$embed_file.
                   9745:                     &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071    raeburn  9746:                                            \%mapping,$allfiles,$codebase,'change').
1.987     raeburn  9747:                     '</td>'.&end_data_table_row();
1.660     raeburn  9748:             }
1.987     raeburn  9749:             $numpathchg ++;
                   9750:             $chgcount ++;
1.660     raeburn  9751:         }
                   9752:     }
1.1071    raeburn  9753:     if ($counter) {
1.987     raeburn  9754:         if ($numpathchg) {
                   9755:             $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
                   9756:                        $numpathchg.'" />'."\n";
                   9757:         }
                   9758:         if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') || 
                   9759:             ($actionurl eq '/adm/imsimport')) {
                   9760:             $output .= '<input type="hidden" name="phase" value="three" />'."\n";
                   9761:         } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
                   9762:             $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071    raeburn  9763:         } elsif ($actionurl eq '/adm/dependencies') {
                   9764:             $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987     raeburn  9765:         }
1.1071    raeburn  9766:         $output .=  '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987     raeburn  9767:     } elsif ($numpathchg) {
                   9768:         my %pathchange = ();
                   9769:         $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
                   9770:         if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
                   9771:             $output .= '<p>'.&mt('or').'</p>'; 
                   9772:         } 
                   9773:     }
1.1071    raeburn  9774:     return ($output,$counter,$numpathchg);
1.987     raeburn  9775: }
                   9776: 
                   9777: sub embedded_file_element {
1.1071    raeburn  9778:     my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987     raeburn  9779:     return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
                   9780:                    (ref($codebase) eq 'HASH'));
                   9781:     my $output;
1.1071    raeburn  9782:     if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987     raeburn  9783:        $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
                   9784:     }
                   9785:     $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
                   9786:                &escape($embed_file).'" />';
                   9787:     unless (($context eq 'upload_embedded') && 
                   9788:             ($mapping->{$embed_file} eq $embed_file)) {
                   9789:         $output .='
                   9790:         <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
                   9791:     }
                   9792:     my $attrib;
                   9793:     if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
                   9794:         $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
                   9795:     }
                   9796:     $output .=
                   9797:         "\n\t\t".
                   9798:         '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
                   9799:         $attrib.'" />';
                   9800:     if (exists($codebase->{$mapping->{$embed_file}})) {
                   9801:         $output .=
                   9802:             "\n\t\t".
                   9803:             '<input name="codebase_'.$num.'" type="hidden" value="'.
                   9804:             &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984     raeburn  9805:     }
1.987     raeburn  9806:     return $output;
1.660     raeburn  9807: }
                   9808: 
1.1071    raeburn  9809: sub get_dependency_details {
                   9810:     my ($currfile,$currsubfile,$embed_file) = @_;
                   9811:     my ($size,$mtime,$showsize,$showmtime);
                   9812:     if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
                   9813:         if ($embed_file =~ m{/}) {
                   9814:             my ($path,$fname) = split(/\//,$embed_file);
                   9815:             if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
                   9816:                 ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
                   9817:             }
                   9818:         } else {
                   9819:             if (ref($currfile->{$embed_file}) eq 'ARRAY') {
                   9820:                 ($size,$mtime) = @{$currfile->{$embed_file}};
                   9821:             }
                   9822:         }
                   9823:         $showsize = $size/1024.0;
                   9824:         $showsize = sprintf("%.1f",$showsize);
                   9825:         if ($mtime > 0) {
                   9826:             $showmtime = &Apache::lonlocal::locallocaltime($mtime);
                   9827:         }
                   9828:     }
                   9829:     return ($showsize,$showmtime);
                   9830: }
                   9831: 
                   9832: sub ask_embedded_js {
                   9833:     return <<"END";
                   9834: <script type="text/javascript"">
                   9835: // <![CDATA[
                   9836: function toggleBrowse(counter) {
                   9837:     var chkboxid = document.getElementById('mod_upload_dep_'+counter);
                   9838:     var fileid = document.getElementById('embedded_item_'+counter);
                   9839:     var uploaddivid = document.getElementById('moduploaddep_'+counter);
                   9840:     if (chkboxid.checked == true) {
                   9841:         uploaddivid.style.display='block';
                   9842:     } else {
                   9843:         uploaddivid.style.display='none';
                   9844:         fileid.value = '';
                   9845:     }
                   9846: }
                   9847: // ]]>
                   9848: </script>
                   9849: 
                   9850: END
                   9851: }
                   9852: 
1.661     raeburn  9853: sub upload_embedded {
                   9854:     my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987     raeburn  9855:         $current_disk_usage,$hiddenstate,$actionurl) = @_;
                   9856:     my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661     raeburn  9857:     for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
                   9858:         next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
                   9859:         my $orig_uploaded_filename =
                   9860:             $env{'form.embedded_item_'.$i.'.filename'};
1.987     raeburn  9861:         foreach my $type ('orig','ref','attrib','codebase') {
                   9862:             if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
                   9863:                 $env{'form.embedded_'.$type.'_'.$i} =
                   9864:                     &unescape($env{'form.embedded_'.$type.'_'.$i});
                   9865:             }
                   9866:         }
1.661     raeburn  9867:         my ($path,$fname) =
                   9868:             ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
                   9869:         # no path, whole string is fname
                   9870:         if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
                   9871:         $fname = &Apache::lonnet::clean_filename($fname);
                   9872:         # See if there is anything left
                   9873:         next if ($fname eq '');
                   9874: 
                   9875:         # Check if file already exists as a file or directory.
                   9876:         my ($state,$msg);
                   9877:         if ($context eq 'portfolio') {
                   9878:             my $port_path = $dirpath;
                   9879:             if ($group ne '') {
                   9880:                 $port_path = "groups/$group/$port_path";
                   9881:             }
1.987     raeburn  9882:             ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
                   9883:                                               $fname,$group,'embedded_item_'.$i,
1.661     raeburn  9884:                                               $dir_root,$port_path,$disk_quota,
                   9885:                                               $current_disk_usage,$uname,$udom);
                   9886:             if ($state eq 'will_exceed_quota'
1.984     raeburn  9887:                 || $state eq 'file_locked') {
1.661     raeburn  9888:                 $output .= $msg;
                   9889:                 next;
                   9890:             }
                   9891:         } elsif (($context eq 'author') || ($context eq 'testbank')) {
                   9892:             ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
                   9893:             if ($state eq 'exists') {
                   9894:                 $output .= $msg;
                   9895:                 next;
                   9896:             }
                   9897:         }
                   9898:         # Check if extension is valid
                   9899:         if (($fname =~ /\.(\w+)$/) &&
                   9900:             (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.987     raeburn  9901:             $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1).'<br />';
1.661     raeburn  9902:             next;
                   9903:         } elsif (($fname =~ /\.(\w+)$/) &&
                   9904:                  (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987     raeburn  9905:             $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661     raeburn  9906:             next;
                   9907:         } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.987     raeburn  9908:             $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2).'<br />';
1.661     raeburn  9909:             next;
                   9910:         }
                   9911:         $env{'form.embedded_item_'.$i.'.filename'}=$fname;
                   9912:         if ($context eq 'portfolio') {
1.984     raeburn  9913:             my $result;
                   9914:             if ($state eq 'existingfile') {
                   9915:                 $result=
                   9916:                     &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.987     raeburn  9917:                                                     $dirpath.$env{'form.currentpath'}.$path);
1.661     raeburn  9918:             } else {
1.984     raeburn  9919:                 $result=
                   9920:                     &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987     raeburn  9921:                                                     $dirpath.
                   9922:                                                     $env{'form.currentpath'}.$path);
1.984     raeburn  9923:                 if ($result !~ m|^/uploaded/|) {
                   9924:                     $output .= '<span class="LC_error">'
                   9925:                                .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
                   9926:                                ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
                   9927:                                .'</span><br />';
                   9928:                     next;
                   9929:                 } else {
1.987     raeburn  9930:                     $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
                   9931:                                $path.$fname.'</span>').'<br />';     
1.984     raeburn  9932:                 }
1.661     raeburn  9933:             }
1.987     raeburn  9934:         } elsif ($context eq 'coursedoc') {
                   9935:             my $result =
                   9936:                 &Apache::lonnet::userfileupload('embedded_item_'.$i,'coursedoc',
                   9937:                                                 $dirpath.'/'.$path);
                   9938:             if ($result !~ m|^/uploaded/|) {
                   9939:                 $output .= '<span class="LC_error">'
                   9940:                            .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
                   9941:                            ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
                   9942:                            .'</span><br />';
                   9943:                     next;
                   9944:             } else {
                   9945:                 $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
                   9946:                            $path.$fname.'</span>').'<br />';
                   9947:             }
1.661     raeburn  9948:         } else {
                   9949: # Save the file
                   9950:             my $target = $env{'form.embedded_item_'.$i};
                   9951:             my $fullpath = $dir_root.$dirpath.'/'.$path;
                   9952:             my $dest = $fullpath.$fname;
                   9953:             my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027    raeburn  9954:             my @parts=split(/\//,"$dirpath/$path");
1.661     raeburn  9955:             my $count;
                   9956:             my $filepath = $dir_root;
1.1027    raeburn  9957:             foreach my $subdir (@parts) {
                   9958:                 $filepath .= "/$subdir";
                   9959:                 if (!-e $filepath) {
1.661     raeburn  9960:                     mkdir($filepath,0770);
                   9961:                 }
                   9962:             }
                   9963:             my $fh;
                   9964:             if (!open($fh,'>'.$dest)) {
                   9965:                 &Apache::lonnet::logthis('Failed to create '.$dest);
                   9966:                 $output .= '<span class="LC_error">'.
1.1071    raeburn  9967:                            &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
                   9968:                                $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661     raeburn  9969:                            '</span><br />';
                   9970:             } else {
                   9971:                 if (!print $fh $env{'form.embedded_item_'.$i}) {
                   9972:                     &Apache::lonnet::logthis('Failed to write to '.$dest);
                   9973:                     $output .= '<span class="LC_error">'.
1.1071    raeburn  9974:                               &mt('An error occurred while writing the file [_1] for embedded element [_2].',
                   9975:                                   $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661     raeburn  9976:                               '</span><br />';
                   9977:                 } else {
1.987     raeburn  9978:                     $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
                   9979:                                $url.'</span>').'<br />';
                   9980:                     unless ($context eq 'testbank') {
                   9981:                         $footer .= &mt('View embedded file: [_1]',
                   9982:                                        '<a href="'.$url.'">'.$fname.'</a>').'<br />';
                   9983:                     }
                   9984:                 }
                   9985:                 close($fh);
                   9986:             }
                   9987:         }
                   9988:         if ($env{'form.embedded_ref_'.$i}) {
                   9989:             $pathchange{$i} = 1;
                   9990:         }
                   9991:     }
                   9992:     if ($output) {
                   9993:         $output = '<p>'.$output.'</p>';
                   9994:     }
                   9995:     $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
                   9996:     $returnflag = 'ok';
1.1071    raeburn  9997:     my $numpathchgs = scalar(keys(%pathchange));
                   9998:     if ($numpathchgs > 0) {
1.987     raeburn  9999:         if ($context eq 'portfolio') {
                   10000:             $output .= '<p>'.&mt('or').'</p>';
                   10001:         } elsif ($context eq 'testbank') {
1.1071    raeburn  10002:             $output .=  '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
                   10003:                                   '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987     raeburn  10004:             $returnflag = 'modify_orightml';
                   10005:         }
                   10006:     }
1.1071    raeburn  10007:     return ($output.$footer,$returnflag,$numpathchgs);
1.987     raeburn  10008: }
                   10009: 
                   10010: sub modify_html_form {
                   10011:     my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
                   10012:     my $end = 0;
                   10013:     my $modifyform;
                   10014:     if ($context eq 'upload_embedded') {
                   10015:         return unless (ref($pathchange) eq 'HASH');
                   10016:         if ($env{'form.number_embedded_items'}) {
                   10017:             $end += $env{'form.number_embedded_items'};
                   10018:         }
                   10019:         if ($env{'form.number_pathchange_items'}) {
                   10020:             $end += $env{'form.number_pathchange_items'};
                   10021:         }
                   10022:         if ($end) {
                   10023:             for (my $i=0; $i<$end; $i++) {
                   10024:                 if ($i < $env{'form.number_embedded_items'}) {
                   10025:                     next unless($pathchange->{$i});
                   10026:                 }
                   10027:                 $modifyform .=
                   10028:                     &start_data_table_row().
                   10029:                     '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
                   10030:                     'checked="checked" /></td>'.
                   10031:                     '<td>'.$env{'form.embedded_ref_'.$i}.
                   10032:                     '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
                   10033:                     &escape($env{'form.embedded_ref_'.$i}).'" />'.
                   10034:                     '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
                   10035:                     &escape($env{'form.embedded_codebase_'.$i}).'" />'.
                   10036:                     '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
                   10037:                     &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
                   10038:                     '<td>'.$env{'form.embedded_orig_'.$i}.
                   10039:                     '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
                   10040:                     &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
                   10041:                     &end_data_table_row();
1.1071    raeburn  10042:             }
1.987     raeburn  10043:         }
                   10044:     } else {
                   10045:         $modifyform = $pathchgtable;
                   10046:         if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
                   10047:             $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
                   10048:         } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
                   10049:             $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
                   10050:         }
                   10051:     }
                   10052:     if ($modifyform) {
1.1071    raeburn  10053:         if ($actionurl eq '/adm/dependencies') {
                   10054:             $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
                   10055:         }
1.987     raeburn  10056:         return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
                   10057:                '<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".
                   10058:                '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
                   10059:                '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
                   10060:                '</ol></p>'."\n".'<p>'.
                   10061:                &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
                   10062:                '<form method="post" name="refchanger" action="'.$actionurl.'">'.
                   10063:                &start_data_table()."\n".
                   10064:                &start_data_table_header_row().
                   10065:                '<th>'.&mt('Change?').'</th>'.
                   10066:                '<th>'.&mt('Current reference').'</th>'.
                   10067:                '<th>'.&mt('Required reference').'</th>'.
                   10068:                &end_data_table_header_row()."\n".
                   10069:                $modifyform.
                   10070:                &end_data_table().'<br />'."\n".$hiddenstate.
                   10071:                '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
                   10072:                '</form>'."\n";
                   10073:     }
                   10074:     return;
                   10075: }
                   10076: 
                   10077: sub modify_html_refs {
                   10078:     my ($context,$dirpath,$uname,$udom,$dir_root) = @_;
                   10079:     my $container;
                   10080:     if ($context eq 'portfolio') {
                   10081:         $container = $env{'form.container'};
                   10082:     } elsif ($context eq 'coursedoc') {
                   10083:         $container = $env{'form.primaryurl'};
1.1071    raeburn  10084:     } elsif ($context eq 'manage_dependencies') {
                   10085:         (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
                   10086:         $container = "/$container";
1.987     raeburn  10087:     } else {
1.1027    raeburn  10088:         $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987     raeburn  10089:     }
                   10090:     my (%allfiles,%codebase,$output,$content);
                   10091:     my @changes = &get_env_multiple('form.namechange');
1.1071    raeburn  10092:     unless (@changes > 0) {
                   10093:         if (wantarray) {
                   10094:             return ('',0,0); 
                   10095:         } else {
                   10096:             return;
                   10097:         }
                   10098:     }
                   10099:     if (($context eq 'portfolio') || ($context eq 'coursedoc') || 
                   10100:         ($context eq 'manage_dependencies')) {
                   10101:         unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
                   10102:             if (wantarray) {
                   10103:                 return ('',0,0);
                   10104:             } else {
                   10105:                 return;
                   10106:             }
                   10107:         } 
1.987     raeburn  10108:         $content = &Apache::lonnet::getfile($container);
1.1071    raeburn  10109:         if ($content eq '-1') {
                   10110:             if (wantarray) {
                   10111:                 return ('',0,0);
                   10112:             } else {
                   10113:                 return;
                   10114:             }
                   10115:         }
1.987     raeburn  10116:     } else {
1.1071    raeburn  10117:         unless ($container =~ /^\Q$dir_root\E/) {
                   10118:             if (wantarray) {
                   10119:                 return ('',0,0);
                   10120:             } else {
                   10121:                 return;
                   10122:             }
                   10123:         } 
1.987     raeburn  10124:         if (open(my $fh,"<$container")) {
                   10125:             $content = join('', <$fh>);
                   10126:             close($fh);
                   10127:         } else {
1.1071    raeburn  10128:             if (wantarray) {
                   10129:                 return ('',0,0);
                   10130:             } else {
                   10131:                 return;
                   10132:             }
1.987     raeburn  10133:         }
                   10134:     }
                   10135:     my ($count,$codebasecount) = (0,0);
                   10136:     my $mm = new File::MMagic;
                   10137:     my $mime_type = $mm->checktype_contents($content);
                   10138:     if ($mime_type eq 'text/html') {
                   10139:         my $parse_result = 
                   10140:             &Apache::lonnet::extract_embedded_items($container,\%allfiles,
                   10141:                                                     \%codebase,\$content);
                   10142:         if ($parse_result eq 'ok') {
                   10143:             foreach my $i (@changes) {
                   10144:                 my $orig = &unescape($env{'form.embedded_orig_'.$i});
                   10145:                 my $ref = &unescape($env{'form.embedded_ref_'.$i});
                   10146:                 if ($allfiles{$ref}) {
                   10147:                     my $newname =  $orig;
                   10148:                     my ($attrib_regexp,$codebase);
1.1006    raeburn  10149:                     $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987     raeburn  10150:                     if ($attrib_regexp =~ /:/) {
                   10151:                         $attrib_regexp =~ s/\:/|/g;
                   10152:                     }
                   10153:                     if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
                   10154:                         my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
                   10155:                         $count += $numchg;
                   10156:                     }
                   10157:                     if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006    raeburn  10158:                         $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987     raeburn  10159:                         my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
                   10160:                         $codebasecount ++;
                   10161:                     }
                   10162:                 }
                   10163:             }
                   10164:             if ($count || $codebasecount) {
                   10165:                 my $saveresult;
1.1071    raeburn  10166:                 if (($context eq 'portfolio') || ($context eq 'coursedoc') || 
                   10167:                     ($context eq 'manage_dependencies')) {
1.987     raeburn  10168:                     my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
                   10169:                     if ($url eq $container) {
                   10170:                         my ($fname) = ($container =~ m{/([^/]+)$});
                   10171:                         $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
                   10172:                                             $count,'<span class="LC_filename">'.
1.1071    raeburn  10173:                                             $fname.'</span>').'</p>';
1.987     raeburn  10174:                     } else {
                   10175:                          $output = '<p class="LC_error">'.
                   10176:                                    &mt('Error: update failed for: [_1].',
                   10177:                                    '<span class="LC_filename">'.
                   10178:                                    $container.'</span>').'</p>';
                   10179:                     }
                   10180:                 } else {
                   10181:                     if (open(my $fh,">$container")) {
                   10182:                         print $fh $content;
                   10183:                         close($fh);
                   10184:                         $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
                   10185:                                   $count,'<span class="LC_filename">'.
                   10186:                                   $container.'</span>').'</p>';
1.661     raeburn  10187:                     } else {
1.987     raeburn  10188:                          $output = '<p class="LC_error">'.
                   10189:                                    &mt('Error: could not update [_1].',
                   10190:                                    '<span class="LC_filename">'.
                   10191:                                    $container.'</span>').'</p>';
1.661     raeburn  10192:                     }
                   10193:                 }
                   10194:             }
1.987     raeburn  10195:         } else {
                   10196:             &logthis('Failed to parse '.$container.
                   10197:                      ' to modify references: '.$parse_result);
1.661     raeburn  10198:         }
                   10199:     }
1.1071    raeburn  10200:     if (wantarray) {
                   10201:         return ($output,$count,$codebasecount);
                   10202:     } else {
                   10203:         return $output;
                   10204:     }
1.661     raeburn  10205: }
                   10206: 
                   10207: sub check_for_existing {
                   10208:     my ($path,$fname,$element) = @_;
                   10209:     my ($state,$msg);
                   10210:     if (-d $path.'/'.$fname) {
                   10211:         $state = 'exists';
                   10212:         $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   10213:     } elsif (-e $path.'/'.$fname) {
                   10214:         $state = 'exists';
                   10215:         $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   10216:     }
                   10217:     if ($state eq 'exists') {
                   10218:         $msg = '<span class="LC_error">'.$msg.'</span><br />';
                   10219:     }
                   10220:     return ($state,$msg);
                   10221: }
                   10222: 
                   10223: sub check_for_upload {
                   10224:     my ($path,$fname,$group,$element,$portfolio_root,$port_path,
                   10225:         $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985     raeburn  10226:     my $filesize = length($env{'form.'.$element});
                   10227:     if (!$filesize) {
                   10228:         my $msg = '<span class="LC_error">'.
                   10229:                   &mt('Unable to upload [_1]. (size = [_2] bytes)', 
                   10230:                       '<span class="LC_filename">'.$fname.'</span>',
                   10231:                       $filesize).'<br />'.
1.1007    raeburn  10232:                   &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985     raeburn  10233:                   '</span>';
                   10234:         return ('zero_bytes',$msg);
                   10235:     }
                   10236:     $filesize =  $filesize/1000; #express in k (1024?)
1.661     raeburn  10237:     my $getpropath = 1;
1.1021    raeburn  10238:     my ($dirlistref,$listerror) =
                   10239:          &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661     raeburn  10240:     my $found_file = 0;
                   10241:     my $locked_file = 0;
1.991     raeburn  10242:     my @lockers;
                   10243:     my $navmap;
                   10244:     if ($env{'request.course.id'}) {
                   10245:         $navmap = Apache::lonnavmaps::navmap->new();
                   10246:     }
1.1021    raeburn  10247:     if (ref($dirlistref) eq 'ARRAY') {
                   10248:         foreach my $line (@{$dirlistref}) {
                   10249:             my ($file_name,$rest)=split(/\&/,$line,2);
                   10250:             if ($file_name eq $fname){
                   10251:                 $file_name = $path.$file_name;
                   10252:                 if ($group ne '') {
                   10253:                     $file_name = $group.$file_name;
                   10254:                 }
                   10255:                 $found_file = 1;
                   10256:                 if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
                   10257:                     foreach my $lock (@lockers) {
                   10258:                         if (ref($lock) eq 'ARRAY') {
                   10259:                             my ($symb,$crsid) = @{$lock};
                   10260:                             if ($crsid eq $env{'request.course.id'}) {
                   10261:                                 if (ref($navmap)) {
                   10262:                                     my $res = $navmap->getBySymb($symb);
                   10263:                                     foreach my $part (@{$res->parts()}) { 
                   10264:                                         my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
                   10265:                                         unless (($slot_status == $res->RESERVED) ||
                   10266:                                                 ($slot_status == $res->RESERVED_LOCATION)) {
                   10267:                                             $locked_file = 1;
                   10268:                                         }
1.991     raeburn  10269:                                     }
1.1021    raeburn  10270:                                 } else {
                   10271:                                     $locked_file = 1;
1.991     raeburn  10272:                                 }
                   10273:                             } else {
                   10274:                                 $locked_file = 1;
                   10275:                             }
                   10276:                         }
1.1021    raeburn  10277:                    }
                   10278:                 } else {
                   10279:                     my @info = split(/\&/,$rest);
                   10280:                     my $currsize = $info[6]/1000;
                   10281:                     if ($currsize < $filesize) {
                   10282:                         my $extra = $filesize - $currsize;
                   10283:                         if (($current_disk_usage + $extra) > $disk_quota) {
                   10284:                             my $msg = '<span class="LC_error">'.
                   10285:                                       &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.',
                   10286:                                           '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
                   10287:                                       '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
                   10288:                                                    $disk_quota,$current_disk_usage);
                   10289:                             return ('will_exceed_quota',$msg);
                   10290:                         }
1.984     raeburn  10291:                     }
                   10292:                 }
1.661     raeburn  10293:             }
                   10294:         }
                   10295:     }
                   10296:     if (($current_disk_usage + $filesize) > $disk_quota){
                   10297:         my $msg = '<span class="LC_error">'.
                   10298:                 &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
                   10299:                   '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
                   10300:         return ('will_exceed_quota',$msg);
                   10301:     } elsif ($found_file) {
                   10302:         if ($locked_file) {
                   10303:             my $msg = '<span class="LC_error">';
                   10304:             $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>');
                   10305:             $msg .= '</span><br />';
                   10306:             $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
                   10307:             return ('file_locked',$msg);
                   10308:         } else {
                   10309:             my $msg = '<span class="LC_error">';
1.984     raeburn  10310:             $msg .= &mt(' A file by that name: [_1] was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
1.661     raeburn  10311:             $msg .= '</span>';
1.984     raeburn  10312:             return ('existingfile',$msg);
1.661     raeburn  10313:         }
                   10314:     }
                   10315: }
                   10316: 
1.987     raeburn  10317: sub check_for_traversal {
                   10318:     my ($path,$url,$toplevel) = @_;
                   10319:     my @parts=split(/\//,$path);
                   10320:     my $cleanpath;
                   10321:     my $fullpath = $url;
                   10322:     for (my $i=0;$i<@parts;$i++) {
                   10323:         next if ($parts[$i] eq '.');
                   10324:         if ($parts[$i] eq '..') {
                   10325:             $fullpath =~ s{([^/]+/)$}{};
                   10326:         } else {
                   10327:             $fullpath .= $parts[$i].'/';
                   10328:         }
                   10329:     }
                   10330:     if ($fullpath =~ /^\Q$url\E(.*)$/) {
                   10331:         $cleanpath = $1;
                   10332:     } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
                   10333:         my $curr_toprel = $1;
                   10334:         my @parts = split(/\//,$curr_toprel);
                   10335:         my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
                   10336:         my @urlparts = split(/\//,$url_toprel);
                   10337:         my $doubledots;
                   10338:         my $startdiff = -1;
                   10339:         for (my $i=0; $i<@urlparts; $i++) {
                   10340:             if ($startdiff == -1) {
                   10341:                 unless ($urlparts[$i] eq $parts[$i]) {
                   10342:                     $startdiff = $i;
                   10343:                     $doubledots .= '../';
                   10344:                 }
                   10345:             } else {
                   10346:                 $doubledots .= '../';
                   10347:             }
                   10348:         }
                   10349:         if ($startdiff > -1) {
                   10350:             $cleanpath = $doubledots;
                   10351:             for (my $i=$startdiff; $i<@parts; $i++) {
                   10352:                 $cleanpath .= $parts[$i].'/';
                   10353:             }
                   10354:         }
                   10355:     }
                   10356:     $cleanpath =~ s{(/)$}{};
                   10357:     return $cleanpath;
                   10358: }
1.31      albertel 10359: 
1.1053    raeburn  10360: sub is_archive_file {
                   10361:     my ($mimetype) = @_;
                   10362:     if (($mimetype eq 'application/octet-stream') ||
                   10363:         ($mimetype eq 'application/x-stuffit') ||
                   10364:         ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
                   10365:         return 1;
                   10366:     }
                   10367:     return;
                   10368: }
                   10369: 
                   10370: sub decompress_form {
1.1065    raeburn  10371:     my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053    raeburn  10372:     my %lt = &Apache::lonlocal::texthash (
                   10373:         this => 'This file is an archive file.',
1.1067    raeburn  10374:         camt => 'This file is a Camtasia archive file.',
1.1065    raeburn  10375:         itsc => 'Its contents are as follows:',
1.1053    raeburn  10376:         youm => 'You may wish to extract its contents.',
                   10377:         extr => 'Extract contents',
1.1067    raeburn  10378:         auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
                   10379:         proa => 'Process automatically?',
1.1053    raeburn  10380:         yes  => 'Yes',
                   10381:         no   => 'No',
1.1067    raeburn  10382:         fold => 'Title for folder containing movie',
                   10383:         movi => 'Title for page containing embedded movie', 
1.1053    raeburn  10384:     );
1.1065    raeburn  10385:     my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067    raeburn  10386:     my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065    raeburn  10387:     my $info = &list_archive_contents($fileloc,\@paths);
                   10388:     if (@paths) {
                   10389:         foreach my $path (@paths) {
                   10390:             $path =~ s{^/}{};
1.1067    raeburn  10391:             if ($path =~ m{^([^/]+)/$}) {
                   10392:                 $topdir = $1;
                   10393:             }
1.1065    raeburn  10394:             if ($path =~ m{^([^/]+)/}) {
                   10395:                 $toplevel{$1} = $path;
                   10396:             } else {
                   10397:                 $toplevel{$path} = $path;
                   10398:             }
                   10399:         }
                   10400:     }
1.1067    raeburn  10401:     if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
                   10402:         my @camtasia = ("$topdir/","$topdir/index.html",
                   10403:                         "$topdir/media/",
                   10404:                         "$topdir/media/$topdir.mp4",
                   10405:                         "$topdir/media/FirstFrame.png",
                   10406:                         "$topdir/media/player.swf",
                   10407:                         "$topdir/media/swfobject.js",
                   10408:                         "$topdir/media/expressInstall.swf");
                   10409:         my @diffs = &compare_arrays(\@paths,\@camtasia);
                   10410:         if (@diffs == 0) {
                   10411:             $is_camtasia = 1;
                   10412:         }
                   10413:     }
                   10414:     my $output;
                   10415:     if ($is_camtasia) {
                   10416:         $output = <<"ENDCAM";
                   10417: <script type="text/javascript" language="Javascript">
                   10418: // <![CDATA[
                   10419: 
                   10420: function camtasiaToggle() {
                   10421:     for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
                   10422:         if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
                   10423:             if (document.uploaded_decompress.autoextract_camtasia[i].value == 1) {
                   10424: 
                   10425:                 document.getElementById('camtasia_titles').style.display='block';
                   10426:             } else {
                   10427:                 document.getElementById('camtasia_titles').style.display='none';
                   10428:             }
                   10429:         }
                   10430:     }
                   10431:     return;
                   10432: }
                   10433: 
                   10434: // ]]>
                   10435: </script>
                   10436: <p>$lt{'camt'}</p>
                   10437: ENDCAM
1.1065    raeburn  10438:     } else {
1.1067    raeburn  10439:         $output = '<p>'.$lt{'this'};
                   10440:         if ($info eq '') {
                   10441:             $output .= ' '.$lt{'youm'}.'</p>'."\n";
                   10442:         } else {
                   10443:             $output .= ' '.$lt{'itsc'}.'</p>'."\n".
                   10444:                        '<div><pre>'.$info.'</pre></div>';
                   10445:         }
1.1065    raeburn  10446:     }
1.1067    raeburn  10447:     $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065    raeburn  10448:     my $duplicates;
                   10449:     my $num = 0;
                   10450:     if (ref($dirlist) eq 'ARRAY') {
                   10451:         foreach my $item (@{$dirlist}) {
                   10452:             if (ref($item) eq 'ARRAY') {
                   10453:                 if (exists($toplevel{$item->[0]})) {
                   10454:                     $duplicates .= 
                   10455:                         &start_data_table_row().
                   10456:                         '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
                   10457:                         'value="0" checked="checked" />'.&mt('No').'</label>'.
                   10458:                         '&nbsp;<label><input type="radio" name="archive_overwrite_'.$num.'" '.
                   10459:                         'value="1" />'.&mt('Yes').'</label>'.
                   10460:                         '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
                   10461:                         '<td>'.$item->[0].'</td>';
                   10462:                     if ($item->[2]) {
                   10463:                         $duplicates .= '<td>'.&mt('Directory').'</td>';
                   10464:                     } else {
                   10465:                         $duplicates .= '<td>'.&mt('File').'</td>';
                   10466:                     }
                   10467:                     $duplicates .= '<td>'.$item->[3].'</td>'.
                   10468:                                    '<td>'.
                   10469:                                    &Apache::lonlocal::locallocaltime($item->[4]).
                   10470:                                    '</td>'.
                   10471:                                    &end_data_table_row();
                   10472:                     $num ++;
                   10473:                 }
                   10474:             }
                   10475:         }
                   10476:     }
                   10477:     my $itemcount;
                   10478:     if (@paths > 0) {
                   10479:         $itemcount = scalar(@paths);
                   10480:     } else {
                   10481:         $itemcount = 1;
                   10482:     }
1.1067    raeburn  10483:     if ($is_camtasia) {
                   10484:         $output .= $lt{'auto'}.'<br />'.
                   10485:                    '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
                   10486:                    '<input type="radio" name="autoextract_camtasia" value="1" onclick="javascript:camtasiaToggle();" checked="checked" />'.
                   10487:                    $lt{'yes'}.'</label>&nbsp;<label>'.
                   10488:                    '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
                   10489:                    $lt{'no'}.'</label></span><br />'.
                   10490:                    '<div id="camtasia_titles" style="display:block">'.
                   10491:                    &Apache::lonhtmlcommon::start_pick_box().
                   10492:                    &Apache::lonhtmlcommon::row_title($lt{'fold'}).
                   10493:                    '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
                   10494:                    &Apache::lonhtmlcommon::row_closure().
                   10495:                    &Apache::lonhtmlcommon::row_title($lt{'movi'}).
                   10496:                    '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
                   10497:                    &Apache::lonhtmlcommon::row_closure(1).
                   10498:                    &Apache::lonhtmlcommon::end_pick_box().
                   10499:                    '</div>';
                   10500:     }
1.1065    raeburn  10501:     $output .= 
                   10502:         '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067    raeburn  10503:         '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
                   10504:         "\n";
1.1065    raeburn  10505:     if ($duplicates ne '') {
                   10506:         $output .= '<p><span class="LC_warning">'.
                   10507:                    &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.  
                   10508:                    &start_data_table().
                   10509:                    &start_data_table_header_row().
                   10510:                    '<th>'.&mt('Overwrite?').'</th>'.
                   10511:                    '<th>'.&mt('Name').'</th>'.
                   10512:                    '<th>'.&mt('Type').'</th>'.
                   10513:                    '<th>'.&mt('Size').'</th>'.
                   10514:                    '<th>'.&mt('Last modified').'</th>'.
                   10515:                    &end_data_table_header_row().
                   10516:                    $duplicates.
                   10517:                    &end_data_table().
                   10518:                    '</p>';
                   10519:     }
1.1067    raeburn  10520:     $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053    raeburn  10521:     if (ref($hiddenelements) eq 'HASH') {
                   10522:         foreach my $hidden (sort(keys(%{$hiddenelements}))) {
                   10523:             $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
                   10524:         }
                   10525:     }
                   10526:     $output .= <<"END";
1.1067    raeburn  10527: <br />
1.1053    raeburn  10528: <input type="submit" name="decompress" value="$lt{'extr'}" />
                   10529: </form>
                   10530: $noextract
                   10531: END
                   10532:     return $output;
                   10533: }
                   10534: 
1.1065    raeburn  10535: sub decompression_utility {
                   10536:     my ($program) = @_;
                   10537:     my @utilities = ('tar','gunzip','bunzip2','unzip'); 
                   10538:     my $location;
                   10539:     if (grep(/^\Q$program\E$/,@utilities)) { 
                   10540:         foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
                   10541:                          '/usr/sbin/') {
                   10542:             if (-x $dir.$program) {
                   10543:                 $location = $dir.$program;
                   10544:                 last;
                   10545:             }
                   10546:         }
                   10547:     }
                   10548:     return $location;
                   10549: }
                   10550: 
                   10551: sub list_archive_contents {
                   10552:     my ($file,$pathsref) = @_;
                   10553:     my (@cmd,$output);
                   10554:     my $needsregexp;
                   10555:     if ($file =~ /\.zip$/) {
                   10556:         @cmd = (&decompression_utility('unzip'),"-l");
                   10557:         $needsregexp = 1;
                   10558:     } elsif (($file =~ m/\.tar\.gz$/) ||
                   10559:              ($file =~ /\.tgz$/)) {
                   10560:         @cmd = (&decompression_utility('tar'),"-ztf");
                   10561:     } elsif ($file =~ /\.tar\.bz2$/) {
                   10562:         @cmd = (&decompression_utility('tar'),"-jtf");
                   10563:     } elsif ($file =~ m|\.tar$|) {
                   10564:         @cmd = (&decompression_utility('tar'),"-tf");
                   10565:     }
                   10566:     if (@cmd) {
                   10567:         undef($!);
                   10568:         undef($@);
                   10569:         if (open(my $fh,"-|", @cmd, $file)) {
                   10570:             while (my $line = <$fh>) {
                   10571:                 $output .= $line;
                   10572:                 chomp($line);
                   10573:                 my $item;
                   10574:                 if ($needsregexp) {
                   10575:                     ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/); 
                   10576:                 } else {
                   10577:                     $item = $line;
                   10578:                 }
                   10579:                 if ($item ne '') {
                   10580:                     unless (grep(/^\Q$item\E$/,@{$pathsref})) {
                   10581:                         push(@{$pathsref},$item);
                   10582:                     } 
                   10583:                 }
                   10584:             }
                   10585:             close($fh);
                   10586:         }
                   10587:     }
                   10588:     return $output;
                   10589: }
                   10590: 
1.1053    raeburn  10591: sub decompress_uploaded_file {
                   10592:     my ($file,$dir) = @_;
                   10593:     &Apache::lonnet::appenv({'cgi.file' => $file});
                   10594:     &Apache::lonnet::appenv({'cgi.dir' => $dir});
                   10595:     my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
                   10596:     my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
                   10597:     my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
                   10598:     &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
                   10599:     my $decompressed = $env{'cgi.decompressed'};
                   10600:     &Apache::lonnet::delenv('cgi.file');
                   10601:     &Apache::lonnet::delenv('cgi.dir');
                   10602:     &Apache::lonnet::delenv('cgi.decompressed');
                   10603:     return ($decompressed,$result);
                   10604: }
                   10605: 
1.1055    raeburn  10606: sub process_decompression {
                   10607:     my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
                   10608:     my ($dir,$error,$warning,$output);
                   10609:     if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
                   10610:         $error = &mt('File name not a supported archive file type.').
                   10611:                  '<br />'.&mt('File name should end with one of: [_1].',
                   10612:                               '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
                   10613:     } else {
                   10614:         my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
                   10615:         if ($docuhome eq 'no_host') {
                   10616:             $error = &mt('Could not determine home server for course.');
                   10617:         } else {
                   10618:             my @ids=&Apache::lonnet::current_machine_ids();
                   10619:             my $currdir = "$dir_root/$destination";
                   10620:             if (grep(/^\Q$docuhome\E$/,@ids)) {
                   10621:                 $dir = &LONCAPA::propath($docudom,$docuname).
                   10622:                        "$dir_root/$destination";
                   10623:             } else {
                   10624:                 $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
                   10625:                        "$dir_root/$docudom/$docuname/$destination";
                   10626:                 unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
                   10627:                     $error = &mt('Archive file not found.');
                   10628:                 }
                   10629:             }
1.1065    raeburn  10630:             my (@to_overwrite,@to_skip);
                   10631:             if ($env{'form.archive_overwrite_total'} > 0) {
                   10632:                 my $total = $env{'form.archive_overwrite_total'};
                   10633:                 for (my $i=0; $i<$total; $i++) {
                   10634:                     if ($env{'form.archive_overwrite_'.$i} == 1) {
                   10635:                         push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
                   10636:                     } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
                   10637:                         push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
                   10638:                     }
                   10639:                 }
                   10640:             }
                   10641:             my $numskip = scalar(@to_skip);
                   10642:             if (($numskip > 0) && 
                   10643:                 ($numskip == $env{'form.archive_itemcount'})) {
                   10644:                 $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');         
                   10645:             } elsif ($dir eq '') {
1.1055    raeburn  10646:                 $error = &mt('Directory containing archive file unavailable.');
                   10647:             } elsif (!$error) {
1.1065    raeburn  10648:                 my ($decompressed,$display);
                   10649:                 if ($numskip > 0) {
                   10650:                     my $tempdir = time.'_'.$$.int(rand(10000));
                   10651:                     mkdir("$dir/$tempdir",0755);
                   10652:                     system("mv $dir/$file $dir/$tempdir/$file");
                   10653:                     ($decompressed,$display) = 
                   10654:                         &decompress_uploaded_file($file,"$dir/$tempdir");
                   10655:                     foreach my $item (@to_skip) {
                   10656:                         if (($item ne '') && ($item !~ /\.\./)) {
                   10657:                             if (-f "$dir/$tempdir/$item") { 
                   10658:                                 unlink("$dir/$tempdir/$item");
                   10659:                             } elsif (-d "$dir/$tempdir/$item") {
                   10660:                                 system("rm -rf $dir/$tempdir/$item");
                   10661:                             }
                   10662:                         }
                   10663:                     }
                   10664:                     system("mv $dir/$tempdir/* $dir");
                   10665:                     rmdir("$dir/$tempdir");   
                   10666:                 } else {
                   10667:                     ($decompressed,$display) = 
                   10668:                         &decompress_uploaded_file($file,$dir);
                   10669:                 }
1.1055    raeburn  10670:                 if ($decompressed eq 'ok') {
1.1065    raeburn  10671:                     $output = '<p class="LC_info">'.
                   10672:                               &mt('Files extracted successfully from archive.').
                   10673:                               '</p>'."\n";
1.1055    raeburn  10674:                     my ($warning,$result,@contents);
                   10675:                     my ($newdirlistref,$newlisterror) =
                   10676:                         &Apache::lonnet::dirlist($currdir,$docudom,
                   10677:                                                  $docuname,1);
                   10678:                     my (%is_dir,%changes,@newitems);
                   10679:                     my $dirptr = 16384;
1.1065    raeburn  10680:                     if (ref($newdirlistref) eq 'ARRAY') {
1.1055    raeburn  10681:                         foreach my $dir_line (@{$newdirlistref}) {
                   10682:                             my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065    raeburn  10683:                             unless (($item =~ /^\.+$/) || ($item eq $file) || 
                   10684:                                     ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055    raeburn  10685:                                 push(@newitems,$item);
                   10686:                                 if ($dirptr&$testdir) {
                   10687:                                     $is_dir{$item} = 1;
                   10688:                                 }
                   10689:                                 $changes{$item} = 1;
                   10690:                             }
                   10691:                         }
                   10692:                     }
                   10693:                     if (keys(%changes) > 0) {
                   10694:                         foreach my $item (sort(@newitems)) {
                   10695:                             if ($changes{$item}) {
                   10696:                                 push(@contents,$item);
                   10697:                             }
                   10698:                         }
                   10699:                     }
                   10700:                     if (@contents > 0) {
1.1067    raeburn  10701:                         my $wantform;
                   10702:                         unless ($env{'form.autoextract_camtasia'}) {
                   10703:                             $wantform = 1;
                   10704:                         }
1.1056    raeburn  10705:                         my (%children,%parent,%dirorder,%titles);
1.1055    raeburn  10706:                         my ($count,$datatable) = &get_extracted($docudom,$docuname,
                   10707:                                                                 $currdir,\%is_dir,
                   10708:                                                                 \%children,\%parent,
1.1056    raeburn  10709:                                                                 \@contents,\%dirorder,
                   10710:                                                                 \%titles,$wantform);
1.1055    raeburn  10711:                         if ($datatable ne '') {
                   10712:                             $output .= &archive_options_form('decompressed',$datatable,
                   10713:                                                              $count,$hiddenelem);
1.1065    raeburn  10714:                             my $startcount = 6;
1.1055    raeburn  10715:                             $output .= &archive_javascript($startcount,$count,
1.1056    raeburn  10716:                                                            \%titles,\%children);
1.1055    raeburn  10717:                         }
1.1067    raeburn  10718:                         if ($env{'form.autoextract_camtasia'}) {
                   10719:                             my %displayed;
                   10720:                             my $total = 1;
                   10721:                             $env{'form.archive_directory'} = [];
                   10722:                             foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
                   10723:                                 my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
                   10724:                                 $path =~ s{/$}{};
                   10725:                                 my $item;
                   10726:                                 if ($path ne '') {
                   10727:                                     $item = "$path/$titles{$i}";
                   10728:                                 } else {
                   10729:                                     $item = $titles{$i};
                   10730:                                 }
                   10731:                                 $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
                   10732:                                 if ($item eq $contents[0]) {
                   10733:                                     push(@{$env{'form.archive_directory'}},$i);
                   10734:                                     $env{'form.archive_'.$i} = 'display';
                   10735:                                     $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
                   10736:                                     $displayed{'folder'} = $i;
                   10737:                                 } elsif ($item eq "$contents[0]/index.html") {
                   10738:                                     $env{'form.archive_'.$i} = 'display';
                   10739:                                     $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
                   10740:                                     $displayed{'web'} = $i;
                   10741:                                 } else {
                   10742:                                     if ($item eq "$contents[0]/media") {
                   10743:                                         push(@{$env{'form.archive_directory'}},$i);
                   10744:                                     }
                   10745:                                     $env{'form.archive_'.$i} = 'dependency';
                   10746:                                 }
                   10747:                                 $total ++;
                   10748:                             }
                   10749:                             for (my $i=1; $i<$total; $i++) {
                   10750:                                 next if ($i == $displayed{'web'});
                   10751:                                 next if ($i == $displayed{'folder'});
                   10752:                                 $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
                   10753:                             }
                   10754:                             $env{'form.phase'} = 'decompress_cleanup';
                   10755:                             $env{'form.archivedelete'} = 1;
                   10756:                             $env{'form.archive_count'} = $total-1;
                   10757:                             $output .=
                   10758:                                 &process_extracted_files('coursedocs',$docudom,
                   10759:                                                          $docuname,$destination,
                   10760:                                                          $dir_root,$hiddenelem);
                   10761:                         }
1.1055    raeburn  10762:                     } else {
                   10763:                         $warning = &mt('No new items extracted from archive file.');
                   10764:                     }
                   10765:                 } else {
                   10766:                     $output = $display;
                   10767:                     $error = &mt('An error occurred during extraction from the archive file.');
                   10768:                 }
                   10769:             }
                   10770:         }
                   10771:     }
                   10772:     if ($error) {
                   10773:         $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
                   10774:                    $error.'</p>'."\n";
                   10775:     }
                   10776:     if ($warning) {
                   10777:         $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
                   10778:     }
                   10779:     return $output;
                   10780: }
                   10781: 
                   10782: sub get_extracted {
1.1056    raeburn  10783:     my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
                   10784:         $titles,$wantform) = @_;
1.1055    raeburn  10785:     my $count = 0;
                   10786:     my $depth = 0;
                   10787:     my $datatable;
1.1056    raeburn  10788:     my @hierarchy;
1.1055    raeburn  10789:     return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056    raeburn  10790:                    (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
                   10791:                    (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055    raeburn  10792:     foreach my $item (@{$contents}) {
                   10793:         $count ++;
1.1056    raeburn  10794:         @{$dirorder->{$count}} = @hierarchy;
                   10795:         $titles->{$count} = $item;
1.1055    raeburn  10796:         &archive_hierarchy($depth,$count,$parent,$children);
                   10797:         if ($wantform) {
                   10798:             $datatable .= &archive_row($is_dir->{$item},$item,
                   10799:                                        $currdir,$depth,$count);
                   10800:         }
                   10801:         if ($is_dir->{$item}) {
                   10802:             $depth ++;
1.1056    raeburn  10803:             push(@hierarchy,$count);
                   10804:             $parent->{$depth} = $count;
1.1055    raeburn  10805:             $datatable .=
                   10806:                 &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056    raeburn  10807:                                            \$depth,\$count,\@hierarchy,$dirorder,
                   10808:                                            $children,$parent,$titles,$wantform);
1.1055    raeburn  10809:             $depth --;
1.1056    raeburn  10810:             pop(@hierarchy);
1.1055    raeburn  10811:         }
                   10812:     }
                   10813:     return ($count,$datatable);
                   10814: }
                   10815: 
                   10816: sub recurse_extracted_archive {
1.1056    raeburn  10817:     my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
                   10818:         $children,$parent,$titles,$wantform) = @_;
1.1055    raeburn  10819:     my $result='';
1.1056    raeburn  10820:     unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
                   10821:             (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
                   10822:             (ref($dirorder) eq 'HASH')) {
1.1055    raeburn  10823:         return $result;
                   10824:     }
                   10825:     my $dirptr = 16384;
                   10826:     my ($newdirlistref,$newlisterror) =
                   10827:         &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
                   10828:     if (ref($newdirlistref) eq 'ARRAY') {
                   10829:         foreach my $dir_line (@{$newdirlistref}) {
                   10830:             my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
                   10831:             unless ($item =~ /^\.+$/) {
                   10832:                 $$count ++;
1.1056    raeburn  10833:                 @{$dirorder->{$$count}} = @{$hierarchy};
                   10834:                 $titles->{$$count} = $item;
1.1055    raeburn  10835:                 &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056    raeburn  10836: 
1.1055    raeburn  10837:                 my $is_dir;
                   10838:                 if ($dirptr&$testdir) {
                   10839:                     $is_dir = 1;
                   10840:                 }
                   10841:                 if ($wantform) {
                   10842:                     $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
                   10843:                 }
                   10844:                 if ($is_dir) {
                   10845:                     $$depth ++;
1.1056    raeburn  10846:                     push(@{$hierarchy},$$count);
                   10847:                     $parent->{$$depth} = $$count;
1.1055    raeburn  10848:                     $result .=
                   10849:                         &recurse_extracted_archive("$currdir/$item",$docudom,
                   10850:                                                    $docuname,$depth,$count,
1.1056    raeburn  10851:                                                    $hierarchy,$dirorder,$children,
                   10852:                                                    $parent,$titles,$wantform);
1.1055    raeburn  10853:                     $$depth --;
1.1056    raeburn  10854:                     pop(@{$hierarchy});
1.1055    raeburn  10855:                 }
                   10856:             }
                   10857:         }
                   10858:     }
                   10859:     return $result;
                   10860: }
                   10861: 
                   10862: sub archive_hierarchy {
                   10863:     my ($depth,$count,$parent,$children) =@_;
                   10864:     if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
                   10865:         if (exists($parent->{$depth})) {
                   10866:              $children->{$parent->{$depth}} .= $count.':';
                   10867:         }
                   10868:     }
                   10869:     return;
                   10870: }
                   10871: 
                   10872: sub archive_row {
                   10873:     my ($is_dir,$item,$currdir,$depth,$count) = @_;
                   10874:     my ($name) = ($item =~ m{([^/]+)$});
                   10875:     my %choices = &Apache::lonlocal::texthash (
1.1059    raeburn  10876:                                        'display'    => 'Add as file',
1.1055    raeburn  10877:                                        'dependency' => 'Include as dependency',
                   10878:                                        'discard'    => 'Discard',
                   10879:                                       );
                   10880:     if ($is_dir) {
1.1059    raeburn  10881:         $choices{'display'} = &mt('Add as folder'); 
1.1055    raeburn  10882:     }
1.1056    raeburn  10883:     my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
                   10884:     my $offset = 0;
1.1055    raeburn  10885:     foreach my $action ('display','dependency','discard') {
1.1056    raeburn  10886:         $offset ++;
1.1065    raeburn  10887:         if ($action ne 'display') {
                   10888:             $offset ++;
                   10889:         }  
1.1055    raeburn  10890:         $output .= '<td><span class="LC_nobreak">'.
                   10891:                    '<label><input type="radio" name="archive_'.$count.
                   10892:                    '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
                   10893:         my $text = $choices{$action};
                   10894:         if ($is_dir) {
                   10895:             $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
                   10896:             if ($action eq 'display') {
1.1059    raeburn  10897:                 $text = &mt('Add as folder');
1.1055    raeburn  10898:             }
1.1056    raeburn  10899:         } else {
                   10900:             $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
                   10901: 
                   10902:         }
                   10903:         $output .= ' />&nbsp;'.$choices{$action}.'</label></span>';
                   10904:         if ($action eq 'dependency') {
                   10905:             $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
                   10906:                        &mt('Used by:').'&nbsp;<select name="archive_dependent_on_'.$count.'" '.
                   10907:                        'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
                   10908:                        '<option value=""></option>'."\n".
                   10909:                        '</select>'."\n".
                   10910:                        '</div>';
1.1059    raeburn  10911:         } elsif ($action eq 'display') {
                   10912:             $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
                   10913:                        &mt('Title:').'&nbsp;<input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
                   10914:                        '</div>';
1.1055    raeburn  10915:         }
1.1056    raeburn  10916:         $output .= '</td>';
1.1055    raeburn  10917:     }
                   10918:     $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
                   10919:                &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.('&nbsp;' x 2);
                   10920:     for (my $i=0; $i<$depth; $i++) {
                   10921:         $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
                   10922:     }
                   10923:     if ($is_dir) {
                   10924:         $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" />&nbsp;'."\n".
                   10925:                    '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
                   10926:     } else {
                   10927:         $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
                   10928:     }
                   10929:     $output .= '&nbsp;'.$name.'</td>'."\n".
                   10930:                &end_data_table_row();
                   10931:     return $output;
                   10932: }
                   10933: 
                   10934: sub archive_options_form {
1.1065    raeburn  10935:     my ($form,$display,$count,$hiddenelem) = @_;
                   10936:     my %lt = &Apache::lonlocal::texthash(
                   10937:                perm => 'Permanently remove archive file?',
                   10938:                hows => 'How should each extracted item be incorporated in the course?',
                   10939:                cont => 'Content actions for all',
                   10940:                addf => 'Add as folder/file',
                   10941:                incd => 'Include as dependency for a displayed file',
                   10942:                disc => 'Discard',
                   10943:                no   => 'No',
                   10944:                yes  => 'Yes',
                   10945:                save => 'Save',
                   10946:     );
                   10947:     my $output = <<"END";
                   10948: <form name="$form" method="post" action="">
                   10949: <p><span class="LC_nobreak">$lt{'perm'}&nbsp;
                   10950: <label>
                   10951:   <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
                   10952: </label>
                   10953: &nbsp;
                   10954: <label>
                   10955:   <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
                   10956: </span>
                   10957: </p>
                   10958: <input type="hidden" name="phase" value="decompress_cleanup" />
                   10959: <br />$lt{'hows'}
                   10960: <div class="LC_columnSection">
                   10961:   <fieldset>
                   10962:     <legend>$lt{'cont'}</legend>
                   10963:     <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" /> 
                   10964:     &nbsp;&nbsp;<input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
                   10965:     &nbsp;&nbsp;<input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
                   10966:   </fieldset>
                   10967: </div>
                   10968: END
                   10969:     return $output.
1.1055    raeburn  10970:            &start_data_table()."\n".
1.1065    raeburn  10971:            $display."\n".
1.1055    raeburn  10972:            &end_data_table()."\n".
                   10973:            '<input type="hidden" name="archive_count" value="'.$count.'" />'.
                   10974:            $hiddenelem.
1.1065    raeburn  10975:            '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055    raeburn  10976:            '</form>';
                   10977: }
                   10978: 
                   10979: sub archive_javascript {
1.1056    raeburn  10980:     my ($startcount,$numitems,$titles,$children) = @_;
                   10981:     return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059    raeburn  10982:     my $maintitle = $env{'form.comment'};
1.1055    raeburn  10983:     my $scripttag = <<START;
                   10984: <script type="text/javascript">
                   10985: // <![CDATA[
                   10986: 
                   10987: function checkAll(form,prefix) {
                   10988:     var idstr =  new RegExp("^archive_"+prefix+"_\\\\d+\$");
                   10989:     for (var i=0; i < form.elements.length; i++) {
                   10990:         var id = form.elements[i].id;
                   10991:         if ((id != '') && (id != undefined)) {
                   10992:             if (idstr.test(id)) {
                   10993:                 if (form.elements[i].type == 'radio') {
                   10994:                     form.elements[i].checked = true;
1.1056    raeburn  10995:                     var nostart = i-$startcount;
1.1059    raeburn  10996:                     var offset = nostart%7;
                   10997:                     var count = (nostart-offset)/7;    
1.1056    raeburn  10998:                     dependencyCheck(form,count,offset);
1.1055    raeburn  10999:                 }
                   11000:             }
                   11001:         }
                   11002:     }
                   11003: }
                   11004: 
                   11005: function propagateCheck(form,count) {
                   11006:     if (count > 0) {
1.1059    raeburn  11007:         var startelement = $startcount + ((count-1) * 7);
                   11008:         for (var j=1; j<6; j++) {
                   11009:             if ((j != 2) && (j != 4)) {
1.1056    raeburn  11010:                 var item = startelement + j; 
                   11011:                 if (form.elements[item].type == 'radio') {
                   11012:                     if (form.elements[item].checked) {
                   11013:                         containerCheck(form,count,j);
                   11014:                         break;
                   11015:                     }
1.1055    raeburn  11016:                 }
                   11017:             }
                   11018:         }
                   11019:     }
                   11020: }
                   11021: 
                   11022: numitems = $numitems
1.1056    raeburn  11023: var titles = new Array(numitems);
                   11024: var parents = new Array(numitems);
1.1055    raeburn  11025: for (var i=0; i<numitems; i++) {
1.1056    raeburn  11026:     parents[i] = new Array;
1.1055    raeburn  11027: }
1.1059    raeburn  11028: var maintitle = '$maintitle';
1.1055    raeburn  11029: 
                   11030: START
                   11031: 
1.1056    raeburn  11032:     foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
                   11033:         my @contents = split(/:/,$children->{$container});
1.1055    raeburn  11034:         for (my $i=0; $i<@contents; $i ++) {
                   11035:             $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
                   11036:         }
                   11037:     }
                   11038: 
1.1056    raeburn  11039:     foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
                   11040:         $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
                   11041:     }
                   11042: 
1.1055    raeburn  11043:     $scripttag .= <<END;
                   11044: 
                   11045: function containerCheck(form,count,offset) {
                   11046:     if (count > 0) {
1.1056    raeburn  11047:         dependencyCheck(form,count,offset);
1.1059    raeburn  11048:         var item = (offset+$startcount)+7*(count-1);
1.1055    raeburn  11049:         form.elements[item].checked = true;
                   11050:         if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
                   11051:             if (parents[count].length > 0) {
                   11052:                 for (var j=0; j<parents[count].length; j++) {
1.1056    raeburn  11053:                     containerCheck(form,parents[count][j],offset);
                   11054:                 }
                   11055:             }
                   11056:         }
                   11057:     }
                   11058: }
                   11059: 
                   11060: function dependencyCheck(form,count,offset) {
                   11061:     if (count > 0) {
1.1059    raeburn  11062:         var chosen = (offset+$startcount)+7*(count-1);
                   11063:         var depitem = $startcount + ((count-1) * 7) + 4;
1.1056    raeburn  11064:         var currtype = form.elements[depitem].type;
                   11065:         if (form.elements[chosen].value == 'dependency') {
                   11066:             document.getElementById('arc_depon_'+count).style.display='block'; 
                   11067:             form.elements[depitem].options.length = 0;
                   11068:             form.elements[depitem].options[0] = new Option('Select','',true,true);
                   11069:             for (var i=1; i<count; i++) {
1.1059    raeburn  11070:                 var startelement = $startcount + (i-1) * 7;
                   11071:                 for (var j=1; j<6; j++) {
                   11072:                     if ((j != 2) && (j!= 4)) {
1.1056    raeburn  11073:                         var item = startelement + j;
                   11074:                         if (form.elements[item].type == 'radio') {
                   11075:                             if (form.elements[item].checked) {
                   11076:                                 if (form.elements[item].value == 'display') {
                   11077:                                     var n = form.elements[depitem].options.length;
                   11078:                                     form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
                   11079:                                 }
                   11080:                             }
                   11081:                         }
                   11082:                     }
                   11083:                 }
                   11084:             }
                   11085:         } else {
                   11086:             document.getElementById('arc_depon_'+count).style.display='none';
                   11087:             form.elements[depitem].options.length = 0;
                   11088:             form.elements[depitem].options[0] = new Option('Select','',true,true);
                   11089:         }
1.1059    raeburn  11090:         titleCheck(form,count,offset);
1.1056    raeburn  11091:     }
                   11092: }
                   11093: 
                   11094: function propagateSelect(form,count,offset) {
                   11095:     if (count > 0) {
1.1065    raeburn  11096:         var item = (1+offset+$startcount)+7*(count-1);
1.1056    raeburn  11097:         var picked = form.elements[item].options[form.elements[item].selectedIndex].value; 
                   11098:         if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
                   11099:             if (parents[count].length > 0) {
                   11100:                 for (var j=0; j<parents[count].length; j++) {
                   11101:                     containerSelect(form,parents[count][j],offset,picked);
1.1055    raeburn  11102:                 }
                   11103:             }
                   11104:         }
                   11105:     }
                   11106: }
1.1056    raeburn  11107: 
                   11108: function containerSelect(form,count,offset,picked) {
                   11109:     if (count > 0) {
1.1065    raeburn  11110:         var item = (offset+$startcount)+7*(count-1);
1.1056    raeburn  11111:         if (form.elements[item].type == 'radio') {
                   11112:             if (form.elements[item].value == 'dependency') {
                   11113:                 if (form.elements[item+1].type == 'select-one') {
                   11114:                     for (var i=0; i<form.elements[item+1].options.length; i++) {
                   11115:                         if (form.elements[item+1].options[i].value == picked) {
                   11116:                             form.elements[item+1].selectedIndex = i;
                   11117:                             break;
                   11118:                         }
                   11119:                     }
                   11120:                 }
                   11121:                 if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
                   11122:                     if (parents[count].length > 0) {
                   11123:                         for (var j=0; j<parents[count].length; j++) {
                   11124:                             containerSelect(form,parents[count][j],offset,picked);
                   11125:                         }
                   11126:                     }
                   11127:                 }
                   11128:             }
                   11129:         }
                   11130:     }
                   11131: }
                   11132: 
1.1059    raeburn  11133: function titleCheck(form,count,offset) {
                   11134:     if (count > 0) {
                   11135:         var chosen = (offset+$startcount)+7*(count-1);
                   11136:         var depitem = $startcount + ((count-1) * 7) + 2;
                   11137:         var currtype = form.elements[depitem].type;
                   11138:         if (form.elements[chosen].value == 'display') {
                   11139:             document.getElementById('arc_title_'+count).style.display='block';
                   11140:             if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
                   11141:                 document.getElementById('archive_title_'+count).value=maintitle;
                   11142:             }
                   11143:         } else {
                   11144:             document.getElementById('arc_title_'+count).style.display='none';
                   11145:             if (currtype == 'text') { 
                   11146:                 document.getElementById('archive_title_'+count).value='';
                   11147:             }
                   11148:         }
                   11149:     }
                   11150:     return;
                   11151: }
                   11152: 
1.1055    raeburn  11153: // ]]>
                   11154: </script>
                   11155: END
                   11156:     return $scripttag;
                   11157: }
                   11158: 
                   11159: sub process_extracted_files {
1.1067    raeburn  11160:     my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055    raeburn  11161:     my $numitems = $env{'form.archive_count'};
                   11162:     return unless ($numitems);
                   11163:     my @ids=&Apache::lonnet::current_machine_ids();
                   11164:     my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067    raeburn  11165:         %folders,%containers,%mapinner,%prompttofetch);
1.1055    raeburn  11166:     my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
                   11167:     if (grep(/^\Q$docuhome\E$/,@ids)) {
                   11168:         $prefix = &LONCAPA::propath($docudom,$docuname);
                   11169:         $pathtocheck = "$dir_root/$destination";
                   11170:         $dir = $dir_root;
                   11171:         $ishome = 1;
                   11172:     } else {
                   11173:         $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
                   11174:         $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
                   11175:         $dir = "$dir_root/$docudom/$docuname";    
                   11176:     }
                   11177:     my $currdir = "$dir_root/$destination";
                   11178:     (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
                   11179:     if ($env{'form.folderpath'}) {
                   11180:         my @items = split('&',$env{'form.folderpath'});
                   11181:         $folders{'0'} = $items[-2];
                   11182:         $containers{'0'}='sequence';
                   11183:     } elsif ($env{'form.pagepath'}) {
                   11184:         my @items = split('&',$env{'form.pagepath'});
                   11185:         $folders{'0'} = $items[-2];
                   11186:         $containers{'0'}='page';
                   11187:     }
                   11188:     my @archdirs = &get_env_multiple('form.archive_directory');
                   11189:     if ($numitems) {
                   11190:         for (my $i=1; $i<=$numitems; $i++) {
                   11191:             my $path = $env{'form.archive_content_'.$i};
                   11192:             if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
                   11193:                 my $item = $1;
                   11194:                 $toplevelitems{$item} = $i;
                   11195:                 if (grep(/^\Q$i\E$/,@archdirs)) {
                   11196:                     $is_dir{$item} = 1;
                   11197:                 }
                   11198:             }
                   11199:         }
                   11200:     }
1.1067    raeburn  11201:     my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055    raeburn  11202:     if (keys(%toplevelitems) > 0) {
                   11203:         my @contents = sort(keys(%toplevelitems));
1.1056    raeburn  11204:         (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
                   11205:                                            \%parent,\@contents,\%dirorder,\%titles);
1.1055    raeburn  11206:     }
1.1066    raeburn  11207:     my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055    raeburn  11208:     if ($numitems) {
                   11209:         for (my $i=1; $i<=$numitems; $i++) {
                   11210:             my $path = $env{'form.archive_content_'.$i};
                   11211:             if ($path =~ /^\Q$pathtocheck\E/) {
                   11212:                 if ($env{'form.archive_'.$i} eq 'discard') {
                   11213:                     if ($prefix ne '' && $path ne '') {
                   11214:                         if (-e $prefix.$path) {
1.1066    raeburn  11215:                             if ((@archdirs > 0) && 
                   11216:                                 (grep(/^\Q$i\E$/,@archdirs))) {
                   11217:                                 $todeletedir{$prefix.$path} = 1;
                   11218:                             } else {
                   11219:                                 $todelete{$prefix.$path} = 1;
                   11220:                             }
1.1055    raeburn  11221:                         }
                   11222:                     }
                   11223:                 } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059    raeburn  11224:                     my ($docstitle,$title,$url,$outer);
1.1055    raeburn  11225:                     ($title) = ($path =~ m{/([^/]+)$});
1.1059    raeburn  11226:                     $docstitle = $env{'form.archive_title_'.$i};
                   11227:                     if ($docstitle eq '') {
                   11228:                         $docstitle = $title;
                   11229:                     }
1.1055    raeburn  11230:                     $outer = 0;
1.1056    raeburn  11231:                     if (ref($dirorder{$i}) eq 'ARRAY') {
                   11232:                         if (@{$dirorder{$i}} > 0) {
                   11233:                             foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055    raeburn  11234:                                 if ($env{'form.archive_'.$item} eq 'display') {
                   11235:                                     $outer = $item;
                   11236:                                     last;
                   11237:                                 }
                   11238:                             }
                   11239:                         }
                   11240:                     }
                   11241:                     my ($errtext,$fatal) = 
                   11242:                         &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
                   11243:                                                '/'.$folders{$outer}.'.'.
                   11244:                                                $containers{$outer});
                   11245:                     next if ($fatal);
                   11246:                     if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
                   11247:                         if ($context eq 'coursedocs') {
1.1056    raeburn  11248:                             $mapinner{$i} = time;
1.1055    raeburn  11249:                             $folders{$i} = 'default_'.$mapinner{$i};
                   11250:                             $containers{$i} = 'sequence';
                   11251:                             my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
                   11252:                                       $folders{$i}.'.'.$containers{$i};
                   11253:                             my $newidx = &LONCAPA::map::getresidx();
                   11254:                             $LONCAPA::map::resources[$newidx]=
1.1059    raeburn  11255:                                 $docstitle.':'.$url.':false:normal:res';
1.1055    raeburn  11256:                             push(@LONCAPA::map::order,$newidx);
                   11257:                             my ($outtext,$errtext) =
                   11258:                                 &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
                   11259:                                                         $docuname.'/'.$folders{$outer}.
                   11260:                                                         '.'.$containers{$outer},1);
1.1056    raeburn  11261:                             $newseqid{$i} = $newidx;
1.1067    raeburn  11262:                             unless ($errtext) {
                   11263:                                 $result .=  '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
                   11264:                             }
1.1055    raeburn  11265:                         }
                   11266:                     } else {
                   11267:                         if ($context eq 'coursedocs') {
                   11268:                             my $newidx=&LONCAPA::map::getresidx();
                   11269:                             my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
                   11270:                                       $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
                   11271:                                       $title;
                   11272:                             if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
                   11273:                                 mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
                   11274:                             }
                   11275:                             if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
                   11276:                                 mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
                   11277:                             }
                   11278:                             if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
                   11279:                                 system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056    raeburn  11280:                                 $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067    raeburn  11281:                                 unless ($ishome) {
                   11282:                                     my $fetch = "$newdest{$i}/$title";
                   11283:                                     $fetch =~ s/^\Q$prefix$dir\E//;
                   11284:                                     $prompttofetch{$fetch} = 1;
                   11285:                                 }
1.1055    raeburn  11286:                             }
                   11287:                             $LONCAPA::map::resources[$newidx]=
1.1059    raeburn  11288:                                 $docstitle.':'.$url.':false:normal:res';
1.1055    raeburn  11289:                             push(@LONCAPA::map::order, $newidx);
                   11290:                             my ($outtext,$errtext)=
                   11291:                                 &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
                   11292:                                                         $docuname.'/'.$folders{$outer}.
                   11293:                                                         '.'.$containers{$outer},1);
1.1067    raeburn  11294:                             unless ($errtext) {
                   11295:                                 if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
                   11296:                                     $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
                   11297:                                 }
                   11298:                             }
1.1055    raeburn  11299:                         }
                   11300:                     }
                   11301:                 } elsif ($env{'form.archive_'.$i} eq 'dependency') {
1.1056    raeburn  11302:                     my ($title) = ($path =~ m{/([^/]+)$});
                   11303:                     $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
                   11304:                     if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
                   11305:                         if (ref($dirorder{$i}) eq 'ARRAY') {
1.1067    raeburn  11306:                             my ($itemidx,$fullpath,$relpath);
1.1056    raeburn  11307:                             for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
                   11308:                                 if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
                   11309:                                     my $container = $dirorder{$referrer{$i}}->[-1];
                   11310:                                     for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
                   11311:                                         if ($dirorder{$i}->[$j] eq $container) {
                   11312:                                             $itemidx = $j;
                   11313:                                         }
                   11314:                                     }
                   11315:                                 }
                   11316:                             }
                   11317:                             if ($itemidx ne '') {
                   11318:                                 if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
                   11319:                                     if ($mapinner{$referrer{$i}}) {
                   11320:                                         $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
                   11321:                                         for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
                   11322:                                             if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
                   11323:                                                 unless (defined($newseqid{$dirorder{$i}->[$j]})) {
                   11324:                                                     $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
1.1067    raeburn  11325:                                                     $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
1.1056    raeburn  11326:                                                     if (!-e $fullpath) {
                   11327:                                                         mkdir($fullpath,0755);
                   11328:                                                     }
                   11329:                                                 }
                   11330:                                             } else {
                   11331:                                                 last;
                   11332:                                             }
                   11333:                                         }
                   11334:                                     }
                   11335:                                 } elsif ($newdest{$referrer{$i}}) {
                   11336:                                     $fullpath = $newdest{$referrer{$i}};
                   11337:                                     for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
                   11338:                                         if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
                   11339:                                             $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
                   11340:                                             last;
                   11341:                                         } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
                   11342:                                             unless (defined($newseqid{$dirorder{$i}->[$j]})) {
                   11343:                                                 $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
1.1067    raeburn  11344:                                                 $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
1.1056    raeburn  11345:                                                 if (!-e $fullpath) {
                   11346:                                                     mkdir($fullpath,0755);
                   11347:                                                 }
                   11348:                                             }
                   11349:                                         } else {
                   11350:                                             last;
                   11351:                                         }
                   11352:                                     }
                   11353:                                 }
                   11354:                                 if ($fullpath ne '') {
1.1067    raeburn  11355:                                     if (-e "$prefix$path") {
                   11356:                                         system("mv $prefix$path $fullpath/$title");
                   11357:                                     }
                   11358:                                     if (-e "$fullpath/$title") {
                   11359:                                         my $showpath;
                   11360:                                         if ($relpath ne '') {
                   11361:                                             $showpath = "$relpath/$title";
                   11362:                                         } else {
                   11363:                                             $showpath = "/$title";
                   11364:                                         } 
                   11365:                                         $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
                   11366:                                     } 
                   11367:                                     unless ($ishome) {
                   11368:                                         my $fetch = "$fullpath/$title";
                   11369:                                         $fetch =~ s/^\Q$prefix$dir\E//; 
                   11370:                                         $prompttofetch{$fetch} = 1;
                   11371:                                     }
1.1056    raeburn  11372:                                 }
1.1055    raeburn  11373:                             }
                   11374:                         }
1.1056    raeburn  11375:                     } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
                   11376:                         $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
                   11377:                                         $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055    raeburn  11378:                     }
                   11379:                 }
                   11380:             } else {
                   11381:                 $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />'; 
                   11382:             }
                   11383:         }
                   11384:         if (keys(%todelete)) {
                   11385:             foreach my $key (keys(%todelete)) {
                   11386:                 unlink($key);
1.1066    raeburn  11387:             }
                   11388:         }
                   11389:         if (keys(%todeletedir)) {
                   11390:             foreach my $key (keys(%todeletedir)) {
                   11391:                 rmdir($key);
                   11392:             }
                   11393:         }
                   11394:         foreach my $dir (sort(keys(%is_dir))) {
                   11395:             if (($pathtocheck ne '') && ($dir ne ''))  {
                   11396:                 &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055    raeburn  11397:             }
                   11398:         }
1.1067    raeburn  11399:         if ($result ne '') {
                   11400:             $output .= '<ul>'."\n".
                   11401:                        $result."\n".
                   11402:                        '</ul>';
                   11403:         }
                   11404:         unless ($ishome) {
                   11405:             my $replicationfail;
                   11406:             foreach my $item (keys(%prompttofetch)) {
                   11407:                 my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
                   11408:                 unless ($fetchresult eq 'ok') {
                   11409:                     $replicationfail .= '<li>'.$item.'</li>'."\n";
                   11410:                 }
                   11411:             }
                   11412:             if ($replicationfail) {
                   11413:                 $output .= '<p class="LC_error">'.
                   11414:                            &mt('Course home server failed to retrieve:').'<ul>'.
                   11415:                            $replicationfail.
                   11416:                            '</ul></p>';
                   11417:             }
                   11418:         }
1.1055    raeburn  11419:     } else {
                   11420:         $warning = &mt('No items found in archive.');
                   11421:     }
                   11422:     if ($error) {
                   11423:         $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
                   11424:                    $error.'</p>'."\n";
                   11425:     }
                   11426:     if ($warning) {
                   11427:         $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
                   11428:     }
                   11429:     return $output;
                   11430: }
                   11431: 
1.1066    raeburn  11432: sub cleanup_empty_dirs {
                   11433:     my ($path) = @_;
                   11434:     if (($path ne '') && (-d $path)) {
                   11435:         if (opendir(my $dirh,$path)) {
                   11436:             my @dircontents = grep(!/^\./,readdir($dirh));
                   11437:             my $numitems = 0;
                   11438:             foreach my $item (@dircontents) {
                   11439:                 if (-d "$path/$item") {
                   11440:                     &recurse_dirs("$path/$item");
                   11441:                     if (-e "$path/$item") {
                   11442:                         $numitems ++;
                   11443:                     }
                   11444:                 } else {
                   11445:                     $numitems ++;
                   11446:                 }
                   11447:             }
                   11448:             if ($numitems == 0) {
                   11449:                 rmdir($path);
                   11450:             }
                   11451:             closedir($dirh);
                   11452:         }
                   11453:     }
                   11454:     return;
                   11455: }
                   11456: 
1.41      ng       11457: =pod
1.45      matthew  11458: 
1.1068    raeburn  11459: =item &get_folder_hierarchy()
                   11460: 
                   11461: Provides hierarchy of names of folders/sub-folders containing the current
                   11462: item,
                   11463: 
                   11464: Inputs: 3
                   11465:      - $navmap - navmaps object
                   11466: 
                   11467:      - $map - url for map (either the trigger itself, or map containing
                   11468:                            the resource, which is the trigger).
                   11469: 
                   11470:      - $showitem - 1 => show title for map itself; 0 => do not show.
                   11471: 
                   11472: Outputs: 1 @pathitems - array of folder/subfolder names.
                   11473: 
                   11474: =cut
                   11475: 
                   11476: sub get_folder_hierarchy {
                   11477:     my ($navmap,$map,$showitem) = @_;
                   11478:     my @pathitems;
                   11479:     if (ref($navmap)) {
                   11480:         my $mapres = $navmap->getResourceByUrl($map);
                   11481:         if (ref($mapres)) {
                   11482:             my $pcslist = $mapres->map_hierarchy();
                   11483:             if ($pcslist ne '') {
                   11484:                 my @pcs = split(/,/,$pcslist);
                   11485:                 foreach my $pc (@pcs) {
                   11486:                     if ($pc == 1) {
                   11487:                         push(@pathitems,&mt('Main Course Documents'));
                   11488:                     } else {
                   11489:                         my $res = $navmap->getByMapPc($pc);
                   11490:                         if (ref($res)) {
                   11491:                             my $title = $res->compTitle();
                   11492:                             $title =~ s/\W+/_/g;
                   11493:                             if ($title ne '') {
                   11494:                                 push(@pathitems,$title);
                   11495:                             }
                   11496:                         }
                   11497:                     }
                   11498:                 }
                   11499:             }
1.1071    raeburn  11500:             if ($showitem) {
                   11501:                 if ($mapres->{ID} eq '0.0') {
                   11502:                     push(@pathitems,&mt('Main Course Documents'));
                   11503:                 } else {
                   11504:                     my $maptitle = $mapres->compTitle();
                   11505:                     $maptitle =~ s/\W+/_/g;
                   11506:                     if ($maptitle ne '') {
                   11507:                         push(@pathitems,$maptitle);
                   11508:                     }
1.1068    raeburn  11509:                 }
                   11510:             }
                   11511:         }
                   11512:     }
                   11513:     return @pathitems;
                   11514: }
                   11515: 
                   11516: =pod
                   11517: 
1.1015    raeburn  11518: =item * &get_turnedin_filepath()
                   11519: 
                   11520: Determines path in a user's portfolio file for storage of files uploaded
                   11521: to a specific essayresponse or dropbox item.
                   11522: 
                   11523: Inputs: 3 required + 1 optional.
                   11524: $symb is symb for resource, $uname and $udom are for current user (required).
                   11525: $caller is optional (can be "submission", if routine is called when storing
                   11526: an upoaded file when "Submit Answer" button was pressed).
                   11527: 
                   11528: Returns array containing $path and $multiresp. 
                   11529: $path is path in portfolio.  $multiresp is 1 if this resource contains more
                   11530: than one file upload item.  Callers of routine should append partid as a 
                   11531: subdirectory to $path in cases where $multiresp is 1.
                   11532: 
                   11533: Called by: homework/essayresponse.pm and homework/structuretags.pm
                   11534: 
                   11535: =cut
                   11536: 
                   11537: sub get_turnedin_filepath {
                   11538:     my ($symb,$uname,$udom,$caller) = @_;
                   11539:     my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
                   11540:     my $turnindir;
                   11541:     my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
                   11542:     $turnindir = $userhash{'turnindir'};
                   11543:     my ($path,$multiresp);
                   11544:     if ($turnindir eq '') {
                   11545:         if ($caller eq 'submission') {
                   11546:             $turnindir = &mt('turned in');
                   11547:             $turnindir =~ s/\W+/_/g;
                   11548:             my %newhash = (
                   11549:                             'turnindir' => $turnindir,
                   11550:                           );
                   11551:             &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
                   11552:         }
                   11553:     }
                   11554:     if ($turnindir ne '') {
                   11555:         $path = '/'.$turnindir.'/';
                   11556:         my ($multipart,$turnin,@pathitems);
                   11557:         my $navmap = Apache::lonnavmaps::navmap->new();
                   11558:         if (defined($navmap)) {
                   11559:             my $mapres = $navmap->getResourceByUrl($map);
                   11560:             if (ref($mapres)) {
                   11561:                 my $pcslist = $mapres->map_hierarchy();
                   11562:                 if ($pcslist ne '') {
                   11563:                     foreach my $pc (split(/,/,$pcslist)) {
                   11564:                         my $res = $navmap->getByMapPc($pc);
                   11565:                         if (ref($res)) {
                   11566:                             my $title = $res->compTitle();
                   11567:                             $title =~ s/\W+/_/g;
                   11568:                             if ($title ne '') {
                   11569:                                 push(@pathitems,$title);
                   11570:                             }
                   11571:                         }
                   11572:                     }
                   11573:                 }
                   11574:                 my $maptitle = $mapres->compTitle();
                   11575:                 $maptitle =~ s/\W+/_/g;
                   11576:                 if ($maptitle ne '') {
                   11577:                     push(@pathitems,$maptitle);
                   11578:                 }
                   11579:                 unless ($env{'request.state'} eq 'construct') {
                   11580:                     my $res = $navmap->getBySymb($symb);
                   11581:                     if (ref($res)) {
                   11582:                         my $partlist = $res->parts();
                   11583:                         my $totaluploads = 0;
                   11584:                         if (ref($partlist) eq 'ARRAY') {
                   11585:                             foreach my $part (@{$partlist}) {
                   11586:                                 my @types = $res->responseType($part);
                   11587:                                 my @ids = $res->responseIds($part);
                   11588:                                 for (my $i=0; $i < scalar(@ids); $i++) {
                   11589:                                     if ($types[$i] eq 'essay') {
                   11590:                                         my $partid = $part.'_'.$ids[$i];
                   11591:                                         if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
                   11592:                                             $totaluploads ++;
                   11593:                                         }
                   11594:                                     }
                   11595:                                 }
                   11596:                             }
                   11597:                             if ($totaluploads > 1) {
                   11598:                                 $multiresp = 1;
                   11599:                             }
                   11600:                         }
                   11601:                     }
                   11602:                 }
                   11603:             } else {
                   11604:                 return;
                   11605:             }
                   11606:         } else {
                   11607:             return;
                   11608:         }
                   11609:         my $restitle=&Apache::lonnet::gettitle($symb);
                   11610:         $restitle =~ s/\W+/_/g;
                   11611:         if ($restitle eq '') {
                   11612:             $restitle = ($resurl =~ m{/[^/]+$});
                   11613:             if ($restitle eq '') {
                   11614:                 $restitle = time;
                   11615:             }
                   11616:         }
                   11617:         push(@pathitems,$restitle);
                   11618:         $path .= join('/',@pathitems);
                   11619:     }
                   11620:     return ($path,$multiresp);
                   11621: }
                   11622: 
                   11623: =pod
                   11624: 
1.464     albertel 11625: =back
1.41      ng       11626: 
1.112     bowersj2 11627: =head1 CSV Upload/Handling functions
1.38      albertel 11628: 
1.41      ng       11629: =over 4
                   11630: 
1.648     raeburn  11631: =item * &upfile_store($r)
1.41      ng       11632: 
                   11633: Store uploaded file, $r should be the HTTP Request object,
1.258     albertel 11634: needs $env{'form.upfile'}
1.41      ng       11635: returns $datatoken to be put into hidden field
                   11636: 
                   11637: =cut
1.31      albertel 11638: 
                   11639: sub upfile_store {
                   11640:     my $r=shift;
1.258     albertel 11641:     $env{'form.upfile'}=~s/\r/\n/gs;
                   11642:     $env{'form.upfile'}=~s/\f/\n/gs;
                   11643:     $env{'form.upfile'}=~s/\n+/\n/gs;
                   11644:     $env{'form.upfile'}=~s/\n+$//gs;
1.31      albertel 11645: 
1.258     albertel 11646:     my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
                   11647: 	'_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31      albertel 11648:     {
1.158     raeburn  11649:         my $datafile = $r->dir_config('lonDaemons').
                   11650:                            '/tmp/'.$datatoken.'.tmp';
                   11651:         if ( open(my $fh,">$datafile") ) {
1.258     albertel 11652:             print $fh $env{'form.upfile'};
1.158     raeburn  11653:             close($fh);
                   11654:         }
1.31      albertel 11655:     }
                   11656:     return $datatoken;
                   11657: }
                   11658: 
1.56      matthew  11659: =pod
                   11660: 
1.648     raeburn  11661: =item * &load_tmp_file($r)
1.41      ng       11662: 
                   11663: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258     albertel 11664: needs $env{'form.datatoken'},
                   11665: sets $env{'form.upfile'} to the contents of the file
1.41      ng       11666: 
                   11667: =cut
1.31      albertel 11668: 
                   11669: sub load_tmp_file {
                   11670:     my $r=shift;
                   11671:     my @studentdata=();
                   11672:     {
1.158     raeburn  11673:         my $studentfile = $r->dir_config('lonDaemons').
1.258     albertel 11674:                               '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158     raeburn  11675:         if ( open(my $fh,"<$studentfile") ) {
                   11676:             @studentdata=<$fh>;
                   11677:             close($fh);
                   11678:         }
1.31      albertel 11679:     }
1.258     albertel 11680:     $env{'form.upfile'}=join('',@studentdata);
1.31      albertel 11681: }
                   11682: 
1.56      matthew  11683: =pod
                   11684: 
1.648     raeburn  11685: =item * &upfile_record_sep()
1.41      ng       11686: 
                   11687: Separate uploaded file into records
                   11688: returns array of records,
1.258     albertel 11689: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41      ng       11690: 
                   11691: =cut
1.31      albertel 11692: 
                   11693: sub upfile_record_sep {
1.258     albertel 11694:     if ($env{'form.upfiletype'} eq 'xml') {
1.31      albertel 11695:     } else {
1.248     albertel 11696: 	my @records;
1.258     albertel 11697: 	foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248     albertel 11698: 	    if ($line=~/^\s*$/) { next; }
                   11699: 	    push(@records,$line);
                   11700: 	}
                   11701: 	return @records;
1.31      albertel 11702:     }
                   11703: }
                   11704: 
1.56      matthew  11705: =pod
                   11706: 
1.648     raeburn  11707: =item * &record_sep($record)
1.41      ng       11708: 
1.258     albertel 11709: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41      ng       11710: 
                   11711: =cut
                   11712: 
1.263     www      11713: sub takeleft {
                   11714:     my $index=shift;
                   11715:     return substr('0000'.$index,-4,4);
                   11716: }
                   11717: 
1.31      albertel 11718: sub record_sep {
                   11719:     my $record=shift;
                   11720:     my %components=();
1.258     albertel 11721:     if ($env{'form.upfiletype'} eq 'xml') {
                   11722:     } elsif ($env{'form.upfiletype'} eq 'space') {
1.31      albertel 11723:         my $i=0;
1.356     albertel 11724:         foreach my $field (split(/\s+/,$record)) {
1.31      albertel 11725:             $field=~s/^(\"|\')//;
                   11726:             $field=~s/(\"|\')$//;
1.263     www      11727:             $components{&takeleft($i)}=$field;
1.31      albertel 11728:             $i++;
                   11729:         }
1.258     albertel 11730:     } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31      albertel 11731:         my $i=0;
1.356     albertel 11732:         foreach my $field (split(/\t/,$record)) {
1.31      albertel 11733:             $field=~s/^(\"|\')//;
                   11734:             $field=~s/(\"|\')$//;
1.263     www      11735:             $components{&takeleft($i)}=$field;
1.31      albertel 11736:             $i++;
                   11737:         }
                   11738:     } else {
1.561     www      11739:         my $separator=',';
1.480     banghart 11740:         if ($env{'form.upfiletype'} eq 'semisv') {
1.561     www      11741:             $separator=';';
1.480     banghart 11742:         }
1.31      albertel 11743:         my $i=0;
1.561     www      11744: # the character we are looking for to indicate the end of a quote or a record 
                   11745:         my $looking_for=$separator;
                   11746: # do not add the characters to the fields
                   11747:         my $ignore=0;
                   11748: # we just encountered a separator (or the beginning of the record)
                   11749:         my $just_found_separator=1;
                   11750: # store the field we are working on here
                   11751:         my $field='';
                   11752: # work our way through all characters in record
                   11753:         foreach my $character ($record=~/(.)/g) {
                   11754:             if ($character eq $looking_for) {
                   11755:                if ($character ne $separator) {
                   11756: # Found the end of a quote, again looking for separator
                   11757:                   $looking_for=$separator;
                   11758:                   $ignore=1;
                   11759:                } else {
                   11760: # Found a separator, store away what we got
                   11761:                   $components{&takeleft($i)}=$field;
                   11762: 	          $i++;
                   11763:                   $just_found_separator=1;
                   11764:                   $ignore=0;
                   11765:                   $field='';
                   11766:                }
                   11767:                next;
                   11768:             }
                   11769: # single or double quotation marks after a separator indicate beginning of a quote
                   11770: # we are now looking for the end of the quote and need to ignore separators
                   11771:             if ((($character eq '"') || ($character eq "'")) && ($just_found_separator))  {
                   11772:                $looking_for=$character;
                   11773:                next;
                   11774:             }
                   11775: # ignore would be true after we reached the end of a quote
                   11776:             if ($ignore) { next; }
                   11777:             if (($just_found_separator) && ($character=~/\s/)) { next; }
                   11778:             $field.=$character;
                   11779:             $just_found_separator=0; 
1.31      albertel 11780:         }
1.561     www      11781: # catch the very last entry, since we never encountered the separator
                   11782:         $components{&takeleft($i)}=$field;
1.31      albertel 11783:     }
                   11784:     return %components;
                   11785: }
                   11786: 
1.144     matthew  11787: ######################################################
                   11788: ######################################################
                   11789: 
1.56      matthew  11790: =pod
                   11791: 
1.648     raeburn  11792: =item * &upfile_select_html()
1.41      ng       11793: 
1.144     matthew  11794: Return HTML code to select a file from the users machine and specify 
                   11795: the file type.
1.41      ng       11796: 
                   11797: =cut
                   11798: 
1.144     matthew  11799: ######################################################
                   11800: ######################################################
1.31      albertel 11801: sub upfile_select_html {
1.144     matthew  11802:     my %Types = (
                   11803:                  csv   => &mt('CSV (comma separated values, spreadsheet)'),
1.480     banghart 11804:                  semisv => &mt('Semicolon separated values'),
1.144     matthew  11805:                  space => &mt('Space separated'),
                   11806:                  tab   => &mt('Tabulator separated'),
                   11807: #                 xml   => &mt('HTML/XML'),
                   11808:                  );
                   11809:     my $Str = '<input type="file" name="upfile" size="50" />'.
1.727     riegler  11810:         '<br />'.&mt('Type').': <select name="upfiletype">';
1.144     matthew  11811:     foreach my $type (sort(keys(%Types))) {
                   11812:         $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
                   11813:     }
                   11814:     $Str .= "</select>\n";
                   11815:     return $Str;
1.31      albertel 11816: }
                   11817: 
1.301     albertel 11818: sub get_samples {
                   11819:     my ($records,$toget) = @_;
                   11820:     my @samples=({});
                   11821:     my $got=0;
                   11822:     foreach my $rec (@$records) {
                   11823: 	my %temp = &record_sep($rec);
                   11824: 	if (! grep(/\S/, values(%temp))) { next; }
                   11825: 	if (%temp) {
                   11826: 	    $samples[$got]=\%temp;
                   11827: 	    $got++;
                   11828: 	    if ($got == $toget) { last; }
                   11829: 	}
                   11830:     }
                   11831:     return \@samples;
                   11832: }
                   11833: 
1.144     matthew  11834: ######################################################
                   11835: ######################################################
                   11836: 
1.56      matthew  11837: =pod
                   11838: 
1.648     raeburn  11839: =item * &csv_print_samples($r,$records)
1.41      ng       11840: 
                   11841: Prints a table of sample values from each column uploaded $r is an
                   11842: Apache Request ref, $records is an arrayref from
                   11843: &Apache::loncommon::upfile_record_sep
                   11844: 
                   11845: =cut
                   11846: 
1.144     matthew  11847: ######################################################
                   11848: ######################################################
1.31      albertel 11849: sub csv_print_samples {
                   11850:     my ($r,$records) = @_;
1.662     bisitz   11851:     my $samples = &get_samples($records,5);
1.301     albertel 11852: 
1.594     raeburn  11853:     $r->print(&mt('Samples').'<br />'.&start_data_table().
                   11854:               &start_data_table_header_row());
1.356     albertel 11855:     foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) { 
1.845     bisitz   11856:         $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594     raeburn  11857:     $r->print(&end_data_table_header_row());
1.301     albertel 11858:     foreach my $hash (@$samples) {
1.594     raeburn  11859: 	$r->print(&start_data_table_row());
1.356     albertel 11860: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31      albertel 11861: 	    $r->print('<td>');
1.356     albertel 11862: 	    if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31      albertel 11863: 	    $r->print('</td>');
                   11864: 	}
1.594     raeburn  11865: 	$r->print(&end_data_table_row());
1.31      albertel 11866:     }
1.594     raeburn  11867:     $r->print(&end_data_table().'<br />'."\n");
1.31      albertel 11868: }
                   11869: 
1.144     matthew  11870: ######################################################
                   11871: ######################################################
                   11872: 
1.56      matthew  11873: =pod
                   11874: 
1.648     raeburn  11875: =item * &csv_print_select_table($r,$records,$d)
1.41      ng       11876: 
                   11877: Prints a table to create associations between values and table columns.
1.144     matthew  11878: 
1.41      ng       11879: $r is an Apache Request ref,
                   11880: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174     matthew  11881: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41      ng       11882: 
                   11883: =cut
                   11884: 
1.144     matthew  11885: ######################################################
                   11886: ######################################################
1.31      albertel 11887: sub csv_print_select_table {
                   11888:     my ($r,$records,$d) = @_;
1.301     albertel 11889:     my $i=0;
                   11890:     my $samples = &get_samples($records,1);
1.144     matthew  11891:     $r->print(&mt('Associate columns with student attributes.')."\n".
1.594     raeburn  11892: 	      &start_data_table().&start_data_table_header_row().
1.144     matthew  11893:               '<th>'.&mt('Attribute').'</th>'.
1.594     raeburn  11894:               '<th>'.&mt('Column').'</th>'.
                   11895:               &end_data_table_header_row()."\n");
1.356     albertel 11896:     foreach my $array_ref (@$d) {
                   11897: 	my ($value,$display,$defaultcol)=@{ $array_ref };
1.729     raeburn  11898: 	$r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31      albertel 11899: 
1.875     bisitz   11900: 	$r->print('<td><select name="f'.$i.'"'.
1.32      matthew  11901: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.31      albertel 11902: 	$r->print('<option value="none"></option>');
1.356     albertel 11903: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
                   11904: 	    $r->print('<option value="'.$sample.'"'.
                   11905:                       ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662     bisitz   11906:                       '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31      albertel 11907: 	}
1.594     raeburn  11908: 	$r->print('</select></td>'.&end_data_table_row()."\n");
1.31      albertel 11909: 	$i++;
                   11910:     }
1.594     raeburn  11911:     $r->print(&end_data_table());
1.31      albertel 11912:     $i--;
                   11913:     return $i;
                   11914: }
1.56      matthew  11915: 
1.144     matthew  11916: ######################################################
                   11917: ######################################################
                   11918: 
1.56      matthew  11919: =pod
1.31      albertel 11920: 
1.648     raeburn  11921: =item * &csv_samples_select_table($r,$records,$d)
1.41      ng       11922: 
                   11923: Prints a table of sample values from the upload and can make associate samples to internal names.
                   11924: 
                   11925: $r is an Apache Request ref,
                   11926: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
                   11927: $d is an array of 2 element arrays (internal name, displayed name)
                   11928: 
                   11929: =cut
                   11930: 
1.144     matthew  11931: ######################################################
                   11932: ######################################################
1.31      albertel 11933: sub csv_samples_select_table {
                   11934:     my ($r,$records,$d) = @_;
                   11935:     my $i=0;
1.144     matthew  11936:     #
1.662     bisitz   11937:     my $max_samples = 5;
                   11938:     my $samples = &get_samples($records,$max_samples);
1.594     raeburn  11939:     $r->print(&start_data_table().
                   11940:               &start_data_table_header_row().'<th>'.
                   11941:               &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
                   11942:               &end_data_table_header_row());
1.301     albertel 11943: 
                   11944:     foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594     raeburn  11945: 	$r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32      matthew  11946: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.301     albertel 11947: 	foreach my $option (@$d) {
                   11948: 	    my ($value,$display,$defaultcol)=@{ $option };
1.174     matthew  11949: 	    $r->print('<option value="'.$value.'"'.
1.253     albertel 11950:                       ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174     matthew  11951:                       $display.'</option>');
1.31      albertel 11952: 	}
                   11953: 	$r->print('</select></td><td>');
1.662     bisitz   11954: 	foreach my $line (0..($max_samples-1)) {
1.301     albertel 11955: 	    if (defined($samples->[$line]{$key})) { 
                   11956: 		$r->print($samples->[$line]{$key}."<br />\n"); 
                   11957: 	    }
                   11958: 	}
1.594     raeburn  11959: 	$r->print('</td>'.&end_data_table_row());
1.31      albertel 11960: 	$i++;
                   11961:     }
1.594     raeburn  11962:     $r->print(&end_data_table());
1.31      albertel 11963:     $i--;
                   11964:     return($i);
1.115     matthew  11965: }
                   11966: 
1.144     matthew  11967: ######################################################
                   11968: ######################################################
                   11969: 
1.115     matthew  11970: =pod
                   11971: 
1.648     raeburn  11972: =item * &clean_excel_name($name)
1.115     matthew  11973: 
                   11974: Returns a replacement for $name which does not contain any illegal characters.
                   11975: 
                   11976: =cut
                   11977: 
1.144     matthew  11978: ######################################################
                   11979: ######################################################
1.115     matthew  11980: sub clean_excel_name {
                   11981:     my ($name) = @_;
                   11982:     $name =~ s/[:\*\?\/\\]//g;
                   11983:     if (length($name) > 31) {
                   11984:         $name = substr($name,0,31);
                   11985:     }
                   11986:     return $name;
1.25      albertel 11987: }
1.84      albertel 11988: 
1.85      albertel 11989: =pod
                   11990: 
1.648     raeburn  11991: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85      albertel 11992: 
                   11993: Returns either 1 or undef
                   11994: 
                   11995: 1 if the part is to be hidden, undef if it is to be shown
                   11996: 
                   11997: Arguments are:
                   11998: 
                   11999: $id the id of the part to be checked
                   12000: $symb, optional the symb of the resource to check
                   12001: $udom, optional the domain of the user to check for
                   12002: $uname, optional the username of the user to check for
                   12003: 
                   12004: =cut
1.84      albertel 12005: 
                   12006: sub check_if_partid_hidden {
                   12007:     my ($id,$symb,$udom,$uname) = @_;
1.133     albertel 12008:     my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84      albertel 12009: 					 $symb,$udom,$uname);
1.141     albertel 12010:     my $truth=1;
                   12011:     #if the string starts with !, then the list is the list to show not hide
                   12012:     if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84      albertel 12013:     my @hiddenlist=split(/,/,$hiddenparts);
                   12014:     foreach my $checkid (@hiddenlist) {
1.141     albertel 12015: 	if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84      albertel 12016:     }
1.141     albertel 12017:     return !$truth;
1.84      albertel 12018: }
1.127     matthew  12019: 
1.138     matthew  12020: 
                   12021: ############################################################
                   12022: ############################################################
                   12023: 
                   12024: =pod
                   12025: 
1.157     matthew  12026: =back 
                   12027: 
1.138     matthew  12028: =head1 cgi-bin script and graphing routines
                   12029: 
1.157     matthew  12030: =over 4
                   12031: 
1.648     raeburn  12032: =item * &get_cgi_id()
1.138     matthew  12033: 
                   12034: Inputs: none
                   12035: 
                   12036: Returns an id which can be used to pass environment variables
                   12037: to various cgi-bin scripts.  These environment variables will
                   12038: be removed from the users environment after a given time by
                   12039: the routine &Apache::lonnet::transfer_profile_to_env.
                   12040: 
                   12041: =cut
                   12042: 
                   12043: ############################################################
                   12044: ############################################################
1.152     albertel 12045: my $uniq=0;
1.136     matthew  12046: sub get_cgi_id {
1.154     albertel 12047:     $uniq=($uniq+1)%100000;
1.280     albertel 12048:     return (time.'_'.$$.'_'.$uniq);
1.136     matthew  12049: }
                   12050: 
1.127     matthew  12051: ############################################################
                   12052: ############################################################
                   12053: 
                   12054: =pod
                   12055: 
1.648     raeburn  12056: =item * &DrawBarGraph()
1.127     matthew  12057: 
1.138     matthew  12058: Facilitates the plotting of data in a (stacked) bar graph.
                   12059: Puts plot definition data into the users environment in order for 
                   12060: graph.png to plot it.  Returns an <img> tag for the plot.
                   12061: The bars on the plot are labeled '1','2',...,'n'.
                   12062: 
                   12063: Inputs:
                   12064: 
                   12065: =over 4
                   12066: 
                   12067: =item $Title: string, the title of the plot
                   12068: 
                   12069: =item $xlabel: string, text describing the X-axis of the plot
                   12070: 
                   12071: =item $ylabel: string, text describing the Y-axis of the plot
                   12072: 
                   12073: =item $Max: scalar, the maximum Y value to use in the plot
                   12074: If $Max is < any data point, the graph will not be rendered.
                   12075: 
1.140     matthew  12076: =item $colors: array ref holding the colors to be used for the data sets when
1.138     matthew  12077: they are plotted.  If undefined, default values will be used.
                   12078: 
1.178     matthew  12079: =item $labels: array ref holding the labels to use on the x-axis for the bars.
                   12080: 
1.138     matthew  12081: =item @Values: An array of array references.  Each array reference holds data
                   12082: to be plotted in a stacked bar chart.
                   12083: 
1.239     matthew  12084: =item If the final element of @Values is a hash reference the key/value
                   12085: pairs will be added to the graph definition.
                   12086: 
1.138     matthew  12087: =back
                   12088: 
                   12089: Returns:
                   12090: 
                   12091: An <img> tag which references graph.png and the appropriate identifying
                   12092: information for the plot.
                   12093: 
1.127     matthew  12094: =cut
                   12095: 
                   12096: ############################################################
                   12097: ############################################################
1.134     matthew  12098: sub DrawBarGraph {
1.178     matthew  12099:     my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134     matthew  12100:     #
                   12101:     if (! defined($colors)) {
                   12102:         $colors = ['#33ff00', 
                   12103:                   '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
                   12104:                   '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
                   12105:                   ]; 
                   12106:     }
1.228     matthew  12107:     my $extra_settings = {};
                   12108:     if (ref($Values[-1]) eq 'HASH') {
                   12109:         $extra_settings = pop(@Values);
                   12110:     }
1.127     matthew  12111:     #
1.136     matthew  12112:     my $identifier = &get_cgi_id();
                   12113:     my $id = 'cgi.'.$identifier;        
1.129     matthew  12114:     if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127     matthew  12115:         return '';
                   12116:     }
1.225     matthew  12117:     #
                   12118:     my @Labels;
                   12119:     if (defined($labels)) {
                   12120:         @Labels = @$labels;
                   12121:     } else {
                   12122:         for (my $i=0;$i<@{$Values[0]};$i++) {
                   12123:             push (@Labels,$i+1);
                   12124:         }
                   12125:     }
                   12126:     #
1.129     matthew  12127:     my $NumBars = scalar(@{$Values[0]});
1.225     matthew  12128:     if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129     matthew  12129:     my %ValuesHash;
                   12130:     my $NumSets=1;
                   12131:     foreach my $array (@Values) {
                   12132:         next if (! ref($array));
1.136     matthew  12133:         $ValuesHash{$id.'.data.'.$NumSets++} = 
1.132     matthew  12134:             join(',',@$array);
1.129     matthew  12135:     }
1.127     matthew  12136:     #
1.136     matthew  12137:     my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225     matthew  12138:     if ($NumBars < 3) {
                   12139:         $width = 120+$NumBars*32;
1.220     matthew  12140:         $xskip = 1;
1.225     matthew  12141:         $bar_width = 30;
                   12142:     } elsif ($NumBars < 5) {
                   12143:         $width = 120+$NumBars*20;
                   12144:         $xskip = 1;
                   12145:         $bar_width = 20;
1.220     matthew  12146:     } elsif ($NumBars < 10) {
1.136     matthew  12147:         $width = 120+$NumBars*15;
                   12148:         $xskip = 1;
                   12149:         $bar_width = 15;
                   12150:     } elsif ($NumBars <= 25) {
                   12151:         $width = 120+$NumBars*11;
                   12152:         $xskip = 5;
                   12153:         $bar_width = 8;
                   12154:     } elsif ($NumBars <= 50) {
                   12155:         $width = 120+$NumBars*8;
                   12156:         $xskip = 5;
                   12157:         $bar_width = 4;
                   12158:     } else {
                   12159:         $width = 120+$NumBars*8;
                   12160:         $xskip = 5;
                   12161:         $bar_width = 4;
                   12162:     }
                   12163:     #
1.137     matthew  12164:     $Max = 1 if ($Max < 1);
                   12165:     if ( int($Max) < $Max ) {
                   12166:         $Max++;
                   12167:         $Max = int($Max);
                   12168:     }
1.127     matthew  12169:     $Title  = '' if (! defined($Title));
                   12170:     $xlabel = '' if (! defined($xlabel));
                   12171:     $ylabel = '' if (! defined($ylabel));
1.369     www      12172:     $ValuesHash{$id.'.title'}    = &escape($Title);
                   12173:     $ValuesHash{$id.'.xlabel'}   = &escape($xlabel);
                   12174:     $ValuesHash{$id.'.ylabel'}   = &escape($ylabel);
1.137     matthew  12175:     $ValuesHash{$id.'.y_max_value'} = $Max;
1.136     matthew  12176:     $ValuesHash{$id.'.NumBars'}  = $NumBars;
                   12177:     $ValuesHash{$id.'.NumSets'}  = $NumSets;
                   12178:     $ValuesHash{$id.'.PlotType'} = 'bar';
                   12179:     $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   12180:     $ValuesHash{$id.'.height'}   = $height;
                   12181:     $ValuesHash{$id.'.width'}    = $width;
                   12182:     $ValuesHash{$id.'.xskip'}    = $xskip;
                   12183:     $ValuesHash{$id.'.bar_width'} = $bar_width;
                   12184:     $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127     matthew  12185:     #
1.228     matthew  12186:     # Deal with other parameters
                   12187:     while (my ($key,$value) = each(%$extra_settings)) {
                   12188:         $ValuesHash{$id.'.'.$key} = $value;
                   12189:     }
                   12190:     #
1.646     raeburn  12191:     &Apache::lonnet::appenv(\%ValuesHash);
1.137     matthew  12192:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   12193: }
                   12194: 
                   12195: ############################################################
                   12196: ############################################################
                   12197: 
                   12198: =pod
                   12199: 
1.648     raeburn  12200: =item * &DrawXYGraph()
1.137     matthew  12201: 
1.138     matthew  12202: Facilitates the plotting of data in an XY graph.
                   12203: Puts plot definition data into the users environment in order for 
                   12204: graph.png to plot it.  Returns an <img> tag for the plot.
                   12205: 
                   12206: Inputs:
                   12207: 
                   12208: =over 4
                   12209: 
                   12210: =item $Title: string, the title of the plot
                   12211: 
                   12212: =item $xlabel: string, text describing the X-axis of the plot
                   12213: 
                   12214: =item $ylabel: string, text describing the Y-axis of the plot
                   12215: 
                   12216: =item $Max: scalar, the maximum Y value to use in the plot
                   12217: If $Max is < any data point, the graph will not be rendered.
                   12218: 
                   12219: =item $colors: Array ref containing the hex color codes for the data to be 
                   12220: plotted in.  If undefined, default values will be used.
                   12221: 
                   12222: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   12223: 
                   12224: =item $Ydata: Array ref containing Array refs.  
1.185     www      12225: Each of the contained arrays will be plotted as a separate curve.
1.138     matthew  12226: 
                   12227: =item %Values: hash indicating or overriding any default values which are 
                   12228: passed to graph.png.  
                   12229: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   12230: 
                   12231: =back
                   12232: 
                   12233: Returns:
                   12234: 
                   12235: An <img> tag which references graph.png and the appropriate identifying
                   12236: information for the plot.
                   12237: 
1.137     matthew  12238: =cut
                   12239: 
                   12240: ############################################################
                   12241: ############################################################
                   12242: sub DrawXYGraph {
                   12243:     my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
                   12244:     #
                   12245:     # Create the identifier for the graph
                   12246:     my $identifier = &get_cgi_id();
                   12247:     my $id = 'cgi.'.$identifier;
                   12248:     #
                   12249:     $Title  = '' if (! defined($Title));
                   12250:     $xlabel = '' if (! defined($xlabel));
                   12251:     $ylabel = '' if (! defined($ylabel));
                   12252:     my %ValuesHash = 
                   12253:         (
1.369     www      12254:          $id.'.title'  => &escape($Title),
                   12255:          $id.'.xlabel' => &escape($xlabel),
                   12256:          $id.'.ylabel' => &escape($ylabel),
1.137     matthew  12257:          $id.'.y_max_value'=> $Max,
                   12258:          $id.'.labels'     => join(',',@$Xlabels),
                   12259:          $id.'.PlotType'   => 'XY',
                   12260:          );
                   12261:     #
                   12262:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   12263:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   12264:     }
                   12265:     #
                   12266:     if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
                   12267:         return '';
                   12268:     }
                   12269:     my $NumSets=1;
1.138     matthew  12270:     foreach my $array (@{$Ydata}){
1.137     matthew  12271:         next if (! ref($array));
                   12272:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
                   12273:     }
1.138     matthew  12274:     $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137     matthew  12275:     #
                   12276:     # Deal with other parameters
                   12277:     while (my ($key,$value) = each(%Values)) {
                   12278:         $ValuesHash{$id.'.'.$key} = $value;
1.127     matthew  12279:     }
                   12280:     #
1.646     raeburn  12281:     &Apache::lonnet::appenv(\%ValuesHash);
1.136     matthew  12282:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   12283: }
                   12284: 
                   12285: ############################################################
                   12286: ############################################################
                   12287: 
                   12288: =pod
                   12289: 
1.648     raeburn  12290: =item * &DrawXYYGraph()
1.138     matthew  12291: 
                   12292: Facilitates the plotting of data in an XY graph with two Y axes.
                   12293: Puts plot definition data into the users environment in order for 
                   12294: graph.png to plot it.  Returns an <img> tag for the plot.
                   12295: 
                   12296: Inputs:
                   12297: 
                   12298: =over 4
                   12299: 
                   12300: =item $Title: string, the title of the plot
                   12301: 
                   12302: =item $xlabel: string, text describing the X-axis of the plot
                   12303: 
                   12304: =item $ylabel: string, text describing the Y-axis of the plot
                   12305: 
                   12306: =item $colors: Array ref containing the hex color codes for the data to be 
                   12307: plotted in.  If undefined, default values will be used.
                   12308: 
                   12309: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   12310: 
                   12311: =item $Ydata1: The first data set
                   12312: 
                   12313: =item $Min1: The minimum value of the left Y-axis
                   12314: 
                   12315: =item $Max1: The maximum value of the left Y-axis
                   12316: 
                   12317: =item $Ydata2: The second data set
                   12318: 
                   12319: =item $Min2: The minimum value of the right Y-axis
                   12320: 
                   12321: =item $Max2: The maximum value of the left Y-axis
                   12322: 
                   12323: =item %Values: hash indicating or overriding any default values which are 
                   12324: passed to graph.png.  
                   12325: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   12326: 
                   12327: =back
                   12328: 
                   12329: Returns:
                   12330: 
                   12331: An <img> tag which references graph.png and the appropriate identifying
                   12332: information for the plot.
1.136     matthew  12333: 
                   12334: =cut
                   12335: 
                   12336: ############################################################
                   12337: ############################################################
1.137     matthew  12338: sub DrawXYYGraph {
                   12339:     my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
                   12340:                                         $Ydata2,$Min2,$Max2,%Values)=@_;
1.136     matthew  12341:     #
                   12342:     # Create the identifier for the graph
                   12343:     my $identifier = &get_cgi_id();
                   12344:     my $id = 'cgi.'.$identifier;
                   12345:     #
                   12346:     $Title  = '' if (! defined($Title));
                   12347:     $xlabel = '' if (! defined($xlabel));
                   12348:     $ylabel = '' if (! defined($ylabel));
                   12349:     my %ValuesHash = 
                   12350:         (
1.369     www      12351:          $id.'.title'  => &escape($Title),
                   12352:          $id.'.xlabel' => &escape($xlabel),
                   12353:          $id.'.ylabel' => &escape($ylabel),
1.136     matthew  12354:          $id.'.labels' => join(',',@$Xlabels),
                   12355:          $id.'.PlotType' => 'XY',
                   12356:          $id.'.NumSets' => 2,
1.137     matthew  12357:          $id.'.two_axes' => 1,
                   12358:          $id.'.y1_max_value' => $Max1,
                   12359:          $id.'.y1_min_value' => $Min1,
                   12360:          $id.'.y2_max_value' => $Max2,
                   12361:          $id.'.y2_min_value' => $Min2,
1.136     matthew  12362:          );
                   12363:     #
1.137     matthew  12364:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   12365:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   12366:     }
                   12367:     #
                   12368:     if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
                   12369:         ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136     matthew  12370:         return '';
                   12371:     }
                   12372:     my $NumSets=1;
1.137     matthew  12373:     foreach my $array ($Ydata1,$Ydata2){
1.136     matthew  12374:         next if (! ref($array));
                   12375:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137     matthew  12376:     }
                   12377:     #
                   12378:     # Deal with other parameters
                   12379:     while (my ($key,$value) = each(%Values)) {
                   12380:         $ValuesHash{$id.'.'.$key} = $value;
1.136     matthew  12381:     }
                   12382:     #
1.646     raeburn  12383:     &Apache::lonnet::appenv(\%ValuesHash);
1.130     albertel 12384:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139     matthew  12385: }
                   12386: 
                   12387: ############################################################
                   12388: ############################################################
                   12389: 
                   12390: =pod
                   12391: 
1.157     matthew  12392: =back 
                   12393: 
1.139     matthew  12394: =head1 Statistics helper routines?  
                   12395: 
                   12396: Bad place for them but what the hell.
                   12397: 
1.157     matthew  12398: =over 4
                   12399: 
1.648     raeburn  12400: =item * &chartlink()
1.139     matthew  12401: 
                   12402: Returns a link to the chart for a specific student.  
                   12403: 
                   12404: Inputs:
                   12405: 
                   12406: =over 4
                   12407: 
                   12408: =item $linktext: The text of the link
                   12409: 
                   12410: =item $sname: The students username
                   12411: 
                   12412: =item $sdomain: The students domain
                   12413: 
                   12414: =back
                   12415: 
1.157     matthew  12416: =back
                   12417: 
1.139     matthew  12418: =cut
                   12419: 
                   12420: ############################################################
                   12421: ############################################################
                   12422: sub chartlink {
                   12423:     my ($linktext, $sname, $sdomain) = @_;
                   12424:     my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369     www      12425:         '&amp;SelectedStudent='.&escape($sname.':'.$sdomain).
1.219     albertel 12426:         '&amp;chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139     matthew  12427:        '">'.$linktext.'</a>';
1.153     matthew  12428: }
                   12429: 
                   12430: #######################################################
                   12431: #######################################################
                   12432: 
                   12433: =pod
                   12434: 
                   12435: =head1 Course Environment Routines
1.157     matthew  12436: 
                   12437: =over 4
1.153     matthew  12438: 
1.648     raeburn  12439: =item * &restore_course_settings()
1.153     matthew  12440: 
1.648     raeburn  12441: =item * &store_course_settings()
1.153     matthew  12442: 
                   12443: Restores/Store indicated form parameters from the course environment.
                   12444: Will not overwrite existing values of the form parameters.
                   12445: 
                   12446: Inputs: 
                   12447: a scalar describing the data (e.g. 'chart', 'problem_analysis')
                   12448: 
                   12449: a hash ref describing the data to be stored.  For example:
                   12450:    
                   12451: %Save_Parameters = ('Status' => 'scalar',
                   12452:     'chartoutputmode' => 'scalar',
                   12453:     'chartoutputdata' => 'scalar',
                   12454:     'Section' => 'array',
1.373     raeburn  12455:     'Group' => 'array',
1.153     matthew  12456:     'StudentData' => 'array',
                   12457:     'Maps' => 'array');
                   12458: 
                   12459: Returns: both routines return nothing
                   12460: 
1.631     raeburn  12461: =back
                   12462: 
1.153     matthew  12463: =cut
                   12464: 
                   12465: #######################################################
                   12466: #######################################################
                   12467: sub store_course_settings {
1.496     albertel 12468:     return &store_settings($env{'request.course.id'},@_);
                   12469: }
                   12470: 
                   12471: sub store_settings {
1.153     matthew  12472:     # save to the environment
                   12473:     # appenv the same items, just to be safe
1.300     albertel 12474:     my $udom  = $env{'user.domain'};
                   12475:     my $uname = $env{'user.name'};
1.496     albertel 12476:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  12477:     my %SaveHash;
                   12478:     my %AppHash;
                   12479:     while (my ($setting,$type) = each(%$Settings)) {
1.496     albertel 12480:         my $basename = join('.','internal',$context,$prefix,$setting);
1.300     albertel 12481:         my $envname = 'environment.'.$basename;
1.258     albertel 12482:         if (exists($env{'form.'.$setting})) {
1.153     matthew  12483:             # Save this value away
                   12484:             if ($type eq 'scalar' &&
1.258     albertel 12485:                 (! exists($env{$envname}) || 
                   12486:                  $env{$envname} ne $env{'form.'.$setting})) {
                   12487:                 $SaveHash{$basename} = $env{'form.'.$setting};
                   12488:                 $AppHash{$envname}   = $env{'form.'.$setting};
1.153     matthew  12489:             } elsif ($type eq 'array') {
                   12490:                 my $stored_form;
1.258     albertel 12491:                 if (ref($env{'form.'.$setting})) {
1.153     matthew  12492:                     $stored_form = join(',',
                   12493:                                         map {
1.369     www      12494:                                             &escape($_);
1.258     albertel 12495:                                         } sort(@{$env{'form.'.$setting}}));
1.153     matthew  12496:                 } else {
                   12497:                     $stored_form = 
1.369     www      12498:                         &escape($env{'form.'.$setting});
1.153     matthew  12499:                 }
                   12500:                 # Determine if the array contents are the same.
1.258     albertel 12501:                 if ($stored_form ne $env{$envname}) {
1.153     matthew  12502:                     $SaveHash{$basename} = $stored_form;
                   12503:                     $AppHash{$envname}   = $stored_form;
                   12504:                 }
                   12505:             }
                   12506:         }
                   12507:     }
                   12508:     my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300     albertel 12509:                                           $udom,$uname);
1.153     matthew  12510:     if ($put_result !~ /^(ok|delayed)/) {
                   12511:         &Apache::lonnet::logthis('unable to save form parameters, '.
                   12512:                                  'got error:'.$put_result);
                   12513:     }
                   12514:     # Make sure these settings stick around in this session, too
1.646     raeburn  12515:     &Apache::lonnet::appenv(\%AppHash);
1.153     matthew  12516:     return;
                   12517: }
                   12518: 
                   12519: sub restore_course_settings {
1.499     albertel 12520:     return &restore_settings($env{'request.course.id'},@_);
1.496     albertel 12521: }
                   12522: 
                   12523: sub restore_settings {
                   12524:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  12525:     while (my ($setting,$type) = each(%$Settings)) {
1.258     albertel 12526:         next if (exists($env{'form.'.$setting}));
1.496     albertel 12527:         my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153     matthew  12528:             '.'.$setting;
1.258     albertel 12529:         if (exists($env{$envname})) {
1.153     matthew  12530:             if ($type eq 'scalar') {
1.258     albertel 12531:                 $env{'form.'.$setting} = $env{$envname};
1.153     matthew  12532:             } elsif ($type eq 'array') {
1.258     albertel 12533:                 $env{'form.'.$setting} = [ 
1.153     matthew  12534:                                            map { 
1.369     www      12535:                                                &unescape($_); 
1.258     albertel 12536:                                            } split(',',$env{$envname})
1.153     matthew  12537:                                            ];
                   12538:             }
                   12539:         }
                   12540:     }
1.127     matthew  12541: }
                   12542: 
1.618     raeburn  12543: #######################################################
                   12544: #######################################################
                   12545: 
                   12546: =pod
                   12547: 
                   12548: =head1 Domain E-mail Routines  
                   12549: 
                   12550: =over 4
                   12551: 
1.648     raeburn  12552: =item * &build_recipient_list()
1.618     raeburn  12553: 
1.884     raeburn  12554: Build recipient lists for five types of e-mail:
1.766     raeburn  12555: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884     raeburn  12556: (d) Help requests, (e) Course requests needing approval,  generated by
                   12557: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
                   12558: loncoursequeueadmin.pm respectively.
1.618     raeburn  12559: 
                   12560: Inputs:
1.619     raeburn  12561: defmail (scalar - email address of default recipient), 
1.618     raeburn  12562: mailing type (scalar - errormail, packagesmail, or helpdeskmail), 
1.619     raeburn  12563: defdom (domain for which to retrieve configuration settings),
                   12564: origmail (scalar - email address of recipient from loncapa.conf, 
                   12565: i.e., predates configuration by DC via domainprefs.pm 
1.618     raeburn  12566: 
1.655     raeburn  12567: Returns: comma separated list of addresses to which to send e-mail.
                   12568: 
                   12569: =back
1.618     raeburn  12570: 
                   12571: =cut
                   12572: 
                   12573: ############################################################
                   12574: ############################################################
                   12575: sub build_recipient_list {
1.619     raeburn  12576:     my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618     raeburn  12577:     my @recipients;
                   12578:     my $otheremails;
                   12579:     my %domconfig =
                   12580:          &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
                   12581:     if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766     raeburn  12582:         if (exists($domconfig{'contacts'}{$mailing})) {
                   12583:             if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
                   12584:                 my @contacts = ('adminemail','supportemail');
                   12585:                 foreach my $item (@contacts) {
                   12586:                     if ($domconfig{'contacts'}{$mailing}{$item}) {
                   12587:                         my $addr = $domconfig{'contacts'}{$item}; 
                   12588:                         if (!grep(/^\Q$addr\E$/,@recipients)) {
                   12589:                             push(@recipients,$addr);
                   12590:                         }
1.619     raeburn  12591:                     }
1.766     raeburn  12592:                     $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618     raeburn  12593:                 }
                   12594:             }
1.766     raeburn  12595:         } elsif ($origmail ne '') {
                   12596:             push(@recipients,$origmail);
1.618     raeburn  12597:         }
1.619     raeburn  12598:     } elsif ($origmail ne '') {
                   12599:         push(@recipients,$origmail);
1.618     raeburn  12600:     }
1.688     raeburn  12601:     if (defined($defmail)) {
                   12602:         if ($defmail ne '') {
                   12603:             push(@recipients,$defmail);
                   12604:         }
1.618     raeburn  12605:     }
                   12606:     if ($otheremails) {
1.619     raeburn  12607:         my @others;
                   12608:         if ($otheremails =~ /,/) {
                   12609:             @others = split(/,/,$otheremails);
1.618     raeburn  12610:         } else {
1.619     raeburn  12611:             push(@others,$otheremails);
                   12612:         }
                   12613:         foreach my $addr (@others) {
                   12614:             if (!grep(/^\Q$addr\E$/,@recipients)) {
                   12615:                 push(@recipients,$addr);
                   12616:             }
1.618     raeburn  12617:         }
                   12618:     }
1.619     raeburn  12619:     my $recipientlist = join(',',@recipients); 
1.618     raeburn  12620:     return $recipientlist;
                   12621: }
                   12622: 
1.127     matthew  12623: ############################################################
                   12624: ############################################################
1.154     albertel 12625: 
1.655     raeburn  12626: =pod
                   12627: 
                   12628: =head1 Course Catalog Routines
                   12629: 
                   12630: =over 4
                   12631: 
                   12632: =item * &gather_categories()
                   12633: 
                   12634: Converts category definitions - keys of categories hash stored in  
                   12635: coursecategories in configuration.db on the primary library server in a 
                   12636: domain - to an array.  Also generates javascript and idx hash used to 
                   12637: generate Domain Coordinator interface for editing Course Categories.
                   12638: 
                   12639: Inputs:
1.663     raeburn  12640: 
1.655     raeburn  12641: categories (reference to hash of category definitions).
1.663     raeburn  12642: 
1.655     raeburn  12643: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   12644:       categories and subcategories).
1.663     raeburn  12645: 
1.655     raeburn  12646: idx (reference to hash of counters used in Domain Coordinator interface for 
                   12647:       editing Course Categories).
1.663     raeburn  12648: 
1.655     raeburn  12649: jsarray (reference to array of categories used to create Javascript arrays for
                   12650:          Domain Coordinator interface for editing Course Categories).
                   12651: 
                   12652: Returns: nothing
                   12653: 
                   12654: Side effects: populates cats, idx and jsarray. 
                   12655: 
                   12656: =cut
                   12657: 
                   12658: sub gather_categories {
                   12659:     my ($categories,$cats,$idx,$jsarray) = @_;
                   12660:     my %counters;
                   12661:     my $num = 0;
                   12662:     foreach my $item (keys(%{$categories})) {
                   12663:         my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   12664:         if ($container eq '' && $depth == 0) {
                   12665:             $cats->[$depth][$categories->{$item}] = $cat;
                   12666:         } else {
                   12667:             $cats->[$depth]{$container}[$categories->{$item}] = $cat;
                   12668:         }
                   12669:         my ($escitem,$tail) = split(/:/,$item,2);
                   12670:         if ($counters{$tail} eq '') {
                   12671:             $counters{$tail} = $num;
                   12672:             $num ++;
                   12673:         }
                   12674:         if (ref($idx) eq 'HASH') {
                   12675:             $idx->{$item} = $counters{$tail};
                   12676:         }
                   12677:         if (ref($jsarray) eq 'ARRAY') {
                   12678:             push(@{$jsarray->[$counters{$tail}]},$item);
                   12679:         }
                   12680:     }
                   12681:     return;
                   12682: }
                   12683: 
                   12684: =pod
                   12685: 
                   12686: =item * &extract_categories()
                   12687: 
                   12688: Used to generate breadcrumb trails for course categories.
                   12689: 
                   12690: Inputs:
1.663     raeburn  12691: 
1.655     raeburn  12692: categories (reference to hash of category definitions).
1.663     raeburn  12693: 
1.655     raeburn  12694: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   12695:       categories and subcategories).
1.663     raeburn  12696: 
1.655     raeburn  12697: trails (reference to array of breacrumb trails for each category).
1.663     raeburn  12698: 
1.655     raeburn  12699: allitems (reference to hash - key is category key 
                   12700:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  12701: 
1.655     raeburn  12702: idx (reference to hash of counters used in Domain Coordinator interface for
                   12703:       editing Course Categories).
1.663     raeburn  12704: 
1.655     raeburn  12705: jsarray (reference to array of categories used to create Javascript arrays for
                   12706:          Domain Coordinator interface for editing Course Categories).
                   12707: 
1.665     raeburn  12708: subcats (reference to hash of arrays containing all subcategories within each 
                   12709:          category, -recursive)
                   12710: 
1.655     raeburn  12711: Returns: nothing
                   12712: 
                   12713: Side effects: populates trails and allitems hash references.
                   12714: 
                   12715: =cut
                   12716: 
                   12717: sub extract_categories {
1.665     raeburn  12718:     my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655     raeburn  12719:     if (ref($categories) eq 'HASH') {
                   12720:         &gather_categories($categories,$cats,$idx,$jsarray);
                   12721:         if (ref($cats->[0]) eq 'ARRAY') {
                   12722:             for (my $i=0; $i<@{$cats->[0]}; $i++) {
                   12723:                 my $name = $cats->[0][$i];
                   12724:                 my $item = &escape($name).'::0';
                   12725:                 my $trailstr;
                   12726:                 if ($name eq 'instcode') {
                   12727:                     $trailstr = &mt('Official courses (with institutional codes)');
1.919     raeburn  12728:                 } elsif ($name eq 'communities') {
                   12729:                     $trailstr = &mt('Communities');
1.655     raeburn  12730:                 } else {
                   12731:                     $trailstr = $name;
                   12732:                 }
                   12733:                 if ($allitems->{$item} eq '') {
                   12734:                     push(@{$trails},$trailstr);
                   12735:                     $allitems->{$item} = scalar(@{$trails})-1;
                   12736:                 }
                   12737:                 my @parents = ($name);
                   12738:                 if (ref($cats->[1]{$name}) eq 'ARRAY') {
                   12739:                     for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
                   12740:                         my $category = $cats->[1]{$name}[$j];
1.665     raeburn  12741:                         if (ref($subcats) eq 'HASH') {
                   12742:                             push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
                   12743:                         }
                   12744:                         &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
                   12745:                     }
                   12746:                 } else {
                   12747:                     if (ref($subcats) eq 'HASH') {
                   12748:                         $subcats->{$item} = [];
1.655     raeburn  12749:                     }
                   12750:                 }
                   12751:             }
                   12752:         }
                   12753:     }
                   12754:     return;
                   12755: }
                   12756: 
                   12757: =pod
                   12758: 
                   12759: =item *&recurse_categories()
                   12760: 
                   12761: Recursively used to generate breadcrumb trails for course categories.
                   12762: 
                   12763: Inputs:
1.663     raeburn  12764: 
1.655     raeburn  12765: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   12766:       categories and subcategories).
1.663     raeburn  12767: 
1.655     raeburn  12768: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663     raeburn  12769: 
                   12770: category (current course category, for which breadcrumb trail is being generated).
                   12771: 
                   12772: trails (reference to array of breadcrumb trails for each category).
                   12773: 
1.655     raeburn  12774: allitems (reference to hash - key is category key
                   12775:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  12776: 
1.655     raeburn  12777: parents (array containing containers directories for current category, 
                   12778:          back to top level). 
                   12779: 
                   12780: Returns: nothing
                   12781: 
                   12782: Side effects: populates trails and allitems hash references
                   12783: 
                   12784: =cut
                   12785: 
                   12786: sub recurse_categories {
1.665     raeburn  12787:     my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655     raeburn  12788:     my $shallower = $depth - 1;
                   12789:     if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
                   12790:         for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
                   12791:             my $name = $cats->[$depth]{$category}[$k];
                   12792:             my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   12793:             my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   12794:             if ($allitems->{$item} eq '') {
                   12795:                 push(@{$trails},$trailstr);
                   12796:                 $allitems->{$item} = scalar(@{$trails})-1;
                   12797:             }
                   12798:             my $deeper = $depth+1;
                   12799:             push(@{$parents},$category);
1.665     raeburn  12800:             if (ref($subcats) eq 'HASH') {
                   12801:                 my $subcat = &escape($name).':'.$category.':'.$depth;
                   12802:                 for (my $j=@{$parents}; $j>=0; $j--) {
                   12803:                     my $higher;
                   12804:                     if ($j > 0) {
                   12805:                         $higher = &escape($parents->[$j]).':'.
                   12806:                                   &escape($parents->[$j-1]).':'.$j;
                   12807:                     } else {
                   12808:                         $higher = &escape($parents->[$j]).'::'.$j;
                   12809:                     }
                   12810:                     push(@{$subcats->{$higher}},$subcat);
                   12811:                 }
                   12812:             }
                   12813:             &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
                   12814:                                 $subcats);
1.655     raeburn  12815:             pop(@{$parents});
                   12816:         }
                   12817:     } else {
                   12818:         my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   12819:         my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   12820:         if ($allitems->{$item} eq '') {
                   12821:             push(@{$trails},$trailstr);
                   12822:             $allitems->{$item} = scalar(@{$trails})-1;
                   12823:         }
                   12824:     }
                   12825:     return;
                   12826: }
                   12827: 
1.663     raeburn  12828: =pod
                   12829: 
                   12830: =item *&assign_categories_table()
                   12831: 
                   12832: Create a datatable for display of hierarchical categories in a domain,
                   12833: with checkboxes to allow a course to be categorized. 
                   12834: 
                   12835: Inputs:
                   12836: 
                   12837: cathash - reference to hash of categories defined for the domain (from
                   12838:           configuration.db)
                   12839: 
                   12840: currcat - scalar with an & separated list of categories assigned to a course. 
                   12841: 
1.919     raeburn  12842: type    - scalar contains course type (Course or Community).
                   12843: 
1.663     raeburn  12844: Returns: $output (markup to be displayed) 
                   12845: 
                   12846: =cut
                   12847: 
                   12848: sub assign_categories_table {
1.919     raeburn  12849:     my ($cathash,$currcat,$type) = @_;
1.663     raeburn  12850:     my $output;
                   12851:     if (ref($cathash) eq 'HASH') {
                   12852:         my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
                   12853:         &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
                   12854:         $maxdepth = scalar(@cats);
                   12855:         if (@cats > 0) {
                   12856:             my $itemcount = 0;
                   12857:             if (ref($cats[0]) eq 'ARRAY') {
                   12858:                 my @currcategories;
                   12859:                 if ($currcat ne '') {
                   12860:                     @currcategories = split('&',$currcat);
                   12861:                 }
1.919     raeburn  12862:                 my $table;
1.663     raeburn  12863:                 for (my $i=0; $i<@{$cats[0]}; $i++) {
                   12864:                     my $parent = $cats[0][$i];
1.919     raeburn  12865:                     next if ($parent eq 'instcode');
                   12866:                     if ($type eq 'Community') {
                   12867:                         next unless ($parent eq 'communities');
                   12868:                     } else {
                   12869:                         next if ($parent eq 'communities');
                   12870:                     }
1.663     raeburn  12871:                     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   12872:                     my $item = &escape($parent).'::0';
                   12873:                     my $checked = '';
                   12874:                     if (@currcategories > 0) {
                   12875:                         if (grep(/^\Q$item\E$/,@currcategories)) {
1.772     bisitz   12876:                             $checked = ' checked="checked"';
1.663     raeburn  12877:                         }
                   12878:                     }
1.919     raeburn  12879:                     my $parent_title = $parent;
                   12880:                     if ($parent eq 'communities') {
                   12881:                         $parent_title = &mt('Communities');
                   12882:                     }
                   12883:                     $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
                   12884:                               '<input type="checkbox" name="usecategory" value="'.
                   12885:                               $item.'"'.$checked.' />'.$parent_title.'</span>'.
                   12886:                               '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663     raeburn  12887:                     my $depth = 1;
                   12888:                     push(@path,$parent);
1.919     raeburn  12889:                     $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663     raeburn  12890:                     pop(@path);
1.919     raeburn  12891:                     $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663     raeburn  12892:                     $itemcount ++;
                   12893:                 }
1.919     raeburn  12894:                 if ($itemcount) {
                   12895:                     $output = &Apache::loncommon::start_data_table().
                   12896:                               $table.
                   12897:                               &Apache::loncommon::end_data_table();
                   12898:                 }
1.663     raeburn  12899:             }
                   12900:         }
                   12901:     }
                   12902:     return $output;
                   12903: }
                   12904: 
                   12905: =pod
                   12906: 
                   12907: =item *&assign_category_rows()
                   12908: 
                   12909: Create a datatable row for display of nested categories in a domain,
                   12910: with checkboxes to allow a course to be categorized,called recursively.
                   12911: 
                   12912: Inputs:
                   12913: 
                   12914: itemcount - track row number for alternating colors
                   12915: 
                   12916: cats - reference to array of arrays/hashes which encapsulates hierarchy of
                   12917:       categories and subcategories.
                   12918: 
                   12919: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
                   12920: 
                   12921: parent - parent of current category item
                   12922: 
                   12923: path - Array containing all categories back up through the hierarchy from the
                   12924:        current category to the top level.
                   12925: 
                   12926: currcategories - reference to array of current categories assigned to the course
                   12927: 
                   12928: Returns: $output (markup to be displayed).
                   12929: 
                   12930: =cut
                   12931: 
                   12932: sub assign_category_rows {
                   12933:     my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
                   12934:     my ($text,$name,$item,$chgstr);
                   12935:     if (ref($cats) eq 'ARRAY') {
                   12936:         my $maxdepth = scalar(@{$cats});
                   12937:         if (ref($cats->[$depth]) eq 'HASH') {
                   12938:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   12939:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   12940:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   12941:                 $text .= '<td><table class="LC_datatable">';
                   12942:                 for (my $j=0; $j<$numchildren; $j++) {
                   12943:                     $name = $cats->[$depth]{$parent}[$j];
                   12944:                     $item = &escape($name).':'.&escape($parent).':'.$depth;
                   12945:                     my $deeper = $depth+1;
                   12946:                     my $checked = '';
                   12947:                     if (ref($currcategories) eq 'ARRAY') {
                   12948:                         if (@{$currcategories} > 0) {
                   12949:                             if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772     bisitz   12950:                                 $checked = ' checked="checked"';
1.663     raeburn  12951:                             }
                   12952:                         }
                   12953:                     }
1.664     raeburn  12954:                     $text .= '<tr><td><span class="LC_nobreak"><label>'.
                   12955:                              '<input type="checkbox" name="usecategory" value="'.
1.675     raeburn  12956:                              $item.'"'.$checked.' />'.$name.'</label></span>'.
                   12957:                              '<input type="hidden" name="catname" value="'.$name.'" />'.
                   12958:                              '</td><td>';
1.663     raeburn  12959:                     if (ref($path) eq 'ARRAY') {
                   12960:                         push(@{$path},$name);
                   12961:                         $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
                   12962:                         pop(@{$path});
                   12963:                     }
                   12964:                     $text .= '</td></tr>';
                   12965:                 }
                   12966:                 $text .= '</table></td>';
                   12967:             }
                   12968:         }
                   12969:     }
                   12970:     return $text;
                   12971: }
                   12972: 
1.655     raeburn  12973: ############################################################
                   12974: ############################################################
                   12975: 
                   12976: 
1.443     albertel 12977: sub commit_customrole {
1.664     raeburn  12978:     my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630     raeburn  12979:     my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443     albertel 12980:                          ($start?', '.&mt('starting').' '.localtime($start):'').
                   12981:                          ($end?', ending '.localtime($end):'').': <b>'.
                   12982:               &Apache::lonnet::assigncustomrole(
1.664     raeburn  12983:                  $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443     albertel 12984:                  '</b><br />';
                   12985:     return $output;
                   12986: }
                   12987: 
                   12988: sub commit_standardrole {
1.541     raeburn  12989:     my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
                   12990:     my ($output,$logmsg,$linefeed);
                   12991:     if ($context eq 'auto') {
                   12992:         $linefeed = "\n";
                   12993:     } else {
                   12994:         $linefeed = "<br />\n";
                   12995:     }  
1.443     albertel 12996:     if ($three eq 'st') {
1.541     raeburn  12997:         my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
                   12998:                                          $one,$two,$sec,$context);
                   12999:         if (($result =~ /^error/) || ($result eq 'not_in_class') || 
1.626     raeburn  13000:             ($result eq 'unknown_course') || ($result eq 'refused')) {
                   13001:             $output = $logmsg.' '.&mt('Error: ').$result."\n"; 
1.443     albertel 13002:         } else {
1.541     raeburn  13003:             $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443     albertel 13004:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  13005:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
                   13006:             if ($context eq 'auto') {
                   13007:                 $output .= $result.$linefeed.&mt('Add to classlist').': ok';
                   13008:             } else {
                   13009:                $output .= '<b>'.$result.'</b>'.$linefeed.
                   13010:                &mt('Add to classlist').': <b>ok</b>';
                   13011:             }
                   13012:             $output .= $linefeed;
1.443     albertel 13013:         }
                   13014:     } else {
                   13015:         $output = &mt('Assigning').' '.$three.' in '.$url.
                   13016:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  13017:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652     raeburn  13018:         my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541     raeburn  13019:         if ($context eq 'auto') {
                   13020:             $output .= $result.$linefeed;
                   13021:         } else {
                   13022:             $output .= '<b>'.$result.'</b>'.$linefeed;
                   13023:         }
1.443     albertel 13024:     }
                   13025:     return $output;
                   13026: }
                   13027: 
                   13028: sub commit_studentrole {
1.541     raeburn  13029:     my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626     raeburn  13030:     my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541     raeburn  13031:     if ($context eq 'auto') {
                   13032:         $linefeed = "\n";
                   13033:     } else {
                   13034:         $linefeed = '<br />'."\n";
                   13035:     }
1.443     albertel 13036:     if (defined($one) && defined($two)) {
                   13037:         my $cid=$one.'_'.$two;
                   13038:         my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
                   13039:         my $secchange = 0;
                   13040:         my $expire_role_result;
                   13041:         my $modify_section_result;
1.628     raeburn  13042:         if ($oldsec ne '-1') { 
                   13043:             if ($oldsec ne $sec) {
1.443     albertel 13044:                 $secchange = 1;
1.628     raeburn  13045:                 my $now = time;
1.443     albertel 13046:                 my $uurl='/'.$cid;
                   13047:                 $uurl=~s/\_/\//g;
                   13048:                 if ($oldsec) {
                   13049:                     $uurl.='/'.$oldsec;
                   13050:                 }
1.626     raeburn  13051:                 $oldsecurl = $uurl;
1.628     raeburn  13052:                 $expire_role_result = 
1.652     raeburn  13053:                     &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628     raeburn  13054:                 if ($env{'request.course.sec'} ne '') { 
                   13055:                     if ($expire_role_result eq 'refused') {
                   13056:                         my @roles = ('st');
                   13057:                         my @statuses = ('previous');
                   13058:                         my @roledoms = ($one);
                   13059:                         my $withsec = 1;
                   13060:                         my %roleshash = 
                   13061:                             &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
                   13062:                                               \@statuses,\@roles,\@roledoms,$withsec);
                   13063:                         if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
                   13064:                             my ($oldstart,$oldend) = 
                   13065:                                 split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
                   13066:                             if ($oldend > 0 && $oldend <= $now) {
                   13067:                                 $expire_role_result = 'ok';
                   13068:                             }
                   13069:                         }
                   13070:                     }
                   13071:                 }
1.443     albertel 13072:                 $result = $expire_role_result;
                   13073:             }
                   13074:         }
                   13075:         if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652     raeburn  13076:             $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443     albertel 13077:             if ($modify_section_result =~ /^ok/) {
                   13078:                 if ($secchange == 1) {
1.628     raeburn  13079:                     if ($sec eq '') {
                   13080:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
                   13081:                     } else {
                   13082:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
                   13083:                     }
1.443     albertel 13084:                 } elsif ($oldsec eq '-1') {
1.628     raeburn  13085:                     if ($sec eq '') {
                   13086:                         $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
                   13087:                     } else {
                   13088:                         $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   13089:                     }
1.443     albertel 13090:                 } else {
1.628     raeburn  13091:                     if ($sec eq '') {
                   13092:                         $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
                   13093:                     } else {
                   13094:                         $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   13095:                     }
1.443     albertel 13096:                 }
                   13097:             } else {
1.628     raeburn  13098:                 if ($secchange) {       
                   13099:                     $$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;
                   13100:                 } else {
                   13101:                     $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
                   13102:                 }
1.443     albertel 13103:             }
                   13104:             $result = $modify_section_result;
                   13105:         } elsif ($secchange == 1) {
1.628     raeburn  13106:             if ($oldsec eq '') {
                   13107:                 $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
                   13108:             } else {
                   13109:                 $$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;
                   13110:             }
1.626     raeburn  13111:             if ($expire_role_result eq 'refused') {
                   13112:                 my $newsecurl = '/'.$cid;
                   13113:                 $newsecurl =~ s/\_/\//g;
                   13114:                 if ($sec ne '') {
                   13115:                     $newsecurl.='/'.$sec;
                   13116:                 }
                   13117:                 if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
                   13118:                     if ($sec eq '') {
                   13119:                         $$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;
                   13120:                     } else {
                   13121:                         $$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;
                   13122:                     }
                   13123:                 }
                   13124:             }
1.443     albertel 13125:         }
                   13126:     } else {
1.626     raeburn  13127:         $$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 13128:         $result = "error: incomplete course id\n";
                   13129:     }
                   13130:     return $result;
                   13131: }
                   13132: 
                   13133: ############################################################
                   13134: ############################################################
                   13135: 
1.566     albertel 13136: sub check_clone {
1.578     raeburn  13137:     my ($args,$linefeed) = @_;
1.566     albertel 13138:     my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
                   13139:     my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
                   13140:     my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
                   13141:     my $clonemsg;
                   13142:     my $can_clone = 0;
1.944     raeburn  13143:     my $lctype = lc($args->{'crstype'});
1.908     raeburn  13144:     if ($lctype ne 'community') {
                   13145:         $lctype = 'course';
                   13146:     }
1.566     albertel 13147:     if ($clonehome eq 'no_host') {
1.944     raeburn  13148:         if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  13149:             $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'});
                   13150:         } else {
                   13151:             $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'});
                   13152:         }     
1.566     albertel 13153:     } else {
                   13154: 	my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944     raeburn  13155:         if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  13156:             if ($clonedesc{'type'} ne 'Community') {
                   13157:                  $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'});
                   13158:                 return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   13159:             }
                   13160:         }
1.882     raeburn  13161: 	if (($env{'request.role.domain'} eq $args->{'clonedomain'}) && 
                   13162:             (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566     albertel 13163: 	    $can_clone = 1;
                   13164: 	} else {
                   13165: 	    my %clonehash = &Apache::lonnet::get('environment',['cloners'],
                   13166: 						 $args->{'clonedomain'},$args->{'clonecourse'});
                   13167: 	    my @cloners = split(/,/,$clonehash{'cloners'});
1.578     raeburn  13168:             if (grep(/^\*$/,@cloners)) {
                   13169:                 $can_clone = 1;
                   13170:             } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
                   13171:                 $can_clone = 1;
                   13172:             } else {
1.908     raeburn  13173:                 my $ccrole = 'cc';
1.944     raeburn  13174:                 if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  13175:                     $ccrole = 'co';
                   13176:                 }
1.578     raeburn  13177: 	        my %roleshash =
                   13178: 		    &Apache::lonnet::get_my_roles($args->{'ccuname'},
                   13179: 					 $args->{'ccdomain'},
1.908     raeburn  13180:                                          'userroles',['active'],[$ccrole],
1.578     raeburn  13181: 					 [$args->{'clonedomain'}]);
1.908     raeburn  13182: 	        if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942     raeburn  13183:                     $can_clone = 1;
                   13184:                 } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
                   13185:                     $can_clone = 1;
                   13186:                 } else {
1.944     raeburn  13187:                     if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  13188:                         $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'});
                   13189:                     } else {
                   13190:                         $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'});
                   13191:                     }
1.578     raeburn  13192: 	        }
1.566     albertel 13193: 	    }
1.578     raeburn  13194:         }
1.566     albertel 13195:     }
                   13196:     return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   13197: }
                   13198: 
1.444     albertel 13199: sub construct_course {
1.885     raeburn  13200:     my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444     albertel 13201:     my $outcome;
1.541     raeburn  13202:     my $linefeed =  '<br />'."\n";
                   13203:     if ($context eq 'auto') {
                   13204:         $linefeed = "\n";
                   13205:     }
1.566     albertel 13206: 
                   13207: #
                   13208: # Are we cloning?
                   13209: #
                   13210:     my ($can_clone, $clonemsg, $cloneid, $clonehome);
                   13211:     if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578     raeburn  13212: 	($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566     albertel 13213: 	if ($context ne 'auto') {
1.578     raeburn  13214:             if ($clonemsg ne '') {
                   13215: 	        $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
                   13216:             }
1.566     albertel 13217: 	}
                   13218: 	$outcome .= $clonemsg.$linefeed;
                   13219: 
                   13220:         if (!$can_clone) {
                   13221: 	    return (0,$outcome);
                   13222: 	}
                   13223:     }
                   13224: 
1.444     albertel 13225: #
                   13226: # Open course
                   13227: #
                   13228:     my $crstype = lc($args->{'crstype'});
                   13229:     my %cenv=();
                   13230:     $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
                   13231:                                              $args->{'cdescr'},
                   13232:                                              $args->{'curl'},
                   13233:                                              $args->{'course_home'},
                   13234:                                              $args->{'nonstandard'},
                   13235:                                              $args->{'crscode'},
                   13236:                                              $args->{'ccuname'}.':'.
                   13237:                                              $args->{'ccdomain'},
1.882     raeburn  13238:                                              $args->{'crstype'},
1.885     raeburn  13239:                                              $cnum,$context,$category);
1.444     albertel 13240: 
                   13241:     # Note: The testing routines depend on this being output; see 
                   13242:     # Utils::Course. This needs to at least be output as a comment
                   13243:     # if anyone ever decides to not show this, and Utils::Course::new
                   13244:     # will need to be suitably modified.
1.541     raeburn  13245:     $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943     raeburn  13246:     if ($$courseid =~ /^error:/) {
                   13247:         return (0,$outcome);
                   13248:     }
                   13249: 
1.444     albertel 13250: #
                   13251: # Check if created correctly
                   13252: #
1.479     albertel 13253:     ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444     albertel 13254:     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943     raeburn  13255:     if ($crsuhome eq 'no_host') {
                   13256:         $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
                   13257:         return (0,$outcome);
                   13258:     }
1.541     raeburn  13259:     $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566     albertel 13260: 
1.444     albertel 13261: #
1.566     albertel 13262: # Do the cloning
                   13263: #   
                   13264:     if ($can_clone && $cloneid) {
                   13265: 	$clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
                   13266: 	if ($context ne 'auto') {
                   13267: 	    $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
                   13268: 	}
                   13269: 	$outcome .= $clonemsg.$linefeed;
                   13270: 	my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444     albertel 13271: # Copy all files
1.637     www      13272: 	&Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444     albertel 13273: # Restore URL
1.566     albertel 13274: 	$cenv{'url'}=$oldcenv{'url'};
1.444     albertel 13275: # Restore title
1.566     albertel 13276: 	$cenv{'description'}=$oldcenv{'description'};
1.955     raeburn  13277: # Restore creation date, creator and creation context.
                   13278:         $cenv{'internal.created'}=$oldcenv{'internal.created'};
                   13279:         $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
                   13280:         $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444     albertel 13281: # Mark as cloned
1.566     albertel 13282: 	$cenv{'clonedfrom'}=$cloneid;
1.638     www      13283: # Need to clone grading mode
                   13284:         my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
                   13285:         $cenv{'grading'}=$newenv{'grading'};
                   13286: # Do not clone these environment entries
                   13287:         &Apache::lonnet::del('environment',
                   13288:                   ['default_enrollment_start_date',
                   13289:                    'default_enrollment_end_date',
                   13290:                    'question.email',
                   13291:                    'policy.email',
                   13292:                    'comment.email',
                   13293:                    'pch.users.denied',
1.725     raeburn  13294:                    'plc.users.denied',
                   13295:                    'hidefromcat',
                   13296:                    'categories'],
1.638     www      13297:                    $$crsudom,$$crsunum);
1.444     albertel 13298:     }
1.566     albertel 13299: 
1.444     albertel 13300: #
                   13301: # Set environment (will override cloned, if existing)
                   13302: #
                   13303:     my @sections = ();
                   13304:     my @xlists = ();
                   13305:     if ($args->{'crstype'}) {
                   13306:         $cenv{'type'}=$args->{'crstype'};
                   13307:     }
                   13308:     if ($args->{'crsid'}) {
                   13309:         $cenv{'courseid'}=$args->{'crsid'};
                   13310:     }
                   13311:     if ($args->{'crscode'}) {
                   13312:         $cenv{'internal.coursecode'}=$args->{'crscode'};
                   13313:     }
                   13314:     if ($args->{'crsquota'} ne '') {
                   13315:         $cenv{'internal.coursequota'}=$args->{'crsquota'};
                   13316:     } else {
                   13317:         $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
                   13318:     }
                   13319:     if ($args->{'ccuname'}) {
                   13320:         $cenv{'internal.courseowner'} = $args->{'ccuname'}.
                   13321:                                         ':'.$args->{'ccdomain'};
                   13322:     } else {
                   13323:         $cenv{'internal.courseowner'} = $args->{'curruser'};
                   13324:     }
                   13325:     my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
                   13326:     if ($args->{'crssections'}) {
                   13327:         $cenv{'internal.sectionnums'} = '';
                   13328:         if ($args->{'crssections'} =~ m/,/) {
                   13329:             @sections = split/,/,$args->{'crssections'};
                   13330:         } else {
                   13331:             $sections[0] = $args->{'crssections'};
                   13332:         }
                   13333:         if (@sections > 0) {
                   13334:             foreach my $item (@sections) {
                   13335:                 my ($sec,$gp) = split/:/,$item;
                   13336:                 my $class = $args->{'crscode'}.$sec;
                   13337:                 my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
                   13338:                 $cenv{'internal.sectionnums'} .= $item.',';
                   13339:                 unless ($addcheck eq 'ok') {
                   13340:                     push @badclasses, $class;
                   13341:                 }
                   13342:             }
                   13343:             $cenv{'internal.sectionnums'} =~ s/,$//;
                   13344:         }
                   13345:     }
                   13346: # do not hide course coordinator from staff listing, 
                   13347: # even if privileged
                   13348:     $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   13349: # add crosslistings
                   13350:     if ($args->{'crsxlist'}) {
                   13351:         $cenv{'internal.crosslistings'}='';
                   13352:         if ($args->{'crsxlist'} =~ m/,/) {
                   13353:             @xlists = split/,/,$args->{'crsxlist'};
                   13354:         } else {
                   13355:             $xlists[0] = $args->{'crsxlist'};
                   13356:         }
                   13357:         if (@xlists > 0) {
                   13358:             foreach my $item (@xlists) {
                   13359:                 my ($xl,$gp) = split/:/,$item;
                   13360:                 my $addcheck =  &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
                   13361:                 $cenv{'internal.crosslistings'} .= $item.',';
                   13362:                 unless ($addcheck eq 'ok') {
                   13363:                     push @badclasses, $xl;
                   13364:                 }
                   13365:             }
                   13366:             $cenv{'internal.crosslistings'} =~ s/,$//;
                   13367:         }
                   13368:     }
                   13369:     if ($args->{'autoadds'}) {
                   13370:         $cenv{'internal.autoadds'}=$args->{'autoadds'};
                   13371:     }
                   13372:     if ($args->{'autodrops'}) {
                   13373:         $cenv{'internal.autodrops'}=$args->{'autodrops'};
                   13374:     }
                   13375: # check for notification of enrollment changes
                   13376:     my @notified = ();
                   13377:     if ($args->{'notify_owner'}) {
                   13378:         if ($args->{'ccuname'} ne '') {
                   13379:             push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
                   13380:         }
                   13381:     }
                   13382:     if ($args->{'notify_dc'}) {
                   13383:         if ($uname ne '') { 
1.630     raeburn  13384:             push(@notified,$uname.':'.$udom);
1.444     albertel 13385:         }
                   13386:     }
                   13387:     if (@notified > 0) {
                   13388:         my $notifylist;
                   13389:         if (@notified > 1) {
                   13390:             $notifylist = join(',',@notified);
                   13391:         } else {
                   13392:             $notifylist = $notified[0];
                   13393:         }
                   13394:         $cenv{'internal.notifylist'} = $notifylist;
                   13395:     }
                   13396:     if (@badclasses > 0) {
                   13397:         my %lt=&Apache::lonlocal::texthash(
                   13398:                 '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',
                   13399:                 'dnhr' => 'does not have rights to access enrollment in these classes',
                   13400:                 'adby' => 'as determined by the policies of your institution on access to official classlists'
                   13401:         );
1.541     raeburn  13402:         my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
                   13403:                            ' ('.$lt{'adby'}.')';
                   13404:         if ($context eq 'auto') {
                   13405:             $outcome .= $badclass_msg.$linefeed;
1.566     albertel 13406:             $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541     raeburn  13407:             foreach my $item (@badclasses) {
                   13408:                 if ($context eq 'auto') {
                   13409:                     $outcome .= " - $item\n";
                   13410:                 } else {
                   13411:                     $outcome .= "<li>$item</li>\n";
                   13412:                 }
                   13413:             }
                   13414:             if ($context eq 'auto') {
                   13415:                 $outcome .= $linefeed;
                   13416:             } else {
1.566     albertel 13417:                 $outcome .= "</ul><br /><br /></div>\n";
1.541     raeburn  13418:             }
                   13419:         } 
1.444     albertel 13420:     }
                   13421:     if ($args->{'no_end_date'}) {
                   13422:         $args->{'endaccess'} = 0;
                   13423:     }
                   13424:     $cenv{'internal.autostart'}=$args->{'enrollstart'};
                   13425:     $cenv{'internal.autoend'}=$args->{'enrollend'};
                   13426:     $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
                   13427:     $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
                   13428:     if ($args->{'showphotos'}) {
                   13429:       $cenv{'internal.showphotos'}=$args->{'showphotos'};
                   13430:     }
                   13431:     $cenv{'internal.authtype'} = $args->{'authtype'};
                   13432:     $cenv{'internal.autharg'} = $args->{'autharg'}; 
                   13433:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
                   13434:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
1.541     raeburn  13435:             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'); 
                   13436:             if ($context eq 'auto') {
                   13437:                 $outcome .= $krb_msg;
                   13438:             } else {
1.566     albertel 13439:                 $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541     raeburn  13440:             }
                   13441:             $outcome .= $linefeed;
1.444     albertel 13442:         }
                   13443:     }
                   13444:     if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
                   13445:        if ($args->{'setpolicy'}) {
                   13446:            $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   13447:        }
                   13448:        if ($args->{'setcontent'}) {
                   13449:            $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   13450:        }
                   13451:     }
                   13452:     if ($args->{'reshome'}) {
                   13453: 	$cenv{'reshome'}=$args->{'reshome'}.'/';
                   13454: 	$cenv{'reshome'}=~s/\/+$/\//;
                   13455:     }
                   13456: #
                   13457: # course has keyed access
                   13458: #
                   13459:     if ($args->{'setkeys'}) {
                   13460:        $cenv{'keyaccess'}='yes';
                   13461:     }
                   13462: # if specified, key authority is not course, but user
                   13463: # only active if keyaccess is yes
                   13464:     if ($args->{'keyauth'}) {
1.487     albertel 13465: 	my ($user,$domain) = split(':',$args->{'keyauth'});
                   13466: 	$user = &LONCAPA::clean_username($user);
                   13467: 	$domain = &LONCAPA::clean_username($domain);
1.488     foxr     13468: 	if ($user ne '' && $domain ne '') {
1.487     albertel 13469: 	    $cenv{'keyauth'}=$user.':'.$domain;
1.444     albertel 13470: 	}
                   13471:     }
                   13472: 
                   13473:     if ($args->{'disresdis'}) {
                   13474:         $cenv{'pch.roles.denied'}='st';
                   13475:     }
                   13476:     if ($args->{'disablechat'}) {
                   13477:         $cenv{'plc.roles.denied'}='st';
                   13478:     }
                   13479: 
                   13480:     # Record we've not yet viewed the Course Initialization Helper for this 
                   13481:     # course
                   13482:     $cenv{'course.helper.not.run'} = 1;
                   13483:     #
                   13484:     # Use new Randomseed
                   13485:     #
                   13486:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
                   13487:     $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
                   13488:     #
                   13489:     # The encryption code and receipt prefix for this course
                   13490:     #
                   13491:     $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
                   13492:     $cenv{'internal.encpref'}=100+int(9*rand(99));
                   13493:     #
                   13494:     # By default, use standard grading
                   13495:     if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
                   13496: 
1.541     raeburn  13497:     $outcome .= $linefeed.&mt('Setting environment').': '.                 
                   13498:           &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 13499: #
                   13500: # Open all assignments
                   13501: #
                   13502:     if ($args->{'openall'}) {
                   13503:        my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
                   13504:        my %storecontent = ($storeunder         => time,
                   13505:                            $storeunder.'.type' => 'date_start');
                   13506:        
                   13507:        $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541     raeburn  13508:                  ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 13509:    }
                   13510: #
                   13511: # Set first page
                   13512: #
                   13513:     unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
                   13514: 	    || ($cloneid)) {
1.445     albertel 13515: 	use LONCAPA::map;
1.444     albertel 13516: 	$outcome .= &mt('Setting first resource').': ';
1.445     albertel 13517: 
                   13518: 	my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
                   13519:         my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
                   13520: 
1.444     albertel 13521:         $outcome .= ($fatal?$errtext:'read ok').' - ';
                   13522:         my $title; my $url;
                   13523:         if ($args->{'firstres'} eq 'syl') {
1.690     bisitz   13524: 	    $title=&mt('Syllabus');
1.444     albertel 13525:             $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
                   13526:         } else {
1.963     raeburn  13527:             $title=&mt('Table of Contents');
1.444     albertel 13528:             $url='/adm/navmaps';
                   13529:         }
1.445     albertel 13530: 
                   13531:         $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
                   13532: 	(my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
                   13533: 
                   13534: 	if ($errtext) { $fatal=2; }
1.541     raeburn  13535:         $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444     albertel 13536:     }
1.566     albertel 13537: 
                   13538:     return (1,$outcome);
1.444     albertel 13539: }
                   13540: 
                   13541: ############################################################
                   13542: ############################################################
                   13543: 
1.953     droeschl 13544: #SD
                   13545: # only Community and Course, or anything else?
1.378     raeburn  13546: sub course_type {
                   13547:     my ($cid) = @_;
                   13548:     if (!defined($cid)) {
                   13549:         $cid = $env{'request.course.id'};
                   13550:     }
1.404     albertel 13551:     if (defined($env{'course.'.$cid.'.type'})) {
                   13552:         return $env{'course.'.$cid.'.type'};
1.378     raeburn  13553:     } else {
                   13554:         return 'Course';
1.377     raeburn  13555:     }
                   13556: }
1.156     albertel 13557: 
1.406     raeburn  13558: sub group_term {
                   13559:     my $crstype = &course_type();
                   13560:     my %names = (
                   13561:                   'Course' => 'group',
1.865     raeburn  13562:                   'Community' => 'group',
1.406     raeburn  13563:                 );
                   13564:     return $names{$crstype};
                   13565: }
                   13566: 
1.902     raeburn  13567: sub course_types {
                   13568:     my @types = ('official','unofficial','community');
                   13569:     my %typename = (
                   13570:                          official   => 'Official course',
                   13571:                          unofficial => 'Unofficial course',
                   13572:                          community  => 'Community',
                   13573:                    );
                   13574:     return (\@types,\%typename);
                   13575: }
                   13576: 
1.156     albertel 13577: sub icon {
                   13578:     my ($file)=@_;
1.505     albertel 13579:     my $curfext = lc((split(/\./,$file))[-1]);
1.168     albertel 13580:     my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156     albertel 13581:     my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168     albertel 13582:     if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
                   13583: 	if (-e  $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
                   13584: 	          $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   13585: 	            $curfext.".gif") {
                   13586: 	    $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   13587: 		$curfext.".gif";
                   13588: 	}
                   13589:     }
1.249     albertel 13590:     return &lonhttpdurl($iconname);
1.154     albertel 13591: } 
1.84      albertel 13592: 
1.575     albertel 13593: sub lonhttpdurl {
1.692     www      13594: #
                   13595: # Had been used for "small fry" static images on separate port 8080.
                   13596: # Modify here if lightweight http functionality desired again.
                   13597: # Currently eliminated due to increasing firewall issues.
                   13598: #
1.575     albertel 13599:     my ($url)=@_;
1.692     www      13600:     return $url;
1.215     albertel 13601: }
                   13602: 
1.213     albertel 13603: sub connection_aborted {
                   13604:     my ($r)=@_;
                   13605:     $r->print(" ");$r->rflush();
                   13606:     my $c = $r->connection;
                   13607:     return $c->aborted();
                   13608: }
                   13609: 
1.221     foxr     13610: #    Escapes strings that may have embedded 's that will be put into
1.222     foxr     13611: #    strings as 'strings'.
                   13612: sub escape_single {
1.221     foxr     13613:     my ($input) = @_;
1.223     albertel 13614:     $input =~ s/\\/\\\\/g;	# Escape the \'s..(must be first)>
1.221     foxr     13615:     $input =~ s/\'/\\\'/g;	# Esacpe the 's....
                   13616:     return $input;
                   13617: }
1.223     albertel 13618: 
1.222     foxr     13619: #  Same as escape_single, but escape's "'s  This 
                   13620: #  can be used for  "strings"
                   13621: sub escape_double {
                   13622:     my ($input) = @_;
                   13623:     $input =~ s/\\/\\\\/g;	# Escape the /'s..(must be first)>
                   13624:     $input =~ s/\"/\\\"/g;	# Esacpe the "s....
                   13625:     return $input;
                   13626: }
1.223     albertel 13627:  
1.222     foxr     13628: #   Escapes the last element of a full URL.
                   13629: sub escape_url {
                   13630:     my ($url)   = @_;
1.238     raeburn  13631:     my @urlslices = split(/\//, $url,-1);
1.369     www      13632:     my $lastitem = &escape(pop(@urlslices));
1.223     albertel 13633:     return join('/',@urlslices).'/'.$lastitem;
1.222     foxr     13634: }
1.462     albertel 13635: 
1.820     raeburn  13636: sub compare_arrays {
                   13637:     my ($arrayref1,$arrayref2) = @_;
                   13638:     my (@difference,%count);
                   13639:     @difference = ();
                   13640:     %count = ();
                   13641:     if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
                   13642:         foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
                   13643:         foreach my $element (keys(%count)) {
                   13644:             if ($count{$element} == 1) {
                   13645:                 push(@difference,$element);
                   13646:             }
                   13647:         }
                   13648:     }
                   13649:     return @difference;
                   13650: }
                   13651: 
1.817     bisitz   13652: # -------------------------------------------------------- Initialize user login
1.462     albertel 13653: sub init_user_environment {
1.463     albertel 13654:     my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462     albertel 13655:     my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
                   13656: 
                   13657:     my $public=($username eq 'public' && $domain eq 'public');
                   13658: 
                   13659: # See if old ID present, if so, remove
                   13660: 
1.1062    raeburn  13661:     my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462     albertel 13662:     my $now=time;
                   13663: 
                   13664:     if ($public) {
                   13665: 	my $max_public=100;
                   13666: 	my $oldest;
                   13667: 	my $oldest_time=0;
                   13668: 	for(my $next=1;$next<=$max_public;$next++) {
                   13669: 	    if (-e $lonids."/publicuser_$next.id") {
                   13670: 		my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
                   13671: 		if ($mtime<$oldest_time || !$oldest_time) {
                   13672: 		    $oldest_time=$mtime;
                   13673: 		    $oldest=$next;
                   13674: 		}
                   13675: 	    } else {
                   13676: 		$cookie="publicuser_$next";
                   13677: 		last;
                   13678: 	    }
                   13679: 	}
                   13680: 	if (!$cookie) { $cookie="publicuser_$oldest"; }
                   13681:     } else {
1.463     albertel 13682: 	# if this isn't a robot, kill any existing non-robot sessions
                   13683: 	if (!$args->{'robot'}) {
                   13684: 	    opendir(DIR,$lonids);
                   13685: 	    while ($filename=readdir(DIR)) {
                   13686: 		if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
                   13687: 		    unlink($lonids.'/'.$filename);
                   13688: 		}
1.462     albertel 13689: 	    }
1.463     albertel 13690: 	    closedir(DIR);
1.462     albertel 13691: 	}
                   13692: # Give them a new cookie
1.463     albertel 13693: 	my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684     www      13694: 		                   : $now.$$.int(rand(10000)));
1.463     albertel 13695: 	$cookie="$username\_$id\_$domain\_$authhost";
1.462     albertel 13696:     
                   13697: # Initialize roles
                   13698: 
1.1062    raeburn  13699: 	($userroles,$firstaccenv,$timerintenv) = 
                   13700:             &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462     albertel 13701:     }
                   13702: # ------------------------------------ Check browser type and MathML capability
                   13703: 
                   13704:     my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   13705:         $clientunicode,$clientos) = &decode_user_agent($r);
                   13706: 
                   13707: # ------------------------------------------------------------- Get environment
                   13708: 
                   13709:     my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
                   13710:     my ($tmp) = keys(%userenv);
                   13711:     if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   13712:     } else {
                   13713: 	undef(%userenv);
                   13714:     }
                   13715:     if (($userenv{'interface'}) && (!$form->{'interface'})) {
                   13716: 	$form->{'interface'}=$userenv{'interface'};
                   13717:     }
                   13718:     if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
                   13719: 
                   13720: # --------------- Do not trust query string to be put directly into environment
1.817     bisitz   13721:     foreach my $option ('interface','localpath','localres') {
                   13722:         $form->{$option}=~s/[\n\r\=]//gs;
1.462     albertel 13723:     }
                   13724: # --------------------------------------------------------- Write first profile
                   13725: 
                   13726:     {
                   13727: 	my %initial_env = 
                   13728: 	    ("user.name"          => $username,
                   13729: 	     "user.domain"        => $domain,
                   13730: 	     "user.home"          => $authhost,
                   13731: 	     "browser.type"       => $clientbrowser,
                   13732: 	     "browser.version"    => $clientversion,
                   13733: 	     "browser.mathml"     => $clientmathml,
                   13734: 	     "browser.unicode"    => $clientunicode,
                   13735: 	     "browser.os"         => $clientos,
                   13736: 	     "server.domain"      => $Apache::lonnet::perlvar{'lonDefDomain'},
                   13737: 	     "request.course.fn"  => '',
                   13738: 	     "request.course.uri" => '',
                   13739: 	     "request.course.sec" => '',
                   13740: 	     "request.role"       => 'cm',
                   13741: 	     "request.role.adv"   => $env{'user.adv'},
                   13742: 	     "request.host"       => $ENV{'REMOTE_ADDR'},);
                   13743: 
                   13744:         if ($form->{'localpath'}) {
                   13745: 	    $initial_env{"browser.localpath"}  = $form->{'localpath'};
                   13746: 	    $initial_env{"browser.localres"}   = $form->{'localres'};
                   13747:         }
                   13748: 	
                   13749: 	if ($form->{'interface'}) {
                   13750: 	    $form->{'interface'}=~s/\W//gs;
                   13751: 	    $initial_env{"browser.interface"} = $form->{'interface'};
                   13752: 	    $env{'browser.interface'}=$form->{'interface'};
                   13753: 	}
                   13754: 
1.981     raeburn  13755:         my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016    raeburn  13756:         my %domdef;
                   13757:         unless ($domain eq 'public') {
                   13758:             %domdef = &Apache::lonnet::get_domain_defaults($domain);
                   13759:         }
1.980     raeburn  13760: 
1.1075.2.7  raeburn  13761:         foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724     raeburn  13762:             $userenv{'availabletools.'.$tool} = 
1.980     raeburn  13763:                 &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
                   13764:                                                   undef,\%userenv,\%domdef,\%is_adv);
1.724     raeburn  13765:         }
                   13766: 
1.864     raeburn  13767:         foreach my $crstype ('official','unofficial','community') {
1.765     raeburn  13768:             $userenv{'canrequest.'.$crstype} =
                   13769:                 &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980     raeburn  13770:                                                   'reload','requestcourses',
                   13771:                                                   \%userenv,\%domdef,\%is_adv);
1.765     raeburn  13772:         }
                   13773: 
1.462     albertel 13774: 	$env{'user.environment'} = "$lonids/$cookie.id";
1.1062    raeburn  13775: 
1.462     albertel 13776: 	if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
                   13777: 		 &GDBM_WRCREAT(),0640)) {
                   13778: 	    &_add_to_env(\%disk_env,\%initial_env);
                   13779: 	    &_add_to_env(\%disk_env,\%userenv,'environment.');
                   13780: 	    &_add_to_env(\%disk_env,$userroles);
1.1062    raeburn  13781:             if (ref($firstaccenv) eq 'HASH') {
                   13782:                 &_add_to_env(\%disk_env,$firstaccenv);
                   13783:             }
                   13784:             if (ref($timerintenv) eq 'HASH') {
                   13785:                 &_add_to_env(\%disk_env,$timerintenv);
                   13786:             }
1.463     albertel 13787: 	    if (ref($args->{'extra_env'})) {
                   13788: 		&_add_to_env(\%disk_env,$args->{'extra_env'});
                   13789: 	    }
1.462     albertel 13790: 	    untie(%disk_env);
                   13791: 	} else {
1.705     tempelho 13792: 	    &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
                   13793: 			   'Could not create environment storage in lonauth: '.$!.'</span>');
1.462     albertel 13794: 	    return 'error: '.$!;
                   13795: 	}
                   13796:     }
                   13797:     $env{'request.role'}='cm';
                   13798:     $env{'request.role.adv'}=$env{'user.adv'};
                   13799:     $env{'browser.type'}=$clientbrowser;
                   13800: 
                   13801:     return $cookie;
                   13802: 
                   13803: }
                   13804: 
                   13805: sub _add_to_env {
                   13806:     my ($idf,$env_data,$prefix) = @_;
1.676     raeburn  13807:     if (ref($env_data) eq 'HASH') {
                   13808:         while (my ($key,$value) = each(%$env_data)) {
                   13809: 	    $idf->{$prefix.$key} = $value;
                   13810: 	    $env{$prefix.$key}   = $value;
                   13811:         }
1.462     albertel 13812:     }
                   13813: }
                   13814: 
1.685     tempelho 13815: # --- Get the symbolic name of a problem and the url
                   13816: sub get_symb {
                   13817:     my ($request,$silent) = @_;
1.726     raeburn  13818:     (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685     tempelho 13819:     my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
                   13820:     if ($symb eq '') {
                   13821:         if (!$silent) {
1.1071    raeburn  13822:             if (ref($request)) { 
                   13823:                 $request->print("Unable to handle ambiguous references:$url:.");
                   13824:             }
1.685     tempelho 13825:             return ();
                   13826:         }
                   13827:     }
                   13828:     &Apache::lonenc::check_decrypt(\$symb);
                   13829:     return ($symb);
                   13830: }
                   13831: 
                   13832: # --------------------------------------------------------------Get annotation
                   13833: 
                   13834: sub get_annotation {
                   13835:     my ($symb,$enc) = @_;
                   13836: 
                   13837:     my $key = $symb;
                   13838:     if (!$enc) {
                   13839:         $key =
                   13840:             &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
                   13841:     }
                   13842:     my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
                   13843:     return $annotation{$key};
                   13844: }
                   13845: 
                   13846: sub clean_symb {
1.731     raeburn  13847:     my ($symb,$delete_enc) = @_;
1.685     tempelho 13848: 
                   13849:     &Apache::lonenc::check_decrypt(\$symb);
                   13850:     my $enc = $env{'request.enc'};
1.731     raeburn  13851:     if ($delete_enc) {
1.730     raeburn  13852:         delete($env{'request.enc'});
                   13853:     }
1.685     tempelho 13854: 
                   13855:     return ($symb,$enc);
                   13856: }
1.462     albertel 13857: 
1.990     raeburn  13858: sub build_release_hashes {
                   13859:     my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
                   13860:     return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
                   13861:                   (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
                   13862:                   (ref($randomizetry) eq 'HASH'));
                   13863:     foreach my $key (keys(%Apache::lonnet::needsrelease)) {
                   13864:         my ($item,$name,$value) = split(/:/,$key);
                   13865:         if ($item eq 'parameter') {
                   13866:             if (ref($checkparms->{$name}) eq 'ARRAY') {
                   13867:                 unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
                   13868:                     push(@{$checkparms->{$name}},$value);
                   13869:                 }
                   13870:             } else {
                   13871:                 push(@{$checkparms->{$name}},$value);
                   13872:             }
                   13873:         } elsif ($item eq 'resourcetag') {
                   13874:             if ($name eq 'responsetype') {
                   13875:                 $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
                   13876:             }
                   13877:         } elsif ($item eq 'course') {
                   13878:             if ($name eq 'crstype') {
                   13879:                 $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
                   13880:             }
                   13881:         }
                   13882:     }
                   13883:     ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
                   13884:     ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
                   13885:     return;
                   13886: }
                   13887: 
1.41      ng       13888: =pod
                   13889: 
                   13890: =back
                   13891: 
1.112     bowersj2 13892: =cut
1.41      ng       13893: 
1.112     bowersj2 13894: 1;
                   13895: __END__;
1.41      ng       13896: 

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