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

1.10      albertel    1: # The LearningOnline Network with CAPA
1.1       albertel    2: # a pile of common routines
1.10      albertel    3: #
1.1055  ! raeburn     4: # $Id: loncommon.pm,v 1.1054 2012/01/16 18:04:20 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.430     albertel 1377:     caller.document.writeln('$start_page<frame name="bannerframe"  src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $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: 
                   1751: =cut
                   1752: 
                   1753: ###############################################################
                   1754: ###############################################################
                   1755: sub define_excel_formats {
                   1756:     my ($workbook) = @_;
                   1757:     my $format;
                   1758:     $format->{'header'} = $workbook->add_format(bold      => 1, 
                   1759:                                                 bottom    => 1,
                   1760:                                                 align     => 'center');
                   1761:     $format->{'bold'} = $workbook->add_format(bold=>1);
                   1762:     $format->{'h1'}   = $workbook->add_format(bold=>1, size=>18);
                   1763:     $format->{'h2'}   = $workbook->add_format(bold=>1, size=>16);
                   1764:     $format->{'h3'}   = $workbook->add_format(bold=>1, size=>14);
1.255     matthew  1765:     $format->{'h4'}   = $workbook->add_format(bold=>1, size=>12);
1.246     matthew  1766:     $format->{'i'}    = $workbook->add_format(italic=>1);
1.180     matthew  1767:     $format->{'date'} = $workbook->add_format(num_format=>
1.207     matthew  1768:                                             'mm/dd/yyyy hh:mm:ss');
1.180     matthew  1769:     return $format;
                   1770: }
                   1771: 
                   1772: ###############################################################
                   1773: ###############################################################
1.113     bowersj2 1774: 
                   1775: =pod
                   1776: 
1.648     raeburn  1777: =item * &create_workbook()
1.255     matthew  1778: 
                   1779: Create an Excel worksheet.  If it fails, output message on the
                   1780: request object and return undefs.
                   1781: 
                   1782: Inputs: Apache request object
                   1783: 
                   1784: Returns (undef) on failure, 
                   1785:     Excel worksheet object, scalar with filename, and formats 
                   1786:     from &Apache::loncommon::define_excel_formats on success
                   1787: 
                   1788: =cut
                   1789: 
                   1790: ###############################################################
                   1791: ###############################################################
                   1792: sub create_workbook {
                   1793:     my ($r) = @_;
                   1794:         #
                   1795:     # Create the excel spreadsheet
                   1796:     my $filename = '/prtspool/'.
1.258     albertel 1797:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255     matthew  1798:         time.'_'.rand(1000000000).'.xls';
                   1799:     my $workbook  = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
                   1800:     if (! defined($workbook)) {
                   1801:         $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928     bisitz   1802:         $r->print(
                   1803:             '<p class="LC_error">'
                   1804:            .&mt('Problems occurred in creating the new Excel file.')
                   1805:            .' '.&mt('This error has been logged.')
                   1806:            .' '.&mt('Please alert your LON-CAPA administrator.')
                   1807:            .'</p>'
                   1808:         );
1.255     matthew  1809:         return (undef);
                   1810:     }
                   1811:     #
1.1014    foxr     1812:     $workbook->set_tempdir(LONCAPA::tempdir());
1.255     matthew  1813:     #
                   1814:     my $format = &Apache::loncommon::define_excel_formats($workbook);
                   1815:     return ($workbook,$filename,$format);
                   1816: }
                   1817: 
                   1818: ###############################################################
                   1819: ###############################################################
                   1820: 
                   1821: =pod
                   1822: 
1.648     raeburn  1823: =item * &create_text_file()
1.113     bowersj2 1824: 
1.542     raeburn  1825: Create a file to write to and eventually make available to the user.
1.256     matthew  1826: If file creation fails, outputs an error message on the request object and 
                   1827: return undefs.
1.113     bowersj2 1828: 
1.256     matthew  1829: Inputs: Apache request object, and file suffix
1.113     bowersj2 1830: 
1.256     matthew  1831: Returns (undef) on failure, 
                   1832:     Filehandle and filename on success.
1.113     bowersj2 1833: 
                   1834: =cut
                   1835: 
1.256     matthew  1836: ###############################################################
                   1837: ###############################################################
                   1838: sub create_text_file {
                   1839:     my ($r,$suffix) = @_;
                   1840:     if (! defined($suffix)) { $suffix = 'txt'; };
                   1841:     my $fh;
                   1842:     my $filename = '/prtspool/'.
1.258     albertel 1843:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256     matthew  1844:         time.'_'.rand(1000000000).'.'.$suffix;
                   1845:     $fh = Apache::File->new('>/home/httpd'.$filename);
                   1846:     if (! defined($fh)) {
                   1847:         $r->log_error("Couldn't open $filename for output $!");
1.928     bisitz   1848:         $r->print(
                   1849:             '<p class="LC_error">'
                   1850:            .&mt('Problems occurred in creating the output file.')
                   1851:            .' '.&mt('This error has been logged.')
                   1852:            .' '.&mt('Please alert your LON-CAPA administrator.')
                   1853:            .'</p>'
                   1854:         );
1.113     bowersj2 1855:     }
1.256     matthew  1856:     return ($fh,$filename)
1.113     bowersj2 1857: }
                   1858: 
                   1859: 
1.256     matthew  1860: =pod 
1.113     bowersj2 1861: 
                   1862: =back
                   1863: 
                   1864: =cut
1.37      matthew  1865: 
                   1866: ###############################################################
1.33      matthew  1867: ##        Home server <option> list generating code          ##
                   1868: ###############################################################
1.35      matthew  1869: 
1.169     www      1870: # ------------------------------------------
                   1871: 
                   1872: sub domain_select {
                   1873:     my ($name,$value,$multiple)=@_;
                   1874:     my %domains=map { 
1.514     albertel 1875: 	$_ => $_.' '. &Apache::lonnet::domain($_,'description') 
1.512     albertel 1876:     } &Apache::lonnet::all_domains();
1.169     www      1877:     if ($multiple) {
                   1878: 	$domains{''}=&mt('Any domain');
1.550     albertel 1879: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287     albertel 1880: 	return &multiple_select_form($name,$value,4,\%domains);
1.169     www      1881:     } else {
1.550     albertel 1882: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970     raeburn  1883: 	return &select_form($name,$value,\%domains);
1.169     www      1884:     }
                   1885: }
                   1886: 
1.282     albertel 1887: #-------------------------------------------
                   1888: 
                   1889: =pod
                   1890: 
1.519     raeburn  1891: =head1 Routines for form select boxes
                   1892: 
                   1893: =over 4
                   1894: 
1.648     raeburn  1895: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282     albertel 1896: 
                   1897: Returns a string containing a <select> element int multiple mode
                   1898: 
                   1899: 
                   1900: Args:
                   1901:   $name - name of the <select> element
1.506     raeburn  1902:   $value - scalar or array ref of values that should already be selected
1.282     albertel 1903:   $size - number of rows long the select element is
1.283     albertel 1904:   $hash - the elements should be 'option' => 'shown text'
1.282     albertel 1905:           (shown text should already have been &mt())
1.506     raeburn  1906:   $order - (optional) array ref of the order to show the elements in
1.283     albertel 1907: 
1.282     albertel 1908: =cut
                   1909: 
                   1910: #-------------------------------------------
1.169     www      1911: sub multiple_select_form {
1.284     albertel 1912:     my ($name,$value,$size,$hash,$order)=@_;
1.169     www      1913:     my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
                   1914:     my $output='';
1.191     matthew  1915:     if (! defined($size)) {
                   1916:         $size = 4;
1.283     albertel 1917:         if (scalar(keys(%$hash))<4) {
                   1918:             $size = scalar(keys(%$hash));
1.191     matthew  1919:         }
                   1920:     }
1.734     bisitz   1921:     $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501     banghart 1922:     my @order;
1.506     raeburn  1923:     if (ref($order) eq 'ARRAY')  {
                   1924:         @order = @{$order};
                   1925:     } else {
                   1926:         @order = sort(keys(%$hash));
1.501     banghart 1927:     }
                   1928:     if (exists($$hash{'select_form_order'})) {
                   1929:         @order = @{$$hash{'select_form_order'}};
                   1930:     }
                   1931:         
1.284     albertel 1932:     foreach my $key (@order) {
1.356     albertel 1933:         $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284     albertel 1934:         $output.='selected="selected" ' if ($selected{$key});
                   1935:         $output.='>'.$hash->{$key}."</option>\n";
1.169     www      1936:     }
                   1937:     $output.="</select>\n";
                   1938:     return $output;
                   1939: }
                   1940: 
1.88      www      1941: #-------------------------------------------
                   1942: 
                   1943: =pod
                   1944: 
1.970     raeburn  1945: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88      www      1946: 
                   1947: Returns a string containing a <select name='$name' size='1'> form to 
1.970     raeburn  1948: allow a user to select options from a ref to a hash containing:
                   1949: option_name => displayed text. An optional $onchange can include
                   1950: a javascript onchange item, e.g., onchange="this.form.submit();"  
                   1951: 
1.88      www      1952: See lonrights.pm for an example invocation and use.
                   1953: 
                   1954: =cut
                   1955: 
                   1956: #-------------------------------------------
                   1957: sub select_form {
1.970     raeburn  1958:     my ($def,$name,$hashref,$onchange) = @_;
                   1959:     return unless (ref($hashref) eq 'HASH');
                   1960:     if ($onchange) {
                   1961:         $onchange = ' onchange="'.$onchange.'"';
                   1962:     }
                   1963:     my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128     albertel 1964:     my @keys;
1.970     raeburn  1965:     if (exists($hashref->{'select_form_order'})) {
                   1966: 	@keys=@{$hashref->{'select_form_order'}};
1.128     albertel 1967:     } else {
1.970     raeburn  1968: 	@keys=sort(keys(%{$hashref}));
1.128     albertel 1969:     }
1.356     albertel 1970:     foreach my $key (@keys) {
                   1971:         $selectform.=
                   1972: 	    '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
                   1973:             ($key eq $def ? 'selected="selected" ' : '').
1.970     raeburn  1974:                 ">".$hashref->{$key}."</option>\n";
1.88      www      1975:     }
                   1976:     $selectform.="</select>";
                   1977:     return $selectform;
                   1978: }
                   1979: 
1.475     www      1980: # For display filters
                   1981: 
                   1982: sub display_filter {
                   1983:     if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477     www      1984:     if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714     bisitz   1985:     return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475     www      1986: 			       &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
                   1987: 							   (&mt('all'),10,20,50,100,1000,10000))).
1.714     bisitz   1988: 	   '</label></span> <span class="LC_nobreak">'.
1.475     www      1989:            &mt('Filter [_1]',
1.477     www      1990: 	   &select_form($env{'form.displayfilter'},
                   1991: 			'displayfilter',
1.970     raeburn  1992: 			{'currentfolder' => 'Current folder/page',
1.477     www      1993: 			 'containing' => 'Containing phrase',
1.970     raeburn  1994: 			 'none' => 'None'})).
1.714     bisitz   1995: 			 '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475     www      1996: }
                   1997: 
1.167     www      1998: sub gradeleveldescription {
                   1999:     my $gradelevel=shift;
                   2000:     my %gradelevels=(0 => 'Not specified',
                   2001: 		     1 => 'Grade 1',
                   2002: 		     2 => 'Grade 2',
                   2003: 		     3 => 'Grade 3',
                   2004: 		     4 => 'Grade 4',
                   2005: 		     5 => 'Grade 5',
                   2006: 		     6 => 'Grade 6',
                   2007: 		     7 => 'Grade 7',
                   2008: 		     8 => 'Grade 8',
                   2009: 		     9 => 'Grade 9',
                   2010: 		     10 => 'Grade 10',
                   2011: 		     11 => 'Grade 11',
                   2012: 		     12 => 'Grade 12',
                   2013: 		     13 => 'Grade 13',
                   2014: 		     14 => '100 Level',
                   2015: 		     15 => '200 Level',
                   2016: 		     16 => '300 Level',
                   2017: 		     17 => '400 Level',
                   2018: 		     18 => 'Graduate Level');
                   2019:     return &mt($gradelevels{$gradelevel});
                   2020: }
                   2021: 
1.163     www      2022: sub select_level_form {
                   2023:     my ($deflevel,$name)=@_;
                   2024:     unless ($deflevel) { $deflevel=0; }
1.167     www      2025:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
                   2026:     for (my $i=0; $i<=18; $i++) {
                   2027:         $selectform.="<option value=\"$i\" ".
1.253     albertel 2028:             ($i==$deflevel ? 'selected="selected" ' : '').
1.167     www      2029:                 ">".&gradeleveldescription($i)."</option>\n";
                   2030:     }
                   2031:     $selectform.="</select>";
                   2032:     return $selectform;
1.163     www      2033: }
1.167     www      2034: 
1.35      matthew  2035: #-------------------------------------------
                   2036: 
1.45      matthew  2037: =pod
                   2038: 
1.910     raeburn  2039: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms)
1.35      matthew  2040: 
                   2041: Returns a string containing a <select name='$name' size='1'> form to 
                   2042: allow a user to select the domain to preform an operation in.  
                   2043: See loncreateuser.pm for an example invocation and use.
                   2044: 
1.90      www      2045: If the $includeempty flag is set, it also includes an empty choice ("no domain
                   2046: selected");
                   2047: 
1.743     raeburn  2048: If the $showdomdesc flag is set, the domain name is followed by the domain description.
                   2049: 
1.910     raeburn  2050: 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.
                   2051: 
                   2052: The optional $incdoms is a reference to an array of domains which will be the only available options. 
1.563     raeburn  2053: 
1.35      matthew  2054: =cut
                   2055: 
                   2056: #-------------------------------------------
1.34      matthew  2057: sub select_dom_form {
1.910     raeburn  2058:     my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms) = @_;
1.872     raeburn  2059:     if ($onchange) {
1.874     raeburn  2060:         $onchange = ' onchange="'.$onchange.'"';
1.743     raeburn  2061:     }
1.910     raeburn  2062:     my @domains;
                   2063:     if (ref($incdoms) eq 'ARRAY') {
                   2064:         @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
                   2065:     } else {
                   2066:         @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
                   2067:     }
1.90      www      2068:     if ($includeempty) { @domains=('',@domains); }
1.743     raeburn  2069:     my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356     albertel 2070:     foreach my $dom (@domains) {
                   2071:         $selectdomain.="<option value=\"$dom\" ".
1.563     raeburn  2072:             ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
                   2073:         if ($showdomdesc) {
                   2074:             if ($dom ne '') {
                   2075:                 my $domdesc = &Apache::lonnet::domain($dom,'description');
                   2076:                 if ($domdesc ne '') {
                   2077:                     $selectdomain .= ' ('.$domdesc.')';
                   2078:                 }
                   2079:             } 
                   2080:         }
                   2081:         $selectdomain .= "</option>\n";
1.34      matthew  2082:     }
                   2083:     $selectdomain.="</select>";
                   2084:     return $selectdomain;
                   2085: }
                   2086: 
1.35      matthew  2087: #-------------------------------------------
                   2088: 
1.45      matthew  2089: =pod
                   2090: 
1.648     raeburn  2091: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35      matthew  2092: 
1.586     raeburn  2093: input: 4 arguments (two required, two optional) - 
                   2094:     $domain - domain of new user
                   2095:     $name - name of form element
                   2096:     $default - Value of 'default' causes a default item to be first 
                   2097:                             option, and selected by default. 
                   2098:     $hide - Value of 'hide' causes hiding of the name of the server, 
                   2099:                             if 1 server found, or default, if 0 found.
1.594     raeburn  2100: output: returns 2 items: 
1.586     raeburn  2101: (a) form element which contains either:
                   2102:    (i) <select name="$name">
                   2103:         <option value="$hostid1">$hostid $servers{$hostid}</option>
                   2104:         <option value="$hostid2">$hostid $servers{$hostid}</option>       
                   2105:        </select>
                   2106:        form item if there are multiple library servers in $domain, or
                   2107:    (ii) an <input type="hidden" name="$name" value="$hostid" /> form item 
                   2108:        if there is only one library server in $domain.
                   2109: 
                   2110: (b) number of library servers found.
                   2111: 
                   2112: See loncreateuser.pm for example of use.
1.35      matthew  2113: 
                   2114: =cut
                   2115: 
                   2116: #-------------------------------------------
1.586     raeburn  2117: sub home_server_form_item {
                   2118:     my ($domain,$name,$default,$hide) = @_;
1.513     albertel 2119:     my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586     raeburn  2120:     my $result;
                   2121:     my $numlib = keys(%servers);
                   2122:     if ($numlib > 1) {
                   2123:         $result .= '<select name="'.$name.'" />'."\n";
                   2124:         if ($default) {
1.804     bisitz   2125:             $result .= '<option value="default" selected="selected">'.&mt('default').
1.586     raeburn  2126:                        '</option>'."\n";
                   2127:         }
                   2128:         foreach my $hostid (sort(keys(%servers))) {
                   2129:             $result.= '<option value="'.$hostid.'">'.
                   2130: 	              $hostid.' '.$servers{$hostid}."</option>\n";
                   2131:         }
                   2132:         $result .= '</select>'."\n";
                   2133:     } elsif ($numlib == 1) {
                   2134:         my $hostid;
                   2135:         foreach my $item (keys(%servers)) {
                   2136:             $hostid = $item;
                   2137:         }
                   2138:         $result .= '<input type="hidden" name="'.$name.'" value="'.
                   2139:                    $hostid.'" />';
                   2140:                    if (!$hide) {
                   2141:                        $result .= $hostid.' '.$servers{$hostid};
                   2142:                    }
                   2143:                    $result .= "\n";
                   2144:     } elsif ($default) {
                   2145:         $result .= '<input type="hidden" name="'.$name.
                   2146:                    '" value="default" />';
                   2147:                    if (!$hide) {
                   2148:                        $result .= &mt('default');
                   2149:                    }
                   2150:                    $result .= "\n";
1.33      matthew  2151:     }
1.586     raeburn  2152:     return ($result,$numlib);
1.33      matthew  2153: }
1.112     bowersj2 2154: 
                   2155: =pod
                   2156: 
1.534     albertel 2157: =back 
                   2158: 
1.112     bowersj2 2159: =cut
1.87      matthew  2160: 
                   2161: ###############################################################
1.112     bowersj2 2162: ##                  Decoding User Agent                      ##
1.87      matthew  2163: ###############################################################
                   2164: 
                   2165: =pod
                   2166: 
1.112     bowersj2 2167: =head1 Decoding the User Agent
                   2168: 
                   2169: =over 4
                   2170: 
                   2171: =item * &decode_user_agent()
1.87      matthew  2172: 
                   2173: Inputs: $r
                   2174: 
                   2175: Outputs:
                   2176: 
                   2177: =over 4
                   2178: 
1.112     bowersj2 2179: =item * $httpbrowser
1.87      matthew  2180: 
1.112     bowersj2 2181: =item * $clientbrowser
1.87      matthew  2182: 
1.112     bowersj2 2183: =item * $clientversion
1.87      matthew  2184: 
1.112     bowersj2 2185: =item * $clientmathml
1.87      matthew  2186: 
1.112     bowersj2 2187: =item * $clientunicode
1.87      matthew  2188: 
1.112     bowersj2 2189: =item * $clientos
1.87      matthew  2190: 
                   2191: =back
                   2192: 
1.157     matthew  2193: =back 
                   2194: 
1.87      matthew  2195: =cut
                   2196: 
                   2197: ###############################################################
                   2198: ###############################################################
                   2199: sub decode_user_agent {
1.247     albertel 2200:     my ($r)=@_;
1.87      matthew  2201:     my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
                   2202:     my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
                   2203:     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247     albertel 2204:     if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87      matthew  2205:     my $clientbrowser='unknown';
                   2206:     my $clientversion='0';
                   2207:     my $clientmathml='';
                   2208:     my $clientunicode='0';
                   2209:     for (my $i=0;$i<=$#browsertype;$i++) {
                   2210:         my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
                   2211: 	if (($httpbrowser=~/$match/i)  && ($httpbrowser!~/$notmatch/i)) {
                   2212: 	    $clientbrowser=$bname;
                   2213:             $httpbrowser=~/$vreg/i;
                   2214: 	    $clientversion=$1;
                   2215:             $clientmathml=($clientversion>=$minv);
                   2216:             $clientunicode=($clientversion>=$univ);
                   2217: 	}
                   2218:     }
                   2219:     my $clientos='unknown';
                   2220:     if (($httpbrowser=~/linux/i) ||
                   2221:         ($httpbrowser=~/unix/i) ||
                   2222:         ($httpbrowser=~/ux/i) ||
                   2223:         ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
                   2224:     if (($httpbrowser=~/vax/i) ||
                   2225:         ($httpbrowser=~/vms/i)) { $clientos='vms'; }
                   2226:     if ($httpbrowser=~/next/i) { $clientos='next'; }
                   2227:     if (($httpbrowser=~/mac/i) ||
                   2228:         ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
                   2229:     if ($httpbrowser=~/win/i) { $clientos='win'; }
                   2230:     if ($httpbrowser=~/embed/i) { $clientos='pda'; }
                   2231:     return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   2232:             $clientunicode,$clientos,);
                   2233: }
                   2234: 
1.32      matthew  2235: ###############################################################
                   2236: ##    Authentication changing form generation subroutines    ##
                   2237: ###############################################################
                   2238: ##
                   2239: ## All of the authform_xxxxxxx subroutines take their inputs in a
                   2240: ## hash, and have reasonable default values.
                   2241: ##
                   2242: ##    formname = the name given in the <form> tag.
1.35      matthew  2243: #-------------------------------------------
                   2244: 
1.45      matthew  2245: =pod
                   2246: 
1.112     bowersj2 2247: =head1 Authentication Routines
                   2248: 
                   2249: =over 4
                   2250: 
1.648     raeburn  2251: =item * &authform_xxxxxx()
1.35      matthew  2252: 
                   2253: The authform_xxxxxx subroutines provide javascript and html forms which 
                   2254: handle some of the conveniences required for authentication forms.  
                   2255: This is not an optimal method, but it works.  
                   2256: 
                   2257: =over 4
                   2258: 
1.112     bowersj2 2259: =item * authform_header
1.35      matthew  2260: 
1.112     bowersj2 2261: =item * authform_authorwarning
1.35      matthew  2262: 
1.112     bowersj2 2263: =item * authform_nochange
1.35      matthew  2264: 
1.112     bowersj2 2265: =item * authform_kerberos
1.35      matthew  2266: 
1.112     bowersj2 2267: =item * authform_internal
1.35      matthew  2268: 
1.112     bowersj2 2269: =item * authform_filesystem
1.35      matthew  2270: 
                   2271: =back
                   2272: 
1.648     raeburn  2273: See loncreateuser.pm for invocation and use examples.
1.157     matthew  2274: 
1.35      matthew  2275: =cut
                   2276: 
                   2277: #-------------------------------------------
1.32      matthew  2278: sub authform_header{  
                   2279:     my %in = (
                   2280:         formname => 'cu',
1.80      albertel 2281:         kerb_def_dom => '',
1.32      matthew  2282:         @_,
                   2283:     );
                   2284:     $in{'formname'} = 'document.' . $in{'formname'};
                   2285:     my $result='';
1.80      albertel 2286: 
                   2287: #---------------------------------------------- Code for upper case translation
                   2288:     my $Javascript_toUpperCase;
                   2289:     unless ($in{kerb_def_dom}) {
                   2290:         $Javascript_toUpperCase =<<"END";
                   2291:         switch (choice) {
                   2292:            case 'krb': currentform.elements[choicearg].value =
                   2293:                currentform.elements[choicearg].value.toUpperCase();
                   2294:                break;
                   2295:            default:
                   2296:         }
                   2297: END
                   2298:     } else {
                   2299:         $Javascript_toUpperCase = "";
                   2300:     }
                   2301: 
1.165     raeburn  2302:     my $radioval = "'nochange'";
1.591     raeburn  2303:     if (defined($in{'curr_authtype'})) {
                   2304:         if ($in{'curr_authtype'} ne '') {
                   2305:             $radioval = "'".$in{'curr_authtype'}."arg'";
                   2306:         }
1.174     matthew  2307:     }
1.165     raeburn  2308:     my $argfield = 'null';
1.591     raeburn  2309:     if (defined($in{'mode'})) {
1.165     raeburn  2310:         if ($in{'mode'} eq 'modifycourse')  {
1.591     raeburn  2311:             if (defined($in{'curr_autharg'})) {
                   2312:                 if ($in{'curr_autharg'} ne '') {
1.165     raeburn  2313:                     $argfield = "'$in{'curr_autharg'}'";
                   2314:                 }
                   2315:             }
                   2316:         }
                   2317:     }
                   2318: 
1.32      matthew  2319:     $result.=<<"END";
                   2320: var current = new Object();
1.165     raeburn  2321: current.radiovalue = $radioval;
                   2322: current.argfield = $argfield;
1.32      matthew  2323: 
                   2324: function changed_radio(choice,currentform) {
                   2325:     var choicearg = choice + 'arg';
                   2326:     // If a radio button in changed, we need to change the argfield
                   2327:     if (current.radiovalue != choice) {
                   2328:         current.radiovalue = choice;
                   2329:         if (current.argfield != null) {
                   2330:             currentform.elements[current.argfield].value = '';
                   2331:         }
                   2332:         if (choice == 'nochange') {
                   2333:             current.argfield = null;
                   2334:         } else {
                   2335:             current.argfield = choicearg;
                   2336:             switch(choice) {
                   2337:                 case 'krb': 
                   2338:                     currentform.elements[current.argfield].value = 
                   2339:                         "$in{'kerb_def_dom'}";
                   2340:                 break;
                   2341:               default:
                   2342:                 break;
                   2343:             }
                   2344:         }
                   2345:     }
                   2346:     return;
                   2347: }
1.22      www      2348: 
1.32      matthew  2349: function changed_text(choice,currentform) {
                   2350:     var choicearg = choice + 'arg';
                   2351:     if (currentform.elements[choicearg].value !='') {
1.80      albertel 2352:         $Javascript_toUpperCase
1.32      matthew  2353:         // clear old field
                   2354:         if ((current.argfield != choicearg) && (current.argfield != null)) {
                   2355:             currentform.elements[current.argfield].value = '';
                   2356:         }
                   2357:         current.argfield = choicearg;
                   2358:     }
                   2359:     set_auth_radio_buttons(choice,currentform);
                   2360:     return;
1.20      www      2361: }
1.32      matthew  2362: 
                   2363: function set_auth_radio_buttons(newvalue,currentform) {
1.986     raeburn  2364:     var numauthchoices = currentform.login.length;
                   2365:     if (typeof numauthchoices  == "undefined") {
                   2366:         return;
                   2367:     } 
1.32      matthew  2368:     var i=0;
1.986     raeburn  2369:     while (i < numauthchoices) {
1.32      matthew  2370:         if (currentform.login[i].value == newvalue) { break; }
                   2371:         i++;
                   2372:     }
1.986     raeburn  2373:     if (i == numauthchoices) {
1.32      matthew  2374:         return;
                   2375:     }
                   2376:     current.radiovalue = newvalue;
                   2377:     currentform.login[i].checked = true;
                   2378:     return;
                   2379: }
                   2380: END
                   2381:     return $result;
                   2382: }
                   2383: 
                   2384: sub authform_authorwarning{
                   2385:     my $result='';
1.144     matthew  2386:     $result='<i>'.
                   2387:         &mt('As a general rule, only authors or co-authors should be '.
                   2388:             'filesystem authenticated '.
                   2389:             '(which allows access to the server filesystem).')."</i>\n";
1.32      matthew  2390:     return $result;
                   2391: }
                   2392: 
                   2393: sub authform_nochange{  
                   2394:     my %in = (
                   2395:               formname => 'document.cu',
                   2396:               kerb_def_dom => 'MSU.EDU',
                   2397:               @_,
                   2398:           );
1.586     raeburn  2399:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'}); 
                   2400:     my $result;
                   2401:     if (keys(%can_assign) == 0) {
                   2402:         $result = &mt('Under you current role you are not permitted to change login settings for this user');  
                   2403:     } else {
                   2404:         $result = '<label>'.&mt('[_1] Do not change login data',
                   2405:                   '<input type="radio" name="login" value="nochange" '.
                   2406:                   'checked="checked" onclick="'.
1.281     albertel 2407:             "javascript:changed_radio('nochange',$in{'formname'});".'" />').
                   2408: 	    '</label>';
1.586     raeburn  2409:     }
1.32      matthew  2410:     return $result;
                   2411: }
                   2412: 
1.591     raeburn  2413: sub authform_kerberos {
1.32      matthew  2414:     my %in = (
                   2415:               formname => 'document.cu',
                   2416:               kerb_def_dom => 'MSU.EDU',
1.80      albertel 2417:               kerb_def_auth => 'krb4',
1.32      matthew  2418:               @_,
                   2419:               );
1.586     raeburn  2420:     my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
                   2421:         $autharg,$jscall);
                   2422:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.80      albertel 2423:     if ($in{'kerb_def_auth'} eq 'krb5') {
1.772     bisitz   2424:        $check5 = ' checked="checked"';
1.80      albertel 2425:     } else {
1.772     bisitz   2426:        $check4 = ' checked="checked"';
1.80      albertel 2427:     }
1.165     raeburn  2428:     $krbarg = $in{'kerb_def_dom'};
1.591     raeburn  2429:     if (defined($in{'curr_authtype'})) {
                   2430:         if ($in{'curr_authtype'} eq 'krb') {
1.772     bisitz   2431:             $krbcheck = ' checked="checked"';
1.623     raeburn  2432:             if (defined($in{'mode'})) {
                   2433:                 if ($in{'mode'} eq 'modifyuser') {
                   2434:                     $krbcheck = '';
                   2435:                 }
                   2436:             }
1.591     raeburn  2437:             if (defined($in{'curr_kerb_ver'})) {
                   2438:                 if ($in{'curr_krb_ver'} eq '5') {
1.772     bisitz   2439:                     $check5 = ' checked="checked"';
1.591     raeburn  2440:                     $check4 = '';
                   2441:                 } else {
1.772     bisitz   2442:                     $check4 = ' checked="checked"';
1.591     raeburn  2443:                     $check5 = '';
                   2444:                 }
1.586     raeburn  2445:             }
1.591     raeburn  2446:             if (defined($in{'curr_autharg'})) {
1.165     raeburn  2447:                 $krbarg = $in{'curr_autharg'};
                   2448:             }
1.586     raeburn  2449:             if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591     raeburn  2450:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2451:                     $result = 
                   2452:     &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
                   2453:         $in{'curr_autharg'},$krbver);
                   2454:                 } else {
                   2455:                     $result =
                   2456:     &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
                   2457:                 }
                   2458:                 return $result; 
                   2459:             }
                   2460:         }
                   2461:     } else {
                   2462:         if ($authnum == 1) {
1.784     bisitz   2463:             $authtype = '<input type="hidden" name="login" value="krb" />';
1.165     raeburn  2464:         }
                   2465:     }
1.586     raeburn  2466:     if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
                   2467:         return;
1.587     raeburn  2468:     } elsif ($authtype eq '') {
1.591     raeburn  2469:         if (defined($in{'mode'})) {
1.587     raeburn  2470:             if ($in{'mode'} eq 'modifycourse') {
                   2471:                 if ($authnum == 1) {
1.784     bisitz   2472:                     $authtype = '<input type="hidden" name="login" value="krb" />';
1.587     raeburn  2473:                 }
                   2474:             }
                   2475:         }
1.586     raeburn  2476:     }
                   2477:     $jscall = "javascript:changed_radio('krb',$in{'formname'});";
                   2478:     if ($authtype eq '') {
                   2479:         $authtype = '<input type="radio" name="login" value="krb" '.
                   2480:                     'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
                   2481:                     $krbcheck.' />';
                   2482:     }
                   2483:     if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
                   2484:         ($can_assign{'krb4'} && !$can_assign{'krb5'} && 
                   2485:          $in{'curr_authtype'} eq 'krb5') ||
                   2486:         (!$can_assign{'krb4'} && $can_assign{'krb5'} && 
                   2487:          $in{'curr_authtype'} eq 'krb4')) {
                   2488:         $result .= &mt
1.144     matthew  2489:         ('[_1] Kerberos authenticated with domain [_2] '.
1.281     albertel 2490:          '[_3] Version 4 [_4] Version 5 [_5]',
1.586     raeburn  2491:          '<label>'.$authtype,
1.281     albertel 2492:          '</label><input type="text" size="10" name="krbarg" '.
1.165     raeburn  2493:              'value="'.$krbarg.'" '.
1.144     matthew  2494:              'onchange="'.$jscall.'" />',
1.281     albertel 2495:          '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
                   2496:          '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
                   2497: 	 '</label>');
1.586     raeburn  2498:     } elsif ($can_assign{'krb4'}) {
                   2499:         $result .= &mt
                   2500:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2501:          '[_3] Version 4 [_4]',
                   2502:          '<label>'.$authtype,
                   2503:          '</label><input type="text" size="10" name="krbarg" '.
                   2504:              'value="'.$krbarg.'" '.
                   2505:              'onchange="'.$jscall.'" />',
                   2506:          '<label><input type="hidden" name="krbver" value="4" />',
                   2507:          '</label>');
                   2508:     } elsif ($can_assign{'krb5'}) {
                   2509:         $result .= &mt
                   2510:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2511:          '[_3] Version 5 [_4]',
                   2512:          '<label>'.$authtype,
                   2513:          '</label><input type="text" size="10" name="krbarg" '.
                   2514:              'value="'.$krbarg.'" '.
                   2515:              'onchange="'.$jscall.'" />',
                   2516:          '<label><input type="hidden" name="krbver" value="5" />',
                   2517:          '</label>');
                   2518:     }
1.32      matthew  2519:     return $result;
                   2520: }
                   2521: 
                   2522: sub authform_internal{  
1.586     raeburn  2523:     my %in = (
1.32      matthew  2524:                 formname => 'document.cu',
                   2525:                 kerb_def_dom => 'MSU.EDU',
                   2526:                 @_,
                   2527:                 );
1.586     raeburn  2528:     my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
                   2529:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2530:     if (defined($in{'curr_authtype'})) {
                   2531:         if ($in{'curr_authtype'} eq 'int') {
1.586     raeburn  2532:             if ($can_assign{'int'}) {
1.772     bisitz   2533:                 $intcheck = 'checked="checked" ';
1.623     raeburn  2534:                 if (defined($in{'mode'})) {
                   2535:                     if ($in{'mode'} eq 'modifyuser') {
                   2536:                         $intcheck = '';
                   2537:                     }
                   2538:                 }
1.591     raeburn  2539:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2540:                     $intarg = $in{'curr_autharg'};
                   2541:                 }
                   2542:             } else {
                   2543:                 $result = &mt('Currently internally authenticated.');
                   2544:                 return $result;
1.165     raeburn  2545:             }
                   2546:         }
1.586     raeburn  2547:     } else {
                   2548:         if ($authnum == 1) {
1.784     bisitz   2549:             $authtype = '<input type="hidden" name="login" value="int" />';
1.586     raeburn  2550:         }
                   2551:     }
                   2552:     if (!$can_assign{'int'}) {
                   2553:         return;
1.587     raeburn  2554:     } elsif ($authtype eq '') {
1.591     raeburn  2555:         if (defined($in{'mode'})) {
1.587     raeburn  2556:             if ($in{'mode'} eq 'modifycourse') {
                   2557:                 if ($authnum == 1) {
1.784     bisitz   2558:                     $authtype = '<input type="hidden" name="login" value="int" />';
1.587     raeburn  2559:                 }
                   2560:             }
                   2561:         }
1.165     raeburn  2562:     }
1.586     raeburn  2563:     $jscall = "javascript:changed_radio('int',$in{'formname'});";
                   2564:     if ($authtype eq '') {
                   2565:         $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
                   2566:                     ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
                   2567:     }
1.605     bisitz   2568:     $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586     raeburn  2569:                $intarg.'" onchange="'.$jscall.'" />';
                   2570:     $result = &mt
1.144     matthew  2571:         ('[_1] Internally authenticated (with initial password [_2])',
1.586     raeburn  2572:          '<label>'.$authtype,'</label>'.$autharg);
1.824     bisitz   2573:     $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  2574:     return $result;
                   2575: }
                   2576: 
                   2577: sub authform_local{  
                   2578:     my %in = (
                   2579:               formname => 'document.cu',
                   2580:               kerb_def_dom => 'MSU.EDU',
                   2581:               @_,
                   2582:               );
1.586     raeburn  2583:     my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
                   2584:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2585:     if (defined($in{'curr_authtype'})) {
                   2586:         if ($in{'curr_authtype'} eq 'loc') {
1.586     raeburn  2587:             if ($can_assign{'loc'}) {
1.772     bisitz   2588:                 $loccheck = 'checked="checked" ';
1.623     raeburn  2589:                 if (defined($in{'mode'})) {
                   2590:                     if ($in{'mode'} eq 'modifyuser') {
                   2591:                         $loccheck = '';
                   2592:                     }
                   2593:                 }
1.591     raeburn  2594:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2595:                     $locarg = $in{'curr_autharg'};
                   2596:                 }
                   2597:             } else {
                   2598:                 $result = &mt('Currently using local (institutional) authentication.');
                   2599:                 return $result;
1.165     raeburn  2600:             }
                   2601:         }
1.586     raeburn  2602:     } else {
                   2603:         if ($authnum == 1) {
1.784     bisitz   2604:             $authtype = '<input type="hidden" name="login" value="loc" />';
1.586     raeburn  2605:         }
                   2606:     }
                   2607:     if (!$can_assign{'loc'}) {
                   2608:         return;
1.587     raeburn  2609:     } elsif ($authtype eq '') {
1.591     raeburn  2610:         if (defined($in{'mode'})) {
1.587     raeburn  2611:             if ($in{'mode'} eq 'modifycourse') {
                   2612:                 if ($authnum == 1) {
1.784     bisitz   2613:                     $authtype = '<input type="hidden" name="login" value="loc" />';
1.587     raeburn  2614:                 }
                   2615:             }
                   2616:         }
1.165     raeburn  2617:     }
1.586     raeburn  2618:     $jscall = "javascript:changed_radio('loc',$in{'formname'});";
                   2619:     if ($authtype eq '') {
                   2620:         $authtype = '<input type="radio" name="login" value="loc" '.
                   2621:                     $loccheck.' onchange="'.$jscall.'" onclick="'.
                   2622:                     $jscall.'" />';
                   2623:     }
                   2624:     $autharg = '<input type="text" size="10" name="locarg" value="'.
                   2625:                $locarg.'" onchange="'.$jscall.'" />';
                   2626:     $result = &mt('[_1] Local Authentication with argument [_2]',
                   2627:                   '<label>'.$authtype,'</label>'.$autharg);
1.32      matthew  2628:     return $result;
                   2629: }
                   2630: 
                   2631: sub authform_filesystem{  
                   2632:     my %in = (
                   2633:               formname => 'document.cu',
                   2634:               kerb_def_dom => 'MSU.EDU',
                   2635:               @_,
                   2636:               );
1.586     raeburn  2637:     my ($fsyscheck,$result,$authtype,$autharg,$jscall);
                   2638:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2639:     if (defined($in{'curr_authtype'})) {
                   2640:         if ($in{'curr_authtype'} eq 'fsys') {
1.586     raeburn  2641:             if ($can_assign{'fsys'}) {
1.772     bisitz   2642:                 $fsyscheck = 'checked="checked" ';
1.623     raeburn  2643:                 if (defined($in{'mode'})) {
                   2644:                     if ($in{'mode'} eq 'modifyuser') {
                   2645:                         $fsyscheck = '';
                   2646:                     }
                   2647:                 }
1.586     raeburn  2648:             } else {
                   2649:                 $result = &mt('Currently Filesystem Authenticated.');
                   2650:                 return $result;
                   2651:             }           
                   2652:         }
                   2653:     } else {
                   2654:         if ($authnum == 1) {
1.784     bisitz   2655:             $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586     raeburn  2656:         }
                   2657:     }
                   2658:     if (!$can_assign{'fsys'}) {
                   2659:         return;
1.587     raeburn  2660:     } elsif ($authtype eq '') {
1.591     raeburn  2661:         if (defined($in{'mode'})) {
1.587     raeburn  2662:             if ($in{'mode'} eq 'modifycourse') {
                   2663:                 if ($authnum == 1) {
1.784     bisitz   2664:                     $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587     raeburn  2665:                 }
                   2666:             }
                   2667:         }
1.586     raeburn  2668:     }
                   2669:     $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
                   2670:     if ($authtype eq '') {
                   2671:         $authtype = '<input type="radio" name="login" value="fsys" '.
                   2672:                     $fsyscheck.' onchange="'.$jscall.'" onclick="'.
                   2673:                     $jscall.'" />';
                   2674:     }
                   2675:     $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
                   2676:                ' onchange="'.$jscall.'" />';
                   2677:     $result = &mt
1.144     matthew  2678:         ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281     albertel 2679:          '<label><input type="radio" name="login" value="fsys" '.
1.586     raeburn  2680:          $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605     bisitz   2681:          '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144     matthew  2682:                   'onchange="'.$jscall.'" />');
1.32      matthew  2683:     return $result;
                   2684: }
                   2685: 
1.586     raeburn  2686: sub get_assignable_auth {
                   2687:     my ($dom) = @_;
                   2688:     if ($dom eq '') {
                   2689:         $dom = $env{'request.role.domain'};
                   2690:     }
                   2691:     my %can_assign = (
                   2692:                           krb4 => 1,
                   2693:                           krb5 => 1,
                   2694:                           int  => 1,
                   2695:                           loc  => 1,
                   2696:                      );
                   2697:     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
                   2698:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   2699:         if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
                   2700:             my $authhash = $domconfig{'usercreation'}{'authtypes'};
                   2701:             my $context;
                   2702:             if ($env{'request.role'} =~ /^au/) {
                   2703:                 $context = 'author';
                   2704:             } elsif ($env{'request.role'} =~ /^dc/) {
                   2705:                 $context = 'domain';
                   2706:             } elsif ($env{'request.course.id'}) {
                   2707:                 $context = 'course';
                   2708:             }
                   2709:             if ($context) {
                   2710:                 if (ref($authhash->{$context}) eq 'HASH') {
                   2711:                    %can_assign = %{$authhash->{$context}}; 
                   2712:                 }
                   2713:             }
                   2714:         }
                   2715:     }
                   2716:     my $authnum = 0;
                   2717:     foreach my $key (keys(%can_assign)) {
                   2718:         if ($can_assign{$key}) {
                   2719:             $authnum ++;
                   2720:         }
                   2721:     }
                   2722:     if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
                   2723:         $authnum --;
                   2724:     }
                   2725:     return ($authnum,%can_assign);
                   2726: }
                   2727: 
1.80      albertel 2728: ###############################################################
                   2729: ##    Get Kerberos Defaults for Domain                 ##
                   2730: ###############################################################
                   2731: ##
                   2732: ## Returns default kerberos version and an associated argument
                   2733: ## as listed in file domain.tab. If not listed, provides
                   2734: ## appropriate default domain and kerberos version.
                   2735: ##
                   2736: #-------------------------------------------
                   2737: 
                   2738: =pod
                   2739: 
1.648     raeburn  2740: =item * &get_kerberos_defaults()
1.80      albertel 2741: 
                   2742: get_kerberos_defaults($target_domain) returns the default kerberos
1.641     raeburn  2743: version and domain. If not found, it defaults to version 4 and the 
                   2744: domain of the server.
1.80      albertel 2745: 
1.648     raeburn  2746: =over 4
                   2747: 
1.80      albertel 2748: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
                   2749: 
1.648     raeburn  2750: =back
                   2751: 
                   2752: =back
                   2753: 
1.80      albertel 2754: =cut
                   2755: 
                   2756: #-------------------------------------------
                   2757: sub get_kerberos_defaults {
                   2758:     my $domain=shift;
1.641     raeburn  2759:     my ($krbdef,$krbdefdom);
                   2760:     my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
                   2761:     if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
                   2762:         $krbdef = $domdefaults{'auth_def'};
                   2763:         $krbdefdom = $domdefaults{'auth_arg_def'};
                   2764:     } else {
1.80      albertel 2765:         $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
                   2766:         my $krbdefdom=$1;
                   2767:         $krbdefdom=~tr/a-z/A-Z/;
                   2768:         $krbdef = "krb4";
                   2769:     }
                   2770:     return ($krbdef,$krbdefdom);
                   2771: }
1.112     bowersj2 2772: 
1.32      matthew  2773: 
1.46      matthew  2774: ###############################################################
                   2775: ##                Thesaurus Functions                        ##
                   2776: ###############################################################
1.20      www      2777: 
1.46      matthew  2778: =pod
1.20      www      2779: 
1.112     bowersj2 2780: =head1 Thesaurus Functions
                   2781: 
                   2782: =over 4
                   2783: 
1.648     raeburn  2784: =item * &initialize_keywords()
1.46      matthew  2785: 
                   2786: Initializes the package variable %Keywords if it is empty.  Uses the
                   2787: package variable $thesaurus_db_file.
                   2788: 
                   2789: =cut
                   2790: 
                   2791: ###################################################
                   2792: 
                   2793: sub initialize_keywords {
                   2794:     return 1 if (scalar keys(%Keywords));
                   2795:     # If we are here, %Keywords is empty, so fill it up
                   2796:     #   Make sure the file we need exists...
                   2797:     if (! -e $thesaurus_db_file) {
                   2798:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
                   2799:                                  " failed because it does not exist");
                   2800:         return 0;
                   2801:     }
                   2802:     #   Set up the hash as a database
                   2803:     my %thesaurus_db;
                   2804:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2805:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2806:         &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
                   2807:                                  $thesaurus_db_file);
                   2808:         return 0;
                   2809:     } 
                   2810:     #  Get the average number of appearances of a word.
                   2811:     my $avecount = $thesaurus_db{'average.count'};
                   2812:     #  Put keywords (those that appear > average) into %Keywords
                   2813:     while (my ($word,$data)=each (%thesaurus_db)) {
                   2814:         my ($count,undef) = split /:/,$data;
                   2815:         $Keywords{$word}++ if ($count > $avecount);
                   2816:     }
                   2817:     untie %thesaurus_db;
                   2818:     # Remove special values from %Keywords.
1.356     albertel 2819:     foreach my $value ('total.count','average.count') {
                   2820:         delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586     raeburn  2821:   }
1.46      matthew  2822:     return 1;
                   2823: }
                   2824: 
                   2825: ###################################################
                   2826: 
                   2827: =pod
                   2828: 
1.648     raeburn  2829: =item * &keyword($word)
1.46      matthew  2830: 
                   2831: Returns true if $word is a keyword.  A keyword is a word that appears more 
                   2832: than the average number of times in the thesaurus database.  Calls 
                   2833: &initialize_keywords
                   2834: 
                   2835: =cut
                   2836: 
                   2837: ###################################################
1.20      www      2838: 
                   2839: sub keyword {
1.46      matthew  2840:     return if (!&initialize_keywords());
                   2841:     my $word=lc(shift());
                   2842:     $word=~s/\W//g;
                   2843:     return exists($Keywords{$word});
1.20      www      2844: }
1.46      matthew  2845: 
                   2846: ###############################################################
                   2847: 
                   2848: =pod 
1.20      www      2849: 
1.648     raeburn  2850: =item * &get_related_words()
1.46      matthew  2851: 
1.160     matthew  2852: Look up a word in the thesaurus.  Takes a scalar argument and returns
1.46      matthew  2853: an array of words.  If the keyword is not in the thesaurus, an empty array
                   2854: will be returned.  The order of the words returned is determined by the
                   2855: database which holds them.
                   2856: 
                   2857: Uses global $thesaurus_db_file.
                   2858: 
                   2859: =cut
                   2860: 
                   2861: ###############################################################
                   2862: sub get_related_words {
                   2863:     my $keyword = shift;
                   2864:     my %thesaurus_db;
                   2865:     if (! -e $thesaurus_db_file) {
                   2866:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
                   2867:                                  "failed because the file does not exist");
                   2868:         return ();
                   2869:     }
                   2870:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2871:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2872:         return ();
                   2873:     } 
                   2874:     my @Words=();
1.429     www      2875:     my $count=0;
1.46      matthew  2876:     if (exists($thesaurus_db{$keyword})) {
1.356     albertel 2877: 	# The first element is the number of times
                   2878: 	# the word appears.  We do not need it now.
1.429     www      2879: 	my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
                   2880: 	my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
                   2881: 	my $threshold=$mostfrequentcount/10;
                   2882:         foreach my $possibleword (@RelatedWords) {
                   2883:             my ($word,$wordcount)=split(/\,/,$possibleword);
                   2884:             if ($wordcount>$threshold) {
                   2885: 		push(@Words,$word);
                   2886:                 $count++;
                   2887:                 if ($count>10) { last; }
                   2888: 	    }
1.20      www      2889:         }
                   2890:     }
1.46      matthew  2891:     untie %thesaurus_db;
                   2892:     return @Words;
1.14      harris41 2893: }
1.46      matthew  2894: 
1.112     bowersj2 2895: =pod
                   2896: 
                   2897: =back
                   2898: 
                   2899: =cut
1.61      www      2900: 
                   2901: # -------------------------------------------------------------- Plaintext name
1.81      albertel 2902: =pod
                   2903: 
1.112     bowersj2 2904: =head1 User Name Functions
                   2905: 
                   2906: =over 4
                   2907: 
1.648     raeburn  2908: =item * &plainname($uname,$udom,$first)
1.81      albertel 2909: 
1.112     bowersj2 2910: Takes a users logon name and returns it as a string in
1.226     albertel 2911: "first middle last generation" form 
                   2912: if $first is set to 'lastname' then it returns it as
                   2913: 'lastname generation, firstname middlename' if their is a lastname
1.81      albertel 2914: 
                   2915: =cut
1.61      www      2916: 
1.295     www      2917: 
1.81      albertel 2918: ###############################################################
1.61      www      2919: sub plainname {
1.226     albertel 2920:     my ($uname,$udom,$first)=@_;
1.537     albertel 2921:     return if (!defined($uname) || !defined($udom));
1.295     www      2922:     my %names=&getnames($uname,$udom);
1.226     albertel 2923:     my $name=&Apache::lonnet::format_name($names{'firstname'},
                   2924: 					  $names{'middlename'},
                   2925: 					  $names{'lastname'},
                   2926: 					  $names{'generation'},$first);
                   2927:     $name=~s/^\s+//;
1.62      www      2928:     $name=~s/\s+$//;
                   2929:     $name=~s/\s+/ /g;
1.353     albertel 2930:     if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62      www      2931:     return $name;
1.61      www      2932: }
1.66      www      2933: 
                   2934: # -------------------------------------------------------------------- Nickname
1.81      albertel 2935: =pod
                   2936: 
1.648     raeburn  2937: =item * &nickname($uname,$udom)
1.81      albertel 2938: 
                   2939: Gets a users name and returns it as a string as
                   2940: 
                   2941: "&quot;nickname&quot;"
1.66      www      2942: 
1.81      albertel 2943: if the user has a nickname or
                   2944: 
                   2945: "first middle last generation"
                   2946: 
                   2947: if the user does not
                   2948: 
                   2949: =cut
1.66      www      2950: 
                   2951: sub nickname {
                   2952:     my ($uname,$udom)=@_;
1.537     albertel 2953:     return if (!defined($uname) || !defined($udom));
1.295     www      2954:     my %names=&getnames($uname,$udom);
1.68      albertel 2955:     my $name=$names{'nickname'};
1.66      www      2956:     if ($name) {
                   2957:        $name='&quot;'.$name.'&quot;'; 
                   2958:     } else {
                   2959:        $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
                   2960: 	     $names{'lastname'}.' '.$names{'generation'};
                   2961:        $name=~s/\s+$//;
                   2962:        $name=~s/\s+/ /g;
                   2963:     }
                   2964:     return $name;
                   2965: }
                   2966: 
1.295     www      2967: sub getnames {
                   2968:     my ($uname,$udom)=@_;
1.537     albertel 2969:     return if (!defined($uname) || !defined($udom));
1.433     albertel 2970:     if ($udom eq 'public' && $uname eq 'public') {
                   2971: 	return ('lastname' => &mt('Public'));
                   2972:     }
1.295     www      2973:     my $id=$uname.':'.$udom;
                   2974:     my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
                   2975:     if ($cached) {
                   2976: 	return %{$names};
                   2977:     } else {
                   2978: 	my %loadnames=&Apache::lonnet::get('environment',
                   2979:                     ['firstname','middlename','lastname','generation','nickname'],
                   2980: 					 $udom,$uname);
                   2981: 	&Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
                   2982: 	return %loadnames;
                   2983:     }
                   2984: }
1.61      www      2985: 
1.542     raeburn  2986: # -------------------------------------------------------------------- getemails
1.648     raeburn  2987: 
1.542     raeburn  2988: =pod
                   2989: 
1.648     raeburn  2990: =item * &getemails($uname,$udom)
1.542     raeburn  2991: 
                   2992: Gets a user's email information and returns it as a hash with keys:
                   2993: notification, critnotification, permanentemail
                   2994: 
                   2995: For notification and critnotification, values are comma-separated lists 
1.648     raeburn  2996: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542     raeburn  2997:  
1.648     raeburn  2998: 
1.542     raeburn  2999: =cut
                   3000: 
1.648     raeburn  3001: 
1.466     albertel 3002: sub getemails {
                   3003:     my ($uname,$udom)=@_;
                   3004:     if ($udom eq 'public' && $uname eq 'public') {
                   3005: 	return;
                   3006:     }
1.467     www      3007:     if (!$udom) { $udom=$env{'user.domain'}; }
                   3008:     if (!$uname) { $uname=$env{'user.name'}; }
1.466     albertel 3009:     my $id=$uname.':'.$udom;
                   3010:     my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
                   3011:     if ($cached) {
                   3012: 	return %{$names};
                   3013:     } else {
                   3014: 	my %loadnames=&Apache::lonnet::get('environment',
                   3015:                     			   ['notification','critnotification',
                   3016: 					    'permanentemail'],
                   3017: 					   $udom,$uname);
                   3018: 	&Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
                   3019: 	return %loadnames;
                   3020:     }
                   3021: }
                   3022: 
1.551     albertel 3023: sub flush_email_cache {
                   3024:     my ($uname,$udom)=@_;
                   3025:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   3026:     if (!$uname) { $uname=$env{'user.name'};   }
                   3027:     return if ($udom eq 'public' && $uname eq 'public');
                   3028:     my $id=$uname.':'.$udom;
                   3029:     &Apache::lonnet::devalidate_cache_new('emailscache',$id);
                   3030: }
                   3031: 
1.728     raeburn  3032: # -------------------------------------------------------------------- getlangs
                   3033: 
                   3034: =pod
                   3035: 
                   3036: =item * &getlangs($uname,$udom)
                   3037: 
                   3038: Gets a user's language preference and returns it as a hash with key:
                   3039: language.
                   3040: 
                   3041: =cut
                   3042: 
                   3043: 
                   3044: sub getlangs {
                   3045:     my ($uname,$udom) = @_;
                   3046:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   3047:     if (!$uname) { $uname=$env{'user.name'};   }
                   3048:     my $id=$uname.':'.$udom;
                   3049:     my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
                   3050:     if ($cached) {
                   3051:         return %{$langs};
                   3052:     } else {
                   3053:         my %loadlangs=&Apache::lonnet::get('environment',['languages'],
                   3054:                                            $udom,$uname);
                   3055:         &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
                   3056:         return %loadlangs;
                   3057:     }
                   3058: }
                   3059: 
                   3060: sub flush_langs_cache {
                   3061:     my ($uname,$udom)=@_;
                   3062:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   3063:     if (!$uname) { $uname=$env{'user.name'};   }
                   3064:     return if ($udom eq 'public' && $uname eq 'public');
                   3065:     my $id=$uname.':'.$udom;
                   3066:     &Apache::lonnet::devalidate_cache_new('userlangs',$id);
                   3067: }
                   3068: 
1.61      www      3069: # ------------------------------------------------------------------ Screenname
1.81      albertel 3070: 
                   3071: =pod
                   3072: 
1.648     raeburn  3073: =item * &screenname($uname,$udom)
1.81      albertel 3074: 
                   3075: Gets a users screenname and returns it as a string
                   3076: 
                   3077: =cut
1.61      www      3078: 
                   3079: sub screenname {
                   3080:     my ($uname,$udom)=@_;
1.258     albertel 3081:     if ($uname eq $env{'user.name'} &&
                   3082: 	$udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212     albertel 3083:     my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68      albertel 3084:     return $names{'screenname'};
1.62      www      3085: }
                   3086: 
1.212     albertel 3087: 
1.802     bisitz   3088: # ------------------------------------------------------------- Confirm Wrapper
                   3089: =pod
                   3090: 
                   3091: =item confirmwrapper
                   3092: 
                   3093: Wrap messages about completion of operation in box
                   3094: 
                   3095: =cut
                   3096: 
                   3097: sub confirmwrapper {
                   3098:     my ($message)=@_;
                   3099:     if ($message) {
                   3100:         return "\n".'<div class="LC_confirm_box">'."\n"
                   3101:                .$message."\n"
                   3102:                .'</div>'."\n";
                   3103:     } else {
                   3104:         return $message;
                   3105:     }
                   3106: }
                   3107: 
1.62      www      3108: # ------------------------------------------------------------- Message Wrapper
                   3109: 
                   3110: sub messagewrapper {
1.369     www      3111:     my ($link,$username,$domain,$subject,$text)=@_;
1.62      www      3112:     return 
1.441     albertel 3113:         '<a href="/adm/email?compose=individual&amp;'.
                   3114:         'recname='.$username.'&amp;recdom='.$domain.
                   3115: 	'&amp;subject='.&escape($subject).'&amp;text='.&escape($text).'" '.
1.200     matthew  3116:         'title="'.&mt('Send message').'">'.$link.'</a>';
1.74      www      3117: }
1.802     bisitz   3118: 
1.74      www      3119: # --------------------------------------------------------------- Notes Wrapper
                   3120: 
                   3121: sub noteswrapper {
                   3122:     my ($link,$un,$do)=@_;
                   3123:     return 
1.896     amueller 3124: "<a href='/adm/email?recordftf=retrieve&amp;recname=$un&amp;recdom=$do'>$link</a>";
1.62      www      3125: }
1.802     bisitz   3126: 
1.62      www      3127: # ------------------------------------------------------------- Aboutme Wrapper
                   3128: 
                   3129: sub aboutmewrapper {
1.166     www      3130:     my ($link,$username,$domain,$target)=@_;
1.447     raeburn  3131:     if (!defined($username)  && !defined($domain)) {
                   3132:         return;
                   3133:     }
1.892     amueller 3134:     return '<a href="/adm/'.$domain.'/'.$username.'/aboutme?forcestudent=1"'.
1.756     weissno  3135: 	($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62      www      3136: }
                   3137: 
                   3138: # ------------------------------------------------------------ Syllabus Wrapper
                   3139: 
                   3140: sub syllabuswrapper {
1.707     bisitz   3141:     my ($linktext,$coursedir,$domain)=@_;
1.208     matthew  3142:     return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61      www      3143: }
1.14      harris41 3144: 
1.802     bisitz   3145: # -----------------------------------------------------------------------------
                   3146: 
1.208     matthew  3147: sub track_student_link {
1.887     raeburn  3148:     my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268     albertel 3149:     my $link ="/adm/trackstudent?";
1.208     matthew  3150:     my $title = 'View recent activity';
                   3151:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   3152:         defined($sdom)  && $sdom  !~ /^\s*$/) {
1.268     albertel 3153:         $link .= "selected_student=$sname:$sdom";
1.208     matthew  3154:         $title .= ' of this student';
1.268     albertel 3155:     } 
1.208     matthew  3156:     if (defined($target) && $target !~ /^\s*$/) {
                   3157:         $target = qq{target="$target"};
                   3158:     } else {
                   3159:         $target = '';
                   3160:     }
1.268     albertel 3161:     if ($start) { $link.='&amp;start='.$start; }
1.887     raeburn  3162:     if ($only_body) { $link .= '&amp;only_body=1'; }
1.554     albertel 3163:     $title = &mt($title);
                   3164:     $linktext = &mt($linktext);
1.448     albertel 3165:     return qq{<a href="$link" title="$title" $target>$linktext</a>}.
                   3166: 	&help_open_topic('View_recent_activity');
1.208     matthew  3167: }
                   3168: 
1.781     raeburn  3169: sub slot_reservations_link {
                   3170:     my ($linktext,$sname,$sdom,$target) = @_;
                   3171:     my $link ="/adm/slotrequest?command=showresv&amp;origin=aboutme";
                   3172:     my $title = 'View slot reservation history';
                   3173:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   3174:         defined($sdom)  && $sdom  !~ /^\s*$/) {
                   3175:         $link .= "&amp;uname=$sname&amp;udom=$sdom";
                   3176:         $title .= ' of this student';
                   3177:     }
                   3178:     if (defined($target) && $target !~ /^\s*$/) {
                   3179:         $target = qq{target="$target"};
                   3180:     } else {
                   3181:         $target = '';
                   3182:     }
                   3183:     $title = &mt($title);
                   3184:     $linktext = &mt($linktext);
                   3185:     return qq{<a href="$link" title="$title" $target>$linktext</a>};
                   3186: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
                   3187: 
                   3188: }
                   3189: 
1.508     www      3190: # ===================================================== Display a student photo
                   3191: 
                   3192: 
1.509     albertel 3193: sub student_image_tag {
1.508     www      3194:     my ($domain,$user)=@_;
                   3195:     my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
                   3196:     if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
                   3197: 	return '<img src="'.$imgsrc.'" align="right" />';
                   3198:     } else {
                   3199: 	return '';
                   3200:     }
                   3201: }
                   3202: 
1.112     bowersj2 3203: =pod
                   3204: 
                   3205: =back
                   3206: 
                   3207: =head1 Access .tab File Data
                   3208: 
                   3209: =over 4
                   3210: 
1.648     raeburn  3211: =item * &languageids() 
1.112     bowersj2 3212: 
                   3213: returns list of all language ids
                   3214: 
                   3215: =cut
                   3216: 
1.14      harris41 3217: sub languageids {
1.16      harris41 3218:     return sort(keys(%language));
1.14      harris41 3219: }
                   3220: 
1.112     bowersj2 3221: =pod
                   3222: 
1.648     raeburn  3223: =item * &languagedescription() 
1.112     bowersj2 3224: 
                   3225: returns description of a specified language id
                   3226: 
                   3227: =cut
                   3228: 
1.14      harris41 3229: sub languagedescription {
1.125     www      3230:     my $code=shift;
                   3231:     return  ($supported_language{$code}?'* ':'').
                   3232:             $language{$code}.
1.126     www      3233: 	    ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145     www      3234: }
                   3235: 
1.1048    foxr     3236: =pod
                   3237: 
                   3238: =item * &plainlanguagedescription
                   3239: 
                   3240: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
                   3241: and the language character encoding (e.g. ISO) separated by a ' - ' string.
                   3242: 
                   3243: =cut
                   3244: 
1.145     www      3245: sub plainlanguagedescription {
                   3246:     my $code=shift;
                   3247:     return $language{$code};
                   3248: }
                   3249: 
1.1048    foxr     3250: =pod
                   3251: 
                   3252: =item * &supportedlanguagecode
                   3253: 
                   3254: Returns the supported language code (e.g. sptutf maps to pt) given a language
                   3255: code.
                   3256: 
                   3257: =cut
                   3258: 
1.145     www      3259: sub supportedlanguagecode {
                   3260:     my $code=shift;
                   3261:     return $supported_language{$code};
1.97      www      3262: }
                   3263: 
1.112     bowersj2 3264: =pod
                   3265: 
1.1048    foxr     3266: =item * &latexlanguage()
                   3267: 
                   3268: Given a language key code returns the correspondnig language to use
                   3269: to select the correct hyphenation on LaTeX printouts.  This is undef if there
                   3270: is no supported hyphenation for the language code.
                   3271: 
                   3272: =cut
                   3273: 
                   3274: sub latexlanguage {
                   3275:     my $code = shift;
                   3276:     return $latex_language{$code};
                   3277: }
                   3278: 
                   3279: =pod
                   3280: 
                   3281: =item * &latexhyphenation()
                   3282: 
                   3283: Same as above but what's supplied is the language as it might be stored
                   3284: in the metadata.
                   3285: 
                   3286: =cut
                   3287: 
                   3288: sub latexhyphenation {
                   3289:     my $key = shift;
                   3290:     return $latex_language_bykey{$key};
                   3291: }
                   3292: 
                   3293: =pod
                   3294: 
1.648     raeburn  3295: =item * &copyrightids() 
1.112     bowersj2 3296: 
                   3297: returns list of all copyrights
                   3298: 
                   3299: =cut
                   3300: 
                   3301: sub copyrightids {
                   3302:     return sort(keys(%cprtag));
                   3303: }
                   3304: 
                   3305: =pod
                   3306: 
1.648     raeburn  3307: =item * &copyrightdescription() 
1.112     bowersj2 3308: 
                   3309: returns description of a specified copyright id
                   3310: 
                   3311: =cut
                   3312: 
                   3313: sub copyrightdescription {
1.166     www      3314:     return &mt($cprtag{shift(@_)});
1.112     bowersj2 3315: }
1.197     matthew  3316: 
                   3317: =pod
                   3318: 
1.648     raeburn  3319: =item * &source_copyrightids() 
1.192     taceyjo1 3320: 
                   3321: returns list of all source copyrights
                   3322: 
                   3323: =cut
                   3324: 
                   3325: sub source_copyrightids {
                   3326:     return sort(keys(%scprtag));
                   3327: }
                   3328: 
                   3329: =pod
                   3330: 
1.648     raeburn  3331: =item * &source_copyrightdescription() 
1.192     taceyjo1 3332: 
                   3333: returns description of a specified source copyright id
                   3334: 
                   3335: =cut
                   3336: 
                   3337: sub source_copyrightdescription {
                   3338:     return &mt($scprtag{shift(@_)});
                   3339: }
1.112     bowersj2 3340: 
                   3341: =pod
                   3342: 
1.648     raeburn  3343: =item * &filecategories() 
1.112     bowersj2 3344: 
                   3345: returns list of all file categories
                   3346: 
                   3347: =cut
                   3348: 
                   3349: sub filecategories {
                   3350:     return sort(keys(%category_extensions));
                   3351: }
                   3352: 
                   3353: =pod
                   3354: 
1.648     raeburn  3355: =item * &filecategorytypes() 
1.112     bowersj2 3356: 
                   3357: returns list of file types belonging to a given file
                   3358: category
                   3359: 
                   3360: =cut
                   3361: 
                   3362: sub filecategorytypes {
1.356     albertel 3363:     my ($cat) = @_;
                   3364:     return @{$category_extensions{lc($cat)}};
1.112     bowersj2 3365: }
                   3366: 
                   3367: =pod
                   3368: 
1.648     raeburn  3369: =item * &fileembstyle() 
1.112     bowersj2 3370: 
                   3371: returns embedding style for a specified file type
                   3372: 
                   3373: =cut
                   3374: 
                   3375: sub fileembstyle {
                   3376:     return $fe{lc(shift(@_))};
1.169     www      3377: }
                   3378: 
1.351     www      3379: sub filemimetype {
                   3380:     return $fm{lc(shift(@_))};
                   3381: }
                   3382: 
1.169     www      3383: 
                   3384: sub filecategoryselect {
                   3385:     my ($name,$value)=@_;
1.189     matthew  3386:     return &select_form($value,$name,
1.970     raeburn  3387:                         {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112     bowersj2 3388: }
                   3389: 
                   3390: =pod
                   3391: 
1.648     raeburn  3392: =item * &filedescription() 
1.112     bowersj2 3393: 
                   3394: returns description for a specified file type
                   3395: 
                   3396: =cut
                   3397: 
                   3398: sub filedescription {
1.188     matthew  3399:     my $file_description = $fd{lc(shift())};
                   3400:     $file_description =~ s:([\[\]]):~$1:g;
                   3401:     return &mt($file_description);
1.112     bowersj2 3402: }
                   3403: 
                   3404: =pod
                   3405: 
1.648     raeburn  3406: =item * &filedescriptionex() 
1.112     bowersj2 3407: 
                   3408: returns description for a specified file type with
                   3409: extra formatting
                   3410: 
                   3411: =cut
                   3412: 
                   3413: sub filedescriptionex {
                   3414:     my $ex=shift;
1.188     matthew  3415:     my $file_description = $fd{lc($ex)};
                   3416:     $file_description =~ s:([\[\]]):~$1:g;
                   3417:     return '.'.$ex.' '.&mt($file_description);
1.112     bowersj2 3418: }
                   3419: 
                   3420: # End of .tab access
                   3421: =pod
                   3422: 
                   3423: =back
                   3424: 
                   3425: =cut
                   3426: 
                   3427: # ------------------------------------------------------------------ File Types
                   3428: sub fileextensions {
                   3429:     return sort(keys(%fe));
                   3430: }
                   3431: 
1.97      www      3432: # ----------------------------------------------------------- Display Languages
                   3433: # returns a hash with all desired display languages
                   3434: #
                   3435: 
                   3436: sub display_languages {
                   3437:     my %languages=();
1.695     raeburn  3438:     foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356     albertel 3439: 	$languages{$lang}=1;
1.97      www      3440:     }
                   3441:     &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258     albertel 3442:     if ($env{'form.displaylanguage'}) {
1.356     albertel 3443: 	foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
                   3444: 	    $languages{$lang}=1;
1.97      www      3445:         }
                   3446:     }
                   3447:     return %languages;
1.14      harris41 3448: }
                   3449: 
1.582     albertel 3450: sub languages {
                   3451:     my ($possible_langs) = @_;
1.695     raeburn  3452:     my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582     albertel 3453:     if (!ref($possible_langs)) {
                   3454: 	if( wantarray ) {
                   3455: 	    return @preferred_langs;
                   3456: 	} else {
                   3457: 	    return $preferred_langs[0];
                   3458: 	}
                   3459:     }
                   3460:     my %possibilities = map { $_ => 1 } (@$possible_langs);
                   3461:     my @preferred_possibilities;
                   3462:     foreach my $preferred_lang (@preferred_langs) {
                   3463: 	if (exists($possibilities{$preferred_lang})) {
                   3464: 	    push(@preferred_possibilities, $preferred_lang);
                   3465: 	}
                   3466:     }
                   3467:     if( wantarray ) {
                   3468: 	return @preferred_possibilities;
                   3469:     }
                   3470:     return $preferred_possibilities[0];
                   3471: }
                   3472: 
1.742     raeburn  3473: sub user_lang {
                   3474:     my ($touname,$toudom,$fromcid) = @_;
                   3475:     my @userlangs;
                   3476:     if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
                   3477:         @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
                   3478:                     $env{'course.'.$fromcid.'.languages'}));
                   3479:     } else {
                   3480:         my %langhash = &getlangs($touname,$toudom);
                   3481:         if ($langhash{'languages'} ne '') {
                   3482:             @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
                   3483:         } else {
                   3484:             my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
                   3485:             if ($domdefs{'lang_def'} ne '') {
                   3486:                 @userlangs = ($domdefs{'lang_def'});
                   3487:             }
                   3488:         }
                   3489:     }
                   3490:     my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
                   3491:     my $user_lh = Apache::localize->get_handle(@languages);
                   3492:     return $user_lh;
                   3493: }
                   3494: 
                   3495: 
1.112     bowersj2 3496: ###############################################################
                   3497: ##               Student Answer Attempts                     ##
                   3498: ###############################################################
                   3499: 
                   3500: =pod
                   3501: 
                   3502: =head1 Alternate Problem Views
                   3503: 
                   3504: =over 4
                   3505: 
1.648     raeburn  3506: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112     bowersj2 3507:     $getattempt, $regexp, $gradesub)
                   3508: 
                   3509: Return string with previous attempt on problem. Arguments:
                   3510: 
                   3511: =over 4
                   3512: 
                   3513: =item * $symb: Problem, including path
                   3514: 
                   3515: =item * $username: username of the desired student
                   3516: 
                   3517: =item * $domain: domain of the desired student
1.14      harris41 3518: 
1.112     bowersj2 3519: =item * $course: Course ID
1.14      harris41 3520: 
1.112     bowersj2 3521: =item * $getattempt: Leave blank for all attempts, otherwise put
                   3522:     something
1.14      harris41 3523: 
1.112     bowersj2 3524: =item * $regexp: if string matches this regexp, the string will be
                   3525:     sent to $gradesub
1.14      harris41 3526: 
1.112     bowersj2 3527: =item * $gradesub: routine that processes the string if it matches $regexp
1.14      harris41 3528: 
1.112     bowersj2 3529: =back
1.14      harris41 3530: 
1.112     bowersj2 3531: The output string is a table containing all desired attempts, if any.
1.16      harris41 3532: 
1.112     bowersj2 3533: =cut
1.1       albertel 3534: 
                   3535: sub get_previous_attempt {
1.43      ng       3536:   my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1       albertel 3537:   my $prevattempts='';
1.43      ng       3538:   no strict 'refs';
1.1       albertel 3539:   if ($symb) {
1.3       albertel 3540:     my (%returnhash)=
                   3541:       &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1       albertel 3542:     if ($returnhash{'version'}) {
                   3543:       my %lasthash=();
                   3544:       my $version;
                   3545:       for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356     albertel 3546:         foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
                   3547: 	  $lasthash{$key}=$returnhash{$version.':'.$key};
1.19      harris41 3548:         }
1.1       albertel 3549:       }
1.596     albertel 3550:       $prevattempts=&start_data_table().&start_data_table_header_row();
                   3551:       $prevattempts.='<th>'.&mt('History').'</th>';
1.978     raeburn  3552:       my (%typeparts,%lasthidden);
1.945     raeburn  3553:       my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356     albertel 3554:       foreach my $key (sort(keys(%lasthash))) {
                   3555: 	my ($ign,@parts) = split(/\./,$key);
1.41      ng       3556: 	if ($#parts > 0) {
1.31      albertel 3557: 	  my $data=$parts[-1];
1.989     raeburn  3558:           next if ($data eq 'foilorder');
1.31      albertel 3559: 	  pop(@parts);
1.1010    www      3560:           $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.'&nbsp;</th>';
1.945     raeburn  3561:           if ($data eq 'type') {
                   3562:               unless ($showsurv) {
                   3563:                   my $id = join(',',@parts);
                   3564:                   $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978     raeburn  3565:                   if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
                   3566:                       $lasthidden{$ign.'.'.$id} = 1;
                   3567:                   }
1.945     raeburn  3568:               }
1.1010    www      3569:           } 
1.31      albertel 3570: 	} else {
1.41      ng       3571: 	  if ($#parts == 0) {
                   3572: 	    $prevattempts.='<th>'.$parts[0].'</th>';
                   3573: 	  } else {
                   3574: 	    $prevattempts.='<th>'.$ign.'</th>';
                   3575: 	  }
1.31      albertel 3576: 	}
1.16      harris41 3577:       }
1.596     albertel 3578:       $prevattempts.=&end_data_table_header_row();
1.40      ng       3579:       if ($getattempt eq '') {
                   3580: 	for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945     raeburn  3581:             my @hidden;
                   3582:             if (%typeparts) {
                   3583:                 foreach my $id (keys(%typeparts)) {
                   3584:                     if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
                   3585:                         push(@hidden,$id);
                   3586:                     }
                   3587:                 }
                   3588:             }
                   3589:             $prevattempts.=&start_data_table_row().
                   3590:                            '<td>'.&mt('Transaction [_1]',$version).'</td>';
                   3591:             if (@hidden) {
                   3592:                 foreach my $key (sort(keys(%lasthash))) {
1.989     raeburn  3593:                     next if ($key =~ /\.foilorder$/);
1.945     raeburn  3594:                     my $hide;
                   3595:                     foreach my $id (@hidden) {
                   3596:                         if ($key =~ /^\Q$id\E/) {
                   3597:                             $hide = 1;
                   3598:                             last;
                   3599:                         }
                   3600:                     }
                   3601:                     if ($hide) {
                   3602:                         my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
                   3603:                         if (($data eq 'award') || ($data eq 'awarddetail')) {
                   3604:                             my $value = &format_previous_attempt_value($key,
                   3605:                                              $returnhash{$version.':'.$key});
                   3606:                             $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3607:                         } else {
                   3608:                             $prevattempts.='<td>&nbsp;</td>';
                   3609:                         }
                   3610:                     } else {
                   3611:                         if ($key =~ /\./) {
                   3612:                             my $value = &format_previous_attempt_value($key,
                   3613:                                               $returnhash{$version.':'.$key});
                   3614:                             $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3615:                         } else {
                   3616:                             $prevattempts.='<td>&nbsp;</td>';
                   3617:                         }
                   3618:                     }
                   3619:                 }
                   3620:             } else {
                   3621: 	        foreach my $key (sort(keys(%lasthash))) {
1.989     raeburn  3622:                     next if ($key =~ /\.foilorder$/);
1.945     raeburn  3623: 		    my $value = &format_previous_attempt_value($key,
                   3624: 			            $returnhash{$version.':'.$key});
                   3625: 		    $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3626: 	        }
                   3627:             }
                   3628: 	    $prevattempts.=&end_data_table_row();
1.40      ng       3629: 	 }
1.1       albertel 3630:       }
1.945     raeburn  3631:       my @currhidden = keys(%lasthidden);
1.596     albertel 3632:       $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356     albertel 3633:       foreach my $key (sort(keys(%lasthash))) {
1.989     raeburn  3634:           next if ($key =~ /\.foilorder$/);
1.945     raeburn  3635:           if (%typeparts) {
                   3636:               my $hidden;
                   3637:               foreach my $id (@currhidden) {
                   3638:                   if ($key =~ /^\Q$id\E/) {
                   3639:                       $hidden = 1;
                   3640:                       last;
                   3641:                   }
                   3642:               }
                   3643:               if ($hidden) {
                   3644:                   my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
                   3645:                   if (($data eq 'award') || ($data eq 'awarddetail')) {
                   3646:                       my $value = &format_previous_attempt_value($key,$lasthash{$key});
                   3647:                       if ($key =~/$regexp$/ && (defined &$gradesub)) {
                   3648:                           $value = &$gradesub($value);
                   3649:                       }
                   3650:                       $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3651:                   } else {
                   3652:                       $prevattempts.='<td>&nbsp;</td>';
                   3653:                   }
                   3654:               } else {
                   3655:                   my $value = &format_previous_attempt_value($key,$lasthash{$key});
                   3656:                   if ($key =~/$regexp$/ && (defined &$gradesub)) {
                   3657:                       $value = &$gradesub($value);
                   3658:                   }
                   3659:                   $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3660:               }
                   3661:           } else {
                   3662: 	      my $value = &format_previous_attempt_value($key,$lasthash{$key});
                   3663: 	      if ($key =~/$regexp$/ && (defined &$gradesub)) {
                   3664:                   $value = &$gradesub($value);
                   3665:               }
                   3666: 	      $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3667:           }
1.16      harris41 3668:       }
1.596     albertel 3669:       $prevattempts.= &end_data_table_row().&end_data_table();
1.1       albertel 3670:     } else {
1.596     albertel 3671:       $prevattempts=
                   3672: 	  &start_data_table().&start_data_table_row().
                   3673: 	  '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
                   3674: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3675:     }
                   3676:   } else {
1.596     albertel 3677:     $prevattempts=
                   3678: 	  &start_data_table().&start_data_table_row().
                   3679: 	  '<td>'.&mt('No data.').'</td>'.
                   3680: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3681:   }
1.10      albertel 3682: }
                   3683: 
1.581     albertel 3684: sub format_previous_attempt_value {
                   3685:     my ($key,$value) = @_;
1.1011    www      3686:     if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581     albertel 3687: 	$value = &Apache::lonlocal::locallocaltime($value);
                   3688:     } elsif (ref($value) eq 'ARRAY') {
                   3689: 	$value = '('.join(', ', @{ $value }).')';
1.988     raeburn  3690:     } elsif ($key =~ /answerstring$/) {
                   3691:         my %answers = &Apache::lonnet::str2hash($value);
                   3692:         my @anskeys = sort(keys(%answers));
                   3693:         if (@anskeys == 1) {
                   3694:             my $answer = $answers{$anskeys[0]};
1.1001    raeburn  3695:             if ($answer =~ m{\0}) {
                   3696:                 $answer =~ s{\0}{,}g;
1.988     raeburn  3697:             }
                   3698:             my $tag_internal_answer_name = 'INTERNAL';
                   3699:             if ($anskeys[0] eq $tag_internal_answer_name) {
                   3700:                 $value = $answer; 
                   3701:             } else {
                   3702:                 $value = $anskeys[0].'='.$answer;
                   3703:             }
                   3704:         } else {
                   3705:             foreach my $ans (@anskeys) {
                   3706:                 my $answer = $answers{$ans};
1.1001    raeburn  3707:                 if ($answer =~ m{\0}) {
                   3708:                     $answer =~ s{\0}{,}g;
1.988     raeburn  3709:                 }
                   3710:                 $value .=  $ans.'='.$answer.'<br />';;
                   3711:             } 
                   3712:         }
1.581     albertel 3713:     } else {
                   3714: 	$value = &unescape($value);
                   3715:     }
                   3716:     return $value;
                   3717: }
                   3718: 
                   3719: 
1.107     albertel 3720: sub relative_to_absolute {
                   3721:     my ($url,$output)=@_;
                   3722:     my $parser=HTML::TokeParser->new(\$output);
                   3723:     my $token;
                   3724:     my $thisdir=$url;
                   3725:     my @rlinks=();
                   3726:     while ($token=$parser->get_token) {
                   3727: 	if ($token->[0] eq 'S') {
                   3728: 	    if ($token->[1] eq 'a') {
                   3729: 		if ($token->[2]->{'href'}) {
                   3730: 		    $rlinks[$#rlinks+1]=$token->[2]->{'href'};
                   3731: 		}
                   3732: 	    } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
                   3733: 		$rlinks[$#rlinks+1]=$token->[2]->{'src'};
                   3734: 	    } elsif ($token->[1] eq 'base') {
                   3735: 		$thisdir=$token->[2]->{'href'};
                   3736: 	    }
                   3737: 	}
                   3738:     }
                   3739:     $thisdir=~s-/[^/]*$--;
1.356     albertel 3740:     foreach my $link (@rlinks) {
1.726     raeburn  3741: 	unless (($link=~/^https?\:\/\//i) ||
1.356     albertel 3742: 		($link=~/^\//) ||
                   3743: 		($link=~/^javascript:/i) ||
                   3744: 		($link=~/^mailto:/i) ||
                   3745: 		($link=~/^\#/)) {
                   3746: 	    my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
                   3747: 	    $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107     albertel 3748: 	}
                   3749:     }
                   3750: # -------------------------------------------------- Deal with Applet codebases
                   3751:     $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
                   3752:     return $output;
                   3753: }
                   3754: 
1.112     bowersj2 3755: =pod
                   3756: 
1.648     raeburn  3757: =item * &get_student_view()
1.112     bowersj2 3758: 
                   3759: show a snapshot of what student was looking at
                   3760: 
                   3761: =cut
                   3762: 
1.10      albertel 3763: sub get_student_view {
1.186     albertel 3764:   my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114     www      3765:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3766:   my (%form);
1.10      albertel 3767:   my @elements=('symb','courseid','domain','username');
                   3768:   foreach my $element (@elements) {
1.186     albertel 3769:       $form{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3770:   }
1.186     albertel 3771:   if (defined($moreenv)) {
                   3772:       %form=(%form,%{$moreenv});
                   3773:   }
1.236     albertel 3774:   if (defined($target)) { $form{'grade_target'} = $target; }
1.107     albertel 3775:   $feedurl=&Apache::lonnet::clutter($feedurl);
1.650     www      3776:   my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11      albertel 3777:   $userview=~s/\<body[^\>]*\>//gi;
                   3778:   $userview=~s/\<\/body\>//gi;
                   3779:   $userview=~s/\<html\>//gi;
                   3780:   $userview=~s/\<\/html\>//gi;
                   3781:   $userview=~s/\<head\>//gi;
                   3782:   $userview=~s/\<\/head\>//gi;
                   3783:   $userview=~s/action\s*\=/would_be_action\=/gi;
1.107     albertel 3784:   $userview=&relative_to_absolute($feedurl,$userview);
1.650     www      3785:   if (wantarray) {
                   3786:      return ($userview,$response);
                   3787:   } else {
                   3788:      return $userview;
                   3789:   }
                   3790: }
                   3791: 
                   3792: sub get_student_view_with_retries {
                   3793:   my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
                   3794: 
                   3795:     my $ok = 0;                 # True if we got a good response.
                   3796:     my $content;
                   3797:     my $response;
                   3798: 
                   3799:     # Try to get the student_view done. within the retries count:
                   3800:     
                   3801:     do {
                   3802:          ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
                   3803:          $ok      = $response->is_success;
                   3804:          if (!$ok) {
                   3805:             &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
                   3806:          }
                   3807:          $retries--;
                   3808:     } while (!$ok && ($retries > 0));
                   3809:     
                   3810:     if (!$ok) {
                   3811:        $content = '';          # On error return an empty content.
                   3812:     }
1.651     www      3813:     if (wantarray) {
                   3814:        return ($content, $response);
                   3815:     } else {
                   3816:        return $content;
                   3817:     }
1.11      albertel 3818: }
                   3819: 
1.112     bowersj2 3820: =pod
                   3821: 
1.648     raeburn  3822: =item * &get_student_answers() 
1.112     bowersj2 3823: 
                   3824: show a snapshot of how student was answering problem
                   3825: 
                   3826: =cut
                   3827: 
1.11      albertel 3828: sub get_student_answers {
1.100     sakharuk 3829:   my ($symb,$username,$domain,$courseid,%form) = @_;
1.114     www      3830:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3831:   my (%moreenv);
1.11      albertel 3832:   my @elements=('symb','courseid','domain','username');
                   3833:   foreach my $element (@elements) {
1.186     albertel 3834:     $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3835:   }
1.186     albertel 3836:   $moreenv{'grade_target'}='answer';
                   3837:   %moreenv=(%form,%moreenv);
1.497     raeburn  3838:   $feedurl = &Apache::lonnet::clutter($feedurl);
                   3839:   my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10      albertel 3840:   return $userview;
1.1       albertel 3841: }
1.116     albertel 3842: 
                   3843: =pod
                   3844: 
                   3845: =item * &submlink()
                   3846: 
1.242     albertel 3847: Inputs: $text $uname $udom $symb $target
1.116     albertel 3848: 
                   3849: Returns: A link to grades.pm such as to see the SUBM view of a student
                   3850: 
                   3851: =cut
                   3852: 
                   3853: ###############################################
                   3854: sub submlink {
1.242     albertel 3855:     my ($text,$uname,$udom,$symb,$target)=@_;
1.116     albertel 3856:     if (!($uname && $udom)) {
                   3857: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3858: 	    &Apache::lonnet::whichuser($symb);
1.116     albertel 3859: 	if (!$symb) { $symb=$cursymb; }
                   3860:     }
1.254     matthew  3861:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3862:     $symb=&escape($symb);
1.960     bisitz   3863:     if ($target) { $target=" target=\"$target\""; }
                   3864:     return
                   3865:         '<a href="/adm/grades?command=submission'.
                   3866:         '&amp;symb='.$symb.
                   3867:         '&amp;student='.$uname.
                   3868:         '&amp;userdom='.$udom.'"'.
                   3869:         $target.'>'.$text.'</a>';
1.242     albertel 3870: }
                   3871: ##############################################
                   3872: 
                   3873: =pod
                   3874: 
                   3875: =item * &pgrdlink()
                   3876: 
                   3877: Inputs: $text $uname $udom $symb $target
                   3878: 
                   3879: Returns: A link to grades.pm such as to see the PGRD view of a student
                   3880: 
                   3881: =cut
                   3882: 
                   3883: ###############################################
                   3884: sub pgrdlink {
                   3885:     my $link=&submlink(@_);
                   3886:     $link=~s/(&command=submission)/$1&showgrading=yes/;
                   3887:     return $link;
                   3888: }
                   3889: ##############################################
                   3890: 
                   3891: =pod
                   3892: 
                   3893: =item * &pprmlink()
                   3894: 
                   3895: Inputs: $text $uname $udom $symb $target
                   3896: 
                   3897: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283     albertel 3898: student and a specific resource
1.242     albertel 3899: 
                   3900: =cut
                   3901: 
                   3902: ###############################################
                   3903: sub pprmlink {
                   3904:     my ($text,$uname,$udom,$symb,$target)=@_;
                   3905:     if (!($uname && $udom)) {
                   3906: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3907: 	    &Apache::lonnet::whichuser($symb);
1.242     albertel 3908: 	if (!$symb) { $symb=$cursymb; }
                   3909:     }
1.254     matthew  3910:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3911:     $symb=&escape($symb);
1.242     albertel 3912:     if ($target) { $target="target=\"$target\""; }
1.595     albertel 3913:     return '<a href="/adm/parmset?command=set&amp;'.
                   3914: 	'symb='.$symb.'&amp;uname='.$uname.
                   3915: 	'&amp;udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116     albertel 3916: }
                   3917: ##############################################
1.37      matthew  3918: 
1.112     bowersj2 3919: =pod
                   3920: 
                   3921: =back
                   3922: 
                   3923: =cut
                   3924: 
1.37      matthew  3925: ###############################################
1.51      www      3926: 
                   3927: 
                   3928: sub timehash {
1.687     raeburn  3929:     my ($thistime) = @_;
                   3930:     my $timezone = &Apache::lonlocal::gettimezone();
                   3931:     my $dt = DateTime->from_epoch(epoch => $thistime)
                   3932:                      ->set_time_zone($timezone);
                   3933:     my $wday = $dt->day_of_week();
                   3934:     if ($wday == 7) { $wday = 0; }
                   3935:     return ( 'second' => $dt->second(),
                   3936:              'minute' => $dt->minute(),
                   3937:              'hour'   => $dt->hour(),
                   3938:              'day'     => $dt->day_of_month(),
                   3939:              'month'   => $dt->month(),
                   3940:              'year'    => $dt->year(),
                   3941:              'weekday' => $wday,
                   3942:              'dayyear' => $dt->day_of_year(),
                   3943:              'dlsav'   => $dt->is_dst() );
1.51      www      3944: }
                   3945: 
1.370     www      3946: sub utc_string {
                   3947:     my ($date)=@_;
1.371     www      3948:     return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370     www      3949: }
                   3950: 
1.51      www      3951: sub maketime {
                   3952:     my %th=@_;
1.687     raeburn  3953:     my ($epoch_time,$timezone,$dt);
                   3954:     $timezone = &Apache::lonlocal::gettimezone();
                   3955:     eval {
                   3956:         $dt = DateTime->new( year   => $th{'year'},
                   3957:                              month  => $th{'month'},
                   3958:                              day    => $th{'day'},
                   3959:                              hour   => $th{'hour'},
                   3960:                              minute => $th{'minute'},
                   3961:                              second => $th{'second'},
                   3962:                              time_zone => $timezone,
                   3963:                          );
                   3964:     };
                   3965:     if (!$@) {
                   3966:         $epoch_time = $dt->epoch;
                   3967:         if ($epoch_time) {
                   3968:             return $epoch_time;
                   3969:         }
                   3970:     }
1.51      www      3971:     return POSIX::mktime(
                   3972:         ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210     www      3973:          $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70      www      3974: }
                   3975: 
                   3976: #########################################
1.51      www      3977: 
                   3978: sub findallcourses {
1.482     raeburn  3979:     my ($roles,$uname,$udom) = @_;
1.355     albertel 3980:     my %roles;
                   3981:     if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348     albertel 3982:     my %courses;
1.51      www      3983:     my $now=time;
1.482     raeburn  3984:     if (!defined($uname)) {
                   3985:         $uname = $env{'user.name'};
                   3986:     }
                   3987:     if (!defined($udom)) {
                   3988:         $udom = $env{'user.domain'};
                   3989:     }
                   3990:     if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.982     raeburn  3991:         my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
                   3992:         my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname,'.',undef,
                   3993:                                               $extra);
1.482     raeburn  3994:         if (!%roles) {
                   3995:             %roles = (
                   3996:                        cc => 1,
1.907     raeburn  3997:                        co => 1,
1.482     raeburn  3998:                        in => 1,
                   3999:                        ep => 1,
                   4000:                        ta => 1,
                   4001:                        cr => 1,
                   4002:                        st => 1,
                   4003:              );
                   4004:         }
                   4005:         foreach my $entry (keys(%roleshash)) {
                   4006:             my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
                   4007:             if ($trole =~ /^cr/) { 
                   4008:                 next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
                   4009:             } else {
                   4010:                 next if (!exists($roles{$trole}));
                   4011:             }
                   4012:             if ($tend) {
                   4013:                 next if ($tend < $now);
                   4014:             }
                   4015:             if ($tstart) {
                   4016:                 next if ($tstart > $now);
                   4017:             }
                   4018:             my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
                   4019:             (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
                   4020:             if ($secpart eq '') {
                   4021:                 ($cnum,$role) = split(/_/,$cnumpart); 
                   4022:                 $sec = 'none';
                   4023:                 $realsec = '';
                   4024:             } else {
                   4025:                 $cnum = $cnumpart;
                   4026:                 ($sec,$role) = split(/_/,$secpart);
                   4027:                 $realsec = $sec;
1.490     raeburn  4028:             }
1.482     raeburn  4029:             $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
                   4030:         }
                   4031:     } else {
                   4032:         foreach my $key (keys(%env)) {
1.483     albertel 4033: 	    if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
                   4034:                  $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482     raeburn  4035: 	        my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
                   4036: 	        next if ($role eq 'ca' || $role eq 'aa');
                   4037: 	        next if (%roles && !exists($roles{$role}));
                   4038: 	        my ($starttime,$endtime)=split(/\./,$env{$key});
                   4039:                 my $active=1;
                   4040:                 if ($starttime) {
                   4041: 		    if ($now<$starttime) { $active=0; }
                   4042:                 }
                   4043:                 if ($endtime) {
                   4044:                     if ($now>$endtime) { $active=0; }
                   4045:                 }
                   4046:                 if ($active) {
                   4047:                     if ($sec eq '') {
                   4048:                         $sec = 'none';
                   4049:                     }
                   4050:                     $courses{$cdom.'_'.$cnum}{$sec} = 
                   4051:                                      $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474     raeburn  4052:                 }
                   4053:             }
1.51      www      4054:         }
                   4055:     }
1.474     raeburn  4056:     return %courses;
1.51      www      4057: }
1.37      matthew  4058: 
1.54      www      4059: ###############################################
1.474     raeburn  4060: 
                   4061: sub blockcheck {
1.482     raeburn  4062:     my ($setters,$activity,$uname,$udom) = @_;
1.490     raeburn  4063: 
                   4064:     if (!defined($udom)) {
                   4065:         $udom = $env{'user.domain'};
                   4066:     }
                   4067:     if (!defined($uname)) {
                   4068:         $uname = $env{'user.name'};
                   4069:     }
                   4070: 
                   4071:     # If uname and udom are for a course, check for blocks in the course.
                   4072: 
                   4073:     if (&Apache::lonnet::is_course($udom,$uname)) {
                   4074:         my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502     raeburn  4075:         my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490     raeburn  4076:         return ($startblock,$endblock);
                   4077:     }
1.474     raeburn  4078: 
1.502     raeburn  4079:     my $startblock = 0;
                   4080:     my $endblock = 0;
1.482     raeburn  4081:     my %live_courses = &findallcourses(undef,$uname,$udom);
1.474     raeburn  4082: 
1.490     raeburn  4083:     # If uname is for a user, and activity is course-specific, i.e.,
                   4084:     # boards, chat or groups, check for blocking in current course only.
1.474     raeburn  4085: 
1.490     raeburn  4086:     if (($activity eq 'boards' || $activity eq 'chat' ||
                   4087:          $activity eq 'groups') && ($env{'request.course.id'})) {
                   4088:         foreach my $key (keys(%live_courses)) {
                   4089:             if ($key ne $env{'request.course.id'}) {
                   4090:                 delete($live_courses{$key});
                   4091:             }
                   4092:         }
                   4093:     }
                   4094: 
                   4095:     my $otheruser = 0;
                   4096:     my %own_courses;
                   4097:     if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
                   4098:         # Resource belongs to user other than current user.
                   4099:         $otheruser = 1;
                   4100:         # Gather courses for current user
                   4101:         %own_courses = 
                   4102:             &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
                   4103:     }
                   4104: 
                   4105:     # Gather active course roles - course coordinator, instructor, 
                   4106:     # exam proctor, ta, student, or custom role.
1.474     raeburn  4107: 
                   4108:     foreach my $course (keys(%live_courses)) {
1.482     raeburn  4109:         my ($cdom,$cnum);
                   4110:         if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
                   4111:             $cdom = $env{'course.'.$course.'.domain'};
                   4112:             $cnum = $env{'course.'.$course.'.num'};
                   4113:         } else {
1.490     raeburn  4114:             ($cdom,$cnum) = split(/_/,$course); 
1.482     raeburn  4115:         }
                   4116:         my $no_ownblock = 0;
                   4117:         my $no_userblock = 0;
1.533     raeburn  4118:         if ($otheruser && $activity ne 'com') {
1.490     raeburn  4119:             # Check if current user has 'evb' priv for this
                   4120:             if (defined($own_courses{$course})) {
                   4121:                 foreach my $sec (keys(%{$own_courses{$course}})) {
                   4122:                     my $checkrole = 'cm./'.$cdom.'/'.$cnum;
                   4123:                     if ($sec ne 'none') {
                   4124:                         $checkrole .= '/'.$sec;
                   4125:                     }
                   4126:                     if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   4127:                         $no_ownblock = 1;
                   4128:                         last;
                   4129:                     }
                   4130:                 }
                   4131:             }
                   4132:             # if they have 'evb' priv and are currently not playing student
                   4133:             next if (($no_ownblock) &&
                   4134:                  ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
                   4135:         }
1.474     raeburn  4136:         foreach my $sec (keys(%{$live_courses{$course}})) {
1.482     raeburn  4137:             my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474     raeburn  4138:             if ($sec ne 'none') {
1.482     raeburn  4139:                 $checkrole .= '/'.$sec;
1.474     raeburn  4140:             }
1.490     raeburn  4141:             if ($otheruser) {
                   4142:                 # Resource belongs to user other than current user.
                   4143:                 # Assemble privs for that user, and check for 'evb' priv.
1.482     raeburn  4144:                 my ($trole,$tdom,$tnum,$tsec);
                   4145:                 my $entry = $live_courses{$course}{$sec};
                   4146:                 if ($entry =~ /^cr/) {
                   4147:                     ($trole,$tdom,$tnum,$tsec) = 
                   4148:                       ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
                   4149:                 } else {
                   4150:                     ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
                   4151:                 }
                   4152:                 my ($spec,$area,$trest,%allroles,%userroles);
                   4153:                 $area = '/'.$tdom.'/'.$tnum;
                   4154:                 $trest = $tnum;
                   4155:                 if ($tsec ne '') {
                   4156:                     $area .= '/'.$tsec;
                   4157:                     $trest .= '/'.$tsec;
                   4158:                 }
                   4159:                 $spec = $trole.'.'.$area;
                   4160:                 if ($trole =~ /^cr/) {
                   4161:                     &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
                   4162:                                                       $tdom,$spec,$trest,$area);
                   4163:                 } else {
                   4164:                     &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
                   4165:                                                        $tdom,$spec,$trest,$area);
                   4166:                 }
                   4167:                 my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486     raeburn  4168:                 if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
                   4169:                     if ($1) {
                   4170:                         $no_userblock = 1;
                   4171:                         last;
                   4172:                     }
                   4173:                 }
1.490     raeburn  4174:             } else {
                   4175:                 # Resource belongs to current user
                   4176:                 # Check for 'evb' priv via lonnet::allowed().
1.482     raeburn  4177:                 if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   4178:                     $no_ownblock = 1;
                   4179:                     last;
                   4180:                 }
1.474     raeburn  4181:             }
                   4182:         }
                   4183:         # if they have the evb priv and are currently not playing student
1.482     raeburn  4184:         next if (($no_ownblock) &&
1.491     albertel 4185:                  ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482     raeburn  4186:         next if ($no_userblock);
1.474     raeburn  4187: 
1.866     kalberla 4188:         # Retrieve blocking times and identity of locker for course
1.490     raeburn  4189:         # of specified user, unless user has 'evb' privilege.
1.502     raeburn  4190:         
                   4191:         my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
                   4192:         if (($start != 0) && 
                   4193:             (($startblock == 0) || ($startblock > $start))) {
                   4194:             $startblock = $start;
                   4195:         }
                   4196:         if (($end != 0)  &&
                   4197:             (($endblock == 0) || ($endblock < $end))) {
                   4198:             $endblock = $end;
                   4199:         }
1.490     raeburn  4200:     }
                   4201:     return ($startblock,$endblock);
                   4202: }
                   4203: 
                   4204: sub get_blocks {
                   4205:     my ($setters,$activity,$cdom,$cnum) = @_;
                   4206:     my $startblock = 0;
                   4207:     my $endblock = 0;
                   4208:     my $course = $cdom.'_'.$cnum;
                   4209:     $setters->{$course} = {};
                   4210:     $setters->{$course}{'staff'} = [];
                   4211:     $setters->{$course}{'times'} = [];
                   4212:     my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
                   4213:     foreach my $record (keys(%records)) {
                   4214:         my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
                   4215:         if ($start <= time && $end >= time) {
                   4216:             my ($staff_name,$staff_dom,$title,$blocks) =
                   4217:                 &parse_block_record($records{$record});
                   4218:             if ($blocks->{$activity} eq 'on') {
                   4219:                 push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
                   4220:                 push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491     albertel 4221:                 if ( ($startblock == 0) || ($startblock > $start) ) {
                   4222:                     $startblock = $start;
1.490     raeburn  4223:                 }
1.491     albertel 4224:                 if ( ($endblock == 0) || ($endblock < $end) ) {
                   4225:                     $endblock = $end;
1.474     raeburn  4226:                 }
                   4227:             }
                   4228:         }
                   4229:     }
                   4230:     return ($startblock,$endblock);
                   4231: }
                   4232: 
                   4233: sub parse_block_record {
                   4234:     my ($record) = @_;
                   4235:     my ($setuname,$setudom,$title,$blocks);
                   4236:     if (ref($record) eq 'HASH') {
                   4237:         ($setuname,$setudom) = split(/:/,$record->{'setter'});
                   4238:         $title = &unescape($record->{'event'});
                   4239:         $blocks = $record->{'blocks'};
                   4240:     } else {
                   4241:         my @data = split(/:/,$record,3);
                   4242:         if (scalar(@data) eq 2) {
                   4243:             $title = $data[1];
                   4244:             ($setuname,$setudom) = split(/@/,$data[0]);
                   4245:         } else {
                   4246:             ($setuname,$setudom,$title) = @data;
                   4247:         }
                   4248:         $blocks = { 'com' => 'on' };
                   4249:     }
                   4250:     return ($setuname,$setudom,$title,$blocks);
                   4251: }
                   4252: 
1.854     kalberla 4253: sub blocking_status {
                   4254:   my ($activity,$uname,$udom) = @_;
1.867     kalberla 4255:   my %setters;
1.890     droeschl 4256: 
                   4257:   # check for active blocking
1.867     kalberla 4258:   my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
1.854     kalberla 4259: 
1.890     droeschl 4260:   my $blocked = $startblock && $endblock ? 1 : 0;
                   4261: 
                   4262:   # caller just wants to know whether a block is active
                   4263:   if (!wantarray) { return $blocked; }
                   4264: 
                   4265:   # build a link to a popup window containing the details
                   4266:   my $querystring  = "?activity=$activity";
                   4267:   # $uname and $udom decide whose portfolio the user is trying to look at
                   4268:      $querystring .= "&amp;udom=$udom"      if $udom;
                   4269:      $querystring .= "&amp;uname=$uname"    if $uname;
                   4270: 
                   4271:   my $output .= <<'END_MYBLOCK';
1.854     kalberla 4272:     function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
                   4273:         var options = "width=" + w + ",height=" + h + ",";
                   4274:         options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
                   4275:         options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
                   4276:         var newWin = window.open(url, wdwName, options);
                   4277:         newWin.focus();
                   4278:     }
1.890     droeschl 4279: END_MYBLOCK
1.854     kalberla 4280: 
1.890     droeschl 4281:   $output = Apache::lonhtmlcommon::scripttag($output);
                   4282:   
1.854     kalberla 4283:   my $popupUrl = "/adm/blockingstatus/$querystring";
1.890     droeschl 4284:   my $text = mt('Communication Blocked');
                   4285: 
1.867     kalberla 4286:   $output .= <<"END_BLOCK";
                   4287: <div class='LC_comblock'>
1.869     kalberla 4288:   <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890     droeschl 4289:   title='$text'>
                   4290:   <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869     kalberla 4291:   <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring' 
1.890     droeschl 4292:   title='$text'>$text</a>
1.867     kalberla 4293: </div>
                   4294: 
                   4295: END_BLOCK
1.474     raeburn  4296: 
1.854     kalberla 4297:   return ($blocked, $output);
                   4298: }
1.490     raeburn  4299: 
1.60      matthew  4300: ###############################################
                   4301: 
1.682     raeburn  4302: sub check_ip_acc {
                   4303:     my ($acc)=@_;
                   4304:     &Apache::lonxml::debug("acc is $acc");
                   4305:     if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
                   4306:         return 1;
                   4307:     }
                   4308:     my $allowed=0;
                   4309:     my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
                   4310: 
                   4311:     my $name;
                   4312:     foreach my $pattern (split(',',$acc)) {
                   4313:         $pattern =~ s/^\s*//;
                   4314:         $pattern =~ s/\s*$//;
                   4315:         if ($pattern =~ /\*$/) {
                   4316:             #35.8.*
                   4317:             $pattern=~s/\*//;
                   4318:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   4319:         } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
                   4320:             #35.8.3.[34-56]
                   4321:             my $low=$2;
                   4322:             my $high=$3;
                   4323:             $pattern=$1;
                   4324:             if ($ip =~ /^\Q$pattern\E/) {
                   4325:                 my $last=(split(/\./,$ip))[3];
                   4326:                 if ($last <=$high && $last >=$low) { $allowed=1; }
                   4327:             }
                   4328:         } elsif ($pattern =~ /^\*/) {
                   4329:             #*.msu.edu
                   4330:             $pattern=~s/\*//;
                   4331:             if (!defined($name)) {
                   4332:                 use Socket;
                   4333:                 my $netaddr=inet_aton($ip);
                   4334:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   4335:             }
                   4336:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   4337:         } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
                   4338:             #127.0.0.1
                   4339:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   4340:         } else {
                   4341:             #some.name.com
                   4342:             if (!defined($name)) {
                   4343:                 use Socket;
                   4344:                 my $netaddr=inet_aton($ip);
                   4345:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   4346:             }
                   4347:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   4348:         }
                   4349:         if ($allowed) { last; }
                   4350:     }
                   4351:     return $allowed;
                   4352: }
                   4353: 
                   4354: ###############################################
                   4355: 
1.60      matthew  4356: =pod
                   4357: 
1.112     bowersj2 4358: =head1 Domain Template Functions
                   4359: 
                   4360: =over 4
                   4361: 
                   4362: =item * &determinedomain()
1.60      matthew  4363: 
                   4364: Inputs: $domain (usually will be undef)
                   4365: 
1.63      www      4366: Returns: Determines which domain should be used for designs
1.60      matthew  4367: 
                   4368: =cut
1.54      www      4369: 
1.60      matthew  4370: ###############################################
1.63      www      4371: sub determinedomain {
                   4372:     my $domain=shift;
1.531     albertel 4373:     if (! $domain) {
1.60      matthew  4374:         # Determine domain if we have not been given one
1.893     raeburn  4375:         $domain = &Apache::lonnet::default_login_domain();
1.258     albertel 4376:         if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
                   4377:         if ($env{'request.role.domain'}) { 
                   4378:             $domain=$env{'request.role.domain'}; 
1.60      matthew  4379:         }
                   4380:     }
1.63      www      4381:     return $domain;
                   4382: }
                   4383: ###############################################
1.517     raeburn  4384: 
1.518     albertel 4385: sub devalidate_domconfig_cache {
                   4386:     my ($udom)=@_;
                   4387:     &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
                   4388: }
                   4389: 
                   4390: # ---------------------- Get domain configuration for a domain
                   4391: sub get_domainconf {
                   4392:     my ($udom) = @_;
                   4393:     my $cachetime=1800;
                   4394:     my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
                   4395:     if (defined($cached)) { return %{$result}; }
                   4396: 
                   4397:     my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948     raeburn  4398: 					     ['login','rolecolors','autoenroll'],$udom);
1.632     raeburn  4399:     my (%designhash,%legacy);
1.518     albertel 4400:     if (keys(%domconfig) > 0) {
                   4401:         if (ref($domconfig{'login'}) eq 'HASH') {
1.632     raeburn  4402:             if (keys(%{$domconfig{'login'}})) {
                   4403:                 foreach my $key (keys(%{$domconfig{'login'}})) {
1.699     raeburn  4404:                     if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946     raeburn  4405:                         if ($key eq 'loginvia') {
                   4406:                             if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
1.1013    raeburn  4407:                                 foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
1.948     raeburn  4408:                                     if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
                   4409:                                         if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
                   4410:                                             my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
                   4411:                                             $designhash{$udom.'.login.loginvia'} = $server;
                   4412:                                             if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
                   4413: 
                   4414:                                                 $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
                   4415:                                             } else {
1.1013    raeburn  4416:                                                 $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
1.948     raeburn  4417:                                             }
                   4418:                                             if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
                   4419:                                                 $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
                   4420:                                             }
1.946     raeburn  4421:                                         }
                   4422:                                     }
                   4423:                                 }
                   4424:                             }
                   4425:                         } else {
                   4426:                             foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
                   4427:                                 $designhash{$udom.'.login.'.$key.'_'.$img} = 
                   4428:                                     $domconfig{'login'}{$key}{$img};
                   4429:                             }
1.699     raeburn  4430:                         }
                   4431:                     } else {
                   4432:                         $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
                   4433:                     }
1.632     raeburn  4434:                 }
                   4435:             } else {
                   4436:                 $legacy{'login'} = 1;
1.518     albertel 4437:             }
1.632     raeburn  4438:         } else {
                   4439:             $legacy{'login'} = 1;
1.518     albertel 4440:         }
                   4441:         if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632     raeburn  4442:             if (keys(%{$domconfig{'rolecolors'}})) {
                   4443:                 foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
                   4444:                     if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
                   4445:                         foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
                   4446:                             $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
                   4447:                         }
1.518     albertel 4448:                     }
                   4449:                 }
1.632     raeburn  4450:             } else {
                   4451:                 $legacy{'rolecolors'} = 1;
1.518     albertel 4452:             }
1.632     raeburn  4453:         } else {
                   4454:             $legacy{'rolecolors'} = 1;
1.518     albertel 4455:         }
1.948     raeburn  4456:         if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   4457:             if ($domconfig{'autoenroll'}{'co-owners'}) {
                   4458:                 $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
                   4459:             }
                   4460:         }
1.632     raeburn  4461:         if (keys(%legacy) > 0) {
                   4462:             my %legacyhash = &get_legacy_domconf($udom);
                   4463:             foreach my $item (keys(%legacyhash)) {
                   4464:                 if ($item =~ /^\Q$udom\E\.login/) {
                   4465:                     if ($legacy{'login'}) { 
                   4466:                         $designhash{$item} = $legacyhash{$item};
                   4467:                     }
                   4468:                 } else {
                   4469:                     if ($legacy{'rolecolors'}) {
                   4470:                         $designhash{$item} = $legacyhash{$item};
                   4471:                     }
1.518     albertel 4472:                 }
                   4473:             }
                   4474:         }
1.632     raeburn  4475:     } else {
                   4476:         %designhash = &get_legacy_domconf($udom); 
1.518     albertel 4477:     }
                   4478:     &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
                   4479: 				  $cachetime);
                   4480:     return %designhash;
                   4481: }
                   4482: 
1.632     raeburn  4483: sub get_legacy_domconf {
                   4484:     my ($udom) = @_;
                   4485:     my %legacyhash;
                   4486:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
                   4487:     my $designfile =  $designdir.'/'.$udom.'.tab';
                   4488:     if (-e $designfile) {
                   4489:         if ( open (my $fh,"<$designfile") ) {
                   4490:             while (my $line = <$fh>) {
                   4491:                 next if ($line =~ /^\#/);
                   4492:                 chomp($line);
                   4493:                 my ($key,$val)=(split(/\=/,$line));
                   4494:                 if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
                   4495:             }
                   4496:             close($fh);
                   4497:         }
                   4498:     }
1.1026    raeburn  4499:     if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632     raeburn  4500:         $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
                   4501:     }
                   4502:     return %legacyhash;
                   4503: }
                   4504: 
1.63      www      4505: =pod
                   4506: 
1.112     bowersj2 4507: =item * &domainlogo()
1.63      www      4508: 
                   4509: Inputs: $domain (usually will be undef)
                   4510: 
                   4511: Returns: A link to a domain logo, if the domain logo exists.
                   4512: If the domain logo does not exist, a description of the domain.
                   4513: 
                   4514: =cut
1.112     bowersj2 4515: 
1.63      www      4516: ###############################################
                   4517: sub domainlogo {
1.517     raeburn  4518:     my $domain = &determinedomain(shift);
1.518     albertel 4519:     my %designhash = &get_domainconf($domain);    
1.517     raeburn  4520:     # See if there is a logo
                   4521:     if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519     raeburn  4522:         my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538     albertel 4523:         if ($imgsrc =~ m{^/(adm|res)/}) {
                   4524: 	    if ($imgsrc =~ m{^/res/}) {
                   4525: 		my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
                   4526: 		&Apache::lonnet::repcopy($local_name);
                   4527: 	    }
                   4528: 	   $imgsrc = &lonhttpdurl($imgsrc);
1.519     raeburn  4529:         } 
                   4530:         return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514     albertel 4531:     } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
                   4532:         return &Apache::lonnet::domain($domain,'description');
1.59      www      4533:     } else {
1.60      matthew  4534:         return '';
1.59      www      4535:     }
                   4536: }
1.63      www      4537: ##############################################
                   4538: 
                   4539: =pod
                   4540: 
1.112     bowersj2 4541: =item * &designparm()
1.63      www      4542: 
                   4543: Inputs: $which parameter; $domain (usually will be undef)
                   4544: 
                   4545: Returns: value of designparamter $which
                   4546: 
                   4547: =cut
1.112     bowersj2 4548: 
1.397     albertel 4549: 
1.400     albertel 4550: ##############################################
1.397     albertel 4551: sub designparm {
                   4552:     my ($which,$domain)=@_;
                   4553:     if (exists($env{'environment.color.'.$which})) {
1.817     bisitz   4554:         return $env{'environment.color.'.$which};
1.96      www      4555:     }
1.63      www      4556:     $domain=&determinedomain($domain);
1.1016    raeburn  4557:     my %domdesign;
                   4558:     unless ($domain eq 'public') {
                   4559:         %domdesign = &get_domainconf($domain);
                   4560:     }
1.520     raeburn  4561:     my $output;
1.517     raeburn  4562:     if ($domdesign{$domain.'.'.$which} ne '') {
1.817     bisitz   4563:         $output = $domdesign{$domain.'.'.$which};
1.63      www      4564:     } else {
1.520     raeburn  4565:         $output = $defaultdesign{$which};
                   4566:     }
                   4567:     if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635     raeburn  4568:         ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538     albertel 4569:         if ($output =~ m{^/(adm|res)/}) {
1.817     bisitz   4570:             if ($output =~ m{^/res/}) {
                   4571:                 my $local_name = &Apache::lonnet::filelocation('',$output);
                   4572:                 &Apache::lonnet::repcopy($local_name);
                   4573:             }
1.520     raeburn  4574:             $output = &lonhttpdurl($output);
                   4575:         }
1.63      www      4576:     }
1.520     raeburn  4577:     return $output;
1.63      www      4578: }
1.59      www      4579: 
1.822     bisitz   4580: ##############################################
                   4581: =pod
                   4582: 
1.832     bisitz   4583: =item * &authorspace()
                   4584: 
1.1028    raeburn  4585: Inputs: $url (usually will be undef).
1.832     bisitz   4586: 
1.1028    raeburn  4587: Returns: Path to Construction Space containing the resource or 
                   4588:          directory being viewed (or for which action is being taken). 
                   4589:          If $url is provided, and begins /priv/<domain>/<uname>
                   4590:          the path will be that portion of the $context argument.
                   4591:          Otherwise the path will be for the author space of the current
                   4592:          user when the current role is author, or for that of the 
                   4593:          co-author/assistant co-author space when the current role 
                   4594:          is co-author or assistant co-author.
1.832     bisitz   4595: 
                   4596: =cut
                   4597: 
                   4598: sub authorspace {
1.1028    raeburn  4599:     my ($url) = @_;
                   4600:     if ($url ne '') {
                   4601:         if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
                   4602:            return $1;
                   4603:         }
                   4604:     }
1.832     bisitz   4605:     my $caname = '';
1.1024    www      4606:     my $cadom = '';
1.1028    raeburn  4607:     if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024    www      4608:         ($cadom,$caname) =
1.832     bisitz   4609:             ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028    raeburn  4610:     } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832     bisitz   4611:         $caname = $env{'user.name'};
1.1024    www      4612:         $cadom = $env{'user.domain'};
1.832     bisitz   4613:     }
1.1028    raeburn  4614:     if (($caname ne '') && ($cadom ne '')) {
                   4615:         return "/priv/$cadom/$caname/";
                   4616:     }
                   4617:     return;
1.832     bisitz   4618: }
                   4619: 
                   4620: ##############################################
                   4621: =pod
                   4622: 
1.822     bisitz   4623: =item * &head_subbox()
                   4624: 
                   4625: Inputs: $content (contains HTML code with page functions, etc.)
                   4626: 
                   4627: Returns: HTML div with $content
                   4628:          To be included in page header
                   4629: 
                   4630: =cut
                   4631: 
                   4632: sub head_subbox {
                   4633:     my ($content)=@_;
                   4634:     my $output =
1.993     raeburn  4635:         '<div class="LC_head_subbox">'
1.822     bisitz   4636:        .$content
                   4637:        .'</div>'
                   4638: }
                   4639: 
                   4640: ##############################################
                   4641: =pod
                   4642: 
                   4643: =item * &CSTR_pageheader()
                   4644: 
1.1026    raeburn  4645: Input: (optional) filename from which breadcrumb trail is built.
                   4646:        In most cases no input as needed, as $env{'request.filename'}
                   4647:        is appropriate for use in building the breadcrumb trail.
1.822     bisitz   4648: 
                   4649: Returns: HTML div with CSTR path and recent box
                   4650:          To be included on Construction Space pages
                   4651: 
                   4652: =cut
                   4653: 
                   4654: sub CSTR_pageheader {
1.1026    raeburn  4655:     my ($trailfile) = @_;
                   4656:     if ($trailfile eq '') {
                   4657:         $trailfile = $env{'request.filename'};
                   4658:     }
                   4659: 
                   4660: # this is for resources; directories have customtitle, and crumbs
                   4661: # and select recent are created in lonpubdir.pm
                   4662: 
                   4663:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022    www      4664:     my ($udom,$uname,$thisdisfn)=
1.1026    raeburn  4665:         ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)/(.*)$});
                   4666:     my $formaction = "/priv/$udom/$uname/$thisdisfn";
                   4667:     $formaction =~ s{/+}{/}g;
1.822     bisitz   4668: 
                   4669:     my $parentpath = '';
                   4670:     my $lastitem = '';
                   4671:     if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
                   4672:         $parentpath = $1;
                   4673:         $lastitem = $2;
                   4674:     } else {
                   4675:         $lastitem = $thisdisfn;
                   4676:     }
1.921     bisitz   4677: 
                   4678:     my $output =
1.822     bisitz   4679:          '<div>'
                   4680:         .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
                   4681:         .'<b>'.&mt('Construction Space:').'</b> '
                   4682:         .'<form name="dirs" method="post" action="'.$formaction
1.921     bisitz   4683:         .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024    www      4684:         .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921     bisitz   4685: 
                   4686:     if ($lastitem) {
                   4687:         $output .=
                   4688:              '<span class="LC_filename">'
                   4689:             .$lastitem
                   4690:             .'</span>';
                   4691:     }
                   4692:     $output .=
                   4693:          '<br />'
1.822     bisitz   4694:         #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
                   4695:         .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
                   4696:         .'</form>'
                   4697:         .&Apache::lonmenu::constspaceform()
                   4698:         .'</div>';
1.921     bisitz   4699: 
                   4700:     return $output;
1.822     bisitz   4701: }
                   4702: 
1.60      matthew  4703: ###############################################
                   4704: ###############################################
                   4705: 
                   4706: =pod
                   4707: 
1.112     bowersj2 4708: =back
                   4709: 
1.549     albertel 4710: =head1 HTML Helpers
1.112     bowersj2 4711: 
                   4712: =over 4
                   4713: 
                   4714: =item * &bodytag()
1.60      matthew  4715: 
                   4716: Returns a uniform header for LON-CAPA web pages.
                   4717: 
                   4718: Inputs: 
                   4719: 
1.112     bowersj2 4720: =over 4
                   4721: 
                   4722: =item * $title, A title to be displayed on the page.
                   4723: 
                   4724: =item * $function, the current role (can be undef).
                   4725: 
                   4726: =item * $addentries, extra parameters for the <body> tag.
                   4727: 
                   4728: =item * $bodyonly, if defined, only return the <body> tag.
                   4729: 
                   4730: =item * $domain, if defined, force a given domain.
                   4731: 
                   4732: =item * $forcereg, if page should register as content page (relevant for 
1.86      www      4733:             text interface only)
1.60      matthew  4734: 
1.814     bisitz   4735: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
                   4736:                      navigational links
1.317     albertel 4737: 
1.338     albertel 4738: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
                   4739: 
1.460     albertel 4740: =item * $args, optional argument valid values are
                   4741:             no_auto_mt_title -> prevents &mt()ing the title arg
1.562     albertel 4742:             inherit_jsmath -> when creating popup window in a page,
                   4743:                               should it have jsmath forced on by the
                   4744:                               current page
1.460     albertel 4745: 
1.112     bowersj2 4746: =back
                   4747: 
1.60      matthew  4748: Returns: A uniform header for LON-CAPA web pages.  
                   4749: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
                   4750: If $bodyonly is undef or zero, an html string containing a <body> tag and 
                   4751: other decorations will be returned.
                   4752: 
                   4753: =cut
                   4754: 
1.54      www      4755: sub bodytag {
1.831     bisitz   4756:     my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.962     droeschl 4757:         $no_nav_bar,$bgcolor,$args)=@_;
1.339     albertel 4758: 
1.954     raeburn  4759:     my $public;
                   4760:     if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
                   4761:         || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
                   4762:         $public = 1;
                   4763:     }
1.460     albertel 4764:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339     albertel 4765: 
1.183     matthew  4766:     $function = &get_users_function() if (!$function);
1.339     albertel 4767:     my $img =    &designparm($function.'.img',$domain);
                   4768:     my $font =   &designparm($function.'.font',$domain);
                   4769:     my $pgbg   = $bgcolor || &designparm($function.'.pgbg',$domain);
                   4770: 
1.803     bisitz   4771:     my %design = ( 'style'   => 'margin-top: 0',
1.535     albertel 4772: 		   'bgcolor' => $pgbg,
1.339     albertel 4773: 		   'text'    => $font,
                   4774:                    'alink'   => &designparm($function.'.alink',$domain),
                   4775: 		   'vlink'   => &designparm($function.'.vlink',$domain),
                   4776: 		   'link'    => &designparm($function.'.link',$domain),);
1.438     albertel 4777:     @design{keys(%$addentries)} = @$addentries{keys(%$addentries)}; 
1.339     albertel 4778: 
1.63      www      4779:  # role and realm
1.378     raeburn  4780:     my ($role,$realm) = split(/\./,$env{'request.role'},2);
                   4781:     if ($role  eq 'ca') {
1.479     albertel 4782:         my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500     albertel 4783:         $realm = &plainname($rname,$rdom);
1.378     raeburn  4784:     } 
1.55      www      4785: # realm
1.258     albertel 4786:     if ($env{'request.course.id'}) {
1.378     raeburn  4787:         if ($env{'request.role'} !~ /^cr/) {
                   4788:             $role = &Apache::lonnet::plaintext($role,&course_type());
                   4789:         }
1.898     raeburn  4790:         if ($env{'request.course.sec'}) {
                   4791:             $role .= ('&nbsp;'x2).'-&nbsp;'.&mt('section:').'&nbsp;'.$env{'request.course.sec'};
                   4792:         }   
1.359     albertel 4793: 	$realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378     raeburn  4794:     } else {
                   4795:         $role = &Apache::lonnet::plaintext($role);
1.54      www      4796:     }
1.433     albertel 4797: 
1.359     albertel 4798:     if (!$realm) { $realm='&nbsp;'; }
1.330     albertel 4799: 
1.438     albertel 4800:     my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329     albertel 4801: 
1.101     www      4802: # construct main body tag
1.359     albertel 4803:     my $bodytag = "<body $extra_body_attr>".
1.562     albertel 4804: 	&Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252     albertel 4805: 
1.530     albertel 4806:     if ($bodyonly) {
1.60      matthew  4807:         return $bodytag;
1.798     tempelho 4808:     } 
1.359     albertel 4809: 
1.410     albertel 4810:     my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.954     raeburn  4811:     if ($public) {
1.433     albertel 4812: 	undef($role);
1.434     albertel 4813:     } else {
                   4814: 	$name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433     albertel 4815:     }
1.359     albertel 4816:     
1.762     bisitz   4817:     my $titleinfo = '<h1>'.$title.'</h1>';
1.359     albertel 4818:     #
                   4819:     # Extra info if you are the DC
                   4820:     my $dc_info = '';
                   4821:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   4822:                         $env{'course.'.$env{'request.course.id'}.
                   4823:                                  '.domain'}.'/'})) {
                   4824:         my $cid = $env{'request.course.id'};
1.917     raeburn  4825:         $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380     www      4826:         $dc_info =~ s/\s+$//;
1.359     albertel 4827:     }
                   4828: 
1.898     raeburn  4829:     $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853     droeschl 4830:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   4831: 
1.916     droeschl 4832:         if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') { 
                   4833:             return $bodytag; 
                   4834:         } 
1.903     droeschl 4835: 
                   4836:         if ($env{'request.state'} eq 'construct') { $forcereg=1; }
                   4837: 
                   4838:         #    if ($env{'request.state'} eq 'construct') {
                   4839:         #        $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
                   4840:         #    }
                   4841: 
1.359     albertel 4842: 
                   4843: 
1.916     droeschl 4844:         if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917     raeburn  4845:              if ($dc_info) {
                   4846:                  $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
                   4847:              }
1.916     droeschl 4848:              $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
                   4849:                 <em>$realm</em> $dc_info</div>|;
1.903     droeschl 4850:             return $bodytag;
                   4851:         }
1.894     droeschl 4852: 
1.927     raeburn  4853:         unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
                   4854:             $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>|;
                   4855:         }
1.916     droeschl 4856: 
1.903     droeschl 4857:         $bodytag .= Apache::lonhtmlcommon::scripttag(
                   4858:             Apache::lonmenu::utilityfunctions(), 'start');
1.816     bisitz   4859: 
1.903     droeschl 4860:         $bodytag .= Apache::lonmenu::primary_menu();
1.852     droeschl 4861: 
1.917     raeburn  4862:         if ($dc_info) {
                   4863:             $dc_info = &dc_courseid_toggle($dc_info);
                   4864:         }
                   4865:         $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916     droeschl 4866: 
1.903     droeschl 4867:         #don't show menus for public users
1.954     raeburn  4868:         if (!$public){
1.903     droeschl 4869:             $bodytag .= Apache::lonmenu::secondary_menu();
                   4870:             $bodytag .= Apache::lonmenu::serverform();
1.920     raeburn  4871:             $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
                   4872:             if ($env{'request.state'} eq 'construct') {
1.962     droeschl 4873:                 $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920     raeburn  4874:                                 $args->{'bread_crumbs'});
                   4875:             } elsif ($forcereg) { 
                   4876:                 $bodytag .= &Apache::lonmenu::innerregister($forcereg);
                   4877:             }
1.903     droeschl 4878:         }else{
                   4879:             # this is to seperate menu from content when there's no secondary
                   4880:             # menu. Especially needed for public accessible ressources.
                   4881:             $bodytag .= '<hr style="clear:both" />';
                   4882:             $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end'); 
1.235     raeburn  4883:         }
1.903     droeschl 4884: 
1.235     raeburn  4885:         return $bodytag;
1.182     matthew  4886: }
                   4887: 
1.917     raeburn  4888: sub dc_courseid_toggle {
                   4889:     my ($dc_info) = @_;
1.980     raeburn  4890:     return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.917     raeburn  4891:            '<a href="javascript:showCourseID();">'.
                   4892:            &mt('(More ...)').'</a></span>'.
                   4893:            '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
                   4894: }
                   4895: 
1.330     albertel 4896: sub make_attr_string {
                   4897:     my ($register,$attr_ref) = @_;
                   4898: 
                   4899:     if ($attr_ref && !ref($attr_ref)) {
                   4900: 	die("addentries Must be a hash ref ".
                   4901: 	    join(':',caller(1))." ".
                   4902: 	    join(':',caller(0))." ");
                   4903:     }
                   4904: 
                   4905:     if ($register) {
1.339     albertel 4906: 	my ($on_load,$on_unload);
                   4907: 	foreach my $key (keys(%{$attr_ref})) {
                   4908: 	    if      (lc($key) eq 'onload') {
                   4909: 		$on_load.=$attr_ref->{$key}.';';
                   4910: 		delete($attr_ref->{$key});
                   4911: 
                   4912: 	    } elsif (lc($key) eq 'onunload') {
                   4913: 		$on_unload.=$attr_ref->{$key}.';';
                   4914: 		delete($attr_ref->{$key});
                   4915: 	    }
                   4916: 	}
1.953     droeschl 4917: 	$attr_ref->{'onload'}  = $on_load;
                   4918: 	$attr_ref->{'onunload'}= $on_unload;
1.330     albertel 4919:     }
1.339     albertel 4920: 
1.330     albertel 4921:     my $attr_string;
                   4922:     foreach my $attr (keys(%$attr_ref)) {
                   4923: 	$attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
                   4924:     }
                   4925:     return $attr_string;
                   4926: }
                   4927: 
                   4928: 
1.182     matthew  4929: ###############################################
1.251     albertel 4930: ###############################################
                   4931: 
                   4932: =pod
                   4933: 
                   4934: =item * &endbodytag()
                   4935: 
                   4936: Returns a uniform footer for LON-CAPA web pages.
                   4937: 
1.635     raeburn  4938: Inputs: 1 - optional reference to an args hash
                   4939: If in the hash, key for noredirectlink has a value which evaluates to true,
                   4940: a 'Continue' link is not displayed if the page contains an
                   4941: internal redirect in the <head></head> section,
                   4942: i.e., $env{'internal.head.redirect'} exists   
1.251     albertel 4943: 
                   4944: =cut
                   4945: 
                   4946: sub endbodytag {
1.635     raeburn  4947:     my ($args) = @_;
1.251     albertel 4948:     my $endbodytag='</body>';
1.269     albertel 4949:     $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315     albertel 4950:     if ( exists( $env{'internal.head.redirect'} ) ) {
1.635     raeburn  4951:         if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
                   4952: 	    $endbodytag=
                   4953: 	        "<br /><a href=\"$env{'internal.head.redirect'}\">".
                   4954: 	        &mt('Continue').'</a>'.
                   4955: 	        $endbodytag;
                   4956:         }
1.315     albertel 4957:     }
1.251     albertel 4958:     return $endbodytag;
                   4959: }
                   4960: 
1.352     albertel 4961: =pod
                   4962: 
                   4963: =item * &standard_css()
                   4964: 
                   4965: Returns a style sheet
                   4966: 
                   4967: Inputs: (all optional)
                   4968:             domain         -> force to color decorate a page for a specific
                   4969:                                domain
                   4970:             function       -> force usage of a specific rolish color scheme
                   4971:             bgcolor        -> override the default page bgcolor
                   4972: 
                   4973: =cut
                   4974: 
1.343     albertel 4975: sub standard_css {
1.345     albertel 4976:     my ($function,$domain,$bgcolor) = @_;
1.352     albertel 4977:     $function  = &get_users_function() if (!$function);
                   4978:     my $img    = &designparm($function.'.img',   $domain);
                   4979:     my $tabbg  = &designparm($function.'.tabbg', $domain);
                   4980:     my $font   = &designparm($function.'.font',  $domain);
1.801     tempelho 4981:     my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791     tempelho 4982: #second colour for later usage
1.345     albertel 4983:     my $sidebg = &designparm($function.'.sidebg',$domain);
1.382     albertel 4984:     my $pgbg_or_bgcolor =
                   4985: 	         $bgcolor ||
1.352     albertel 4986: 	         &designparm($function.'.pgbg',  $domain);
1.382     albertel 4987:     my $pgbg   = &designparm($function.'.pgbg',  $domain);
1.352     albertel 4988:     my $alink  = &designparm($function.'.alink', $domain);
                   4989:     my $vlink  = &designparm($function.'.vlink', $domain);
                   4990:     my $link   = &designparm($function.'.link',  $domain);
                   4991: 
1.602     albertel 4992:     my $sans                 = 'Verdana,Arial,Helvetica,sans-serif';
1.395     albertel 4993:     my $mono                 = 'monospace';
1.850     bisitz   4994:     my $data_table_head      = $sidebg;
                   4995:     my $data_table_light     = '#FAFAFA';
                   4996:     my $data_table_dark      = '#F0F0F0';
1.470     banghart 4997:     my $data_table_darker    = '#CCCCCC';
1.349     albertel 4998:     my $data_table_highlight = '#FFFF00';
1.352     albertel 4999:     my $mail_new             = '#FFBB77';
                   5000:     my $mail_new_hover       = '#DD9955';
                   5001:     my $mail_read            = '#BBBB77';
                   5002:     my $mail_read_hover      = '#999944';
                   5003:     my $mail_replied         = '#AAAA88';
                   5004:     my $mail_replied_hover   = '#888855';
                   5005:     my $mail_other           = '#99BBBB';
                   5006:     my $mail_other_hover     = '#669999';
1.391     albertel 5007:     my $table_header         = '#DDDDDD';
1.489     raeburn  5008:     my $feedback_link_bg     = '#BBBBBB';
1.911     bisitz   5009:     my $lg_border_color      = '#C8C8C8';
1.952     onken    5010:     my $button_hover         = '#BF2317';
1.392     albertel 5011: 
1.608     albertel 5012:     my $border = ($env{'browser.type'} eq 'explorer' ||
1.911     bisitz   5013:       $env{'browser.type'} eq 'safari'     ) ? '0 2px 0 2px'
                   5014:                                              : '0 3px 0 4px';
1.448     albertel 5015: 
1.523     albertel 5016: 
1.343     albertel 5017:     return <<END;
1.947     droeschl 5018: 
                   5019: /* needed for iframe to allow 100% height in FF */
                   5020: body, html { 
                   5021:     margin: 0;
                   5022:     padding: 0 0.5%;
                   5023:     height: 99%; /* to avoid scrollbars */
                   5024: }
                   5025: 
1.795     www      5026: body {
1.911     bisitz   5027:   font-family: $sans;
                   5028:   line-height:130%;
                   5029:   font-size:0.83em;
                   5030:   color:$font;
1.795     www      5031: }
                   5032: 
1.959     onken    5033: a:focus,
                   5034: a:focus img {
1.795     www      5035:   color: red;
                   5036: }
1.698     harmsja  5037: 
1.911     bisitz   5038: form, .inline {
                   5039:   display: inline;
1.795     www      5040: }
1.721     harmsja  5041: 
1.795     www      5042: .LC_right {
1.911     bisitz   5043:   text-align:right;
1.795     www      5044: }
                   5045: 
                   5046: .LC_middle {
1.911     bisitz   5047:   vertical-align:middle;
1.795     www      5048: }
1.721     harmsja  5049: 
1.911     bisitz   5050: .LC_400Box {
                   5051:   width:400px;
                   5052: }
1.721     harmsja  5053: 
1.947     droeschl 5054: .LC_iframecontainer {
                   5055:     width: 98%;
                   5056:     margin: 0;
                   5057:     position: fixed;
                   5058:     top: 8.5em;
                   5059:     bottom: 0;
                   5060: }
                   5061: 
                   5062: .LC_iframecontainer iframe{
                   5063:     border: none;
                   5064:     width: 100%;
                   5065:     height: 100%;
                   5066: }
                   5067: 
1.778     bisitz   5068: .LC_filename {
                   5069:   font-family: $mono;
                   5070:   white-space:pre;
1.921     bisitz   5071:   font-size: 120%;
1.778     bisitz   5072: }
                   5073: 
                   5074: .LC_fileicon {
                   5075:   border: none;
                   5076:   height: 1.3em;
                   5077:   vertical-align: text-bottom;
                   5078:   margin-right: 0.3em;
                   5079:   text-decoration:none;
                   5080: }
                   5081: 
1.1008    www      5082: .LC_setting {
                   5083:   text-decoration:underline;
                   5084: }
                   5085: 
1.350     albertel 5086: .LC_error {
                   5087:   color: red;
                   5088:   font-size: larger;
                   5089: }
1.795     www      5090: 
1.457     albertel 5091: .LC_warning,
                   5092: .LC_diff_removed {
1.733     bisitz   5093:   color: red;
1.394     albertel 5094: }
1.532     albertel 5095: 
                   5096: .LC_info,
1.457     albertel 5097: .LC_success,
                   5098: .LC_diff_added {
1.350     albertel 5099:   color: green;
                   5100: }
1.795     www      5101: 
1.802     bisitz   5102: div.LC_confirm_box {
                   5103:   background-color: #FAFAFA;
                   5104:   border: 1px solid $lg_border_color;
                   5105:   margin-right: 0;
                   5106:   padding: 5px;
                   5107: }
                   5108: 
                   5109: div.LC_confirm_box .LC_error img,
                   5110: div.LC_confirm_box .LC_success img {
                   5111:   vertical-align: middle;
                   5112: }
                   5113: 
1.440     albertel 5114: .LC_icon {
1.771     droeschl 5115:   border: none;
1.790     droeschl 5116:   vertical-align: middle;
1.771     droeschl 5117: }
                   5118: 
1.543     albertel 5119: .LC_docs_spacer {
                   5120:   width: 25px;
                   5121:   height: 1px;
1.771     droeschl 5122:   border: none;
1.543     albertel 5123: }
1.346     albertel 5124: 
1.532     albertel 5125: .LC_internal_info {
1.735     bisitz   5126:   color: #999999;
1.532     albertel 5127: }
                   5128: 
1.794     www      5129: .LC_discussion {
1.1050    www      5130:   background: $data_table_dark;
1.911     bisitz   5131:   border: 1px solid black;
                   5132:   margin: 2px;
1.794     www      5133: }
                   5134: 
                   5135: .LC_disc_action_left {
1.1050    www      5136:   background: $sidebg;
1.911     bisitz   5137:   text-align: left;
1.1050    www      5138:   padding: 4px;
                   5139:   margin: 2px;
1.794     www      5140: }
                   5141: 
                   5142: .LC_disc_action_right {
1.1050    www      5143:   background: $sidebg;
1.911     bisitz   5144:   text-align: right;
1.1050    www      5145:   padding: 4px;
                   5146:   margin: 2px;
1.794     www      5147: }
                   5148: 
                   5149: .LC_disc_new_item {
1.911     bisitz   5150:   background: white;
                   5151:   border: 2px solid red;
1.1050    www      5152:   margin: 4px;
                   5153:   padding: 4px;
1.794     www      5154: }
                   5155: 
                   5156: .LC_disc_old_item {
1.911     bisitz   5157:   background: white;
1.1050    www      5158:   margin: 4px;
                   5159:   padding: 4px;
1.794     www      5160: }
                   5161: 
1.458     albertel 5162: table.LC_pastsubmission {
                   5163:   border: 1px solid black;
                   5164:   margin: 2px;
                   5165: }
                   5166: 
1.924     bisitz   5167: table#LC_menubuttons {
1.345     albertel 5168:   width: 100%;
                   5169:   background: $pgbg;
1.392     albertel 5170:   border: 2px;
1.402     albertel 5171:   border-collapse: separate;
1.803     bisitz   5172:   padding: 0;
1.345     albertel 5173: }
1.392     albertel 5174: 
1.801     tempelho 5175: table#LC_title_bar a {
                   5176:   color: $fontmenu;
                   5177: }
1.836     bisitz   5178: 
1.807     droeschl 5179: table#LC_title_bar {
1.819     tempelho 5180:   clear: both;
1.836     bisitz   5181:   display: none;
1.807     droeschl 5182: }
                   5183: 
1.795     www      5184: table#LC_title_bar,
1.933     droeschl 5185: table.LC_breadcrumbs, /* obsolete? */
1.393     albertel 5186: table#LC_title_bar.LC_with_remote {
1.359     albertel 5187:   width: 100%;
1.392     albertel 5188:   border-color: $pgbg;
                   5189:   border-style: solid;
                   5190:   border-width: $border;
1.379     albertel 5191:   background: $pgbg;
1.801     tempelho 5192:   color: $fontmenu;
1.392     albertel 5193:   border-collapse: collapse;
1.803     bisitz   5194:   padding: 0;
1.819     tempelho 5195:   margin: 0;
1.359     albertel 5196: }
1.795     www      5197: 
1.933     droeschl 5198: ul.LC_breadcrumb_tools_outerlist {
1.913     droeschl 5199:     margin: 0;
                   5200:     padding: 0;
1.933     droeschl 5201:     position: relative;
                   5202:     list-style: none;
1.913     droeschl 5203: }
1.933     droeschl 5204: ul.LC_breadcrumb_tools_outerlist li {
1.913     droeschl 5205:     display: inline;
                   5206: }
1.933     droeschl 5207: 
                   5208: .LC_breadcrumb_tools_navigation {
1.913     droeschl 5209:     padding: 0;
1.933     droeschl 5210:     margin: 0;
                   5211:     float: left;
1.913     droeschl 5212: }
1.933     droeschl 5213: .LC_breadcrumb_tools_tools {
                   5214:     padding: 0;
                   5215:     margin: 0;
1.913     droeschl 5216:     float: right;
                   5217: }
                   5218: 
1.359     albertel 5219: table#LC_title_bar td {
                   5220:   background: $tabbg;
                   5221: }
1.795     www      5222: 
1.911     bisitz   5223: table#LC_menubuttons img {
1.803     bisitz   5224:   border: none;
1.346     albertel 5225: }
1.795     www      5226: 
1.842     droeschl 5227: .LC_breadcrumbs_component {
1.911     bisitz   5228:   float: right;
                   5229:   margin: 0 1em;
1.357     albertel 5230: }
1.842     droeschl 5231: .LC_breadcrumbs_component img {
1.911     bisitz   5232:   vertical-align: middle;
1.777     tempelho 5233: }
1.795     www      5234: 
1.383     albertel 5235: td.LC_table_cell_checkbox {
                   5236:   text-align: center;
                   5237: }
1.795     www      5238: 
                   5239: .LC_fontsize_small {
1.911     bisitz   5240:   font-size: 70%;
1.705     tempelho 5241: }
                   5242: 
1.844     bisitz   5243: #LC_breadcrumbs {
1.911     bisitz   5244:   clear:both;
                   5245:   background: $sidebg;
                   5246:   border-bottom: 1px solid $lg_border_color;
                   5247:   line-height: 2.5em;
1.933     droeschl 5248:   overflow: hidden;
1.911     bisitz   5249:   margin: 0;
                   5250:   padding: 0;
1.995     raeburn  5251:   text-align: left;
1.819     tempelho 5252: }
1.862     bisitz   5253: 
1.993     raeburn  5254: .LC_head_subbox {
1.911     bisitz   5255:   clear:both;
                   5256:   background: #F8F8F8; /* $sidebg; */
1.915     droeschl 5257:   border: 1px solid $sidebg;
                   5258:   margin: 0 0 10px 0;      
1.966     bisitz   5259:   padding: 3px;
1.995     raeburn  5260:   text-align: left;
1.822     bisitz   5261: }
                   5262: 
1.795     www      5263: .LC_fontsize_medium {
1.911     bisitz   5264:   font-size: 85%;
1.705     tempelho 5265: }
                   5266: 
1.795     www      5267: .LC_fontsize_large {
1.911     bisitz   5268:   font-size: 120%;
1.705     tempelho 5269: }
                   5270: 
1.346     albertel 5271: .LC_menubuttons_inline_text {
                   5272:   color: $font;
1.698     harmsja  5273:   font-size: 90%;
1.701     harmsja  5274:   padding-left:3px;
1.346     albertel 5275: }
                   5276: 
1.934     droeschl 5277: .LC_menubuttons_inline_text img{
                   5278:   vertical-align: middle;
                   5279: }
                   5280: 
1.1051    www      5281: li.LC_menubuttons_inline_text img {
1.951     onken    5282:   cursor:pointer;
1.1002    droeschl 5283:   text-decoration: none;
1.951     onken    5284: }
                   5285: 
1.526     www      5286: .LC_menubuttons_link {
                   5287:   text-decoration: none;
                   5288: }
1.795     www      5289: 
1.522     albertel 5290: .LC_menubuttons_category {
1.521     www      5291:   color: $font;
1.526     www      5292:   background: $pgbg;
1.521     www      5293:   font-size: larger;
                   5294:   font-weight: bold;
                   5295: }
                   5296: 
1.346     albertel 5297: td.LC_menubuttons_text {
1.911     bisitz   5298:   color: $font;
1.346     albertel 5299: }
1.706     harmsja  5300: 
1.346     albertel 5301: .LC_current_location {
                   5302:   background: $tabbg;
                   5303: }
1.795     www      5304: 
1.938     bisitz   5305: table.LC_data_table {
1.347     albertel 5306:   border: 1px solid #000000;
1.402     albertel 5307:   border-collapse: separate;
1.426     albertel 5308:   border-spacing: 1px;
1.610     albertel 5309:   background: $pgbg;
1.347     albertel 5310: }
1.795     www      5311: 
1.422     albertel 5312: .LC_data_table_dense {
                   5313:   font-size: small;
                   5314: }
1.795     www      5315: 
1.507     raeburn  5316: table.LC_nested_outer {
                   5317:   border: 1px solid #000000;
1.589     raeburn  5318:   border-collapse: collapse;
1.803     bisitz   5319:   border-spacing: 0;
1.507     raeburn  5320:   width: 100%;
                   5321: }
1.795     www      5322: 
1.879     raeburn  5323: table.LC_innerpickbox,
1.507     raeburn  5324: table.LC_nested {
1.803     bisitz   5325:   border: none;
1.589     raeburn  5326:   border-collapse: collapse;
1.803     bisitz   5327:   border-spacing: 0;
1.507     raeburn  5328:   width: 100%;
                   5329: }
1.795     www      5330: 
1.911     bisitz   5331: table.LC_data_table tr th,
                   5332: table.LC_calendar tr th,
1.879     raeburn  5333: table.LC_prior_tries tr th,
                   5334: table.LC_innerpickbox tr th {
1.349     albertel 5335:   font-weight: bold;
                   5336:   background-color: $data_table_head;
1.801     tempelho 5337:   color:$fontmenu;
1.701     harmsja  5338:   font-size:90%;
1.347     albertel 5339: }
1.795     www      5340: 
1.879     raeburn  5341: table.LC_innerpickbox tr th,
                   5342: table.LC_innerpickbox tr td {
                   5343:   vertical-align: top;
                   5344: }
                   5345: 
1.711     raeburn  5346: table.LC_data_table tr.LC_info_row > td {
1.735     bisitz   5347:   background-color: #CCCCCC;
1.711     raeburn  5348:   font-weight: bold;
                   5349:   text-align: left;
                   5350: }
1.795     www      5351: 
1.912     bisitz   5352: table.LC_data_table tr.LC_odd_row > td {
                   5353:   background-color: $data_table_light;
                   5354:   padding: 2px;
                   5355:   vertical-align: top;
                   5356: }
                   5357: 
1.809     bisitz   5358: table.LC_pick_box tr > td.LC_odd_row {
1.349     albertel 5359:   background-color: $data_table_light;
1.912     bisitz   5360:   vertical-align: top;
                   5361: }
                   5362: 
                   5363: table.LC_data_table tr.LC_even_row > td {
                   5364:   background-color: $data_table_dark;
1.425     albertel 5365:   padding: 2px;
1.900     bisitz   5366:   vertical-align: top;
1.347     albertel 5367: }
1.795     www      5368: 
1.809     bisitz   5369: table.LC_pick_box tr > td.LC_even_row {
1.349     albertel 5370:   background-color: $data_table_dark;
1.900     bisitz   5371:   vertical-align: top;
1.347     albertel 5372: }
1.795     www      5373: 
1.425     albertel 5374: table.LC_data_table tr.LC_data_table_highlight td {
                   5375:   background-color: $data_table_darker;
                   5376: }
1.795     www      5377: 
1.639     raeburn  5378: table.LC_data_table tr td.LC_leftcol_header {
                   5379:   background-color: $data_table_head;
                   5380:   font-weight: bold;
                   5381: }
1.795     www      5382: 
1.451     albertel 5383: table.LC_data_table tr.LC_empty_row td,
1.507     raeburn  5384: table.LC_nested tr.LC_empty_row td {
1.421     albertel 5385:   font-weight: bold;
                   5386:   font-style: italic;
                   5387:   text-align: center;
                   5388:   padding: 8px;
1.347     albertel 5389: }
1.795     www      5390: 
1.940     bisitz   5391: table.LC_data_table tr.LC_empty_row td {
                   5392:   background-color: $sidebg;
                   5393: }
                   5394: 
                   5395: table.LC_nested tr.LC_empty_row td {
                   5396:   background-color: #FFFFFF;
                   5397: }
                   5398: 
1.890     droeschl 5399: table.LC_caption {
                   5400: }
                   5401: 
1.507     raeburn  5402: table.LC_nested tr.LC_empty_row td {
1.465     albertel 5403:   padding: 4ex
                   5404: }
1.795     www      5405: 
1.507     raeburn  5406: table.LC_nested_outer tr th {
                   5407:   font-weight: bold;
1.801     tempelho 5408:   color:$fontmenu;
1.507     raeburn  5409:   background-color: $data_table_head;
1.701     harmsja  5410:   font-size: small;
1.507     raeburn  5411:   border-bottom: 1px solid #000000;
                   5412: }
1.795     www      5413: 
1.507     raeburn  5414: table.LC_nested_outer tr td.LC_subheader {
                   5415:   background-color: $data_table_head;
                   5416:   font-weight: bold;
                   5417:   font-size: small;
                   5418:   border-bottom: 1px solid #000000;
                   5419:   text-align: right;
1.451     albertel 5420: }
1.795     www      5421: 
1.507     raeburn  5422: table.LC_nested tr.LC_info_row td {
1.735     bisitz   5423:   background-color: #CCCCCC;
1.451     albertel 5424:   font-weight: bold;
                   5425:   font-size: small;
1.507     raeburn  5426:   text-align: center;
                   5427: }
1.795     www      5428: 
1.589     raeburn  5429: table.LC_nested tr.LC_info_row td.LC_left_item,
                   5430: table.LC_nested_outer tr th.LC_left_item {
1.507     raeburn  5431:   text-align: left;
1.451     albertel 5432: }
1.795     www      5433: 
1.507     raeburn  5434: table.LC_nested td {
1.735     bisitz   5435:   background-color: #FFFFFF;
1.451     albertel 5436:   font-size: small;
1.507     raeburn  5437: }
1.795     www      5438: 
1.507     raeburn  5439: table.LC_nested_outer tr th.LC_right_item,
                   5440: table.LC_nested tr.LC_info_row td.LC_right_item,
                   5441: table.LC_nested tr.LC_odd_row td.LC_right_item,
                   5442: table.LC_nested tr td.LC_right_item {
1.451     albertel 5443:   text-align: right;
                   5444: }
                   5445: 
1.507     raeburn  5446: table.LC_nested tr.LC_odd_row td {
1.735     bisitz   5447:   background-color: #EEEEEE;
1.451     albertel 5448: }
                   5449: 
1.473     raeburn  5450: table.LC_createuser {
                   5451: }
                   5452: 
                   5453: table.LC_createuser tr.LC_section_row td {
1.701     harmsja  5454:   font-size: small;
1.473     raeburn  5455: }
                   5456: 
                   5457: table.LC_createuser tr.LC_info_row td  {
1.735     bisitz   5458:   background-color: #CCCCCC;
1.473     raeburn  5459:   font-weight: bold;
                   5460:   text-align: center;
                   5461: }
                   5462: 
1.349     albertel 5463: table.LC_calendar {
                   5464:   border: 1px solid #000000;
                   5465:   border-collapse: collapse;
1.917     raeburn  5466:   width: 98%;
1.349     albertel 5467: }
1.795     www      5468: 
1.349     albertel 5469: table.LC_calendar_pickdate {
                   5470:   font-size: xx-small;
                   5471: }
1.795     www      5472: 
1.349     albertel 5473: table.LC_calendar tr td {
                   5474:   border: 1px solid #000000;
                   5475:   vertical-align: top;
1.917     raeburn  5476:   width: 14%;
1.349     albertel 5477: }
1.795     www      5478: 
1.349     albertel 5479: table.LC_calendar tr td.LC_calendar_day_empty {
                   5480:   background-color: $data_table_dark;
                   5481: }
1.795     www      5482: 
1.779     bisitz   5483: table.LC_calendar tr td.LC_calendar_day_current {
                   5484:   background-color: $data_table_highlight;
1.777     tempelho 5485: }
1.795     www      5486: 
1.938     bisitz   5487: table.LC_data_table tr td.LC_mail_new {
1.349     albertel 5488:   background-color: $mail_new;
                   5489: }
1.795     www      5490: 
1.938     bisitz   5491: table.LC_data_table tr.LC_mail_new:hover {
1.349     albertel 5492:   background-color: $mail_new_hover;
                   5493: }
1.795     www      5494: 
1.938     bisitz   5495: table.LC_data_table tr td.LC_mail_read {
1.349     albertel 5496:   background-color: $mail_read;
                   5497: }
1.795     www      5498: 
1.938     bisitz   5499: /*
                   5500: table.LC_data_table tr.LC_mail_read:hover {
1.349     albertel 5501:   background-color: $mail_read_hover;
                   5502: }
1.938     bisitz   5503: */
1.795     www      5504: 
1.938     bisitz   5505: table.LC_data_table tr td.LC_mail_replied {
1.349     albertel 5506:   background-color: $mail_replied;
                   5507: }
1.795     www      5508: 
1.938     bisitz   5509: /*
                   5510: table.LC_data_table tr.LC_mail_replied:hover {
1.349     albertel 5511:   background-color: $mail_replied_hover;
                   5512: }
1.938     bisitz   5513: */
1.795     www      5514: 
1.938     bisitz   5515: table.LC_data_table tr td.LC_mail_other {
1.349     albertel 5516:   background-color: $mail_other;
                   5517: }
1.795     www      5518: 
1.938     bisitz   5519: /*
                   5520: table.LC_data_table tr.LC_mail_other:hover {
1.349     albertel 5521:   background-color: $mail_other_hover;
                   5522: }
1.938     bisitz   5523: */
1.494     raeburn  5524: 
1.777     tempelho 5525: table.LC_data_table tr > td.LC_browser_file,
                   5526: table.LC_data_table tr > td.LC_browser_file_published {
1.899     bisitz   5527:   background: #AAEE77;
1.389     albertel 5528: }
1.795     www      5529: 
1.777     tempelho 5530: table.LC_data_table tr > td.LC_browser_file_locked,
                   5531: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389     albertel 5532:   background: #FFAA99;
1.387     albertel 5533: }
1.795     www      5534: 
1.777     tempelho 5535: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899     bisitz   5536:   background: #888888;
1.779     bisitz   5537: }
1.795     www      5538: 
1.777     tempelho 5539: table.LC_data_table tr > td.LC_browser_file_modified,
1.779     bisitz   5540: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899     bisitz   5541:   background: #F8F866;
1.777     tempelho 5542: }
1.795     www      5543: 
1.696     bisitz   5544: table.LC_data_table tr.LC_browser_folder > td {
1.899     bisitz   5545:   background: #E0E8FF;
1.387     albertel 5546: }
1.696     bisitz   5547: 
1.707     bisitz   5548: table.LC_data_table tr > td.LC_roles_is {
1.911     bisitz   5549:   /* background: #77FF77; */
1.707     bisitz   5550: }
1.795     www      5551: 
1.707     bisitz   5552: table.LC_data_table tr > td.LC_roles_future {
1.939     bisitz   5553:   border-right: 8px solid #FFFF77;
1.707     bisitz   5554: }
1.795     www      5555: 
1.707     bisitz   5556: table.LC_data_table tr > td.LC_roles_will {
1.939     bisitz   5557:   border-right: 8px solid #FFAA77;
1.707     bisitz   5558: }
1.795     www      5559: 
1.707     bisitz   5560: table.LC_data_table tr > td.LC_roles_expired {
1.939     bisitz   5561:   border-right: 8px solid #FF7777;
1.707     bisitz   5562: }
1.795     www      5563: 
1.707     bisitz   5564: table.LC_data_table tr > td.LC_roles_will_not {
1.939     bisitz   5565:   border-right: 8px solid #AAFF77;
1.707     bisitz   5566: }
1.795     www      5567: 
1.707     bisitz   5568: table.LC_data_table tr > td.LC_roles_selected {
1.939     bisitz   5569:   border-right: 8px solid #11CC55;
1.707     bisitz   5570: }
                   5571: 
1.388     albertel 5572: span.LC_current_location {
1.701     harmsja  5573:   font-size:larger;
1.388     albertel 5574:   background: $pgbg;
                   5575: }
1.387     albertel 5576: 
1.1029    www      5577: span.LC_current_nav_location {
                   5578:   font-weight:bold;
                   5579:   background: $sidebg;
                   5580: }
                   5581: 
1.395     albertel 5582: span.LC_parm_menu_item {
                   5583:   font-size: larger;
                   5584: }
1.795     www      5585: 
1.395     albertel 5586: span.LC_parm_scope_all {
                   5587:   color: red;
                   5588: }
1.795     www      5589: 
1.395     albertel 5590: span.LC_parm_scope_folder {
                   5591:   color: green;
                   5592: }
1.795     www      5593: 
1.395     albertel 5594: span.LC_parm_scope_resource {
                   5595:   color: orange;
                   5596: }
1.795     www      5597: 
1.395     albertel 5598: span.LC_parm_part {
                   5599:   color: blue;
                   5600: }
1.795     www      5601: 
1.911     bisitz   5602: span.LC_parm_folder,
                   5603: span.LC_parm_symb {
1.395     albertel 5604:   font-size: x-small;
                   5605:   font-family: $mono;
                   5606:   color: #AAAAAA;
                   5607: }
                   5608: 
1.977     bisitz   5609: ul.LC_parm_parmlist li {
                   5610:   display: inline-block;
                   5611:   padding: 0.3em 0.8em;
                   5612:   vertical-align: top;
                   5613:   width: 150px;
                   5614:   border-top:1px solid $lg_border_color;
                   5615: }
                   5616: 
1.795     www      5617: td.LC_parm_overview_level_menu,
                   5618: td.LC_parm_overview_map_menu,
                   5619: td.LC_parm_overview_parm_selectors,
                   5620: td.LC_parm_overview_restrictions  {
1.396     albertel 5621:   border: 1px solid black;
                   5622:   border-collapse: collapse;
                   5623: }
1.795     www      5624: 
1.396     albertel 5625: table.LC_parm_overview_restrictions td {
                   5626:   border-width: 1px 4px 1px 4px;
                   5627:   border-style: solid;
                   5628:   border-color: $pgbg;
                   5629:   text-align: center;
                   5630: }
1.795     www      5631: 
1.396     albertel 5632: table.LC_parm_overview_restrictions th {
                   5633:   background: $tabbg;
                   5634:   border-width: 1px 4px 1px 4px;
                   5635:   border-style: solid;
                   5636:   border-color: $pgbg;
                   5637: }
1.795     www      5638: 
1.398     albertel 5639: table#LC_helpmenu {
1.803     bisitz   5640:   border: none;
1.398     albertel 5641:   height: 55px;
1.803     bisitz   5642:   border-spacing: 0;
1.398     albertel 5643: }
                   5644: 
                   5645: table#LC_helpmenu fieldset legend {
                   5646:   font-size: larger;
                   5647: }
1.795     www      5648: 
1.397     albertel 5649: table#LC_helpmenu_links {
                   5650:   width: 100%;
                   5651:   border: 1px solid black;
                   5652:   background: $pgbg;
1.803     bisitz   5653:   padding: 0;
1.397     albertel 5654:   border-spacing: 1px;
                   5655: }
1.795     www      5656: 
1.397     albertel 5657: table#LC_helpmenu_links tr td {
                   5658:   padding: 1px;
                   5659:   background: $tabbg;
1.399     albertel 5660:   text-align: center;
                   5661:   font-weight: bold;
1.397     albertel 5662: }
1.396     albertel 5663: 
1.795     www      5664: table#LC_helpmenu_links a:link,
                   5665: table#LC_helpmenu_links a:visited,
1.397     albertel 5666: table#LC_helpmenu_links a:active {
                   5667:   text-decoration: none;
                   5668:   color: $font;
                   5669: }
1.795     www      5670: 
1.397     albertel 5671: table#LC_helpmenu_links a:hover {
                   5672:   text-decoration: underline;
                   5673:   color: $vlink;
                   5674: }
1.396     albertel 5675: 
1.417     albertel 5676: .LC_chrt_popup_exists {
                   5677:   border: 1px solid #339933;
                   5678:   margin: -1px;
                   5679: }
1.795     www      5680: 
1.417     albertel 5681: .LC_chrt_popup_up {
                   5682:   border: 1px solid yellow;
                   5683:   margin: -1px;
                   5684: }
1.795     www      5685: 
1.417     albertel 5686: .LC_chrt_popup {
                   5687:   border: 1px solid #8888FF;
                   5688:   background: #CCCCFF;
                   5689: }
1.795     www      5690: 
1.421     albertel 5691: table.LC_pick_box {
                   5692:   border-collapse: separate;
                   5693:   background: white;
                   5694:   border: 1px solid black;
                   5695:   border-spacing: 1px;
                   5696: }
1.795     www      5697: 
1.421     albertel 5698: table.LC_pick_box td.LC_pick_box_title {
1.850     bisitz   5699:   background: $sidebg;
1.421     albertel 5700:   font-weight: bold;
1.900     bisitz   5701:   text-align: left;
1.740     bisitz   5702:   vertical-align: top;
1.421     albertel 5703:   width: 184px;
                   5704:   padding: 8px;
                   5705: }
1.795     www      5706: 
1.579     raeburn  5707: table.LC_pick_box td.LC_pick_box_value {
                   5708:   text-align: left;
                   5709:   padding: 8px;
                   5710: }
1.795     www      5711: 
1.579     raeburn  5712: table.LC_pick_box td.LC_pick_box_select {
                   5713:   text-align: left;
                   5714:   padding: 8px;
                   5715: }
1.795     www      5716: 
1.424     albertel 5717: table.LC_pick_box td.LC_pick_box_separator {
1.803     bisitz   5718:   padding: 0;
1.421     albertel 5719:   height: 1px;
                   5720:   background: black;
                   5721: }
1.795     www      5722: 
1.421     albertel 5723: table.LC_pick_box td.LC_pick_box_submit {
                   5724:   text-align: right;
                   5725: }
1.795     www      5726: 
1.579     raeburn  5727: table.LC_pick_box td.LC_evenrow_value {
                   5728:   text-align: left;
                   5729:   padding: 8px;
                   5730:   background-color: $data_table_light;
                   5731: }
1.795     www      5732: 
1.579     raeburn  5733: table.LC_pick_box td.LC_oddrow_value {
                   5734:   text-align: left;
                   5735:   padding: 8px;
                   5736:   background-color: $data_table_light;
                   5737: }
1.795     www      5738: 
1.579     raeburn  5739: span.LC_helpform_receipt_cat {
                   5740:   font-weight: bold;
                   5741: }
1.795     www      5742: 
1.424     albertel 5743: table.LC_group_priv_box {
                   5744:   background: white;
                   5745:   border: 1px solid black;
                   5746:   border-spacing: 1px;
                   5747: }
1.795     www      5748: 
1.424     albertel 5749: table.LC_group_priv_box td.LC_pick_box_title {
                   5750:   background: $tabbg;
                   5751:   font-weight: bold;
                   5752:   text-align: right;
                   5753:   width: 184px;
                   5754: }
1.795     www      5755: 
1.424     albertel 5756: table.LC_group_priv_box td.LC_groups_fixed {
                   5757:   background: $data_table_light;
                   5758:   text-align: center;
                   5759: }
1.795     www      5760: 
1.424     albertel 5761: table.LC_group_priv_box td.LC_groups_optional {
                   5762:   background: $data_table_dark;
                   5763:   text-align: center;
                   5764: }
1.795     www      5765: 
1.424     albertel 5766: table.LC_group_priv_box td.LC_groups_functionality {
                   5767:   background: $data_table_darker;
                   5768:   text-align: center;
                   5769:   font-weight: bold;
                   5770: }
1.795     www      5771: 
1.424     albertel 5772: table.LC_group_priv td {
                   5773:   text-align: left;
1.803     bisitz   5774:   padding: 0;
1.424     albertel 5775: }
                   5776: 
                   5777: .LC_navbuttons {
                   5778:   margin: 2ex 0ex 2ex 0ex;
                   5779: }
1.795     www      5780: 
1.423     albertel 5781: .LC_topic_bar {
                   5782:   font-weight: bold;
                   5783:   background: $tabbg;
1.918     wenzelju 5784:   margin: 1em 0em 1em 2em;
1.805     bisitz   5785:   padding: 3px;
1.918     wenzelju 5786:   font-size: 1.2em;
1.423     albertel 5787: }
1.795     www      5788: 
1.423     albertel 5789: .LC_topic_bar span {
1.918     wenzelju 5790:   left: 0.5em;
                   5791:   position: absolute;
1.423     albertel 5792:   vertical-align: middle;
1.918     wenzelju 5793:   font-size: 1.2em;
1.423     albertel 5794: }
1.795     www      5795: 
1.423     albertel 5796: table.LC_course_group_status {
                   5797:   margin: 20px;
                   5798: }
1.795     www      5799: 
1.423     albertel 5800: table.LC_status_selector td {
                   5801:   vertical-align: top;
                   5802:   text-align: center;
1.424     albertel 5803:   padding: 4px;
                   5804: }
1.795     www      5805: 
1.599     albertel 5806: div.LC_feedback_link {
1.616     albertel 5807:   clear: both;
1.829     kalberla 5808:   background: $sidebg;
1.779     bisitz   5809:   width: 100%;
1.829     kalberla 5810:   padding-bottom: 10px;
                   5811:   border: 1px $tabbg solid;
1.833     kalberla 5812:   height: 22px;
                   5813:   line-height: 22px;
                   5814:   padding-top: 5px;
                   5815: }
                   5816: 
                   5817: div.LC_feedback_link img {
                   5818:   height: 22px;
1.867     kalberla 5819:   vertical-align:middle;
1.829     kalberla 5820: }
                   5821: 
1.911     bisitz   5822: div.LC_feedback_link a {
1.829     kalberla 5823:   text-decoration: none;
1.489     raeburn  5824: }
1.795     www      5825: 
1.867     kalberla 5826: div.LC_comblock {
1.911     bisitz   5827:   display:inline;
1.867     kalberla 5828:   color:$font;
                   5829:   font-size:90%;
                   5830: }
                   5831: 
                   5832: div.LC_feedback_link div.LC_comblock {
                   5833:   padding-left:5px;
                   5834: }
                   5835: 
                   5836: div.LC_feedback_link div.LC_comblock a {
                   5837:   color:$font;
                   5838: }
                   5839: 
1.489     raeburn  5840: span.LC_feedback_link {
1.858     bisitz   5841:   /* background: $feedback_link_bg; */
1.599     albertel 5842:   font-size: larger;
                   5843: }
1.795     www      5844: 
1.599     albertel 5845: span.LC_message_link {
1.858     bisitz   5846:   /* background: $feedback_link_bg; */
1.599     albertel 5847:   font-size: larger;
                   5848:   position: absolute;
                   5849:   right: 1em;
1.489     raeburn  5850: }
1.421     albertel 5851: 
1.515     albertel 5852: table.LC_prior_tries {
1.524     albertel 5853:   border: 1px solid #000000;
                   5854:   border-collapse: separate;
                   5855:   border-spacing: 1px;
1.515     albertel 5856: }
1.523     albertel 5857: 
1.515     albertel 5858: table.LC_prior_tries td {
1.524     albertel 5859:   padding: 2px;
1.515     albertel 5860: }
1.523     albertel 5861: 
                   5862: .LC_answer_correct {
1.795     www      5863:   background: lightgreen;
                   5864:   color: darkgreen;
                   5865:   padding: 6px;
1.523     albertel 5866: }
1.795     www      5867: 
1.523     albertel 5868: .LC_answer_charged_try {
1.797     www      5869:   background: #FFAAAA;
1.795     www      5870:   color: darkred;
                   5871:   padding: 6px;
1.523     albertel 5872: }
1.795     www      5873: 
1.779     bisitz   5874: .LC_answer_not_charged_try,
1.523     albertel 5875: .LC_answer_no_grade,
                   5876: .LC_answer_late {
1.795     www      5877:   background: lightyellow;
1.523     albertel 5878:   color: black;
1.795     www      5879:   padding: 6px;
1.523     albertel 5880: }
1.795     www      5881: 
1.523     albertel 5882: .LC_answer_previous {
1.795     www      5883:   background: lightblue;
                   5884:   color: darkblue;
                   5885:   padding: 6px;
1.523     albertel 5886: }
1.795     www      5887: 
1.779     bisitz   5888: .LC_answer_no_message {
1.777     tempelho 5889:   background: #FFFFFF;
                   5890:   color: black;
1.795     www      5891:   padding: 6px;
1.779     bisitz   5892: }
1.795     www      5893: 
1.779     bisitz   5894: .LC_answer_unknown {
                   5895:   background: orange;
                   5896:   color: black;
1.795     www      5897:   padding: 6px;
1.777     tempelho 5898: }
1.795     www      5899: 
1.529     albertel 5900: span.LC_prior_numerical,
                   5901: span.LC_prior_string,
                   5902: span.LC_prior_custom,
                   5903: span.LC_prior_reaction,
                   5904: span.LC_prior_math {
1.925     bisitz   5905:   font-family: $mono;
1.523     albertel 5906:   white-space: pre;
                   5907: }
                   5908: 
1.525     albertel 5909: span.LC_prior_string {
1.925     bisitz   5910:   font-family: $mono;
1.525     albertel 5911:   white-space: pre;
                   5912: }
                   5913: 
1.523     albertel 5914: table.LC_prior_option {
                   5915:   width: 100%;
                   5916:   border-collapse: collapse;
                   5917: }
1.795     www      5918: 
1.911     bisitz   5919: table.LC_prior_rank,
1.795     www      5920: table.LC_prior_match {
1.528     albertel 5921:   border-collapse: collapse;
                   5922: }
1.795     www      5923: 
1.528     albertel 5924: table.LC_prior_option tr td,
                   5925: table.LC_prior_rank tr td,
                   5926: table.LC_prior_match tr td {
1.524     albertel 5927:   border: 1px solid #000000;
1.515     albertel 5928: }
                   5929: 
1.855     bisitz   5930: .LC_nobreak {
1.544     albertel 5931:   white-space: nowrap;
1.519     raeburn  5932: }
                   5933: 
1.576     raeburn  5934: span.LC_cusr_emph {
                   5935:   font-style: italic;
                   5936: }
                   5937: 
1.633     raeburn  5938: span.LC_cusr_subheading {
                   5939:   font-weight: normal;
                   5940:   font-size: 85%;
                   5941: }
                   5942: 
1.861     bisitz   5943: div.LC_docs_entry_move {
1.859     bisitz   5944:   border: 1px solid #BBBBBB;
1.545     albertel 5945:   background: #DDDDDD;
1.861     bisitz   5946:   width: 22px;
1.859     bisitz   5947:   padding: 1px;
                   5948:   margin: 0;
1.545     albertel 5949: }
                   5950: 
1.861     bisitz   5951: table.LC_data_table tr > td.LC_docs_entry_commands,
                   5952: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545     albertel 5953:   background: #DDDDDD;
                   5954:   font-size: x-small;
                   5955: }
1.795     www      5956: 
1.861     bisitz   5957: .LC_docs_entry_parameter {
                   5958:   white-space: nowrap;
                   5959: }
                   5960: 
1.544     albertel 5961: .LC_docs_copy {
1.545     albertel 5962:   color: #000099;
1.544     albertel 5963: }
1.795     www      5964: 
1.544     albertel 5965: .LC_docs_cut {
1.545     albertel 5966:   color: #550044;
1.544     albertel 5967: }
1.795     www      5968: 
1.544     albertel 5969: .LC_docs_rename {
1.545     albertel 5970:   color: #009900;
1.544     albertel 5971: }
1.795     www      5972: 
1.544     albertel 5973: .LC_docs_remove {
1.545     albertel 5974:   color: #990000;
                   5975: }
                   5976: 
1.547     albertel 5977: .LC_docs_reinit_warn,
                   5978: .LC_docs_ext_edit {
                   5979:   font-size: x-small;
                   5980: }
                   5981: 
1.545     albertel 5982: table.LC_docs_adddocs td,
                   5983: table.LC_docs_adddocs th {
                   5984:   border: 1px solid #BBBBBB;
                   5985:   padding: 4px;
                   5986:   background: #DDDDDD;
1.543     albertel 5987: }
                   5988: 
1.584     albertel 5989: table.LC_sty_begin {
                   5990:   background: #BBFFBB;
                   5991: }
1.795     www      5992: 
1.584     albertel 5993: table.LC_sty_end {
                   5994:   background: #FFBBBB;
                   5995: }
                   5996: 
1.589     raeburn  5997: table.LC_double_column {
1.803     bisitz   5998:   border-width: 0;
1.589     raeburn  5999:   border-collapse: collapse;
                   6000:   width: 100%;
                   6001:   padding: 2px;
                   6002: }
                   6003: 
                   6004: table.LC_double_column tr td.LC_left_col {
1.590     raeburn  6005:   top: 2px;
1.589     raeburn  6006:   left: 2px;
                   6007:   width: 47%;
                   6008:   vertical-align: top;
                   6009: }
                   6010: 
                   6011: table.LC_double_column tr td.LC_right_col {
                   6012:   top: 2px;
1.779     bisitz   6013:   right: 2px;
1.589     raeburn  6014:   width: 47%;
                   6015:   vertical-align: top;
                   6016: }
                   6017: 
1.591     raeburn  6018: div.LC_left_float {
                   6019:   float: left;
                   6020:   padding-right: 5%;
1.597     albertel 6021:   padding-bottom: 4px;
1.591     raeburn  6022: }
                   6023: 
                   6024: div.LC_clear_float_header {
1.597     albertel 6025:   padding-bottom: 2px;
1.591     raeburn  6026: }
                   6027: 
                   6028: div.LC_clear_float_footer {
1.597     albertel 6029:   padding-top: 10px;
1.591     raeburn  6030:   clear: both;
                   6031: }
                   6032: 
1.597     albertel 6033: div.LC_grade_show_user {
1.941     bisitz   6034: /*  border-left: 5px solid $sidebg; */
                   6035:   border-top: 5px solid #000000;
                   6036:   margin: 50px 0 0 0;
1.936     bisitz   6037:   padding: 15px 0 5px 10px;
1.597     albertel 6038: }
1.795     www      6039: 
1.936     bisitz   6040: div.LC_grade_show_user_odd_row {
1.941     bisitz   6041: /*  border-left: 5px solid #000000; */
                   6042: }
                   6043: 
                   6044: div.LC_grade_show_user div.LC_Box {
                   6045:   margin-right: 50px;
1.597     albertel 6046: }
                   6047: 
                   6048: div.LC_grade_submissions,
                   6049: div.LC_grade_message_center,
1.936     bisitz   6050: div.LC_grade_info_links {
1.597     albertel 6051:   margin: 5px;
                   6052:   width: 99%;
                   6053:   background: #FFFFFF;
                   6054: }
1.795     www      6055: 
1.597     albertel 6056: div.LC_grade_submissions_header,
1.936     bisitz   6057: div.LC_grade_message_center_header {
1.705     tempelho 6058:   font-weight: bold;
                   6059:   font-size: large;
1.597     albertel 6060: }
1.795     www      6061: 
1.597     albertel 6062: div.LC_grade_submissions_body,
1.936     bisitz   6063: div.LC_grade_message_center_body {
1.597     albertel 6064:   border: 1px solid black;
                   6065:   width: 99%;
                   6066:   background: #FFFFFF;
                   6067: }
1.795     www      6068: 
1.613     albertel 6069: table.LC_scantron_action {
                   6070:   width: 100%;
                   6071: }
1.795     www      6072: 
1.613     albertel 6073: table.LC_scantron_action tr th {
1.698     harmsja  6074:   font-weight:bold;
                   6075:   font-style:normal;
1.613     albertel 6076: }
1.795     www      6077: 
1.779     bisitz   6078: .LC_edit_problem_header,
1.614     albertel 6079: div.LC_edit_problem_footer {
1.705     tempelho 6080:   font-weight: normal;
                   6081:   font-size:  medium;
1.602     albertel 6082:   margin: 2px;
1.600     albertel 6083: }
1.795     www      6084: 
1.600     albertel 6085: div.LC_edit_problem_header,
1.602     albertel 6086: div.LC_edit_problem_header div,
1.614     albertel 6087: div.LC_edit_problem_footer,
                   6088: div.LC_edit_problem_footer div,
1.602     albertel 6089: div.LC_edit_problem_editxml_header,
                   6090: div.LC_edit_problem_editxml_header div {
1.600     albertel 6091:   margin-top: 5px;
                   6092: }
1.795     www      6093: 
1.600     albertel 6094: div.LC_edit_problem_header_title {
1.705     tempelho 6095:   font-weight: bold;
                   6096:   font-size: larger;
1.602     albertel 6097:   background: $tabbg;
                   6098:   padding: 3px;
                   6099: }
1.795     www      6100: 
1.602     albertel 6101: table.LC_edit_problem_header_title {
                   6102:   width: 100%;
1.600     albertel 6103:   background: $tabbg;
1.602     albertel 6104: }
                   6105: 
                   6106: div.LC_edit_problem_discards {
                   6107:   float: left;
                   6108:   padding-bottom: 5px;
                   6109: }
1.795     www      6110: 
1.602     albertel 6111: div.LC_edit_problem_saves {
                   6112:   float: right;
                   6113:   padding-bottom: 5px;
1.600     albertel 6114: }
1.795     www      6115: 
1.911     bisitz   6116: img.stift {
1.803     bisitz   6117:   border-width: 0;
                   6118:   vertical-align: middle;
1.677     riegler  6119: }
1.680     riegler  6120: 
1.923     bisitz   6121: table td.LC_mainmenu_col_fieldset {
1.680     riegler  6122:   vertical-align: top;
1.777     tempelho 6123: }
1.795     www      6124: 
1.716     raeburn  6125: div.LC_createcourse {
1.911     bisitz   6126:   margin: 10px 10px 10px 10px;
1.716     raeburn  6127: }
                   6128: 
1.917     raeburn  6129: .LC_dccid {
                   6130:   margin: 0.2em 0 0 0;
                   6131:   padding: 0;
                   6132:   font-size: 90%;
                   6133:   display:none;
                   6134: }
                   6135: 
1.897     wenzelju 6136: ol.LC_primary_menu a:hover,
1.721     harmsja  6137: ol#LC_MenuBreadcrumbs a:hover,
                   6138: ol#LC_PathBreadcrumbs a:hover,
1.897     wenzelju 6139: ul#LC_secondary_menu a:hover,
1.721     harmsja  6140: .LC_FormSectionClearButton input:hover
1.795     www      6141: ul.LC_TabContent   li:hover a {
1.952     onken    6142:   color:$button_hover;
1.911     bisitz   6143:   text-decoration:none;
1.693     droeschl 6144: }
                   6145: 
1.779     bisitz   6146: h1 {
1.911     bisitz   6147:   padding: 0;
                   6148:   line-height:130%;
1.693     droeschl 6149: }
1.698     harmsja  6150: 
1.911     bisitz   6151: h2,
                   6152: h3,
                   6153: h4,
                   6154: h5,
                   6155: h6 {
                   6156:   margin: 5px 0 5px 0;
                   6157:   padding: 0;
                   6158:   line-height:130%;
1.693     droeschl 6159: }
1.795     www      6160: 
                   6161: .LC_hcell {
1.911     bisitz   6162:   padding:3px 15px 3px 15px;
                   6163:   margin: 0;
                   6164:   background-color:$tabbg;
                   6165:   color:$fontmenu;
                   6166:   border-bottom:solid 1px $lg_border_color;
1.693     droeschl 6167: }
1.795     www      6168: 
1.840     bisitz   6169: .LC_Box > .LC_hcell {
1.911     bisitz   6170:   margin: 0 -10px 10px -10px;
1.835     bisitz   6171: }
                   6172: 
1.721     harmsja  6173: .LC_noBorder {
1.911     bisitz   6174:   border: 0;
1.698     harmsja  6175: }
1.693     droeschl 6176: 
1.721     harmsja  6177: .LC_FormSectionClearButton input {
1.911     bisitz   6178:   background-color:transparent;
                   6179:   border: none;
                   6180:   cursor:pointer;
                   6181:   text-decoration:underline;
1.693     droeschl 6182: }
1.763     bisitz   6183: 
                   6184: .LC_help_open_topic {
1.911     bisitz   6185:   color: #FFFFFF;
                   6186:   background-color: #EEEEFF;
                   6187:   margin: 1px;
                   6188:   padding: 4px;
                   6189:   border: 1px solid #000033;
                   6190:   white-space: nowrap;
                   6191:   /* vertical-align: middle; */
1.759     neumanie 6192: }
1.693     droeschl 6193: 
1.911     bisitz   6194: dl,
                   6195: ul,
                   6196: div,
                   6197: fieldset {
                   6198:   margin: 10px 10px 10px 0;
                   6199:   /* overflow: hidden; */
1.693     droeschl 6200: }
1.795     www      6201: 
1.838     bisitz   6202: fieldset > legend {
1.911     bisitz   6203:   font-weight: bold;
                   6204:   padding: 0 5px 0 5px;
1.838     bisitz   6205: }
                   6206: 
1.813     bisitz   6207: #LC_nav_bar {
1.911     bisitz   6208:   float: left;
1.995     raeburn  6209:   background-color: $pgbg_or_bgcolor;
1.966     bisitz   6210:   margin: 0 0 2px 0;
1.807     droeschl 6211: }
                   6212: 
1.916     droeschl 6213: #LC_realm {
                   6214:   margin: 0.2em 0 0 0;
                   6215:   padding: 0;
                   6216:   font-weight: bold;
                   6217:   text-align: center;
1.995     raeburn  6218:   background-color: $pgbg_or_bgcolor;
1.916     droeschl 6219: }
                   6220: 
1.911     bisitz   6221: #LC_nav_bar em {
                   6222:   font-weight: bold;
                   6223:   font-style: normal;
1.807     droeschl 6224: }
                   6225: 
1.897     wenzelju 6226: ol.LC_primary_menu {
1.911     bisitz   6227:   float: right;
1.934     droeschl 6228:   margin: 0;
1.995     raeburn  6229:   background-color: $pgbg_or_bgcolor;
1.807     droeschl 6230: }
                   6231: 
1.852     droeschl 6232: ol#LC_PathBreadcrumbs {
1.911     bisitz   6233:   margin: 0;
1.693     droeschl 6234: }
                   6235: 
1.897     wenzelju 6236: ol.LC_primary_menu li {
1.911     bisitz   6237:   display: inline;
                   6238:   padding: 5px 5px 0 10px;
                   6239:   vertical-align: top;
1.693     droeschl 6240: }
                   6241: 
1.897     wenzelju 6242: ol.LC_primary_menu li img {
1.911     bisitz   6243:   vertical-align: bottom;
1.934     droeschl 6244:   height: 1.1em;
1.693     droeschl 6245: }
                   6246: 
1.897     wenzelju 6247: ol.LC_primary_menu a {
1.911     bisitz   6248:   color: RGB(80, 80, 80);
                   6249:   text-decoration: none;
1.693     droeschl 6250: }
1.795     www      6251: 
1.949     droeschl 6252: ol.LC_primary_menu a.LC_new_message {
                   6253:   font-weight:bold;
                   6254:   color: darkred;
                   6255: }
                   6256: 
1.975     raeburn  6257: ol.LC_docs_parameters {
                   6258:   margin-left: 0;
                   6259:   padding: 0;
                   6260:   list-style: none;
                   6261: }
                   6262: 
                   6263: ol.LC_docs_parameters li {
                   6264:   margin: 0;
                   6265:   padding-right: 20px;
                   6266:   display: inline;
                   6267: }
                   6268: 
1.976     raeburn  6269: ol.LC_docs_parameters li:before {
                   6270:   content: "\\002022 \\0020";
                   6271: }
                   6272: 
                   6273: li.LC_docs_parameters_title {
                   6274:   font-weight: bold;
                   6275: }
                   6276: 
                   6277: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
                   6278:   content: "";
                   6279: }
                   6280: 
1.897     wenzelju 6281: ul#LC_secondary_menu {
1.911     bisitz   6282:   clear: both;
                   6283:   color: $fontmenu;
                   6284:   background: $tabbg;
                   6285:   list-style: none;
                   6286:   padding: 0;
                   6287:   margin: 0;
                   6288:   width: 100%;
1.995     raeburn  6289:   text-align: left;
1.808     droeschl 6290: }
                   6291: 
1.897     wenzelju 6292: ul#LC_secondary_menu li {
1.911     bisitz   6293:   font-weight: bold;
                   6294:   line-height: 1.8em;
                   6295:   padding: 0 0.8em;
                   6296:   border-right: 1px solid black;
                   6297:   display: inline;
                   6298:   vertical-align: middle;
1.807     droeschl 6299: }
                   6300: 
1.847     tempelho 6301: ul.LC_TabContent {
1.911     bisitz   6302:   display:block;
                   6303:   background: $sidebg;
                   6304:   border-bottom: solid 1px $lg_border_color;
                   6305:   list-style:none;
1.1020    raeburn  6306:   margin: -1px -10px 0 -10px;
1.911     bisitz   6307:   padding: 0;
1.693     droeschl 6308: }
                   6309: 
1.795     www      6310: ul.LC_TabContent li,
                   6311: ul.LC_TabContentBigger li {
1.911     bisitz   6312:   float:left;
1.741     harmsja  6313: }
1.795     www      6314: 
1.897     wenzelju 6315: ul#LC_secondary_menu li a {
1.911     bisitz   6316:   color: $fontmenu;
                   6317:   text-decoration: none;
1.693     droeschl 6318: }
1.795     www      6319: 
1.721     harmsja  6320: ul.LC_TabContent {
1.952     onken    6321:   min-height:20px;
1.721     harmsja  6322: }
1.795     www      6323: 
                   6324: ul.LC_TabContent li {
1.911     bisitz   6325:   vertical-align:middle;
1.959     onken    6326:   padding: 0 16px 0 10px;
1.911     bisitz   6327:   background-color:$tabbg;
                   6328:   border-bottom:solid 1px $lg_border_color;
1.1020    raeburn  6329:   border-left: solid 1px $font;
1.721     harmsja  6330: }
1.795     www      6331: 
1.847     tempelho 6332: ul.LC_TabContent .right {
1.911     bisitz   6333:   float:right;
1.847     tempelho 6334: }
                   6335: 
1.911     bisitz   6336: ul.LC_TabContent li a,
                   6337: ul.LC_TabContent li {
                   6338:   color:rgb(47,47,47);
                   6339:   text-decoration:none;
                   6340:   font-size:95%;
                   6341:   font-weight:bold;
1.952     onken    6342:   min-height:20px;
                   6343: }
                   6344: 
1.959     onken    6345: ul.LC_TabContent li a:hover,
                   6346: ul.LC_TabContent li a:focus {
1.952     onken    6347:   color: $button_hover;
1.959     onken    6348:   background:none;
                   6349:   outline:none;
1.952     onken    6350: }
                   6351: 
                   6352: ul.LC_TabContent li:hover {
                   6353:   color: $button_hover;
                   6354:   cursor:pointer;
1.721     harmsja  6355: }
1.795     www      6356: 
1.911     bisitz   6357: ul.LC_TabContent li.active {
1.952     onken    6358:   color: $font;
1.911     bisitz   6359:   background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952     onken    6360:   border-bottom:solid 1px #FFFFFF;
                   6361:   cursor: default;
1.744     ehlerst  6362: }
1.795     www      6363: 
1.959     onken    6364: ul.LC_TabContent li.active a {
                   6365:   color:$font;
                   6366:   background:#FFFFFF;
                   6367:   outline: none;
                   6368: }
1.1047    raeburn  6369: 
                   6370: ul.LC_TabContent li.goback {
                   6371:   float: left;
                   6372:   border-left: none;
                   6373: }
                   6374: 
1.870     tempelho 6375: #maincoursedoc {
1.911     bisitz   6376:   clear:both;
1.870     tempelho 6377: }
                   6378: 
                   6379: ul.LC_TabContentBigger {
1.911     bisitz   6380:   display:block;
                   6381:   list-style:none;
                   6382:   padding: 0;
1.870     tempelho 6383: }
                   6384: 
1.795     www      6385: ul.LC_TabContentBigger li {
1.911     bisitz   6386:   vertical-align:bottom;
                   6387:   height: 30px;
                   6388:   font-size:110%;
                   6389:   font-weight:bold;
                   6390:   color: #737373;
1.841     tempelho 6391: }
                   6392: 
1.957     onken    6393: ul.LC_TabContentBigger li.active {
                   6394:   position: relative;
                   6395:   top: 1px;
                   6396: }
                   6397: 
1.870     tempelho 6398: ul.LC_TabContentBigger li a {
1.911     bisitz   6399:   background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
                   6400:   height: 30px;
                   6401:   line-height: 30px;
                   6402:   text-align: center;
                   6403:   display: block;
                   6404:   text-decoration: none;
1.958     onken    6405:   outline: none;  
1.741     harmsja  6406: }
1.795     www      6407: 
1.870     tempelho 6408: ul.LC_TabContentBigger li.active a {
1.911     bisitz   6409:   background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
                   6410:   color:$font;
1.744     ehlerst  6411: }
1.795     www      6412: 
1.870     tempelho 6413: ul.LC_TabContentBigger li b {
1.911     bisitz   6414:   background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
                   6415:   display: block;
                   6416:   float: left;
                   6417:   padding: 0 30px;
1.957     onken    6418:   border-bottom: 1px solid $lg_border_color;
1.870     tempelho 6419: }
                   6420: 
1.956     onken    6421: ul.LC_TabContentBigger li:hover b {
                   6422:   color:$button_hover;
                   6423: }
                   6424: 
1.870     tempelho 6425: ul.LC_TabContentBigger li.active b {
1.911     bisitz   6426:   background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
                   6427:   color:$font;
1.957     onken    6428:   border: 0;
1.741     harmsja  6429: }
1.693     droeschl 6430: 
1.870     tempelho 6431: 
1.862     bisitz   6432: ul.LC_CourseBreadcrumbs {
                   6433:   background: $sidebg;
1.1020    raeburn  6434:   height: 2em;
1.862     bisitz   6435:   padding-left: 10px;
1.1020    raeburn  6436:   margin: 0;
1.862     bisitz   6437:   list-style-position: inside;
                   6438: }
                   6439: 
1.911     bisitz   6440: ol#LC_MenuBreadcrumbs,
1.862     bisitz   6441: ol#LC_PathBreadcrumbs {
1.911     bisitz   6442:   padding-left: 10px;
                   6443:   margin: 0;
1.933     droeschl 6444:   height: 2.5em;  /* equal to #LC_breadcrumbs line-height */
1.693     droeschl 6445: }
                   6446: 
1.911     bisitz   6447: ol#LC_MenuBreadcrumbs li,
                   6448: ol#LC_PathBreadcrumbs li,
1.862     bisitz   6449: ul.LC_CourseBreadcrumbs li {
1.911     bisitz   6450:   display: inline;
1.933     droeschl 6451:   white-space: normal;  
1.693     droeschl 6452: }
                   6453: 
1.823     bisitz   6454: ol#LC_MenuBreadcrumbs li a,
1.862     bisitz   6455: ul.LC_CourseBreadcrumbs li a {
1.911     bisitz   6456:   text-decoration: none;
                   6457:   font-size:90%;
1.693     droeschl 6458: }
1.795     www      6459: 
1.969     droeschl 6460: ol#LC_MenuBreadcrumbs h1 {
                   6461:   display: inline;
                   6462:   font-size: 90%;
                   6463:   line-height: 2.5em;
                   6464:   margin: 0;
                   6465:   padding: 0;
                   6466: }
                   6467: 
1.795     www      6468: ol#LC_PathBreadcrumbs li a {
1.911     bisitz   6469:   text-decoration:none;
                   6470:   font-size:100%;
                   6471:   font-weight:bold;
1.693     droeschl 6472: }
1.795     www      6473: 
1.840     bisitz   6474: .LC_Box {
1.911     bisitz   6475:   border: solid 1px $lg_border_color;
                   6476:   padding: 0 10px 10px 10px;
1.746     neumanie 6477: }
1.795     www      6478: 
1.1020    raeburn  6479: .LC_DocsBox {
                   6480:   border: solid 1px $lg_border_color;
                   6481:   padding: 0 0 10px 10px;
                   6482: }
                   6483: 
1.795     www      6484: .LC_AboutMe_Image {
1.911     bisitz   6485:   float:left;
                   6486:   margin-right:10px;
1.747     neumanie 6487: }
1.795     www      6488: 
                   6489: .LC_Clear_AboutMe_Image {
1.911     bisitz   6490:   clear:left;
1.747     neumanie 6491: }
1.795     www      6492: 
1.721     harmsja  6493: dl.LC_ListStyleClean dt {
1.911     bisitz   6494:   padding-right: 5px;
                   6495:   display: table-header-group;
1.693     droeschl 6496: }
                   6497: 
1.721     harmsja  6498: dl.LC_ListStyleClean dd {
1.911     bisitz   6499:   display: table-row;
1.693     droeschl 6500: }
                   6501: 
1.721     harmsja  6502: .LC_ListStyleClean,
                   6503: .LC_ListStyleSimple,
                   6504: .LC_ListStyleNormal,
1.795     www      6505: .LC_ListStyleSpecial {
1.911     bisitz   6506:   /* display:block; */
                   6507:   list-style-position: inside;
                   6508:   list-style-type: none;
                   6509:   overflow: hidden;
                   6510:   padding: 0;
1.693     droeschl 6511: }
                   6512: 
1.721     harmsja  6513: .LC_ListStyleSimple li,
                   6514: .LC_ListStyleSimple dd,
                   6515: .LC_ListStyleNormal li,
                   6516: .LC_ListStyleNormal dd,
                   6517: .LC_ListStyleSpecial li,
1.795     www      6518: .LC_ListStyleSpecial dd {
1.911     bisitz   6519:   margin: 0;
                   6520:   padding: 5px 5px 5px 10px;
                   6521:   clear: both;
1.693     droeschl 6522: }
                   6523: 
1.721     harmsja  6524: .LC_ListStyleClean li,
                   6525: .LC_ListStyleClean dd {
1.911     bisitz   6526:   padding-top: 0;
                   6527:   padding-bottom: 0;
1.693     droeschl 6528: }
                   6529: 
1.721     harmsja  6530: .LC_ListStyleSimple dd,
1.795     www      6531: .LC_ListStyleSimple li {
1.911     bisitz   6532:   border-bottom: solid 1px $lg_border_color;
1.693     droeschl 6533: }
                   6534: 
1.721     harmsja  6535: .LC_ListStyleSpecial li,
                   6536: .LC_ListStyleSpecial dd {
1.911     bisitz   6537:   list-style-type: none;
                   6538:   background-color: RGB(220, 220, 220);
                   6539:   margin-bottom: 4px;
1.693     droeschl 6540: }
                   6541: 
1.721     harmsja  6542: table.LC_SimpleTable {
1.911     bisitz   6543:   margin:5px;
                   6544:   border:solid 1px $lg_border_color;
1.795     www      6545: }
1.693     droeschl 6546: 
1.721     harmsja  6547: table.LC_SimpleTable tr {
1.911     bisitz   6548:   padding: 0;
                   6549:   border:solid 1px $lg_border_color;
1.693     droeschl 6550: }
1.795     www      6551: 
                   6552: table.LC_SimpleTable thead {
1.911     bisitz   6553:   background:rgb(220,220,220);
1.693     droeschl 6554: }
                   6555: 
1.721     harmsja  6556: div.LC_columnSection {
1.911     bisitz   6557:   display: block;
                   6558:   clear: both;
                   6559:   overflow: hidden;
                   6560:   margin: 0;
1.693     droeschl 6561: }
                   6562: 
1.721     harmsja  6563: div.LC_columnSection>* {
1.911     bisitz   6564:   float: left;
                   6565:   margin: 10px 20px 10px 0;
                   6566:   overflow:hidden;
1.693     droeschl 6567: }
1.721     harmsja  6568: 
1.795     www      6569: table em {
1.911     bisitz   6570:   font-weight: bold;
                   6571:   font-style: normal;
1.748     schulted 6572: }
1.795     www      6573: 
1.779     bisitz   6574: table.LC_tableBrowseRes,
1.795     www      6575: table.LC_tableOfContent {
1.911     bisitz   6576:   border:none;
                   6577:   border-spacing: 1px;
                   6578:   padding: 3px;
                   6579:   background-color: #FFFFFF;
                   6580:   font-size: 90%;
1.753     droeschl 6581: }
1.789     droeschl 6582: 
1.911     bisitz   6583: table.LC_tableOfContent {
                   6584:   border-collapse: collapse;
1.789     droeschl 6585: }
                   6586: 
1.771     droeschl 6587: table.LC_tableBrowseRes a,
1.768     schulted 6588: table.LC_tableOfContent a {
1.911     bisitz   6589:   background-color: transparent;
                   6590:   text-decoration: none;
1.753     droeschl 6591: }
                   6592: 
1.795     www      6593: table.LC_tableOfContent img {
1.911     bisitz   6594:   border: none;
                   6595:   height: 1.3em;
                   6596:   vertical-align: text-bottom;
                   6597:   margin-right: 0.3em;
1.753     droeschl 6598: }
1.757     schulted 6599: 
1.795     www      6600: a#LC_content_toolbar_firsthomework {
1.911     bisitz   6601:   background-image:url(/res/adm/pages/open-first-problem.gif);
1.774     ehlerst  6602: }
                   6603: 
1.795     www      6604: a#LC_content_toolbar_everything {
1.911     bisitz   6605:   background-image:url(/res/adm/pages/show-all.gif);
1.774     ehlerst  6606: }
                   6607: 
1.795     www      6608: a#LC_content_toolbar_uncompleted {
1.911     bisitz   6609:   background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774     ehlerst  6610: }
                   6611: 
1.795     www      6612: #LC_content_toolbar_clearbubbles {
1.911     bisitz   6613:   background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774     ehlerst  6614: }
                   6615: 
1.795     www      6616: a#LC_content_toolbar_changefolder {
1.911     bisitz   6617:   background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757     schulted 6618: }
                   6619: 
1.795     www      6620: a#LC_content_toolbar_changefolder_toggled {
1.911     bisitz   6621:   background-image:url(/res/adm/pages/open-all-folders.gif);
1.757     schulted 6622: }
                   6623: 
1.1043    raeburn  6624: a#LC_content_toolbar_edittoplevel {
                   6625:   background-image:url(/res/adm/pages/edittoplevel.gif);
                   6626: }
                   6627: 
1.795     www      6628: ul#LC_toolbar li a:hover {
1.911     bisitz   6629:   background-position: bottom center;
1.757     schulted 6630: }
                   6631: 
1.795     www      6632: ul#LC_toolbar {
1.911     bisitz   6633:   padding: 0;
                   6634:   margin: 2px;
                   6635:   list-style:none;
                   6636:   position:relative;
                   6637:   background-color:white;
1.757     schulted 6638: }
                   6639: 
1.795     www      6640: ul#LC_toolbar li {
1.911     bisitz   6641:   border:1px solid white;
                   6642:   padding: 0;
                   6643:   margin: 0;
                   6644:   float: left;
                   6645:   display:inline;
                   6646:   vertical-align:middle;
                   6647: }
1.757     schulted 6648: 
1.783     amueller 6649: 
1.795     www      6650: a.LC_toolbarItem {
1.911     bisitz   6651:   display:block;
                   6652:   padding: 0;
                   6653:   margin: 0;
                   6654:   height: 32px;
                   6655:   width: 32px;
                   6656:   color:white;
                   6657:   border: none;
                   6658:   background-repeat:no-repeat;
                   6659:   background-color:transparent;
1.757     schulted 6660: }
                   6661: 
1.915     droeschl 6662: ul.LC_funclist {
                   6663:     margin: 0;
                   6664:     padding: 0.5em 1em 0.5em 0;
                   6665: }
                   6666: 
1.933     droeschl 6667: ul.LC_funclist > li:first-child {
                   6668:     font-weight:bold; 
                   6669:     margin-left:0.8em;
                   6670: }
                   6671: 
1.915     droeschl 6672: ul.LC_funclist + ul.LC_funclist {
                   6673:     /* 
                   6674:        left border as a seperator if we have more than
                   6675:        one list 
                   6676:     */
                   6677:     border-left: 1px solid $sidebg;
                   6678:     /* 
                   6679:        this hides the left border behind the border of the 
                   6680:        outer box if element is wrapped to the next 'line' 
                   6681:     */
                   6682:     margin-left: -1px;
                   6683: }
                   6684: 
1.843     bisitz   6685: ul.LC_funclist li {
1.915     droeschl 6686:   display: inline;
1.782     bisitz   6687:   white-space: nowrap;
1.915     droeschl 6688:   margin: 0 0 0 25px;
                   6689:   line-height: 150%;
1.782     bisitz   6690: }
                   6691: 
1.974     wenzelju 6692: .LC_hidden {
                   6693:   display: none;
                   6694: }
                   6695: 
1.1030    www      6696: .LCmodal-overlay {
                   6697: 		position:fixed;
                   6698: 		top:0;
                   6699: 		right:0;
                   6700: 		bottom:0;
                   6701: 		left:0;
                   6702: 		height:100%;
                   6703: 		width:100%;
                   6704: 		margin:0;
                   6705: 		padding:0;
                   6706: 		background:#999;
                   6707: 		opacity:.75;
                   6708: 		filter: alpha(opacity=75);
                   6709: 		-moz-opacity: 0.75;
                   6710: 		z-index:101;
                   6711: }
                   6712: 
                   6713: * html .LCmodal-overlay {   
                   6714: 		position: absolute;
                   6715: 		height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
                   6716: }
                   6717: 
                   6718: .LCmodal-window {
                   6719: 		position:fixed;
                   6720: 		top:50%;
                   6721: 		left:50%;
                   6722: 		margin:0;
                   6723: 		padding:0;
                   6724: 		z-index:102;
                   6725: 	}
                   6726: 
                   6727: * html .LCmodal-window {
                   6728: 		position:absolute;
                   6729: }
                   6730: 
                   6731: .LCclose-window {
                   6732: 		position:absolute;
                   6733: 		width:32px;
                   6734: 		height:32px;
                   6735: 		right:8px;
                   6736: 		top:8px;
                   6737: 		background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
                   6738: 		text-indent:-99999px;
                   6739: 		overflow:hidden;
                   6740: 		cursor:pointer;
                   6741: }
                   6742: 
1.343     albertel 6743: END
                   6744: }
                   6745: 
1.306     albertel 6746: =pod
                   6747: 
                   6748: =item * &headtag()
                   6749: 
                   6750: Returns a uniform footer for LON-CAPA web pages.
                   6751: 
1.307     albertel 6752: Inputs: $title - optional title for the head
                   6753:         $head_extra - optional extra HTML to put inside the <head>
1.315     albertel 6754:         $args - optional arguments
1.319     albertel 6755:             force_register - if is true call registerurl so the remote is 
                   6756:                              informed
1.415     albertel 6757:             redirect       -> array ref of
                   6758:                                    1- seconds before redirect occurs
                   6759:                                    2- url to redirect to
                   6760:                                    3- whether the side effect should occur
1.315     albertel 6761:                            (side effect of setting 
                   6762:                                $env{'internal.head.redirect'} to the url 
                   6763:                                redirected too)
1.352     albertel 6764:             domain         -> force to color decorate a page for a specific
                   6765:                                domain
                   6766:             function       -> force usage of a specific rolish color scheme
                   6767:             bgcolor        -> override the default page bgcolor
1.460     albertel 6768:             no_auto_mt_title
                   6769:                            -> prevent &mt()ing the title arg
1.464     albertel 6770: 
1.306     albertel 6771: =cut
                   6772: 
                   6773: sub headtag {
1.313     albertel 6774:     my ($title,$head_extra,$args) = @_;
1.306     albertel 6775:     
1.363     albertel 6776:     my $function = $args->{'function'} || &get_users_function();
                   6777:     my $domain   = $args->{'domain'}   || &determinedomain();
                   6778:     my $bgcolor  = $args->{'bgcolor'}  || &designparm($function.'.pgbg',$domain);
1.418     albertel 6779:     my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458     albertel 6780: 		   $Apache::lonnet::perlvar{'lonVersion'},
1.531     albertel 6781: 		   #time(),
1.418     albertel 6782: 		   $env{'environment.color.timestamp'},
1.363     albertel 6783: 		   $function,$domain,$bgcolor);
                   6784: 
1.369     www      6785:     $url = '/adm/css/'.&escape($url).'.css';
1.363     albertel 6786: 
1.308     albertel 6787:     my $result =
                   6788: 	'<head>'.
1.461     albertel 6789: 	&font_settings();
1.319     albertel 6790: 
1.461     albertel 6791:     if (!$args->{'frameset'}) {
                   6792: 	$result .= &Apache::lonhtmlcommon::htmlareaheaders();
                   6793:     }
1.962     droeschl 6794:     if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
                   6795:         $result .= Apache::lonxml::display_title();
1.319     albertel 6796:     }
1.436     albertel 6797:     if (!$args->{'no_nav_bar'} 
                   6798: 	&& !$args->{'only_body'}
                   6799: 	&& !$args->{'frameset'}) {
                   6800: 	$result .= &help_menu_js();
1.1032    www      6801:         $result.=&modal_window();
1.1038    www      6802:         $result.=&togglebox_script();
1.1034    www      6803:         $result.=&wishlist_window();
1.1041    www      6804:         $result.=&LCprogressbarUpdate_script();
1.1034    www      6805:     } else {
                   6806:         if ($args->{'add_modal'}) {
                   6807:            $result.=&modal_window();
                   6808:         }
                   6809:         if ($args->{'add_wishlist'}) {
                   6810:            $result.=&wishlist_window();
                   6811:         }
1.1038    www      6812:         if ($args->{'add_togglebox'}) {
                   6813:            $result.=&togglebox_script();
                   6814:         }
1.1041    www      6815:         if ($args->{'add_progressbar'}) {
                   6816:            $result.=&LCprogressbarUpdate_script();
                   6817:         }
1.436     albertel 6818:     }
1.314     albertel 6819:     if (ref($args->{'redirect'})) {
1.414     albertel 6820: 	my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315     albertel 6821: 	$url = &Apache::lonenc::check_encrypt($url);
1.414     albertel 6822: 	if (!$inhibit_continue) {
                   6823: 	    $env{'internal.head.redirect'} = $url;
                   6824: 	}
1.313     albertel 6825: 	$result.=<<ADDMETA
                   6826: <meta http-equiv="pragma" content="no-cache" />
1.344     albertel 6827: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313     albertel 6828: ADDMETA
                   6829:     }
1.306     albertel 6830:     if (!defined($title)) {
                   6831: 	$title = 'The LearningOnline Network with CAPA';
                   6832:     }
1.460     albertel 6833:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
                   6834:     $result .= '<title> LON-CAPA '.$title.'</title>'
1.414     albertel 6835: 	.'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
                   6836: 	.$head_extra;
1.962     droeschl 6837:     return $result.'</head>';
1.306     albertel 6838: }
                   6839: 
                   6840: =pod
                   6841: 
1.340     albertel 6842: =item * &font_settings()
                   6843: 
                   6844: Returns neccessary <meta> to set the proper encoding
                   6845: 
                   6846: Inputs: none
                   6847: 
                   6848: =cut
                   6849: 
                   6850: sub font_settings {
                   6851:     my $headerstring='';
1.647     www      6852:     if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340     albertel 6853: 	$headerstring.=
                   6854: 	    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
                   6855:     }
                   6856:     return $headerstring;
                   6857: }
                   6858: 
1.341     albertel 6859: =pod
                   6860: 
                   6861: =item * &xml_begin()
                   6862: 
                   6863: Returns the needed doctype and <html>
                   6864: 
                   6865: Inputs: none
                   6866: 
                   6867: =cut
                   6868: 
                   6869: sub xml_begin {
                   6870:     my $output='';
                   6871: 
                   6872:     if ($env{'browser.mathml'}) {
                   6873: 	$output='<?xml version="1.0"?>'
                   6874:             #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
                   6875: #            .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
                   6876:             
                   6877: #	    .'<!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">] >'
                   6878: 	    .'<!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">'
                   6879:             .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" ' 
                   6880: 	    .'xmlns="http://www.w3.org/1999/xhtml">';
                   6881:     } else {
1.849     bisitz   6882: 	$output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
                   6883:            .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341     albertel 6884:     }
                   6885:     return $output;
                   6886: }
1.340     albertel 6887: 
                   6888: =pod
                   6889: 
1.306     albertel 6890: =item * &start_page()
                   6891: 
                   6892: Returns a complete <html> .. <body> section for LON-CAPA web pages.
                   6893: 
1.648     raeburn  6894: Inputs:
                   6895: 
                   6896: =over 4
                   6897: 
                   6898: $title - optional title for the page
                   6899: 
                   6900: $head_extra - optional extra HTML to incude inside the <head>
                   6901: 
                   6902: $args - additional optional args supported are:
                   6903: 
                   6904: =over 8
                   6905: 
                   6906:              only_body      -> is true will set &bodytag() onlybodytag
1.317     albertel 6907:                                     arg on
1.814     bisitz   6908:              no_nav_bar     -> is true will set &bodytag() no_nav_bar arg on
1.648     raeburn  6909:              add_entries    -> additional attributes to add to the  <body>
                   6910:              domain         -> force to color decorate a page for a 
1.317     albertel 6911:                                     specific domain
1.648     raeburn  6912:              function       -> force usage of a specific rolish color
1.317     albertel 6913:                                     scheme
1.648     raeburn  6914:              redirect       -> see &headtag()
                   6915:              bgcolor        -> override the default page bg color
                   6916:              js_ready       -> return a string ready for being used in 
1.317     albertel 6917:                                     a javascript writeln
1.648     raeburn  6918:              html_encode    -> return a string ready for being used in 
1.320     albertel 6919:                                     a html attribute
1.648     raeburn  6920:              force_register -> if is true will turn on the &bodytag()
1.317     albertel 6921:                                     $forcereg arg
1.648     raeburn  6922:              frameset       -> if true will start with a <frameset>
1.330     albertel 6923:                                     rather than <body>
1.648     raeburn  6924:              skip_phases    -> hash ref of 
1.338     albertel 6925:                                     head -> skip the <html><head> generation
                   6926:                                     body -> skip all <body> generation
1.648     raeburn  6927:              no_auto_mt_title -> prevent &mt()ing the title arg
                   6928:              inherit_jsmath -> when creating popup window in a page,
                   6929:                                     should it have jsmath forced on by the
                   6930:                                     current page
1.867     kalberla 6931:              bread_crumbs ->             Array containing breadcrumbs
1.983     raeburn  6932:              bread_crumbs_component ->  if exists show it as headline else show only the breadcrumbs
1.361     albertel 6933: 
1.648     raeburn  6934: =back
1.460     albertel 6935: 
1.648     raeburn  6936: =back
1.562     albertel 6937: 
1.306     albertel 6938: =cut
                   6939: 
                   6940: sub start_page {
1.309     albertel 6941:     my ($title,$head_extra,$args) = @_;
1.318     albertel 6942:     #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319     albertel 6943: 
1.315     albertel 6944:     $env{'internal.start_page'}++;
1.338     albertel 6945:     my $result;
1.964     droeschl 6946: 
1.338     albertel 6947:     if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1030    www      6948:         $result .= &xml_begin() . &headtag($title, $head_extra, $args);
1.338     albertel 6949:     }
                   6950:     
                   6951:     if (! exists($args->{'skip_phases'}{'body'}) ) {
                   6952: 	if ($args->{'frameset'}) {
                   6953: 	    my $attr_string = &make_attr_string($args->{'force_register'},
                   6954: 						$args->{'add_entries'});
                   6955: 	    $result .= "\n<frameset $attr_string>\n";
1.831     bisitz   6956:         } else {
                   6957:             $result .=
                   6958:                 &bodytag($title, 
                   6959:                          $args->{'function'},       $args->{'add_entries'},
                   6960:                          $args->{'only_body'},      $args->{'domain'},
                   6961:                          $args->{'force_register'}, $args->{'no_nav_bar'},
1.962     droeschl 6962:                          $args->{'bgcolor'},        $args);
1.831     bisitz   6963:         }
1.330     albertel 6964:     }
1.338     albertel 6965: 
1.315     albertel 6966:     if ($args->{'js_ready'}) {
1.713     kaisler  6967: 		$result = &js_ready($result);
1.315     albertel 6968:     }
1.320     albertel 6969:     if ($args->{'html_encode'}) {
1.713     kaisler  6970: 		$result = &html_encode($result);
                   6971:     }
                   6972: 
1.813     bisitz   6973:     # Preparation for new and consistent functionlist at top of screen
                   6974:     # if ($args->{'functionlist'}) {
                   6975:     #            $result .= &build_functionlist();
                   6976:     #}
                   6977: 
1.964     droeschl 6978:     # Don't add anything more if only_body wanted or in const space
                   6979:     return $result if    $args->{'only_body'} 
                   6980:                       || $env{'request.state'} eq 'construct';
1.813     bisitz   6981: 
                   6982:     #Breadcrumbs
1.758     kaisler  6983:     if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
                   6984: 		&Apache::lonhtmlcommon::clear_breadcrumbs();
                   6985: 		#if any br links exists, add them to the breadcrumbs
                   6986: 		if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {         
                   6987: 			foreach my $crumb (@{$args->{'bread_crumbs'}}){
                   6988: 				&Apache::lonhtmlcommon::add_breadcrumb($crumb);
                   6989: 			}
                   6990: 		}
                   6991: 
                   6992: 		#if bread_crumbs_component exists show it as headline else show only the breadcrumbs
                   6993: 		if(exists($args->{'bread_crumbs_component'})){
                   6994: 			$result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
                   6995: 		}else{
                   6996: 			$result .= &Apache::lonhtmlcommon::breadcrumbs();
                   6997: 		}
1.320     albertel 6998:     }
1.315     albertel 6999:     return $result;
1.306     albertel 7000: }
                   7001: 
                   7002: sub end_page {
1.315     albertel 7003:     my ($args) = @_;
                   7004:     $env{'internal.end_page'}++;
1.330     albertel 7005:     my $result;
1.335     albertel 7006:     if ($args->{'discussion'}) {
                   7007: 	my ($target,$parser);
                   7008: 	if (ref($args->{'discussion'})) {
                   7009: 	    ($target,$parser) =($args->{'discussion'}{'target'},
                   7010: 				$args->{'discussion'}{'parser'});
                   7011: 	}
                   7012: 	$result .= &Apache::lonxml::xmlend($target,$parser);
                   7013:     }
1.330     albertel 7014:     if ($args->{'frameset'}) {
                   7015: 	$result .= '</frameset>';
                   7016:     } else {
1.635     raeburn  7017: 	$result .= &endbodytag($args);
1.330     albertel 7018:     }
                   7019:     $result .= "\n</html>";
                   7020: 
1.315     albertel 7021:     if ($args->{'js_ready'}) {
1.317     albertel 7022: 	$result = &js_ready($result);
1.315     albertel 7023:     }
1.335     albertel 7024: 
1.320     albertel 7025:     if ($args->{'html_encode'}) {
                   7026: 	$result = &html_encode($result);
                   7027:     }
1.335     albertel 7028: 
1.315     albertel 7029:     return $result;
                   7030: }
                   7031: 
1.1034    www      7032: sub wishlist_window {
                   7033:     return(<<'ENDWISHLIST');
1.1046    raeburn  7034: <script type="text/javascript">
1.1034    www      7035: // <![CDATA[
                   7036: // <!-- BEGIN LON-CAPA Internal
                   7037: function set_wishlistlink(title, path) {
                   7038:     if (!title) {
                   7039:         title = document.title;
                   7040:         title = title.replace(/^LON-CAPA /,'');
                   7041:     }
                   7042:     if (!path) {
                   7043:         path = location.pathname;
                   7044:     }
                   7045:     Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
                   7046:                       'wishlistNewLink','width=560,height=350,scrollbars=0');
                   7047: }
                   7048: // END LON-CAPA Internal -->
                   7049: // ]]>
                   7050: </script>
                   7051: ENDWISHLIST
                   7052: }
                   7053: 
1.1030    www      7054: sub modal_window {
                   7055:     return(<<'ENDMODAL');
1.1046    raeburn  7056: <script type="text/javascript">
1.1030    www      7057: // <![CDATA[
                   7058: // <!-- BEGIN LON-CAPA Internal
                   7059: var modalWindow = {
                   7060: 	parent:"body",
                   7061: 	windowId:null,
                   7062: 	content:null,
                   7063: 	width:null,
                   7064: 	height:null,
                   7065: 	close:function()
                   7066: 	{
                   7067: 	        $(".LCmodal-window").remove();
                   7068: 	        $(".LCmodal-overlay").remove();
                   7069: 	},
                   7070: 	open:function()
                   7071: 	{
                   7072: 		var modal = "";
                   7073: 		modal += "<div class=\"LCmodal-overlay\"></div>";
                   7074: 		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;\">";
                   7075: 		modal += this.content;
                   7076: 		modal += "</div>";	
                   7077: 
                   7078: 		$(this.parent).append(modal);
                   7079: 
                   7080: 		$(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
                   7081: 		$(".LCclose-window").click(function(){modalWindow.close();});
                   7082: 		$(".LCmodal-overlay").click(function(){modalWindow.close();});
                   7083: 	}
                   7084: };
1.1031    www      7085: 	var openMyModal = function(source,width,height,scrolling)
1.1030    www      7086: 	{
                   7087: 		modalWindow.windowId = "myModal";
                   7088: 		modalWindow.width = width;
                   7089: 		modalWindow.height = height;
1.1031    www      7090: 		modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='true' src='" + source + "'>&lt/iframe>";
1.1030    www      7091: 		modalWindow.open();
                   7092: 	};	
                   7093: // END LON-CAPA Internal -->
                   7094: // ]]>
                   7095: </script>
                   7096: ENDMODAL
                   7097: }
                   7098: 
                   7099: sub modal_link {
1.1052    www      7100:     my ($link,$linktext,$width,$height,$target,$scrolling,$title)=@_;
1.1030    www      7101:     unless ($width) { $width=480; }
                   7102:     unless ($height) { $height=400; }
1.1031    www      7103:     unless ($scrolling) { $scrolling='yes'; }
1.1052    www      7104:     return '<a href="'.$link.'" target="'.$target.'" title="'.$title.'" onclick="openMyModal(\''.$link.'\','.$width.','.$height.',\''.$scrolling.'\'); return false;">'.
1.1031    www      7105:            $linktext.'</a>';
1.1030    www      7106: }
                   7107: 
1.1032    www      7108: sub modal_adhoc_script {
                   7109:     my ($funcname,$width,$height,$content)=@_;
                   7110:     return (<<ENDADHOC);
1.1046    raeburn  7111: <script type="text/javascript">
1.1032    www      7112: // <![CDATA[
                   7113:         var $funcname = function()
                   7114:         {
                   7115:                 modalWindow.windowId = "myModal";
                   7116:                 modalWindow.width = $width;
                   7117:                 modalWindow.height = $height;
                   7118:                 modalWindow.content = '$content';
                   7119:                 modalWindow.open();
                   7120:         };  
                   7121: // ]]>
                   7122: </script>
                   7123: ENDADHOC
                   7124: }
                   7125: 
1.1041    www      7126: sub modal_adhoc_inner {
                   7127:     my ($funcname,$width,$height,$content)=@_;
                   7128:     my $innerwidth=$width-20;
                   7129:     $content=&js_ready(
1.1042    www      7130:                &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1041    www      7131:                  &start_scrollbox($width.'px',$innerwidth.'px',$height.'px').
                   7132:                     $content.
                   7133:                  &end_scrollbox().
                   7134:                &end_page()
                   7135:              );
                   7136:     return &modal_adhoc_script($funcname,$width,$height,$content);
                   7137: }
                   7138: 
                   7139: sub modal_adhoc_window {
                   7140:     my ($funcname,$width,$height,$content,$linktext)=@_;
                   7141:     return &modal_adhoc_inner($funcname,$width,$height,$content).
                   7142:            "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
                   7143: }
                   7144: 
                   7145: sub modal_adhoc_launch {
                   7146:     my ($funcname,$width,$height,$content)=@_;
                   7147:     return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
                   7148: <script type="text/javascript">
                   7149: // <![CDATA[
                   7150: $funcname();
                   7151: // ]]>
                   7152: </script>
                   7153: ENDLAUNCH
                   7154: }
                   7155: 
                   7156: sub modal_adhoc_close {
                   7157:     return (<<ENDCLOSE);
                   7158: <script type="text/javascript">
                   7159: // <![CDATA[
                   7160: modalWindow.close();
                   7161: // ]]>
                   7162: </script>
                   7163: ENDCLOSE
                   7164: }
                   7165: 
1.1038    www      7166: sub togglebox_script {
                   7167:    return(<<ENDTOGGLE);
                   7168: <script type="text/javascript"> 
                   7169: // <![CDATA[
                   7170: function LCtoggleDisplay(id,hidetext,showtext) {
                   7171:    link = document.getElementById(id + "link").childNodes[0];
                   7172:    with (document.getElementById(id).style) {
                   7173:       if (display == "none" ) {
                   7174:           display = "inline";
                   7175:           link.nodeValue = hidetext;
                   7176:         } else {
                   7177:           display = "none";
                   7178:           link.nodeValue = showtext;
                   7179:        }
                   7180:    }
                   7181: }
                   7182: // ]]>
                   7183: </script>
                   7184: ENDTOGGLE
                   7185: }
                   7186: 
1.1039    www      7187: sub start_togglebox {
                   7188:     my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
                   7189:     unless ($heading) { $heading=''; } else { $heading.=' '; }
                   7190:     unless ($showtext) { $showtext=&mt('show'); }
                   7191:     unless ($hidetext) { $hidetext=&mt('hide'); }
                   7192:     unless ($headerbg) { $headerbg='#FFFFFF'; }
                   7193:     return &start_data_table().
                   7194:            &start_data_table_header_row().
                   7195:            '<td bgcolor="'.$headerbg.'">'.$heading.
                   7196:            '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
                   7197:            $showtext.'\')">'.$showtext.'</a>]</td>'.
                   7198:            &end_data_table_header_row().
                   7199:            '<tr id="'.$id.'" style="display:none""><td>';
                   7200: }
                   7201: 
                   7202: sub end_togglebox {
                   7203:     return '</td></tr>'.&end_data_table();
                   7204: }
                   7205: 
1.1041    www      7206: sub LCprogressbar_script {
1.1045    www      7207:    my ($id)=@_;
1.1041    www      7208:    return(<<ENDPROGRESS);
                   7209: <script type="text/javascript">
                   7210: // <![CDATA[
1.1045    www      7211: \$('#progressbar$id').progressbar({
1.1041    www      7212:   value: 0,
                   7213:   change: function(event, ui) {
                   7214:     var newVal = \$(this).progressbar('option', 'value');
                   7215:     \$('.pblabel', this).text(LCprogressTxt);
                   7216:   }
                   7217: });
                   7218: // ]]>
                   7219: </script>
                   7220: ENDPROGRESS
                   7221: }
                   7222: 
                   7223: sub LCprogressbarUpdate_script {
                   7224:    return(<<ENDPROGRESSUPDATE);
                   7225: <style type="text/css">
                   7226: .ui-progressbar { position:relative; }
                   7227: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
                   7228: </style>
                   7229: <script type="text/javascript">
                   7230: // <![CDATA[
1.1045    www      7231: var LCprogressTxt='---';
                   7232: 
                   7233: function LCupdateProgress(percent,progresstext,id) {
1.1041    www      7234:    LCprogressTxt=progresstext;
1.1045    www      7235:    \$('#progressbar'+id).progressbar('value',percent);
1.1041    www      7236: }
                   7237: // ]]>
                   7238: </script>
                   7239: ENDPROGRESSUPDATE
                   7240: }
                   7241: 
1.1042    www      7242: my $LClastpercent;
1.1045    www      7243: my $LCidcnt;
                   7244: my $LCcurrentid;
1.1042    www      7245: 
1.1041    www      7246: sub LCprogressbar {
1.1042    www      7247:     my ($r)=(@_);
                   7248:     $LClastpercent=0;
1.1045    www      7249:     $LCidcnt++;
                   7250:     $LCcurrentid=$$.'_'.$LCidcnt;
1.1041    www      7251:     my $starting=&mt('Starting');
                   7252:     my $content=(<<ENDPROGBAR);
                   7253: <p>
1.1045    www      7254:   <div id="progressbar$LCcurrentid">
1.1041    www      7255:     <span class="pblabel">$starting</span>
                   7256:   </div>
                   7257: </p>
                   7258: ENDPROGBAR
1.1045    www      7259:     &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041    www      7260: }
                   7261: 
                   7262: sub LCprogressbarUpdate {
1.1042    www      7263:     my ($r,$val,$text)=@_;
                   7264:     unless ($val) { 
                   7265:        if ($LClastpercent) {
                   7266:            $val=$LClastpercent;
                   7267:        } else {
                   7268:            $val=0;
                   7269:        }
                   7270:     }
1.1041    www      7271:     if ($val<0) { $val=0; }
                   7272:     if ($val>100) { $val=0; }
1.1042    www      7273:     $LClastpercent=$val;
1.1041    www      7274:     unless ($text) { $text=$val.'%'; }
                   7275:     $text=&js_ready($text);
1.1044    www      7276:     &r_print($r,<<ENDUPDATE);
1.1041    www      7277: <script type="text/javascript">
                   7278: // <![CDATA[
1.1045    www      7279: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041    www      7280: // ]]>
                   7281: </script>
                   7282: ENDUPDATE
1.1035    www      7283: }
                   7284: 
1.1042    www      7285: sub LCprogressbarClose {
                   7286:     my ($r)=@_;
                   7287:     $LClastpercent=0;
1.1044    www      7288:     &r_print($r,<<ENDCLOSE);
1.1042    www      7289: <script type="text/javascript">
                   7290: // <![CDATA[
1.1045    www      7291: \$("#progressbar$LCcurrentid").hide('slow'); 
1.1042    www      7292: // ]]>
                   7293: </script>
                   7294: ENDCLOSE
1.1044    www      7295: }
                   7296: 
                   7297: sub r_print {
                   7298:     my ($r,$to_print)=@_;
                   7299:     if ($r) {
                   7300:       $r->print($to_print);
                   7301:       $r->rflush();
                   7302:     } else {
                   7303:       print($to_print);
                   7304:     }
1.1042    www      7305: }
                   7306: 
1.320     albertel 7307: sub html_encode {
                   7308:     my ($result) = @_;
                   7309: 
1.322     albertel 7310:     $result = &HTML::Entities::encode($result,'<>&"');
1.320     albertel 7311:     
                   7312:     return $result;
                   7313: }
1.1044    www      7314: 
1.317     albertel 7315: sub js_ready {
                   7316:     my ($result) = @_;
                   7317: 
1.323     albertel 7318:     $result =~ s/[\n\r]/ /xmsg;
                   7319:     $result =~ s/\\/\\\\/xmsg;
                   7320:     $result =~ s/'/\\'/xmsg;
1.372     albertel 7321:     $result =~ s{</}{<\\/}xmsg;
1.317     albertel 7322:     
                   7323:     return $result;
                   7324: }
                   7325: 
1.315     albertel 7326: sub validate_page {
                   7327:     if (  exists($env{'internal.start_page'})
1.316     albertel 7328: 	  &&     $env{'internal.start_page'} > 1) {
                   7329: 	&Apache::lonnet::logthis('start_page called multiple times '.
1.318     albertel 7330: 				 $env{'internal.start_page'}.' '.
1.316     albertel 7331: 				 $ENV{'request.filename'});
1.315     albertel 7332:     }
                   7333:     if (  exists($env{'internal.end_page'})
1.316     albertel 7334: 	  &&     $env{'internal.end_page'} > 1) {
                   7335: 	&Apache::lonnet::logthis('end_page called multiple times '.
1.318     albertel 7336: 				 $env{'internal.end_page'}.' '.
1.316     albertel 7337: 				 $env{'request.filename'});
1.315     albertel 7338:     }
                   7339:     if (     exists($env{'internal.start_page'})
                   7340: 	&& ! exists($env{'internal.end_page'})) {
1.316     albertel 7341: 	&Apache::lonnet::logthis('start_page called without end_page '.
                   7342: 				 $env{'request.filename'});
1.315     albertel 7343:     }
                   7344:     if (   ! exists($env{'internal.start_page'})
                   7345: 	&&   exists($env{'internal.end_page'})) {
1.316     albertel 7346: 	&Apache::lonnet::logthis('end_page called without start_page'.
                   7347: 				 $env{'request.filename'});
1.315     albertel 7348:     }
1.306     albertel 7349: }
1.315     albertel 7350: 
1.996     www      7351: 
                   7352: sub start_scrollbox {
1.1018    raeburn  7353:     my ($outerwidth,$width,$height,$id)=@_;
1.998     raeburn  7354:     unless ($outerwidth) { $outerwidth='520px'; }
                   7355:     unless ($width) { $width='500px'; }
                   7356:     unless ($height) { $height='200px'; }
1.1020    raeburn  7357:     my ($table_id,$div_id);
1.1018    raeburn  7358:     if ($id ne '') {
1.1020    raeburn  7359:         $table_id = " id='table_$id'";
                   7360:         $div_id = " id='div_$id'";
1.1018    raeburn  7361:     }
1.1020    raeburn  7362:     return "<table style='width: $outerwidth; border: 1px solid none;'$table_id><tr><td style='width: $width;' bgcolor='#FFFFFF'><div style='overflow:auto; width:$width; height: $height;'$div_id>";
1.996     www      7363: }
                   7364: 
                   7365: sub end_scrollbox {
1.1036    www      7366:     return '</div></td></tr></table>';
1.996     www      7367: }
                   7368: 
1.318     albertel 7369: sub simple_error_page {
                   7370:     my ($r,$title,$msg) = @_;
                   7371:     my $page =
                   7372: 	&Apache::loncommon::start_page($title).
                   7373: 	&mt($msg).
                   7374: 	&Apache::loncommon::end_page();
                   7375:     if (ref($r)) {
                   7376: 	$r->print($page);
1.327     albertel 7377: 	return;
1.318     albertel 7378:     }
                   7379:     return $page;
                   7380: }
1.347     albertel 7381: 
                   7382: {
1.610     albertel 7383:     my @row_count;
1.961     onken    7384: 
                   7385:     sub start_data_table_count {
                   7386:         unshift(@row_count, 0);
                   7387:         return;
                   7388:     }
                   7389: 
                   7390:     sub end_data_table_count {
                   7391:         shift(@row_count);
                   7392:         return;
                   7393:     }
                   7394: 
1.347     albertel 7395:     sub start_data_table {
1.1018    raeburn  7396: 	my ($add_class,$id) = @_;
1.422     albertel 7397: 	my $css_class = (join(' ','LC_data_table',$add_class));
1.1018    raeburn  7398:         my $table_id;
                   7399:         if (defined($id)) {
                   7400:             $table_id = ' id="'.$id.'"';
                   7401:         }
1.961     onken    7402: 	&start_data_table_count();
1.1018    raeburn  7403: 	return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347     albertel 7404:     }
                   7405: 
                   7406:     sub end_data_table {
1.961     onken    7407: 	&end_data_table_count();
1.389     albertel 7408: 	return '</table>'."\n";;
1.347     albertel 7409:     }
                   7410: 
                   7411:     sub start_data_table_row {
1.974     wenzelju 7412: 	my ($add_class, $id) = @_;
1.610     albertel 7413: 	$row_count[0]++;
                   7414: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900     bisitz   7415: 	$css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974     wenzelju 7416:         $id = (' id="'.$id.'"') unless ($id eq '');
                   7417:         return  '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347     albertel 7418:     }
1.471     banghart 7419:     
                   7420:     sub continue_data_table_row {
1.974     wenzelju 7421: 	my ($add_class, $id) = @_;
1.610     albertel 7422: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974     wenzelju 7423: 	$css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
                   7424:         $id = (' id="'.$id.'"') unless ($id eq '');
                   7425:         return  '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471     banghart 7426:     }
1.347     albertel 7427: 
                   7428:     sub end_data_table_row {
1.389     albertel 7429: 	return '</tr>'."\n";;
1.347     albertel 7430:     }
1.367     www      7431: 
1.421     albertel 7432:     sub start_data_table_empty_row {
1.707     bisitz   7433: #	$row_count[0]++;
1.421     albertel 7434: 	return  '<tr class="LC_empty_row" >'."\n";;
                   7435:     }
                   7436: 
                   7437:     sub end_data_table_empty_row {
                   7438: 	return '</tr>'."\n";;
                   7439:     }
                   7440: 
1.367     www      7441:     sub start_data_table_header_row {
1.389     albertel 7442: 	return  '<tr class="LC_header_row">'."\n";;
1.367     www      7443:     }
                   7444: 
                   7445:     sub end_data_table_header_row {
1.389     albertel 7446: 	return '</tr>'."\n";;
1.367     www      7447:     }
1.890     droeschl 7448: 
                   7449:     sub data_table_caption {
                   7450:         my $caption = shift;
                   7451:         return "<caption class=\"LC_caption\">$caption</caption>";
                   7452:     }
1.347     albertel 7453: }
                   7454: 
1.548     albertel 7455: =pod
                   7456: 
                   7457: =item * &inhibit_menu_check($arg)
                   7458: 
                   7459: Checks for a inhibitmenu state and generates output to preserve it
                   7460: 
                   7461: Inputs:         $arg - can be any of
                   7462:                      - undef - in which case the return value is a string 
                   7463:                                to add  into arguments list of a uri
                   7464:                      - 'input' - in which case the return value is a HTML
                   7465:                                  <form> <input> field of type hidden to
                   7466:                                  preserve the value
                   7467:                      - a url - in which case the return value is the url with
                   7468:                                the neccesary cgi args added to preserve the
                   7469:                                inhibitmenu state
                   7470:                      - a ref to a url - no return value, but the string is
                   7471:                                         updated to include the neccessary cgi
                   7472:                                         args to preserve the inhibitmenu state
                   7473: 
                   7474: =cut
                   7475: 
                   7476: sub inhibit_menu_check {
                   7477:     my ($arg) = @_;
                   7478:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   7479:     if ($arg eq 'input') {
                   7480: 	if ($env{'form.inhibitmenu'}) {
                   7481: 	    return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
                   7482: 	} else {
                   7483: 	    return
                   7484: 	}
                   7485:     }
                   7486:     if ($env{'form.inhibitmenu'}) {
                   7487: 	if (ref($arg)) {
                   7488: 	    $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   7489: 	} elsif ($arg eq '') {
                   7490: 	    $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
                   7491: 	} else {
                   7492: 	    $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   7493: 	}
                   7494:     }
                   7495:     if (!ref($arg)) {
                   7496: 	return $arg;
                   7497:     }
                   7498: }
                   7499: 
1.251     albertel 7500: ###############################################
1.182     matthew  7501: 
                   7502: =pod
                   7503: 
1.549     albertel 7504: =back
                   7505: 
                   7506: =head1 User Information Routines
                   7507: 
                   7508: =over 4
                   7509: 
1.405     albertel 7510: =item * &get_users_function()
1.182     matthew  7511: 
                   7512: Used by &bodytag to determine the current users primary role.
                   7513: Returns either 'student','coordinator','admin', or 'author'.
                   7514: 
                   7515: =cut
                   7516: 
                   7517: ###############################################
                   7518: sub get_users_function {
1.815     tempelho 7519:     my $function = 'norole';
1.818     tempelho 7520:     if ($env{'request.role'}=~/^(st)/) {
                   7521:         $function='student';
                   7522:     }
1.907     raeburn  7523:     if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182     matthew  7524:         $function='coordinator';
                   7525:     }
1.258     albertel 7526:     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182     matthew  7527:         $function='admin';
                   7528:     }
1.826     bisitz   7529:     if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025    raeburn  7530:         ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182     matthew  7531:         $function='author';
                   7532:     }
                   7533:     return $function;
1.54      www      7534: }
1.99      www      7535: 
                   7536: ###############################################
                   7537: 
1.233     raeburn  7538: =pod
                   7539: 
1.821     raeburn  7540: =item * &show_course()
                   7541: 
                   7542: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
                   7543: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
                   7544: 
                   7545: Inputs:
                   7546: None
                   7547: 
                   7548: Outputs:
                   7549: Scalar: 1 if 'Course' to be used, 0 otherwise.
                   7550: 
                   7551: =cut
                   7552: 
                   7553: ###############################################
                   7554: sub show_course {
                   7555:     my $course = !$env{'user.adv'};
                   7556:     if (!$env{'user.adv'}) {
                   7557:         foreach my $env (keys(%env)) {
                   7558:             next if ($env !~ m/^user\.priv\./);
                   7559:             if ($env !~ m/^user\.priv\.(?:st|cm)/) {
                   7560:                 $course = 0;
                   7561:                 last;
                   7562:             }
                   7563:         }
                   7564:     }
                   7565:     return $course;
                   7566: }
                   7567: 
                   7568: ###############################################
                   7569: 
                   7570: =pod
                   7571: 
1.542     raeburn  7572: =item * &check_user_status()
1.274     raeburn  7573: 
                   7574: Determines current status of supplied role for a
                   7575: specific user. Roles can be active, previous or future.
                   7576: 
                   7577: Inputs: 
                   7578: user's domain, user's username, course's domain,
1.375     raeburn  7579: course's number, optional section ID.
1.274     raeburn  7580: 
                   7581: Outputs:
                   7582: role status: active, previous or future. 
                   7583: 
                   7584: =cut
                   7585: 
                   7586: sub check_user_status {
1.412     raeburn  7587:     my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.982     raeburn  7588:     my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
                   7589:     my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname,'.',undef,$extra);
1.274     raeburn  7590:     my @uroles = keys %userinfo;
                   7591:     my $srchstr;
                   7592:     my $active_chk = 'none';
1.412     raeburn  7593:     my $now = time;
1.274     raeburn  7594:     if (@uroles > 0) {
1.908     raeburn  7595:         if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274     raeburn  7596:             $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
                   7597:         } else {
1.412     raeburn  7598:             $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
                   7599:         }
                   7600:         if (grep/^\Q$srchstr\E$/,@uroles) {
1.274     raeburn  7601:             my $role_end = 0;
                   7602:             my $role_start = 0;
                   7603:             $active_chk = 'active';
1.412     raeburn  7604:             if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
                   7605:                 $role_end = $1;
                   7606:                 if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
                   7607:                     $role_start = $1;
1.274     raeburn  7608:                 }
                   7609:             }
                   7610:             if ($role_start > 0) {
1.412     raeburn  7611:                 if ($now < $role_start) {
1.274     raeburn  7612:                     $active_chk = 'future';
                   7613:                 }
                   7614:             }
                   7615:             if ($role_end > 0) {
1.412     raeburn  7616:                 if ($now > $role_end) {
1.274     raeburn  7617:                     $active_chk = 'previous';
                   7618:                 }
                   7619:             }
                   7620:         }
                   7621:     }
                   7622:     return $active_chk;
                   7623: }
                   7624: 
                   7625: ###############################################
                   7626: 
                   7627: =pod
                   7628: 
1.405     albertel 7629: =item * &get_sections()
1.233     raeburn  7630: 
                   7631: Determines all the sections for a course including
                   7632: sections with students and sections containing other roles.
1.419     raeburn  7633: Incoming parameters: 
                   7634: 
                   7635: 1. domain
                   7636: 2. course number 
                   7637: 3. reference to array containing roles for which sections should 
                   7638: be gathered (optional).
                   7639: 4. reference to array containing status types for which sections 
                   7640: should be gathered (optional).
                   7641: 
                   7642: If the third argument is undefined, sections are gathered for any role. 
                   7643: If the fourth argument is undefined, sections are gathered for any status.
                   7644: Permissible values are 'active' or 'future' or 'previous'.
1.233     raeburn  7645:  
1.374     raeburn  7646: Returns section hash (keys are section IDs, values are
                   7647: number of users in each section), subject to the
1.419     raeburn  7648: optional roles filter, optional status filter 
1.233     raeburn  7649: 
                   7650: =cut
                   7651: 
                   7652: ###############################################
                   7653: sub get_sections {
1.419     raeburn  7654:     my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366     albertel 7655:     if (!defined($cdom) || !defined($cnum)) {
                   7656:         my $cid =  $env{'request.course.id'};
                   7657: 
                   7658: 	return if (!defined($cid));
                   7659: 
                   7660:         $cdom = $env{'course.'.$cid.'.domain'};
                   7661:         $cnum = $env{'course.'.$cid.'.num'};
                   7662:     }
                   7663: 
                   7664:     my %sectioncount;
1.419     raeburn  7665:     my $now = time;
1.240     albertel 7666: 
1.366     albertel 7667:     if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276     albertel 7668: 	my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240     albertel 7669: 	my $sec_index = &Apache::loncoursedata::CL_SECTION();
                   7670: 	my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419     raeburn  7671:         my $start_index = &Apache::loncoursedata::CL_START();
                   7672:         my $end_index = &Apache::loncoursedata::CL_END();
                   7673:         my $status;
1.366     albertel 7674: 	while (my ($student,$data) = each(%$classlist)) {
1.419     raeburn  7675: 	    my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
                   7676: 				                     $data->[$status_index],
                   7677:                                                      $data->[$start_index],
                   7678:                                                      $data->[$end_index]);
                   7679:             if ($stu_status eq 'Active') {
                   7680:                 $status = 'active';
                   7681:             } elsif ($end < $now) {
                   7682:                 $status = 'previous';
                   7683:             } elsif ($start > $now) {
                   7684:                 $status = 'future';
                   7685:             } 
                   7686: 	    if ($section ne '-1' && $section !~ /^\s*$/) {
                   7687:                 if ((!defined($possible_status)) || (($status ne '') && 
                   7688:                     (grep/^\Q$status\E$/,@{$possible_status}))) { 
                   7689: 		    $sectioncount{$section}++;
                   7690:                 }
1.240     albertel 7691: 	    }
                   7692: 	}
                   7693:     }
                   7694:     my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7695:     foreach my $user (sort(keys(%courseroles))) {
                   7696: 	if ($user !~ /^(\w{2})/) { next; }
                   7697: 	my ($role) = ($user =~ /^(\w{2})/);
                   7698: 	if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419     raeburn  7699: 	my ($section,$status);
1.240     albertel 7700: 	if ($role eq 'cr' &&
                   7701: 	    $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
                   7702: 	    $section=$1;
                   7703: 	}
                   7704: 	if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
                   7705: 	if (!defined($section) || $section eq '-1') { next; }
1.419     raeburn  7706:         my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
                   7707:         if ($end == -1 && $start == -1) {
                   7708:             next; #deleted role
                   7709:         }
                   7710:         if (!defined($possible_status)) { 
                   7711:             $sectioncount{$section}++;
                   7712:         } else {
                   7713:             if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
                   7714:                 $status = 'active';
                   7715:             } elsif ($end < $now) {
                   7716:                 $status = 'future';
                   7717:             } elsif ($start > $now) {
                   7718:                 $status = 'previous';
                   7719:             }
                   7720:             if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
                   7721:                 $sectioncount{$section}++;
                   7722:             }
                   7723:         }
1.233     raeburn  7724:     }
1.366     albertel 7725:     return %sectioncount;
1.233     raeburn  7726: }
                   7727: 
1.274     raeburn  7728: ###############################################
1.294     raeburn  7729: 
                   7730: =pod
1.405     albertel 7731: 
                   7732: =item * &get_course_users()
                   7733: 
1.275     raeburn  7734: Retrieves usernames:domains for users in the specified course
                   7735: with specific role(s), and access status. 
                   7736: 
                   7737: Incoming parameters:
1.277     albertel 7738: 1. course domain
                   7739: 2. course number
                   7740: 3. access status: users must have - either active, 
1.275     raeburn  7741: previous, future, or all.
1.277     albertel 7742: 4. reference to array of permissible roles
1.288     raeburn  7743: 5. reference to array of section restrictions (optional)
                   7744: 6. reference to results object (hash of hashes).
                   7745: 7. reference to optional userdata hash
1.609     raeburn  7746: 8. reference to optional statushash
1.630     raeburn  7747: 9. flag if privileged users (except those set to unhide in
                   7748:    course settings) should be excluded    
1.609     raeburn  7749: Keys of top level results hash are roles.
1.275     raeburn  7750: Keys of inner hashes are username:domain, with 
                   7751: values set to access type.
1.288     raeburn  7752: Optional userdata hash returns an array with arguments in the 
                   7753: same order as loncoursedata::get_classlist() for student data.
                   7754: 
1.609     raeburn  7755: Optional statushash returns
                   7756: 
1.288     raeburn  7757: Entries for end, start, section and status are blank because
                   7758: of the possibility of multiple values for non-student roles.
                   7759: 
1.275     raeburn  7760: =cut
1.405     albertel 7761: 
1.275     raeburn  7762: ###############################################
1.405     albertel 7763: 
1.275     raeburn  7764: sub get_course_users {
1.630     raeburn  7765:     my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288     raeburn  7766:     my %idx = ();
1.419     raeburn  7767:     my %seclists;
1.288     raeburn  7768: 
                   7769:     $idx{udom} = &Apache::loncoursedata::CL_SDOM();
                   7770:     $idx{uname} =  &Apache::loncoursedata::CL_SNAME();
                   7771:     $idx{end} = &Apache::loncoursedata::CL_END();
                   7772:     $idx{start} = &Apache::loncoursedata::CL_START();
                   7773:     $idx{id} = &Apache::loncoursedata::CL_ID();
                   7774:     $idx{section} = &Apache::loncoursedata::CL_SECTION();
                   7775:     $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
                   7776:     $idx{status} = &Apache::loncoursedata::CL_STATUS();
                   7777: 
1.290     albertel 7778:     if (grep(/^st$/,@{$roles})) {
1.276     albertel 7779:         my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278     raeburn  7780:         my $now = time;
1.277     albertel 7781:         foreach my $student (keys(%{$classlist})) {
1.288     raeburn  7782:             my $match = 0;
1.412     raeburn  7783:             my $secmatch = 0;
1.419     raeburn  7784:             my $section = $$classlist{$student}[$idx{section}];
1.609     raeburn  7785:             my $status = $$classlist{$student}[$idx{status}];
1.419     raeburn  7786:             if ($section eq '') {
                   7787:                 $section = 'none';
                   7788:             }
1.291     albertel 7789:             if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 7790:                 if (grep(/^all$/,@{$sections})) {
1.412     raeburn  7791:                     $secmatch = 1;
                   7792:                 } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420     albertel 7793:                     if (grep(/^none$/,@{$sections})) {
1.412     raeburn  7794:                         $secmatch = 1;
                   7795:                     }
                   7796:                 } else {  
1.419     raeburn  7797: 		    if (grep(/^\Q$section\E$/,@{$sections})) {
1.412     raeburn  7798: 		        $secmatch = 1;
                   7799:                     }
1.290     albertel 7800: 		}
1.412     raeburn  7801:                 if (!$secmatch) {
                   7802:                     next;
                   7803:                 }
1.419     raeburn  7804:             }
1.275     raeburn  7805:             if (defined($$types{'active'})) {
1.288     raeburn  7806:                 if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275     raeburn  7807:                     push(@{$$users{st}{$student}},'active');
1.288     raeburn  7808:                     $match = 1;
1.275     raeburn  7809:                 }
                   7810:             }
                   7811:             if (defined($$types{'previous'})) {
1.609     raeburn  7812:                 if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275     raeburn  7813:                     push(@{$$users{st}{$student}},'previous');
1.288     raeburn  7814:                     $match = 1;
1.275     raeburn  7815:                 }
                   7816:             }
                   7817:             if (defined($$types{'future'})) {
1.609     raeburn  7818:                 if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275     raeburn  7819:                     push(@{$$users{st}{$student}},'future');
1.288     raeburn  7820:                     $match = 1;
1.275     raeburn  7821:                 }
                   7822:             }
1.609     raeburn  7823:             if ($match) {
                   7824:                 push(@{$seclists{$student}},$section);
                   7825:                 if (ref($userdata) eq 'HASH') {
                   7826:                     $$userdata{$student} = $$classlist{$student};
                   7827:                 }
                   7828:                 if (ref($statushash) eq 'HASH') {
                   7829:                     $statushash->{$student}{'st'}{$section} = $status;
                   7830:                 }
1.288     raeburn  7831:             }
1.275     raeburn  7832:         }
                   7833:     }
1.412     raeburn  7834:     if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439     raeburn  7835:         my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7836:         my $now = time;
1.609     raeburn  7837:         my %displaystatus = ( previous => 'Expired',
                   7838:                               active   => 'Active',
                   7839:                               future   => 'Future',
                   7840:                             );
1.630     raeburn  7841:         my %nothide;
                   7842:         if ($hidepriv) {
                   7843:             my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
                   7844:             foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
                   7845:                 if ($user !~ /:/) {
                   7846:                     $nothide{join(':',split(/[\@]/,$user))}=1;
                   7847:                 } else {
                   7848:                     $nothide{$user} = 1;
                   7849:                 }
                   7850:             }
                   7851:         }
1.439     raeburn  7852:         foreach my $person (sort(keys(%coursepersonnel))) {
1.288     raeburn  7853:             my $match = 0;
1.412     raeburn  7854:             my $secmatch = 0;
1.439     raeburn  7855:             my $status;
1.412     raeburn  7856:             my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275     raeburn  7857:             $user =~ s/:$//;
1.439     raeburn  7858:             my ($end,$start) = split(/:/,$coursepersonnel{$person});
                   7859:             if ($end == -1 || $start == -1) {
                   7860:                 next;
                   7861:             }
                   7862:             if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
                   7863:                 (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412     raeburn  7864:                 my ($uname,$udom) = split(/:/,$user);
                   7865:                 if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 7866:                     if (grep(/^all$/,@{$sections})) {
1.412     raeburn  7867:                         $secmatch = 1;
                   7868:                     } elsif ($usec eq '') {
1.420     albertel 7869:                         if (grep(/^none$/,@{$sections})) {
1.412     raeburn  7870:                             $secmatch = 1;
                   7871:                         }
                   7872:                     } else {
                   7873:                         if (grep(/^\Q$usec\E$/,@{$sections})) {
                   7874:                             $secmatch = 1;
                   7875:                         }
                   7876:                     }
                   7877:                     if (!$secmatch) {
                   7878:                         next;
                   7879:                     }
1.288     raeburn  7880:                 }
1.419     raeburn  7881:                 if ($usec eq '') {
                   7882:                     $usec = 'none';
                   7883:                 }
1.275     raeburn  7884:                 if ($uname ne '' && $udom ne '') {
1.630     raeburn  7885:                     if ($hidepriv) {
                   7886:                         if ((&Apache::lonnet::privileged($uname,$udom)) &&
                   7887:                             (!$nothide{$uname.':'.$udom})) {
                   7888:                             next;
                   7889:                         }
                   7890:                     }
1.503     raeburn  7891:                     if ($end > 0 && $end < $now) {
1.439     raeburn  7892:                         $status = 'previous';
                   7893:                     } elsif ($start > $now) {
                   7894:                         $status = 'future';
                   7895:                     } else {
                   7896:                         $status = 'active';
                   7897:                     }
1.277     albertel 7898:                     foreach my $type (keys(%{$types})) { 
1.275     raeburn  7899:                         if ($status eq $type) {
1.420     albertel 7900:                             if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419     raeburn  7901:                                 push(@{$$users{$role}{$user}},$type);
                   7902:                             }
1.288     raeburn  7903:                             $match = 1;
                   7904:                         }
                   7905:                     }
1.419     raeburn  7906:                     if (($match) && (ref($userdata) eq 'HASH')) {
                   7907:                         if (!exists($$userdata{$uname.':'.$udom})) {
                   7908: 			    &get_user_info($udom,$uname,\%idx,$userdata);
                   7909:                         }
1.420     albertel 7910:                         if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419     raeburn  7911:                             push(@{$seclists{$uname.':'.$udom}},$usec);
                   7912:                         }
1.609     raeburn  7913:                         if (ref($statushash) eq 'HASH') {
                   7914:                             $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
                   7915:                         }
1.275     raeburn  7916:                     }
                   7917:                 }
                   7918:             }
                   7919:         }
1.290     albertel 7920:         if (grep(/^ow$/,@{$roles})) {
1.279     raeburn  7921:             if ((defined($cdom)) && (defined($cnum))) {
                   7922:                 my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
                   7923:                 if ( defined($csettings{'internal.courseowner'}) ) {
                   7924:                     my $owner = $csettings{'internal.courseowner'};
1.609     raeburn  7925:                     next if ($owner eq '');
                   7926:                     my ($ownername,$ownerdom);
                   7927:                     if ($owner =~ /^([^:]+):([^:]+)$/) {
                   7928:                         $ownername = $1;
                   7929:                         $ownerdom = $2;
                   7930:                     } else {
                   7931:                         $ownername = $owner;
                   7932:                         $ownerdom = $cdom;
                   7933:                         $owner = $ownername.':'.$ownerdom;
1.439     raeburn  7934:                     }
                   7935:                     @{$$users{'ow'}{$owner}} = 'any';
1.290     albertel 7936:                     if (defined($userdata) && 
1.609     raeburn  7937: 			!exists($$userdata{$owner})) {
                   7938: 			&get_user_info($ownerdom,$ownername,\%idx,$userdata);
                   7939:                         if (!grep(/^none$/,@{$seclists{$owner}})) {
                   7940:                             push(@{$seclists{$owner}},'none');
                   7941:                         }
                   7942:                         if (ref($statushash) eq 'HASH') {
                   7943:                             $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419     raeburn  7944:                         }
1.290     albertel 7945: 		    }
1.279     raeburn  7946:                 }
                   7947:             }
                   7948:         }
1.419     raeburn  7949:         foreach my $user (keys(%seclists)) {
                   7950:             @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
                   7951:             $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
                   7952:         }
1.275     raeburn  7953:     }
                   7954:     return;
                   7955: }
                   7956: 
1.288     raeburn  7957: sub get_user_info {
                   7958:     my ($udom,$uname,$idx,$userdata) = @_;
1.289     albertel 7959:     $$userdata{$uname.':'.$udom}[$$idx{fullname}] = 
                   7960: 	&plainname($uname,$udom,'lastname');
1.291     albertel 7961:     $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297     raeburn  7962:     $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609     raeburn  7963:     my %idhash =  &Apache::lonnet::idrget($udom,($uname));
                   7964:     $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname}; 
1.288     raeburn  7965:     return;
                   7966: }
1.275     raeburn  7967: 
1.472     raeburn  7968: ###############################################
                   7969: 
                   7970: =pod
                   7971: 
                   7972: =item * &get_user_quota()
                   7973: 
                   7974: Retrieves quota assigned for storage of portfolio files for a user  
                   7975: 
                   7976: Incoming parameters:
                   7977: 1. user's username
                   7978: 2. user's domain
                   7979: 
                   7980: Returns:
1.536     raeburn  7981: 1. Disk quota (in Mb) assigned to student.
                   7982: 2. (Optional) Type of setting: custom or default
                   7983:    (individually assigned or default for user's 
                   7984:    institutional status).
                   7985: 3. (Optional) - User's institutional status (e.g., faculty, staff
                   7986:    or student - types as defined in localenroll::inst_usertypes 
                   7987:    for user's domain, which determines default quota for user.
                   7988: 4. (Optional) - Default quota which would apply to the user.
1.472     raeburn  7989: 
                   7990: If a value has been stored in the user's environment, 
1.536     raeburn  7991: it will return that, otherwise it returns the maximal default
                   7992: defined for the user's instituional status(es) in the domain.
1.472     raeburn  7993: 
                   7994: =cut
                   7995: 
                   7996: ###############################################
                   7997: 
                   7998: 
                   7999: sub get_user_quota {
                   8000:     my ($uname,$udom) = @_;
1.536     raeburn  8001:     my ($quota,$quotatype,$settingstatus,$defquota);
1.472     raeburn  8002:     if (!defined($udom)) {
                   8003:         $udom = $env{'user.domain'};
                   8004:     }
                   8005:     if (!defined($uname)) {
                   8006:         $uname = $env{'user.name'};
                   8007:     }
                   8008:     if (($udom eq '' || $uname eq '') ||
                   8009:         ($udom eq 'public') && ($uname eq 'public')) {
                   8010:         $quota = 0;
1.536     raeburn  8011:         $quotatype = 'default';
                   8012:         $defquota = 0; 
1.472     raeburn  8013:     } else {
1.536     raeburn  8014:         my $inststatus;
1.472     raeburn  8015:         if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
                   8016:             $quota = $env{'environment.portfolioquota'};
1.536     raeburn  8017:             $inststatus = $env{'environment.inststatus'};
1.472     raeburn  8018:         } else {
1.536     raeburn  8019:             my %userenv = 
                   8020:                 &Apache::lonnet::get('environment',['portfolioquota',
                   8021:                                      'inststatus'],$udom,$uname);
1.472     raeburn  8022:             my ($tmp) = keys(%userenv);
                   8023:             if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   8024:                 $quota = $userenv{'portfolioquota'};
1.536     raeburn  8025:                 $inststatus = $userenv{'inststatus'};
1.472     raeburn  8026:             } else {
                   8027:                 undef(%userenv);
                   8028:             }
                   8029:         }
1.536     raeburn  8030:         ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472     raeburn  8031:         if ($quota eq '') {
1.536     raeburn  8032:             $quota = $defquota;
                   8033:             $quotatype = 'default';
                   8034:         } else {
                   8035:             $quotatype = 'custom';
1.472     raeburn  8036:         }
                   8037:     }
1.536     raeburn  8038:     if (wantarray) {
                   8039:         return ($quota,$quotatype,$settingstatus,$defquota);
                   8040:     } else {
                   8041:         return $quota;
                   8042:     }
1.472     raeburn  8043: }
                   8044: 
                   8045: ###############################################
                   8046: 
                   8047: =pod
                   8048: 
                   8049: =item * &default_quota()
                   8050: 
1.536     raeburn  8051: Retrieves default quota assigned for storage of user portfolio files,
                   8052: given an (optional) user's institutional status.
1.472     raeburn  8053: 
                   8054: Incoming parameters:
                   8055: 1. domain
1.536     raeburn  8056: 2. (Optional) institutional status(es).  This is a : separated list of 
                   8057:    status types (e.g., faculty, staff, student etc.)
                   8058:    which apply to the user for whom the default is being retrieved.
                   8059:    If the institutional status string in undefined, the domain
                   8060:    default quota will be returned. 
1.472     raeburn  8061: 
                   8062: Returns:
                   8063: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536     raeburn  8064: 2. (Optional) institutional type which determined the value of the
                   8065:    default quota.
1.472     raeburn  8066: 
                   8067: If a value has been stored in the domain's configuration db,
                   8068: it will return that, otherwise it returns 20 (for backwards 
                   8069: compatibility with domains which have not set up a configuration
                   8070: db file; the original statically defined portfolio quota was 20 Mb). 
                   8071: 
1.536     raeburn  8072: If the user's status includes multiple types (e.g., staff and student),
                   8073: the largest default quota which applies to the user determines the
                   8074: default quota returned.
                   8075: 
1.780     raeburn  8076: =back
                   8077: 
1.472     raeburn  8078: =cut
                   8079: 
                   8080: ###############################################
                   8081: 
                   8082: 
                   8083: sub default_quota {
1.536     raeburn  8084:     my ($udom,$inststatus) = @_;
                   8085:     my ($defquota,$settingstatus);
                   8086:     my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622     raeburn  8087:                                             ['quotas'],$udom);
                   8088:     if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536     raeburn  8089:         if ($inststatus ne '') {
1.765     raeburn  8090:             my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536     raeburn  8091:             foreach my $item (@statuses) {
1.711     raeburn  8092:                 if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   8093:                     if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
                   8094:                         if ($defquota eq '') {
                   8095:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   8096:                             $settingstatus = $item;
                   8097:                         } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
                   8098:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   8099:                             $settingstatus = $item;
                   8100:                         }
                   8101:                     }
                   8102:                 } else {
                   8103:                     if ($quotahash{'quotas'}{$item} ne '') {
                   8104:                         if ($defquota eq '') {
                   8105:                             $defquota = $quotahash{'quotas'}{$item};
                   8106:                             $settingstatus = $item;
                   8107:                         } elsif ($quotahash{'quotas'}{$item} > $defquota) {
                   8108:                             $defquota = $quotahash{'quotas'}{$item};
                   8109:                             $settingstatus = $item;
                   8110:                         }
1.536     raeburn  8111:                     }
                   8112:                 }
                   8113:             }
                   8114:         }
                   8115:         if ($defquota eq '') {
1.711     raeburn  8116:             if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   8117:                 $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
                   8118:             } else {
                   8119:                 $defquota = $quotahash{'quotas'}{'default'};
                   8120:             }
1.536     raeburn  8121:             $settingstatus = 'default';
                   8122:         }
                   8123:     } else {
                   8124:         $settingstatus = 'default';
                   8125:         $defquota = 20;
                   8126:     }
                   8127:     if (wantarray) {
                   8128:         return ($defquota,$settingstatus);
1.472     raeburn  8129:     } else {
1.536     raeburn  8130:         return $defquota;
1.472     raeburn  8131:     }
                   8132: }
                   8133: 
1.384     raeburn  8134: sub get_secgrprole_info {
                   8135:     my ($cdom,$cnum,$needroles,$type)  = @_;
                   8136:     my %sections_count = &get_sections($cdom,$cnum);
                   8137:     my @sections =  (sort {$a <=> $b} keys(%sections_count));
                   8138:     my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
                   8139:     my @groups = sort(keys(%curr_groups));
                   8140:     my $allroles = [];
                   8141:     my $rolehash;
                   8142:     my $accesshash = {
                   8143:                      active => 'Currently has access',
                   8144:                      future => 'Will have future access',
                   8145:                      previous => 'Previously had access',
                   8146:                   };
                   8147:     if ($needroles) {
                   8148:         $rolehash = {'all' => 'all'};
1.385     albertel 8149:         my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   8150: 	if (&Apache::lonnet::error(%user_roles)) {
                   8151: 	    undef(%user_roles);
                   8152: 	}
                   8153:         foreach my $item (keys(%user_roles)) {
1.384     raeburn  8154:             my ($role)=split(/\:/,$item,2);
                   8155:             if ($role eq 'cr') { next; }
                   8156:             if ($role =~ /^cr/) {
                   8157:                 $$rolehash{$role} = (split('/',$role))[3];
                   8158:             } else {
                   8159:                 $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
                   8160:             }
                   8161:         }
                   8162:         foreach my $key (sort(keys(%{$rolehash}))) {
                   8163:             push(@{$allroles},$key);
                   8164:         }
                   8165:         push (@{$allroles},'st');
                   8166:         $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
                   8167:     }
                   8168:     return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
                   8169: }
                   8170: 
1.555     raeburn  8171: sub user_picker {
1.994     raeburn  8172:     my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555     raeburn  8173:     my $currdom = $dom;
                   8174:     my %curr_selected = (
                   8175:                         srchin => 'dom',
1.580     raeburn  8176:                         srchby => 'lastname',
1.555     raeburn  8177:                       );
                   8178:     my $srchterm;
1.625     raeburn  8179:     if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555     raeburn  8180:         if ($srch->{'srchby'} ne '') {
                   8181:             $curr_selected{'srchby'} = $srch->{'srchby'};
                   8182:         }
                   8183:         if ($srch->{'srchin'} ne '') {
                   8184:             $curr_selected{'srchin'} = $srch->{'srchin'};
                   8185:         }
                   8186:         if ($srch->{'srchtype'} ne '') {
                   8187:             $curr_selected{'srchtype'} = $srch->{'srchtype'};
                   8188:         }
                   8189:         if ($srch->{'srchdomain'} ne '') {
                   8190:             $currdom = $srch->{'srchdomain'};
                   8191:         }
                   8192:         $srchterm = $srch->{'srchterm'};
                   8193:     }
                   8194:     my %lt=&Apache::lonlocal::texthash(
1.573     raeburn  8195:                     'usr'       => 'Search criteria',
1.563     raeburn  8196:                     'doma'      => 'Domain/institution to search',
1.558     albertel 8197:                     'uname'     => 'username',
                   8198:                     'lastname'  => 'last name',
1.555     raeburn  8199:                     'lastfirst' => 'last name, first name',
1.558     albertel 8200:                     'crs'       => 'in this course',
1.576     raeburn  8201:                     'dom'       => 'in selected LON-CAPA domain', 
1.558     albertel 8202:                     'alc'       => 'all LON-CAPA',
1.573     raeburn  8203:                     'instd'     => 'in institutional directory for selected domain',
1.558     albertel 8204:                     'exact'     => 'is',
                   8205:                     'contains'  => 'contains',
1.569     raeburn  8206:                     'begins'    => 'begins with',
1.571     raeburn  8207:                     'youm'      => "You must include some text to search for.",
                   8208:                     'thte'      => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
                   8209:                     'thet'      => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
                   8210:                     'yomc'      => "You must choose a domain when using an institutional directory search.",
                   8211:                     'ymcd'      => "You must choose a domain when using a domain search.",
                   8212:                     'whus'      => "When using searching by last,first you must include a comma as separator between last name and first name.",
                   8213:                     'whse'      => "When searching by last,first you must include at least one character in the first name.",
                   8214:                      'thfo'     => "The following need to be corrected before the search can be run:",
1.555     raeburn  8215:                                        );
1.563     raeburn  8216:     my $domform = &select_dom_form($currdom,'srchdomain',1,1);
                   8217:     my $srchinsel = ' <select name="srchin">';
1.555     raeburn  8218: 
                   8219:     my @srchins = ('crs','dom','alc','instd');
                   8220: 
                   8221:     foreach my $option (@srchins) {
                   8222:         # FIXME 'alc' option unavailable until 
                   8223:         #       loncreateuser::print_user_query_page()
                   8224:         #       has been completed.
                   8225:         next if ($option eq 'alc');
1.880     raeburn  8226:         next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));  
1.555     raeburn  8227:         next if ($option eq 'crs' && !$env{'request.course.id'});
1.563     raeburn  8228:         if ($curr_selected{'srchin'} eq $option) {
                   8229:             $srchinsel .= ' 
                   8230:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   8231:         } else {
                   8232:             $srchinsel .= '
                   8233:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   8234:         }
1.555     raeburn  8235:     }
1.563     raeburn  8236:     $srchinsel .= "\n  </select>\n";
1.555     raeburn  8237: 
                   8238:     my $srchbysel =  ' <select name="srchby">';
1.580     raeburn  8239:     foreach my $option ('lastname','lastfirst','uname') {
1.555     raeburn  8240:         if ($curr_selected{'srchby'} eq $option) {
                   8241:             $srchbysel .= '
                   8242:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   8243:         } else {
                   8244:             $srchbysel .= '
                   8245:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   8246:          }
                   8247:     }
                   8248:     $srchbysel .= "\n  </select>\n";
                   8249: 
                   8250:     my $srchtypesel = ' <select name="srchtype">';
1.580     raeburn  8251:     foreach my $option ('begins','contains','exact') {
1.555     raeburn  8252:         if ($curr_selected{'srchtype'} eq $option) {
                   8253:             $srchtypesel .= '
                   8254:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   8255:         } else {
                   8256:             $srchtypesel .= '
                   8257:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   8258:         }
                   8259:     }
                   8260:     $srchtypesel .= "\n  </select>\n";
                   8261: 
1.558     albertel 8262:     my ($newuserscript,$new_user_create);
1.994     raeburn  8263:     my $context_dom = $env{'request.role.domain'};
                   8264:     if ($context eq 'requestcrs') {
                   8265:         if ($env{'form.coursedom'} ne '') { 
                   8266:             $context_dom = $env{'form.coursedom'};
                   8267:         }
                   8268:     }
1.556     raeburn  8269:     if ($forcenewuser) {
1.576     raeburn  8270:         if (ref($srch) eq 'HASH') {
1.994     raeburn  8271:             if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627     raeburn  8272:                 if ($cancreate) {
                   8273:                     $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>';
                   8274:                 } else {
1.799     bisitz   8275:                     my $helplink = 'javascript:helpMenu('."'display'".')';
1.627     raeburn  8276:                     my %usertypetext = (
                   8277:                         official   => 'institutional',
                   8278:                         unofficial => 'non-institutional',
                   8279:                     );
1.799     bisitz   8280:                     $new_user_create = '<p class="LC_warning">'
                   8281:                                       .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
                   8282:                                       .' '
                   8283:                                       .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
                   8284:                                           ,'<a href="'.$helplink.'">','</a>')
                   8285:                                       .'</p><br />';
1.627     raeburn  8286:                 }
1.576     raeburn  8287:             }
                   8288:         }
                   8289: 
1.556     raeburn  8290:         $newuserscript = <<"ENDSCRIPT";
                   8291: 
1.570     raeburn  8292: function setSearch(createnew,callingForm) {
1.556     raeburn  8293:     if (createnew == 1) {
1.570     raeburn  8294:         for (var i=0; i<callingForm.srchby.length; i++) {
                   8295:             if (callingForm.srchby.options[i].value == 'uname') {
                   8296:                 callingForm.srchby.selectedIndex = i;
1.556     raeburn  8297:             }
                   8298:         }
1.570     raeburn  8299:         for (var i=0; i<callingForm.srchin.length; i++) {
                   8300:             if ( callingForm.srchin.options[i].value == 'dom') {
                   8301: 		callingForm.srchin.selectedIndex = i;
1.556     raeburn  8302:             }
                   8303:         }
1.570     raeburn  8304:         for (var i=0; i<callingForm.srchtype.length; i++) {
                   8305:             if (callingForm.srchtype.options[i].value == 'exact') {
                   8306:                 callingForm.srchtype.selectedIndex = i;
1.556     raeburn  8307:             }
                   8308:         }
1.570     raeburn  8309:         for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994     raeburn  8310:             if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570     raeburn  8311:                 callingForm.srchdomain.selectedIndex = i;
1.556     raeburn  8312:             }
                   8313:         }
                   8314:     }
                   8315: }
                   8316: ENDSCRIPT
1.558     albertel 8317: 
1.556     raeburn  8318:     }
                   8319: 
1.555     raeburn  8320:     my $output = <<"END_BLOCK";
1.556     raeburn  8321: <script type="text/javascript">
1.824     bisitz   8322: // <![CDATA[
1.570     raeburn  8323: function validateEntry(callingForm) {
1.558     albertel 8324: 
1.556     raeburn  8325:     var checkok = 1;
1.558     albertel 8326:     var srchin;
1.570     raeburn  8327:     for (var i=0; i<callingForm.srchin.length; i++) {
                   8328: 	if ( callingForm.srchin[i].checked ) {
                   8329: 	    srchin = callingForm.srchin[i].value;
1.558     albertel 8330: 	}
                   8331:     }
                   8332: 
1.570     raeburn  8333:     var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
                   8334:     var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
                   8335:     var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
                   8336:     var srchterm =  callingForm.srchterm.value;
                   8337:     var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556     raeburn  8338:     var msg = "";
                   8339: 
                   8340:     if (srchterm == "") {
                   8341:         checkok = 0;
1.571     raeburn  8342:         msg += "$lt{'youm'}\\n";
1.556     raeburn  8343:     }
                   8344: 
1.569     raeburn  8345:     if (srchtype== 'begins') {
                   8346:         if (srchterm.length < 2) {
                   8347:             checkok = 0;
1.571     raeburn  8348:             msg += "$lt{'thte'}\\n";
1.569     raeburn  8349:         }
                   8350:     }
                   8351: 
1.556     raeburn  8352:     if (srchtype== 'contains') {
                   8353:         if (srchterm.length < 3) {
                   8354:             checkok = 0;
1.571     raeburn  8355:             msg += "$lt{'thet'}\\n";
1.556     raeburn  8356:         }
                   8357:     }
                   8358:     if (srchin == 'instd') {
                   8359:         if (srchdomain == '') {
                   8360:             checkok = 0;
1.571     raeburn  8361:             msg += "$lt{'yomc'}\\n";
1.556     raeburn  8362:         }
                   8363:     }
                   8364:     if (srchin == 'dom') {
                   8365:         if (srchdomain == '') {
                   8366:             checkok = 0;
1.571     raeburn  8367:             msg += "$lt{'ymcd'}\\n";
1.556     raeburn  8368:         }
                   8369:     }
                   8370:     if (srchby == 'lastfirst') {
                   8371:         if (srchterm.indexOf(",") == -1) {
                   8372:             checkok = 0;
1.571     raeburn  8373:             msg += "$lt{'whus'}\\n";
1.556     raeburn  8374:         }
                   8375:         if (srchterm.indexOf(",") == srchterm.length -1) {
                   8376:             checkok = 0;
1.571     raeburn  8377:             msg += "$lt{'whse'}\\n";
1.556     raeburn  8378:         }
                   8379:     }
                   8380:     if (checkok == 0) {
1.571     raeburn  8381:         alert("$lt{'thfo'}\\n"+msg);
1.556     raeburn  8382:         return;
                   8383:     }
                   8384:     if (checkok == 1) {
1.570     raeburn  8385:         callingForm.submit();
1.556     raeburn  8386:     }
                   8387: }
                   8388: 
                   8389: $newuserscript
                   8390: 
1.824     bisitz   8391: // ]]>
1.556     raeburn  8392: </script>
1.558     albertel 8393: 
                   8394: $new_user_create
                   8395: 
1.555     raeburn  8396: END_BLOCK
1.558     albertel 8397: 
1.876     raeburn  8398:     $output .= &Apache::lonhtmlcommon::start_pick_box().
                   8399:                &Apache::lonhtmlcommon::row_title($lt{'doma'}).
                   8400:                $domform.
                   8401:                &Apache::lonhtmlcommon::row_closure().
                   8402:                &Apache::lonhtmlcommon::row_title($lt{'usr'}).
                   8403:                $srchbysel.
                   8404:                $srchtypesel. 
                   8405:                '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
                   8406:                $srchinsel.
                   8407:                &Apache::lonhtmlcommon::row_closure(1). 
                   8408:                &Apache::lonhtmlcommon::end_pick_box().
                   8409:                '<br />';
1.555     raeburn  8410:     return $output;
                   8411: }
                   8412: 
1.612     raeburn  8413: sub user_rule_check {
1.615     raeburn  8414:     my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612     raeburn  8415:     my $response;
                   8416:     if (ref($usershash) eq 'HASH') {
                   8417:         foreach my $user (keys(%{$usershash})) {
                   8418:             my ($uname,$udom) = split(/:/,$user);
                   8419:             next if ($udom eq '' || $uname eq '');
1.615     raeburn  8420:             my ($id,$newuser);
1.612     raeburn  8421:             if (ref($usershash->{$user}) eq 'HASH') {
1.615     raeburn  8422:                 $newuser = $usershash->{$user}->{'newuser'};
1.612     raeburn  8423:                 $id = $usershash->{$user}->{'id'};
                   8424:             }
                   8425:             my $inst_response;
                   8426:             if (ref($checks) eq 'HASH') {
                   8427:                 if (defined($checks->{'username'})) {
1.615     raeburn  8428:                     ($inst_response,%{$inst_results->{$user}}) = 
1.612     raeburn  8429:                         &Apache::lonnet::get_instuser($udom,$uname);
                   8430:                 } elsif (defined($checks->{'id'})) {
1.615     raeburn  8431:                     ($inst_response,%{$inst_results->{$user}}) =
1.612     raeburn  8432:                         &Apache::lonnet::get_instuser($udom,undef,$id);
                   8433:                 }
1.615     raeburn  8434:             } else {
                   8435:                 ($inst_response,%{$inst_results->{$user}}) =
                   8436:                     &Apache::lonnet::get_instuser($udom,$uname);
                   8437:                 return;
1.612     raeburn  8438:             }
1.615     raeburn  8439:             if (!$got_rules->{$udom}) {
1.612     raeburn  8440:                 my %domconfig = &Apache::lonnet::get_dom('configuration',
                   8441:                                                   ['usercreation'],$udom);
                   8442:                 if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615     raeburn  8443:                     foreach my $item ('username','id') {
1.612     raeburn  8444:                         if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
                   8445:                             $$curr_rules{$udom}{$item} = 
                   8446:                                 $domconfig{'usercreation'}{$item.'_rule'};
1.585     raeburn  8447:                         }
                   8448:                     }
                   8449:                 }
1.615     raeburn  8450:                 $got_rules->{$udom} = 1;  
1.585     raeburn  8451:             }
1.612     raeburn  8452:             foreach my $item (keys(%{$checks})) {
                   8453:                 if (ref($$curr_rules{$udom}) eq 'HASH') {
                   8454:                     if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
                   8455:                         if (@{$$curr_rules{$udom}{$item}} > 0) {
                   8456:                             my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
                   8457:                             foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
                   8458:                                 if ($rule_check{$rule}) {
                   8459:                                     $$rulematch{$user}{$item} = $rule;
                   8460:                                     if ($inst_response eq 'ok') {
1.615     raeburn  8461:                                         if (ref($inst_results) eq 'HASH') {
                   8462:                                             if (ref($inst_results->{$user}) eq 'HASH') {
                   8463:                                                 if (keys(%{$inst_results->{$user}}) == 0) {
                   8464:                                                     $$alerts{$item}{$udom}{$uname} = 1;
                   8465:                                                 }
1.612     raeburn  8466:                                             }
                   8467:                                         }
1.615     raeburn  8468:                                     }
                   8469:                                     last;
1.585     raeburn  8470:                                 }
                   8471:                             }
                   8472:                         }
                   8473:                     }
                   8474:                 }
                   8475:             }
                   8476:         }
                   8477:     }
1.612     raeburn  8478:     return;
                   8479: }
                   8480: 
                   8481: sub user_rule_formats {
                   8482:     my ($domain,$domdesc,$curr_rules,$check) = @_;
                   8483:     my %text = ( 
                   8484:                  'username' => 'Usernames',
                   8485:                  'id'       => 'IDs',
                   8486:                );
                   8487:     my $output;
                   8488:     my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
                   8489:     if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
                   8490:         if (@{$ruleorder} > 0) {
                   8491:             $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>';
                   8492:             foreach my $rule (@{$ruleorder}) {
                   8493:                 if (ref($curr_rules) eq 'ARRAY') {
                   8494:                     if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
                   8495:                         if (ref($rules->{$rule}) eq 'HASH') {
                   8496:                             $output .= '<li>'.$rules->{$rule}{'name'}.': '.
                   8497:                                         $rules->{$rule}{'desc'}.'</li>';
                   8498:                         }
                   8499:                     }
                   8500:                 }
                   8501:             }
                   8502:             $output .= '</ul>';
                   8503:         }
                   8504:     }
                   8505:     return $output;
                   8506: }
                   8507: 
                   8508: sub instrule_disallow_msg {
1.615     raeburn  8509:     my ($checkitem,$domdesc,$count,$mode) = @_;
1.612     raeburn  8510:     my $response;
                   8511:     my %text = (
                   8512:                   item   => 'username',
                   8513:                   items  => 'usernames',
                   8514:                   match  => 'matches',
                   8515:                   do     => 'does',
                   8516:                   action => 'a username',
                   8517:                   one    => 'one',
                   8518:                );
                   8519:     if ($count > 1) {
                   8520:         $text{'item'} = 'usernames';
                   8521:         $text{'match'} ='match';
                   8522:         $text{'do'} = 'do';
                   8523:         $text{'action'} = 'usernames',
                   8524:         $text{'one'} = 'ones';
                   8525:     }
                   8526:     if ($checkitem eq 'id') {
                   8527:         $text{'items'} = 'IDs';
                   8528:         $text{'item'} = 'ID';
                   8529:         $text{'action'} = 'an ID';
1.615     raeburn  8530:         if ($count > 1) {
                   8531:             $text{'item'} = 'IDs';
                   8532:             $text{'action'} = 'IDs';
                   8533:         }
1.612     raeburn  8534:     }
1.674     bisitz   8535:     $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  8536:     if ($mode eq 'upload') {
                   8537:         if ($checkitem eq 'username') {
                   8538:             $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'}.");
                   8539:         } elsif ($checkitem eq 'id') {
1.674     bisitz   8540:             $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  8541:         }
1.669     raeburn  8542:     } elsif ($mode eq 'selfcreate') {
                   8543:         if ($checkitem eq 'id') {
                   8544:             $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.");
                   8545:         }
1.615     raeburn  8546:     } else {
                   8547:         if ($checkitem eq 'username') {
                   8548:             $response .= &mt("You must choose $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
                   8549:         } elsif ($checkitem eq 'id') {
                   8550:             $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.");
                   8551:         }
1.612     raeburn  8552:     }
                   8553:     return $response;
1.585     raeburn  8554: }
                   8555: 
1.624     raeburn  8556: sub personal_data_fieldtitles {
                   8557:     my %fieldtitles = &Apache::lonlocal::texthash (
                   8558:                         id => 'Student/Employee ID',
                   8559:                         permanentemail => 'E-mail address',
                   8560:                         lastname => 'Last Name',
                   8561:                         firstname => 'First Name',
                   8562:                         middlename => 'Middle Name',
                   8563:                         generation => 'Generation',
                   8564:                         gen => 'Generation',
1.765     raeburn  8565:                         inststatus => 'Affiliation',
1.624     raeburn  8566:                    );
                   8567:     return %fieldtitles;
                   8568: }
                   8569: 
1.642     raeburn  8570: sub sorted_inst_types {
                   8571:     my ($dom) = @_;
                   8572:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
                   8573:     my $othertitle = &mt('All users');
                   8574:     if ($env{'request.course.id'}) {
1.668     raeburn  8575:         $othertitle  = &mt('Any users');
1.642     raeburn  8576:     }
                   8577:     my @types;
                   8578:     if (ref($order) eq 'ARRAY') {
                   8579:         @types = @{$order};
                   8580:     }
                   8581:     if (@types == 0) {
                   8582:         if (ref($usertypes) eq 'HASH') {
                   8583:             @types = sort(keys(%{$usertypes}));
                   8584:         }
                   8585:     }
                   8586:     if (keys(%{$usertypes}) > 0) {
                   8587:         $othertitle = &mt('Other users');
                   8588:     }
                   8589:     return ($othertitle,$usertypes,\@types);
                   8590: }
                   8591: 
1.645     raeburn  8592: sub get_institutional_codes {
                   8593:     my ($settings,$allcourses,$LC_code) = @_;
                   8594: # Get complete list of course sections to update
                   8595:     my @currsections = ();
                   8596:     my @currxlists = ();
                   8597:     my $coursecode = $$settings{'internal.coursecode'};
                   8598: 
                   8599:     if ($$settings{'internal.sectionnums'} ne '') {
                   8600:         @currsections = split(/,/,$$settings{'internal.sectionnums'});
                   8601:     }
                   8602: 
                   8603:     if ($$settings{'internal.crosslistings'} ne '') {
                   8604:         @currxlists = split(/,/,$$settings{'internal.crosslistings'});
                   8605:     }
                   8606: 
                   8607:     if (@currxlists > 0) {
                   8608:         foreach (@currxlists) {
                   8609:             if (m/^([^:]+):(\w*)$/) {
                   8610:                 unless (grep/^$1$/,@{$allcourses}) {
                   8611:                     push @{$allcourses},$1;
                   8612:                     $$LC_code{$1} = $2;
                   8613:                 }
                   8614:             }
                   8615:         }
                   8616:     }
                   8617:  
                   8618:     if (@currsections > 0) {
                   8619:         foreach (@currsections) {
                   8620:             if (m/^(\w+):(\w*)$/) {
                   8621:                 my $sec = $coursecode.$1;
                   8622:                 my $lc_sec = $2;
                   8623:                 unless (grep/^$sec$/,@{$allcourses}) {
                   8624:                     push @{$allcourses},$sec;
                   8625:                     $$LC_code{$sec} = $lc_sec;
                   8626:                 }
                   8627:             }
                   8628:         }
                   8629:     }
                   8630:     return;
                   8631: }
                   8632: 
1.971     raeburn  8633: sub get_standard_codeitems {
                   8634:     return ('Year','Semester','Department','Number','Section');
                   8635: }
                   8636: 
1.112     bowersj2 8637: =pod
                   8638: 
1.780     raeburn  8639: =head1 Slot Helpers
                   8640: 
                   8641: =over 4
                   8642: 
                   8643: =item * sorted_slots()
                   8644: 
1.1040    raeburn  8645: Sorts an array of slot names in order of an optional sort key,
                   8646: default sort is by slot start time (earliest first). 
1.780     raeburn  8647: 
                   8648: Inputs:
                   8649: 
                   8650: =over 4
                   8651: 
                   8652: slotsarr  - Reference to array of unsorted slot names.
                   8653: 
                   8654: slots     - Reference to hash of hash, where outer hash keys are slot names.
                   8655: 
1.1040    raeburn  8656: sortkey   - Name of key in inner hash to be sorted on (e.g., starttime).
                   8657: 
1.549     albertel 8658: =back
                   8659: 
1.780     raeburn  8660: Returns:
                   8661: 
                   8662: =over 4
                   8663: 
1.1040    raeburn  8664: sorted   - An array of slot names sorted by a specified sort key 
                   8665:            (default sort key is start time of the slot).
1.780     raeburn  8666: 
                   8667: =back
                   8668: 
                   8669: =cut
                   8670: 
                   8671: 
                   8672: sub sorted_slots {
1.1040    raeburn  8673:     my ($slotsarr,$slots,$sortkey) = @_;
                   8674:     if ($sortkey eq '') {
                   8675:         $sortkey = 'starttime';
                   8676:     }
1.780     raeburn  8677:     my @sorted;
                   8678:     if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
                   8679:         @sorted =
                   8680:             sort {
                   8681:                      if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040    raeburn  8682:                          return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780     raeburn  8683:                      }
                   8684:                      if (ref($slots->{$a})) { return -1;}
                   8685:                      if (ref($slots->{$b})) { return 1;}
                   8686:                      return 0;
                   8687:                  } @{$slotsarr};
                   8688:     }
                   8689:     return @sorted;
                   8690: }
                   8691: 
1.1040    raeburn  8692: =pod
                   8693: 
                   8694: =item * get_future_slots()
                   8695: 
                   8696: Inputs:
                   8697: 
                   8698: =over 4
                   8699: 
                   8700: cnum - course number
                   8701: 
                   8702: cdom - course domain
                   8703: 
                   8704: now - current UNIX time
                   8705: 
                   8706: symb - optional symb
                   8707: 
                   8708: =back
                   8709: 
                   8710: Returns:
                   8711: 
                   8712: =over 4
                   8713: 
                   8714: sorted_reservable - ref to array of student_schedulable slots currently 
                   8715:                     reservable, ordered by end date of reservation period.
                   8716: 
                   8717: reservable_now - ref to hash of student_schedulable slots currently
                   8718:                  reservable.
                   8719: 
                   8720:     Keys in inner hash are:
                   8721:     (a) symb: either blank or symb to which slot use is restricted.
                   8722:     (b) endreserve: end date of reservation period. 
                   8723: 
                   8724: sorted_future - ref to array of student_schedulable slots reservable in
                   8725:                 the future, ordered by start date of reservation period.
                   8726: 
                   8727: future_reservable - ref to hash of student_schedulable slots reservable
                   8728:                     in the future.
                   8729: 
                   8730:     Keys in inner hash are:
                   8731:     (a) symb: either blank or symb to which slot use is restricted.
                   8732:     (b) startreserve:  start date of reservation period.
                   8733: 
                   8734: =back
                   8735: 
                   8736: =cut
                   8737: 
                   8738: sub get_future_slots {
                   8739:     my ($cnum,$cdom,$now,$symb) = @_;
                   8740:     my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
                   8741:     my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
                   8742:     foreach my $slot (keys(%slots)) {
                   8743:         next unless($slots{$slot}->{'type'} eq 'schedulable_student');
                   8744:         if ($symb) {
                   8745:             next if (($slots{$slot}->{'symb'} ne '') && 
                   8746:                      ($slots{$slot}->{'symb'} ne $symb));
                   8747:         }
                   8748:         if (($slots{$slot}->{'starttime'} > $now) &&
                   8749:             ($slots{$slot}->{'endtime'} > $now)) {
                   8750:             if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
                   8751:                 my $userallowed = 0;
                   8752:                 if ($slots{$slot}->{'allowedsections'}) {
                   8753:                     my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
                   8754:                     if (!defined($env{'request.role.sec'})
                   8755:                         && grep(/^No section assigned$/,@allowed_sec)) {
                   8756:                         $userallowed=1;
                   8757:                     } else {
                   8758:                         if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
                   8759:                             $userallowed=1;
                   8760:                         }
                   8761:                     }
                   8762:                     unless ($userallowed) {
                   8763:                         if (defined($env{'request.course.groups'})) {
                   8764:                             my @groups = split(/:/,$env{'request.course.groups'});
                   8765:                             foreach my $group (@groups) {
                   8766:                                 if (grep(/^\Q$group\E$/,@allowed_sec)) {
                   8767:                                     $userallowed=1;
                   8768:                                     last;
                   8769:                                 }
                   8770:                             }
                   8771:                         }
                   8772:                     }
                   8773:                 }
                   8774:                 if ($slots{$slot}->{'allowedusers'}) {
                   8775:                     my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
                   8776:                     my $user = $env{'user.name'}.':'.$env{'user.domain'};
                   8777:                     if (grep(/^\Q$user\E$/,@allowed_users)) {
                   8778:                         $userallowed = 1;
                   8779:                     }
                   8780:                 }
                   8781:                 next unless($userallowed);
                   8782:             }
                   8783:             my $startreserve = $slots{$slot}->{'startreserve'};
                   8784:             my $endreserve = $slots{$slot}->{'endreserve'};
                   8785:             my $symb = $slots{$slot}->{'symb'};
                   8786:             if (($startreserve < $now) &&
                   8787:                 (!$endreserve || $endreserve > $now)) {
                   8788:                 my $lastres = $endreserve;
                   8789:                 if (!$lastres) {
                   8790:                     $lastres = $slots{$slot}->{'starttime'};
                   8791:                 }
                   8792:                 $reservable_now{$slot} = {
                   8793:                                            symb       => $symb,
                   8794:                                            endreserve => $lastres
                   8795:                                          };
                   8796:             } elsif (($startreserve > $now) &&
                   8797:                      (!$endreserve || $endreserve > $startreserve)) {
                   8798:                 $future_reservable{$slot} = {
                   8799:                                               symb         => $symb,
                   8800:                                               startreserve => $startreserve
                   8801:                                             };
                   8802:             }
                   8803:         }
                   8804:     }
                   8805:     my @unsorted_reservable = keys(%reservable_now);
                   8806:     if (@unsorted_reservable > 0) {
                   8807:         @sorted_reservable = 
                   8808:             &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
                   8809:     }
                   8810:     my @unsorted_future = keys(%future_reservable);
                   8811:     if (@unsorted_future > 0) {
                   8812:         @sorted_future =
                   8813:             &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
                   8814:     }
                   8815:     return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
                   8816: }
1.780     raeburn  8817: 
                   8818: =pod
                   8819: 
1.549     albertel 8820: =head1 HTTP Helpers
                   8821: 
                   8822: =over 4
                   8823: 
1.648     raeburn  8824: =item * &get_unprocessed_cgi($query,$possible_names)
1.112     bowersj2 8825: 
1.258     albertel 8826: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112     bowersj2 8827: $query.  The parameters listed in $possible_names (an array reference),
1.258     albertel 8828: will be set in $env{'form.name'} if they do not already exist.
1.112     bowersj2 8829: 
                   8830: Typically called with $ENV{'QUERY_STRING'} as the first parameter.  
                   8831: $possible_names is an ref to an array of form element names.  As an example:
                   8832: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258     albertel 8833: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112     bowersj2 8834: 
                   8835: =cut
1.1       albertel 8836: 
1.6       albertel 8837: sub get_unprocessed_cgi {
1.25      albertel 8838:   my ($query,$possible_names)= @_;
1.26      matthew  8839:   # $Apache::lonxml::debug=1;
1.356     albertel 8840:   foreach my $pair (split(/&/,$query)) {
                   8841:     my ($name, $value) = split(/=/,$pair);
1.369     www      8842:     $name = &unescape($name);
1.25      albertel 8843:     if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
                   8844:       $value =~ tr/+/ /;
                   8845:       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258     albertel 8846:       unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25      albertel 8847:     }
1.16      harris41 8848:   }
1.6       albertel 8849: }
                   8850: 
1.112     bowersj2 8851: =pod
                   8852: 
1.648     raeburn  8853: =item * &cacheheader() 
1.112     bowersj2 8854: 
                   8855: returns cache-controlling header code
                   8856: 
                   8857: =cut
                   8858: 
1.7       albertel 8859: sub cacheheader {
1.258     albertel 8860:     unless ($env{'request.method'} eq 'GET') { return ''; }
1.216     albertel 8861:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
                   8862:     my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7       albertel 8863:                 <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
                   8864:                 <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216     albertel 8865:     return $output;
1.7       albertel 8866: }
                   8867: 
1.112     bowersj2 8868: =pod
                   8869: 
1.648     raeburn  8870: =item * &no_cache($r) 
1.112     bowersj2 8871: 
                   8872: specifies header code to not have cache
                   8873: 
                   8874: =cut
                   8875: 
1.9       albertel 8876: sub no_cache {
1.216     albertel 8877:     my ($r) = @_;
                   8878:     if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258     albertel 8879: 	$env{'request.method'} ne 'GET') { return ''; }
1.216     albertel 8880:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
                   8881:     $r->no_cache(1);
                   8882:     $r->header_out("Expires" => $date);
                   8883:     $r->header_out("Pragma" => "no-cache");
1.123     www      8884: }
                   8885: 
                   8886: sub content_type {
1.181     albertel 8887:     my ($r,$type,$charset) = @_;
1.299     foxr     8888:     if ($r) {
                   8889: 	#  Note that printout.pl calls this with undef for $r.
                   8890: 	&no_cache($r);
                   8891:     }
1.258     albertel 8892:     if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181     albertel 8893:     unless ($charset) {
                   8894: 	$charset=&Apache::lonlocal::current_encoding;
                   8895:     }
                   8896:     if ($charset) { $type.='; charset='.$charset; }
                   8897:     if ($r) {
                   8898: 	$r->content_type($type);
                   8899:     } else {
                   8900: 	print("Content-type: $type\n\n");
                   8901:     }
1.9       albertel 8902: }
1.25      albertel 8903: 
1.112     bowersj2 8904: =pod
                   8905: 
1.648     raeburn  8906: =item * &add_to_env($name,$value) 
1.112     bowersj2 8907: 
1.258     albertel 8908: adds $name to the %env hash with value
1.112     bowersj2 8909: $value, if $name already exists, the entry is converted to an array
                   8910: reference and $value is added to the array.
                   8911: 
                   8912: =cut
                   8913: 
1.25      albertel 8914: sub add_to_env {
                   8915:   my ($name,$value)=@_;
1.258     albertel 8916:   if (defined($env{$name})) {
                   8917:     if (ref($env{$name})) {
1.25      albertel 8918:       #already have multiple values
1.258     albertel 8919:       push(@{ $env{$name} },$value);
1.25      albertel 8920:     } else {
                   8921:       #first time seeing multiple values, convert hash entry to an arrayref
1.258     albertel 8922:       my $first=$env{$name};
                   8923:       undef($env{$name});
                   8924:       push(@{ $env{$name} },$first,$value);
1.25      albertel 8925:     }
                   8926:   } else {
1.258     albertel 8927:     $env{$name}=$value;
1.25      albertel 8928:   }
1.31      albertel 8929: }
1.149     albertel 8930: 
                   8931: =pod
                   8932: 
1.648     raeburn  8933: =item * &get_env_multiple($name) 
1.149     albertel 8934: 
1.258     albertel 8935: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149     albertel 8936: values may be defined and end up as an array ref.
                   8937: 
                   8938: returns an array of values
                   8939: 
                   8940: =cut
                   8941: 
                   8942: sub get_env_multiple {
                   8943:     my ($name) = @_;
                   8944:     my @values;
1.258     albertel 8945:     if (defined($env{$name})) {
1.149     albertel 8946:         # exists is it an array
1.258     albertel 8947:         if (ref($env{$name})) {
                   8948:             @values=@{ $env{$name} };
1.149     albertel 8949:         } else {
1.258     albertel 8950:             $values[0]=$env{$name};
1.149     albertel 8951:         }
                   8952:     }
                   8953:     return(@values);
                   8954: }
                   8955: 
1.660     raeburn  8956: sub ask_for_embedded_content {
                   8957:     my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.987     raeburn  8958:     my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges);
1.660     raeburn  8959:     my $num = 0;
1.987     raeburn  8960:     my $numremref = 0;
                   8961:     my $numinvalid = 0;
                   8962:     my $numpathchg = 0;
                   8963:     my $numexisting = 0;
                   8964:     my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath);
1.984     raeburn  8965:     if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
                   8966:         my $current_path='/';
                   8967:         if ($env{'form.currentpath'}) {
                   8968:             $current_path = $env{'form.currentpath'};
                   8969:         }
                   8970:         if ($actionurl eq '/adm/coursegrp_portfolio') {
                   8971:             $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   8972:             $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
                   8973:             $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
                   8974:         } else {
                   8975:             $udom = $env{'user.domain'};
                   8976:             $uname = $env{'user.name'};
                   8977:             $url = '/userfiles/portfolio';
                   8978:         }
1.987     raeburn  8979:         $toplevel = $url.'/';
1.984     raeburn  8980:         $url .= $current_path;
                   8981:         $getpropath = 1;
1.987     raeburn  8982:     } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
                   8983:              ($actionurl eq '/adm/imsimport')) { 
1.1022    www      8984:         my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026    raeburn  8985:         $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987     raeburn  8986:         $toplevel = $url;
1.984     raeburn  8987:         if ($rest ne '') {
1.987     raeburn  8988:             $url .= $rest;
                   8989:         }
                   8990:     } elsif ($actionurl eq '/adm/coursedocs') {
                   8991:         if (ref($args) eq 'HASH') {
                   8992:            $url = $args->{'docs_url'};
                   8993:            $toplevel = $url;
                   8994:         }
                   8995:     }
                   8996:     my $now = time();
                   8997:     foreach my $embed_file (keys(%{$allfiles})) {
                   8998:         my $absolutepath;
                   8999:         if ($embed_file =~ m{^\w+://}) {
                   9000:             $newfiles{$embed_file} = 1;
                   9001:             $mapping{$embed_file} = $embed_file;
                   9002:         } else {
                   9003:             if ($embed_file =~ m{^/}) {
                   9004:                 $absolutepath = $embed_file;
                   9005:                 $embed_file =~ s{^(/+)}{};
                   9006:             }
                   9007:             if ($embed_file =~ m{/}) {
                   9008:                 my ($path,$fname) = ($embed_file =~ m{^(.+)/([^/]*)$});
                   9009:                 $path = &check_for_traversal($path,$url,$toplevel);
                   9010:                 my $item = $fname;
                   9011:                 if ($path ne '') {
                   9012:                     $item = $path.'/'.$fname;
                   9013:                     $subdependencies{$path}{$fname} = 1;
                   9014:                 } else {
                   9015:                     $dependencies{$item} = 1;
                   9016:                 }
                   9017:                 if ($absolutepath) {
                   9018:                     $mapping{$item} = $absolutepath;
                   9019:                 } else {
                   9020:                     $mapping{$item} = $embed_file;
                   9021:                 }
                   9022:             } else {
                   9023:                 $dependencies{$embed_file} = 1;
                   9024:                 if ($absolutepath) {
                   9025:                     $mapping{$embed_file} = $absolutepath;
                   9026:                 } else {
                   9027:                     $mapping{$embed_file} = $embed_file;
                   9028:                 }
                   9029:             }
1.984     raeburn  9030:         }
                   9031:     }
                   9032:     foreach my $path (keys(%subdependencies)) {
                   9033:         my %currsubfile;
                   9034:         if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) { 
1.1021    raeburn  9035:             my ($sublistref,$listerror) =
                   9036:                 &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
                   9037:             if (ref($sublistref) eq 'ARRAY') {
                   9038:                 foreach my $line (@{$sublistref}) {
                   9039:                     my ($file_name,$rest) = split(/\&/,$line,2);
                   9040:                     $currsubfile{$file_name} = 1;
                   9041:                 }
1.984     raeburn  9042:             }
1.987     raeburn  9043:         } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984     raeburn  9044:             if (opendir(my $dir,$url.'/'.$path)) {
                   9045:                 my @subdir_list = grep(!/^\./,readdir($dir));
                   9046:                 map {$currsubfile{$_} = 1;} @subdir_list;
                   9047:             }
                   9048:         }
                   9049:         foreach my $file (keys(%{$subdependencies{$path}})) {
1.987     raeburn  9050:             if ($currsubfile{$file}) {
                   9051:                 my $item = $path.'/'.$file;
                   9052:                 unless ($mapping{$item} eq $item) {
                   9053:                     $pathchanges{$item} = 1;
                   9054:                 }
                   9055:                 $existing{$item} = 1;
                   9056:                 $numexisting ++;
                   9057:             } else {
                   9058:                 $newfiles{$path.'/'.$file} = 1;
1.984     raeburn  9059:             }
                   9060:         }
                   9061:     }
1.987     raeburn  9062:     my %currfile;
1.984     raeburn  9063:     if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021    raeburn  9064:         my ($dirlistref,$listerror) =
                   9065:             &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
                   9066:         if (ref($dirlistref) eq 'ARRAY') {
                   9067:             foreach my $line (@{$dirlistref}) {
                   9068:                 my ($file_name,$rest) = split(/\&/,$line,2);
                   9069:                 $currfile{$file_name} = 1;
                   9070:             }
1.984     raeburn  9071:         }
1.987     raeburn  9072:     } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984     raeburn  9073:         if (opendir(my $dir,$url)) {
1.987     raeburn  9074:             my @dir_list = grep(!/^\./,readdir($dir));
1.984     raeburn  9075:             map {$currfile{$_} = 1;} @dir_list;
                   9076:         }
                   9077:     }
                   9078:     foreach my $file (keys(%dependencies)) {
1.987     raeburn  9079:         if ($currfile{$file}) {
                   9080:             unless ($mapping{$file} eq $file) {
                   9081:                 $pathchanges{$file} = 1;
                   9082:             }
                   9083:             $existing{$file} = 1;
                   9084:             $numexisting ++;
                   9085:         } else {
1.984     raeburn  9086:             $newfiles{$file} = 1;
                   9087:         }
                   9088:     }
                   9089:     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.660     raeburn  9090:         $upload_output .= &start_data_table_row().
1.987     raeburn  9091:                           '<td><span class="LC_filename">'.$embed_file.'</span>';
                   9092:         unless ($mapping{$embed_file} eq $embed_file) {
                   9093:             $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.&mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
                   9094:         }
                   9095:         $upload_output .= '</td><td>';
1.660     raeburn  9096:         if ($args->{'ignore_remote_references'}
                   9097:             && $embed_file =~ m{^\w+://}) {
                   9098:             $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
1.987     raeburn  9099:             $numremref++;
1.660     raeburn  9100:         } elsif ($args->{'error_on_invalid_names'}
                   9101:             && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
                   9102: 
1.987     raeburn  9103:             $upload_output.='<span class="LC_warning">'.&mt('Invalid characters').'</span>';
                   9104:             $numinvalid++;
1.660     raeburn  9105:         } else {
1.987     raeburn  9106:             $upload_output .= &embedded_file_element('upload_embedded',$num,
                   9107:                                                      $embed_file,\%mapping,
                   9108:                                                      $allfiles,$codebase);
                   9109:             $num++;
                   9110:         }
                   9111:         $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
                   9112:     }
                   9113:     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
                   9114:         $upload_output .= &start_data_table_row().
                   9115:                           '<td><span class="LC_filename">'.$embed_file.'</span></td>'.
                   9116:                           '<td><span class="LC_warning">'.&mt('Already exists').'</span></td>'.
                   9117:                           &Apache::loncommon::end_data_table_row()."\n";
                   9118:     }
                   9119:     if ($upload_output) {
                   9120:         $upload_output = &start_data_table().
                   9121:                          $upload_output.
                   9122:                          &end_data_table()."\n";
                   9123:     }
                   9124:     my $applies = 0;
                   9125:     if ($numremref) {
                   9126:         $applies ++;
                   9127:     }
                   9128:     if ($numinvalid) {
                   9129:         $applies ++;
                   9130:     }
                   9131:     if ($numexisting) {
                   9132:         $applies ++;
                   9133:     }
                   9134:     if ($num) {
                   9135:         $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
                   9136:                   ' method="post" enctype="multipart/form-data">'."\n".
                   9137:                   $state.
                   9138:                   '<h3>'.&mt('Upload embedded files').
                   9139:                   ':</h3>'.$upload_output.'<br />'."\n".
                   9140:                   '<input type ="hidden" name="number_embedded_items" value="'.
                   9141:                   $num.'" />'."\n";
                   9142:         if ($actionurl eq '') {
                   9143:             $output .=  '<input type="hidden" name="phase" value="three" />';
                   9144:         }
                   9145:     } elsif ($applies) {
                   9146:         $output = '<b>'.&mt('Referenced files').'</b>:<br />';
                   9147:         if ($applies > 1) {
                   9148:             $output .=  
                   9149:                 &mt('No files need to be uploaded, as one of the following applies to each reference:').'<ul>';
                   9150:             if ($numremref) {
                   9151:                 $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
                   9152:             }
                   9153:             if ($numinvalid) {
                   9154:                 $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
                   9155:             }
                   9156:             if ($numexisting) {
                   9157:                 $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
                   9158:             }
                   9159:             $output .= '</ul><br />';
                   9160:         } elsif ($numremref) {
                   9161:             $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
                   9162:         } elsif ($numinvalid) {
                   9163:             $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
                   9164:         } elsif ($numexisting) {
                   9165:             $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
                   9166:         }
                   9167:         $output .= $upload_output.'<br />';
                   9168:     }
                   9169:     my ($pathchange_output,$chgcount);
                   9170:     $chgcount = $num;
                   9171:     if (keys(%pathchanges) > 0) {
                   9172:         foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
                   9173:             if ($num) {
                   9174:                 $output .= &embedded_file_element('pathchange',$chgcount,
                   9175:                                                   $embed_file,\%mapping,
                   9176:                                                   $allfiles,$codebase);
                   9177:             } else {
                   9178:                 $pathchange_output .= 
                   9179:                     &start_data_table_row().
                   9180:                     '<td><input type ="checkbox" name="namechange" value="'.
                   9181:                     $chgcount.'" checked="checked" /></td>'.
                   9182:                     '<td>'.$mapping{$embed_file}.'</td>'.
                   9183:                     '<td>'.$embed_file.
                   9184:                     &embedded_file_element('pathchange',$numpathchg,$embed_file,
                   9185:                                            \%mapping,$allfiles,$codebase).
                   9186:                     '</td>'.&end_data_table_row();
1.660     raeburn  9187:             }
1.987     raeburn  9188:             $numpathchg ++;
                   9189:             $chgcount ++;
1.660     raeburn  9190:         }
                   9191:     }
1.984     raeburn  9192:     if ($num) {
1.987     raeburn  9193:         if ($numpathchg) {
                   9194:             $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
                   9195:                        $numpathchg.'" />'."\n";
                   9196:         }
                   9197:         if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') || 
                   9198:             ($actionurl eq '/adm/imsimport')) {
                   9199:             $output .= '<input type="hidden" name="phase" value="three" />'."\n";
                   9200:         } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
                   9201:             $output .= '<input type="hidden" name="action" value="upload_embedded" />';
                   9202:         }
                   9203:         $output .=  '<input type ="submit" value="'.&mt('Upload Listed Files').'" />'."\n".
                   9204:                     &mt('(only files for which a location has been provided will be uploaded)').'</form>'."\n";
                   9205:     } elsif ($numpathchg) {
                   9206:         my %pathchange = ();
                   9207:         $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
                   9208:         if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
                   9209:             $output .= '<p>'.&mt('or').'</p>'; 
                   9210:         } 
                   9211:     }
                   9212:     return ($output,$num,$numpathchg);
                   9213: }
                   9214: 
                   9215: sub embedded_file_element {
                   9216:     my ($context,$num,$embed_file,$mapping,$allfiles,$codebase) = @_;
                   9217:     return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
                   9218:                    (ref($codebase) eq 'HASH'));
                   9219:     my $output;
                   9220:     if ($context eq 'upload_embedded') {
                   9221:        $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
                   9222:     }
                   9223:     $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
                   9224:                &escape($embed_file).'" />';
                   9225:     unless (($context eq 'upload_embedded') && 
                   9226:             ($mapping->{$embed_file} eq $embed_file)) {
                   9227:         $output .='
                   9228:         <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
                   9229:     }
                   9230:     my $attrib;
                   9231:     if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
                   9232:         $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
                   9233:     }
                   9234:     $output .=
                   9235:         "\n\t\t".
                   9236:         '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
                   9237:         $attrib.'" />';
                   9238:     if (exists($codebase->{$mapping->{$embed_file}})) {
                   9239:         $output .=
                   9240:             "\n\t\t".
                   9241:             '<input name="codebase_'.$num.'" type="hidden" value="'.
                   9242:             &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984     raeburn  9243:     }
1.987     raeburn  9244:     return $output;
1.660     raeburn  9245: }
                   9246: 
1.661     raeburn  9247: sub upload_embedded {
                   9248:     my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987     raeburn  9249:         $current_disk_usage,$hiddenstate,$actionurl) = @_;
                   9250:     my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661     raeburn  9251:     for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
                   9252:         next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
                   9253:         my $orig_uploaded_filename =
                   9254:             $env{'form.embedded_item_'.$i.'.filename'};
1.987     raeburn  9255:         foreach my $type ('orig','ref','attrib','codebase') {
                   9256:             if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
                   9257:                 $env{'form.embedded_'.$type.'_'.$i} =
                   9258:                     &unescape($env{'form.embedded_'.$type.'_'.$i});
                   9259:             }
                   9260:         }
1.661     raeburn  9261:         my ($path,$fname) =
                   9262:             ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
                   9263:         # no path, whole string is fname
                   9264:         if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
                   9265:         $fname = &Apache::lonnet::clean_filename($fname);
                   9266:         # See if there is anything left
                   9267:         next if ($fname eq '');
                   9268: 
                   9269:         # Check if file already exists as a file or directory.
                   9270:         my ($state,$msg);
                   9271:         if ($context eq 'portfolio') {
                   9272:             my $port_path = $dirpath;
                   9273:             if ($group ne '') {
                   9274:                 $port_path = "groups/$group/$port_path";
                   9275:             }
1.987     raeburn  9276:             ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
                   9277:                                               $fname,$group,'embedded_item_'.$i,
1.661     raeburn  9278:                                               $dir_root,$port_path,$disk_quota,
                   9279:                                               $current_disk_usage,$uname,$udom);
                   9280:             if ($state eq 'will_exceed_quota'
1.984     raeburn  9281:                 || $state eq 'file_locked') {
1.661     raeburn  9282:                 $output .= $msg;
                   9283:                 next;
                   9284:             }
                   9285:         } elsif (($context eq 'author') || ($context eq 'testbank')) {
                   9286:             ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
                   9287:             if ($state eq 'exists') {
                   9288:                 $output .= $msg;
                   9289:                 next;
                   9290:             }
                   9291:         }
                   9292:         # Check if extension is valid
                   9293:         if (($fname =~ /\.(\w+)$/) &&
                   9294:             (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.987     raeburn  9295:             $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  9296:             next;
                   9297:         } elsif (($fname =~ /\.(\w+)$/) &&
                   9298:                  (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987     raeburn  9299:             $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661     raeburn  9300:             next;
                   9301:         } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.987     raeburn  9302:             $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  9303:             next;
                   9304:         }
                   9305: 
                   9306:         $env{'form.embedded_item_'.$i.'.filename'}=$fname;
                   9307:         if ($context eq 'portfolio') {
1.984     raeburn  9308:             my $result;
                   9309:             if ($state eq 'existingfile') {
                   9310:                 $result=
                   9311:                     &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.987     raeburn  9312:                                                     $dirpath.$env{'form.currentpath'}.$path);
1.661     raeburn  9313:             } else {
1.984     raeburn  9314:                 $result=
                   9315:                     &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987     raeburn  9316:                                                     $dirpath.
                   9317:                                                     $env{'form.currentpath'}.$path);
1.984     raeburn  9318:                 if ($result !~ m|^/uploaded/|) {
                   9319:                     $output .= '<span class="LC_error">'
                   9320:                                .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
                   9321:                                ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
                   9322:                                .'</span><br />';
                   9323:                     next;
                   9324:                 } else {
1.987     raeburn  9325:                     $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
                   9326:                                $path.$fname.'</span>').'<br />';     
1.984     raeburn  9327:                 }
1.661     raeburn  9328:             }
1.987     raeburn  9329:         } elsif ($context eq 'coursedoc') {
                   9330:             my $result =
                   9331:                 &Apache::lonnet::userfileupload('embedded_item_'.$i,'coursedoc',
                   9332:                                                 $dirpath.'/'.$path);
                   9333:             if ($result !~ m|^/uploaded/|) {
                   9334:                 $output .= '<span class="LC_error">'
                   9335:                            .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
                   9336:                            ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
                   9337:                            .'</span><br />';
                   9338:                     next;
                   9339:             } else {
                   9340:                 $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
                   9341:                            $path.$fname.'</span>').'<br />';
                   9342:             }
1.661     raeburn  9343:         } else {
                   9344: # Save the file
                   9345:             my $target = $env{'form.embedded_item_'.$i};
                   9346:             my $fullpath = $dir_root.$dirpath.'/'.$path;
                   9347:             my $dest = $fullpath.$fname;
                   9348:             my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027    raeburn  9349:             my @parts=split(/\//,"$dirpath/$path");
1.661     raeburn  9350:             my $count;
                   9351:             my $filepath = $dir_root;
1.1027    raeburn  9352:             foreach my $subdir (@parts) {
                   9353:                 $filepath .= "/$subdir";
                   9354:                 if (!-e $filepath) {
1.661     raeburn  9355:                     mkdir($filepath,0770);
                   9356:                 }
                   9357:             }
                   9358:             my $fh;
                   9359:             if (!open($fh,'>'.$dest)) {
                   9360:                 &Apache::lonnet::logthis('Failed to create '.$dest);
                   9361:                 $output .= '<span class="LC_error">'.
                   9362:                            &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   9363:                            '</span><br />';
                   9364:             } else {
                   9365:                 if (!print $fh $env{'form.embedded_item_'.$i}) {
                   9366:                     &Apache::lonnet::logthis('Failed to write to '.$dest);
                   9367:                     $output .= '<span class="LC_error">'.
                   9368:                               &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   9369:                               '</span><br />';
                   9370:                 } else {
1.987     raeburn  9371:                     $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
                   9372:                                $url.'</span>').'<br />';
                   9373:                     unless ($context eq 'testbank') {
                   9374:                         $footer .= &mt('View embedded file: [_1]',
                   9375:                                        '<a href="'.$url.'">'.$fname.'</a>').'<br />';
                   9376:                     }
                   9377:                 }
                   9378:                 close($fh);
                   9379:             }
                   9380:         }
                   9381:         if ($env{'form.embedded_ref_'.$i}) {
                   9382:             $pathchange{$i} = 1;
                   9383:         }
                   9384:     }
                   9385:     if ($output) {
                   9386:         $output = '<p>'.$output.'</p>';
                   9387:     }
                   9388:     $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
                   9389:     $returnflag = 'ok';
                   9390:     if (keys(%pathchange) > 0) {
                   9391:         if ($context eq 'portfolio') {
                   9392:             $output .= '<p>'.&mt('or').'</p>';
                   9393:         } elsif ($context eq 'testbank') {
1.988     raeburn  9394:             $output .=  '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).','<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987     raeburn  9395:             $returnflag = 'modify_orightml';
                   9396:         }
                   9397:     }
                   9398:     return ($output.$footer,$returnflag);
                   9399: }
                   9400: 
                   9401: sub modify_html_form {
                   9402:     my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
                   9403:     my $end = 0;
                   9404:     my $modifyform;
                   9405:     if ($context eq 'upload_embedded') {
                   9406:         return unless (ref($pathchange) eq 'HASH');
                   9407:         if ($env{'form.number_embedded_items'}) {
                   9408:             $end += $env{'form.number_embedded_items'};
                   9409:         }
                   9410:         if ($env{'form.number_pathchange_items'}) {
                   9411:             $end += $env{'form.number_pathchange_items'};
                   9412:         }
                   9413:         if ($end) {
                   9414:             for (my $i=0; $i<$end; $i++) {
                   9415:                 if ($i < $env{'form.number_embedded_items'}) {
                   9416:                     next unless($pathchange->{$i});
                   9417:                 }
                   9418:                 $modifyform .=
                   9419:                     &start_data_table_row().
                   9420:                     '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
                   9421:                     'checked="checked" /></td>'.
                   9422:                     '<td>'.$env{'form.embedded_ref_'.$i}.
                   9423:                     '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
                   9424:                     &escape($env{'form.embedded_ref_'.$i}).'" />'.
                   9425:                     '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
                   9426:                     &escape($env{'form.embedded_codebase_'.$i}).'" />'.
                   9427:                     '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
                   9428:                     &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
                   9429:                     '<td>'.$env{'form.embedded_orig_'.$i}.
                   9430:                     '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
                   9431:                     &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
                   9432:                     &end_data_table_row();
                   9433:             } 
                   9434:         }
                   9435:     } else {
                   9436:         $modifyform = $pathchgtable;
                   9437:         if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
                   9438:             $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
                   9439:         } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
                   9440:             $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
                   9441:         }
                   9442:     }
                   9443:     if ($modifyform) {
                   9444:         return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
                   9445:                '<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".
                   9446:                '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
                   9447:                '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
                   9448:                '</ol></p>'."\n".'<p>'.
                   9449:                &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
                   9450:                '<form method="post" name="refchanger" action="'.$actionurl.'">'.
                   9451:                &start_data_table()."\n".
                   9452:                &start_data_table_header_row().
                   9453:                '<th>'.&mt('Change?').'</th>'.
                   9454:                '<th>'.&mt('Current reference').'</th>'.
                   9455:                '<th>'.&mt('Required reference').'</th>'.
                   9456:                &end_data_table_header_row()."\n".
                   9457:                $modifyform.
                   9458:                &end_data_table().'<br />'."\n".$hiddenstate.
                   9459:                '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
                   9460:                '</form>'."\n";
                   9461:     }
                   9462:     return;
                   9463: }
                   9464: 
                   9465: sub modify_html_refs {
                   9466:     my ($context,$dirpath,$uname,$udom,$dir_root) = @_;
                   9467:     my $container;
                   9468:     if ($context eq 'portfolio') {
                   9469:         $container = $env{'form.container'};
                   9470:     } elsif ($context eq 'coursedoc') {
                   9471:         $container = $env{'form.primaryurl'};
                   9472:     } else {
1.1027    raeburn  9473:         $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987     raeburn  9474:     }
                   9475:     my (%allfiles,%codebase,$output,$content);
                   9476:     my @changes = &get_env_multiple('form.namechange');
                   9477:     return unless (@changes > 0);
                   9478:     if (($context eq 'portfolio') || ($context eq 'coursedoc')) {
                   9479:         return unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/});
                   9480:         $content = &Apache::lonnet::getfile($container);
                   9481:         return if ($content eq '-1');
                   9482:     } else {
                   9483:         return unless ($container =~ /^\Q$dir_root\E/); 
                   9484:         if (open(my $fh,"<$container")) {
                   9485:             $content = join('', <$fh>);
                   9486:             close($fh);
                   9487:         } else {
                   9488:             return;
                   9489:         }
                   9490:     }
                   9491:     my ($count,$codebasecount) = (0,0);
                   9492:     my $mm = new File::MMagic;
                   9493:     my $mime_type = $mm->checktype_contents($content);
                   9494:     if ($mime_type eq 'text/html') {
                   9495:         my $parse_result = 
                   9496:             &Apache::lonnet::extract_embedded_items($container,\%allfiles,
                   9497:                                                     \%codebase,\$content);
                   9498:         if ($parse_result eq 'ok') {
                   9499:             foreach my $i (@changes) {
                   9500:                 my $orig = &unescape($env{'form.embedded_orig_'.$i});
                   9501:                 my $ref = &unescape($env{'form.embedded_ref_'.$i});
                   9502:                 if ($allfiles{$ref}) {
                   9503:                     my $newname =  $orig;
                   9504:                     my ($attrib_regexp,$codebase);
1.1006    raeburn  9505:                     $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987     raeburn  9506:                     if ($attrib_regexp =~ /:/) {
                   9507:                         $attrib_regexp =~ s/\:/|/g;
                   9508:                     }
                   9509:                     if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
                   9510:                         my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
                   9511:                         $count += $numchg;
                   9512:                     }
                   9513:                     if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006    raeburn  9514:                         $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987     raeburn  9515:                         my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
                   9516:                         $codebasecount ++;
                   9517:                     }
                   9518:                 }
                   9519:             }
                   9520:             if ($count || $codebasecount) {
                   9521:                 my $saveresult;
                   9522:                 if ($context eq 'portfolio' || $context eq 'coursedoc') {
                   9523:                     my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
                   9524:                     if ($url eq $container) {
                   9525:                         my ($fname) = ($container =~ m{/([^/]+)$});
                   9526:                         $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
                   9527:                                             $count,'<span class="LC_filename">'.
                   9528:                                             $fname.'</span>').'</p>'; 
                   9529:                     } else {
                   9530:                          $output = '<p class="LC_error">'.
                   9531:                                    &mt('Error: update failed for: [_1].',
                   9532:                                    '<span class="LC_filename">'.
                   9533:                                    $container.'</span>').'</p>';
                   9534:                     }
                   9535:                 } else {
                   9536:                     if (open(my $fh,">$container")) {
                   9537:                         print $fh $content;
                   9538:                         close($fh);
                   9539:                         $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
                   9540:                                   $count,'<span class="LC_filename">'.
                   9541:                                   $container.'</span>').'</p>';
1.661     raeburn  9542:                     } else {
1.987     raeburn  9543:                          $output = '<p class="LC_error">'.
                   9544:                                    &mt('Error: could not update [_1].',
                   9545:                                    '<span class="LC_filename">'.
                   9546:                                    $container.'</span>').'</p>';
1.661     raeburn  9547:                     }
                   9548:                 }
                   9549:             }
1.987     raeburn  9550:         } else {
                   9551:             &logthis('Failed to parse '.$container.
                   9552:                      ' to modify references: '.$parse_result);
1.661     raeburn  9553:         }
                   9554:     }
                   9555:     return $output;
                   9556: }
                   9557: 
                   9558: sub check_for_existing {
                   9559:     my ($path,$fname,$element) = @_;
                   9560:     my ($state,$msg);
                   9561:     if (-d $path.'/'.$fname) {
                   9562:         $state = 'exists';
                   9563:         $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   9564:     } elsif (-e $path.'/'.$fname) {
                   9565:         $state = 'exists';
                   9566:         $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   9567:     }
                   9568:     if ($state eq 'exists') {
                   9569:         $msg = '<span class="LC_error">'.$msg.'</span><br />';
                   9570:     }
                   9571:     return ($state,$msg);
                   9572: }
                   9573: 
                   9574: sub check_for_upload {
                   9575:     my ($path,$fname,$group,$element,$portfolio_root,$port_path,
                   9576:         $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985     raeburn  9577:     my $filesize = length($env{'form.'.$element});
                   9578:     if (!$filesize) {
                   9579:         my $msg = '<span class="LC_error">'.
                   9580:                   &mt('Unable to upload [_1]. (size = [_2] bytes)', 
                   9581:                       '<span class="LC_filename">'.$fname.'</span>',
                   9582:                       $filesize).'<br />'.
1.1007    raeburn  9583:                   &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985     raeburn  9584:                   '</span>';
                   9585:         return ('zero_bytes',$msg);
                   9586:     }
                   9587:     $filesize =  $filesize/1000; #express in k (1024?)
1.661     raeburn  9588:     my $getpropath = 1;
1.1021    raeburn  9589:     my ($dirlistref,$listerror) =
                   9590:          &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661     raeburn  9591:     my $found_file = 0;
                   9592:     my $locked_file = 0;
1.991     raeburn  9593:     my @lockers;
                   9594:     my $navmap;
                   9595:     if ($env{'request.course.id'}) {
                   9596:         $navmap = Apache::lonnavmaps::navmap->new();
                   9597:     }
1.1021    raeburn  9598:     if (ref($dirlistref) eq 'ARRAY') {
                   9599:         foreach my $line (@{$dirlistref}) {
                   9600:             my ($file_name,$rest)=split(/\&/,$line,2);
                   9601:             if ($file_name eq $fname){
                   9602:                 $file_name = $path.$file_name;
                   9603:                 if ($group ne '') {
                   9604:                     $file_name = $group.$file_name;
                   9605:                 }
                   9606:                 $found_file = 1;
                   9607:                 if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
                   9608:                     foreach my $lock (@lockers) {
                   9609:                         if (ref($lock) eq 'ARRAY') {
                   9610:                             my ($symb,$crsid) = @{$lock};
                   9611:                             if ($crsid eq $env{'request.course.id'}) {
                   9612:                                 if (ref($navmap)) {
                   9613:                                     my $res = $navmap->getBySymb($symb);
                   9614:                                     foreach my $part (@{$res->parts()}) { 
                   9615:                                         my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
                   9616:                                         unless (($slot_status == $res->RESERVED) ||
                   9617:                                                 ($slot_status == $res->RESERVED_LOCATION)) {
                   9618:                                             $locked_file = 1;
                   9619:                                         }
1.991     raeburn  9620:                                     }
1.1021    raeburn  9621:                                 } else {
                   9622:                                     $locked_file = 1;
1.991     raeburn  9623:                                 }
                   9624:                             } else {
                   9625:                                 $locked_file = 1;
                   9626:                             }
                   9627:                         }
1.1021    raeburn  9628:                    }
                   9629:                 } else {
                   9630:                     my @info = split(/\&/,$rest);
                   9631:                     my $currsize = $info[6]/1000;
                   9632:                     if ($currsize < $filesize) {
                   9633:                         my $extra = $filesize - $currsize;
                   9634:                         if (($current_disk_usage + $extra) > $disk_quota) {
                   9635:                             my $msg = '<span class="LC_error">'.
                   9636:                                       &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.',
                   9637:                                           '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
                   9638:                                       '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
                   9639:                                                    $disk_quota,$current_disk_usage);
                   9640:                             return ('will_exceed_quota',$msg);
                   9641:                         }
1.984     raeburn  9642:                     }
                   9643:                 }
1.661     raeburn  9644:             }
                   9645:         }
                   9646:     }
                   9647:     if (($current_disk_usage + $filesize) > $disk_quota){
                   9648:         my $msg = '<span class="LC_error">'.
                   9649:                 &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
                   9650:                   '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
                   9651:         return ('will_exceed_quota',$msg);
                   9652:     } elsif ($found_file) {
                   9653:         if ($locked_file) {
                   9654:             my $msg = '<span class="LC_error">';
                   9655:             $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>');
                   9656:             $msg .= '</span><br />';
                   9657:             $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
                   9658:             return ('file_locked',$msg);
                   9659:         } else {
                   9660:             my $msg = '<span class="LC_error">';
1.984     raeburn  9661:             $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  9662:             $msg .= '</span>';
1.984     raeburn  9663:             return ('existingfile',$msg);
1.661     raeburn  9664:         }
                   9665:     }
                   9666: }
                   9667: 
1.987     raeburn  9668: sub check_for_traversal {
                   9669:     my ($path,$url,$toplevel) = @_;
                   9670:     my @parts=split(/\//,$path);
                   9671:     my $cleanpath;
                   9672:     my $fullpath = $url;
                   9673:     for (my $i=0;$i<@parts;$i++) {
                   9674:         next if ($parts[$i] eq '.');
                   9675:         if ($parts[$i] eq '..') {
                   9676:             $fullpath =~ s{([^/]+/)$}{};
                   9677:         } else {
                   9678:             $fullpath .= $parts[$i].'/';
                   9679:         }
                   9680:     }
                   9681:     if ($fullpath =~ /^\Q$url\E(.*)$/) {
                   9682:         $cleanpath = $1;
                   9683:     } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
                   9684:         my $curr_toprel = $1;
                   9685:         my @parts = split(/\//,$curr_toprel);
                   9686:         my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
                   9687:         my @urlparts = split(/\//,$url_toprel);
                   9688:         my $doubledots;
                   9689:         my $startdiff = -1;
                   9690:         for (my $i=0; $i<@urlparts; $i++) {
                   9691:             if ($startdiff == -1) {
                   9692:                 unless ($urlparts[$i] eq $parts[$i]) {
                   9693:                     $startdiff = $i;
                   9694:                     $doubledots .= '../';
                   9695:                 }
                   9696:             } else {
                   9697:                 $doubledots .= '../';
                   9698:             }
                   9699:         }
                   9700:         if ($startdiff > -1) {
                   9701:             $cleanpath = $doubledots;
                   9702:             for (my $i=$startdiff; $i<@parts; $i++) {
                   9703:                 $cleanpath .= $parts[$i].'/';
                   9704:             }
                   9705:         }
                   9706:     }
                   9707:     $cleanpath =~ s{(/)$}{};
                   9708:     return $cleanpath;
                   9709: }
1.31      albertel 9710: 
1.1053    raeburn  9711: sub is_archive_file {
                   9712:     my ($mimetype) = @_;
                   9713:     if (($mimetype eq 'application/octet-stream') ||
                   9714:         ($mimetype eq 'application/x-stuffit') ||
                   9715:         ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
                   9716:         return 1;
                   9717:     }
                   9718:     return;
                   9719: }
                   9720: 
                   9721: sub decompress_form {
                   9722:     my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements) = @_;
                   9723:     my %lt = &Apache::lonlocal::texthash (
                   9724:         this => 'This file is an archive file.',
                   9725:         youm => 'You may wish to extract its contents.',
                   9726:         camt => 'Extraction of contents is recommended for Camtasia zip files.',
                   9727:         perm => 'Permanently remove archive file after extraction of contents?',
                   9728:         extr => 'Extract contents',
                   9729:         yes  => 'Yes',
                   9730:         no   => 'No',
                   9731:     );
                   9732:     my $output = '<p>'.$lt{'this'}.' '.$lt{'youm'}.'<br />';
                   9733:     if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
                   9734:         $output .= $lt{'camt'};
                   9735:     }
                   9736:     $output .= '</p>';
                   9737:     $output .= <<"START";
1.1055  ! raeburn  9738: <p>
        !          9739: $lt{'this'} $lt{'youm'}
        !          9740: </p>
1.1053    raeburn  9741: <div id="uploadfileresult">
                   9742:   <form name="uploaded_decompress" action="$action" method="post">
                   9743:   <input type="hidden" name="archiveurl" value="$archiveurl" />
                   9744: START
                   9745:     if (ref($hiddenelements) eq 'HASH') {
                   9746:         foreach my $hidden (sort(keys(%{$hiddenelements}))) {
                   9747:             $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
                   9748:         }
                   9749:     }
                   9750:     $output .= <<"END";
                   9751: <span class="LC_nobreak">$lt{'perm'}&nbsp;
                   9752: <label><input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}</label>&nbsp;&nbsp;
                   9753: <label><input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label></span><br />
                   9754: <input type="submit" name="decompress" value="$lt{'extr'}" />
                   9755: </form>
                   9756: $noextract
                   9757: </div>
                   9758: END
                   9759:     return $output;
                   9760: }
                   9761: 
                   9762: sub decompress_uploaded_file {
                   9763:     my ($file,$dir) = @_;
                   9764:     &Apache::lonnet::appenv({'cgi.file' => $file});
                   9765:     &Apache::lonnet::appenv({'cgi.dir' => $dir});
                   9766:     my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
                   9767:     my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
                   9768:     my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
                   9769:     &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
                   9770:     my $decompressed = $env{'cgi.decompressed'};
                   9771:     &Apache::lonnet::delenv('cgi.file');
                   9772:     &Apache::lonnet::delenv('cgi.dir');
                   9773:     &Apache::lonnet::delenv('cgi.decompressed');
                   9774:     return ($decompressed,$result);
                   9775: }
                   9776: 
1.1055  ! raeburn  9777: sub process_decompression {
        !          9778:     my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
        !          9779:     my ($dir,$error,$warning,$output);
        !          9780:     if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/) {
        !          9781:         $error = &mt('File name not a supported archive file type.').
        !          9782:                  '<br />'.&mt('File name should end with one of: [_1].',
        !          9783:                               '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
        !          9784:     } else {
        !          9785:         my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
        !          9786:         if ($docuhome eq 'no_host') {
        !          9787:             $error = &mt('Could not determine home server for course.');
        !          9788:         } else {
        !          9789:             my @ids=&Apache::lonnet::current_machine_ids();
        !          9790:             my $currdir = "$dir_root/$destination";
        !          9791:             my ($currdirlistref,$currlisterror) =
        !          9792:                 &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
        !          9793:             if (grep(/^\Q$docuhome\E$/,@ids)) {
        !          9794:                 $dir = &LONCAPA::propath($docudom,$docuname).
        !          9795:                        "$dir_root/$destination";
        !          9796:             } else {
        !          9797:                 $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
        !          9798:                        "$dir_root/$docudom/$docuname/$destination";
        !          9799:                 unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
        !          9800:                     $error = &mt('Archive file not found.');
        !          9801:                 }
        !          9802:             }
        !          9803:             if ($dir eq '') {
        !          9804:                 $error = &mt('Directory containing archive file unavailable.');
        !          9805:             } elsif (!$error) {
        !          9806:                 my ($decompressed,$display) = &decompress_uploaded_file($file,$dir);
        !          9807:                 if ($decompressed eq 'ok') {
        !          9808:                     $output = &mt('Files extracted successfully from archive.').'<br />';
        !          9809:                     my ($warning,$result,@contents);
        !          9810:                     my ($newdirlistref,$newlisterror) =
        !          9811:                         &Apache::lonnet::dirlist($currdir,$docudom,
        !          9812:                                                  $docuname,1);
        !          9813:                     my (%is_dir,%changes,@newitems);
        !          9814:                     my $dirptr = 16384;
        !          9815:                     if (ref($currdirlistref) eq 'ARRAY') {
        !          9816:                         my @curritems;
        !          9817:                         foreach my $dir_line (@{$currdirlistref}) {
        !          9818:                             my ($item,$rest)=split(/\&/,$dir_line,2);
        !          9819:                             unless ($item =~ /\.+$/) {
        !          9820:                                 push(@curritems,$item);
        !          9821:                             }
        !          9822:                         }
        !          9823:                         if (ref($newdirlistref) eq 'ARRAY') {
        !          9824:                             foreach my $dir_line (@{$newdirlistref}) {
        !          9825:                                 my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,4);
        !          9826:                                 unless ($item =~ /^\.+$/) {
        !          9827:                                     if ($dirptr&$testdir) {
        !          9828:                                         $is_dir{$item} = 1;
        !          9829:                                     }
        !          9830:                                     push(@newitems,$item);
        !          9831:                                 }
        !          9832:                             }
        !          9833:                             my @diffs = &compare_arrays(\@curritems,\@newitems);
        !          9834:                             if (@diffs > 0) {
        !          9835:                                foreach my $item (@diffs) {
        !          9836:                                    $changes{$item} = 1;
        !          9837:                                }
        !          9838:                             }
        !          9839:                         }
        !          9840:                     } elsif (ref($newdirlistref) eq 'ARRAY') {
        !          9841:                         foreach my $dir_line (@{$newdirlistref}) {
        !          9842:                             my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
        !          9843:                             unless ($item =~ /\.+$/) {
        !          9844:                                 push(@newitems,$item);
        !          9845:                                 if ($dirptr&$testdir) {
        !          9846:                                     $is_dir{$item} = 1;
        !          9847:                                 }
        !          9848:                                 $changes{$item} = 1;
        !          9849:                             }
        !          9850:                         }
        !          9851:                     }
        !          9852:                     if (keys(%changes) > 0) {
        !          9853:                         foreach my $item (sort(@newitems)) {
        !          9854:                             if ($changes{$item}) {
        !          9855:                                 push(@contents,$item);
        !          9856:                             }
        !          9857:                         }
        !          9858:                     }
        !          9859:                     if (@contents > 0) {
        !          9860:                         my (%children,%parent);
        !          9861:                         my $wantform = 1;
        !          9862:                         my ($count,$datatable) = &get_extracted($docudom,$docuname,
        !          9863:                                                                 $currdir,\%is_dir,
        !          9864:                                                                 \%children,\%parent,
        !          9865:                                                                 \@contents,$wantform);
        !          9866:                         if ($datatable ne '') {
        !          9867:                             $output .= &archive_options_form('decompressed',$datatable,
        !          9868:                                                              $count,$hiddenelem);
        !          9869:                             my $startcount = 3;
        !          9870:                             $output .= &archive_javascript($startcount,$count,
        !          9871:                                                            %children);
        !          9872:                         }
        !          9873:                     } else {
        !          9874:                         $warning = &mt('No new items extracted from archive file.');
        !          9875:                     }
        !          9876:                 } else {
        !          9877:                     $output = $display;
        !          9878:                     $error = &mt('An error occurred during extraction from the archive file.');
        !          9879:                 }
        !          9880:             }
        !          9881:         }
        !          9882:     }
        !          9883:     if ($error) {
        !          9884:         $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
        !          9885:                    $error.'</p>'."\n";
        !          9886:     }
        !          9887:     if ($warning) {
        !          9888:         $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
        !          9889:     }
        !          9890:     return $output;
        !          9891: }
        !          9892: 
        !          9893: sub get_extracted {
        !          9894:     my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$wantform) = @_;
        !          9895:     my $count = 0;
        !          9896:     my $lastcontainer = 0;
        !          9897:     my $depth = 0;
        !          9898:     my $datatable;
        !          9899:     return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
        !          9900:                    (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY'));
        !          9901:     foreach my $item (@{$contents}) {
        !          9902:         $count ++;
        !          9903:         &archive_hierarchy($depth,$count,$parent,$children);
        !          9904:         if ($wantform) {
        !          9905:             $datatable .= &archive_row($is_dir->{$item},$item,
        !          9906:                                        $currdir,$depth,$count);
        !          9907:         }
        !          9908:         if ($is_dir->{$item}) {
        !          9909:             $depth ++;
        !          9910:             $lastcontainer = $count;
        !          9911:             $parent->{$depth} = $lastcontainer;
        !          9912:             $datatable .=
        !          9913:                 &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
        !          9914:                                            \$depth,\$count,\$lastcontainer,
        !          9915:                                            $children,$parent,$wantform);
        !          9916:             $depth --;
        !          9917:             $lastcontainer = $parent->{$depth};
        !          9918:         }
        !          9919:     }
        !          9920:     return ($count,$datatable);
        !          9921: }
        !          9922: 
        !          9923: sub recurse_extracted_archive {
        !          9924:     my ($currdir,$docudom,$docuname,$depth,$count,$lastcontainer,
        !          9925:         $children,$parent,$wantform) = @_;
        !          9926:     my $result='';
        !          9927:     unless ((ref($depth)) && (ref($count)) && (ref($lastcontainer)) &&
        !          9928:             (ref($children) eq 'HASH') && (ref($parent) eq 'HASH')) {
        !          9929:         return $result;
        !          9930:     }
        !          9931:     my $dirptr = 16384;
        !          9932:     my ($newdirlistref,$newlisterror) =
        !          9933:         &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
        !          9934:     if (ref($newdirlistref) eq 'ARRAY') {
        !          9935:         foreach my $dir_line (@{$newdirlistref}) {
        !          9936:             my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
        !          9937:             unless ($item =~ /^\.+$/) {
        !          9938:                 $$count ++;
        !          9939:                 &archive_hierarchy($$depth,$$count,$parent,$children);
        !          9940:                 my $is_dir;
        !          9941:                 if ($dirptr&$testdir) {
        !          9942:                     $is_dir = 1;
        !          9943:                 }
        !          9944:                 if ($wantform) {
        !          9945:                     $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
        !          9946:                 }
        !          9947:                 if ($is_dir) {
        !          9948:                     $$depth ++;
        !          9949:                     $$lastcontainer = $$count;
        !          9950:                     $parent->{$$depth} = $$lastcontainer;
        !          9951:                     $result .=
        !          9952:                         &recurse_extracted_archive("$currdir/$item",$docudom,
        !          9953:                                                    $docuname,$depth,$count,
        !          9954:                                                    $lastcontainer,$children,
        !          9955:                                                    $parent,$wantform);
        !          9956:                     $$depth --;
        !          9957:                     $$lastcontainer = $parent->{$$depth};
        !          9958:                 }
        !          9959:             }
        !          9960:         }
        !          9961:     }
        !          9962:     return $result;
        !          9963: }
        !          9964: 
        !          9965: sub archive_hierarchy {
        !          9966:     my ($depth,$count,$parent,$children) =@_;
        !          9967:     if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
        !          9968:         if (exists($parent->{$depth})) {
        !          9969:              $children->{$parent->{$depth}} .= $count.':';
        !          9970:         }
        !          9971:     }
        !          9972:     return;
        !          9973: }
        !          9974: 
        !          9975: sub archive_row {
        !          9976:     my ($is_dir,$item,$currdir,$depth,$count) = @_;
        !          9977:     my ($name) = ($item =~ m{([^/]+)$});
        !          9978:     my %choices = &Apache::lonlocal::texthash (
        !          9979:                                        'display'    => 'Add as File',
        !          9980:                                        'dependency' => 'Include as dependency',
        !          9981:                                        'discard'    => 'Discard',
        !          9982:                                       );
        !          9983:     if ($is_dir) {
        !          9984:         $choices{'display'} = &mt('Add as Folder'); 
        !          9985:     }
        !          9986:     my $output = &start_data_table_row()."\n";
        !          9987:     foreach my $action ('display','dependency','discard') {
        !          9988:         $output .= '<td><span class="LC_nobreak">'.
        !          9989:                    '<label><input type="radio" name="archive_'.$count.
        !          9990:                    '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
        !          9991:         my $text = $choices{$action};
        !          9992:         if ($is_dir) {
        !          9993:             $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
        !          9994:             if ($action eq 'display') {
        !          9995:                 $text = &mt('Add as Folder');
        !          9996:             }
        !          9997:         }
        !          9998:         $output .= ' />&nbsp;'.$choices{$action}.'</label></span></td>';
        !          9999:     }
        !          10000:     $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
        !          10001:                &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.('&nbsp;' x 2);
        !          10002:     for (my $i=0; $i<$depth; $i++) {
        !          10003:         $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
        !          10004:     }
        !          10005:     if ($is_dir) {
        !          10006:         $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" />&nbsp;'."\n".
        !          10007:                    '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
        !          10008:     } else {
        !          10009:         $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
        !          10010:     }
        !          10011:     $output .= '&nbsp;'.$name.'</td>'."\n".
        !          10012:                &end_data_table_row();
        !          10013:     return $output;
        !          10014: }
        !          10015: 
        !          10016: sub archive_options_form {
        !          10017:     my ($form,$output,$count,$hiddenelem) = @_;
        !          10018:     return '<form name="'.$form.'" method="post" action="">'."\n".
        !          10019:            '<input type="hidden" name="phase" value="decompress_cleanup" />'."\n".
        !          10020:                     '<p>'.
        !          10021:                     &mt('How should each item be incorporated in the course?').
        !          10022:                     '</p>'.
        !          10023:                     '<div class="LC_columnSection"><fieldset>'.
        !          10024:                     '<legend>'.&mt('Content actions for all').'</legend>'.
        !          10025:                     '<input type="button" value="'.&mt('Display in Contents').'" '.
        !          10026:                     'onclick="javascript:checkAll(document.'.$form.",'display'".')" />'.
        !          10027:                     '&nbsp;&nbsp;<input type="button" value="'.&mt('Include as dependency for a displayed item').'"'.
        !          10028:                     ' onclick="javascript:checkAll(document.'.$form.",'dependency'".')" />'.
        !          10029:                     '&nbsp;&nbsp;<input type="button" value="'.&mt('Discard').'"'.
        !          10030:                     ' onclick="javascript:checkAll(document.'.$form.",'discard'".')" />'.
        !          10031:                      '</fieldset></div>'.
        !          10032:            &start_data_table()."\n".
        !          10033:            $output."\n".
        !          10034:            &end_data_table()."\n".
        !          10035:            '<input type="hidden" name="archive_count" value="'.$count.'" />'.
        !          10036:            $hiddenelem.
        !          10037:            '<br /><input type="submit" name="archive_submit" value="'.&mt('Save').'" />'.
        !          10038:            '</form>';
        !          10039: }
        !          10040: 
        !          10041: sub archive_javascript {
        !          10042:     my ($startcount,$numitems,%children) = @_;
        !          10043:     my $scripttag = <<START;
        !          10044: <script type="text/javascript">
        !          10045: // <![CDATA[
        !          10046: 
        !          10047: function checkAll(form,prefix) {
        !          10048:     var idstr =  new RegExp("^archive_"+prefix+"_\\\\d+\$");
        !          10049:     for (var i=0; i < form.elements.length; i++) {
        !          10050:         var id = form.elements[i].id;
        !          10051:         if ((id != '') && (id != undefined)) {
        !          10052:             if (idstr.test(id)) {
        !          10053:                 if (form.elements[i].type == 'radio') {
        !          10054:                     form.elements[i].checked = true;
        !          10055:                 }
        !          10056:             }
        !          10057:         }
        !          10058:     }
        !          10059: }
        !          10060: 
        !          10061: function propagateCheck(form,count) {
        !          10062:     if (count > 0) {
        !          10063:         var startelement = $startcount + (count-1) * 5;
        !          10064:         for (var j=1; j<4; j++) {
        !          10065:             var item = startelement + j; 
        !          10066:             if (form.elements[item].type == 'radio') {
        !          10067:                 if (form.elements[item].checked) {
        !          10068:                     containerCheck(form,count,j);
        !          10069:                     break;
        !          10070:                 }
        !          10071:             }
        !          10072:         }
        !          10073:     }
        !          10074: }
        !          10075: 
        !          10076: numitems = $numitems
        !          10077: var parents = new Array(numitems)
        !          10078: for (var i=0; i<numitems; i++) {
        !          10079:     parents[i] = new Array
        !          10080: }
        !          10081: 
        !          10082: START
        !          10083: 
        !          10084:     foreach my $container (sort { $a <=> $b } (keys(%children))) {
        !          10085:         my @contents = split(/:/,$children{$container});
        !          10086:         for (my $i=0; $i<@contents; $i ++) {
        !          10087:             $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
        !          10088:         }
        !          10089:     }
        !          10090: 
        !          10091:     $scripttag .= <<END;
        !          10092: 
        !          10093: function containerCheck(form,count,offset) {
        !          10094:     if (count > 0) {
        !          10095:         var item = $startcount + ((count-1) * 5) + offset;
        !          10096:         form.elements[item].checked = true;
        !          10097:         if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
        !          10098:             if (parents[count].length > 0) {
        !          10099:                 for (var j=0; j<parents[count].length; j++) {
        !          10100:                     containerCheck(form,parents[count][j],offset)
        !          10101:                 }
        !          10102:             }
        !          10103:         }
        !          10104:     }
        !          10105: }
        !          10106: // ]]>
        !          10107: </script>
        !          10108: END
        !          10109:     return $scripttag;
        !          10110: }
        !          10111: 
        !          10112: sub process_extracted_files {
        !          10113:     my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
        !          10114:     my $numitems = $env{'form.archive_count'};
        !          10115:     return unless ($numitems);
        !          10116:     my @ids=&Apache::lonnet::current_machine_ids();
        !          10117:     my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
        !          10118:         %folders,%containers,%mapinner);
        !          10119:     my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
        !          10120:     if (grep(/^\Q$docuhome\E$/,@ids)) {
        !          10121:         $prefix = &LONCAPA::propath($docudom,$docuname);
        !          10122:         $pathtocheck = "$dir_root/$destination";
        !          10123:         $dir = $dir_root;
        !          10124:         $ishome = 1;
        !          10125:     } else {
        !          10126:         $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
        !          10127:         $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
        !          10128:         $dir = "$dir_root/$docudom/$docuname";    
        !          10129:     }
        !          10130:     my $currdir = "$dir_root/$destination";
        !          10131:     (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
        !          10132:     if ($env{'form.folderpath'}) {
        !          10133:         my @items = split('&',$env{'form.folderpath'});
        !          10134:         $folders{'0'} = $items[-2];
        !          10135:         $containers{'0'}='sequence';
        !          10136:     } elsif ($env{'form.pagepath'}) {
        !          10137:         my @items = split('&',$env{'form.pagepath'});
        !          10138:         $folders{'0'} = $items[-2];
        !          10139:         $containers{'0'}='page';
        !          10140:     }
        !          10141:     my @archdirs = &get_env_multiple('form.archive_directory');
        !          10142:     if ($numitems) {
        !          10143:         for (my $i=1; $i<=$numitems; $i++) {
        !          10144:             my $path = $env{'form.archive_content_'.$i};
        !          10145:             if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
        !          10146:                 my $item = $1;
        !          10147:                 $toplevelitems{$item} = $i;
        !          10148:                 if (grep(/^\Q$i\E$/,@archdirs)) {
        !          10149:                     $is_dir{$item} = 1;
        !          10150:                 }
        !          10151:             }
        !          10152:         }
        !          10153:     }
        !          10154:     my ($output,%children,%parent);
        !          10155:     if (keys(%toplevelitems) > 0) {
        !          10156:         my @contents = sort(keys(%toplevelitems));
        !          10157:         my ($count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,
        !          10158:                                            \%children,\%parent,\@contents);
        !          10159:     }
        !          10160:     my (@above,%hierarchy,%referrer,%orphaned,%todelete);
        !          10161:     foreach my $depth (sort { $a <=> $b } keys(%parent)) {
        !          10162:         push(@above,$parent{$depth}); 
        !          10163:         foreach my $item (split(/:/,$children{$parent{$depth}})) {
        !          10164:             $hierarchy{$item} = \@above;
        !          10165:         }
        !          10166:     }
        !          10167:     if ($numitems) {
        !          10168:         for (my $i=1; $i<=$numitems; $i++) {
        !          10169:             my $path = $env{'form.archive_content_'.$i};
        !          10170:             if ($path =~ /^\Q$pathtocheck\E/) {
        !          10171:                 if ($env{'form.archive_'.$i} eq 'discard') {
        !          10172:                     if ($prefix ne '' && $path ne '') {
        !          10173:                         if (-e $prefix.$path) {
        !          10174:                             $todelete{$prefix.$path} = 1;
        !          10175:                         }
        !          10176:                     }
        !          10177:                 } elsif ($env{'form.archive_'.$i} eq 'display') {
        !          10178:                     my ($title,$url,$outer);
        !          10179:                     ($title) = ($path =~ m{/([^/]+)$});
        !          10180:                     $outer = 0;
        !          10181:                     if (ref($hierarchy{$i}) eq 'ARRAY') {
        !          10182:                         if (@{$hierarchy{$i}} > 0) {
        !          10183:                             foreach my $item (reverse(@{$hierarchy{$i}})) {
        !          10184:                                 if ($env{'form.archive_'.$item} eq 'display') {
        !          10185:                                     $outer = $item;
        !          10186:                                     last;
        !          10187:                                 }
        !          10188:                             }
        !          10189:                         }
        !          10190:                     }
        !          10191:                     my ($errtext,$fatal) = 
        !          10192:                         &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
        !          10193:                                                '/'.$folders{$outer}.'.'.
        !          10194:                                                $containers{$outer});
        !          10195:                     next if ($fatal);
        !          10196:                     if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
        !          10197:                         if ($context eq 'coursedocs') {
        !          10198:                             $mapinner{$i} = time; 
        !          10199:                             $folders{$i} = 'default_'.$mapinner{$i};
        !          10200:                             $containers{$i} = 'sequence';
        !          10201:                             my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
        !          10202:                                       $folders{$i}.'.'.$containers{$i};
        !          10203:                             my $newidx = &LONCAPA::map::getresidx();
        !          10204:                             $LONCAPA::map::resources[$newidx]=
        !          10205:                                 $title.':'.$url.':false:normal:res';
        !          10206:                             push(@LONCAPA::map::order,$newidx);
        !          10207:                             my ($outtext,$errtext) =
        !          10208:                                 &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
        !          10209:                                                         $docuname.'/'.$folders{$outer}.
        !          10210:                                                         '.'.$containers{$outer},1);
        !          10211:                         }
        !          10212:                     } else {
        !          10213:                         if ($context eq 'coursedocs') {
        !          10214:                             my $newidx=&LONCAPA::map::getresidx();
        !          10215:                             my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
        !          10216:                                       $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
        !          10217:                                       $title;
        !          10218:                             if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
        !          10219:                                 mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
        !          10220:                             }
        !          10221:                             if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
        !          10222:                                 mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
        !          10223:                             }
        !          10224:                             if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
        !          10225:                                 system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
        !          10226:                             }
        !          10227:                             $LONCAPA::map::resources[$newidx]=
        !          10228:                                 $title.':'.$url.':false:normal:res';
        !          10229:                             push(@LONCAPA::map::order, $newidx);
        !          10230:                             my ($outtext,$errtext)=
        !          10231:                                 &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
        !          10232:                                                         $docuname.'/'.$folders{$outer}.
        !          10233:                                                         '.'.$containers{$outer},1);
        !          10234:                         }
        !          10235:                     }
        !          10236:                 } elsif ($env{'form.archive_'.$i} eq 'dependency') {
        !          10237:                     if (ref($hierarchy{$i}) eq 'ARRAY') {
        !          10238:                         foreach my $item (reverse(@{$hierarchy{$i}})) {
        !          10239:                             if ($env{'form.archive_'.$item} eq 'display') {
        !          10240:                                 $referrer{$i} = $item;
        !          10241:                                 last;
        !          10242:                                 #FIXME identify as dependency in db file
        !          10243:                                 #FIXME need to move item to referrer location
        !          10244:                                 #FIXME need to setup httprefs so access allowed
        !          10245:                             } elsif ($env{'form.archive_'.$item} eq 'discard') {
        !          10246:                                 $orphaned{$i} = $item;
        !          10247:                                 last;
        !          10248:                             }
        !          10249:                         }
        !          10250:                     }
        !          10251:                 }
        !          10252:             } else {
        !          10253:                 $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />'; 
        !          10254:             }
        !          10255:         }
        !          10256:         if (keys(%todelete)) {
        !          10257:             foreach my $key (keys(%todelete)) {
        !          10258:                 unlink($key);
        !          10259:                 unless ($ishome) {
        !          10260:                     #FIXME Need to notify homeserver to delete files.
        !          10261:                 }
        !          10262:             }
        !          10263:         }
        !          10264:     } else {
        !          10265:         $warning = &mt('No items found in archive.');
        !          10266:     }
        !          10267:     if ($error) {
        !          10268:         $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
        !          10269:                    $error.'</p>'."\n";
        !          10270:     }
        !          10271:     if ($warning) {
        !          10272:         $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
        !          10273:     }
        !          10274:     return $output;
        !          10275: }
        !          10276: 
1.41      ng       10277: =pod
1.45      matthew  10278: 
1.1015    raeburn  10279: =item * &get_turnedin_filepath()
                   10280: 
                   10281: Determines path in a user's portfolio file for storage of files uploaded
                   10282: to a specific essayresponse or dropbox item.
                   10283: 
                   10284: Inputs: 3 required + 1 optional.
                   10285: $symb is symb for resource, $uname and $udom are for current user (required).
                   10286: $caller is optional (can be "submission", if routine is called when storing
                   10287: an upoaded file when "Submit Answer" button was pressed).
                   10288: 
                   10289: Returns array containing $path and $multiresp. 
                   10290: $path is path in portfolio.  $multiresp is 1 if this resource contains more
                   10291: than one file upload item.  Callers of routine should append partid as a 
                   10292: subdirectory to $path in cases where $multiresp is 1.
                   10293: 
                   10294: Called by: homework/essayresponse.pm and homework/structuretags.pm
                   10295: 
                   10296: =cut
                   10297: 
                   10298: sub get_turnedin_filepath {
                   10299:     my ($symb,$uname,$udom,$caller) = @_;
                   10300:     my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
                   10301:     my $turnindir;
                   10302:     my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
                   10303:     $turnindir = $userhash{'turnindir'};
                   10304:     my ($path,$multiresp);
                   10305:     if ($turnindir eq '') {
                   10306:         if ($caller eq 'submission') {
                   10307:             $turnindir = &mt('turned in');
                   10308:             $turnindir =~ s/\W+/_/g;
                   10309:             my %newhash = (
                   10310:                             'turnindir' => $turnindir,
                   10311:                           );
                   10312:             &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
                   10313:         }
                   10314:     }
                   10315:     if ($turnindir ne '') {
                   10316:         $path = '/'.$turnindir.'/';
                   10317:         my ($multipart,$turnin,@pathitems);
                   10318:         my $navmap = Apache::lonnavmaps::navmap->new();
                   10319:         if (defined($navmap)) {
                   10320:             my $mapres = $navmap->getResourceByUrl($map);
                   10321:             if (ref($mapres)) {
                   10322:                 my $pcslist = $mapres->map_hierarchy();
                   10323:                 if ($pcslist ne '') {
                   10324:                     foreach my $pc (split(/,/,$pcslist)) {
                   10325:                         my $res = $navmap->getByMapPc($pc);
                   10326:                         if (ref($res)) {
                   10327:                             my $title = $res->compTitle();
                   10328:                             $title =~ s/\W+/_/g;
                   10329:                             if ($title ne '') {
                   10330:                                 push(@pathitems,$title);
                   10331:                             }
                   10332:                         }
                   10333:                     }
                   10334:                 }
                   10335:                 my $maptitle = $mapres->compTitle();
                   10336:                 $maptitle =~ s/\W+/_/g;
                   10337:                 if ($maptitle ne '') {
                   10338:                     push(@pathitems,$maptitle);
                   10339:                 }
                   10340:                 unless ($env{'request.state'} eq 'construct') {
                   10341:                     my $res = $navmap->getBySymb($symb);
                   10342:                     if (ref($res)) {
                   10343:                         my $partlist = $res->parts();
                   10344:                         my $totaluploads = 0;
                   10345:                         if (ref($partlist) eq 'ARRAY') {
                   10346:                             foreach my $part (@{$partlist}) {
                   10347:                                 my @types = $res->responseType($part);
                   10348:                                 my @ids = $res->responseIds($part);
                   10349:                                 for (my $i=0; $i < scalar(@ids); $i++) {
                   10350:                                     if ($types[$i] eq 'essay') {
                   10351:                                         my $partid = $part.'_'.$ids[$i];
                   10352:                                         if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
                   10353:                                             $totaluploads ++;
                   10354:                                         }
                   10355:                                     }
                   10356:                                 }
                   10357:                             }
                   10358:                             if ($totaluploads > 1) {
                   10359:                                 $multiresp = 1;
                   10360:                             }
                   10361:                         }
                   10362:                     }
                   10363:                 }
                   10364:             } else {
                   10365:                 return;
                   10366:             }
                   10367:         } else {
                   10368:             return;
                   10369:         }
                   10370:         my $restitle=&Apache::lonnet::gettitle($symb);
                   10371:         $restitle =~ s/\W+/_/g;
                   10372:         if ($restitle eq '') {
                   10373:             $restitle = ($resurl =~ m{/[^/]+$});
                   10374:             if ($restitle eq '') {
                   10375:                 $restitle = time;
                   10376:             }
                   10377:         }
                   10378:         push(@pathitems,$restitle);
                   10379:         $path .= join('/',@pathitems);
                   10380:     }
                   10381:     return ($path,$multiresp);
                   10382: }
                   10383: 
                   10384: =pod
                   10385: 
1.464     albertel 10386: =back
1.41      ng       10387: 
1.112     bowersj2 10388: =head1 CSV Upload/Handling functions
1.38      albertel 10389: 
1.41      ng       10390: =over 4
                   10391: 
1.648     raeburn  10392: =item * &upfile_store($r)
1.41      ng       10393: 
                   10394: Store uploaded file, $r should be the HTTP Request object,
1.258     albertel 10395: needs $env{'form.upfile'}
1.41      ng       10396: returns $datatoken to be put into hidden field
                   10397: 
                   10398: =cut
1.31      albertel 10399: 
                   10400: sub upfile_store {
                   10401:     my $r=shift;
1.258     albertel 10402:     $env{'form.upfile'}=~s/\r/\n/gs;
                   10403:     $env{'form.upfile'}=~s/\f/\n/gs;
                   10404:     $env{'form.upfile'}=~s/\n+/\n/gs;
                   10405:     $env{'form.upfile'}=~s/\n+$//gs;
1.31      albertel 10406: 
1.258     albertel 10407:     my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
                   10408: 	'_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31      albertel 10409:     {
1.158     raeburn  10410:         my $datafile = $r->dir_config('lonDaemons').
                   10411:                            '/tmp/'.$datatoken.'.tmp';
                   10412:         if ( open(my $fh,">$datafile") ) {
1.258     albertel 10413:             print $fh $env{'form.upfile'};
1.158     raeburn  10414:             close($fh);
                   10415:         }
1.31      albertel 10416:     }
                   10417:     return $datatoken;
                   10418: }
                   10419: 
1.56      matthew  10420: =pod
                   10421: 
1.648     raeburn  10422: =item * &load_tmp_file($r)
1.41      ng       10423: 
                   10424: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258     albertel 10425: needs $env{'form.datatoken'},
                   10426: sets $env{'form.upfile'} to the contents of the file
1.41      ng       10427: 
                   10428: =cut
1.31      albertel 10429: 
                   10430: sub load_tmp_file {
                   10431:     my $r=shift;
                   10432:     my @studentdata=();
                   10433:     {
1.158     raeburn  10434:         my $studentfile = $r->dir_config('lonDaemons').
1.258     albertel 10435:                               '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158     raeburn  10436:         if ( open(my $fh,"<$studentfile") ) {
                   10437:             @studentdata=<$fh>;
                   10438:             close($fh);
                   10439:         }
1.31      albertel 10440:     }
1.258     albertel 10441:     $env{'form.upfile'}=join('',@studentdata);
1.31      albertel 10442: }
                   10443: 
1.56      matthew  10444: =pod
                   10445: 
1.648     raeburn  10446: =item * &upfile_record_sep()
1.41      ng       10447: 
                   10448: Separate uploaded file into records
                   10449: returns array of records,
1.258     albertel 10450: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41      ng       10451: 
                   10452: =cut
1.31      albertel 10453: 
                   10454: sub upfile_record_sep {
1.258     albertel 10455:     if ($env{'form.upfiletype'} eq 'xml') {
1.31      albertel 10456:     } else {
1.248     albertel 10457: 	my @records;
1.258     albertel 10458: 	foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248     albertel 10459: 	    if ($line=~/^\s*$/) { next; }
                   10460: 	    push(@records,$line);
                   10461: 	}
                   10462: 	return @records;
1.31      albertel 10463:     }
                   10464: }
                   10465: 
1.56      matthew  10466: =pod
                   10467: 
1.648     raeburn  10468: =item * &record_sep($record)
1.41      ng       10469: 
1.258     albertel 10470: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41      ng       10471: 
                   10472: =cut
                   10473: 
1.263     www      10474: sub takeleft {
                   10475:     my $index=shift;
                   10476:     return substr('0000'.$index,-4,4);
                   10477: }
                   10478: 
1.31      albertel 10479: sub record_sep {
                   10480:     my $record=shift;
                   10481:     my %components=();
1.258     albertel 10482:     if ($env{'form.upfiletype'} eq 'xml') {
                   10483:     } elsif ($env{'form.upfiletype'} eq 'space') {
1.31      albertel 10484:         my $i=0;
1.356     albertel 10485:         foreach my $field (split(/\s+/,$record)) {
1.31      albertel 10486:             $field=~s/^(\"|\')//;
                   10487:             $field=~s/(\"|\')$//;
1.263     www      10488:             $components{&takeleft($i)}=$field;
1.31      albertel 10489:             $i++;
                   10490:         }
1.258     albertel 10491:     } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31      albertel 10492:         my $i=0;
1.356     albertel 10493:         foreach my $field (split(/\t/,$record)) {
1.31      albertel 10494:             $field=~s/^(\"|\')//;
                   10495:             $field=~s/(\"|\')$//;
1.263     www      10496:             $components{&takeleft($i)}=$field;
1.31      albertel 10497:             $i++;
                   10498:         }
                   10499:     } else {
1.561     www      10500:         my $separator=',';
1.480     banghart 10501:         if ($env{'form.upfiletype'} eq 'semisv') {
1.561     www      10502:             $separator=';';
1.480     banghart 10503:         }
1.31      albertel 10504:         my $i=0;
1.561     www      10505: # the character we are looking for to indicate the end of a quote or a record 
                   10506:         my $looking_for=$separator;
                   10507: # do not add the characters to the fields
                   10508:         my $ignore=0;
                   10509: # we just encountered a separator (or the beginning of the record)
                   10510:         my $just_found_separator=1;
                   10511: # store the field we are working on here
                   10512:         my $field='';
                   10513: # work our way through all characters in record
                   10514:         foreach my $character ($record=~/(.)/g) {
                   10515:             if ($character eq $looking_for) {
                   10516:                if ($character ne $separator) {
                   10517: # Found the end of a quote, again looking for separator
                   10518:                   $looking_for=$separator;
                   10519:                   $ignore=1;
                   10520:                } else {
                   10521: # Found a separator, store away what we got
                   10522:                   $components{&takeleft($i)}=$field;
                   10523: 	          $i++;
                   10524:                   $just_found_separator=1;
                   10525:                   $ignore=0;
                   10526:                   $field='';
                   10527:                }
                   10528:                next;
                   10529:             }
                   10530: # single or double quotation marks after a separator indicate beginning of a quote
                   10531: # we are now looking for the end of the quote and need to ignore separators
                   10532:             if ((($character eq '"') || ($character eq "'")) && ($just_found_separator))  {
                   10533:                $looking_for=$character;
                   10534:                next;
                   10535:             }
                   10536: # ignore would be true after we reached the end of a quote
                   10537:             if ($ignore) { next; }
                   10538:             if (($just_found_separator) && ($character=~/\s/)) { next; }
                   10539:             $field.=$character;
                   10540:             $just_found_separator=0; 
1.31      albertel 10541:         }
1.561     www      10542: # catch the very last entry, since we never encountered the separator
                   10543:         $components{&takeleft($i)}=$field;
1.31      albertel 10544:     }
                   10545:     return %components;
                   10546: }
                   10547: 
1.144     matthew  10548: ######################################################
                   10549: ######################################################
                   10550: 
1.56      matthew  10551: =pod
                   10552: 
1.648     raeburn  10553: =item * &upfile_select_html()
1.41      ng       10554: 
1.144     matthew  10555: Return HTML code to select a file from the users machine and specify 
                   10556: the file type.
1.41      ng       10557: 
                   10558: =cut
                   10559: 
1.144     matthew  10560: ######################################################
                   10561: ######################################################
1.31      albertel 10562: sub upfile_select_html {
1.144     matthew  10563:     my %Types = (
                   10564:                  csv   => &mt('CSV (comma separated values, spreadsheet)'),
1.480     banghart 10565:                  semisv => &mt('Semicolon separated values'),
1.144     matthew  10566:                  space => &mt('Space separated'),
                   10567:                  tab   => &mt('Tabulator separated'),
                   10568: #                 xml   => &mt('HTML/XML'),
                   10569:                  );
                   10570:     my $Str = '<input type="file" name="upfile" size="50" />'.
1.727     riegler  10571:         '<br />'.&mt('Type').': <select name="upfiletype">';
1.144     matthew  10572:     foreach my $type (sort(keys(%Types))) {
                   10573:         $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
                   10574:     }
                   10575:     $Str .= "</select>\n";
                   10576:     return $Str;
1.31      albertel 10577: }
                   10578: 
1.301     albertel 10579: sub get_samples {
                   10580:     my ($records,$toget) = @_;
                   10581:     my @samples=({});
                   10582:     my $got=0;
                   10583:     foreach my $rec (@$records) {
                   10584: 	my %temp = &record_sep($rec);
                   10585: 	if (! grep(/\S/, values(%temp))) { next; }
                   10586: 	if (%temp) {
                   10587: 	    $samples[$got]=\%temp;
                   10588: 	    $got++;
                   10589: 	    if ($got == $toget) { last; }
                   10590: 	}
                   10591:     }
                   10592:     return \@samples;
                   10593: }
                   10594: 
1.144     matthew  10595: ######################################################
                   10596: ######################################################
                   10597: 
1.56      matthew  10598: =pod
                   10599: 
1.648     raeburn  10600: =item * &csv_print_samples($r,$records)
1.41      ng       10601: 
                   10602: Prints a table of sample values from each column uploaded $r is an
                   10603: Apache Request ref, $records is an arrayref from
                   10604: &Apache::loncommon::upfile_record_sep
                   10605: 
                   10606: =cut
                   10607: 
1.144     matthew  10608: ######################################################
                   10609: ######################################################
1.31      albertel 10610: sub csv_print_samples {
                   10611:     my ($r,$records) = @_;
1.662     bisitz   10612:     my $samples = &get_samples($records,5);
1.301     albertel 10613: 
1.594     raeburn  10614:     $r->print(&mt('Samples').'<br />'.&start_data_table().
                   10615:               &start_data_table_header_row());
1.356     albertel 10616:     foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) { 
1.845     bisitz   10617:         $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594     raeburn  10618:     $r->print(&end_data_table_header_row());
1.301     albertel 10619:     foreach my $hash (@$samples) {
1.594     raeburn  10620: 	$r->print(&start_data_table_row());
1.356     albertel 10621: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31      albertel 10622: 	    $r->print('<td>');
1.356     albertel 10623: 	    if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31      albertel 10624: 	    $r->print('</td>');
                   10625: 	}
1.594     raeburn  10626: 	$r->print(&end_data_table_row());
1.31      albertel 10627:     }
1.594     raeburn  10628:     $r->print(&end_data_table().'<br />'."\n");
1.31      albertel 10629: }
                   10630: 
1.144     matthew  10631: ######################################################
                   10632: ######################################################
                   10633: 
1.56      matthew  10634: =pod
                   10635: 
1.648     raeburn  10636: =item * &csv_print_select_table($r,$records,$d)
1.41      ng       10637: 
                   10638: Prints a table to create associations between values and table columns.
1.144     matthew  10639: 
1.41      ng       10640: $r is an Apache Request ref,
                   10641: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174     matthew  10642: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41      ng       10643: 
                   10644: =cut
                   10645: 
1.144     matthew  10646: ######################################################
                   10647: ######################################################
1.31      albertel 10648: sub csv_print_select_table {
                   10649:     my ($r,$records,$d) = @_;
1.301     albertel 10650:     my $i=0;
                   10651:     my $samples = &get_samples($records,1);
1.144     matthew  10652:     $r->print(&mt('Associate columns with student attributes.')."\n".
1.594     raeburn  10653: 	      &start_data_table().&start_data_table_header_row().
1.144     matthew  10654:               '<th>'.&mt('Attribute').'</th>'.
1.594     raeburn  10655:               '<th>'.&mt('Column').'</th>'.
                   10656:               &end_data_table_header_row()."\n");
1.356     albertel 10657:     foreach my $array_ref (@$d) {
                   10658: 	my ($value,$display,$defaultcol)=@{ $array_ref };
1.729     raeburn  10659: 	$r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31      albertel 10660: 
1.875     bisitz   10661: 	$r->print('<td><select name="f'.$i.'"'.
1.32      matthew  10662: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.31      albertel 10663: 	$r->print('<option value="none"></option>');
1.356     albertel 10664: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
                   10665: 	    $r->print('<option value="'.$sample.'"'.
                   10666:                       ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662     bisitz   10667:                       '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31      albertel 10668: 	}
1.594     raeburn  10669: 	$r->print('</select></td>'.&end_data_table_row()."\n");
1.31      albertel 10670: 	$i++;
                   10671:     }
1.594     raeburn  10672:     $r->print(&end_data_table());
1.31      albertel 10673:     $i--;
                   10674:     return $i;
                   10675: }
1.56      matthew  10676: 
1.144     matthew  10677: ######################################################
                   10678: ######################################################
                   10679: 
1.56      matthew  10680: =pod
1.31      albertel 10681: 
1.648     raeburn  10682: =item * &csv_samples_select_table($r,$records,$d)
1.41      ng       10683: 
                   10684: Prints a table of sample values from the upload and can make associate samples to internal names.
                   10685: 
                   10686: $r is an Apache Request ref,
                   10687: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
                   10688: $d is an array of 2 element arrays (internal name, displayed name)
                   10689: 
                   10690: =cut
                   10691: 
1.144     matthew  10692: ######################################################
                   10693: ######################################################
1.31      albertel 10694: sub csv_samples_select_table {
                   10695:     my ($r,$records,$d) = @_;
                   10696:     my $i=0;
1.144     matthew  10697:     #
1.662     bisitz   10698:     my $max_samples = 5;
                   10699:     my $samples = &get_samples($records,$max_samples);
1.594     raeburn  10700:     $r->print(&start_data_table().
                   10701:               &start_data_table_header_row().'<th>'.
                   10702:               &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
                   10703:               &end_data_table_header_row());
1.301     albertel 10704: 
                   10705:     foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594     raeburn  10706: 	$r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32      matthew  10707: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.301     albertel 10708: 	foreach my $option (@$d) {
                   10709: 	    my ($value,$display,$defaultcol)=@{ $option };
1.174     matthew  10710: 	    $r->print('<option value="'.$value.'"'.
1.253     albertel 10711:                       ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174     matthew  10712:                       $display.'</option>');
1.31      albertel 10713: 	}
                   10714: 	$r->print('</select></td><td>');
1.662     bisitz   10715: 	foreach my $line (0..($max_samples-1)) {
1.301     albertel 10716: 	    if (defined($samples->[$line]{$key})) { 
                   10717: 		$r->print($samples->[$line]{$key}."<br />\n"); 
                   10718: 	    }
                   10719: 	}
1.594     raeburn  10720: 	$r->print('</td>'.&end_data_table_row());
1.31      albertel 10721: 	$i++;
                   10722:     }
1.594     raeburn  10723:     $r->print(&end_data_table());
1.31      albertel 10724:     $i--;
                   10725:     return($i);
1.115     matthew  10726: }
                   10727: 
1.144     matthew  10728: ######################################################
                   10729: ######################################################
                   10730: 
1.115     matthew  10731: =pod
                   10732: 
1.648     raeburn  10733: =item * &clean_excel_name($name)
1.115     matthew  10734: 
                   10735: Returns a replacement for $name which does not contain any illegal characters.
                   10736: 
                   10737: =cut
                   10738: 
1.144     matthew  10739: ######################################################
                   10740: ######################################################
1.115     matthew  10741: sub clean_excel_name {
                   10742:     my ($name) = @_;
                   10743:     $name =~ s/[:\*\?\/\\]//g;
                   10744:     if (length($name) > 31) {
                   10745:         $name = substr($name,0,31);
                   10746:     }
                   10747:     return $name;
1.25      albertel 10748: }
1.84      albertel 10749: 
1.85      albertel 10750: =pod
                   10751: 
1.648     raeburn  10752: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85      albertel 10753: 
                   10754: Returns either 1 or undef
                   10755: 
                   10756: 1 if the part is to be hidden, undef if it is to be shown
                   10757: 
                   10758: Arguments are:
                   10759: 
                   10760: $id the id of the part to be checked
                   10761: $symb, optional the symb of the resource to check
                   10762: $udom, optional the domain of the user to check for
                   10763: $uname, optional the username of the user to check for
                   10764: 
                   10765: =cut
1.84      albertel 10766: 
                   10767: sub check_if_partid_hidden {
                   10768:     my ($id,$symb,$udom,$uname) = @_;
1.133     albertel 10769:     my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84      albertel 10770: 					 $symb,$udom,$uname);
1.141     albertel 10771:     my $truth=1;
                   10772:     #if the string starts with !, then the list is the list to show not hide
                   10773:     if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84      albertel 10774:     my @hiddenlist=split(/,/,$hiddenparts);
                   10775:     foreach my $checkid (@hiddenlist) {
1.141     albertel 10776: 	if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84      albertel 10777:     }
1.141     albertel 10778:     return !$truth;
1.84      albertel 10779: }
1.127     matthew  10780: 
1.138     matthew  10781: 
                   10782: ############################################################
                   10783: ############################################################
                   10784: 
                   10785: =pod
                   10786: 
1.157     matthew  10787: =back 
                   10788: 
1.138     matthew  10789: =head1 cgi-bin script and graphing routines
                   10790: 
1.157     matthew  10791: =over 4
                   10792: 
1.648     raeburn  10793: =item * &get_cgi_id()
1.138     matthew  10794: 
                   10795: Inputs: none
                   10796: 
                   10797: Returns an id which can be used to pass environment variables
                   10798: to various cgi-bin scripts.  These environment variables will
                   10799: be removed from the users environment after a given time by
                   10800: the routine &Apache::lonnet::transfer_profile_to_env.
                   10801: 
                   10802: =cut
                   10803: 
                   10804: ############################################################
                   10805: ############################################################
1.152     albertel 10806: my $uniq=0;
1.136     matthew  10807: sub get_cgi_id {
1.154     albertel 10808:     $uniq=($uniq+1)%100000;
1.280     albertel 10809:     return (time.'_'.$$.'_'.$uniq);
1.136     matthew  10810: }
                   10811: 
1.127     matthew  10812: ############################################################
                   10813: ############################################################
                   10814: 
                   10815: =pod
                   10816: 
1.648     raeburn  10817: =item * &DrawBarGraph()
1.127     matthew  10818: 
1.138     matthew  10819: Facilitates the plotting of data in a (stacked) bar graph.
                   10820: Puts plot definition data into the users environment in order for 
                   10821: graph.png to plot it.  Returns an <img> tag for the plot.
                   10822: The bars on the plot are labeled '1','2',...,'n'.
                   10823: 
                   10824: Inputs:
                   10825: 
                   10826: =over 4
                   10827: 
                   10828: =item $Title: string, the title of the plot
                   10829: 
                   10830: =item $xlabel: string, text describing the X-axis of the plot
                   10831: 
                   10832: =item $ylabel: string, text describing the Y-axis of the plot
                   10833: 
                   10834: =item $Max: scalar, the maximum Y value to use in the plot
                   10835: If $Max is < any data point, the graph will not be rendered.
                   10836: 
1.140     matthew  10837: =item $colors: array ref holding the colors to be used for the data sets when
1.138     matthew  10838: they are plotted.  If undefined, default values will be used.
                   10839: 
1.178     matthew  10840: =item $labels: array ref holding the labels to use on the x-axis for the bars.
                   10841: 
1.138     matthew  10842: =item @Values: An array of array references.  Each array reference holds data
                   10843: to be plotted in a stacked bar chart.
                   10844: 
1.239     matthew  10845: =item If the final element of @Values is a hash reference the key/value
                   10846: pairs will be added to the graph definition.
                   10847: 
1.138     matthew  10848: =back
                   10849: 
                   10850: Returns:
                   10851: 
                   10852: An <img> tag which references graph.png and the appropriate identifying
                   10853: information for the plot.
                   10854: 
1.127     matthew  10855: =cut
                   10856: 
                   10857: ############################################################
                   10858: ############################################################
1.134     matthew  10859: sub DrawBarGraph {
1.178     matthew  10860:     my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134     matthew  10861:     #
                   10862:     if (! defined($colors)) {
                   10863:         $colors = ['#33ff00', 
                   10864:                   '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
                   10865:                   '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
                   10866:                   ]; 
                   10867:     }
1.228     matthew  10868:     my $extra_settings = {};
                   10869:     if (ref($Values[-1]) eq 'HASH') {
                   10870:         $extra_settings = pop(@Values);
                   10871:     }
1.127     matthew  10872:     #
1.136     matthew  10873:     my $identifier = &get_cgi_id();
                   10874:     my $id = 'cgi.'.$identifier;        
1.129     matthew  10875:     if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127     matthew  10876:         return '';
                   10877:     }
1.225     matthew  10878:     #
                   10879:     my @Labels;
                   10880:     if (defined($labels)) {
                   10881:         @Labels = @$labels;
                   10882:     } else {
                   10883:         for (my $i=0;$i<@{$Values[0]};$i++) {
                   10884:             push (@Labels,$i+1);
                   10885:         }
                   10886:     }
                   10887:     #
1.129     matthew  10888:     my $NumBars = scalar(@{$Values[0]});
1.225     matthew  10889:     if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129     matthew  10890:     my %ValuesHash;
                   10891:     my $NumSets=1;
                   10892:     foreach my $array (@Values) {
                   10893:         next if (! ref($array));
1.136     matthew  10894:         $ValuesHash{$id.'.data.'.$NumSets++} = 
1.132     matthew  10895:             join(',',@$array);
1.129     matthew  10896:     }
1.127     matthew  10897:     #
1.136     matthew  10898:     my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225     matthew  10899:     if ($NumBars < 3) {
                   10900:         $width = 120+$NumBars*32;
1.220     matthew  10901:         $xskip = 1;
1.225     matthew  10902:         $bar_width = 30;
                   10903:     } elsif ($NumBars < 5) {
                   10904:         $width = 120+$NumBars*20;
                   10905:         $xskip = 1;
                   10906:         $bar_width = 20;
1.220     matthew  10907:     } elsif ($NumBars < 10) {
1.136     matthew  10908:         $width = 120+$NumBars*15;
                   10909:         $xskip = 1;
                   10910:         $bar_width = 15;
                   10911:     } elsif ($NumBars <= 25) {
                   10912:         $width = 120+$NumBars*11;
                   10913:         $xskip = 5;
                   10914:         $bar_width = 8;
                   10915:     } elsif ($NumBars <= 50) {
                   10916:         $width = 120+$NumBars*8;
                   10917:         $xskip = 5;
                   10918:         $bar_width = 4;
                   10919:     } else {
                   10920:         $width = 120+$NumBars*8;
                   10921:         $xskip = 5;
                   10922:         $bar_width = 4;
                   10923:     }
                   10924:     #
1.137     matthew  10925:     $Max = 1 if ($Max < 1);
                   10926:     if ( int($Max) < $Max ) {
                   10927:         $Max++;
                   10928:         $Max = int($Max);
                   10929:     }
1.127     matthew  10930:     $Title  = '' if (! defined($Title));
                   10931:     $xlabel = '' if (! defined($xlabel));
                   10932:     $ylabel = '' if (! defined($ylabel));
1.369     www      10933:     $ValuesHash{$id.'.title'}    = &escape($Title);
                   10934:     $ValuesHash{$id.'.xlabel'}   = &escape($xlabel);
                   10935:     $ValuesHash{$id.'.ylabel'}   = &escape($ylabel);
1.137     matthew  10936:     $ValuesHash{$id.'.y_max_value'} = $Max;
1.136     matthew  10937:     $ValuesHash{$id.'.NumBars'}  = $NumBars;
                   10938:     $ValuesHash{$id.'.NumSets'}  = $NumSets;
                   10939:     $ValuesHash{$id.'.PlotType'} = 'bar';
                   10940:     $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   10941:     $ValuesHash{$id.'.height'}   = $height;
                   10942:     $ValuesHash{$id.'.width'}    = $width;
                   10943:     $ValuesHash{$id.'.xskip'}    = $xskip;
                   10944:     $ValuesHash{$id.'.bar_width'} = $bar_width;
                   10945:     $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127     matthew  10946:     #
1.228     matthew  10947:     # Deal with other parameters
                   10948:     while (my ($key,$value) = each(%$extra_settings)) {
                   10949:         $ValuesHash{$id.'.'.$key} = $value;
                   10950:     }
                   10951:     #
1.646     raeburn  10952:     &Apache::lonnet::appenv(\%ValuesHash);
1.137     matthew  10953:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   10954: }
                   10955: 
                   10956: ############################################################
                   10957: ############################################################
                   10958: 
                   10959: =pod
                   10960: 
1.648     raeburn  10961: =item * &DrawXYGraph()
1.137     matthew  10962: 
1.138     matthew  10963: Facilitates the plotting of data in an XY graph.
                   10964: Puts plot definition data into the users environment in order for 
                   10965: graph.png to plot it.  Returns an <img> tag for the plot.
                   10966: 
                   10967: Inputs:
                   10968: 
                   10969: =over 4
                   10970: 
                   10971: =item $Title: string, the title of the plot
                   10972: 
                   10973: =item $xlabel: string, text describing the X-axis of the plot
                   10974: 
                   10975: =item $ylabel: string, text describing the Y-axis of the plot
                   10976: 
                   10977: =item $Max: scalar, the maximum Y value to use in the plot
                   10978: If $Max is < any data point, the graph will not be rendered.
                   10979: 
                   10980: =item $colors: Array ref containing the hex color codes for the data to be 
                   10981: plotted in.  If undefined, default values will be used.
                   10982: 
                   10983: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   10984: 
                   10985: =item $Ydata: Array ref containing Array refs.  
1.185     www      10986: Each of the contained arrays will be plotted as a separate curve.
1.138     matthew  10987: 
                   10988: =item %Values: hash indicating or overriding any default values which are 
                   10989: passed to graph.png.  
                   10990: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   10991: 
                   10992: =back
                   10993: 
                   10994: Returns:
                   10995: 
                   10996: An <img> tag which references graph.png and the appropriate identifying
                   10997: information for the plot.
                   10998: 
1.137     matthew  10999: =cut
                   11000: 
                   11001: ############################################################
                   11002: ############################################################
                   11003: sub DrawXYGraph {
                   11004:     my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
                   11005:     #
                   11006:     # Create the identifier for the graph
                   11007:     my $identifier = &get_cgi_id();
                   11008:     my $id = 'cgi.'.$identifier;
                   11009:     #
                   11010:     $Title  = '' if (! defined($Title));
                   11011:     $xlabel = '' if (! defined($xlabel));
                   11012:     $ylabel = '' if (! defined($ylabel));
                   11013:     my %ValuesHash = 
                   11014:         (
1.369     www      11015:          $id.'.title'  => &escape($Title),
                   11016:          $id.'.xlabel' => &escape($xlabel),
                   11017:          $id.'.ylabel' => &escape($ylabel),
1.137     matthew  11018:          $id.'.y_max_value'=> $Max,
                   11019:          $id.'.labels'     => join(',',@$Xlabels),
                   11020:          $id.'.PlotType'   => 'XY',
                   11021:          );
                   11022:     #
                   11023:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   11024:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   11025:     }
                   11026:     #
                   11027:     if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
                   11028:         return '';
                   11029:     }
                   11030:     my $NumSets=1;
1.138     matthew  11031:     foreach my $array (@{$Ydata}){
1.137     matthew  11032:         next if (! ref($array));
                   11033:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
                   11034:     }
1.138     matthew  11035:     $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137     matthew  11036:     #
                   11037:     # Deal with other parameters
                   11038:     while (my ($key,$value) = each(%Values)) {
                   11039:         $ValuesHash{$id.'.'.$key} = $value;
1.127     matthew  11040:     }
                   11041:     #
1.646     raeburn  11042:     &Apache::lonnet::appenv(\%ValuesHash);
1.136     matthew  11043:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   11044: }
                   11045: 
                   11046: ############################################################
                   11047: ############################################################
                   11048: 
                   11049: =pod
                   11050: 
1.648     raeburn  11051: =item * &DrawXYYGraph()
1.138     matthew  11052: 
                   11053: Facilitates the plotting of data in an XY graph with two Y axes.
                   11054: Puts plot definition data into the users environment in order for 
                   11055: graph.png to plot it.  Returns an <img> tag for the plot.
                   11056: 
                   11057: Inputs:
                   11058: 
                   11059: =over 4
                   11060: 
                   11061: =item $Title: string, the title of the plot
                   11062: 
                   11063: =item $xlabel: string, text describing the X-axis of the plot
                   11064: 
                   11065: =item $ylabel: string, text describing the Y-axis of the plot
                   11066: 
                   11067: =item $colors: Array ref containing the hex color codes for the data to be 
                   11068: plotted in.  If undefined, default values will be used.
                   11069: 
                   11070: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   11071: 
                   11072: =item $Ydata1: The first data set
                   11073: 
                   11074: =item $Min1: The minimum value of the left Y-axis
                   11075: 
                   11076: =item $Max1: The maximum value of the left Y-axis
                   11077: 
                   11078: =item $Ydata2: The second data set
                   11079: 
                   11080: =item $Min2: The minimum value of the right Y-axis
                   11081: 
                   11082: =item $Max2: The maximum value of the left Y-axis
                   11083: 
                   11084: =item %Values: hash indicating or overriding any default values which are 
                   11085: passed to graph.png.  
                   11086: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   11087: 
                   11088: =back
                   11089: 
                   11090: Returns:
                   11091: 
                   11092: An <img> tag which references graph.png and the appropriate identifying
                   11093: information for the plot.
1.136     matthew  11094: 
                   11095: =cut
                   11096: 
                   11097: ############################################################
                   11098: ############################################################
1.137     matthew  11099: sub DrawXYYGraph {
                   11100:     my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
                   11101:                                         $Ydata2,$Min2,$Max2,%Values)=@_;
1.136     matthew  11102:     #
                   11103:     # Create the identifier for the graph
                   11104:     my $identifier = &get_cgi_id();
                   11105:     my $id = 'cgi.'.$identifier;
                   11106:     #
                   11107:     $Title  = '' if (! defined($Title));
                   11108:     $xlabel = '' if (! defined($xlabel));
                   11109:     $ylabel = '' if (! defined($ylabel));
                   11110:     my %ValuesHash = 
                   11111:         (
1.369     www      11112:          $id.'.title'  => &escape($Title),
                   11113:          $id.'.xlabel' => &escape($xlabel),
                   11114:          $id.'.ylabel' => &escape($ylabel),
1.136     matthew  11115:          $id.'.labels' => join(',',@$Xlabels),
                   11116:          $id.'.PlotType' => 'XY',
                   11117:          $id.'.NumSets' => 2,
1.137     matthew  11118:          $id.'.two_axes' => 1,
                   11119:          $id.'.y1_max_value' => $Max1,
                   11120:          $id.'.y1_min_value' => $Min1,
                   11121:          $id.'.y2_max_value' => $Max2,
                   11122:          $id.'.y2_min_value' => $Min2,
1.136     matthew  11123:          );
                   11124:     #
1.137     matthew  11125:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   11126:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   11127:     }
                   11128:     #
                   11129:     if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
                   11130:         ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136     matthew  11131:         return '';
                   11132:     }
                   11133:     my $NumSets=1;
1.137     matthew  11134:     foreach my $array ($Ydata1,$Ydata2){
1.136     matthew  11135:         next if (! ref($array));
                   11136:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137     matthew  11137:     }
                   11138:     #
                   11139:     # Deal with other parameters
                   11140:     while (my ($key,$value) = each(%Values)) {
                   11141:         $ValuesHash{$id.'.'.$key} = $value;
1.136     matthew  11142:     }
                   11143:     #
1.646     raeburn  11144:     &Apache::lonnet::appenv(\%ValuesHash);
1.130     albertel 11145:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139     matthew  11146: }
                   11147: 
                   11148: ############################################################
                   11149: ############################################################
                   11150: 
                   11151: =pod
                   11152: 
1.157     matthew  11153: =back 
                   11154: 
1.139     matthew  11155: =head1 Statistics helper routines?  
                   11156: 
                   11157: Bad place for them but what the hell.
                   11158: 
1.157     matthew  11159: =over 4
                   11160: 
1.648     raeburn  11161: =item * &chartlink()
1.139     matthew  11162: 
                   11163: Returns a link to the chart for a specific student.  
                   11164: 
                   11165: Inputs:
                   11166: 
                   11167: =over 4
                   11168: 
                   11169: =item $linktext: The text of the link
                   11170: 
                   11171: =item $sname: The students username
                   11172: 
                   11173: =item $sdomain: The students domain
                   11174: 
                   11175: =back
                   11176: 
1.157     matthew  11177: =back
                   11178: 
1.139     matthew  11179: =cut
                   11180: 
                   11181: ############################################################
                   11182: ############################################################
                   11183: sub chartlink {
                   11184:     my ($linktext, $sname, $sdomain) = @_;
                   11185:     my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369     www      11186:         '&amp;SelectedStudent='.&escape($sname.':'.$sdomain).
1.219     albertel 11187:         '&amp;chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139     matthew  11188:        '">'.$linktext.'</a>';
1.153     matthew  11189: }
                   11190: 
                   11191: #######################################################
                   11192: #######################################################
                   11193: 
                   11194: =pod
                   11195: 
                   11196: =head1 Course Environment Routines
1.157     matthew  11197: 
                   11198: =over 4
1.153     matthew  11199: 
1.648     raeburn  11200: =item * &restore_course_settings()
1.153     matthew  11201: 
1.648     raeburn  11202: =item * &store_course_settings()
1.153     matthew  11203: 
                   11204: Restores/Store indicated form parameters from the course environment.
                   11205: Will not overwrite existing values of the form parameters.
                   11206: 
                   11207: Inputs: 
                   11208: a scalar describing the data (e.g. 'chart', 'problem_analysis')
                   11209: 
                   11210: a hash ref describing the data to be stored.  For example:
                   11211:    
                   11212: %Save_Parameters = ('Status' => 'scalar',
                   11213:     'chartoutputmode' => 'scalar',
                   11214:     'chartoutputdata' => 'scalar',
                   11215:     'Section' => 'array',
1.373     raeburn  11216:     'Group' => 'array',
1.153     matthew  11217:     'StudentData' => 'array',
                   11218:     'Maps' => 'array');
                   11219: 
                   11220: Returns: both routines return nothing
                   11221: 
1.631     raeburn  11222: =back
                   11223: 
1.153     matthew  11224: =cut
                   11225: 
                   11226: #######################################################
                   11227: #######################################################
                   11228: sub store_course_settings {
1.496     albertel 11229:     return &store_settings($env{'request.course.id'},@_);
                   11230: }
                   11231: 
                   11232: sub store_settings {
1.153     matthew  11233:     # save to the environment
                   11234:     # appenv the same items, just to be safe
1.300     albertel 11235:     my $udom  = $env{'user.domain'};
                   11236:     my $uname = $env{'user.name'};
1.496     albertel 11237:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  11238:     my %SaveHash;
                   11239:     my %AppHash;
                   11240:     while (my ($setting,$type) = each(%$Settings)) {
1.496     albertel 11241:         my $basename = join('.','internal',$context,$prefix,$setting);
1.300     albertel 11242:         my $envname = 'environment.'.$basename;
1.258     albertel 11243:         if (exists($env{'form.'.$setting})) {
1.153     matthew  11244:             # Save this value away
                   11245:             if ($type eq 'scalar' &&
1.258     albertel 11246:                 (! exists($env{$envname}) || 
                   11247:                  $env{$envname} ne $env{'form.'.$setting})) {
                   11248:                 $SaveHash{$basename} = $env{'form.'.$setting};
                   11249:                 $AppHash{$envname}   = $env{'form.'.$setting};
1.153     matthew  11250:             } elsif ($type eq 'array') {
                   11251:                 my $stored_form;
1.258     albertel 11252:                 if (ref($env{'form.'.$setting})) {
1.153     matthew  11253:                     $stored_form = join(',',
                   11254:                                         map {
1.369     www      11255:                                             &escape($_);
1.258     albertel 11256:                                         } sort(@{$env{'form.'.$setting}}));
1.153     matthew  11257:                 } else {
                   11258:                     $stored_form = 
1.369     www      11259:                         &escape($env{'form.'.$setting});
1.153     matthew  11260:                 }
                   11261:                 # Determine if the array contents are the same.
1.258     albertel 11262:                 if ($stored_form ne $env{$envname}) {
1.153     matthew  11263:                     $SaveHash{$basename} = $stored_form;
                   11264:                     $AppHash{$envname}   = $stored_form;
                   11265:                 }
                   11266:             }
                   11267:         }
                   11268:     }
                   11269:     my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300     albertel 11270:                                           $udom,$uname);
1.153     matthew  11271:     if ($put_result !~ /^(ok|delayed)/) {
                   11272:         &Apache::lonnet::logthis('unable to save form parameters, '.
                   11273:                                  'got error:'.$put_result);
                   11274:     }
                   11275:     # Make sure these settings stick around in this session, too
1.646     raeburn  11276:     &Apache::lonnet::appenv(\%AppHash);
1.153     matthew  11277:     return;
                   11278: }
                   11279: 
                   11280: sub restore_course_settings {
1.499     albertel 11281:     return &restore_settings($env{'request.course.id'},@_);
1.496     albertel 11282: }
                   11283: 
                   11284: sub restore_settings {
                   11285:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  11286:     while (my ($setting,$type) = each(%$Settings)) {
1.258     albertel 11287:         next if (exists($env{'form.'.$setting}));
1.496     albertel 11288:         my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153     matthew  11289:             '.'.$setting;
1.258     albertel 11290:         if (exists($env{$envname})) {
1.153     matthew  11291:             if ($type eq 'scalar') {
1.258     albertel 11292:                 $env{'form.'.$setting} = $env{$envname};
1.153     matthew  11293:             } elsif ($type eq 'array') {
1.258     albertel 11294:                 $env{'form.'.$setting} = [ 
1.153     matthew  11295:                                            map { 
1.369     www      11296:                                                &unescape($_); 
1.258     albertel 11297:                                            } split(',',$env{$envname})
1.153     matthew  11298:                                            ];
                   11299:             }
                   11300:         }
                   11301:     }
1.127     matthew  11302: }
                   11303: 
1.618     raeburn  11304: #######################################################
                   11305: #######################################################
                   11306: 
                   11307: =pod
                   11308: 
                   11309: =head1 Domain E-mail Routines  
                   11310: 
                   11311: =over 4
                   11312: 
1.648     raeburn  11313: =item * &build_recipient_list()
1.618     raeburn  11314: 
1.884     raeburn  11315: Build recipient lists for five types of e-mail:
1.766     raeburn  11316: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884     raeburn  11317: (d) Help requests, (e) Course requests needing approval,  generated by
                   11318: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
                   11319: loncoursequeueadmin.pm respectively.
1.618     raeburn  11320: 
                   11321: Inputs:
1.619     raeburn  11322: defmail (scalar - email address of default recipient), 
1.618     raeburn  11323: mailing type (scalar - errormail, packagesmail, or helpdeskmail), 
1.619     raeburn  11324: defdom (domain for which to retrieve configuration settings),
                   11325: origmail (scalar - email address of recipient from loncapa.conf, 
                   11326: i.e., predates configuration by DC via domainprefs.pm 
1.618     raeburn  11327: 
1.655     raeburn  11328: Returns: comma separated list of addresses to which to send e-mail.
                   11329: 
                   11330: =back
1.618     raeburn  11331: 
                   11332: =cut
                   11333: 
                   11334: ############################################################
                   11335: ############################################################
                   11336: sub build_recipient_list {
1.619     raeburn  11337:     my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618     raeburn  11338:     my @recipients;
                   11339:     my $otheremails;
                   11340:     my %domconfig =
                   11341:          &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
                   11342:     if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766     raeburn  11343:         if (exists($domconfig{'contacts'}{$mailing})) {
                   11344:             if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
                   11345:                 my @contacts = ('adminemail','supportemail');
                   11346:                 foreach my $item (@contacts) {
                   11347:                     if ($domconfig{'contacts'}{$mailing}{$item}) {
                   11348:                         my $addr = $domconfig{'contacts'}{$item}; 
                   11349:                         if (!grep(/^\Q$addr\E$/,@recipients)) {
                   11350:                             push(@recipients,$addr);
                   11351:                         }
1.619     raeburn  11352:                     }
1.766     raeburn  11353:                     $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618     raeburn  11354:                 }
                   11355:             }
1.766     raeburn  11356:         } elsif ($origmail ne '') {
                   11357:             push(@recipients,$origmail);
1.618     raeburn  11358:         }
1.619     raeburn  11359:     } elsif ($origmail ne '') {
                   11360:         push(@recipients,$origmail);
1.618     raeburn  11361:     }
1.688     raeburn  11362:     if (defined($defmail)) {
                   11363:         if ($defmail ne '') {
                   11364:             push(@recipients,$defmail);
                   11365:         }
1.618     raeburn  11366:     }
                   11367:     if ($otheremails) {
1.619     raeburn  11368:         my @others;
                   11369:         if ($otheremails =~ /,/) {
                   11370:             @others = split(/,/,$otheremails);
1.618     raeburn  11371:         } else {
1.619     raeburn  11372:             push(@others,$otheremails);
                   11373:         }
                   11374:         foreach my $addr (@others) {
                   11375:             if (!grep(/^\Q$addr\E$/,@recipients)) {
                   11376:                 push(@recipients,$addr);
                   11377:             }
1.618     raeburn  11378:         }
                   11379:     }
1.619     raeburn  11380:     my $recipientlist = join(',',@recipients); 
1.618     raeburn  11381:     return $recipientlist;
                   11382: }
                   11383: 
1.127     matthew  11384: ############################################################
                   11385: ############################################################
1.154     albertel 11386: 
1.655     raeburn  11387: =pod
                   11388: 
                   11389: =head1 Course Catalog Routines
                   11390: 
                   11391: =over 4
                   11392: 
                   11393: =item * &gather_categories()
                   11394: 
                   11395: Converts category definitions - keys of categories hash stored in  
                   11396: coursecategories in configuration.db on the primary library server in a 
                   11397: domain - to an array.  Also generates javascript and idx hash used to 
                   11398: generate Domain Coordinator interface for editing Course Categories.
                   11399: 
                   11400: Inputs:
1.663     raeburn  11401: 
1.655     raeburn  11402: categories (reference to hash of category definitions).
1.663     raeburn  11403: 
1.655     raeburn  11404: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   11405:       categories and subcategories).
1.663     raeburn  11406: 
1.655     raeburn  11407: idx (reference to hash of counters used in Domain Coordinator interface for 
                   11408:       editing Course Categories).
1.663     raeburn  11409: 
1.655     raeburn  11410: jsarray (reference to array of categories used to create Javascript arrays for
                   11411:          Domain Coordinator interface for editing Course Categories).
                   11412: 
                   11413: Returns: nothing
                   11414: 
                   11415: Side effects: populates cats, idx and jsarray. 
                   11416: 
                   11417: =cut
                   11418: 
                   11419: sub gather_categories {
                   11420:     my ($categories,$cats,$idx,$jsarray) = @_;
                   11421:     my %counters;
                   11422:     my $num = 0;
                   11423:     foreach my $item (keys(%{$categories})) {
                   11424:         my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   11425:         if ($container eq '' && $depth == 0) {
                   11426:             $cats->[$depth][$categories->{$item}] = $cat;
                   11427:         } else {
                   11428:             $cats->[$depth]{$container}[$categories->{$item}] = $cat;
                   11429:         }
                   11430:         my ($escitem,$tail) = split(/:/,$item,2);
                   11431:         if ($counters{$tail} eq '') {
                   11432:             $counters{$tail} = $num;
                   11433:             $num ++;
                   11434:         }
                   11435:         if (ref($idx) eq 'HASH') {
                   11436:             $idx->{$item} = $counters{$tail};
                   11437:         }
                   11438:         if (ref($jsarray) eq 'ARRAY') {
                   11439:             push(@{$jsarray->[$counters{$tail}]},$item);
                   11440:         }
                   11441:     }
                   11442:     return;
                   11443: }
                   11444: 
                   11445: =pod
                   11446: 
                   11447: =item * &extract_categories()
                   11448: 
                   11449: Used to generate breadcrumb trails for course categories.
                   11450: 
                   11451: Inputs:
1.663     raeburn  11452: 
1.655     raeburn  11453: categories (reference to hash of category definitions).
1.663     raeburn  11454: 
1.655     raeburn  11455: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   11456:       categories and subcategories).
1.663     raeburn  11457: 
1.655     raeburn  11458: trails (reference to array of breacrumb trails for each category).
1.663     raeburn  11459: 
1.655     raeburn  11460: allitems (reference to hash - key is category key 
                   11461:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  11462: 
1.655     raeburn  11463: idx (reference to hash of counters used in Domain Coordinator interface for
                   11464:       editing Course Categories).
1.663     raeburn  11465: 
1.655     raeburn  11466: jsarray (reference to array of categories used to create Javascript arrays for
                   11467:          Domain Coordinator interface for editing Course Categories).
                   11468: 
1.665     raeburn  11469: subcats (reference to hash of arrays containing all subcategories within each 
                   11470:          category, -recursive)
                   11471: 
1.655     raeburn  11472: Returns: nothing
                   11473: 
                   11474: Side effects: populates trails and allitems hash references.
                   11475: 
                   11476: =cut
                   11477: 
                   11478: sub extract_categories {
1.665     raeburn  11479:     my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655     raeburn  11480:     if (ref($categories) eq 'HASH') {
                   11481:         &gather_categories($categories,$cats,$idx,$jsarray);
                   11482:         if (ref($cats->[0]) eq 'ARRAY') {
                   11483:             for (my $i=0; $i<@{$cats->[0]}; $i++) {
                   11484:                 my $name = $cats->[0][$i];
                   11485:                 my $item = &escape($name).'::0';
                   11486:                 my $trailstr;
                   11487:                 if ($name eq 'instcode') {
                   11488:                     $trailstr = &mt('Official courses (with institutional codes)');
1.919     raeburn  11489:                 } elsif ($name eq 'communities') {
                   11490:                     $trailstr = &mt('Communities');
1.655     raeburn  11491:                 } else {
                   11492:                     $trailstr = $name;
                   11493:                 }
                   11494:                 if ($allitems->{$item} eq '') {
                   11495:                     push(@{$trails},$trailstr);
                   11496:                     $allitems->{$item} = scalar(@{$trails})-1;
                   11497:                 }
                   11498:                 my @parents = ($name);
                   11499:                 if (ref($cats->[1]{$name}) eq 'ARRAY') {
                   11500:                     for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
                   11501:                         my $category = $cats->[1]{$name}[$j];
1.665     raeburn  11502:                         if (ref($subcats) eq 'HASH') {
                   11503:                             push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
                   11504:                         }
                   11505:                         &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
                   11506:                     }
                   11507:                 } else {
                   11508:                     if (ref($subcats) eq 'HASH') {
                   11509:                         $subcats->{$item} = [];
1.655     raeburn  11510:                     }
                   11511:                 }
                   11512:             }
                   11513:         }
                   11514:     }
                   11515:     return;
                   11516: }
                   11517: 
                   11518: =pod
                   11519: 
                   11520: =item *&recurse_categories()
                   11521: 
                   11522: Recursively used to generate breadcrumb trails for course categories.
                   11523: 
                   11524: Inputs:
1.663     raeburn  11525: 
1.655     raeburn  11526: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   11527:       categories and subcategories).
1.663     raeburn  11528: 
1.655     raeburn  11529: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663     raeburn  11530: 
                   11531: category (current course category, for which breadcrumb trail is being generated).
                   11532: 
                   11533: trails (reference to array of breadcrumb trails for each category).
                   11534: 
1.655     raeburn  11535: allitems (reference to hash - key is category key
                   11536:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  11537: 
1.655     raeburn  11538: parents (array containing containers directories for current category, 
                   11539:          back to top level). 
                   11540: 
                   11541: Returns: nothing
                   11542: 
                   11543: Side effects: populates trails and allitems hash references
                   11544: 
                   11545: =cut
                   11546: 
                   11547: sub recurse_categories {
1.665     raeburn  11548:     my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655     raeburn  11549:     my $shallower = $depth - 1;
                   11550:     if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
                   11551:         for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
                   11552:             my $name = $cats->[$depth]{$category}[$k];
                   11553:             my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   11554:             my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   11555:             if ($allitems->{$item} eq '') {
                   11556:                 push(@{$trails},$trailstr);
                   11557:                 $allitems->{$item} = scalar(@{$trails})-1;
                   11558:             }
                   11559:             my $deeper = $depth+1;
                   11560:             push(@{$parents},$category);
1.665     raeburn  11561:             if (ref($subcats) eq 'HASH') {
                   11562:                 my $subcat = &escape($name).':'.$category.':'.$depth;
                   11563:                 for (my $j=@{$parents}; $j>=0; $j--) {
                   11564:                     my $higher;
                   11565:                     if ($j > 0) {
                   11566:                         $higher = &escape($parents->[$j]).':'.
                   11567:                                   &escape($parents->[$j-1]).':'.$j;
                   11568:                     } else {
                   11569:                         $higher = &escape($parents->[$j]).'::'.$j;
                   11570:                     }
                   11571:                     push(@{$subcats->{$higher}},$subcat);
                   11572:                 }
                   11573:             }
                   11574:             &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
                   11575:                                 $subcats);
1.655     raeburn  11576:             pop(@{$parents});
                   11577:         }
                   11578:     } else {
                   11579:         my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   11580:         my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   11581:         if ($allitems->{$item} eq '') {
                   11582:             push(@{$trails},$trailstr);
                   11583:             $allitems->{$item} = scalar(@{$trails})-1;
                   11584:         }
                   11585:     }
                   11586:     return;
                   11587: }
                   11588: 
1.663     raeburn  11589: =pod
                   11590: 
                   11591: =item *&assign_categories_table()
                   11592: 
                   11593: Create a datatable for display of hierarchical categories in a domain,
                   11594: with checkboxes to allow a course to be categorized. 
                   11595: 
                   11596: Inputs:
                   11597: 
                   11598: cathash - reference to hash of categories defined for the domain (from
                   11599:           configuration.db)
                   11600: 
                   11601: currcat - scalar with an & separated list of categories assigned to a course. 
                   11602: 
1.919     raeburn  11603: type    - scalar contains course type (Course or Community).
                   11604: 
1.663     raeburn  11605: Returns: $output (markup to be displayed) 
                   11606: 
                   11607: =cut
                   11608: 
                   11609: sub assign_categories_table {
1.919     raeburn  11610:     my ($cathash,$currcat,$type) = @_;
1.663     raeburn  11611:     my $output;
                   11612:     if (ref($cathash) eq 'HASH') {
                   11613:         my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
                   11614:         &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
                   11615:         $maxdepth = scalar(@cats);
                   11616:         if (@cats > 0) {
                   11617:             my $itemcount = 0;
                   11618:             if (ref($cats[0]) eq 'ARRAY') {
                   11619:                 my @currcategories;
                   11620:                 if ($currcat ne '') {
                   11621:                     @currcategories = split('&',$currcat);
                   11622:                 }
1.919     raeburn  11623:                 my $table;
1.663     raeburn  11624:                 for (my $i=0; $i<@{$cats[0]}; $i++) {
                   11625:                     my $parent = $cats[0][$i];
1.919     raeburn  11626:                     next if ($parent eq 'instcode');
                   11627:                     if ($type eq 'Community') {
                   11628:                         next unless ($parent eq 'communities');
                   11629:                     } else {
                   11630:                         next if ($parent eq 'communities');
                   11631:                     }
1.663     raeburn  11632:                     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   11633:                     my $item = &escape($parent).'::0';
                   11634:                     my $checked = '';
                   11635:                     if (@currcategories > 0) {
                   11636:                         if (grep(/^\Q$item\E$/,@currcategories)) {
1.772     bisitz   11637:                             $checked = ' checked="checked"';
1.663     raeburn  11638:                         }
                   11639:                     }
1.919     raeburn  11640:                     my $parent_title = $parent;
                   11641:                     if ($parent eq 'communities') {
                   11642:                         $parent_title = &mt('Communities');
                   11643:                     }
                   11644:                     $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
                   11645:                               '<input type="checkbox" name="usecategory" value="'.
                   11646:                               $item.'"'.$checked.' />'.$parent_title.'</span>'.
                   11647:                               '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663     raeburn  11648:                     my $depth = 1;
                   11649:                     push(@path,$parent);
1.919     raeburn  11650:                     $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663     raeburn  11651:                     pop(@path);
1.919     raeburn  11652:                     $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663     raeburn  11653:                     $itemcount ++;
                   11654:                 }
1.919     raeburn  11655:                 if ($itemcount) {
                   11656:                     $output = &Apache::loncommon::start_data_table().
                   11657:                               $table.
                   11658:                               &Apache::loncommon::end_data_table();
                   11659:                 }
1.663     raeburn  11660:             }
                   11661:         }
                   11662:     }
                   11663:     return $output;
                   11664: }
                   11665: 
                   11666: =pod
                   11667: 
                   11668: =item *&assign_category_rows()
                   11669: 
                   11670: Create a datatable row for display of nested categories in a domain,
                   11671: with checkboxes to allow a course to be categorized,called recursively.
                   11672: 
                   11673: Inputs:
                   11674: 
                   11675: itemcount - track row number for alternating colors
                   11676: 
                   11677: cats - reference to array of arrays/hashes which encapsulates hierarchy of
                   11678:       categories and subcategories.
                   11679: 
                   11680: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
                   11681: 
                   11682: parent - parent of current category item
                   11683: 
                   11684: path - Array containing all categories back up through the hierarchy from the
                   11685:        current category to the top level.
                   11686: 
                   11687: currcategories - reference to array of current categories assigned to the course
                   11688: 
                   11689: Returns: $output (markup to be displayed).
                   11690: 
                   11691: =cut
                   11692: 
                   11693: sub assign_category_rows {
                   11694:     my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
                   11695:     my ($text,$name,$item,$chgstr);
                   11696:     if (ref($cats) eq 'ARRAY') {
                   11697:         my $maxdepth = scalar(@{$cats});
                   11698:         if (ref($cats->[$depth]) eq 'HASH') {
                   11699:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   11700:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   11701:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   11702:                 $text .= '<td><table class="LC_datatable">';
                   11703:                 for (my $j=0; $j<$numchildren; $j++) {
                   11704:                     $name = $cats->[$depth]{$parent}[$j];
                   11705:                     $item = &escape($name).':'.&escape($parent).':'.$depth;
                   11706:                     my $deeper = $depth+1;
                   11707:                     my $checked = '';
                   11708:                     if (ref($currcategories) eq 'ARRAY') {
                   11709:                         if (@{$currcategories} > 0) {
                   11710:                             if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772     bisitz   11711:                                 $checked = ' checked="checked"';
1.663     raeburn  11712:                             }
                   11713:                         }
                   11714:                     }
1.664     raeburn  11715:                     $text .= '<tr><td><span class="LC_nobreak"><label>'.
                   11716:                              '<input type="checkbox" name="usecategory" value="'.
1.675     raeburn  11717:                              $item.'"'.$checked.' />'.$name.'</label></span>'.
                   11718:                              '<input type="hidden" name="catname" value="'.$name.'" />'.
                   11719:                              '</td><td>';
1.663     raeburn  11720:                     if (ref($path) eq 'ARRAY') {
                   11721:                         push(@{$path},$name);
                   11722:                         $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
                   11723:                         pop(@{$path});
                   11724:                     }
                   11725:                     $text .= '</td></tr>';
                   11726:                 }
                   11727:                 $text .= '</table></td>';
                   11728:             }
                   11729:         }
                   11730:     }
                   11731:     return $text;
                   11732: }
                   11733: 
1.655     raeburn  11734: ############################################################
                   11735: ############################################################
                   11736: 
                   11737: 
1.443     albertel 11738: sub commit_customrole {
1.664     raeburn  11739:     my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630     raeburn  11740:     my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443     albertel 11741:                          ($start?', '.&mt('starting').' '.localtime($start):'').
                   11742:                          ($end?', ending '.localtime($end):'').': <b>'.
                   11743:               &Apache::lonnet::assigncustomrole(
1.664     raeburn  11744:                  $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443     albertel 11745:                  '</b><br />';
                   11746:     return $output;
                   11747: }
                   11748: 
                   11749: sub commit_standardrole {
1.541     raeburn  11750:     my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
                   11751:     my ($output,$logmsg,$linefeed);
                   11752:     if ($context eq 'auto') {
                   11753:         $linefeed = "\n";
                   11754:     } else {
                   11755:         $linefeed = "<br />\n";
                   11756:     }  
1.443     albertel 11757:     if ($three eq 'st') {
1.541     raeburn  11758:         my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
                   11759:                                          $one,$two,$sec,$context);
                   11760:         if (($result =~ /^error/) || ($result eq 'not_in_class') || 
1.626     raeburn  11761:             ($result eq 'unknown_course') || ($result eq 'refused')) {
                   11762:             $output = $logmsg.' '.&mt('Error: ').$result."\n"; 
1.443     albertel 11763:         } else {
1.541     raeburn  11764:             $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443     albertel 11765:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  11766:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
                   11767:             if ($context eq 'auto') {
                   11768:                 $output .= $result.$linefeed.&mt('Add to classlist').': ok';
                   11769:             } else {
                   11770:                $output .= '<b>'.$result.'</b>'.$linefeed.
                   11771:                &mt('Add to classlist').': <b>ok</b>';
                   11772:             }
                   11773:             $output .= $linefeed;
1.443     albertel 11774:         }
                   11775:     } else {
                   11776:         $output = &mt('Assigning').' '.$three.' in '.$url.
                   11777:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  11778:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652     raeburn  11779:         my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541     raeburn  11780:         if ($context eq 'auto') {
                   11781:             $output .= $result.$linefeed;
                   11782:         } else {
                   11783:             $output .= '<b>'.$result.'</b>'.$linefeed;
                   11784:         }
1.443     albertel 11785:     }
                   11786:     return $output;
                   11787: }
                   11788: 
                   11789: sub commit_studentrole {
1.541     raeburn  11790:     my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626     raeburn  11791:     my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541     raeburn  11792:     if ($context eq 'auto') {
                   11793:         $linefeed = "\n";
                   11794:     } else {
                   11795:         $linefeed = '<br />'."\n";
                   11796:     }
1.443     albertel 11797:     if (defined($one) && defined($two)) {
                   11798:         my $cid=$one.'_'.$two;
                   11799:         my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
                   11800:         my $secchange = 0;
                   11801:         my $expire_role_result;
                   11802:         my $modify_section_result;
1.628     raeburn  11803:         if ($oldsec ne '-1') { 
                   11804:             if ($oldsec ne $sec) {
1.443     albertel 11805:                 $secchange = 1;
1.628     raeburn  11806:                 my $now = time;
1.443     albertel 11807:                 my $uurl='/'.$cid;
                   11808:                 $uurl=~s/\_/\//g;
                   11809:                 if ($oldsec) {
                   11810:                     $uurl.='/'.$oldsec;
                   11811:                 }
1.626     raeburn  11812:                 $oldsecurl = $uurl;
1.628     raeburn  11813:                 $expire_role_result = 
1.652     raeburn  11814:                     &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628     raeburn  11815:                 if ($env{'request.course.sec'} ne '') { 
                   11816:                     if ($expire_role_result eq 'refused') {
                   11817:                         my @roles = ('st');
                   11818:                         my @statuses = ('previous');
                   11819:                         my @roledoms = ($one);
                   11820:                         my $withsec = 1;
                   11821:                         my %roleshash = 
                   11822:                             &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
                   11823:                                               \@statuses,\@roles,\@roledoms,$withsec);
                   11824:                         if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
                   11825:                             my ($oldstart,$oldend) = 
                   11826:                                 split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
                   11827:                             if ($oldend > 0 && $oldend <= $now) {
                   11828:                                 $expire_role_result = 'ok';
                   11829:                             }
                   11830:                         }
                   11831:                     }
                   11832:                 }
1.443     albertel 11833:                 $result = $expire_role_result;
                   11834:             }
                   11835:         }
                   11836:         if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652     raeburn  11837:             $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443     albertel 11838:             if ($modify_section_result =~ /^ok/) {
                   11839:                 if ($secchange == 1) {
1.628     raeburn  11840:                     if ($sec eq '') {
                   11841:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
                   11842:                     } else {
                   11843:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
                   11844:                     }
1.443     albertel 11845:                 } elsif ($oldsec eq '-1') {
1.628     raeburn  11846:                     if ($sec eq '') {
                   11847:                         $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
                   11848:                     } else {
                   11849:                         $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   11850:                     }
1.443     albertel 11851:                 } else {
1.628     raeburn  11852:                     if ($sec eq '') {
                   11853:                         $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
                   11854:                     } else {
                   11855:                         $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   11856:                     }
1.443     albertel 11857:                 }
                   11858:             } else {
1.628     raeburn  11859:                 if ($secchange) {       
                   11860:                     $$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;
                   11861:                 } else {
                   11862:                     $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
                   11863:                 }
1.443     albertel 11864:             }
                   11865:             $result = $modify_section_result;
                   11866:         } elsif ($secchange == 1) {
1.628     raeburn  11867:             if ($oldsec eq '') {
                   11868:                 $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
                   11869:             } else {
                   11870:                 $$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;
                   11871:             }
1.626     raeburn  11872:             if ($expire_role_result eq 'refused') {
                   11873:                 my $newsecurl = '/'.$cid;
                   11874:                 $newsecurl =~ s/\_/\//g;
                   11875:                 if ($sec ne '') {
                   11876:                     $newsecurl.='/'.$sec;
                   11877:                 }
                   11878:                 if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
                   11879:                     if ($sec eq '') {
                   11880:                         $$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;
                   11881:                     } else {
                   11882:                         $$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;
                   11883:                     }
                   11884:                 }
                   11885:             }
1.443     albertel 11886:         }
                   11887:     } else {
1.626     raeburn  11888:         $$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 11889:         $result = "error: incomplete course id\n";
                   11890:     }
                   11891:     return $result;
                   11892: }
                   11893: 
                   11894: ############################################################
                   11895: ############################################################
                   11896: 
1.566     albertel 11897: sub check_clone {
1.578     raeburn  11898:     my ($args,$linefeed) = @_;
1.566     albertel 11899:     my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
                   11900:     my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
                   11901:     my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
                   11902:     my $clonemsg;
                   11903:     my $can_clone = 0;
1.944     raeburn  11904:     my $lctype = lc($args->{'crstype'});
1.908     raeburn  11905:     if ($lctype ne 'community') {
                   11906:         $lctype = 'course';
                   11907:     }
1.566     albertel 11908:     if ($clonehome eq 'no_host') {
1.944     raeburn  11909:         if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  11910:             $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'});
                   11911:         } else {
                   11912:             $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'});
                   11913:         }     
1.566     albertel 11914:     } else {
                   11915: 	my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944     raeburn  11916:         if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  11917:             if ($clonedesc{'type'} ne 'Community') {
                   11918:                  $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'});
                   11919:                 return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   11920:             }
                   11921:         }
1.882     raeburn  11922: 	if (($env{'request.role.domain'} eq $args->{'clonedomain'}) && 
                   11923:             (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566     albertel 11924: 	    $can_clone = 1;
                   11925: 	} else {
                   11926: 	    my %clonehash = &Apache::lonnet::get('environment',['cloners'],
                   11927: 						 $args->{'clonedomain'},$args->{'clonecourse'});
                   11928: 	    my @cloners = split(/,/,$clonehash{'cloners'});
1.578     raeburn  11929:             if (grep(/^\*$/,@cloners)) {
                   11930:                 $can_clone = 1;
                   11931:             } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
                   11932:                 $can_clone = 1;
                   11933:             } else {
1.908     raeburn  11934:                 my $ccrole = 'cc';
1.944     raeburn  11935:                 if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  11936:                     $ccrole = 'co';
                   11937:                 }
1.578     raeburn  11938: 	        my %roleshash =
                   11939: 		    &Apache::lonnet::get_my_roles($args->{'ccuname'},
                   11940: 					 $args->{'ccdomain'},
1.908     raeburn  11941:                                          'userroles',['active'],[$ccrole],
1.578     raeburn  11942: 					 [$args->{'clonedomain'}]);
1.908     raeburn  11943: 	        if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942     raeburn  11944:                     $can_clone = 1;
                   11945:                 } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
                   11946:                     $can_clone = 1;
                   11947:                 } else {
1.944     raeburn  11948:                     if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  11949:                         $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'});
                   11950:                     } else {
                   11951:                         $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'});
                   11952:                     }
1.578     raeburn  11953: 	        }
1.566     albertel 11954: 	    }
1.578     raeburn  11955:         }
1.566     albertel 11956:     }
                   11957:     return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   11958: }
                   11959: 
1.444     albertel 11960: sub construct_course {
1.885     raeburn  11961:     my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444     albertel 11962:     my $outcome;
1.541     raeburn  11963:     my $linefeed =  '<br />'."\n";
                   11964:     if ($context eq 'auto') {
                   11965:         $linefeed = "\n";
                   11966:     }
1.566     albertel 11967: 
                   11968: #
                   11969: # Are we cloning?
                   11970: #
                   11971:     my ($can_clone, $clonemsg, $cloneid, $clonehome);
                   11972:     if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578     raeburn  11973: 	($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566     albertel 11974: 	if ($context ne 'auto') {
1.578     raeburn  11975:             if ($clonemsg ne '') {
                   11976: 	        $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
                   11977:             }
1.566     albertel 11978: 	}
                   11979: 	$outcome .= $clonemsg.$linefeed;
                   11980: 
                   11981:         if (!$can_clone) {
                   11982: 	    return (0,$outcome);
                   11983: 	}
                   11984:     }
                   11985: 
1.444     albertel 11986: #
                   11987: # Open course
                   11988: #
                   11989:     my $crstype = lc($args->{'crstype'});
                   11990:     my %cenv=();
                   11991:     $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
                   11992:                                              $args->{'cdescr'},
                   11993:                                              $args->{'curl'},
                   11994:                                              $args->{'course_home'},
                   11995:                                              $args->{'nonstandard'},
                   11996:                                              $args->{'crscode'},
                   11997:                                              $args->{'ccuname'}.':'.
                   11998:                                              $args->{'ccdomain'},
1.882     raeburn  11999:                                              $args->{'crstype'},
1.885     raeburn  12000:                                              $cnum,$context,$category);
1.444     albertel 12001: 
                   12002:     # Note: The testing routines depend on this being output; see 
                   12003:     # Utils::Course. This needs to at least be output as a comment
                   12004:     # if anyone ever decides to not show this, and Utils::Course::new
                   12005:     # will need to be suitably modified.
1.541     raeburn  12006:     $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943     raeburn  12007:     if ($$courseid =~ /^error:/) {
                   12008:         return (0,$outcome);
                   12009:     }
                   12010: 
1.444     albertel 12011: #
                   12012: # Check if created correctly
                   12013: #
1.479     albertel 12014:     ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444     albertel 12015:     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943     raeburn  12016:     if ($crsuhome eq 'no_host') {
                   12017:         $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
                   12018:         return (0,$outcome);
                   12019:     }
1.541     raeburn  12020:     $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566     albertel 12021: 
1.444     albertel 12022: #
1.566     albertel 12023: # Do the cloning
                   12024: #   
                   12025:     if ($can_clone && $cloneid) {
                   12026: 	$clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
                   12027: 	if ($context ne 'auto') {
                   12028: 	    $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
                   12029: 	}
                   12030: 	$outcome .= $clonemsg.$linefeed;
                   12031: 	my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444     albertel 12032: # Copy all files
1.637     www      12033: 	&Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444     albertel 12034: # Restore URL
1.566     albertel 12035: 	$cenv{'url'}=$oldcenv{'url'};
1.444     albertel 12036: # Restore title
1.566     albertel 12037: 	$cenv{'description'}=$oldcenv{'description'};
1.955     raeburn  12038: # Restore creation date, creator and creation context.
                   12039:         $cenv{'internal.created'}=$oldcenv{'internal.created'};
                   12040:         $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
                   12041:         $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444     albertel 12042: # Mark as cloned
1.566     albertel 12043: 	$cenv{'clonedfrom'}=$cloneid;
1.638     www      12044: # Need to clone grading mode
                   12045:         my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
                   12046:         $cenv{'grading'}=$newenv{'grading'};
                   12047: # Do not clone these environment entries
                   12048:         &Apache::lonnet::del('environment',
                   12049:                   ['default_enrollment_start_date',
                   12050:                    'default_enrollment_end_date',
                   12051:                    'question.email',
                   12052:                    'policy.email',
                   12053:                    'comment.email',
                   12054:                    'pch.users.denied',
1.725     raeburn  12055:                    'plc.users.denied',
                   12056:                    'hidefromcat',
                   12057:                    'categories'],
1.638     www      12058:                    $$crsudom,$$crsunum);
1.444     albertel 12059:     }
1.566     albertel 12060: 
1.444     albertel 12061: #
                   12062: # Set environment (will override cloned, if existing)
                   12063: #
                   12064:     my @sections = ();
                   12065:     my @xlists = ();
                   12066:     if ($args->{'crstype'}) {
                   12067:         $cenv{'type'}=$args->{'crstype'};
                   12068:     }
                   12069:     if ($args->{'crsid'}) {
                   12070:         $cenv{'courseid'}=$args->{'crsid'};
                   12071:     }
                   12072:     if ($args->{'crscode'}) {
                   12073:         $cenv{'internal.coursecode'}=$args->{'crscode'};
                   12074:     }
                   12075:     if ($args->{'crsquota'} ne '') {
                   12076:         $cenv{'internal.coursequota'}=$args->{'crsquota'};
                   12077:     } else {
                   12078:         $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
                   12079:     }
                   12080:     if ($args->{'ccuname'}) {
                   12081:         $cenv{'internal.courseowner'} = $args->{'ccuname'}.
                   12082:                                         ':'.$args->{'ccdomain'};
                   12083:     } else {
                   12084:         $cenv{'internal.courseowner'} = $args->{'curruser'};
                   12085:     }
                   12086:     my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
                   12087:     if ($args->{'crssections'}) {
                   12088:         $cenv{'internal.sectionnums'} = '';
                   12089:         if ($args->{'crssections'} =~ m/,/) {
                   12090:             @sections = split/,/,$args->{'crssections'};
                   12091:         } else {
                   12092:             $sections[0] = $args->{'crssections'};
                   12093:         }
                   12094:         if (@sections > 0) {
                   12095:             foreach my $item (@sections) {
                   12096:                 my ($sec,$gp) = split/:/,$item;
                   12097:                 my $class = $args->{'crscode'}.$sec;
                   12098:                 my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
                   12099:                 $cenv{'internal.sectionnums'} .= $item.',';
                   12100:                 unless ($addcheck eq 'ok') {
                   12101:                     push @badclasses, $class;
                   12102:                 }
                   12103:             }
                   12104:             $cenv{'internal.sectionnums'} =~ s/,$//;
                   12105:         }
                   12106:     }
                   12107: # do not hide course coordinator from staff listing, 
                   12108: # even if privileged
                   12109:     $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   12110: # add crosslistings
                   12111:     if ($args->{'crsxlist'}) {
                   12112:         $cenv{'internal.crosslistings'}='';
                   12113:         if ($args->{'crsxlist'} =~ m/,/) {
                   12114:             @xlists = split/,/,$args->{'crsxlist'};
                   12115:         } else {
                   12116:             $xlists[0] = $args->{'crsxlist'};
                   12117:         }
                   12118:         if (@xlists > 0) {
                   12119:             foreach my $item (@xlists) {
                   12120:                 my ($xl,$gp) = split/:/,$item;
                   12121:                 my $addcheck =  &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
                   12122:                 $cenv{'internal.crosslistings'} .= $item.',';
                   12123:                 unless ($addcheck eq 'ok') {
                   12124:                     push @badclasses, $xl;
                   12125:                 }
                   12126:             }
                   12127:             $cenv{'internal.crosslistings'} =~ s/,$//;
                   12128:         }
                   12129:     }
                   12130:     if ($args->{'autoadds'}) {
                   12131:         $cenv{'internal.autoadds'}=$args->{'autoadds'};
                   12132:     }
                   12133:     if ($args->{'autodrops'}) {
                   12134:         $cenv{'internal.autodrops'}=$args->{'autodrops'};
                   12135:     }
                   12136: # check for notification of enrollment changes
                   12137:     my @notified = ();
                   12138:     if ($args->{'notify_owner'}) {
                   12139:         if ($args->{'ccuname'} ne '') {
                   12140:             push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
                   12141:         }
                   12142:     }
                   12143:     if ($args->{'notify_dc'}) {
                   12144:         if ($uname ne '') { 
1.630     raeburn  12145:             push(@notified,$uname.':'.$udom);
1.444     albertel 12146:         }
                   12147:     }
                   12148:     if (@notified > 0) {
                   12149:         my $notifylist;
                   12150:         if (@notified > 1) {
                   12151:             $notifylist = join(',',@notified);
                   12152:         } else {
                   12153:             $notifylist = $notified[0];
                   12154:         }
                   12155:         $cenv{'internal.notifylist'} = $notifylist;
                   12156:     }
                   12157:     if (@badclasses > 0) {
                   12158:         my %lt=&Apache::lonlocal::texthash(
                   12159:                 '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',
                   12160:                 'dnhr' => 'does not have rights to access enrollment in these classes',
                   12161:                 'adby' => 'as determined by the policies of your institution on access to official classlists'
                   12162:         );
1.541     raeburn  12163:         my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
                   12164:                            ' ('.$lt{'adby'}.')';
                   12165:         if ($context eq 'auto') {
                   12166:             $outcome .= $badclass_msg.$linefeed;
1.566     albertel 12167:             $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541     raeburn  12168:             foreach my $item (@badclasses) {
                   12169:                 if ($context eq 'auto') {
                   12170:                     $outcome .= " - $item\n";
                   12171:                 } else {
                   12172:                     $outcome .= "<li>$item</li>\n";
                   12173:                 }
                   12174:             }
                   12175:             if ($context eq 'auto') {
                   12176:                 $outcome .= $linefeed;
                   12177:             } else {
1.566     albertel 12178:                 $outcome .= "</ul><br /><br /></div>\n";
1.541     raeburn  12179:             }
                   12180:         } 
1.444     albertel 12181:     }
                   12182:     if ($args->{'no_end_date'}) {
                   12183:         $args->{'endaccess'} = 0;
                   12184:     }
                   12185:     $cenv{'internal.autostart'}=$args->{'enrollstart'};
                   12186:     $cenv{'internal.autoend'}=$args->{'enrollend'};
                   12187:     $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
                   12188:     $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
                   12189:     if ($args->{'showphotos'}) {
                   12190:       $cenv{'internal.showphotos'}=$args->{'showphotos'};
                   12191:     }
                   12192:     $cenv{'internal.authtype'} = $args->{'authtype'};
                   12193:     $cenv{'internal.autharg'} = $args->{'autharg'}; 
                   12194:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
                   12195:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
1.541     raeburn  12196:             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'); 
                   12197:             if ($context eq 'auto') {
                   12198:                 $outcome .= $krb_msg;
                   12199:             } else {
1.566     albertel 12200:                 $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541     raeburn  12201:             }
                   12202:             $outcome .= $linefeed;
1.444     albertel 12203:         }
                   12204:     }
                   12205:     if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
                   12206:        if ($args->{'setpolicy'}) {
                   12207:            $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   12208:        }
                   12209:        if ($args->{'setcontent'}) {
                   12210:            $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   12211:        }
                   12212:     }
                   12213:     if ($args->{'reshome'}) {
                   12214: 	$cenv{'reshome'}=$args->{'reshome'}.'/';
                   12215: 	$cenv{'reshome'}=~s/\/+$/\//;
                   12216:     }
                   12217: #
                   12218: # course has keyed access
                   12219: #
                   12220:     if ($args->{'setkeys'}) {
                   12221:        $cenv{'keyaccess'}='yes';
                   12222:     }
                   12223: # if specified, key authority is not course, but user
                   12224: # only active if keyaccess is yes
                   12225:     if ($args->{'keyauth'}) {
1.487     albertel 12226: 	my ($user,$domain) = split(':',$args->{'keyauth'});
                   12227: 	$user = &LONCAPA::clean_username($user);
                   12228: 	$domain = &LONCAPA::clean_username($domain);
1.488     foxr     12229: 	if ($user ne '' && $domain ne '') {
1.487     albertel 12230: 	    $cenv{'keyauth'}=$user.':'.$domain;
1.444     albertel 12231: 	}
                   12232:     }
                   12233: 
                   12234:     if ($args->{'disresdis'}) {
                   12235:         $cenv{'pch.roles.denied'}='st';
                   12236:     }
                   12237:     if ($args->{'disablechat'}) {
                   12238:         $cenv{'plc.roles.denied'}='st';
                   12239:     }
                   12240: 
                   12241:     # Record we've not yet viewed the Course Initialization Helper for this 
                   12242:     # course
                   12243:     $cenv{'course.helper.not.run'} = 1;
                   12244:     #
                   12245:     # Use new Randomseed
                   12246:     #
                   12247:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
                   12248:     $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
                   12249:     #
                   12250:     # The encryption code and receipt prefix for this course
                   12251:     #
                   12252:     $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
                   12253:     $cenv{'internal.encpref'}=100+int(9*rand(99));
                   12254:     #
                   12255:     # By default, use standard grading
                   12256:     if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
                   12257: 
1.541     raeburn  12258:     $outcome .= $linefeed.&mt('Setting environment').': '.                 
                   12259:           &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 12260: #
                   12261: # Open all assignments
                   12262: #
                   12263:     if ($args->{'openall'}) {
                   12264:        my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
                   12265:        my %storecontent = ($storeunder         => time,
                   12266:                            $storeunder.'.type' => 'date_start');
                   12267:        
                   12268:        $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541     raeburn  12269:                  ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 12270:    }
                   12271: #
                   12272: # Set first page
                   12273: #
                   12274:     unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
                   12275: 	    || ($cloneid)) {
1.445     albertel 12276: 	use LONCAPA::map;
1.444     albertel 12277: 	$outcome .= &mt('Setting first resource').': ';
1.445     albertel 12278: 
                   12279: 	my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
                   12280:         my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
                   12281: 
1.444     albertel 12282:         $outcome .= ($fatal?$errtext:'read ok').' - ';
                   12283:         my $title; my $url;
                   12284:         if ($args->{'firstres'} eq 'syl') {
1.690     bisitz   12285: 	    $title=&mt('Syllabus');
1.444     albertel 12286:             $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
                   12287:         } else {
1.963     raeburn  12288:             $title=&mt('Table of Contents');
1.444     albertel 12289:             $url='/adm/navmaps';
                   12290:         }
1.445     albertel 12291: 
                   12292:         $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
                   12293: 	(my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
                   12294: 
                   12295: 	if ($errtext) { $fatal=2; }
1.541     raeburn  12296:         $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444     albertel 12297:     }
1.566     albertel 12298: 
                   12299:     return (1,$outcome);
1.444     albertel 12300: }
                   12301: 
                   12302: ############################################################
                   12303: ############################################################
                   12304: 
1.953     droeschl 12305: #SD
                   12306: # only Community and Course, or anything else?
1.378     raeburn  12307: sub course_type {
                   12308:     my ($cid) = @_;
                   12309:     if (!defined($cid)) {
                   12310:         $cid = $env{'request.course.id'};
                   12311:     }
1.404     albertel 12312:     if (defined($env{'course.'.$cid.'.type'})) {
                   12313:         return $env{'course.'.$cid.'.type'};
1.378     raeburn  12314:     } else {
                   12315:         return 'Course';
1.377     raeburn  12316:     }
                   12317: }
1.156     albertel 12318: 
1.406     raeburn  12319: sub group_term {
                   12320:     my $crstype = &course_type();
                   12321:     my %names = (
                   12322:                   'Course' => 'group',
1.865     raeburn  12323:                   'Community' => 'group',
1.406     raeburn  12324:                 );
                   12325:     return $names{$crstype};
                   12326: }
                   12327: 
1.902     raeburn  12328: sub course_types {
                   12329:     my @types = ('official','unofficial','community');
                   12330:     my %typename = (
                   12331:                          official   => 'Official course',
                   12332:                          unofficial => 'Unofficial course',
                   12333:                          community  => 'Community',
                   12334:                    );
                   12335:     return (\@types,\%typename);
                   12336: }
                   12337: 
1.156     albertel 12338: sub icon {
                   12339:     my ($file)=@_;
1.505     albertel 12340:     my $curfext = lc((split(/\./,$file))[-1]);
1.168     albertel 12341:     my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156     albertel 12342:     my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168     albertel 12343:     if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
                   12344: 	if (-e  $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
                   12345: 	          $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   12346: 	            $curfext.".gif") {
                   12347: 	    $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   12348: 		$curfext.".gif";
                   12349: 	}
                   12350:     }
1.249     albertel 12351:     return &lonhttpdurl($iconname);
1.154     albertel 12352: } 
1.84      albertel 12353: 
1.575     albertel 12354: sub lonhttpdurl {
1.692     www      12355: #
                   12356: # Had been used for "small fry" static images on separate port 8080.
                   12357: # Modify here if lightweight http functionality desired again.
                   12358: # Currently eliminated due to increasing firewall issues.
                   12359: #
1.575     albertel 12360:     my ($url)=@_;
1.692     www      12361:     return $url;
1.215     albertel 12362: }
                   12363: 
1.213     albertel 12364: sub connection_aborted {
                   12365:     my ($r)=@_;
                   12366:     $r->print(" ");$r->rflush();
                   12367:     my $c = $r->connection;
                   12368:     return $c->aborted();
                   12369: }
                   12370: 
1.221     foxr     12371: #    Escapes strings that may have embedded 's that will be put into
1.222     foxr     12372: #    strings as 'strings'.
                   12373: sub escape_single {
1.221     foxr     12374:     my ($input) = @_;
1.223     albertel 12375:     $input =~ s/\\/\\\\/g;	# Escape the \'s..(must be first)>
1.221     foxr     12376:     $input =~ s/\'/\\\'/g;	# Esacpe the 's....
                   12377:     return $input;
                   12378: }
1.223     albertel 12379: 
1.222     foxr     12380: #  Same as escape_single, but escape's "'s  This 
                   12381: #  can be used for  "strings"
                   12382: sub escape_double {
                   12383:     my ($input) = @_;
                   12384:     $input =~ s/\\/\\\\/g;	# Escape the /'s..(must be first)>
                   12385:     $input =~ s/\"/\\\"/g;	# Esacpe the "s....
                   12386:     return $input;
                   12387: }
1.223     albertel 12388:  
1.222     foxr     12389: #   Escapes the last element of a full URL.
                   12390: sub escape_url {
                   12391:     my ($url)   = @_;
1.238     raeburn  12392:     my @urlslices = split(/\//, $url,-1);
1.369     www      12393:     my $lastitem = &escape(pop(@urlslices));
1.223     albertel 12394:     return join('/',@urlslices).'/'.$lastitem;
1.222     foxr     12395: }
1.462     albertel 12396: 
1.820     raeburn  12397: sub compare_arrays {
                   12398:     my ($arrayref1,$arrayref2) = @_;
                   12399:     my (@difference,%count);
                   12400:     @difference = ();
                   12401:     %count = ();
                   12402:     if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
                   12403:         foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
                   12404:         foreach my $element (keys(%count)) {
                   12405:             if ($count{$element} == 1) {
                   12406:                 push(@difference,$element);
                   12407:             }
                   12408:         }
                   12409:     }
                   12410:     return @difference;
                   12411: }
                   12412: 
1.817     bisitz   12413: # -------------------------------------------------------- Initialize user login
1.462     albertel 12414: sub init_user_environment {
1.463     albertel 12415:     my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462     albertel 12416:     my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
                   12417: 
                   12418:     my $public=($username eq 'public' && $domain eq 'public');
                   12419: 
                   12420: # See if old ID present, if so, remove
                   12421: 
                   12422:     my ($filename,$cookie,$userroles);
                   12423:     my $now=time;
                   12424: 
                   12425:     if ($public) {
                   12426: 	my $max_public=100;
                   12427: 	my $oldest;
                   12428: 	my $oldest_time=0;
                   12429: 	for(my $next=1;$next<=$max_public;$next++) {
                   12430: 	    if (-e $lonids."/publicuser_$next.id") {
                   12431: 		my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
                   12432: 		if ($mtime<$oldest_time || !$oldest_time) {
                   12433: 		    $oldest_time=$mtime;
                   12434: 		    $oldest=$next;
                   12435: 		}
                   12436: 	    } else {
                   12437: 		$cookie="publicuser_$next";
                   12438: 		last;
                   12439: 	    }
                   12440: 	}
                   12441: 	if (!$cookie) { $cookie="publicuser_$oldest"; }
                   12442:     } else {
1.463     albertel 12443: 	# if this isn't a robot, kill any existing non-robot sessions
                   12444: 	if (!$args->{'robot'}) {
                   12445: 	    opendir(DIR,$lonids);
                   12446: 	    while ($filename=readdir(DIR)) {
                   12447: 		if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
                   12448: 		    unlink($lonids.'/'.$filename);
                   12449: 		}
1.462     albertel 12450: 	    }
1.463     albertel 12451: 	    closedir(DIR);
1.462     albertel 12452: 	}
                   12453: # Give them a new cookie
1.463     albertel 12454: 	my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684     www      12455: 		                   : $now.$$.int(rand(10000)));
1.463     albertel 12456: 	$cookie="$username\_$id\_$domain\_$authhost";
1.462     albertel 12457:     
                   12458: # Initialize roles
                   12459: 
                   12460: 	$userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
                   12461:     }
                   12462: # ------------------------------------ Check browser type and MathML capability
                   12463: 
                   12464:     my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   12465:         $clientunicode,$clientos) = &decode_user_agent($r);
                   12466: 
                   12467: # ------------------------------------------------------------- Get environment
                   12468: 
                   12469:     my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
                   12470:     my ($tmp) = keys(%userenv);
                   12471:     if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   12472:     } else {
                   12473: 	undef(%userenv);
                   12474:     }
                   12475:     if (($userenv{'interface'}) && (!$form->{'interface'})) {
                   12476: 	$form->{'interface'}=$userenv{'interface'};
                   12477:     }
                   12478:     if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
                   12479: 
                   12480: # --------------- Do not trust query string to be put directly into environment
1.817     bisitz   12481:     foreach my $option ('interface','localpath','localres') {
                   12482:         $form->{$option}=~s/[\n\r\=]//gs;
1.462     albertel 12483:     }
                   12484: # --------------------------------------------------------- Write first profile
                   12485: 
                   12486:     {
                   12487: 	my %initial_env = 
                   12488: 	    ("user.name"          => $username,
                   12489: 	     "user.domain"        => $domain,
                   12490: 	     "user.home"          => $authhost,
                   12491: 	     "browser.type"       => $clientbrowser,
                   12492: 	     "browser.version"    => $clientversion,
                   12493: 	     "browser.mathml"     => $clientmathml,
                   12494: 	     "browser.unicode"    => $clientunicode,
                   12495: 	     "browser.os"         => $clientos,
                   12496: 	     "server.domain"      => $Apache::lonnet::perlvar{'lonDefDomain'},
                   12497: 	     "request.course.fn"  => '',
                   12498: 	     "request.course.uri" => '',
                   12499: 	     "request.course.sec" => '',
                   12500: 	     "request.role"       => 'cm',
                   12501: 	     "request.role.adv"   => $env{'user.adv'},
                   12502: 	     "request.host"       => $ENV{'REMOTE_ADDR'},);
                   12503: 
                   12504:         if ($form->{'localpath'}) {
                   12505: 	    $initial_env{"browser.localpath"}  = $form->{'localpath'};
                   12506: 	    $initial_env{"browser.localres"}   = $form->{'localres'};
                   12507:         }
                   12508: 	
                   12509: 	if ($form->{'interface'}) {
                   12510: 	    $form->{'interface'}=~s/\W//gs;
                   12511: 	    $initial_env{"browser.interface"} = $form->{'interface'};
                   12512: 	    $env{'browser.interface'}=$form->{'interface'};
                   12513: 	}
                   12514: 
1.981     raeburn  12515:         my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016    raeburn  12516:         my %domdef;
                   12517:         unless ($domain eq 'public') {
                   12518:             %domdef = &Apache::lonnet::get_domain_defaults($domain);
                   12519:         }
1.980     raeburn  12520: 
1.724     raeburn  12521:         foreach my $tool ('aboutme','blog','portfolio') {
                   12522:             $userenv{'availabletools.'.$tool} = 
1.980     raeburn  12523:                 &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
                   12524:                                                   undef,\%userenv,\%domdef,\%is_adv);
1.724     raeburn  12525:         }
                   12526: 
1.864     raeburn  12527:         foreach my $crstype ('official','unofficial','community') {
1.765     raeburn  12528:             $userenv{'canrequest.'.$crstype} =
                   12529:                 &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980     raeburn  12530:                                                   'reload','requestcourses',
                   12531:                                                   \%userenv,\%domdef,\%is_adv);
1.765     raeburn  12532:         }
                   12533: 
1.462     albertel 12534: 	$env{'user.environment'} = "$lonids/$cookie.id";
                   12535: 	
                   12536: 	if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
                   12537: 		 &GDBM_WRCREAT(),0640)) {
                   12538: 	    &_add_to_env(\%disk_env,\%initial_env);
                   12539: 	    &_add_to_env(\%disk_env,\%userenv,'environment.');
                   12540: 	    &_add_to_env(\%disk_env,$userroles);
1.463     albertel 12541: 	    if (ref($args->{'extra_env'})) {
                   12542: 		&_add_to_env(\%disk_env,$args->{'extra_env'});
                   12543: 	    }
1.462     albertel 12544: 	    untie(%disk_env);
                   12545: 	} else {
1.705     tempelho 12546: 	    &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
                   12547: 			   'Could not create environment storage in lonauth: '.$!.'</span>');
1.462     albertel 12548: 	    return 'error: '.$!;
                   12549: 	}
                   12550:     }
                   12551:     $env{'request.role'}='cm';
                   12552:     $env{'request.role.adv'}=$env{'user.adv'};
                   12553:     $env{'browser.type'}=$clientbrowser;
                   12554: 
                   12555:     return $cookie;
                   12556: 
                   12557: }
                   12558: 
                   12559: sub _add_to_env {
                   12560:     my ($idf,$env_data,$prefix) = @_;
1.676     raeburn  12561:     if (ref($env_data) eq 'HASH') {
                   12562:         while (my ($key,$value) = each(%$env_data)) {
                   12563: 	    $idf->{$prefix.$key} = $value;
                   12564: 	    $env{$prefix.$key}   = $value;
                   12565:         }
1.462     albertel 12566:     }
                   12567: }
                   12568: 
1.685     tempelho 12569: # --- Get the symbolic name of a problem and the url
                   12570: sub get_symb {
                   12571:     my ($request,$silent) = @_;
1.726     raeburn  12572:     (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685     tempelho 12573:     my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
                   12574:     if ($symb eq '') {
                   12575:         if (!$silent) {
                   12576:             $request->print("Unable to handle ambiguous references:$url:.");
                   12577:             return ();
                   12578:         }
                   12579:     }
                   12580:     &Apache::lonenc::check_decrypt(\$symb);
                   12581:     return ($symb);
                   12582: }
                   12583: 
                   12584: # --------------------------------------------------------------Get annotation
                   12585: 
                   12586: sub get_annotation {
                   12587:     my ($symb,$enc) = @_;
                   12588: 
                   12589:     my $key = $symb;
                   12590:     if (!$enc) {
                   12591:         $key =
                   12592:             &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
                   12593:     }
                   12594:     my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
                   12595:     return $annotation{$key};
                   12596: }
                   12597: 
                   12598: sub clean_symb {
1.731     raeburn  12599:     my ($symb,$delete_enc) = @_;
1.685     tempelho 12600: 
                   12601:     &Apache::lonenc::check_decrypt(\$symb);
                   12602:     my $enc = $env{'request.enc'};
1.731     raeburn  12603:     if ($delete_enc) {
1.730     raeburn  12604:         delete($env{'request.enc'});
                   12605:     }
1.685     tempelho 12606: 
                   12607:     return ($symb,$enc);
                   12608: }
1.462     albertel 12609: 
1.990     raeburn  12610: sub build_release_hashes {
                   12611:     my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
                   12612:     return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
                   12613:                   (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
                   12614:                   (ref($randomizetry) eq 'HASH'));
                   12615:     foreach my $key (keys(%Apache::lonnet::needsrelease)) {
                   12616:         my ($item,$name,$value) = split(/:/,$key);
                   12617:         if ($item eq 'parameter') {
                   12618:             if (ref($checkparms->{$name}) eq 'ARRAY') {
                   12619:                 unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
                   12620:                     push(@{$checkparms->{$name}},$value);
                   12621:                 }
                   12622:             } else {
                   12623:                 push(@{$checkparms->{$name}},$value);
                   12624:             }
                   12625:         } elsif ($item eq 'resourcetag') {
                   12626:             if ($name eq 'responsetype') {
                   12627:                 $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
                   12628:             }
                   12629:         } elsif ($item eq 'course') {
                   12630:             if ($name eq 'crstype') {
                   12631:                 $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
                   12632:             }
                   12633:         }
                   12634:     }
                   12635:     ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
                   12636:     ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
                   12637:     return;
                   12638: }
                   12639: 
1.41      ng       12640: =pod
                   12641: 
                   12642: =back
                   12643: 
1.112     bowersj2 12644: =cut
1.41      ng       12645: 
1.112     bowersj2 12646: 1;
                   12647: __END__;
1.41      ng       12648: 

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