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

1.10      albertel    1: # The LearningOnline Network with CAPA
1.1       albertel    2: # a pile of common routines
1.10      albertel    3: #
1.1027  ! raeburn     4: # $Id: loncommon.pm,v 1.1026 2011/10/31 17:27:15 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.12      harris41  157: my %cprtag;
1.192     taceyjo1  158: my %scprtag;
1.351     www       159: my %fe; my %fd; my %fm;
1.41      ng        160: my %category_extensions;
1.12      harris41  161: 
1.46      matthew   162: # ---------------------------------------------- Thesaurus variables
1.144     matthew   163: #
                    164: # %Keywords:
                    165: #      A hash used by &keyword to determine if a word is considered a keyword.
                    166: # $thesaurus_db_file 
                    167: #      Scalar containing the full path to the thesaurus database.
1.46      matthew   168: 
                    169: my %Keywords;
                    170: my $thesaurus_db_file;
                    171: 
1.144     matthew   172: #
                    173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
                    174: # thesaurus.tab, and filecategories.tab.
                    175: #
1.18      www       176: BEGIN {
1.46      matthew   177:     # Variable initialization
                    178:     $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
                    179:     #
1.22      www       180:     unless ($readit) {
1.12      harris41  181: # ------------------------------------------------------------------- languages
                    182:     {
1.158     raeburn   183:         my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    184:                                    '/language.tab';
                    185:         if ( open(my $fh,"<$langtabfile") ) {
1.356     albertel  186:             while (my $line = <$fh>) {
                    187:                 next if ($line=~/^\#/);
                    188:                 chomp($line);
                    189:                 my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158     raeburn   190:                 $language{$key}=$val.' - '.$enc;
                    191:                 if ($sup) {
                    192:                     $supported_language{$key}=$sup;
                    193:                 }
                    194:             }
                    195:             close($fh);
                    196:         }
1.12      harris41  197:     }
                    198: # ------------------------------------------------------------------ copyrights
                    199:     {
1.158     raeburn   200:         my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
                    201:                                   '/copyright.tab';
                    202:         if ( open (my $fh,"<$copyrightfile") ) {
1.356     albertel  203:             while (my $line = <$fh>) {
                    204:                 next if ($line=~/^\#/);
                    205:                 chomp($line);
                    206:                 my ($key,$val)=(split(/\s+/,$line,2));
1.158     raeburn   207:                 $cprtag{$key}=$val;
                    208:             }
                    209:             close($fh);
                    210:         }
1.12      harris41  211:     }
1.351     www       212: # ----------------------------------------------------------- source copyrights
1.192     taceyjo1  213:     {
                    214:         my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
                    215:                                   '/source_copyright.tab';
                    216:         if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356     albertel  217:             while (my $line = <$fh>) {
                    218:                 next if ($line =~ /^\#/);
                    219:                 chomp($line);
                    220:                 my ($key,$val)=(split(/\s+/,$line,2));
1.192     taceyjo1  221:                 $scprtag{$key}=$val;
                    222:             }
                    223:             close($fh);
                    224:         }
                    225:     }
1.63      www       226: 
1.517     raeburn   227: # -------------------------------------------------------------- default domain designs
1.63      www       228:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517     raeburn   229:     my $designfile = $designdir.'/default.tab';
                    230:     if ( open (my $fh,"<$designfile") ) {
                    231:         while (my $line = <$fh>) {
                    232:             next if ($line =~ /^\#/);
                    233:             chomp($line);
                    234:             my ($key,$val)=(split(/\=/,$line));
                    235:             if ($val) { $defaultdesign{$key}=$val; }
                    236:         }
                    237:         close($fh);
1.63      www       238:     }
                    239: 
1.15      harris41  240: # ------------------------------------------------------------- file categories
                    241:     {
1.158     raeburn   242:         my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    243:                                   '/filecategories.tab';
                    244:         if ( open (my $fh,"<$categoryfile") ) {
1.356     albertel  245: 	    while (my $line = <$fh>) {
                    246: 		next if ($line =~ /^\#/);
                    247: 		chomp($line);
                    248:                 my ($extension,$category)=(split(/\s+/,$line,2));
1.158     raeburn   249:                 push @{$category_extensions{lc($category)}},$extension;
                    250:             }
                    251:             close($fh);
                    252:         }
                    253: 
1.15      harris41  254:     }
1.12      harris41  255: # ------------------------------------------------------------------ file types
                    256:     {
1.158     raeburn   257:         my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    258:                '/filetypes.tab';
                    259:         if ( open (my $fh,"<$typesfile") ) {
1.356     albertel  260:             while (my $line = <$fh>) {
                    261: 		next if ($line =~ /^\#/);
                    262: 		chomp($line);
                    263:                 my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158     raeburn   264:                 if ($descr ne '') {
                    265:                     $fe{$ending}=lc($emb);
                    266:                     $fd{$ending}=$descr;
1.351     www       267:                     if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158     raeburn   268:                 }
                    269:             }
                    270:             close($fh);
                    271:         }
1.12      harris41  272:     }
1.22      www       273:     &Apache::lonnet::logthis(
1.705     tempelho  274:              "<span style='color:yellow;'>INFO: Read file types</span>");
1.22      www       275:     $readit=1;
1.46      matthew   276:     }  # end of unless($readit) 
1.32      matthew   277:     
                    278: }
1.112     bowersj2  279: 
1.42      matthew   280: ###############################################################
                    281: ##           HTML and Javascript Helper Functions            ##
                    282: ###############################################################
                    283: 
                    284: =pod 
                    285: 
1.112     bowersj2  286: =head1 HTML and Javascript Functions
1.42      matthew   287: 
1.112     bowersj2  288: =over 4
                    289: 
1.648     raeburn   290: =item * &browser_and_searcher_javascript()
1.112     bowersj2  291: 
                    292: X<browsing, javascript>X<searching, javascript>Returns a string
                    293: containing javascript with two functions, C<openbrowser> and
                    294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
                    295: tags.
1.42      matthew   296: 
1.648     raeburn   297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42      matthew   298: 
                    299: inputs: formname, elementname, only, omit
                    300: 
                    301: formname and elementname indicate the name of the html form and name of
                    302: the element that the results of the browsing selection are to be placed in. 
                    303: 
                    304: Specifying 'only' will restrict the browser to displaying only files
1.185     www       305: with the given extension.  Can be a comma separated list.
1.42      matthew   306: 
                    307: Specifying 'omit' will restrict the browser to NOT displaying files
1.185     www       308: with the given extension.  Can be a comma separated list.
1.42      matthew   309: 
1.648     raeburn   310: =item * &opensearcher(formname,elementname) [javascript]
1.42      matthew   311: 
                    312: Inputs: formname, elementname
                    313: 
                    314: formname and elementname specify the name of the html form and the name
                    315: of the element the selection from the search results will be placed in.
1.542     raeburn   316: 
1.42      matthew   317: =cut
                    318: 
                    319: sub browser_and_searcher_javascript {
1.199     albertel  320:     my ($mode)=@_;
                    321:     if (!defined($mode)) { $mode='edit'; }
1.453     albertel  322:     my $resurl=&escape_single(&lastresurl());
1.42      matthew   323:     return <<END;
1.219     albertel  324: // <!-- BEGIN LON-CAPA Internal
1.50      matthew   325:     var editbrowser = null;
1.135     albertel  326:     function openbrowser(formname,elementname,only,omit,titleelement) {
1.170     www       327:         var url = '$resurl/?';
1.42      matthew   328:         if (editbrowser == null) {
                    329:             url += 'launch=1&';
                    330:         }
                    331:         url += 'catalogmode=interactive&';
1.199     albertel  332:         url += 'mode=$mode&';
1.611     albertel  333:         url += 'inhibitmenu=yes&';
1.42      matthew   334:         url += 'form=' + formname + '&';
                    335:         if (only != null) {
                    336:             url += 'only=' + only + '&';
1.217     albertel  337:         } else {
                    338:             url += 'only=&';
                    339: 	}
1.42      matthew   340:         if (omit != null) {
                    341:             url += 'omit=' + omit + '&';
1.217     albertel  342:         } else {
                    343:             url += 'omit=&';
                    344: 	}
1.135     albertel  345:         if (titleelement != null) {
                    346:             url += 'titleelement=' + titleelement + '&';
1.217     albertel  347:         } else {
                    348: 	    url += 'titleelement=&';
                    349: 	}
1.42      matthew   350:         url += 'element=' + elementname + '';
                    351:         var title = 'Browser';
1.435     albertel  352:         var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42      matthew   353:         options += ',width=700,height=600';
                    354:         editbrowser = open(url,title,options,'1');
                    355:         editbrowser.focus();
                    356:     }
                    357:     var editsearcher;
1.135     albertel  358:     function opensearcher(formname,elementname,titleelement) {
1.42      matthew   359:         var url = '/adm/searchcat?';
                    360:         if (editsearcher == null) {
                    361:             url += 'launch=1&';
                    362:         }
                    363:         url += 'catalogmode=interactive&';
1.199     albertel  364:         url += 'mode=$mode&';
1.42      matthew   365:         url += 'form=' + formname + '&';
1.135     albertel  366:         if (titleelement != null) {
                    367:             url += 'titleelement=' + titleelement + '&';
1.217     albertel  368:         } else {
                    369: 	    url += 'titleelement=&';
                    370: 	}
1.42      matthew   371:         url += 'element=' + elementname + '';
                    372:         var title = 'Search';
1.435     albertel  373:         var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42      matthew   374:         options += ',width=700,height=600';
                    375:         editsearcher = open(url,title,options,'1');
                    376:         editsearcher.focus();
                    377:     }
1.219     albertel  378: // END LON-CAPA Internal -->
1.42      matthew   379: END
1.170     www       380: }
                    381: 
                    382: sub lastresurl {
1.258     albertel  383:     if ($env{'environment.lastresurl'}) {
                    384: 	return $env{'environment.lastresurl'}
1.170     www       385:     } else {
                    386: 	return '/res';
                    387:     }
                    388: }
                    389: 
                    390: sub storeresurl {
                    391:     my $resurl=&Apache::lonnet::clutter(shift);
                    392:     unless ($resurl=~/^\/res/) { return 0; }
                    393:     $resurl=~s/\/$//;
                    394:     &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646     raeburn   395:     &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170     www       396:     return 1;
1.42      matthew   397: }
                    398: 
1.74      www       399: sub studentbrowser_javascript {
1.111     www       400:    unless (
1.258     albertel  401:             (($env{'request.course.id'}) && 
1.302     albertel  402:              (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    403: 	      || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                    404: 					  '/'.$env{'request.course.sec'})
                    405: 	      ))
1.258     albertel  406:          || ($env{'request.role'}=~/^(au|dc|su)/)
1.111     www       407:           ) { return ''; }  
1.74      www       408:    return (<<'ENDSTDBRW');
1.776     bisitz    409: <script type="text/javascript" language="Javascript">
1.824     bisitz    410: // <![CDATA[
1.74      www       411:     var stdeditbrowser;
1.999     www       412:     function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74      www       413:         var url = '/adm/pickstudent?';
                    414:         var filter;
1.558     albertel  415: 	if (!ignorefilter) {
                    416: 	    eval('filter=document.'+formname+'.'+uname+'.value;');
                    417: 	}
1.74      www       418:         if (filter != null) {
                    419:            if (filter != '') {
                    420:                url += 'filter='+filter+'&';
                    421: 	   }
                    422:         }
                    423:         url += 'form=' + formname + '&unameelement='+uname+
1.999     www       424:                                     '&udomelement='+udom+
                    425:                                     '&clicker='+clicker;
1.111     www       426: 	if (roleflag) { url+="&roles=1"; }
1.793     raeburn   427:         if (courseadvonly) { url+="&courseadvonly=1"; }
1.102     www       428:         var title = 'Student_Browser';
1.74      www       429:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    430:         options += ',width=700,height=600';
                    431:         stdeditbrowser = open(url,title,options,'1');
                    432:         stdeditbrowser.focus();
                    433:     }
1.824     bisitz    434: // ]]>
1.74      www       435: </script>
                    436: ENDSTDBRW
                    437: }
1.42      matthew   438: 
1.1003    www       439: sub resourcebrowser_javascript {
                    440:    unless ($env{'request.course.id'}) { return ''; }
1.1004    www       441:    return (<<'ENDRESBRW');
1.1003    www       442: <script type="text/javascript" language="Javascript">
                    443: // <![CDATA[
                    444:     var reseditbrowser;
1.1004    www       445:     function openresbrowser(formname,reslink) {
1.1005    www       446:         var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003    www       447:         var title = 'Resource_Browser';
                    448:         var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005    www       449:         options += ',width=700,height=500';
1.1004    www       450:         reseditbrowser = open(url,title,options,'1');
                    451:         reseditbrowser.focus();
1.1003    www       452:     }
                    453: // ]]>
                    454: </script>
1.1004    www       455: ENDRESBRW
1.1003    www       456: }
                    457: 
1.74      www       458: sub selectstudent_link {
1.999     www       459:    my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
                    460:    my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
                    461:                       &Apache::lonhtmlcommon::entity_encode($unameele)."','".
                    462:                       &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258     albertel  463:    if ($env{'request.course.id'}) {  
1.302     albertel  464:        if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    465: 	   && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                    466: 					'/'.$env{'request.course.sec'})) {
1.111     www       467: 	   return '';
                    468:        }
1.999     www       469:        $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793     raeburn   470:        if ($courseadvonly)  {
                    471:            $callargs .= ",'',1,1";
                    472:        }
                    473:        return '<span class="LC_nobreak">'.
                    474:               '<a href="javascript:openstdbrowser('.$callargs.');">'.
                    475:               &mt('Select User').'</a></span>';
1.74      www       476:    }
1.258     albertel  477:    if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012    www       478:        $callargs .= ",'',1"; 
1.793     raeburn   479:        return '<span class="LC_nobreak">'.
                    480:               '<a href="javascript:openstdbrowser('.$callargs.');">'.
                    481:               &mt('Select User').'</a></span>';
1.111     www       482:    }
                    483:    return '';
1.91      www       484: }
                    485: 
1.1004    www       486: sub selectresource_link {
                    487:    my ($form,$reslink,$arg)=@_;
                    488:    
                    489:    my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
                    490:                       &Apache::lonhtmlcommon::entity_encode($reslink)."'";
                    491:    unless ($env{'request.course.id'}) { return $arg; }
                    492:    return '<span class="LC_nobreak">'.
                    493:               '<a href="javascript:openresbrowser('.$callargs.');">'.
                    494:               $arg.'</a></span>';
                    495: }
                    496: 
                    497: 
                    498: 
1.653     raeburn   499: sub authorbrowser_javascript {
                    500:     return <<"ENDAUTHORBRW";
1.776     bisitz    501: <script type="text/javascript" language="JavaScript">
1.824     bisitz    502: // <![CDATA[
1.653     raeburn   503: var stdeditbrowser;
                    504: 
                    505: function openauthorbrowser(formname,udom) {
                    506:     var url = '/adm/pickauthor?';
                    507:     url += 'form='+formname+'&roledom='+udom;
                    508:     var title = 'Author_Browser';
                    509:     var options = 'scrollbars=1,resizable=1,menubar=0';
                    510:     options += ',width=700,height=600';
                    511:     stdeditbrowser = open(url,title,options,'1');
                    512:     stdeditbrowser.focus();
                    513: }
                    514: 
1.824     bisitz    515: // ]]>
1.653     raeburn   516: </script>
                    517: ENDAUTHORBRW
                    518: }
                    519: 
1.91      www       520: sub coursebrowser_javascript {
1.909     raeburn   521:     my ($domainfilter,$sec_element,$formname,$role_element,$crstype) = @_;
1.932     raeburn   522:     my $wintitle = 'Course_Browser';
1.931     raeburn   523:     if ($crstype eq 'Community') {
1.932     raeburn   524:         $wintitle = 'Community_Browser';
1.909     raeburn   525:     }
1.876     raeburn   526:     my $id_functions = &javascript_index_functions();
                    527:     my $output = '
1.776     bisitz    528: <script type="text/javascript" language="JavaScript">
1.824     bisitz    529: // <![CDATA[
1.468     raeburn   530:     var stdeditbrowser;'."\n";
1.876     raeburn   531: 
                    532:     $output .= <<"ENDSTDBRW";
1.909     raeburn   533:     function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91      www       534:         var url = '/adm/pickcourse?';
1.895     raeburn   535:         var formid = getFormIdByName(formname);
1.876     raeburn   536:         var domainfilter = getDomainFromSelectbox(formname,udom);
1.128     albertel  537:         if (domainfilter != null) {
                    538:            if (domainfilter != '') {
                    539:                url += 'domainfilter='+domainfilter+'&';
                    540: 	   }
                    541:         }
1.91      www       542:         url += 'form=' + formname + '&cnumelement='+uname+
1.187     albertel  543: 	                            '&cdomelement='+udom+
                    544:                                     '&cnameelement='+desc;
1.468     raeburn   545:         if (extra_element !=null && extra_element != '') {
1.594     raeburn   546:             if (formname == 'rolechoice' || formname == 'studentform') {
1.468     raeburn   547:                 url += '&roleelement='+extra_element;
                    548:                 if (domainfilter == null || domainfilter == '') {
                    549:                     url += '&domainfilter='+extra_element;
                    550:                 }
1.234     raeburn   551:             }
1.468     raeburn   552:             else {
                    553:                 if (formname == 'portform') {
                    554:                     url += '&setroles='+extra_element;
1.800     raeburn   555:                 } else {
                    556:                     if (formname == 'rules') {
                    557:                         url += '&fixeddom='+extra_element; 
                    558:                     }
1.468     raeburn   559:                 }
                    560:             }     
1.230     raeburn   561:         }
1.909     raeburn   562:         if (type != null && type != '') {
                    563:             url += '&type='+type;
                    564:         }
                    565:         if (type_elem != null && type_elem != '') {
                    566:             url += '&typeelement='+type_elem;
                    567:         }
1.872     raeburn   568:         if (formname == 'ccrs') {
                    569:             var ownername = document.forms[formid].ccuname.value;
                    570:             var ownerdom =  document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
                    571:             url += '&cloner='+ownername+':'+ownerdom;
                    572:         }
1.293     raeburn   573:         if (multflag !=null && multflag != '') {
                    574:             url += '&multiple='+multflag;
                    575:         }
1.909     raeburn   576:         var title = '$wintitle';
1.91      www       577:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    578:         options += ',width=700,height=600';
                    579:         stdeditbrowser = open(url,title,options,'1');
                    580:         stdeditbrowser.focus();
                    581:     }
1.876     raeburn   582: $id_functions
                    583: ENDSTDBRW
1.905     raeburn   584:     if (($sec_element ne '') || ($role_element ne '')) {
                    585:         $output .= &setsec_javascript($sec_element,$formname,$role_element);
1.876     raeburn   586:     }
                    587:     $output .= '
                    588: // ]]>
                    589: </script>';
                    590:     return $output;
                    591: }
                    592: 
                    593: sub javascript_index_functions {
                    594:     return <<"ENDJS";
                    595: 
                    596: function getFormIdByName(formname) {
                    597:     for (var i=0;i<document.forms.length;i++) {
                    598:         if (document.forms[i].name == formname) {
                    599:             return i;
                    600:         }
                    601:     }
                    602:     return -1;
                    603: }
                    604: 
                    605: function getIndexByName(formid,item) {
                    606:     for (var i=0;i<document.forms[formid].elements.length;i++) {
                    607:         if (document.forms[formid].elements[i].name == item) {
                    608:             return i;
                    609:         }
                    610:     }
                    611:     return -1;
                    612: }
1.468     raeburn   613: 
1.876     raeburn   614: function getDomainFromSelectbox(formname,udom) {
                    615:     var userdom;
                    616:     var formid = getFormIdByName(formname);
                    617:     if (formid > -1) {
                    618:         var domid = getIndexByName(formid,udom);
                    619:         if (domid > -1) {
                    620:             if (document.forms[formid].elements[domid].type == 'select-one') {
                    621:                 userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
                    622:             }
                    623:             if (document.forms[formid].elements[domid].type == 'hidden') {
                    624:                 userdom=document.forms[formid].elements[domid].value;
1.468     raeburn   625:             }
                    626:         }
                    627:     }
1.876     raeburn   628:     return userdom;
                    629: }
                    630: 
                    631: ENDJS
1.468     raeburn   632: 
1.876     raeburn   633: }
                    634: 
1.1017    raeburn   635: sub javascript_array_indexof {
1.1018    raeburn   636:     return <<ENDJS;
1.1017    raeburn   637: <script type="text/javascript" language="JavaScript">
                    638: // <![CDATA[
                    639: 
                    640: if (!Array.prototype.indexOf) {
                    641:     Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
                    642:         "use strict";
                    643:         if (this === void 0 || this === null) {
                    644:             throw new TypeError();
                    645:         }
                    646:         var t = Object(this);
                    647:         var len = t.length >>> 0;
                    648:         if (len === 0) {
                    649:             return -1;
                    650:         }
                    651:         var n = 0;
                    652:         if (arguments.length > 0) {
                    653:             n = Number(arguments[1]);
                    654:             if (n !== n) { // shortcut for verifying if it's NaN
                    655:                 n = 0;
                    656:             } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
                    657:                 n = (n > 0 || -1) * Math.floor(Math.abs(n));
                    658:             }
                    659:         }
                    660:         if (n >= len) {
                    661:             return -1;
                    662:         }
                    663:         var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
                    664:         for (; k < len; k++) {
                    665:             if (k in t && t[k] === searchElement) {
                    666:                 return k;
                    667:             }
                    668:         }
                    669:         return -1;
                    670:     }
                    671: }
                    672: 
                    673: // ]]>
                    674: </script>
                    675: 
                    676: ENDJS
                    677: 
                    678: }
                    679: 
1.876     raeburn   680: sub userbrowser_javascript {
                    681:     my $id_functions = &javascript_index_functions();
                    682:     return <<"ENDUSERBRW";
                    683: 
1.888     raeburn   684: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876     raeburn   685:     var url = '/adm/pickuser?';
                    686:     var userdom = getDomainFromSelectbox(formname,udom);
                    687:     if (userdom != null) {
                    688:        if (userdom != '') {
                    689:            url += 'srchdom='+userdom+'&';
                    690:        }
                    691:     }
                    692:     url += 'form=' + formname + '&unameelement='+uname+
                    693:                                 '&udomelement='+udom+
                    694:                                 '&ulastelement='+ulast+
                    695:                                 '&ufirstelement='+ufirst+
                    696:                                 '&uemailelement='+uemail+
1.881     raeburn   697:                                 '&hideudomelement='+hideudom+
                    698:                                 '&coursedom='+crsdom;
1.888     raeburn   699:     if ((caller != null) && (caller != undefined)) {
                    700:         url += '&caller='+caller;
                    701:     }
1.876     raeburn   702:     var title = 'User_Browser';
                    703:     var options = 'scrollbars=1,resizable=1,menubar=0';
                    704:     options += ',width=700,height=600';
                    705:     var stdeditbrowser = open(url,title,options,'1');
                    706:     stdeditbrowser.focus();
                    707: }
                    708: 
1.888     raeburn   709: function fix_domain (formname,udom,origdom,uname) {
1.876     raeburn   710:     var formid = getFormIdByName(formname);
                    711:     if (formid > -1) {
1.888     raeburn   712:         var unameid = getIndexByName(formid,uname);
1.876     raeburn   713:         var domid = getIndexByName(formid,udom);
                    714:         var hidedomid = getIndexByName(formid,origdom);
                    715:         if (hidedomid > -1) {
                    716:             var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888     raeburn   717:             var unameval = document.forms[formid].elements[unameid].value;
                    718:             if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
                    719:                 if (domid > -1) {
                    720:                     var slct = document.forms[formid].elements[domid];
                    721:                     if (slct.type == 'select-one') {
                    722:                         var i;
                    723:                         for (i=0;i<slct.length;i++) {
                    724:                             if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
                    725:                         }
                    726:                     }
                    727:                     if (slct.type == 'hidden') {
                    728:                         slct.value = fixeddom;
1.876     raeburn   729:                     }
                    730:                 }
1.468     raeburn   731:             }
                    732:         }
                    733:     }
1.876     raeburn   734:     return;
                    735: }
                    736: 
                    737: $id_functions
                    738: ENDUSERBRW
1.468     raeburn   739: }
                    740: 
                    741: sub setsec_javascript {
1.905     raeburn   742:     my ($sec_element,$formname,$role_element) = @_;
                    743:     my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
                    744:         $communityrolestr);
                    745:     if ($role_element ne '') {
                    746:         my @allroles = ('st','ta','ep','in','ad');
                    747:         foreach my $crstype ('Course','Community') {
                    748:             if ($crstype eq 'Community') {
                    749:                 foreach my $role (@allroles) {
                    750:                     push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
                    751:                 }
                    752:                 push(@communityrolenames,&Apache::lonnet::plaintext('co'));
                    753:             } else {
                    754:                 foreach my $role (@allroles) {
                    755:                     push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
                    756:                 }
                    757:                 push(@courserolenames,&Apache::lonnet::plaintext('cc'));
                    758:             }
                    759:         }
                    760:         $rolestr = '"'.join('","',@allroles).'"';
                    761:         $courserolestr = '"'.join('","',@courserolenames).'"';
                    762:         $communityrolestr = '"'.join('","',@communityrolenames).'"';
                    763:     }
1.468     raeburn   764:     my $setsections = qq|
                    765: function setSect(sectionlist) {
1.629     raeburn   766:     var sectionsArray = new Array();
                    767:     if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
                    768:         sectionsArray = sectionlist.split(",");
                    769:     }
1.468     raeburn   770:     var numSections = sectionsArray.length;
                    771:     document.$formname.$sec_element.length = 0;
                    772:     if (numSections == 0) {
                    773:         document.$formname.$sec_element.multiple=false;
                    774:         document.$formname.$sec_element.size=1;
                    775:         document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
                    776:     } else {
                    777:         if (numSections == 1) {
                    778:             document.$formname.$sec_element.multiple=false;
                    779:             document.$formname.$sec_element.size=1;
                    780:             document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
                    781:             document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
                    782:             document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
                    783:         } else {
                    784:             for (var i=0; i<numSections; i++) {
                    785:                 document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
                    786:             }
                    787:             document.$formname.$sec_element.multiple=true
                    788:             if (numSections < 3) {
                    789:                 document.$formname.$sec_element.size=numSections;
                    790:             } else {
                    791:                 document.$formname.$sec_element.size=3;
                    792:             }
                    793:             document.$formname.$sec_element.options[0].selected = false
                    794:         }
                    795:     }
1.91      www       796: }
1.905     raeburn   797: 
                    798: function setRole(crstype) {
1.468     raeburn   799: |;
1.905     raeburn   800:     if ($role_element eq '') {
                    801:         $setsections .= '    return;
                    802: }
                    803: ';
                    804:     } else {
                    805:         $setsections .= qq|
                    806:     var elementLength = document.$formname.$role_element.length;
                    807:     var allroles = Array($rolestr);
                    808:     var courserolenames = Array($courserolestr);
                    809:     var communityrolenames = Array($communityrolestr);
                    810:     if (elementLength != undefined) {
                    811:         if (document.$formname.$role_element.options[5].value == 'cc') {
                    812:             if (crstype == 'Course') {
                    813:                 return;
                    814:             } else {
                    815:                 allroles[5] = 'co';
                    816:                 for (var i=0; i<6; i++) {
                    817:                     document.$formname.$role_element.options[i].value = allroles[i];
                    818:                     document.$formname.$role_element.options[i].text = communityrolenames[i];
                    819:                 }
                    820:             }
                    821:         } else {
                    822:             if (crstype == 'Community') {
                    823:                 return;
                    824:             } else {
                    825:                 allroles[5] = 'cc';
                    826:                 for (var i=0; i<6; i++) {
                    827:                     document.$formname.$role_element.options[i].value = allroles[i];
                    828:                     document.$formname.$role_element.options[i].text = courserolenames[i];
                    829:                 }
                    830:             }
                    831:         }
                    832:     }
                    833:     return;
                    834: }
                    835: |;
                    836:     }
1.468     raeburn   837:     return $setsections;
                    838: }
                    839: 
1.91      www       840: sub selectcourse_link {
1.909     raeburn   841:    my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
                    842:        $typeelement) = @_;
                    843:    my $type = $selecttype;
1.871     raeburn   844:    my $linktext = &mt('Select Course');
                    845:    if ($selecttype eq 'Community') {
1.909     raeburn   846:        $linktext = &mt('Select Community');
1.906     raeburn   847:    } elsif ($selecttype eq 'Course/Community') {
                    848:        $linktext = &mt('Select Course/Community');
1.909     raeburn   849:        $type = '';
1.1019    raeburn   850:    } elsif ($selecttype eq 'Select') {
                    851:        $linktext = &mt('Select');
                    852:        $type = '';
1.871     raeburn   853:    }
1.787     bisitz    854:    return '<span class="LC_nobreak">'
                    855:          ."<a href='"
                    856:          .'javascript:opencrsbrowser("'.$form.'","'.$unameele
                    857:          .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909     raeburn   858:          .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871     raeburn   859:          ."'>".$linktext.'</a>'
1.787     bisitz    860:          .'</span>';
1.74      www       861: }
1.42      matthew   862: 
1.653     raeburn   863: sub selectauthor_link {
                    864:    my ($form,$udom)=@_;
                    865:    return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
                    866:           &mt('Select Author').'</a>';
                    867: }
                    868: 
1.876     raeburn   869: sub selectuser_link {
1.881     raeburn   870:     my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888     raeburn   871:         $coursedom,$linktext,$caller) = @_;
1.876     raeburn   872:     return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888     raeburn   873:            "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881     raeburn   874:            ');">'.$linktext.'</a>';
1.876     raeburn   875: }
                    876: 
1.273     raeburn   877: sub check_uncheck_jscript {
                    878:     my $jscript = <<"ENDSCRT";
                    879: function checkAll(field) {
                    880:     if (field.length > 0) {
                    881:         for (i = 0; i < field.length; i++) {
                    882:             field[i].checked = true ;
                    883:         }
                    884:     } else {
                    885:         field.checked = true
                    886:     }
                    887: }
                    888:  
                    889: function uncheckAll(field) {
                    890:     if (field.length > 0) {
                    891:         for (i = 0; i < field.length; i++) {
                    892:             field[i].checked = false ;
1.543     albertel  893:         }
                    894:     } else {
1.273     raeburn   895:         field.checked = false ;
                    896:     }
                    897: }
                    898: ENDSCRT
                    899:     return $jscript;
                    900: }
                    901: 
1.656     www       902: sub select_timezone {
1.659     raeburn   903:    my ($name,$selected,$onchange,$includeempty)=@_;
                    904:    my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    905:    if ($includeempty) {
                    906:        $output .= '<option value=""';
                    907:        if (($selected eq '') || ($selected eq 'local')) {
                    908:            $output .= ' selected="selected" ';
                    909:        }
                    910:        $output .= '> </option>';
                    911:    }
1.657     raeburn   912:    my @timezones = DateTime::TimeZone->all_names;
                    913:    foreach my $tzone (@timezones) {
                    914:        $output.= '<option value="'.$tzone.'"';
                    915:        if ($tzone eq $selected) {
                    916:            $output.=' selected="selected"';
                    917:        }
                    918:        $output.=">$tzone</option>\n";
1.656     www       919:    }
                    920:    $output.="</select>";
                    921:    return $output;
                    922: }
1.273     raeburn   923: 
1.687     raeburn   924: sub select_datelocale {
                    925:     my ($name,$selected,$onchange,$includeempty)=@_;
                    926:     my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    927:     if ($includeempty) {
                    928:         $output .= '<option value=""';
                    929:         if ($selected eq '') {
                    930:             $output .= ' selected="selected" ';
                    931:         }
                    932:         $output .= '> </option>';
                    933:     }
                    934:     my (@possibles,%locale_names);
                    935:     my @locales = DateTime::Locale::Catalog::Locales;
                    936:     foreach my $locale (@locales) {
                    937:         if (ref($locale) eq 'HASH') {
                    938:             my $id = $locale->{'id'};
                    939:             if ($id ne '') {
                    940:                 my $en_terr = $locale->{'en_territory'};
                    941:                 my $native_terr = $locale->{'native_territory'};
1.695     raeburn   942:                 my @languages = &Apache::lonlocal::preferred_languages();
1.687     raeburn   943:                 if (grep(/^en$/,@languages) || !@languages) {
                    944:                     if ($en_terr ne '') {
                    945:                         $locale_names{$id} = '('.$en_terr.')';
                    946:                     } elsif ($native_terr ne '') {
                    947:                         $locale_names{$id} = $native_terr;
                    948:                     }
                    949:                 } else {
                    950:                     if ($native_terr ne '') {
                    951:                         $locale_names{$id} = $native_terr.' ';
                    952:                     } elsif ($en_terr ne '') {
                    953:                         $locale_names{$id} = '('.$en_terr.')';
                    954:                     }
                    955:                 }
                    956:                 push (@possibles,$id);
                    957:             }
                    958:         }
                    959:     }
                    960:     foreach my $item (sort(@possibles)) {
                    961:         $output.= '<option value="'.$item.'"';
                    962:         if ($item eq $selected) {
                    963:             $output.=' selected="selected"';
                    964:         }
                    965:         $output.=">$item";
                    966:         if ($locale_names{$item} ne '') {
                    967:             $output.="  $locale_names{$item}</option>\n";
                    968:         }
                    969:         $output.="</option>\n";
                    970:     }
                    971:     $output.="</select>";
                    972:     return $output;
                    973: }
                    974: 
1.792     raeburn   975: sub select_language {
                    976:     my ($name,$selected,$includeempty) = @_;
                    977:     my %langchoices;
                    978:     if ($includeempty) {
                    979:         %langchoices = ('' => 'No language preference');
                    980:     }
                    981:     foreach my $id (&languageids()) {
                    982:         my $code = &supportedlanguagecode($id);
                    983:         if ($code) {
                    984:             $langchoices{$code} = &plainlanguagedescription($id);
                    985:         }
                    986:     }
1.970     raeburn   987:     return &select_form($selected,$name,\%langchoices);
1.792     raeburn   988: }
                    989: 
1.42      matthew   990: =pod
1.36      matthew   991: 
1.648     raeburn   992: =item * &linked_select_forms(...)
1.36      matthew   993: 
                    994: linked_select_forms returns a string containing a <script></script> block
                    995: and html for two <select> menus.  The select menus will be linked in that
                    996: changing the value of the first menu will result in new values being placed
                    997: in the second menu.  The values in the select menu will appear in alphabetical
1.609     raeburn   998: order unless a defined order is provided.
1.36      matthew   999: 
                   1000: linked_select_forms takes the following ordered inputs:
                   1001: 
                   1002: =over 4
                   1003: 
1.112     bowersj2 1004: =item * $formname, the name of the <form> tag
1.36      matthew  1005: 
1.112     bowersj2 1006: =item * $middletext, the text which appears between the <select> tags
1.36      matthew  1007: 
1.112     bowersj2 1008: =item * $firstdefault, the default value for the first menu
1.36      matthew  1009: 
1.112     bowersj2 1010: =item * $firstselectname, the name of the first <select> tag
1.36      matthew  1011: 
1.112     bowersj2 1012: =item * $secondselectname, the name of the second <select> tag
1.36      matthew  1013: 
1.112     bowersj2 1014: =item * $hashref, a reference to a hash containing the data for the menus.
1.36      matthew  1015: 
1.609     raeburn  1016: =item * $menuorder, the order of values in the first menu
                   1017: 
1.41      ng       1018: =back 
                   1019: 
1.36      matthew  1020: Below is an example of such a hash.  Only the 'text', 'default', and 
                   1021: 'select2' keys must appear as stated.  keys(%menu) are the possible 
                   1022: values for the first select menu.  The text that coincides with the 
1.41      ng       1023: first menu value is given in $menu{$choice1}->{'text'}.  The values 
1.36      matthew  1024: and text for the second menu are given in the hash pointed to by 
                   1025: $menu{$choice1}->{'select2'}.  
                   1026: 
1.112     bowersj2 1027:  my %menu = ( A1 => { text =>"Choice A1" ,
                   1028:                        default => "B3",
                   1029:                        select2 => { 
                   1030:                            B1 => "Choice B1",
                   1031:                            B2 => "Choice B2",
                   1032:                            B3 => "Choice B3",
                   1033:                            B4 => "Choice B4"
1.609     raeburn  1034:                            },
                   1035:                        order => ['B4','B3','B1','B2'],
1.112     bowersj2 1036:                    },
                   1037:                A2 => { text =>"Choice A2" ,
                   1038:                        default => "C2",
                   1039:                        select2 => { 
                   1040:                            C1 => "Choice C1",
                   1041:                            C2 => "Choice C2",
                   1042:                            C3 => "Choice C3"
1.609     raeburn  1043:                            },
                   1044:                        order => ['C2','C1','C3'],
1.112     bowersj2 1045:                    },
                   1046:                A3 => { text =>"Choice A3" ,
                   1047:                        default => "D6",
                   1048:                        select2 => { 
                   1049:                            D1 => "Choice D1",
                   1050:                            D2 => "Choice D2",
                   1051:                            D3 => "Choice D3",
                   1052:                            D4 => "Choice D4",
                   1053:                            D5 => "Choice D5",
                   1054:                            D6 => "Choice D6",
                   1055:                            D7 => "Choice D7"
1.609     raeburn  1056:                            },
                   1057:                        order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112     bowersj2 1058:                    }
                   1059:                );
1.36      matthew  1060: 
                   1061: =cut
                   1062: 
                   1063: sub linked_select_forms {
                   1064:     my ($formname,
                   1065:         $middletext,
                   1066:         $firstdefault,
                   1067:         $firstselectname,
                   1068:         $secondselectname, 
1.609     raeburn  1069:         $hashref,
                   1070:         $menuorder,
1.36      matthew  1071:         ) = @_;
                   1072:     my $second = "document.$formname.$secondselectname";
                   1073:     my $first = "document.$formname.$firstselectname";
                   1074:     # output the javascript to do the changing
                   1075:     my $result = '';
1.776     bisitz   1076:     $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824     bisitz   1077:     $result.="// <![CDATA[\n";
1.36      matthew  1078:     $result.="var select2data = new Object();\n";
                   1079:     $" = '","';
                   1080:     my $debug = '';
                   1081:     foreach my $s1 (sort(keys(%$hashref))) {
                   1082:         $result.="select2data.d_$s1 = new Object();\n";        
                   1083:         $result.="select2data.d_$s1.def = new String('".
                   1084:             $hashref->{$s1}->{'default'}."');\n";
1.609     raeburn  1085:         $result.="select2data.d_$s1.values = new Array(";
1.36      matthew  1086:         my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609     raeburn  1087:         if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
                   1088:             @s2values = @{$hashref->{$s1}->{'order'}};
                   1089:         }
1.36      matthew  1090:         $result.="\"@s2values\");\n";
                   1091:         $result.="select2data.d_$s1.texts = new Array(";        
                   1092:         my @s2texts;
                   1093:         foreach my $value (@s2values) {
                   1094:             push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
                   1095:         }
                   1096:         $result.="\"@s2texts\");\n";
                   1097:     }
                   1098:     $"=' ';
                   1099:     $result.= <<"END";
                   1100: 
                   1101: function select1_changed() {
                   1102:     // Determine new choice
                   1103:     var newvalue = "d_" + $first.value;
                   1104:     // update select2
                   1105:     var values     = select2data[newvalue].values;
                   1106:     var texts      = select2data[newvalue].texts;
                   1107:     var select2def = select2data[newvalue].def;
                   1108:     var i;
                   1109:     // out with the old
                   1110:     for (i = 0; i < $second.options.length; i++) {
                   1111:         $second.options[i] = null;
                   1112:     }
                   1113:     // in with the nuclear
                   1114:     for (i=0;i<values.length; i++) {
                   1115:         $second.options[i] = new Option(values[i]);
1.143     matthew  1116:         $second.options[i].value = values[i];
1.36      matthew  1117:         $second.options[i].text = texts[i];
                   1118:         if (values[i] == select2def) {
                   1119:             $second.options[i].selected = true;
                   1120:         }
                   1121:     }
                   1122: }
1.824     bisitz   1123: // ]]>
1.36      matthew  1124: </script>
                   1125: END
                   1126:     # output the initial values for the selection lists
                   1127:     $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609     raeburn  1128:     my @order = sort(keys(%{$hashref}));
                   1129:     if (ref($menuorder) eq 'ARRAY') {
                   1130:         @order = @{$menuorder};
                   1131:     }
                   1132:     foreach my $value (@order) {
1.36      matthew  1133:         $result.="    <option value=\"$value\" ";
1.253     albertel 1134:         $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119     www      1135:         $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36      matthew  1136:     }
                   1137:     $result .= "</select>\n";
                   1138:     my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
                   1139:     $result .= $middletext;
                   1140:     $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
                   1141:     my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609     raeburn  1142:     
                   1143:     my @secondorder = sort(keys(%select2));
                   1144:     if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
                   1145:         @secondorder = @{$hashref->{$firstdefault}->{'order'}};
                   1146:     }
                   1147:     foreach my $value (@secondorder) {
1.36      matthew  1148:         $result.="    <option value=\"$value\" ";        
1.253     albertel 1149:         $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119     www      1150:         $result.=">".&mt($select2{$value})."</option>\n";
1.36      matthew  1151:     }
                   1152:     $result .= "</select>\n";
                   1153:     #    return $debug;
                   1154:     return $result;
                   1155: }   #  end of sub linked_select_forms {
                   1156: 
1.45      matthew  1157: =pod
1.44      bowersj2 1158: 
1.973     raeburn  1159: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44      bowersj2 1160: 
1.112     bowersj2 1161: Returns a string corresponding to an HTML link to the given help
                   1162: $topic, where $topic corresponds to the name of a .tex file in
                   1163: /home/httpd/html/adm/help/tex, with underscores replaced by
                   1164: spaces. 
                   1165: 
                   1166: $text will optionally be linked to the same topic, allowing you to
                   1167: link text in addition to the graphic. If you do not want to link
                   1168: text, but wish to specify one of the later parameters, pass an
                   1169: empty string. 
                   1170: 
                   1171: $stayOnPage is a value that will be interpreted as a boolean. If true,
                   1172: the link will not open a new window. If false, the link will open
                   1173: a new window using Javascript. (Default is false.) 
                   1174: 
                   1175: $width and $height are optional numerical parameters that will
                   1176: override the width and height of the popped up window, which may
1.973     raeburn  1177: be useful for certain help topics with big pictures included.
                   1178: 
                   1179: $imgid is the id of the img tag used for the help icon. This may be
                   1180: used in a javascript call to switch the image src.  See 
                   1181: lonhtmlcommon::htmlareaselectactive() for an example.
1.44      bowersj2 1182: 
                   1183: =cut
                   1184: 
                   1185: sub help_open_topic {
1.973     raeburn  1186:     my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48      bowersj2 1187:     $text = "" if (not defined $text);
1.44      bowersj2 1188:     $stayOnPage = 0 if (not defined $stayOnPage);
                   1189:     $width = 350 if (not defined $width);
                   1190:     $height = 400 if (not defined $height);
                   1191:     my $filename = $topic;
                   1192:     $filename =~ s/ /_/g;
                   1193: 
1.48      bowersj2 1194:     my $template = "";
                   1195:     my $link;
1.572     banghart 1196:     
1.159     www      1197:     $topic=~s/\W/\_/g;
1.44      bowersj2 1198: 
1.572     banghart 1199:     if (!$stayOnPage) {
1.72      bowersj2 1200: 	$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 1201:     } else {
1.48      bowersj2 1202: 	$link = "/adm/help/${filename}.hlp";
                   1203:     }
                   1204: 
                   1205:     # Add the text
1.755     neumanie 1206:     if ($text ne "") {	
1.763     bisitz   1207: 	$template.='<span class="LC_help_open_topic">'
                   1208:                   .'<a target="_top" href="'.$link.'">'
                   1209:                   .$text.'</a>';
1.48      bowersj2 1210:     }
                   1211: 
1.763     bisitz   1212:     # (Always) Add the graphic
1.179     matthew  1213:     my $title = &mt('Online Help');
1.667     raeburn  1214:     my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973     raeburn  1215:     if ($imgid ne '') {
                   1216:         $imgid = ' id="'.$imgid.'"';
                   1217:     }
1.763     bisitz   1218:     $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
                   1219:               .'<img src="'.$helpicon.'" border="0"'
                   1220:               .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973     raeburn  1221:               .' title="'.$title.'" style="vertical-align:middle;"'.$imgid 
1.763     bisitz   1222:               .' /></a>';
                   1223:     if ($text ne "") {	
                   1224:         $template.='</span>';
                   1225:     }
1.44      bowersj2 1226:     return $template;
                   1227: 
1.106     bowersj2 1228: }
                   1229: 
                   1230: # This is a quicky function for Latex cheatsheet editing, since it 
                   1231: # appears in at least four places
                   1232: sub helpLatexCheatsheet {
1.732     raeburn  1233:     my ($topic,$text,$not_author) = @_;
                   1234:     my $out;
1.106     bowersj2 1235:     my $addOther = '';
1.732     raeburn  1236:     if ($topic) {
1.763     bisitz   1237: 	$addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
                   1238: 							       undef, undef, 600).
                   1239: 								   '</span> ';
                   1240:     }
                   1241:     $out = '<span>' # Start cheatsheet
                   1242: 	  .$addOther
                   1243:           .'<span>'
                   1244: 	  .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
                   1245: 					       undef,undef,600)
                   1246: 	  .'</span> <span>'
                   1247: 	  .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
                   1248: 					       undef,undef,600)
                   1249: 	  .'</span>';
1.732     raeburn  1250:     unless ($not_author) {
1.763     bisitz   1251:         $out .= ' <span>'
                   1252: 	       .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
                   1253: 	                                            undef,undef,600)
                   1254: 	       .'</span>';
1.732     raeburn  1255:     }
1.763     bisitz   1256:     $out .= '</span>'; # End cheatsheet
1.732     raeburn  1257:     return $out;
1.172     www      1258: }
                   1259: 
1.430     albertel 1260: sub general_help {
                   1261:     my $helptopic='Student_Intro';
                   1262:     if ($env{'request.role'}=~/^(ca|au)/) {
                   1263: 	$helptopic='Authoring_Intro';
1.907     raeburn  1264:     } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430     albertel 1265: 	$helptopic='Course_Coordination_Intro';
1.672     raeburn  1266:     } elsif ($env{'request.role'}=~/^dc/) {
                   1267:         $helptopic='Domain_Coordination_Intro';
1.430     albertel 1268:     }
                   1269:     return $helptopic;
                   1270: }
                   1271: 
                   1272: sub update_help_link {
                   1273:     my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
                   1274:     my $origurl = $ENV{'REQUEST_URI'};
                   1275:     $origurl=~s|^/~|/priv/|;
                   1276:     my $timestamp = time;
                   1277:     foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
                   1278:         $$datum = &escape($$datum);
                   1279:     }
                   1280: 
                   1281:     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";
                   1282:     my $output .= <<"ENDOUTPUT";
                   1283: <script type="text/javascript">
1.824     bisitz   1284: // <![CDATA[
1.430     albertel 1285: banner_link = '$banner_link';
1.824     bisitz   1286: // ]]>
1.430     albertel 1287: </script>
                   1288: ENDOUTPUT
                   1289:     return $output;
                   1290: }
                   1291: 
                   1292: # now just updates the help link and generates a blue icon
1.193     raeburn  1293: sub help_open_menu {
1.430     albertel 1294:     my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text) 
1.552     banghart 1295: 	= @_;    
1.949     droeschl 1296:     $stayOnPage = 1;
1.430     albertel 1297:     my $output;
                   1298:     if ($component_help) {
                   1299: 	if (!$text) {
                   1300: 	    $output=&help_open_topic($component_help,undef,$stayOnPage,
                   1301: 				       $width,$height);
                   1302: 	} else {
                   1303: 	    my $help_text;
                   1304: 	    $help_text=&unescape($topic);
                   1305: 	    $output='<table><tr><td>'.
                   1306: 		&help_open_topic($component_help,$help_text,$stayOnPage,
                   1307: 				 $width,$height).'</td></tr></table>';
                   1308: 	}
                   1309:     }
                   1310:     my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
                   1311:     return $output.$banner_link;
                   1312: }
                   1313: 
                   1314: sub top_nav_help {
                   1315:     my ($text) = @_;
1.436     albertel 1316:     $text = &mt($text);
1.949     droeschl 1317:     my $stay_on_page = 1;
                   1318: 
1.572     banghart 1319:     my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436     albertel 1320: 	                     : "javascript:helpMenu('open')";
1.572     banghart 1321:     my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436     albertel 1322: 
1.201     raeburn  1323:     my $title = &mt('Get help');
1.436     albertel 1324: 
                   1325:     return <<"END";
                   1326: $banner_link
                   1327:  <a href="$link" title="$title">$text</a>
                   1328: END
                   1329: }
                   1330: 
                   1331: sub help_menu_js {
                   1332:     my ($text) = @_;
1.949     droeschl 1333:     my $stayOnPage = 1;
1.436     albertel 1334:     my $width = 620;
                   1335:     my $height = 600;
1.430     albertel 1336:     my $helptopic=&general_help();
                   1337:     my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261     albertel 1338:     my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331     albertel 1339:     my $start_page =
                   1340:         &Apache::loncommon::start_page('Help Menu', undef,
                   1341: 				       {'frameset'    => 1,
                   1342: 					'js_ready'    => 1,
                   1343: 					'add_entries' => {
                   1344: 					    'border' => '0',
1.579     raeburn  1345: 					    'rows'   => "110,*",},});
1.331     albertel 1346:     my $end_page =
                   1347:         &Apache::loncommon::end_page({'frameset' => 1,
                   1348: 				      'js_ready' => 1,});
                   1349: 
1.436     albertel 1350:     my $template .= <<"ENDTEMPLATE";
                   1351: <script type="text/javascript">
1.877     bisitz   1352: // <![CDATA[
1.253     albertel 1353: // <!-- BEGIN LON-CAPA Internal
1.430     albertel 1354: var banner_link = '';
1.243     raeburn  1355: function helpMenu(target) {
                   1356:     var caller = this;
                   1357:     if (target == 'open') {
                   1358:         var newWindow = null;
                   1359:         try {
1.262     albertel 1360:             newWindow =  window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243     raeburn  1361:         }
                   1362:         catch(error) {
                   1363:             writeHelp(caller);
                   1364:             return;
                   1365:         }
                   1366:         if (newWindow) {
                   1367:             caller = newWindow;
                   1368:         }
1.193     raeburn  1369:     }
1.243     raeburn  1370:     writeHelp(caller);
                   1371:     return;
                   1372: }
                   1373: function writeHelp(caller) {
1.430     albertel 1374:     caller.document.writeln('$start_page<frame name="bannerframe"  src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243     raeburn  1375:     caller.document.close()
                   1376:     caller.focus()
1.193     raeburn  1377: }
1.877     bisitz   1378: // END LON-CAPA Internal -->
1.253     albertel 1379: // ]]>
1.436     albertel 1380: </script>
1.193     raeburn  1381: ENDTEMPLATE
                   1382:     return $template;
                   1383: }
                   1384: 
1.172     www      1385: sub help_open_bug {
                   1386:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1387:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1388:     unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
                   1389:     $text = "" if (not defined $text);
                   1390: 	$stayOnPage=1;
1.184     albertel 1391:     $width = 600 if (not defined $width);
                   1392:     $height = 600 if (not defined $height);
1.172     www      1393: 
                   1394:     $topic=~s/\W+/\+/g;
                   1395:     my $link='';
                   1396:     my $template='';
1.379     albertel 1397:     my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&amp;bug_file_loc='.
                   1398: 	&escape($ENV{'REQUEST_URI'}).'&amp;component='.$topic;
1.172     www      1399:     if (!$stayOnPage)
                   1400:     {
                   1401: 	$link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1402:     }
                   1403:     else
                   1404:     {
                   1405: 	$link = $url;
                   1406:     }
                   1407:     # Add the text
                   1408:     if ($text ne "")
                   1409:     {
                   1410: 	$template .= 
                   1411:   "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1412:   "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172     www      1413:     }
                   1414: 
                   1415:     # Add the graphic
1.179     matthew  1416:     my $title = &mt('Report a Bug');
1.215     albertel 1417:     my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172     www      1418:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1419:  <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172     www      1420: ENDTEMPLATE
                   1421:     if ($text ne '') { $template.='</td></tr></table>' };
                   1422:     return $template;
                   1423: 
                   1424: }
                   1425: 
                   1426: sub help_open_faq {
                   1427:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1428:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1429:     unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
                   1430:     $text = "" if (not defined $text);
                   1431: 	$stayOnPage=1;
                   1432:     $width = 350 if (not defined $width);
                   1433:     $height = 400 if (not defined $height);
                   1434: 
                   1435:     $topic=~s/\W+/\+/g;
                   1436:     my $link='';
                   1437:     my $template='';
                   1438:     my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
                   1439:     if (!$stayOnPage)
                   1440:     {
                   1441: 	$link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1442:     }
                   1443:     else
                   1444:     {
                   1445: 	$link = $url;
                   1446:     }
                   1447: 
                   1448:     # Add the text
                   1449:     if ($text ne "")
                   1450:     {
                   1451: 	$template .= 
1.173     www      1452:   "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1453:   "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172     www      1454:     }
                   1455: 
                   1456:     # Add the graphic
1.179     matthew  1457:     my $title = &mt('View the FAQ');
1.215     albertel 1458:     my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172     www      1459:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1460:  <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172     www      1461: ENDTEMPLATE
                   1462:     if ($text ne '') { $template.='</td></tr></table>' };
                   1463:     return $template;
                   1464: 
1.44      bowersj2 1465: }
1.37      matthew  1466: 
1.180     matthew  1467: ###############################################################
                   1468: ###############################################################
                   1469: 
1.45      matthew  1470: =pod
                   1471: 
1.648     raeburn  1472: =item * &change_content_javascript():
1.256     matthew  1473: 
                   1474: This and the next function allow you to create small sections of an
                   1475: otherwise static HTML page that you can update on the fly with
                   1476: Javascript, even in Netscape 4.
                   1477: 
                   1478: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
                   1479: must be written to the HTML page once. It will prove the Javascript
                   1480: function "change(name, content)". Calling the change function with the
                   1481: name of the section 
                   1482: you want to update, matching the name passed to C<changable_area>, and
                   1483: the new content you want to put in there, will put the content into
                   1484: that area.
                   1485: 
                   1486: B<Note>: Netscape 4 only reserves enough space for the changable area
                   1487: to contain room for the original contents. You need to "make space"
                   1488: for whatever changes you wish to make, and be B<sure> to check your
                   1489: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
                   1490: it's adequate for updating a one-line status display, but little more.
                   1491: This script will set the space to 100% width, so you only need to
                   1492: worry about height in Netscape 4.
                   1493: 
                   1494: Modern browsers are much less limiting, and if you can commit to the
                   1495: user not using Netscape 4, this feature may be used freely with
                   1496: pretty much any HTML.
                   1497: 
                   1498: =cut
                   1499: 
                   1500: sub change_content_javascript {
                   1501:     # If we're on Netscape 4, we need to use Layer-based code
1.258     albertel 1502:     if ($env{'browser.type'} eq 'netscape' &&
                   1503: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1504: 	return (<<NETSCAPE4);
                   1505: 	function change(name, content) {
                   1506: 	    doc = document.layers[name+"___escape"].layers[0].document;
                   1507: 	    doc.open();
                   1508: 	    doc.write(content);
                   1509: 	    doc.close();
                   1510: 	}
                   1511: NETSCAPE4
                   1512:     } else {
                   1513: 	# Otherwise, we need to use semi-standards-compliant code
                   1514: 	# (technically, "innerHTML" isn't standard but the equivalent
                   1515: 	# is really scary, and every useful browser supports it
                   1516: 	return (<<DOMBASED);
                   1517: 	function change(name, content) {
                   1518: 	    element = document.getElementById(name);
                   1519: 	    element.innerHTML = content;
                   1520: 	}
                   1521: DOMBASED
                   1522:     }
                   1523: }
                   1524: 
                   1525: =pod
                   1526: 
1.648     raeburn  1527: =item * &changable_area($name,$origContent):
1.256     matthew  1528: 
                   1529: This provides a "changable area" that can be modified on the fly via
                   1530: the Javascript code provided in C<change_content_javascript>. $name is
                   1531: the name you will use to reference the area later; do not repeat the
                   1532: same name on a given HTML page more then once. $origContent is what
                   1533: the area will originally contain, which can be left blank.
                   1534: 
                   1535: =cut
                   1536: 
                   1537: sub changable_area {
                   1538:     my ($name, $origContent) = @_;
                   1539: 
1.258     albertel 1540:     if ($env{'browser.type'} eq 'netscape' &&
                   1541: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1542: 	# If this is netscape 4, we need to use the Layer tag
                   1543: 	return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
                   1544:     } else {
                   1545: 	return "<span id='$name'>$origContent</span>";
                   1546:     }
                   1547: }
                   1548: 
                   1549: =pod
                   1550: 
1.648     raeburn  1551: =item * &viewport_geometry_js 
1.590     raeburn  1552: 
                   1553: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
                   1554: 
                   1555: =cut
                   1556: 
                   1557: 
                   1558: sub viewport_geometry_js { 
                   1559:     return <<"GEOMETRY";
                   1560: var Geometry = {};
                   1561: function init_geometry() {
                   1562:     if (Geometry.init) { return };
                   1563:     Geometry.init=1;
                   1564:     if (window.innerHeight) {
                   1565:         Geometry.getViewportHeight   = function() { return window.innerHeight; };
                   1566:         Geometry.getViewportWidth   = function() { return window.innerWidth; };
                   1567:         Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
                   1568:         Geometry.getVerticalScroll   = function() { return window.pageYOffset; };
                   1569:     }
                   1570:     else if (document.documentElement && document.documentElement.clientHeight) {
                   1571:         Geometry.getViewportHeight =
                   1572:             function() { return document.documentElement.clientHeight; };
                   1573:         Geometry.getViewportWidth =
                   1574:             function() { return document.documentElement.clientWidth; };
                   1575: 
                   1576:         Geometry.getHorizontalScroll =
                   1577:             function() { return document.documentElement.scrollLeft; };
                   1578:         Geometry.getVerticalScroll =
                   1579:             function() { return document.documentElement.scrollTop; };
                   1580:     }
                   1581:     else if (document.body.clientHeight) {
                   1582:         Geometry.getViewportHeight =
                   1583:             function() { return document.body.clientHeight; };
                   1584:         Geometry.getViewportWidth =
                   1585:             function() { return document.body.clientWidth; };
                   1586:         Geometry.getHorizontalScroll =
                   1587:             function() { return document.body.scrollLeft; };
                   1588:         Geometry.getVerticalScroll =
                   1589:             function() { return document.body.scrollTop; };
                   1590:     }
                   1591: }
                   1592: 
                   1593: GEOMETRY
                   1594: }
                   1595: 
                   1596: =pod
                   1597: 
1.648     raeburn  1598: =item * &viewport_size_js()
1.590     raeburn  1599: 
                   1600: 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. 
                   1601: 
                   1602: =cut
                   1603: 
                   1604: sub viewport_size_js {
                   1605:     my $geometry = &viewport_geometry_js();
                   1606:     return <<"DIMS";
                   1607: 
                   1608: $geometry
                   1609: 
                   1610: function getViewportDims(width,height) {
                   1611:     init_geometry();
                   1612:     width.value = Geometry.getViewportWidth();
                   1613:     height.value = Geometry.getViewportHeight();
                   1614:     return;
                   1615: }
                   1616: 
                   1617: DIMS
                   1618: }
                   1619: 
                   1620: =pod
                   1621: 
1.648     raeburn  1622: =item * &resize_textarea_js()
1.565     albertel 1623: 
                   1624: emits the needed javascript to resize a textarea to be as big as possible
                   1625: 
                   1626: creates a function resize_textrea that takes two IDs first should be
                   1627: the id of the element to resize, second should be the id of a div that
                   1628: surrounds everything that comes after the textarea, this routine needs
                   1629: to be attached to the <body> for the onload and onresize events.
                   1630: 
1.648     raeburn  1631: =back
1.565     albertel 1632: 
                   1633: =cut
                   1634: 
                   1635: sub resize_textarea_js {
1.590     raeburn  1636:     my $geometry = &viewport_geometry_js();
1.565     albertel 1637:     return <<"RESIZE";
                   1638:     <script type="text/javascript">
1.824     bisitz   1639: // <![CDATA[
1.590     raeburn  1640: $geometry
1.565     albertel 1641: 
1.588     albertel 1642: function getX(element) {
                   1643:     var x = 0;
                   1644:     while (element) {
                   1645: 	x += element.offsetLeft;
                   1646: 	element = element.offsetParent;
                   1647:     }
                   1648:     return x;
                   1649: }
                   1650: function getY(element) {
                   1651:     var y = 0;
                   1652:     while (element) {
                   1653: 	y += element.offsetTop;
                   1654: 	element = element.offsetParent;
                   1655:     }
                   1656:     return y;
                   1657: }
                   1658: 
                   1659: 
1.565     albertel 1660: function resize_textarea(textarea_id,bottom_id) {
                   1661:     init_geometry();
                   1662:     var textarea        = document.getElementById(textarea_id);
                   1663:     //alert(textarea);
                   1664: 
1.588     albertel 1665:     var textarea_top    = getY(textarea);
1.565     albertel 1666:     var textarea_height = textarea.offsetHeight;
                   1667:     var bottom          = document.getElementById(bottom_id);
1.588     albertel 1668:     var bottom_top      = getY(bottom);
1.565     albertel 1669:     var bottom_height   = bottom.offsetHeight;
                   1670:     var window_height   = Geometry.getViewportHeight();
1.588     albertel 1671:     var fudge           = 23;
1.565     albertel 1672:     var new_height      = window_height-fudge-textarea_top-bottom_height;
                   1673:     if (new_height < 300) {
                   1674: 	new_height = 300;
                   1675:     }
                   1676:     textarea.style.height=new_height+'px';
                   1677: }
1.824     bisitz   1678: // ]]>
1.565     albertel 1679: </script>
                   1680: RESIZE
                   1681: 
                   1682: }
                   1683: 
                   1684: =pod
                   1685: 
1.256     matthew  1686: =head1 Excel and CSV file utility routines
                   1687: 
                   1688: =over 4
                   1689: 
                   1690: =cut
                   1691: 
                   1692: ###############################################################
                   1693: ###############################################################
                   1694: 
                   1695: =pod
                   1696: 
1.648     raeburn  1697: =item * &csv_translate($text) 
1.37      matthew  1698: 
1.185     www      1699: Translate $text to allow it to be output as a 'comma separated values' 
1.37      matthew  1700: format.
                   1701: 
                   1702: =cut
                   1703: 
1.180     matthew  1704: ###############################################################
                   1705: ###############################################################
1.37      matthew  1706: sub csv_translate {
                   1707:     my $text = shift;
                   1708:     $text =~ s/\"/\"\"/g;
1.209     albertel 1709:     $text =~ s/\n/ /g;
1.37      matthew  1710:     return $text;
                   1711: }
1.180     matthew  1712: 
                   1713: ###############################################################
                   1714: ###############################################################
                   1715: 
                   1716: =pod
                   1717: 
1.648     raeburn  1718: =item * &define_excel_formats()
1.180     matthew  1719: 
                   1720: Define some commonly used Excel cell formats.
                   1721: 
                   1722: Currently supported formats:
                   1723: 
                   1724: =over 4
                   1725: 
                   1726: =item header
                   1727: 
                   1728: =item bold
                   1729: 
                   1730: =item h1
                   1731: 
                   1732: =item h2
                   1733: 
                   1734: =item h3
                   1735: 
1.256     matthew  1736: =item h4
                   1737: 
                   1738: =item i
                   1739: 
1.180     matthew  1740: =item date
                   1741: 
                   1742: =back
                   1743: 
                   1744: Inputs: $workbook
                   1745: 
                   1746: Returns: $format, a hash reference.
                   1747: 
                   1748: =cut
                   1749: 
                   1750: ###############################################################
                   1751: ###############################################################
                   1752: sub define_excel_formats {
                   1753:     my ($workbook) = @_;
                   1754:     my $format;
                   1755:     $format->{'header'} = $workbook->add_format(bold      => 1, 
                   1756:                                                 bottom    => 1,
                   1757:                                                 align     => 'center');
                   1758:     $format->{'bold'} = $workbook->add_format(bold=>1);
                   1759:     $format->{'h1'}   = $workbook->add_format(bold=>1, size=>18);
                   1760:     $format->{'h2'}   = $workbook->add_format(bold=>1, size=>16);
                   1761:     $format->{'h3'}   = $workbook->add_format(bold=>1, size=>14);
1.255     matthew  1762:     $format->{'h4'}   = $workbook->add_format(bold=>1, size=>12);
1.246     matthew  1763:     $format->{'i'}    = $workbook->add_format(italic=>1);
1.180     matthew  1764:     $format->{'date'} = $workbook->add_format(num_format=>
1.207     matthew  1765:                                             'mm/dd/yyyy hh:mm:ss');
1.180     matthew  1766:     return $format;
                   1767: }
                   1768: 
                   1769: ###############################################################
                   1770: ###############################################################
1.113     bowersj2 1771: 
                   1772: =pod
                   1773: 
1.648     raeburn  1774: =item * &create_workbook()
1.255     matthew  1775: 
                   1776: Create an Excel worksheet.  If it fails, output message on the
                   1777: request object and return undefs.
                   1778: 
                   1779: Inputs: Apache request object
                   1780: 
                   1781: Returns (undef) on failure, 
                   1782:     Excel worksheet object, scalar with filename, and formats 
                   1783:     from &Apache::loncommon::define_excel_formats on success
                   1784: 
                   1785: =cut
                   1786: 
                   1787: ###############################################################
                   1788: ###############################################################
                   1789: sub create_workbook {
                   1790:     my ($r) = @_;
                   1791:         #
                   1792:     # Create the excel spreadsheet
                   1793:     my $filename = '/prtspool/'.
1.258     albertel 1794:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255     matthew  1795:         time.'_'.rand(1000000000).'.xls';
                   1796:     my $workbook  = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
                   1797:     if (! defined($workbook)) {
                   1798:         $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928     bisitz   1799:         $r->print(
                   1800:             '<p class="LC_error">'
                   1801:            .&mt('Problems occurred in creating the new Excel file.')
                   1802:            .' '.&mt('This error has been logged.')
                   1803:            .' '.&mt('Please alert your LON-CAPA administrator.')
                   1804:            .'</p>'
                   1805:         );
1.255     matthew  1806:         return (undef);
                   1807:     }
                   1808:     #
1.1014    foxr     1809:     $workbook->set_tempdir(LONCAPA::tempdir());
1.255     matthew  1810:     #
                   1811:     my $format = &Apache::loncommon::define_excel_formats($workbook);
                   1812:     return ($workbook,$filename,$format);
                   1813: }
                   1814: 
                   1815: ###############################################################
                   1816: ###############################################################
                   1817: 
                   1818: =pod
                   1819: 
1.648     raeburn  1820: =item * &create_text_file()
1.113     bowersj2 1821: 
1.542     raeburn  1822: Create a file to write to and eventually make available to the user.
1.256     matthew  1823: If file creation fails, outputs an error message on the request object and 
                   1824: return undefs.
1.113     bowersj2 1825: 
1.256     matthew  1826: Inputs: Apache request object, and file suffix
1.113     bowersj2 1827: 
1.256     matthew  1828: Returns (undef) on failure, 
                   1829:     Filehandle and filename on success.
1.113     bowersj2 1830: 
                   1831: =cut
                   1832: 
1.256     matthew  1833: ###############################################################
                   1834: ###############################################################
                   1835: sub create_text_file {
                   1836:     my ($r,$suffix) = @_;
                   1837:     if (! defined($suffix)) { $suffix = 'txt'; };
                   1838:     my $fh;
                   1839:     my $filename = '/prtspool/'.
1.258     albertel 1840:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256     matthew  1841:         time.'_'.rand(1000000000).'.'.$suffix;
                   1842:     $fh = Apache::File->new('>/home/httpd'.$filename);
                   1843:     if (! defined($fh)) {
                   1844:         $r->log_error("Couldn't open $filename for output $!");
1.928     bisitz   1845:         $r->print(
                   1846:             '<p class="LC_error">'
                   1847:            .&mt('Problems occurred in creating the output file.')
                   1848:            .' '.&mt('This error has been logged.')
                   1849:            .' '.&mt('Please alert your LON-CAPA administrator.')
                   1850:            .'</p>'
                   1851:         );
1.113     bowersj2 1852:     }
1.256     matthew  1853:     return ($fh,$filename)
1.113     bowersj2 1854: }
                   1855: 
                   1856: 
1.256     matthew  1857: =pod 
1.113     bowersj2 1858: 
                   1859: =back
                   1860: 
                   1861: =cut
1.37      matthew  1862: 
                   1863: ###############################################################
1.33      matthew  1864: ##        Home server <option> list generating code          ##
                   1865: ###############################################################
1.35      matthew  1866: 
1.169     www      1867: # ------------------------------------------
                   1868: 
                   1869: sub domain_select {
                   1870:     my ($name,$value,$multiple)=@_;
                   1871:     my %domains=map { 
1.514     albertel 1872: 	$_ => $_.' '. &Apache::lonnet::domain($_,'description') 
1.512     albertel 1873:     } &Apache::lonnet::all_domains();
1.169     www      1874:     if ($multiple) {
                   1875: 	$domains{''}=&mt('Any domain');
1.550     albertel 1876: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287     albertel 1877: 	return &multiple_select_form($name,$value,4,\%domains);
1.169     www      1878:     } else {
1.550     albertel 1879: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970     raeburn  1880: 	return &select_form($name,$value,\%domains);
1.169     www      1881:     }
                   1882: }
                   1883: 
1.282     albertel 1884: #-------------------------------------------
                   1885: 
                   1886: =pod
                   1887: 
1.519     raeburn  1888: =head1 Routines for form select boxes
                   1889: 
                   1890: =over 4
                   1891: 
1.648     raeburn  1892: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282     albertel 1893: 
                   1894: Returns a string containing a <select> element int multiple mode
                   1895: 
                   1896: 
                   1897: Args:
                   1898:   $name - name of the <select> element
1.506     raeburn  1899:   $value - scalar or array ref of values that should already be selected
1.282     albertel 1900:   $size - number of rows long the select element is
1.283     albertel 1901:   $hash - the elements should be 'option' => 'shown text'
1.282     albertel 1902:           (shown text should already have been &mt())
1.506     raeburn  1903:   $order - (optional) array ref of the order to show the elements in
1.283     albertel 1904: 
1.282     albertel 1905: =cut
                   1906: 
                   1907: #-------------------------------------------
1.169     www      1908: sub multiple_select_form {
1.284     albertel 1909:     my ($name,$value,$size,$hash,$order)=@_;
1.169     www      1910:     my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
                   1911:     my $output='';
1.191     matthew  1912:     if (! defined($size)) {
                   1913:         $size = 4;
1.283     albertel 1914:         if (scalar(keys(%$hash))<4) {
                   1915:             $size = scalar(keys(%$hash));
1.191     matthew  1916:         }
                   1917:     }
1.734     bisitz   1918:     $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501     banghart 1919:     my @order;
1.506     raeburn  1920:     if (ref($order) eq 'ARRAY')  {
                   1921:         @order = @{$order};
                   1922:     } else {
                   1923:         @order = sort(keys(%$hash));
1.501     banghart 1924:     }
                   1925:     if (exists($$hash{'select_form_order'})) {
                   1926:         @order = @{$$hash{'select_form_order'}};
                   1927:     }
                   1928:         
1.284     albertel 1929:     foreach my $key (@order) {
1.356     albertel 1930:         $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284     albertel 1931:         $output.='selected="selected" ' if ($selected{$key});
                   1932:         $output.='>'.$hash->{$key}."</option>\n";
1.169     www      1933:     }
                   1934:     $output.="</select>\n";
                   1935:     return $output;
                   1936: }
                   1937: 
1.88      www      1938: #-------------------------------------------
                   1939: 
                   1940: =pod
                   1941: 
1.970     raeburn  1942: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88      www      1943: 
                   1944: Returns a string containing a <select name='$name' size='1'> form to 
1.970     raeburn  1945: allow a user to select options from a ref to a hash containing:
                   1946: option_name => displayed text. An optional $onchange can include
                   1947: a javascript onchange item, e.g., onchange="this.form.submit();"  
                   1948: 
1.88      www      1949: See lonrights.pm for an example invocation and use.
                   1950: 
                   1951: =cut
                   1952: 
                   1953: #-------------------------------------------
                   1954: sub select_form {
1.970     raeburn  1955:     my ($def,$name,$hashref,$onchange) = @_;
                   1956:     return unless (ref($hashref) eq 'HASH');
                   1957:     if ($onchange) {
                   1958:         $onchange = ' onchange="'.$onchange.'"';
                   1959:     }
                   1960:     my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128     albertel 1961:     my @keys;
1.970     raeburn  1962:     if (exists($hashref->{'select_form_order'})) {
                   1963: 	@keys=@{$hashref->{'select_form_order'}};
1.128     albertel 1964:     } else {
1.970     raeburn  1965: 	@keys=sort(keys(%{$hashref}));
1.128     albertel 1966:     }
1.356     albertel 1967:     foreach my $key (@keys) {
                   1968:         $selectform.=
                   1969: 	    '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
                   1970:             ($key eq $def ? 'selected="selected" ' : '').
1.970     raeburn  1971:                 ">".$hashref->{$key}."</option>\n";
1.88      www      1972:     }
                   1973:     $selectform.="</select>";
                   1974:     return $selectform;
                   1975: }
                   1976: 
1.475     www      1977: # For display filters
                   1978: 
                   1979: sub display_filter {
                   1980:     if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477     www      1981:     if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714     bisitz   1982:     return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475     www      1983: 			       &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
                   1984: 							   (&mt('all'),10,20,50,100,1000,10000))).
1.714     bisitz   1985: 	   '</label></span> <span class="LC_nobreak">'.
1.475     www      1986:            &mt('Filter [_1]',
1.477     www      1987: 	   &select_form($env{'form.displayfilter'},
                   1988: 			'displayfilter',
1.970     raeburn  1989: 			{'currentfolder' => 'Current folder/page',
1.477     www      1990: 			 'containing' => 'Containing phrase',
1.970     raeburn  1991: 			 'none' => 'None'})).
1.714     bisitz   1992: 			 '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475     www      1993: }
                   1994: 
1.167     www      1995: sub gradeleveldescription {
                   1996:     my $gradelevel=shift;
                   1997:     my %gradelevels=(0 => 'Not specified',
                   1998: 		     1 => 'Grade 1',
                   1999: 		     2 => 'Grade 2',
                   2000: 		     3 => 'Grade 3',
                   2001: 		     4 => 'Grade 4',
                   2002: 		     5 => 'Grade 5',
                   2003: 		     6 => 'Grade 6',
                   2004: 		     7 => 'Grade 7',
                   2005: 		     8 => 'Grade 8',
                   2006: 		     9 => 'Grade 9',
                   2007: 		     10 => 'Grade 10',
                   2008: 		     11 => 'Grade 11',
                   2009: 		     12 => 'Grade 12',
                   2010: 		     13 => 'Grade 13',
                   2011: 		     14 => '100 Level',
                   2012: 		     15 => '200 Level',
                   2013: 		     16 => '300 Level',
                   2014: 		     17 => '400 Level',
                   2015: 		     18 => 'Graduate Level');
                   2016:     return &mt($gradelevels{$gradelevel});
                   2017: }
                   2018: 
1.163     www      2019: sub select_level_form {
                   2020:     my ($deflevel,$name)=@_;
                   2021:     unless ($deflevel) { $deflevel=0; }
1.167     www      2022:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
                   2023:     for (my $i=0; $i<=18; $i++) {
                   2024:         $selectform.="<option value=\"$i\" ".
1.253     albertel 2025:             ($i==$deflevel ? 'selected="selected" ' : '').
1.167     www      2026:                 ">".&gradeleveldescription($i)."</option>\n";
                   2027:     }
                   2028:     $selectform.="</select>";
                   2029:     return $selectform;
1.163     www      2030: }
1.167     www      2031: 
1.35      matthew  2032: #-------------------------------------------
                   2033: 
1.45      matthew  2034: =pod
                   2035: 
1.910     raeburn  2036: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms)
1.35      matthew  2037: 
                   2038: Returns a string containing a <select name='$name' size='1'> form to 
                   2039: allow a user to select the domain to preform an operation in.  
                   2040: See loncreateuser.pm for an example invocation and use.
                   2041: 
1.90      www      2042: If the $includeempty flag is set, it also includes an empty choice ("no domain
                   2043: selected");
                   2044: 
1.743     raeburn  2045: If the $showdomdesc flag is set, the domain name is followed by the domain description.
                   2046: 
1.910     raeburn  2047: 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.
                   2048: 
                   2049: The optional $incdoms is a reference to an array of domains which will be the only available options. 
1.563     raeburn  2050: 
1.35      matthew  2051: =cut
                   2052: 
                   2053: #-------------------------------------------
1.34      matthew  2054: sub select_dom_form {
1.910     raeburn  2055:     my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms) = @_;
1.872     raeburn  2056:     if ($onchange) {
1.874     raeburn  2057:         $onchange = ' onchange="'.$onchange.'"';
1.743     raeburn  2058:     }
1.910     raeburn  2059:     my @domains;
                   2060:     if (ref($incdoms) eq 'ARRAY') {
                   2061:         @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
                   2062:     } else {
                   2063:         @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
                   2064:     }
1.90      www      2065:     if ($includeempty) { @domains=('',@domains); }
1.743     raeburn  2066:     my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356     albertel 2067:     foreach my $dom (@domains) {
                   2068:         $selectdomain.="<option value=\"$dom\" ".
1.563     raeburn  2069:             ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
                   2070:         if ($showdomdesc) {
                   2071:             if ($dom ne '') {
                   2072:                 my $domdesc = &Apache::lonnet::domain($dom,'description');
                   2073:                 if ($domdesc ne '') {
                   2074:                     $selectdomain .= ' ('.$domdesc.')';
                   2075:                 }
                   2076:             } 
                   2077:         }
                   2078:         $selectdomain .= "</option>\n";
1.34      matthew  2079:     }
                   2080:     $selectdomain.="</select>";
                   2081:     return $selectdomain;
                   2082: }
                   2083: 
1.35      matthew  2084: #-------------------------------------------
                   2085: 
1.45      matthew  2086: =pod
                   2087: 
1.648     raeburn  2088: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35      matthew  2089: 
1.586     raeburn  2090: input: 4 arguments (two required, two optional) - 
                   2091:     $domain - domain of new user
                   2092:     $name - name of form element
                   2093:     $default - Value of 'default' causes a default item to be first 
                   2094:                             option, and selected by default. 
                   2095:     $hide - Value of 'hide' causes hiding of the name of the server, 
                   2096:                             if 1 server found, or default, if 0 found.
1.594     raeburn  2097: output: returns 2 items: 
1.586     raeburn  2098: (a) form element which contains either:
                   2099:    (i) <select name="$name">
                   2100:         <option value="$hostid1">$hostid $servers{$hostid}</option>
                   2101:         <option value="$hostid2">$hostid $servers{$hostid}</option>       
                   2102:        </select>
                   2103:        form item if there are multiple library servers in $domain, or
                   2104:    (ii) an <input type="hidden" name="$name" value="$hostid" /> form item 
                   2105:        if there is only one library server in $domain.
                   2106: 
                   2107: (b) number of library servers found.
                   2108: 
                   2109: See loncreateuser.pm for example of use.
1.35      matthew  2110: 
                   2111: =cut
                   2112: 
                   2113: #-------------------------------------------
1.586     raeburn  2114: sub home_server_form_item {
                   2115:     my ($domain,$name,$default,$hide) = @_;
1.513     albertel 2116:     my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586     raeburn  2117:     my $result;
                   2118:     my $numlib = keys(%servers);
                   2119:     if ($numlib > 1) {
                   2120:         $result .= '<select name="'.$name.'" />'."\n";
                   2121:         if ($default) {
1.804     bisitz   2122:             $result .= '<option value="default" selected="selected">'.&mt('default').
1.586     raeburn  2123:                        '</option>'."\n";
                   2124:         }
                   2125:         foreach my $hostid (sort(keys(%servers))) {
                   2126:             $result.= '<option value="'.$hostid.'">'.
                   2127: 	              $hostid.' '.$servers{$hostid}."</option>\n";
                   2128:         }
                   2129:         $result .= '</select>'."\n";
                   2130:     } elsif ($numlib == 1) {
                   2131:         my $hostid;
                   2132:         foreach my $item (keys(%servers)) {
                   2133:             $hostid = $item;
                   2134:         }
                   2135:         $result .= '<input type="hidden" name="'.$name.'" value="'.
                   2136:                    $hostid.'" />';
                   2137:                    if (!$hide) {
                   2138:                        $result .= $hostid.' '.$servers{$hostid};
                   2139:                    }
                   2140:                    $result .= "\n";
                   2141:     } elsif ($default) {
                   2142:         $result .= '<input type="hidden" name="'.$name.
                   2143:                    '" value="default" />';
                   2144:                    if (!$hide) {
                   2145:                        $result .= &mt('default');
                   2146:                    }
                   2147:                    $result .= "\n";
1.33      matthew  2148:     }
1.586     raeburn  2149:     return ($result,$numlib);
1.33      matthew  2150: }
1.112     bowersj2 2151: 
                   2152: =pod
                   2153: 
1.534     albertel 2154: =back 
                   2155: 
1.112     bowersj2 2156: =cut
1.87      matthew  2157: 
                   2158: ###############################################################
1.112     bowersj2 2159: ##                  Decoding User Agent                      ##
1.87      matthew  2160: ###############################################################
                   2161: 
                   2162: =pod
                   2163: 
1.112     bowersj2 2164: =head1 Decoding the User Agent
                   2165: 
                   2166: =over 4
                   2167: 
                   2168: =item * &decode_user_agent()
1.87      matthew  2169: 
                   2170: Inputs: $r
                   2171: 
                   2172: Outputs:
                   2173: 
                   2174: =over 4
                   2175: 
1.112     bowersj2 2176: =item * $httpbrowser
1.87      matthew  2177: 
1.112     bowersj2 2178: =item * $clientbrowser
1.87      matthew  2179: 
1.112     bowersj2 2180: =item * $clientversion
1.87      matthew  2181: 
1.112     bowersj2 2182: =item * $clientmathml
1.87      matthew  2183: 
1.112     bowersj2 2184: =item * $clientunicode
1.87      matthew  2185: 
1.112     bowersj2 2186: =item * $clientos
1.87      matthew  2187: 
                   2188: =back
                   2189: 
1.157     matthew  2190: =back 
                   2191: 
1.87      matthew  2192: =cut
                   2193: 
                   2194: ###############################################################
                   2195: ###############################################################
                   2196: sub decode_user_agent {
1.247     albertel 2197:     my ($r)=@_;
1.87      matthew  2198:     my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
                   2199:     my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
                   2200:     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247     albertel 2201:     if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87      matthew  2202:     my $clientbrowser='unknown';
                   2203:     my $clientversion='0';
                   2204:     my $clientmathml='';
                   2205:     my $clientunicode='0';
                   2206:     for (my $i=0;$i<=$#browsertype;$i++) {
                   2207:         my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
                   2208: 	if (($httpbrowser=~/$match/i)  && ($httpbrowser!~/$notmatch/i)) {
                   2209: 	    $clientbrowser=$bname;
                   2210:             $httpbrowser=~/$vreg/i;
                   2211: 	    $clientversion=$1;
                   2212:             $clientmathml=($clientversion>=$minv);
                   2213:             $clientunicode=($clientversion>=$univ);
                   2214: 	}
                   2215:     }
                   2216:     my $clientos='unknown';
                   2217:     if (($httpbrowser=~/linux/i) ||
                   2218:         ($httpbrowser=~/unix/i) ||
                   2219:         ($httpbrowser=~/ux/i) ||
                   2220:         ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
                   2221:     if (($httpbrowser=~/vax/i) ||
                   2222:         ($httpbrowser=~/vms/i)) { $clientos='vms'; }
                   2223:     if ($httpbrowser=~/next/i) { $clientos='next'; }
                   2224:     if (($httpbrowser=~/mac/i) ||
                   2225:         ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
                   2226:     if ($httpbrowser=~/win/i) { $clientos='win'; }
                   2227:     if ($httpbrowser=~/embed/i) { $clientos='pda'; }
                   2228:     return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   2229:             $clientunicode,$clientos,);
                   2230: }
                   2231: 
1.32      matthew  2232: ###############################################################
                   2233: ##    Authentication changing form generation subroutines    ##
                   2234: ###############################################################
                   2235: ##
                   2236: ## All of the authform_xxxxxxx subroutines take their inputs in a
                   2237: ## hash, and have reasonable default values.
                   2238: ##
                   2239: ##    formname = the name given in the <form> tag.
1.35      matthew  2240: #-------------------------------------------
                   2241: 
1.45      matthew  2242: =pod
                   2243: 
1.112     bowersj2 2244: =head1 Authentication Routines
                   2245: 
                   2246: =over 4
                   2247: 
1.648     raeburn  2248: =item * &authform_xxxxxx()
1.35      matthew  2249: 
                   2250: The authform_xxxxxx subroutines provide javascript and html forms which 
                   2251: handle some of the conveniences required for authentication forms.  
                   2252: This is not an optimal method, but it works.  
                   2253: 
                   2254: =over 4
                   2255: 
1.112     bowersj2 2256: =item * authform_header
1.35      matthew  2257: 
1.112     bowersj2 2258: =item * authform_authorwarning
1.35      matthew  2259: 
1.112     bowersj2 2260: =item * authform_nochange
1.35      matthew  2261: 
1.112     bowersj2 2262: =item * authform_kerberos
1.35      matthew  2263: 
1.112     bowersj2 2264: =item * authform_internal
1.35      matthew  2265: 
1.112     bowersj2 2266: =item * authform_filesystem
1.35      matthew  2267: 
                   2268: =back
                   2269: 
1.648     raeburn  2270: See loncreateuser.pm for invocation and use examples.
1.157     matthew  2271: 
1.35      matthew  2272: =cut
                   2273: 
                   2274: #-------------------------------------------
1.32      matthew  2275: sub authform_header{  
                   2276:     my %in = (
                   2277:         formname => 'cu',
1.80      albertel 2278:         kerb_def_dom => '',
1.32      matthew  2279:         @_,
                   2280:     );
                   2281:     $in{'formname'} = 'document.' . $in{'formname'};
                   2282:     my $result='';
1.80      albertel 2283: 
                   2284: #---------------------------------------------- Code for upper case translation
                   2285:     my $Javascript_toUpperCase;
                   2286:     unless ($in{kerb_def_dom}) {
                   2287:         $Javascript_toUpperCase =<<"END";
                   2288:         switch (choice) {
                   2289:            case 'krb': currentform.elements[choicearg].value =
                   2290:                currentform.elements[choicearg].value.toUpperCase();
                   2291:                break;
                   2292:            default:
                   2293:         }
                   2294: END
                   2295:     } else {
                   2296:         $Javascript_toUpperCase = "";
                   2297:     }
                   2298: 
1.165     raeburn  2299:     my $radioval = "'nochange'";
1.591     raeburn  2300:     if (defined($in{'curr_authtype'})) {
                   2301:         if ($in{'curr_authtype'} ne '') {
                   2302:             $radioval = "'".$in{'curr_authtype'}."arg'";
                   2303:         }
1.174     matthew  2304:     }
1.165     raeburn  2305:     my $argfield = 'null';
1.591     raeburn  2306:     if (defined($in{'mode'})) {
1.165     raeburn  2307:         if ($in{'mode'} eq 'modifycourse')  {
1.591     raeburn  2308:             if (defined($in{'curr_autharg'})) {
                   2309:                 if ($in{'curr_autharg'} ne '') {
1.165     raeburn  2310:                     $argfield = "'$in{'curr_autharg'}'";
                   2311:                 }
                   2312:             }
                   2313:         }
                   2314:     }
                   2315: 
1.32      matthew  2316:     $result.=<<"END";
                   2317: var current = new Object();
1.165     raeburn  2318: current.radiovalue = $radioval;
                   2319: current.argfield = $argfield;
1.32      matthew  2320: 
                   2321: function changed_radio(choice,currentform) {
                   2322:     var choicearg = choice + 'arg';
                   2323:     // If a radio button in changed, we need to change the argfield
                   2324:     if (current.radiovalue != choice) {
                   2325:         current.radiovalue = choice;
                   2326:         if (current.argfield != null) {
                   2327:             currentform.elements[current.argfield].value = '';
                   2328:         }
                   2329:         if (choice == 'nochange') {
                   2330:             current.argfield = null;
                   2331:         } else {
                   2332:             current.argfield = choicearg;
                   2333:             switch(choice) {
                   2334:                 case 'krb': 
                   2335:                     currentform.elements[current.argfield].value = 
                   2336:                         "$in{'kerb_def_dom'}";
                   2337:                 break;
                   2338:               default:
                   2339:                 break;
                   2340:             }
                   2341:         }
                   2342:     }
                   2343:     return;
                   2344: }
1.22      www      2345: 
1.32      matthew  2346: function changed_text(choice,currentform) {
                   2347:     var choicearg = choice + 'arg';
                   2348:     if (currentform.elements[choicearg].value !='') {
1.80      albertel 2349:         $Javascript_toUpperCase
1.32      matthew  2350:         // clear old field
                   2351:         if ((current.argfield != choicearg) && (current.argfield != null)) {
                   2352:             currentform.elements[current.argfield].value = '';
                   2353:         }
                   2354:         current.argfield = choicearg;
                   2355:     }
                   2356:     set_auth_radio_buttons(choice,currentform);
                   2357:     return;
1.20      www      2358: }
1.32      matthew  2359: 
                   2360: function set_auth_radio_buttons(newvalue,currentform) {
1.986     raeburn  2361:     var numauthchoices = currentform.login.length;
                   2362:     if (typeof numauthchoices  == "undefined") {
                   2363:         return;
                   2364:     } 
1.32      matthew  2365:     var i=0;
1.986     raeburn  2366:     while (i < numauthchoices) {
1.32      matthew  2367:         if (currentform.login[i].value == newvalue) { break; }
                   2368:         i++;
                   2369:     }
1.986     raeburn  2370:     if (i == numauthchoices) {
1.32      matthew  2371:         return;
                   2372:     }
                   2373:     current.radiovalue = newvalue;
                   2374:     currentform.login[i].checked = true;
                   2375:     return;
                   2376: }
                   2377: END
                   2378:     return $result;
                   2379: }
                   2380: 
                   2381: sub authform_authorwarning{
                   2382:     my $result='';
1.144     matthew  2383:     $result='<i>'.
                   2384:         &mt('As a general rule, only authors or co-authors should be '.
                   2385:             'filesystem authenticated '.
                   2386:             '(which allows access to the server filesystem).')."</i>\n";
1.32      matthew  2387:     return $result;
                   2388: }
                   2389: 
                   2390: sub authform_nochange{  
                   2391:     my %in = (
                   2392:               formname => 'document.cu',
                   2393:               kerb_def_dom => 'MSU.EDU',
                   2394:               @_,
                   2395:           );
1.586     raeburn  2396:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'}); 
                   2397:     my $result;
                   2398:     if (keys(%can_assign) == 0) {
                   2399:         $result = &mt('Under you current role you are not permitted to change login settings for this user');  
                   2400:     } else {
                   2401:         $result = '<label>'.&mt('[_1] Do not change login data',
                   2402:                   '<input type="radio" name="login" value="nochange" '.
                   2403:                   'checked="checked" onclick="'.
1.281     albertel 2404:             "javascript:changed_radio('nochange',$in{'formname'});".'" />').
                   2405: 	    '</label>';
1.586     raeburn  2406:     }
1.32      matthew  2407:     return $result;
                   2408: }
                   2409: 
1.591     raeburn  2410: sub authform_kerberos {
1.32      matthew  2411:     my %in = (
                   2412:               formname => 'document.cu',
                   2413:               kerb_def_dom => 'MSU.EDU',
1.80      albertel 2414:               kerb_def_auth => 'krb4',
1.32      matthew  2415:               @_,
                   2416:               );
1.586     raeburn  2417:     my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
                   2418:         $autharg,$jscall);
                   2419:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.80      albertel 2420:     if ($in{'kerb_def_auth'} eq 'krb5') {
1.772     bisitz   2421:        $check5 = ' checked="checked"';
1.80      albertel 2422:     } else {
1.772     bisitz   2423:        $check4 = ' checked="checked"';
1.80      albertel 2424:     }
1.165     raeburn  2425:     $krbarg = $in{'kerb_def_dom'};
1.591     raeburn  2426:     if (defined($in{'curr_authtype'})) {
                   2427:         if ($in{'curr_authtype'} eq 'krb') {
1.772     bisitz   2428:             $krbcheck = ' checked="checked"';
1.623     raeburn  2429:             if (defined($in{'mode'})) {
                   2430:                 if ($in{'mode'} eq 'modifyuser') {
                   2431:                     $krbcheck = '';
                   2432:                 }
                   2433:             }
1.591     raeburn  2434:             if (defined($in{'curr_kerb_ver'})) {
                   2435:                 if ($in{'curr_krb_ver'} eq '5') {
1.772     bisitz   2436:                     $check5 = ' checked="checked"';
1.591     raeburn  2437:                     $check4 = '';
                   2438:                 } else {
1.772     bisitz   2439:                     $check4 = ' checked="checked"';
1.591     raeburn  2440:                     $check5 = '';
                   2441:                 }
1.586     raeburn  2442:             }
1.591     raeburn  2443:             if (defined($in{'curr_autharg'})) {
1.165     raeburn  2444:                 $krbarg = $in{'curr_autharg'};
                   2445:             }
1.586     raeburn  2446:             if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591     raeburn  2447:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2448:                     $result = 
                   2449:     &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
                   2450:         $in{'curr_autharg'},$krbver);
                   2451:                 } else {
                   2452:                     $result =
                   2453:     &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
                   2454:                 }
                   2455:                 return $result; 
                   2456:             }
                   2457:         }
                   2458:     } else {
                   2459:         if ($authnum == 1) {
1.784     bisitz   2460:             $authtype = '<input type="hidden" name="login" value="krb" />';
1.165     raeburn  2461:         }
                   2462:     }
1.586     raeburn  2463:     if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
                   2464:         return;
1.587     raeburn  2465:     } elsif ($authtype eq '') {
1.591     raeburn  2466:         if (defined($in{'mode'})) {
1.587     raeburn  2467:             if ($in{'mode'} eq 'modifycourse') {
                   2468:                 if ($authnum == 1) {
1.784     bisitz   2469:                     $authtype = '<input type="hidden" name="login" value="krb" />';
1.587     raeburn  2470:                 }
                   2471:             }
                   2472:         }
1.586     raeburn  2473:     }
                   2474:     $jscall = "javascript:changed_radio('krb',$in{'formname'});";
                   2475:     if ($authtype eq '') {
                   2476:         $authtype = '<input type="radio" name="login" value="krb" '.
                   2477:                     'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
                   2478:                     $krbcheck.' />';
                   2479:     }
                   2480:     if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
                   2481:         ($can_assign{'krb4'} && !$can_assign{'krb5'} && 
                   2482:          $in{'curr_authtype'} eq 'krb5') ||
                   2483:         (!$can_assign{'krb4'} && $can_assign{'krb5'} && 
                   2484:          $in{'curr_authtype'} eq 'krb4')) {
                   2485:         $result .= &mt
1.144     matthew  2486:         ('[_1] Kerberos authenticated with domain [_2] '.
1.281     albertel 2487:          '[_3] Version 4 [_4] Version 5 [_5]',
1.586     raeburn  2488:          '<label>'.$authtype,
1.281     albertel 2489:          '</label><input type="text" size="10" name="krbarg" '.
1.165     raeburn  2490:              'value="'.$krbarg.'" '.
1.144     matthew  2491:              'onchange="'.$jscall.'" />',
1.281     albertel 2492:          '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
                   2493:          '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
                   2494: 	 '</label>');
1.586     raeburn  2495:     } elsif ($can_assign{'krb4'}) {
                   2496:         $result .= &mt
                   2497:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2498:          '[_3] Version 4 [_4]',
                   2499:          '<label>'.$authtype,
                   2500:          '</label><input type="text" size="10" name="krbarg" '.
                   2501:              'value="'.$krbarg.'" '.
                   2502:              'onchange="'.$jscall.'" />',
                   2503:          '<label><input type="hidden" name="krbver" value="4" />',
                   2504:          '</label>');
                   2505:     } elsif ($can_assign{'krb5'}) {
                   2506:         $result .= &mt
                   2507:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2508:          '[_3] Version 5 [_4]',
                   2509:          '<label>'.$authtype,
                   2510:          '</label><input type="text" size="10" name="krbarg" '.
                   2511:              'value="'.$krbarg.'" '.
                   2512:              'onchange="'.$jscall.'" />',
                   2513:          '<label><input type="hidden" name="krbver" value="5" />',
                   2514:          '</label>');
                   2515:     }
1.32      matthew  2516:     return $result;
                   2517: }
                   2518: 
                   2519: sub authform_internal{  
1.586     raeburn  2520:     my %in = (
1.32      matthew  2521:                 formname => 'document.cu',
                   2522:                 kerb_def_dom => 'MSU.EDU',
                   2523:                 @_,
                   2524:                 );
1.586     raeburn  2525:     my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
                   2526:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2527:     if (defined($in{'curr_authtype'})) {
                   2528:         if ($in{'curr_authtype'} eq 'int') {
1.586     raeburn  2529:             if ($can_assign{'int'}) {
1.772     bisitz   2530:                 $intcheck = 'checked="checked" ';
1.623     raeburn  2531:                 if (defined($in{'mode'})) {
                   2532:                     if ($in{'mode'} eq 'modifyuser') {
                   2533:                         $intcheck = '';
                   2534:                     }
                   2535:                 }
1.591     raeburn  2536:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2537:                     $intarg = $in{'curr_autharg'};
                   2538:                 }
                   2539:             } else {
                   2540:                 $result = &mt('Currently internally authenticated.');
                   2541:                 return $result;
1.165     raeburn  2542:             }
                   2543:         }
1.586     raeburn  2544:     } else {
                   2545:         if ($authnum == 1) {
1.784     bisitz   2546:             $authtype = '<input type="hidden" name="login" value="int" />';
1.586     raeburn  2547:         }
                   2548:     }
                   2549:     if (!$can_assign{'int'}) {
                   2550:         return;
1.587     raeburn  2551:     } elsif ($authtype eq '') {
1.591     raeburn  2552:         if (defined($in{'mode'})) {
1.587     raeburn  2553:             if ($in{'mode'} eq 'modifycourse') {
                   2554:                 if ($authnum == 1) {
1.784     bisitz   2555:                     $authtype = '<input type="hidden" name="login" value="int" />';
1.587     raeburn  2556:                 }
                   2557:             }
                   2558:         }
1.165     raeburn  2559:     }
1.586     raeburn  2560:     $jscall = "javascript:changed_radio('int',$in{'formname'});";
                   2561:     if ($authtype eq '') {
                   2562:         $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
                   2563:                     ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
                   2564:     }
1.605     bisitz   2565:     $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586     raeburn  2566:                $intarg.'" onchange="'.$jscall.'" />';
                   2567:     $result = &mt
1.144     matthew  2568:         ('[_1] Internally authenticated (with initial password [_2])',
1.586     raeburn  2569:          '<label>'.$authtype,'</label>'.$autharg);
1.824     bisitz   2570:     $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  2571:     return $result;
                   2572: }
                   2573: 
                   2574: sub authform_local{  
                   2575:     my %in = (
                   2576:               formname => 'document.cu',
                   2577:               kerb_def_dom => 'MSU.EDU',
                   2578:               @_,
                   2579:               );
1.586     raeburn  2580:     my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
                   2581:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2582:     if (defined($in{'curr_authtype'})) {
                   2583:         if ($in{'curr_authtype'} eq 'loc') {
1.586     raeburn  2584:             if ($can_assign{'loc'}) {
1.772     bisitz   2585:                 $loccheck = 'checked="checked" ';
1.623     raeburn  2586:                 if (defined($in{'mode'})) {
                   2587:                     if ($in{'mode'} eq 'modifyuser') {
                   2588:                         $loccheck = '';
                   2589:                     }
                   2590:                 }
1.591     raeburn  2591:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2592:                     $locarg = $in{'curr_autharg'};
                   2593:                 }
                   2594:             } else {
                   2595:                 $result = &mt('Currently using local (institutional) authentication.');
                   2596:                 return $result;
1.165     raeburn  2597:             }
                   2598:         }
1.586     raeburn  2599:     } else {
                   2600:         if ($authnum == 1) {
1.784     bisitz   2601:             $authtype = '<input type="hidden" name="login" value="loc" />';
1.586     raeburn  2602:         }
                   2603:     }
                   2604:     if (!$can_assign{'loc'}) {
                   2605:         return;
1.587     raeburn  2606:     } elsif ($authtype eq '') {
1.591     raeburn  2607:         if (defined($in{'mode'})) {
1.587     raeburn  2608:             if ($in{'mode'} eq 'modifycourse') {
                   2609:                 if ($authnum == 1) {
1.784     bisitz   2610:                     $authtype = '<input type="hidden" name="login" value="loc" />';
1.587     raeburn  2611:                 }
                   2612:             }
                   2613:         }
1.165     raeburn  2614:     }
1.586     raeburn  2615:     $jscall = "javascript:changed_radio('loc',$in{'formname'});";
                   2616:     if ($authtype eq '') {
                   2617:         $authtype = '<input type="radio" name="login" value="loc" '.
                   2618:                     $loccheck.' onchange="'.$jscall.'" onclick="'.
                   2619:                     $jscall.'" />';
                   2620:     }
                   2621:     $autharg = '<input type="text" size="10" name="locarg" value="'.
                   2622:                $locarg.'" onchange="'.$jscall.'" />';
                   2623:     $result = &mt('[_1] Local Authentication with argument [_2]',
                   2624:                   '<label>'.$authtype,'</label>'.$autharg);
1.32      matthew  2625:     return $result;
                   2626: }
                   2627: 
                   2628: sub authform_filesystem{  
                   2629:     my %in = (
                   2630:               formname => 'document.cu',
                   2631:               kerb_def_dom => 'MSU.EDU',
                   2632:               @_,
                   2633:               );
1.586     raeburn  2634:     my ($fsyscheck,$result,$authtype,$autharg,$jscall);
                   2635:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2636:     if (defined($in{'curr_authtype'})) {
                   2637:         if ($in{'curr_authtype'} eq 'fsys') {
1.586     raeburn  2638:             if ($can_assign{'fsys'}) {
1.772     bisitz   2639:                 $fsyscheck = 'checked="checked" ';
1.623     raeburn  2640:                 if (defined($in{'mode'})) {
                   2641:                     if ($in{'mode'} eq 'modifyuser') {
                   2642:                         $fsyscheck = '';
                   2643:                     }
                   2644:                 }
1.586     raeburn  2645:             } else {
                   2646:                 $result = &mt('Currently Filesystem Authenticated.');
                   2647:                 return $result;
                   2648:             }           
                   2649:         }
                   2650:     } else {
                   2651:         if ($authnum == 1) {
1.784     bisitz   2652:             $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586     raeburn  2653:         }
                   2654:     }
                   2655:     if (!$can_assign{'fsys'}) {
                   2656:         return;
1.587     raeburn  2657:     } elsif ($authtype eq '') {
1.591     raeburn  2658:         if (defined($in{'mode'})) {
1.587     raeburn  2659:             if ($in{'mode'} eq 'modifycourse') {
                   2660:                 if ($authnum == 1) {
1.784     bisitz   2661:                     $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587     raeburn  2662:                 }
                   2663:             }
                   2664:         }
1.586     raeburn  2665:     }
                   2666:     $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
                   2667:     if ($authtype eq '') {
                   2668:         $authtype = '<input type="radio" name="login" value="fsys" '.
                   2669:                     $fsyscheck.' onchange="'.$jscall.'" onclick="'.
                   2670:                     $jscall.'" />';
                   2671:     }
                   2672:     $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
                   2673:                ' onchange="'.$jscall.'" />';
                   2674:     $result = &mt
1.144     matthew  2675:         ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281     albertel 2676:          '<label><input type="radio" name="login" value="fsys" '.
1.586     raeburn  2677:          $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605     bisitz   2678:          '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144     matthew  2679:                   'onchange="'.$jscall.'" />');
1.32      matthew  2680:     return $result;
                   2681: }
                   2682: 
1.586     raeburn  2683: sub get_assignable_auth {
                   2684:     my ($dom) = @_;
                   2685:     if ($dom eq '') {
                   2686:         $dom = $env{'request.role.domain'};
                   2687:     }
                   2688:     my %can_assign = (
                   2689:                           krb4 => 1,
                   2690:                           krb5 => 1,
                   2691:                           int  => 1,
                   2692:                           loc  => 1,
                   2693:                      );
                   2694:     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
                   2695:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   2696:         if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
                   2697:             my $authhash = $domconfig{'usercreation'}{'authtypes'};
                   2698:             my $context;
                   2699:             if ($env{'request.role'} =~ /^au/) {
                   2700:                 $context = 'author';
                   2701:             } elsif ($env{'request.role'} =~ /^dc/) {
                   2702:                 $context = 'domain';
                   2703:             } elsif ($env{'request.course.id'}) {
                   2704:                 $context = 'course';
                   2705:             }
                   2706:             if ($context) {
                   2707:                 if (ref($authhash->{$context}) eq 'HASH') {
                   2708:                    %can_assign = %{$authhash->{$context}}; 
                   2709:                 }
                   2710:             }
                   2711:         }
                   2712:     }
                   2713:     my $authnum = 0;
                   2714:     foreach my $key (keys(%can_assign)) {
                   2715:         if ($can_assign{$key}) {
                   2716:             $authnum ++;
                   2717:         }
                   2718:     }
                   2719:     if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
                   2720:         $authnum --;
                   2721:     }
                   2722:     return ($authnum,%can_assign);
                   2723: }
                   2724: 
1.80      albertel 2725: ###############################################################
                   2726: ##    Get Kerberos Defaults for Domain                 ##
                   2727: ###############################################################
                   2728: ##
                   2729: ## Returns default kerberos version and an associated argument
                   2730: ## as listed in file domain.tab. If not listed, provides
                   2731: ## appropriate default domain and kerberos version.
                   2732: ##
                   2733: #-------------------------------------------
                   2734: 
                   2735: =pod
                   2736: 
1.648     raeburn  2737: =item * &get_kerberos_defaults()
1.80      albertel 2738: 
                   2739: get_kerberos_defaults($target_domain) returns the default kerberos
1.641     raeburn  2740: version and domain. If not found, it defaults to version 4 and the 
                   2741: domain of the server.
1.80      albertel 2742: 
1.648     raeburn  2743: =over 4
                   2744: 
1.80      albertel 2745: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
                   2746: 
1.648     raeburn  2747: =back
                   2748: 
                   2749: =back
                   2750: 
1.80      albertel 2751: =cut
                   2752: 
                   2753: #-------------------------------------------
                   2754: sub get_kerberos_defaults {
                   2755:     my $domain=shift;
1.641     raeburn  2756:     my ($krbdef,$krbdefdom);
                   2757:     my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
                   2758:     if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
                   2759:         $krbdef = $domdefaults{'auth_def'};
                   2760:         $krbdefdom = $domdefaults{'auth_arg_def'};
                   2761:     } else {
1.80      albertel 2762:         $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
                   2763:         my $krbdefdom=$1;
                   2764:         $krbdefdom=~tr/a-z/A-Z/;
                   2765:         $krbdef = "krb4";
                   2766:     }
                   2767:     return ($krbdef,$krbdefdom);
                   2768: }
1.112     bowersj2 2769: 
1.32      matthew  2770: 
1.46      matthew  2771: ###############################################################
                   2772: ##                Thesaurus Functions                        ##
                   2773: ###############################################################
1.20      www      2774: 
1.46      matthew  2775: =pod
1.20      www      2776: 
1.112     bowersj2 2777: =head1 Thesaurus Functions
                   2778: 
                   2779: =over 4
                   2780: 
1.648     raeburn  2781: =item * &initialize_keywords()
1.46      matthew  2782: 
                   2783: Initializes the package variable %Keywords if it is empty.  Uses the
                   2784: package variable $thesaurus_db_file.
                   2785: 
                   2786: =cut
                   2787: 
                   2788: ###################################################
                   2789: 
                   2790: sub initialize_keywords {
                   2791:     return 1 if (scalar keys(%Keywords));
                   2792:     # If we are here, %Keywords is empty, so fill it up
                   2793:     #   Make sure the file we need exists...
                   2794:     if (! -e $thesaurus_db_file) {
                   2795:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
                   2796:                                  " failed because it does not exist");
                   2797:         return 0;
                   2798:     }
                   2799:     #   Set up the hash as a database
                   2800:     my %thesaurus_db;
                   2801:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2802:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2803:         &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
                   2804:                                  $thesaurus_db_file);
                   2805:         return 0;
                   2806:     } 
                   2807:     #  Get the average number of appearances of a word.
                   2808:     my $avecount = $thesaurus_db{'average.count'};
                   2809:     #  Put keywords (those that appear > average) into %Keywords
                   2810:     while (my ($word,$data)=each (%thesaurus_db)) {
                   2811:         my ($count,undef) = split /:/,$data;
                   2812:         $Keywords{$word}++ if ($count > $avecount);
                   2813:     }
                   2814:     untie %thesaurus_db;
                   2815:     # Remove special values from %Keywords.
1.356     albertel 2816:     foreach my $value ('total.count','average.count') {
                   2817:         delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586     raeburn  2818:   }
1.46      matthew  2819:     return 1;
                   2820: }
                   2821: 
                   2822: ###################################################
                   2823: 
                   2824: =pod
                   2825: 
1.648     raeburn  2826: =item * &keyword($word)
1.46      matthew  2827: 
                   2828: Returns true if $word is a keyword.  A keyword is a word that appears more 
                   2829: than the average number of times in the thesaurus database.  Calls 
                   2830: &initialize_keywords
                   2831: 
                   2832: =cut
                   2833: 
                   2834: ###################################################
1.20      www      2835: 
                   2836: sub keyword {
1.46      matthew  2837:     return if (!&initialize_keywords());
                   2838:     my $word=lc(shift());
                   2839:     $word=~s/\W//g;
                   2840:     return exists($Keywords{$word});
1.20      www      2841: }
1.46      matthew  2842: 
                   2843: ###############################################################
                   2844: 
                   2845: =pod 
1.20      www      2846: 
1.648     raeburn  2847: =item * &get_related_words()
1.46      matthew  2848: 
1.160     matthew  2849: Look up a word in the thesaurus.  Takes a scalar argument and returns
1.46      matthew  2850: an array of words.  If the keyword is not in the thesaurus, an empty array
                   2851: will be returned.  The order of the words returned is determined by the
                   2852: database which holds them.
                   2853: 
                   2854: Uses global $thesaurus_db_file.
                   2855: 
                   2856: =cut
                   2857: 
                   2858: ###############################################################
                   2859: sub get_related_words {
                   2860:     my $keyword = shift;
                   2861:     my %thesaurus_db;
                   2862:     if (! -e $thesaurus_db_file) {
                   2863:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
                   2864:                                  "failed because the file does not exist");
                   2865:         return ();
                   2866:     }
                   2867:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2868:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2869:         return ();
                   2870:     } 
                   2871:     my @Words=();
1.429     www      2872:     my $count=0;
1.46      matthew  2873:     if (exists($thesaurus_db{$keyword})) {
1.356     albertel 2874: 	# The first element is the number of times
                   2875: 	# the word appears.  We do not need it now.
1.429     www      2876: 	my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
                   2877: 	my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
                   2878: 	my $threshold=$mostfrequentcount/10;
                   2879:         foreach my $possibleword (@RelatedWords) {
                   2880:             my ($word,$wordcount)=split(/\,/,$possibleword);
                   2881:             if ($wordcount>$threshold) {
                   2882: 		push(@Words,$word);
                   2883:                 $count++;
                   2884:                 if ($count>10) { last; }
                   2885: 	    }
1.20      www      2886:         }
                   2887:     }
1.46      matthew  2888:     untie %thesaurus_db;
                   2889:     return @Words;
1.14      harris41 2890: }
1.46      matthew  2891: 
1.112     bowersj2 2892: =pod
                   2893: 
                   2894: =back
                   2895: 
                   2896: =cut
1.61      www      2897: 
                   2898: # -------------------------------------------------------------- Plaintext name
1.81      albertel 2899: =pod
                   2900: 
1.112     bowersj2 2901: =head1 User Name Functions
                   2902: 
                   2903: =over 4
                   2904: 
1.648     raeburn  2905: =item * &plainname($uname,$udom,$first)
1.81      albertel 2906: 
1.112     bowersj2 2907: Takes a users logon name and returns it as a string in
1.226     albertel 2908: "first middle last generation" form 
                   2909: if $first is set to 'lastname' then it returns it as
                   2910: 'lastname generation, firstname middlename' if their is a lastname
1.81      albertel 2911: 
                   2912: =cut
1.61      www      2913: 
1.295     www      2914: 
1.81      albertel 2915: ###############################################################
1.61      www      2916: sub plainname {
1.226     albertel 2917:     my ($uname,$udom,$first)=@_;
1.537     albertel 2918:     return if (!defined($uname) || !defined($udom));
1.295     www      2919:     my %names=&getnames($uname,$udom);
1.226     albertel 2920:     my $name=&Apache::lonnet::format_name($names{'firstname'},
                   2921: 					  $names{'middlename'},
                   2922: 					  $names{'lastname'},
                   2923: 					  $names{'generation'},$first);
                   2924:     $name=~s/^\s+//;
1.62      www      2925:     $name=~s/\s+$//;
                   2926:     $name=~s/\s+/ /g;
1.353     albertel 2927:     if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62      www      2928:     return $name;
1.61      www      2929: }
1.66      www      2930: 
                   2931: # -------------------------------------------------------------------- Nickname
1.81      albertel 2932: =pod
                   2933: 
1.648     raeburn  2934: =item * &nickname($uname,$udom)
1.81      albertel 2935: 
                   2936: Gets a users name and returns it as a string as
                   2937: 
                   2938: "&quot;nickname&quot;"
1.66      www      2939: 
1.81      albertel 2940: if the user has a nickname or
                   2941: 
                   2942: "first middle last generation"
                   2943: 
                   2944: if the user does not
                   2945: 
                   2946: =cut
1.66      www      2947: 
                   2948: sub nickname {
                   2949:     my ($uname,$udom)=@_;
1.537     albertel 2950:     return if (!defined($uname) || !defined($udom));
1.295     www      2951:     my %names=&getnames($uname,$udom);
1.68      albertel 2952:     my $name=$names{'nickname'};
1.66      www      2953:     if ($name) {
                   2954:        $name='&quot;'.$name.'&quot;'; 
                   2955:     } else {
                   2956:        $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
                   2957: 	     $names{'lastname'}.' '.$names{'generation'};
                   2958:        $name=~s/\s+$//;
                   2959:        $name=~s/\s+/ /g;
                   2960:     }
                   2961:     return $name;
                   2962: }
                   2963: 
1.295     www      2964: sub getnames {
                   2965:     my ($uname,$udom)=@_;
1.537     albertel 2966:     return if (!defined($uname) || !defined($udom));
1.433     albertel 2967:     if ($udom eq 'public' && $uname eq 'public') {
                   2968: 	return ('lastname' => &mt('Public'));
                   2969:     }
1.295     www      2970:     my $id=$uname.':'.$udom;
                   2971:     my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
                   2972:     if ($cached) {
                   2973: 	return %{$names};
                   2974:     } else {
                   2975: 	my %loadnames=&Apache::lonnet::get('environment',
                   2976:                     ['firstname','middlename','lastname','generation','nickname'],
                   2977: 					 $udom,$uname);
                   2978: 	&Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
                   2979: 	return %loadnames;
                   2980:     }
                   2981: }
1.61      www      2982: 
1.542     raeburn  2983: # -------------------------------------------------------------------- getemails
1.648     raeburn  2984: 
1.542     raeburn  2985: =pod
                   2986: 
1.648     raeburn  2987: =item * &getemails($uname,$udom)
1.542     raeburn  2988: 
                   2989: Gets a user's email information and returns it as a hash with keys:
                   2990: notification, critnotification, permanentemail
                   2991: 
                   2992: For notification and critnotification, values are comma-separated lists 
1.648     raeburn  2993: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542     raeburn  2994:  
1.648     raeburn  2995: 
1.542     raeburn  2996: =cut
                   2997: 
1.648     raeburn  2998: 
1.466     albertel 2999: sub getemails {
                   3000:     my ($uname,$udom)=@_;
                   3001:     if ($udom eq 'public' && $uname eq 'public') {
                   3002: 	return;
                   3003:     }
1.467     www      3004:     if (!$udom) { $udom=$env{'user.domain'}; }
                   3005:     if (!$uname) { $uname=$env{'user.name'}; }
1.466     albertel 3006:     my $id=$uname.':'.$udom;
                   3007:     my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
                   3008:     if ($cached) {
                   3009: 	return %{$names};
                   3010:     } else {
                   3011: 	my %loadnames=&Apache::lonnet::get('environment',
                   3012:                     			   ['notification','critnotification',
                   3013: 					    'permanentemail'],
                   3014: 					   $udom,$uname);
                   3015: 	&Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
                   3016: 	return %loadnames;
                   3017:     }
                   3018: }
                   3019: 
1.551     albertel 3020: sub flush_email_cache {
                   3021:     my ($uname,$udom)=@_;
                   3022:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   3023:     if (!$uname) { $uname=$env{'user.name'};   }
                   3024:     return if ($udom eq 'public' && $uname eq 'public');
                   3025:     my $id=$uname.':'.$udom;
                   3026:     &Apache::lonnet::devalidate_cache_new('emailscache',$id);
                   3027: }
                   3028: 
1.728     raeburn  3029: # -------------------------------------------------------------------- getlangs
                   3030: 
                   3031: =pod
                   3032: 
                   3033: =item * &getlangs($uname,$udom)
                   3034: 
                   3035: Gets a user's language preference and returns it as a hash with key:
                   3036: language.
                   3037: 
                   3038: =cut
                   3039: 
                   3040: 
                   3041: sub getlangs {
                   3042:     my ($uname,$udom) = @_;
                   3043:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   3044:     if (!$uname) { $uname=$env{'user.name'};   }
                   3045:     my $id=$uname.':'.$udom;
                   3046:     my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
                   3047:     if ($cached) {
                   3048:         return %{$langs};
                   3049:     } else {
                   3050:         my %loadlangs=&Apache::lonnet::get('environment',['languages'],
                   3051:                                            $udom,$uname);
                   3052:         &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
                   3053:         return %loadlangs;
                   3054:     }
                   3055: }
                   3056: 
                   3057: sub flush_langs_cache {
                   3058:     my ($uname,$udom)=@_;
                   3059:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   3060:     if (!$uname) { $uname=$env{'user.name'};   }
                   3061:     return if ($udom eq 'public' && $uname eq 'public');
                   3062:     my $id=$uname.':'.$udom;
                   3063:     &Apache::lonnet::devalidate_cache_new('userlangs',$id);
                   3064: }
                   3065: 
1.61      www      3066: # ------------------------------------------------------------------ Screenname
1.81      albertel 3067: 
                   3068: =pod
                   3069: 
1.648     raeburn  3070: =item * &screenname($uname,$udom)
1.81      albertel 3071: 
                   3072: Gets a users screenname and returns it as a string
                   3073: 
                   3074: =cut
1.61      www      3075: 
                   3076: sub screenname {
                   3077:     my ($uname,$udom)=@_;
1.258     albertel 3078:     if ($uname eq $env{'user.name'} &&
                   3079: 	$udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212     albertel 3080:     my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68      albertel 3081:     return $names{'screenname'};
1.62      www      3082: }
                   3083: 
1.212     albertel 3084: 
1.802     bisitz   3085: # ------------------------------------------------------------- Confirm Wrapper
                   3086: =pod
                   3087: 
                   3088: =item confirmwrapper
                   3089: 
                   3090: Wrap messages about completion of operation in box
                   3091: 
                   3092: =cut
                   3093: 
                   3094: sub confirmwrapper {
                   3095:     my ($message)=@_;
                   3096:     if ($message) {
                   3097:         return "\n".'<div class="LC_confirm_box">'."\n"
                   3098:                .$message."\n"
                   3099:                .'</div>'."\n";
                   3100:     } else {
                   3101:         return $message;
                   3102:     }
                   3103: }
                   3104: 
1.62      www      3105: # ------------------------------------------------------------- Message Wrapper
                   3106: 
                   3107: sub messagewrapper {
1.369     www      3108:     my ($link,$username,$domain,$subject,$text)=@_;
1.62      www      3109:     return 
1.441     albertel 3110:         '<a href="/adm/email?compose=individual&amp;'.
                   3111:         'recname='.$username.'&amp;recdom='.$domain.
                   3112: 	'&amp;subject='.&escape($subject).'&amp;text='.&escape($text).'" '.
1.200     matthew  3113:         'title="'.&mt('Send message').'">'.$link.'</a>';
1.74      www      3114: }
1.802     bisitz   3115: 
1.74      www      3116: # --------------------------------------------------------------- Notes Wrapper
                   3117: 
                   3118: sub noteswrapper {
                   3119:     my ($link,$un,$do)=@_;
                   3120:     return 
1.896     amueller 3121: "<a href='/adm/email?recordftf=retrieve&amp;recname=$un&amp;recdom=$do'>$link</a>";
1.62      www      3122: }
1.802     bisitz   3123: 
1.62      www      3124: # ------------------------------------------------------------- Aboutme Wrapper
                   3125: 
                   3126: sub aboutmewrapper {
1.166     www      3127:     my ($link,$username,$domain,$target)=@_;
1.447     raeburn  3128:     if (!defined($username)  && !defined($domain)) {
                   3129:         return;
                   3130:     }
1.892     amueller 3131:     return '<a href="/adm/'.$domain.'/'.$username.'/aboutme?forcestudent=1"'.
1.756     weissno  3132: 	($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62      www      3133: }
                   3134: 
                   3135: # ------------------------------------------------------------ Syllabus Wrapper
                   3136: 
                   3137: sub syllabuswrapper {
1.707     bisitz   3138:     my ($linktext,$coursedir,$domain)=@_;
1.208     matthew  3139:     return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61      www      3140: }
1.14      harris41 3141: 
1.802     bisitz   3142: # -----------------------------------------------------------------------------
                   3143: 
1.208     matthew  3144: sub track_student_link {
1.887     raeburn  3145:     my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268     albertel 3146:     my $link ="/adm/trackstudent?";
1.208     matthew  3147:     my $title = 'View recent activity';
                   3148:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   3149:         defined($sdom)  && $sdom  !~ /^\s*$/) {
1.268     albertel 3150:         $link .= "selected_student=$sname:$sdom";
1.208     matthew  3151:         $title .= ' of this student';
1.268     albertel 3152:     } 
1.208     matthew  3153:     if (defined($target) && $target !~ /^\s*$/) {
                   3154:         $target = qq{target="$target"};
                   3155:     } else {
                   3156:         $target = '';
                   3157:     }
1.268     albertel 3158:     if ($start) { $link.='&amp;start='.$start; }
1.887     raeburn  3159:     if ($only_body) { $link .= '&amp;only_body=1'; }
1.554     albertel 3160:     $title = &mt($title);
                   3161:     $linktext = &mt($linktext);
1.448     albertel 3162:     return qq{<a href="$link" title="$title" $target>$linktext</a>}.
                   3163: 	&help_open_topic('View_recent_activity');
1.208     matthew  3164: }
                   3165: 
1.781     raeburn  3166: sub slot_reservations_link {
                   3167:     my ($linktext,$sname,$sdom,$target) = @_;
                   3168:     my $link ="/adm/slotrequest?command=showresv&amp;origin=aboutme";
                   3169:     my $title = 'View slot reservation history';
                   3170:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   3171:         defined($sdom)  && $sdom  !~ /^\s*$/) {
                   3172:         $link .= "&amp;uname=$sname&amp;udom=$sdom";
                   3173:         $title .= ' of this student';
                   3174:     }
                   3175:     if (defined($target) && $target !~ /^\s*$/) {
                   3176:         $target = qq{target="$target"};
                   3177:     } else {
                   3178:         $target = '';
                   3179:     }
                   3180:     $title = &mt($title);
                   3181:     $linktext = &mt($linktext);
                   3182:     return qq{<a href="$link" title="$title" $target>$linktext</a>};
                   3183: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
                   3184: 
                   3185: }
                   3186: 
1.508     www      3187: # ===================================================== Display a student photo
                   3188: 
                   3189: 
1.509     albertel 3190: sub student_image_tag {
1.508     www      3191:     my ($domain,$user)=@_;
                   3192:     my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
                   3193:     if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
                   3194: 	return '<img src="'.$imgsrc.'" align="right" />';
                   3195:     } else {
                   3196: 	return '';
                   3197:     }
                   3198: }
                   3199: 
1.112     bowersj2 3200: =pod
                   3201: 
                   3202: =back
                   3203: 
                   3204: =head1 Access .tab File Data
                   3205: 
                   3206: =over 4
                   3207: 
1.648     raeburn  3208: =item * &languageids() 
1.112     bowersj2 3209: 
                   3210: returns list of all language ids
                   3211: 
                   3212: =cut
                   3213: 
1.14      harris41 3214: sub languageids {
1.16      harris41 3215:     return sort(keys(%language));
1.14      harris41 3216: }
                   3217: 
1.112     bowersj2 3218: =pod
                   3219: 
1.648     raeburn  3220: =item * &languagedescription() 
1.112     bowersj2 3221: 
                   3222: returns description of a specified language id
                   3223: 
                   3224: =cut
                   3225: 
1.14      harris41 3226: sub languagedescription {
1.125     www      3227:     my $code=shift;
                   3228:     return  ($supported_language{$code}?'* ':'').
                   3229:             $language{$code}.
1.126     www      3230: 	    ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145     www      3231: }
                   3232: 
                   3233: sub plainlanguagedescription {
                   3234:     my $code=shift;
                   3235:     return $language{$code};
                   3236: }
                   3237: 
                   3238: sub supportedlanguagecode {
                   3239:     my $code=shift;
                   3240:     return $supported_language{$code};
1.97      www      3241: }
                   3242: 
1.112     bowersj2 3243: =pod
                   3244: 
1.648     raeburn  3245: =item * &copyrightids() 
1.112     bowersj2 3246: 
                   3247: returns list of all copyrights
                   3248: 
                   3249: =cut
                   3250: 
                   3251: sub copyrightids {
                   3252:     return sort(keys(%cprtag));
                   3253: }
                   3254: 
                   3255: =pod
                   3256: 
1.648     raeburn  3257: =item * &copyrightdescription() 
1.112     bowersj2 3258: 
                   3259: returns description of a specified copyright id
                   3260: 
                   3261: =cut
                   3262: 
                   3263: sub copyrightdescription {
1.166     www      3264:     return &mt($cprtag{shift(@_)});
1.112     bowersj2 3265: }
1.197     matthew  3266: 
                   3267: =pod
                   3268: 
1.648     raeburn  3269: =item * &source_copyrightids() 
1.192     taceyjo1 3270: 
                   3271: returns list of all source copyrights
                   3272: 
                   3273: =cut
                   3274: 
                   3275: sub source_copyrightids {
                   3276:     return sort(keys(%scprtag));
                   3277: }
                   3278: 
                   3279: =pod
                   3280: 
1.648     raeburn  3281: =item * &source_copyrightdescription() 
1.192     taceyjo1 3282: 
                   3283: returns description of a specified source copyright id
                   3284: 
                   3285: =cut
                   3286: 
                   3287: sub source_copyrightdescription {
                   3288:     return &mt($scprtag{shift(@_)});
                   3289: }
1.112     bowersj2 3290: 
                   3291: =pod
                   3292: 
1.648     raeburn  3293: =item * &filecategories() 
1.112     bowersj2 3294: 
                   3295: returns list of all file categories
                   3296: 
                   3297: =cut
                   3298: 
                   3299: sub filecategories {
                   3300:     return sort(keys(%category_extensions));
                   3301: }
                   3302: 
                   3303: =pod
                   3304: 
1.648     raeburn  3305: =item * &filecategorytypes() 
1.112     bowersj2 3306: 
                   3307: returns list of file types belonging to a given file
                   3308: category
                   3309: 
                   3310: =cut
                   3311: 
                   3312: sub filecategorytypes {
1.356     albertel 3313:     my ($cat) = @_;
                   3314:     return @{$category_extensions{lc($cat)}};
1.112     bowersj2 3315: }
                   3316: 
                   3317: =pod
                   3318: 
1.648     raeburn  3319: =item * &fileembstyle() 
1.112     bowersj2 3320: 
                   3321: returns embedding style for a specified file type
                   3322: 
                   3323: =cut
                   3324: 
                   3325: sub fileembstyle {
                   3326:     return $fe{lc(shift(@_))};
1.169     www      3327: }
                   3328: 
1.351     www      3329: sub filemimetype {
                   3330:     return $fm{lc(shift(@_))};
                   3331: }
                   3332: 
1.169     www      3333: 
                   3334: sub filecategoryselect {
                   3335:     my ($name,$value)=@_;
1.189     matthew  3336:     return &select_form($value,$name,
1.970     raeburn  3337:                         {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112     bowersj2 3338: }
                   3339: 
                   3340: =pod
                   3341: 
1.648     raeburn  3342: =item * &filedescription() 
1.112     bowersj2 3343: 
                   3344: returns description for a specified file type
                   3345: 
                   3346: =cut
                   3347: 
                   3348: sub filedescription {
1.188     matthew  3349:     my $file_description = $fd{lc(shift())};
                   3350:     $file_description =~ s:([\[\]]):~$1:g;
                   3351:     return &mt($file_description);
1.112     bowersj2 3352: }
                   3353: 
                   3354: =pod
                   3355: 
1.648     raeburn  3356: =item * &filedescriptionex() 
1.112     bowersj2 3357: 
                   3358: returns description for a specified file type with
                   3359: extra formatting
                   3360: 
                   3361: =cut
                   3362: 
                   3363: sub filedescriptionex {
                   3364:     my $ex=shift;
1.188     matthew  3365:     my $file_description = $fd{lc($ex)};
                   3366:     $file_description =~ s:([\[\]]):~$1:g;
                   3367:     return '.'.$ex.' '.&mt($file_description);
1.112     bowersj2 3368: }
                   3369: 
                   3370: # End of .tab access
                   3371: =pod
                   3372: 
                   3373: =back
                   3374: 
                   3375: =cut
                   3376: 
                   3377: # ------------------------------------------------------------------ File Types
                   3378: sub fileextensions {
                   3379:     return sort(keys(%fe));
                   3380: }
                   3381: 
1.97      www      3382: # ----------------------------------------------------------- Display Languages
                   3383: # returns a hash with all desired display languages
                   3384: #
                   3385: 
                   3386: sub display_languages {
                   3387:     my %languages=();
1.695     raeburn  3388:     foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356     albertel 3389: 	$languages{$lang}=1;
1.97      www      3390:     }
                   3391:     &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258     albertel 3392:     if ($env{'form.displaylanguage'}) {
1.356     albertel 3393: 	foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
                   3394: 	    $languages{$lang}=1;
1.97      www      3395:         }
                   3396:     }
                   3397:     return %languages;
1.14      harris41 3398: }
                   3399: 
1.582     albertel 3400: sub languages {
                   3401:     my ($possible_langs) = @_;
1.695     raeburn  3402:     my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582     albertel 3403:     if (!ref($possible_langs)) {
                   3404: 	if( wantarray ) {
                   3405: 	    return @preferred_langs;
                   3406: 	} else {
                   3407: 	    return $preferred_langs[0];
                   3408: 	}
                   3409:     }
                   3410:     my %possibilities = map { $_ => 1 } (@$possible_langs);
                   3411:     my @preferred_possibilities;
                   3412:     foreach my $preferred_lang (@preferred_langs) {
                   3413: 	if (exists($possibilities{$preferred_lang})) {
                   3414: 	    push(@preferred_possibilities, $preferred_lang);
                   3415: 	}
                   3416:     }
                   3417:     if( wantarray ) {
                   3418: 	return @preferred_possibilities;
                   3419:     }
                   3420:     return $preferred_possibilities[0];
                   3421: }
                   3422: 
1.742     raeburn  3423: sub user_lang {
                   3424:     my ($touname,$toudom,$fromcid) = @_;
                   3425:     my @userlangs;
                   3426:     if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
                   3427:         @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
                   3428:                     $env{'course.'.$fromcid.'.languages'}));
                   3429:     } else {
                   3430:         my %langhash = &getlangs($touname,$toudom);
                   3431:         if ($langhash{'languages'} ne '') {
                   3432:             @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
                   3433:         } else {
                   3434:             my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
                   3435:             if ($domdefs{'lang_def'} ne '') {
                   3436:                 @userlangs = ($domdefs{'lang_def'});
                   3437:             }
                   3438:         }
                   3439:     }
                   3440:     my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
                   3441:     my $user_lh = Apache::localize->get_handle(@languages);
                   3442:     return $user_lh;
                   3443: }
                   3444: 
                   3445: 
1.112     bowersj2 3446: ###############################################################
                   3447: ##               Student Answer Attempts                     ##
                   3448: ###############################################################
                   3449: 
                   3450: =pod
                   3451: 
                   3452: =head1 Alternate Problem Views
                   3453: 
                   3454: =over 4
                   3455: 
1.648     raeburn  3456: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112     bowersj2 3457:     $getattempt, $regexp, $gradesub)
                   3458: 
                   3459: Return string with previous attempt on problem. Arguments:
                   3460: 
                   3461: =over 4
                   3462: 
                   3463: =item * $symb: Problem, including path
                   3464: 
                   3465: =item * $username: username of the desired student
                   3466: 
                   3467: =item * $domain: domain of the desired student
1.14      harris41 3468: 
1.112     bowersj2 3469: =item * $course: Course ID
1.14      harris41 3470: 
1.112     bowersj2 3471: =item * $getattempt: Leave blank for all attempts, otherwise put
                   3472:     something
1.14      harris41 3473: 
1.112     bowersj2 3474: =item * $regexp: if string matches this regexp, the string will be
                   3475:     sent to $gradesub
1.14      harris41 3476: 
1.112     bowersj2 3477: =item * $gradesub: routine that processes the string if it matches $regexp
1.14      harris41 3478: 
1.112     bowersj2 3479: =back
1.14      harris41 3480: 
1.112     bowersj2 3481: The output string is a table containing all desired attempts, if any.
1.16      harris41 3482: 
1.112     bowersj2 3483: =cut
1.1       albertel 3484: 
                   3485: sub get_previous_attempt {
1.43      ng       3486:   my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1       albertel 3487:   my $prevattempts='';
1.43      ng       3488:   no strict 'refs';
1.1       albertel 3489:   if ($symb) {
1.3       albertel 3490:     my (%returnhash)=
                   3491:       &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1       albertel 3492:     if ($returnhash{'version'}) {
                   3493:       my %lasthash=();
                   3494:       my $version;
                   3495:       for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356     albertel 3496:         foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
                   3497: 	  $lasthash{$key}=$returnhash{$version.':'.$key};
1.19      harris41 3498:         }
1.1       albertel 3499:       }
1.596     albertel 3500:       $prevattempts=&start_data_table().&start_data_table_header_row();
                   3501:       $prevattempts.='<th>'.&mt('History').'</th>';
1.978     raeburn  3502:       my (%typeparts,%lasthidden);
1.945     raeburn  3503:       my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356     albertel 3504:       foreach my $key (sort(keys(%lasthash))) {
                   3505: 	my ($ign,@parts) = split(/\./,$key);
1.41      ng       3506: 	if ($#parts > 0) {
1.31      albertel 3507: 	  my $data=$parts[-1];
1.989     raeburn  3508:           next if ($data eq 'foilorder');
1.31      albertel 3509: 	  pop(@parts);
1.1010    www      3510:           $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.'&nbsp;</th>';
1.945     raeburn  3511:           if ($data eq 'type') {
                   3512:               unless ($showsurv) {
                   3513:                   my $id = join(',',@parts);
                   3514:                   $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978     raeburn  3515:                   if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
                   3516:                       $lasthidden{$ign.'.'.$id} = 1;
                   3517:                   }
1.945     raeburn  3518:               }
1.1010    www      3519:           } 
1.31      albertel 3520: 	} else {
1.41      ng       3521: 	  if ($#parts == 0) {
                   3522: 	    $prevattempts.='<th>'.$parts[0].'</th>';
                   3523: 	  } else {
                   3524: 	    $prevattempts.='<th>'.$ign.'</th>';
                   3525: 	  }
1.31      albertel 3526: 	}
1.16      harris41 3527:       }
1.596     albertel 3528:       $prevattempts.=&end_data_table_header_row();
1.40      ng       3529:       if ($getattempt eq '') {
                   3530: 	for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945     raeburn  3531:             my @hidden;
                   3532:             if (%typeparts) {
                   3533:                 foreach my $id (keys(%typeparts)) {
                   3534:                     if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
                   3535:                         push(@hidden,$id);
                   3536:                     }
                   3537:                 }
                   3538:             }
                   3539:             $prevattempts.=&start_data_table_row().
                   3540:                            '<td>'.&mt('Transaction [_1]',$version).'</td>';
                   3541:             if (@hidden) {
                   3542:                 foreach my $key (sort(keys(%lasthash))) {
1.989     raeburn  3543:                     next if ($key =~ /\.foilorder$/);
1.945     raeburn  3544:                     my $hide;
                   3545:                     foreach my $id (@hidden) {
                   3546:                         if ($key =~ /^\Q$id\E/) {
                   3547:                             $hide = 1;
                   3548:                             last;
                   3549:                         }
                   3550:                     }
                   3551:                     if ($hide) {
                   3552:                         my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
                   3553:                         if (($data eq 'award') || ($data eq 'awarddetail')) {
                   3554:                             my $value = &format_previous_attempt_value($key,
                   3555:                                              $returnhash{$version.':'.$key});
                   3556:                             $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3557:                         } else {
                   3558:                             $prevattempts.='<td>&nbsp;</td>';
                   3559:                         }
                   3560:                     } else {
                   3561:                         if ($key =~ /\./) {
                   3562:                             my $value = &format_previous_attempt_value($key,
                   3563:                                               $returnhash{$version.':'.$key});
                   3564:                             $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3565:                         } else {
                   3566:                             $prevattempts.='<td>&nbsp;</td>';
                   3567:                         }
                   3568:                     }
                   3569:                 }
                   3570:             } else {
                   3571: 	        foreach my $key (sort(keys(%lasthash))) {
1.989     raeburn  3572:                     next if ($key =~ /\.foilorder$/);
1.945     raeburn  3573: 		    my $value = &format_previous_attempt_value($key,
                   3574: 			            $returnhash{$version.':'.$key});
                   3575: 		    $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3576: 	        }
                   3577:             }
                   3578: 	    $prevattempts.=&end_data_table_row();
1.40      ng       3579: 	 }
1.1       albertel 3580:       }
1.945     raeburn  3581:       my @currhidden = keys(%lasthidden);
1.596     albertel 3582:       $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356     albertel 3583:       foreach my $key (sort(keys(%lasthash))) {
1.989     raeburn  3584:           next if ($key =~ /\.foilorder$/);
1.945     raeburn  3585:           if (%typeparts) {
                   3586:               my $hidden;
                   3587:               foreach my $id (@currhidden) {
                   3588:                   if ($key =~ /^\Q$id\E/) {
                   3589:                       $hidden = 1;
                   3590:                       last;
                   3591:                   }
                   3592:               }
                   3593:               if ($hidden) {
                   3594:                   my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
                   3595:                   if (($data eq 'award') || ($data eq 'awarddetail')) {
                   3596:                       my $value = &format_previous_attempt_value($key,$lasthash{$key});
                   3597:                       if ($key =~/$regexp$/ && (defined &$gradesub)) {
                   3598:                           $value = &$gradesub($value);
                   3599:                       }
                   3600:                       $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3601:                   } else {
                   3602:                       $prevattempts.='<td>&nbsp;</td>';
                   3603:                   }
                   3604:               } else {
                   3605:                   my $value = &format_previous_attempt_value($key,$lasthash{$key});
                   3606:                   if ($key =~/$regexp$/ && (defined &$gradesub)) {
                   3607:                       $value = &$gradesub($value);
                   3608:                   }
                   3609:                   $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3610:               }
                   3611:           } else {
                   3612: 	      my $value = &format_previous_attempt_value($key,$lasthash{$key});
                   3613: 	      if ($key =~/$regexp$/ && (defined &$gradesub)) {
                   3614:                   $value = &$gradesub($value);
                   3615:               }
                   3616: 	      $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3617:           }
1.16      harris41 3618:       }
1.596     albertel 3619:       $prevattempts.= &end_data_table_row().&end_data_table();
1.1       albertel 3620:     } else {
1.596     albertel 3621:       $prevattempts=
                   3622: 	  &start_data_table().&start_data_table_row().
                   3623: 	  '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
                   3624: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3625:     }
                   3626:   } else {
1.596     albertel 3627:     $prevattempts=
                   3628: 	  &start_data_table().&start_data_table_row().
                   3629: 	  '<td>'.&mt('No data.').'</td>'.
                   3630: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3631:   }
1.10      albertel 3632: }
                   3633: 
1.581     albertel 3634: sub format_previous_attempt_value {
                   3635:     my ($key,$value) = @_;
1.1011    www      3636:     if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581     albertel 3637: 	$value = &Apache::lonlocal::locallocaltime($value);
                   3638:     } elsif (ref($value) eq 'ARRAY') {
                   3639: 	$value = '('.join(', ', @{ $value }).')';
1.988     raeburn  3640:     } elsif ($key =~ /answerstring$/) {
                   3641:         my %answers = &Apache::lonnet::str2hash($value);
                   3642:         my @anskeys = sort(keys(%answers));
                   3643:         if (@anskeys == 1) {
                   3644:             my $answer = $answers{$anskeys[0]};
1.1001    raeburn  3645:             if ($answer =~ m{\0}) {
                   3646:                 $answer =~ s{\0}{,}g;
1.988     raeburn  3647:             }
                   3648:             my $tag_internal_answer_name = 'INTERNAL';
                   3649:             if ($anskeys[0] eq $tag_internal_answer_name) {
                   3650:                 $value = $answer; 
                   3651:             } else {
                   3652:                 $value = $anskeys[0].'='.$answer;
                   3653:             }
                   3654:         } else {
                   3655:             foreach my $ans (@anskeys) {
                   3656:                 my $answer = $answers{$ans};
1.1001    raeburn  3657:                 if ($answer =~ m{\0}) {
                   3658:                     $answer =~ s{\0}{,}g;
1.988     raeburn  3659:                 }
                   3660:                 $value .=  $ans.'='.$answer.'<br />';;
                   3661:             } 
                   3662:         }
1.581     albertel 3663:     } else {
                   3664: 	$value = &unescape($value);
                   3665:     }
                   3666:     return $value;
                   3667: }
                   3668: 
                   3669: 
1.107     albertel 3670: sub relative_to_absolute {
                   3671:     my ($url,$output)=@_;
                   3672:     my $parser=HTML::TokeParser->new(\$output);
                   3673:     my $token;
                   3674:     my $thisdir=$url;
                   3675:     my @rlinks=();
                   3676:     while ($token=$parser->get_token) {
                   3677: 	if ($token->[0] eq 'S') {
                   3678: 	    if ($token->[1] eq 'a') {
                   3679: 		if ($token->[2]->{'href'}) {
                   3680: 		    $rlinks[$#rlinks+1]=$token->[2]->{'href'};
                   3681: 		}
                   3682: 	    } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
                   3683: 		$rlinks[$#rlinks+1]=$token->[2]->{'src'};
                   3684: 	    } elsif ($token->[1] eq 'base') {
                   3685: 		$thisdir=$token->[2]->{'href'};
                   3686: 	    }
                   3687: 	}
                   3688:     }
                   3689:     $thisdir=~s-/[^/]*$--;
1.356     albertel 3690:     foreach my $link (@rlinks) {
1.726     raeburn  3691: 	unless (($link=~/^https?\:\/\//i) ||
1.356     albertel 3692: 		($link=~/^\//) ||
                   3693: 		($link=~/^javascript:/i) ||
                   3694: 		($link=~/^mailto:/i) ||
                   3695: 		($link=~/^\#/)) {
                   3696: 	    my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
                   3697: 	    $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107     albertel 3698: 	}
                   3699:     }
                   3700: # -------------------------------------------------- Deal with Applet codebases
                   3701:     $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
                   3702:     return $output;
                   3703: }
                   3704: 
1.112     bowersj2 3705: =pod
                   3706: 
1.648     raeburn  3707: =item * &get_student_view()
1.112     bowersj2 3708: 
                   3709: show a snapshot of what student was looking at
                   3710: 
                   3711: =cut
                   3712: 
1.10      albertel 3713: sub get_student_view {
1.186     albertel 3714:   my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114     www      3715:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3716:   my (%form);
1.10      albertel 3717:   my @elements=('symb','courseid','domain','username');
                   3718:   foreach my $element (@elements) {
1.186     albertel 3719:       $form{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3720:   }
1.186     albertel 3721:   if (defined($moreenv)) {
                   3722:       %form=(%form,%{$moreenv});
                   3723:   }
1.236     albertel 3724:   if (defined($target)) { $form{'grade_target'} = $target; }
1.107     albertel 3725:   $feedurl=&Apache::lonnet::clutter($feedurl);
1.650     www      3726:   my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11      albertel 3727:   $userview=~s/\<body[^\>]*\>//gi;
                   3728:   $userview=~s/\<\/body\>//gi;
                   3729:   $userview=~s/\<html\>//gi;
                   3730:   $userview=~s/\<\/html\>//gi;
                   3731:   $userview=~s/\<head\>//gi;
                   3732:   $userview=~s/\<\/head\>//gi;
                   3733:   $userview=~s/action\s*\=/would_be_action\=/gi;
1.107     albertel 3734:   $userview=&relative_to_absolute($feedurl,$userview);
1.650     www      3735:   if (wantarray) {
                   3736:      return ($userview,$response);
                   3737:   } else {
                   3738:      return $userview;
                   3739:   }
                   3740: }
                   3741: 
                   3742: sub get_student_view_with_retries {
                   3743:   my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
                   3744: 
                   3745:     my $ok = 0;                 # True if we got a good response.
                   3746:     my $content;
                   3747:     my $response;
                   3748: 
                   3749:     # Try to get the student_view done. within the retries count:
                   3750:     
                   3751:     do {
                   3752:          ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
                   3753:          $ok      = $response->is_success;
                   3754:          if (!$ok) {
                   3755:             &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
                   3756:          }
                   3757:          $retries--;
                   3758:     } while (!$ok && ($retries > 0));
                   3759:     
                   3760:     if (!$ok) {
                   3761:        $content = '';          # On error return an empty content.
                   3762:     }
1.651     www      3763:     if (wantarray) {
                   3764:        return ($content, $response);
                   3765:     } else {
                   3766:        return $content;
                   3767:     }
1.11      albertel 3768: }
                   3769: 
1.112     bowersj2 3770: =pod
                   3771: 
1.648     raeburn  3772: =item * &get_student_answers() 
1.112     bowersj2 3773: 
                   3774: show a snapshot of how student was answering problem
                   3775: 
                   3776: =cut
                   3777: 
1.11      albertel 3778: sub get_student_answers {
1.100     sakharuk 3779:   my ($symb,$username,$domain,$courseid,%form) = @_;
1.114     www      3780:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3781:   my (%moreenv);
1.11      albertel 3782:   my @elements=('symb','courseid','domain','username');
                   3783:   foreach my $element (@elements) {
1.186     albertel 3784:     $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3785:   }
1.186     albertel 3786:   $moreenv{'grade_target'}='answer';
                   3787:   %moreenv=(%form,%moreenv);
1.497     raeburn  3788:   $feedurl = &Apache::lonnet::clutter($feedurl);
                   3789:   my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10      albertel 3790:   return $userview;
1.1       albertel 3791: }
1.116     albertel 3792: 
                   3793: =pod
                   3794: 
                   3795: =item * &submlink()
                   3796: 
1.242     albertel 3797: Inputs: $text $uname $udom $symb $target
1.116     albertel 3798: 
                   3799: Returns: A link to grades.pm such as to see the SUBM view of a student
                   3800: 
                   3801: =cut
                   3802: 
                   3803: ###############################################
                   3804: sub submlink {
1.242     albertel 3805:     my ($text,$uname,$udom,$symb,$target)=@_;
1.116     albertel 3806:     if (!($uname && $udom)) {
                   3807: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3808: 	    &Apache::lonnet::whichuser($symb);
1.116     albertel 3809: 	if (!$symb) { $symb=$cursymb; }
                   3810:     }
1.254     matthew  3811:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3812:     $symb=&escape($symb);
1.960     bisitz   3813:     if ($target) { $target=" target=\"$target\""; }
                   3814:     return
                   3815:         '<a href="/adm/grades?command=submission'.
                   3816:         '&amp;symb='.$symb.
                   3817:         '&amp;student='.$uname.
                   3818:         '&amp;userdom='.$udom.'"'.
                   3819:         $target.'>'.$text.'</a>';
1.242     albertel 3820: }
                   3821: ##############################################
                   3822: 
                   3823: =pod
                   3824: 
                   3825: =item * &pgrdlink()
                   3826: 
                   3827: Inputs: $text $uname $udom $symb $target
                   3828: 
                   3829: Returns: A link to grades.pm such as to see the PGRD view of a student
                   3830: 
                   3831: =cut
                   3832: 
                   3833: ###############################################
                   3834: sub pgrdlink {
                   3835:     my $link=&submlink(@_);
                   3836:     $link=~s/(&command=submission)/$1&showgrading=yes/;
                   3837:     return $link;
                   3838: }
                   3839: ##############################################
                   3840: 
                   3841: =pod
                   3842: 
                   3843: =item * &pprmlink()
                   3844: 
                   3845: Inputs: $text $uname $udom $symb $target
                   3846: 
                   3847: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283     albertel 3848: student and a specific resource
1.242     albertel 3849: 
                   3850: =cut
                   3851: 
                   3852: ###############################################
                   3853: sub pprmlink {
                   3854:     my ($text,$uname,$udom,$symb,$target)=@_;
                   3855:     if (!($uname && $udom)) {
                   3856: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3857: 	    &Apache::lonnet::whichuser($symb);
1.242     albertel 3858: 	if (!$symb) { $symb=$cursymb; }
                   3859:     }
1.254     matthew  3860:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3861:     $symb=&escape($symb);
1.242     albertel 3862:     if ($target) { $target="target=\"$target\""; }
1.595     albertel 3863:     return '<a href="/adm/parmset?command=set&amp;'.
                   3864: 	'symb='.$symb.'&amp;uname='.$uname.
                   3865: 	'&amp;udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116     albertel 3866: }
                   3867: ##############################################
1.37      matthew  3868: 
1.112     bowersj2 3869: =pod
                   3870: 
                   3871: =back
                   3872: 
                   3873: =cut
                   3874: 
1.37      matthew  3875: ###############################################
1.51      www      3876: 
                   3877: 
                   3878: sub timehash {
1.687     raeburn  3879:     my ($thistime) = @_;
                   3880:     my $timezone = &Apache::lonlocal::gettimezone();
                   3881:     my $dt = DateTime->from_epoch(epoch => $thistime)
                   3882:                      ->set_time_zone($timezone);
                   3883:     my $wday = $dt->day_of_week();
                   3884:     if ($wday == 7) { $wday = 0; }
                   3885:     return ( 'second' => $dt->second(),
                   3886:              'minute' => $dt->minute(),
                   3887:              'hour'   => $dt->hour(),
                   3888:              'day'     => $dt->day_of_month(),
                   3889:              'month'   => $dt->month(),
                   3890:              'year'    => $dt->year(),
                   3891:              'weekday' => $wday,
                   3892:              'dayyear' => $dt->day_of_year(),
                   3893:              'dlsav'   => $dt->is_dst() );
1.51      www      3894: }
                   3895: 
1.370     www      3896: sub utc_string {
                   3897:     my ($date)=@_;
1.371     www      3898:     return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370     www      3899: }
                   3900: 
1.51      www      3901: sub maketime {
                   3902:     my %th=@_;
1.687     raeburn  3903:     my ($epoch_time,$timezone,$dt);
                   3904:     $timezone = &Apache::lonlocal::gettimezone();
                   3905:     eval {
                   3906:         $dt = DateTime->new( year   => $th{'year'},
                   3907:                              month  => $th{'month'},
                   3908:                              day    => $th{'day'},
                   3909:                              hour   => $th{'hour'},
                   3910:                              minute => $th{'minute'},
                   3911:                              second => $th{'second'},
                   3912:                              time_zone => $timezone,
                   3913:                          );
                   3914:     };
                   3915:     if (!$@) {
                   3916:         $epoch_time = $dt->epoch;
                   3917:         if ($epoch_time) {
                   3918:             return $epoch_time;
                   3919:         }
                   3920:     }
1.51      www      3921:     return POSIX::mktime(
                   3922:         ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210     www      3923:          $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70      www      3924: }
                   3925: 
                   3926: #########################################
1.51      www      3927: 
                   3928: sub findallcourses {
1.482     raeburn  3929:     my ($roles,$uname,$udom) = @_;
1.355     albertel 3930:     my %roles;
                   3931:     if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348     albertel 3932:     my %courses;
1.51      www      3933:     my $now=time;
1.482     raeburn  3934:     if (!defined($uname)) {
                   3935:         $uname = $env{'user.name'};
                   3936:     }
                   3937:     if (!defined($udom)) {
                   3938:         $udom = $env{'user.domain'};
                   3939:     }
                   3940:     if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.982     raeburn  3941:         my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
                   3942:         my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname,'.',undef,
                   3943:                                               $extra);
1.482     raeburn  3944:         if (!%roles) {
                   3945:             %roles = (
                   3946:                        cc => 1,
1.907     raeburn  3947:                        co => 1,
1.482     raeburn  3948:                        in => 1,
                   3949:                        ep => 1,
                   3950:                        ta => 1,
                   3951:                        cr => 1,
                   3952:                        st => 1,
                   3953:              );
                   3954:         }
                   3955:         foreach my $entry (keys(%roleshash)) {
                   3956:             my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
                   3957:             if ($trole =~ /^cr/) { 
                   3958:                 next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
                   3959:             } else {
                   3960:                 next if (!exists($roles{$trole}));
                   3961:             }
                   3962:             if ($tend) {
                   3963:                 next if ($tend < $now);
                   3964:             }
                   3965:             if ($tstart) {
                   3966:                 next if ($tstart > $now);
                   3967:             }
                   3968:             my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
                   3969:             (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
                   3970:             if ($secpart eq '') {
                   3971:                 ($cnum,$role) = split(/_/,$cnumpart); 
                   3972:                 $sec = 'none';
                   3973:                 $realsec = '';
                   3974:             } else {
                   3975:                 $cnum = $cnumpart;
                   3976:                 ($sec,$role) = split(/_/,$secpart);
                   3977:                 $realsec = $sec;
1.490     raeburn  3978:             }
1.482     raeburn  3979:             $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
                   3980:         }
                   3981:     } else {
                   3982:         foreach my $key (keys(%env)) {
1.483     albertel 3983: 	    if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
                   3984:                  $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482     raeburn  3985: 	        my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
                   3986: 	        next if ($role eq 'ca' || $role eq 'aa');
                   3987: 	        next if (%roles && !exists($roles{$role}));
                   3988: 	        my ($starttime,$endtime)=split(/\./,$env{$key});
                   3989:                 my $active=1;
                   3990:                 if ($starttime) {
                   3991: 		    if ($now<$starttime) { $active=0; }
                   3992:                 }
                   3993:                 if ($endtime) {
                   3994:                     if ($now>$endtime) { $active=0; }
                   3995:                 }
                   3996:                 if ($active) {
                   3997:                     if ($sec eq '') {
                   3998:                         $sec = 'none';
                   3999:                     }
                   4000:                     $courses{$cdom.'_'.$cnum}{$sec} = 
                   4001:                                      $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474     raeburn  4002:                 }
                   4003:             }
1.51      www      4004:         }
                   4005:     }
1.474     raeburn  4006:     return %courses;
1.51      www      4007: }
1.37      matthew  4008: 
1.54      www      4009: ###############################################
1.474     raeburn  4010: 
                   4011: sub blockcheck {
1.482     raeburn  4012:     my ($setters,$activity,$uname,$udom) = @_;
1.490     raeburn  4013: 
                   4014:     if (!defined($udom)) {
                   4015:         $udom = $env{'user.domain'};
                   4016:     }
                   4017:     if (!defined($uname)) {
                   4018:         $uname = $env{'user.name'};
                   4019:     }
                   4020: 
                   4021:     # If uname and udom are for a course, check for blocks in the course.
                   4022: 
                   4023:     if (&Apache::lonnet::is_course($udom,$uname)) {
                   4024:         my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502     raeburn  4025:         my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490     raeburn  4026:         return ($startblock,$endblock);
                   4027:     }
1.474     raeburn  4028: 
1.502     raeburn  4029:     my $startblock = 0;
                   4030:     my $endblock = 0;
1.482     raeburn  4031:     my %live_courses = &findallcourses(undef,$uname,$udom);
1.474     raeburn  4032: 
1.490     raeburn  4033:     # If uname is for a user, and activity is course-specific, i.e.,
                   4034:     # boards, chat or groups, check for blocking in current course only.
1.474     raeburn  4035: 
1.490     raeburn  4036:     if (($activity eq 'boards' || $activity eq 'chat' ||
                   4037:          $activity eq 'groups') && ($env{'request.course.id'})) {
                   4038:         foreach my $key (keys(%live_courses)) {
                   4039:             if ($key ne $env{'request.course.id'}) {
                   4040:                 delete($live_courses{$key});
                   4041:             }
                   4042:         }
                   4043:     }
                   4044: 
                   4045:     my $otheruser = 0;
                   4046:     my %own_courses;
                   4047:     if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
                   4048:         # Resource belongs to user other than current user.
                   4049:         $otheruser = 1;
                   4050:         # Gather courses for current user
                   4051:         %own_courses = 
                   4052:             &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
                   4053:     }
                   4054: 
                   4055:     # Gather active course roles - course coordinator, instructor, 
                   4056:     # exam proctor, ta, student, or custom role.
1.474     raeburn  4057: 
                   4058:     foreach my $course (keys(%live_courses)) {
1.482     raeburn  4059:         my ($cdom,$cnum);
                   4060:         if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
                   4061:             $cdom = $env{'course.'.$course.'.domain'};
                   4062:             $cnum = $env{'course.'.$course.'.num'};
                   4063:         } else {
1.490     raeburn  4064:             ($cdom,$cnum) = split(/_/,$course); 
1.482     raeburn  4065:         }
                   4066:         my $no_ownblock = 0;
                   4067:         my $no_userblock = 0;
1.533     raeburn  4068:         if ($otheruser && $activity ne 'com') {
1.490     raeburn  4069:             # Check if current user has 'evb' priv for this
                   4070:             if (defined($own_courses{$course})) {
                   4071:                 foreach my $sec (keys(%{$own_courses{$course}})) {
                   4072:                     my $checkrole = 'cm./'.$cdom.'/'.$cnum;
                   4073:                     if ($sec ne 'none') {
                   4074:                         $checkrole .= '/'.$sec;
                   4075:                     }
                   4076:                     if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   4077:                         $no_ownblock = 1;
                   4078:                         last;
                   4079:                     }
                   4080:                 }
                   4081:             }
                   4082:             # if they have 'evb' priv and are currently not playing student
                   4083:             next if (($no_ownblock) &&
                   4084:                  ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
                   4085:         }
1.474     raeburn  4086:         foreach my $sec (keys(%{$live_courses{$course}})) {
1.482     raeburn  4087:             my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474     raeburn  4088:             if ($sec ne 'none') {
1.482     raeburn  4089:                 $checkrole .= '/'.$sec;
1.474     raeburn  4090:             }
1.490     raeburn  4091:             if ($otheruser) {
                   4092:                 # Resource belongs to user other than current user.
                   4093:                 # Assemble privs for that user, and check for 'evb' priv.
1.482     raeburn  4094:                 my ($trole,$tdom,$tnum,$tsec);
                   4095:                 my $entry = $live_courses{$course}{$sec};
                   4096:                 if ($entry =~ /^cr/) {
                   4097:                     ($trole,$tdom,$tnum,$tsec) = 
                   4098:                       ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
                   4099:                 } else {
                   4100:                     ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
                   4101:                 }
                   4102:                 my ($spec,$area,$trest,%allroles,%userroles);
                   4103:                 $area = '/'.$tdom.'/'.$tnum;
                   4104:                 $trest = $tnum;
                   4105:                 if ($tsec ne '') {
                   4106:                     $area .= '/'.$tsec;
                   4107:                     $trest .= '/'.$tsec;
                   4108:                 }
                   4109:                 $spec = $trole.'.'.$area;
                   4110:                 if ($trole =~ /^cr/) {
                   4111:                     &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
                   4112:                                                       $tdom,$spec,$trest,$area);
                   4113:                 } else {
                   4114:                     &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
                   4115:                                                        $tdom,$spec,$trest,$area);
                   4116:                 }
                   4117:                 my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486     raeburn  4118:                 if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
                   4119:                     if ($1) {
                   4120:                         $no_userblock = 1;
                   4121:                         last;
                   4122:                     }
                   4123:                 }
1.490     raeburn  4124:             } else {
                   4125:                 # Resource belongs to current user
                   4126:                 # Check for 'evb' priv via lonnet::allowed().
1.482     raeburn  4127:                 if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   4128:                     $no_ownblock = 1;
                   4129:                     last;
                   4130:                 }
1.474     raeburn  4131:             }
                   4132:         }
                   4133:         # if they have the evb priv and are currently not playing student
1.482     raeburn  4134:         next if (($no_ownblock) &&
1.491     albertel 4135:                  ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482     raeburn  4136:         next if ($no_userblock);
1.474     raeburn  4137: 
1.866     kalberla 4138:         # Retrieve blocking times and identity of locker for course
1.490     raeburn  4139:         # of specified user, unless user has 'evb' privilege.
1.502     raeburn  4140:         
                   4141:         my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
                   4142:         if (($start != 0) && 
                   4143:             (($startblock == 0) || ($startblock > $start))) {
                   4144:             $startblock = $start;
                   4145:         }
                   4146:         if (($end != 0)  &&
                   4147:             (($endblock == 0) || ($endblock < $end))) {
                   4148:             $endblock = $end;
                   4149:         }
1.490     raeburn  4150:     }
                   4151:     return ($startblock,$endblock);
                   4152: }
                   4153: 
                   4154: sub get_blocks {
                   4155:     my ($setters,$activity,$cdom,$cnum) = @_;
                   4156:     my $startblock = 0;
                   4157:     my $endblock = 0;
                   4158:     my $course = $cdom.'_'.$cnum;
                   4159:     $setters->{$course} = {};
                   4160:     $setters->{$course}{'staff'} = [];
                   4161:     $setters->{$course}{'times'} = [];
                   4162:     my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
                   4163:     foreach my $record (keys(%records)) {
                   4164:         my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
                   4165:         if ($start <= time && $end >= time) {
                   4166:             my ($staff_name,$staff_dom,$title,$blocks) =
                   4167:                 &parse_block_record($records{$record});
                   4168:             if ($blocks->{$activity} eq 'on') {
                   4169:                 push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
                   4170:                 push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491     albertel 4171:                 if ( ($startblock == 0) || ($startblock > $start) ) {
                   4172:                     $startblock = $start;
1.490     raeburn  4173:                 }
1.491     albertel 4174:                 if ( ($endblock == 0) || ($endblock < $end) ) {
                   4175:                     $endblock = $end;
1.474     raeburn  4176:                 }
                   4177:             }
                   4178:         }
                   4179:     }
                   4180:     return ($startblock,$endblock);
                   4181: }
                   4182: 
                   4183: sub parse_block_record {
                   4184:     my ($record) = @_;
                   4185:     my ($setuname,$setudom,$title,$blocks);
                   4186:     if (ref($record) eq 'HASH') {
                   4187:         ($setuname,$setudom) = split(/:/,$record->{'setter'});
                   4188:         $title = &unescape($record->{'event'});
                   4189:         $blocks = $record->{'blocks'};
                   4190:     } else {
                   4191:         my @data = split(/:/,$record,3);
                   4192:         if (scalar(@data) eq 2) {
                   4193:             $title = $data[1];
                   4194:             ($setuname,$setudom) = split(/@/,$data[0]);
                   4195:         } else {
                   4196:             ($setuname,$setudom,$title) = @data;
                   4197:         }
                   4198:         $blocks = { 'com' => 'on' };
                   4199:     }
                   4200:     return ($setuname,$setudom,$title,$blocks);
                   4201: }
                   4202: 
1.854     kalberla 4203: sub blocking_status {
                   4204:   my ($activity,$uname,$udom) = @_;
1.867     kalberla 4205:   my %setters;
1.890     droeschl 4206: 
                   4207:   # check for active blocking
1.867     kalberla 4208:   my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
1.854     kalberla 4209: 
1.890     droeschl 4210:   my $blocked = $startblock && $endblock ? 1 : 0;
                   4211: 
                   4212:   # caller just wants to know whether a block is active
                   4213:   if (!wantarray) { return $blocked; }
                   4214: 
                   4215:   # build a link to a popup window containing the details
                   4216:   my $querystring  = "?activity=$activity";
                   4217:   # $uname and $udom decide whose portfolio the user is trying to look at
                   4218:      $querystring .= "&amp;udom=$udom"      if $udom;
                   4219:      $querystring .= "&amp;uname=$uname"    if $uname;
                   4220: 
                   4221:   my $output .= <<'END_MYBLOCK';
1.854     kalberla 4222:     function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
                   4223:         var options = "width=" + w + ",height=" + h + ",";
                   4224:         options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
                   4225:         options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
                   4226:         var newWin = window.open(url, wdwName, options);
                   4227:         newWin.focus();
                   4228:     }
1.890     droeschl 4229: END_MYBLOCK
1.854     kalberla 4230: 
1.890     droeschl 4231:   $output = Apache::lonhtmlcommon::scripttag($output);
                   4232:   
1.854     kalberla 4233:   my $popupUrl = "/adm/blockingstatus/$querystring";
1.890     droeschl 4234:   my $text = mt('Communication Blocked');
                   4235: 
1.867     kalberla 4236:   $output .= <<"END_BLOCK";
                   4237: <div class='LC_comblock'>
1.869     kalberla 4238:   <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890     droeschl 4239:   title='$text'>
                   4240:   <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869     kalberla 4241:   <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring' 
1.890     droeschl 4242:   title='$text'>$text</a>
1.867     kalberla 4243: </div>
                   4244: 
                   4245: END_BLOCK
1.474     raeburn  4246: 
1.854     kalberla 4247:   return ($blocked, $output);
                   4248: }
1.490     raeburn  4249: 
1.60      matthew  4250: ###############################################
                   4251: 
1.682     raeburn  4252: sub check_ip_acc {
                   4253:     my ($acc)=@_;
                   4254:     &Apache::lonxml::debug("acc is $acc");
                   4255:     if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
                   4256:         return 1;
                   4257:     }
                   4258:     my $allowed=0;
                   4259:     my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
                   4260: 
                   4261:     my $name;
                   4262:     foreach my $pattern (split(',',$acc)) {
                   4263:         $pattern =~ s/^\s*//;
                   4264:         $pattern =~ s/\s*$//;
                   4265:         if ($pattern =~ /\*$/) {
                   4266:             #35.8.*
                   4267:             $pattern=~s/\*//;
                   4268:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   4269:         } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
                   4270:             #35.8.3.[34-56]
                   4271:             my $low=$2;
                   4272:             my $high=$3;
                   4273:             $pattern=$1;
                   4274:             if ($ip =~ /^\Q$pattern\E/) {
                   4275:                 my $last=(split(/\./,$ip))[3];
                   4276:                 if ($last <=$high && $last >=$low) { $allowed=1; }
                   4277:             }
                   4278:         } elsif ($pattern =~ /^\*/) {
                   4279:             #*.msu.edu
                   4280:             $pattern=~s/\*//;
                   4281:             if (!defined($name)) {
                   4282:                 use Socket;
                   4283:                 my $netaddr=inet_aton($ip);
                   4284:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   4285:             }
                   4286:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   4287:         } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
                   4288:             #127.0.0.1
                   4289:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   4290:         } else {
                   4291:             #some.name.com
                   4292:             if (!defined($name)) {
                   4293:                 use Socket;
                   4294:                 my $netaddr=inet_aton($ip);
                   4295:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   4296:             }
                   4297:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   4298:         }
                   4299:         if ($allowed) { last; }
                   4300:     }
                   4301:     return $allowed;
                   4302: }
                   4303: 
                   4304: ###############################################
                   4305: 
1.60      matthew  4306: =pod
                   4307: 
1.112     bowersj2 4308: =head1 Domain Template Functions
                   4309: 
                   4310: =over 4
                   4311: 
                   4312: =item * &determinedomain()
1.60      matthew  4313: 
                   4314: Inputs: $domain (usually will be undef)
                   4315: 
1.63      www      4316: Returns: Determines which domain should be used for designs
1.60      matthew  4317: 
                   4318: =cut
1.54      www      4319: 
1.60      matthew  4320: ###############################################
1.63      www      4321: sub determinedomain {
                   4322:     my $domain=shift;
1.531     albertel 4323:     if (! $domain) {
1.60      matthew  4324:         # Determine domain if we have not been given one
1.893     raeburn  4325:         $domain = &Apache::lonnet::default_login_domain();
1.258     albertel 4326:         if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
                   4327:         if ($env{'request.role.domain'}) { 
                   4328:             $domain=$env{'request.role.domain'}; 
1.60      matthew  4329:         }
                   4330:     }
1.63      www      4331:     return $domain;
                   4332: }
                   4333: ###############################################
1.517     raeburn  4334: 
1.518     albertel 4335: sub devalidate_domconfig_cache {
                   4336:     my ($udom)=@_;
                   4337:     &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
                   4338: }
                   4339: 
                   4340: # ---------------------- Get domain configuration for a domain
                   4341: sub get_domainconf {
                   4342:     my ($udom) = @_;
                   4343:     my $cachetime=1800;
                   4344:     my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
                   4345:     if (defined($cached)) { return %{$result}; }
                   4346: 
                   4347:     my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948     raeburn  4348: 					     ['login','rolecolors','autoenroll'],$udom);
1.632     raeburn  4349:     my (%designhash,%legacy);
1.518     albertel 4350:     if (keys(%domconfig) > 0) {
                   4351:         if (ref($domconfig{'login'}) eq 'HASH') {
1.632     raeburn  4352:             if (keys(%{$domconfig{'login'}})) {
                   4353:                 foreach my $key (keys(%{$domconfig{'login'}})) {
1.699     raeburn  4354:                     if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946     raeburn  4355:                         if ($key eq 'loginvia') {
                   4356:                             if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
1.1013    raeburn  4357:                                 foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
1.948     raeburn  4358:                                     if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
                   4359:                                         if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
                   4360:                                             my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
                   4361:                                             $designhash{$udom.'.login.loginvia'} = $server;
                   4362:                                             if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
                   4363: 
                   4364:                                                 $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
                   4365:                                             } else {
1.1013    raeburn  4366:                                                 $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
1.948     raeburn  4367:                                             }
                   4368:                                             if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
                   4369:                                                 $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
                   4370:                                             }
1.946     raeburn  4371:                                         }
                   4372:                                     }
                   4373:                                 }
                   4374:                             }
                   4375:                         } else {
                   4376:                             foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
                   4377:                                 $designhash{$udom.'.login.'.$key.'_'.$img} = 
                   4378:                                     $domconfig{'login'}{$key}{$img};
                   4379:                             }
1.699     raeburn  4380:                         }
                   4381:                     } else {
                   4382:                         $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
                   4383:                     }
1.632     raeburn  4384:                 }
                   4385:             } else {
                   4386:                 $legacy{'login'} = 1;
1.518     albertel 4387:             }
1.632     raeburn  4388:         } else {
                   4389:             $legacy{'login'} = 1;
1.518     albertel 4390:         }
                   4391:         if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632     raeburn  4392:             if (keys(%{$domconfig{'rolecolors'}})) {
                   4393:                 foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
                   4394:                     if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
                   4395:                         foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
                   4396:                             $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
                   4397:                         }
1.518     albertel 4398:                     }
                   4399:                 }
1.632     raeburn  4400:             } else {
                   4401:                 $legacy{'rolecolors'} = 1;
1.518     albertel 4402:             }
1.632     raeburn  4403:         } else {
                   4404:             $legacy{'rolecolors'} = 1;
1.518     albertel 4405:         }
1.948     raeburn  4406:         if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   4407:             if ($domconfig{'autoenroll'}{'co-owners'}) {
                   4408:                 $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
                   4409:             }
                   4410:         }
1.632     raeburn  4411:         if (keys(%legacy) > 0) {
                   4412:             my %legacyhash = &get_legacy_domconf($udom);
                   4413:             foreach my $item (keys(%legacyhash)) {
                   4414:                 if ($item =~ /^\Q$udom\E\.login/) {
                   4415:                     if ($legacy{'login'}) { 
                   4416:                         $designhash{$item} = $legacyhash{$item};
                   4417:                     }
                   4418:                 } else {
                   4419:                     if ($legacy{'rolecolors'}) {
                   4420:                         $designhash{$item} = $legacyhash{$item};
                   4421:                     }
1.518     albertel 4422:                 }
                   4423:             }
                   4424:         }
1.632     raeburn  4425:     } else {
                   4426:         %designhash = &get_legacy_domconf($udom); 
1.518     albertel 4427:     }
                   4428:     &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
                   4429: 				  $cachetime);
                   4430:     return %designhash;
                   4431: }
                   4432: 
1.632     raeburn  4433: sub get_legacy_domconf {
                   4434:     my ($udom) = @_;
                   4435:     my %legacyhash;
                   4436:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
                   4437:     my $designfile =  $designdir.'/'.$udom.'.tab';
                   4438:     if (-e $designfile) {
                   4439:         if ( open (my $fh,"<$designfile") ) {
                   4440:             while (my $line = <$fh>) {
                   4441:                 next if ($line =~ /^\#/);
                   4442:                 chomp($line);
                   4443:                 my ($key,$val)=(split(/\=/,$line));
                   4444:                 if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
                   4445:             }
                   4446:             close($fh);
                   4447:         }
                   4448:     }
1.1026    raeburn  4449:     if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632     raeburn  4450:         $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
                   4451:     }
                   4452:     return %legacyhash;
                   4453: }
                   4454: 
1.63      www      4455: =pod
                   4456: 
1.112     bowersj2 4457: =item * &domainlogo()
1.63      www      4458: 
                   4459: Inputs: $domain (usually will be undef)
                   4460: 
                   4461: Returns: A link to a domain logo, if the domain logo exists.
                   4462: If the domain logo does not exist, a description of the domain.
                   4463: 
                   4464: =cut
1.112     bowersj2 4465: 
1.63      www      4466: ###############################################
                   4467: sub domainlogo {
1.517     raeburn  4468:     my $domain = &determinedomain(shift);
1.518     albertel 4469:     my %designhash = &get_domainconf($domain);    
1.517     raeburn  4470:     # See if there is a logo
                   4471:     if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519     raeburn  4472:         my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538     albertel 4473:         if ($imgsrc =~ m{^/(adm|res)/}) {
                   4474: 	    if ($imgsrc =~ m{^/res/}) {
                   4475: 		my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
                   4476: 		&Apache::lonnet::repcopy($local_name);
                   4477: 	    }
                   4478: 	   $imgsrc = &lonhttpdurl($imgsrc);
1.519     raeburn  4479:         } 
                   4480:         return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514     albertel 4481:     } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
                   4482:         return &Apache::lonnet::domain($domain,'description');
1.59      www      4483:     } else {
1.60      matthew  4484:         return '';
1.59      www      4485:     }
                   4486: }
1.63      www      4487: ##############################################
                   4488: 
                   4489: =pod
                   4490: 
1.112     bowersj2 4491: =item * &designparm()
1.63      www      4492: 
                   4493: Inputs: $which parameter; $domain (usually will be undef)
                   4494: 
                   4495: Returns: value of designparamter $which
                   4496: 
                   4497: =cut
1.112     bowersj2 4498: 
1.397     albertel 4499: 
1.400     albertel 4500: ##############################################
1.397     albertel 4501: sub designparm {
                   4502:     my ($which,$domain)=@_;
                   4503:     if (exists($env{'environment.color.'.$which})) {
1.817     bisitz   4504:         return $env{'environment.color.'.$which};
1.96      www      4505:     }
1.63      www      4506:     $domain=&determinedomain($domain);
1.1016    raeburn  4507:     my %domdesign;
                   4508:     unless ($domain eq 'public') {
                   4509:         %domdesign = &get_domainconf($domain);
                   4510:     }
1.520     raeburn  4511:     my $output;
1.517     raeburn  4512:     if ($domdesign{$domain.'.'.$which} ne '') {
1.817     bisitz   4513:         $output = $domdesign{$domain.'.'.$which};
1.63      www      4514:     } else {
1.520     raeburn  4515:         $output = $defaultdesign{$which};
                   4516:     }
                   4517:     if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635     raeburn  4518:         ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538     albertel 4519:         if ($output =~ m{^/(adm|res)/}) {
1.817     bisitz   4520:             if ($output =~ m{^/res/}) {
                   4521:                 my $local_name = &Apache::lonnet::filelocation('',$output);
                   4522:                 &Apache::lonnet::repcopy($local_name);
                   4523:             }
1.520     raeburn  4524:             $output = &lonhttpdurl($output);
                   4525:         }
1.63      www      4526:     }
1.520     raeburn  4527:     return $output;
1.63      www      4528: }
1.59      www      4529: 
1.822     bisitz   4530: ##############################################
                   4531: =pod
                   4532: 
1.832     bisitz   4533: =item * &authorspace()
                   4534: 
                   4535: Inputs: ./.
                   4536: 
                   4537: Returns: Path to the Construction Space of the current user's
                   4538:          accessed author space
                   4539:          The author space will be that of the current user
                   4540:          when accessing the own author space
                   4541:          and that of the co-author/assistent co-author
                   4542:          when accessing the co-author's/assistent co-author's
                   4543:          space
                   4544: 
                   4545: =cut
                   4546: 
                   4547: sub authorspace {
                   4548:     my $caname = '';
1.1024    www      4549:     my $cadom = '';
1.832     bisitz   4550:     if ($env{'request.role'} =~ /^ca|^aa/) {
1.1024    www      4551:         ($cadom,$caname) =
1.832     bisitz   4552:             ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
                   4553:     } else {
                   4554:         $caname = $env{'user.name'};
1.1024    www      4555:         $cadom = $env{'user.domain'};
1.832     bisitz   4556:     }
1.1024    www      4557:     return '/priv/'.$cadom.'/'.$caname.'/';
1.832     bisitz   4558: }
                   4559: 
                   4560: ##############################################
                   4561: =pod
                   4562: 
1.822     bisitz   4563: =item * &head_subbox()
                   4564: 
                   4565: Inputs: $content (contains HTML code with page functions, etc.)
                   4566: 
                   4567: Returns: HTML div with $content
                   4568:          To be included in page header
                   4569: 
                   4570: =cut
                   4571: 
                   4572: sub head_subbox {
                   4573:     my ($content)=@_;
                   4574:     my $output =
1.993     raeburn  4575:         '<div class="LC_head_subbox">'
1.822     bisitz   4576:        .$content
                   4577:        .'</div>'
                   4578: }
                   4579: 
                   4580: ##############################################
                   4581: =pod
                   4582: 
                   4583: =item * &CSTR_pageheader()
                   4584: 
1.1026    raeburn  4585: Input: (optional) filename from which breadcrumb trail is built.
                   4586:        In most cases no input as needed, as $env{'request.filename'}
                   4587:        is appropriate for use in building the breadcrumb trail.
1.822     bisitz   4588: 
                   4589: Returns: HTML div with CSTR path and recent box
                   4590:          To be included on Construction Space pages
                   4591: 
                   4592: =cut
                   4593: 
                   4594: sub CSTR_pageheader {
1.1026    raeburn  4595:     my ($trailfile) = @_;
                   4596:     if ($trailfile eq '') {
                   4597:         $trailfile = $env{'request.filename'};
                   4598:     }
                   4599: 
                   4600: # this is for resources; directories have customtitle, and crumbs
                   4601: # and select recent are created in lonpubdir.pm
                   4602: 
                   4603:     my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022    www      4604:     my ($udom,$uname,$thisdisfn)=
1.1026    raeburn  4605:         ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)/(.*)$});
                   4606:     my $formaction = "/priv/$udom/$uname/$thisdisfn";
                   4607:     $formaction =~ s{/+}{/}g;
1.822     bisitz   4608: 
                   4609:     my $parentpath = '';
                   4610:     my $lastitem = '';
                   4611:     if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
                   4612:         $parentpath = $1;
                   4613:         $lastitem = $2;
                   4614:     } else {
                   4615:         $lastitem = $thisdisfn;
                   4616:     }
1.921     bisitz   4617: 
                   4618:     my $output =
1.822     bisitz   4619:          '<div>'
                   4620:         .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
                   4621:         .'<b>'.&mt('Construction Space:').'</b> '
                   4622:         .'<form name="dirs" method="post" action="'.$formaction
1.921     bisitz   4623:         .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024    www      4624:         .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921     bisitz   4625: 
                   4626:     if ($lastitem) {
                   4627:         $output .=
                   4628:              '<span class="LC_filename">'
                   4629:             .$lastitem
                   4630:             .'</span>';
                   4631:     }
                   4632:     $output .=
                   4633:          '<br />'
1.822     bisitz   4634:         #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
                   4635:         .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
                   4636:         .'</form>'
                   4637:         .&Apache::lonmenu::constspaceform()
                   4638:         .'</div>';
1.921     bisitz   4639: 
                   4640:     return $output;
1.822     bisitz   4641: }
                   4642: 
1.60      matthew  4643: ###############################################
                   4644: ###############################################
                   4645: 
                   4646: =pod
                   4647: 
1.112     bowersj2 4648: =back
                   4649: 
1.549     albertel 4650: =head1 HTML Helpers
1.112     bowersj2 4651: 
                   4652: =over 4
                   4653: 
                   4654: =item * &bodytag()
1.60      matthew  4655: 
                   4656: Returns a uniform header for LON-CAPA web pages.
                   4657: 
                   4658: Inputs: 
                   4659: 
1.112     bowersj2 4660: =over 4
                   4661: 
                   4662: =item * $title, A title to be displayed on the page.
                   4663: 
                   4664: =item * $function, the current role (can be undef).
                   4665: 
                   4666: =item * $addentries, extra parameters for the <body> tag.
                   4667: 
                   4668: =item * $bodyonly, if defined, only return the <body> tag.
                   4669: 
                   4670: =item * $domain, if defined, force a given domain.
                   4671: 
                   4672: =item * $forcereg, if page should register as content page (relevant for 
1.86      www      4673:             text interface only)
1.60      matthew  4674: 
1.814     bisitz   4675: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
                   4676:                      navigational links
1.317     albertel 4677: 
1.338     albertel 4678: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
                   4679: 
1.460     albertel 4680: =item * $args, optional argument valid values are
                   4681:             no_auto_mt_title -> prevents &mt()ing the title arg
1.562     albertel 4682:             inherit_jsmath -> when creating popup window in a page,
                   4683:                               should it have jsmath forced on by the
                   4684:                               current page
1.460     albertel 4685: 
1.112     bowersj2 4686: =back
                   4687: 
1.60      matthew  4688: Returns: A uniform header for LON-CAPA web pages.  
                   4689: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
                   4690: If $bodyonly is undef or zero, an html string containing a <body> tag and 
                   4691: other decorations will be returned.
                   4692: 
                   4693: =cut
                   4694: 
1.54      www      4695: sub bodytag {
1.831     bisitz   4696:     my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.962     droeschl 4697:         $no_nav_bar,$bgcolor,$args)=@_;
1.339     albertel 4698: 
1.954     raeburn  4699:     my $public;
                   4700:     if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
                   4701:         || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
                   4702:         $public = 1;
                   4703:     }
1.460     albertel 4704:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339     albertel 4705: 
1.183     matthew  4706:     $function = &get_users_function() if (!$function);
1.339     albertel 4707:     my $img =    &designparm($function.'.img',$domain);
                   4708:     my $font =   &designparm($function.'.font',$domain);
                   4709:     my $pgbg   = $bgcolor || &designparm($function.'.pgbg',$domain);
                   4710: 
1.803     bisitz   4711:     my %design = ( 'style'   => 'margin-top: 0',
1.535     albertel 4712: 		   'bgcolor' => $pgbg,
1.339     albertel 4713: 		   'text'    => $font,
                   4714:                    'alink'   => &designparm($function.'.alink',$domain),
                   4715: 		   'vlink'   => &designparm($function.'.vlink',$domain),
                   4716: 		   'link'    => &designparm($function.'.link',$domain),);
1.438     albertel 4717:     @design{keys(%$addentries)} = @$addentries{keys(%$addentries)}; 
1.339     albertel 4718: 
1.63      www      4719:  # role and realm
1.378     raeburn  4720:     my ($role,$realm) = split(/\./,$env{'request.role'},2);
                   4721:     if ($role  eq 'ca') {
1.479     albertel 4722:         my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500     albertel 4723:         $realm = &plainname($rname,$rdom);
1.378     raeburn  4724:     } 
1.55      www      4725: # realm
1.258     albertel 4726:     if ($env{'request.course.id'}) {
1.378     raeburn  4727:         if ($env{'request.role'} !~ /^cr/) {
                   4728:             $role = &Apache::lonnet::plaintext($role,&course_type());
                   4729:         }
1.898     raeburn  4730:         if ($env{'request.course.sec'}) {
                   4731:             $role .= ('&nbsp;'x2).'-&nbsp;'.&mt('section:').'&nbsp;'.$env{'request.course.sec'};
                   4732:         }   
1.359     albertel 4733: 	$realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378     raeburn  4734:     } else {
                   4735:         $role = &Apache::lonnet::plaintext($role);
1.54      www      4736:     }
1.433     albertel 4737: 
1.359     albertel 4738:     if (!$realm) { $realm='&nbsp;'; }
1.330     albertel 4739: 
1.438     albertel 4740:     my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329     albertel 4741: 
1.101     www      4742: # construct main body tag
1.359     albertel 4743:     my $bodytag = "<body $extra_body_attr>".
1.562     albertel 4744: 	&Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252     albertel 4745: 
1.530     albertel 4746:     if ($bodyonly) {
1.60      matthew  4747:         return $bodytag;
1.798     tempelho 4748:     } 
1.359     albertel 4749: 
1.410     albertel 4750:     my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.954     raeburn  4751:     if ($public) {
1.433     albertel 4752: 	undef($role);
1.434     albertel 4753:     } else {
                   4754: 	$name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433     albertel 4755:     }
1.359     albertel 4756:     
1.762     bisitz   4757:     my $titleinfo = '<h1>'.$title.'</h1>';
1.359     albertel 4758:     #
                   4759:     # Extra info if you are the DC
                   4760:     my $dc_info = '';
                   4761:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   4762:                         $env{'course.'.$env{'request.course.id'}.
                   4763:                                  '.domain'}.'/'})) {
                   4764:         my $cid = $env{'request.course.id'};
1.917     raeburn  4765:         $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380     www      4766:         $dc_info =~ s/\s+$//;
1.359     albertel 4767:     }
                   4768: 
1.898     raeburn  4769:     $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853     droeschl 4770:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   4771: 
1.916     droeschl 4772:         if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') { 
                   4773:             return $bodytag; 
                   4774:         } 
1.903     droeschl 4775: 
                   4776:         if ($env{'request.state'} eq 'construct') { $forcereg=1; }
                   4777: 
                   4778:         #    if ($env{'request.state'} eq 'construct') {
                   4779:         #        $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
                   4780:         #    }
                   4781: 
1.359     albertel 4782: 
                   4783: 
1.916     droeschl 4784:         if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917     raeburn  4785:              if ($dc_info) {
                   4786:                  $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
                   4787:              }
1.916     droeschl 4788:              $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
                   4789:                 <em>$realm</em> $dc_info</div>|;
1.903     droeschl 4790:             return $bodytag;
                   4791:         }
1.894     droeschl 4792: 
1.927     raeburn  4793:         unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
                   4794:             $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>|;
                   4795:         }
1.916     droeschl 4796: 
1.903     droeschl 4797:         $bodytag .= Apache::lonhtmlcommon::scripttag(
                   4798:             Apache::lonmenu::utilityfunctions(), 'start');
1.816     bisitz   4799: 
1.903     droeschl 4800:         $bodytag .= Apache::lonmenu::primary_menu();
1.852     droeschl 4801: 
1.917     raeburn  4802:         if ($dc_info) {
                   4803:             $dc_info = &dc_courseid_toggle($dc_info);
                   4804:         }
                   4805:         $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916     droeschl 4806: 
1.903     droeschl 4807:         #don't show menus for public users
1.954     raeburn  4808:         if (!$public){
1.903     droeschl 4809:             $bodytag .= Apache::lonmenu::secondary_menu();
                   4810:             $bodytag .= Apache::lonmenu::serverform();
1.920     raeburn  4811:             $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
                   4812:             if ($env{'request.state'} eq 'construct') {
1.962     droeschl 4813:                 $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920     raeburn  4814:                                 $args->{'bread_crumbs'});
                   4815:             } elsif ($forcereg) { 
                   4816:                 $bodytag .= &Apache::lonmenu::innerregister($forcereg);
                   4817:             }
1.903     droeschl 4818:         }else{
                   4819:             # this is to seperate menu from content when there's no secondary
                   4820:             # menu. Especially needed for public accessible ressources.
                   4821:             $bodytag .= '<hr style="clear:both" />';
                   4822:             $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end'); 
1.235     raeburn  4823:         }
1.903     droeschl 4824: 
1.235     raeburn  4825:         return $bodytag;
1.182     matthew  4826: }
                   4827: 
1.917     raeburn  4828: sub dc_courseid_toggle {
                   4829:     my ($dc_info) = @_;
1.980     raeburn  4830:     return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.917     raeburn  4831:            '<a href="javascript:showCourseID();">'.
                   4832:            &mt('(More ...)').'</a></span>'.
                   4833:            '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
                   4834: }
                   4835: 
1.330     albertel 4836: sub make_attr_string {
                   4837:     my ($register,$attr_ref) = @_;
                   4838: 
                   4839:     if ($attr_ref && !ref($attr_ref)) {
                   4840: 	die("addentries Must be a hash ref ".
                   4841: 	    join(':',caller(1))." ".
                   4842: 	    join(':',caller(0))." ");
                   4843:     }
                   4844: 
                   4845:     if ($register) {
1.339     albertel 4846: 	my ($on_load,$on_unload);
                   4847: 	foreach my $key (keys(%{$attr_ref})) {
                   4848: 	    if      (lc($key) eq 'onload') {
                   4849: 		$on_load.=$attr_ref->{$key}.';';
                   4850: 		delete($attr_ref->{$key});
                   4851: 
                   4852: 	    } elsif (lc($key) eq 'onunload') {
                   4853: 		$on_unload.=$attr_ref->{$key}.';';
                   4854: 		delete($attr_ref->{$key});
                   4855: 	    }
                   4856: 	}
1.953     droeschl 4857: 	$attr_ref->{'onload'}  = $on_load;
                   4858: 	$attr_ref->{'onunload'}= $on_unload;
1.330     albertel 4859:     }
1.339     albertel 4860: 
1.330     albertel 4861:     my $attr_string;
                   4862:     foreach my $attr (keys(%$attr_ref)) {
                   4863: 	$attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
                   4864:     }
                   4865:     return $attr_string;
                   4866: }
                   4867: 
                   4868: 
1.182     matthew  4869: ###############################################
1.251     albertel 4870: ###############################################
                   4871: 
                   4872: =pod
                   4873: 
                   4874: =item * &endbodytag()
                   4875: 
                   4876: Returns a uniform footer for LON-CAPA web pages.
                   4877: 
1.635     raeburn  4878: Inputs: 1 - optional reference to an args hash
                   4879: If in the hash, key for noredirectlink has a value which evaluates to true,
                   4880: a 'Continue' link is not displayed if the page contains an
                   4881: internal redirect in the <head></head> section,
                   4882: i.e., $env{'internal.head.redirect'} exists   
1.251     albertel 4883: 
                   4884: =cut
                   4885: 
                   4886: sub endbodytag {
1.635     raeburn  4887:     my ($args) = @_;
1.251     albertel 4888:     my $endbodytag='</body>';
1.269     albertel 4889:     $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315     albertel 4890:     if ( exists( $env{'internal.head.redirect'} ) ) {
1.635     raeburn  4891:         if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
                   4892: 	    $endbodytag=
                   4893: 	        "<br /><a href=\"$env{'internal.head.redirect'}\">".
                   4894: 	        &mt('Continue').'</a>'.
                   4895: 	        $endbodytag;
                   4896:         }
1.315     albertel 4897:     }
1.251     albertel 4898:     return $endbodytag;
                   4899: }
                   4900: 
1.352     albertel 4901: =pod
                   4902: 
                   4903: =item * &standard_css()
                   4904: 
                   4905: Returns a style sheet
                   4906: 
                   4907: Inputs: (all optional)
                   4908:             domain         -> force to color decorate a page for a specific
                   4909:                                domain
                   4910:             function       -> force usage of a specific rolish color scheme
                   4911:             bgcolor        -> override the default page bgcolor
                   4912: 
                   4913: =cut
                   4914: 
1.343     albertel 4915: sub standard_css {
1.345     albertel 4916:     my ($function,$domain,$bgcolor) = @_;
1.352     albertel 4917:     $function  = &get_users_function() if (!$function);
                   4918:     my $img    = &designparm($function.'.img',   $domain);
                   4919:     my $tabbg  = &designparm($function.'.tabbg', $domain);
                   4920:     my $font   = &designparm($function.'.font',  $domain);
1.801     tempelho 4921:     my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791     tempelho 4922: #second colour for later usage
1.345     albertel 4923:     my $sidebg = &designparm($function.'.sidebg',$domain);
1.382     albertel 4924:     my $pgbg_or_bgcolor =
                   4925: 	         $bgcolor ||
1.352     albertel 4926: 	         &designparm($function.'.pgbg',  $domain);
1.382     albertel 4927:     my $pgbg   = &designparm($function.'.pgbg',  $domain);
1.352     albertel 4928:     my $alink  = &designparm($function.'.alink', $domain);
                   4929:     my $vlink  = &designparm($function.'.vlink', $domain);
                   4930:     my $link   = &designparm($function.'.link',  $domain);
                   4931: 
1.602     albertel 4932:     my $sans                 = 'Verdana,Arial,Helvetica,sans-serif';
1.395     albertel 4933:     my $mono                 = 'monospace';
1.850     bisitz   4934:     my $data_table_head      = $sidebg;
                   4935:     my $data_table_light     = '#FAFAFA';
                   4936:     my $data_table_dark      = '#F0F0F0';
1.470     banghart 4937:     my $data_table_darker    = '#CCCCCC';
1.349     albertel 4938:     my $data_table_highlight = '#FFFF00';
1.352     albertel 4939:     my $mail_new             = '#FFBB77';
                   4940:     my $mail_new_hover       = '#DD9955';
                   4941:     my $mail_read            = '#BBBB77';
                   4942:     my $mail_read_hover      = '#999944';
                   4943:     my $mail_replied         = '#AAAA88';
                   4944:     my $mail_replied_hover   = '#888855';
                   4945:     my $mail_other           = '#99BBBB';
                   4946:     my $mail_other_hover     = '#669999';
1.391     albertel 4947:     my $table_header         = '#DDDDDD';
1.489     raeburn  4948:     my $feedback_link_bg     = '#BBBBBB';
1.911     bisitz   4949:     my $lg_border_color      = '#C8C8C8';
1.952     onken    4950:     my $button_hover         = '#BF2317';
1.392     albertel 4951: 
1.608     albertel 4952:     my $border = ($env{'browser.type'} eq 'explorer' ||
1.911     bisitz   4953:       $env{'browser.type'} eq 'safari'     ) ? '0 2px 0 2px'
                   4954:                                              : '0 3px 0 4px';
1.448     albertel 4955: 
1.523     albertel 4956: 
1.343     albertel 4957:     return <<END;
1.947     droeschl 4958: 
                   4959: /* needed for iframe to allow 100% height in FF */
                   4960: body, html { 
                   4961:     margin: 0;
                   4962:     padding: 0 0.5%;
                   4963:     height: 99%; /* to avoid scrollbars */
                   4964: }
                   4965: 
1.795     www      4966: body {
1.911     bisitz   4967:   font-family: $sans;
                   4968:   line-height:130%;
                   4969:   font-size:0.83em;
                   4970:   color:$font;
1.795     www      4971: }
                   4972: 
1.959     onken    4973: a:focus,
                   4974: a:focus img {
1.795     www      4975:   color: red;
1.911     bisitz   4976:   background: yellow;
1.795     www      4977: }
1.698     harmsja  4978: 
1.911     bisitz   4979: form, .inline {
                   4980:   display: inline;
1.795     www      4981: }
1.721     harmsja  4982: 
1.795     www      4983: .LC_right {
1.911     bisitz   4984:   text-align:right;
1.795     www      4985: }
                   4986: 
                   4987: .LC_middle {
1.911     bisitz   4988:   vertical-align:middle;
1.795     www      4989: }
1.721     harmsja  4990: 
1.911     bisitz   4991: .LC_400Box {
                   4992:   width:400px;
                   4993: }
1.721     harmsja  4994: 
1.947     droeschl 4995: .LC_iframecontainer {
                   4996:     width: 98%;
                   4997:     margin: 0;
                   4998:     position: fixed;
                   4999:     top: 8.5em;
                   5000:     bottom: 0;
                   5001: }
                   5002: 
                   5003: .LC_iframecontainer iframe{
                   5004:     border: none;
                   5005:     width: 100%;
                   5006:     height: 100%;
                   5007: }
                   5008: 
1.778     bisitz   5009: .LC_filename {
                   5010:   font-family: $mono;
                   5011:   white-space:pre;
1.921     bisitz   5012:   font-size: 120%;
1.778     bisitz   5013: }
                   5014: 
                   5015: .LC_fileicon {
                   5016:   border: none;
                   5017:   height: 1.3em;
                   5018:   vertical-align: text-bottom;
                   5019:   margin-right: 0.3em;
                   5020:   text-decoration:none;
                   5021: }
                   5022: 
1.1008    www      5023: .LC_setting {
                   5024:   text-decoration:underline;
                   5025: }
                   5026: 
1.350     albertel 5027: .LC_error {
                   5028:   color: red;
                   5029:   font-size: larger;
                   5030: }
1.795     www      5031: 
1.457     albertel 5032: .LC_warning,
                   5033: .LC_diff_removed {
1.733     bisitz   5034:   color: red;
1.394     albertel 5035: }
1.532     albertel 5036: 
                   5037: .LC_info,
1.457     albertel 5038: .LC_success,
                   5039: .LC_diff_added {
1.350     albertel 5040:   color: green;
                   5041: }
1.795     www      5042: 
1.802     bisitz   5043: div.LC_confirm_box {
                   5044:   background-color: #FAFAFA;
                   5045:   border: 1px solid $lg_border_color;
                   5046:   margin-right: 0;
                   5047:   padding: 5px;
                   5048: }
                   5049: 
                   5050: div.LC_confirm_box .LC_error img,
                   5051: div.LC_confirm_box .LC_success img {
                   5052:   vertical-align: middle;
                   5053: }
                   5054: 
1.440     albertel 5055: .LC_icon {
1.771     droeschl 5056:   border: none;
1.790     droeschl 5057:   vertical-align: middle;
1.771     droeschl 5058: }
                   5059: 
1.543     albertel 5060: .LC_docs_spacer {
                   5061:   width: 25px;
                   5062:   height: 1px;
1.771     droeschl 5063:   border: none;
1.543     albertel 5064: }
1.346     albertel 5065: 
1.532     albertel 5066: .LC_internal_info {
1.735     bisitz   5067:   color: #999999;
1.532     albertel 5068: }
                   5069: 
1.794     www      5070: .LC_discussion {
1.911     bisitz   5071:   background: $tabbg;
                   5072:   border: 1px solid black;
                   5073:   margin: 2px;
1.794     www      5074: }
                   5075: 
                   5076: .LC_disc_action_links_bar {
1.911     bisitz   5077:   background: $tabbg;
                   5078:   border: none;
                   5079:   margin: 4px;
1.794     www      5080: }
                   5081: 
                   5082: .LC_disc_action_left {
1.911     bisitz   5083:   text-align: left;
1.794     www      5084: }
                   5085: 
                   5086: .LC_disc_action_right {
1.911     bisitz   5087:   text-align: right;
1.794     www      5088: }
                   5089: 
                   5090: .LC_disc_new_item {
1.911     bisitz   5091:   background: white;
                   5092:   border: 2px solid red;
                   5093:   margin: 2px;
1.794     www      5094: }
                   5095: 
                   5096: .LC_disc_old_item {
1.911     bisitz   5097:   background: white;
                   5098:   border: 1px solid black;
                   5099:   margin: 2px;
1.794     www      5100: }
                   5101: 
1.458     albertel 5102: table.LC_pastsubmission {
                   5103:   border: 1px solid black;
                   5104:   margin: 2px;
                   5105: }
                   5106: 
1.924     bisitz   5107: table#LC_menubuttons {
1.345     albertel 5108:   width: 100%;
                   5109:   background: $pgbg;
1.392     albertel 5110:   border: 2px;
1.402     albertel 5111:   border-collapse: separate;
1.803     bisitz   5112:   padding: 0;
1.345     albertel 5113: }
1.392     albertel 5114: 
1.801     tempelho 5115: table#LC_title_bar a {
                   5116:   color: $fontmenu;
                   5117: }
1.836     bisitz   5118: 
1.807     droeschl 5119: table#LC_title_bar {
1.819     tempelho 5120:   clear: both;
1.836     bisitz   5121:   display: none;
1.807     droeschl 5122: }
                   5123: 
1.795     www      5124: table#LC_title_bar,
1.933     droeschl 5125: table.LC_breadcrumbs, /* obsolete? */
1.393     albertel 5126: table#LC_title_bar.LC_with_remote {
1.359     albertel 5127:   width: 100%;
1.392     albertel 5128:   border-color: $pgbg;
                   5129:   border-style: solid;
                   5130:   border-width: $border;
1.379     albertel 5131:   background: $pgbg;
1.801     tempelho 5132:   color: $fontmenu;
1.392     albertel 5133:   border-collapse: collapse;
1.803     bisitz   5134:   padding: 0;
1.819     tempelho 5135:   margin: 0;
1.359     albertel 5136: }
1.795     www      5137: 
1.933     droeschl 5138: ul.LC_breadcrumb_tools_outerlist {
1.913     droeschl 5139:     margin: 0;
                   5140:     padding: 0;
1.933     droeschl 5141:     position: relative;
                   5142:     list-style: none;
1.913     droeschl 5143: }
1.933     droeschl 5144: ul.LC_breadcrumb_tools_outerlist li {
1.913     droeschl 5145:     display: inline;
                   5146: }
1.933     droeschl 5147: 
                   5148: .LC_breadcrumb_tools_navigation {
1.913     droeschl 5149:     padding: 0;
1.933     droeschl 5150:     margin: 0;
                   5151:     float: left;
1.913     droeschl 5152: }
1.933     droeschl 5153: .LC_breadcrumb_tools_tools {
                   5154:     padding: 0;
                   5155:     margin: 0;
1.913     droeschl 5156:     float: right;
                   5157: }
                   5158: 
1.359     albertel 5159: table#LC_title_bar td {
                   5160:   background: $tabbg;
                   5161: }
1.795     www      5162: 
1.911     bisitz   5163: table#LC_menubuttons img {
1.803     bisitz   5164:   border: none;
1.346     albertel 5165: }
1.795     www      5166: 
1.842     droeschl 5167: .LC_breadcrumbs_component {
1.911     bisitz   5168:   float: right;
                   5169:   margin: 0 1em;
1.357     albertel 5170: }
1.842     droeschl 5171: .LC_breadcrumbs_component img {
1.911     bisitz   5172:   vertical-align: middle;
1.777     tempelho 5173: }
1.795     www      5174: 
1.383     albertel 5175: td.LC_table_cell_checkbox {
                   5176:   text-align: center;
                   5177: }
1.795     www      5178: 
                   5179: .LC_fontsize_small {
1.911     bisitz   5180:   font-size: 70%;
1.705     tempelho 5181: }
                   5182: 
1.844     bisitz   5183: #LC_breadcrumbs {
1.911     bisitz   5184:   clear:both;
                   5185:   background: $sidebg;
                   5186:   border-bottom: 1px solid $lg_border_color;
                   5187:   line-height: 2.5em;
1.933     droeschl 5188:   overflow: hidden;
1.911     bisitz   5189:   margin: 0;
                   5190:   padding: 0;
1.995     raeburn  5191:   text-align: left;
1.819     tempelho 5192: }
1.862     bisitz   5193: 
1.993     raeburn  5194: .LC_head_subbox {
1.911     bisitz   5195:   clear:both;
                   5196:   background: #F8F8F8; /* $sidebg; */
1.915     droeschl 5197:   border: 1px solid $sidebg;
                   5198:   margin: 0 0 10px 0;      
1.966     bisitz   5199:   padding: 3px;
1.995     raeburn  5200:   text-align: left;
1.822     bisitz   5201: }
                   5202: 
1.795     www      5203: .LC_fontsize_medium {
1.911     bisitz   5204:   font-size: 85%;
1.705     tempelho 5205: }
                   5206: 
1.795     www      5207: .LC_fontsize_large {
1.911     bisitz   5208:   font-size: 120%;
1.705     tempelho 5209: }
                   5210: 
1.346     albertel 5211: .LC_menubuttons_inline_text {
                   5212:   color: $font;
1.698     harmsja  5213:   font-size: 90%;
1.701     harmsja  5214:   padding-left:3px;
1.346     albertel 5215: }
                   5216: 
1.934     droeschl 5217: .LC_menubuttons_inline_text img{
                   5218:   vertical-align: middle;
                   5219: }
                   5220: 
1.951     onken    5221: li.LC_menubuttons_inline_text img,a {
                   5222:   cursor:pointer;
1.1002    droeschl 5223:   text-decoration: none;
1.951     onken    5224: }
                   5225: 
1.526     www      5226: .LC_menubuttons_link {
                   5227:   text-decoration: none;
                   5228: }
1.795     www      5229: 
1.522     albertel 5230: .LC_menubuttons_category {
1.521     www      5231:   color: $font;
1.526     www      5232:   background: $pgbg;
1.521     www      5233:   font-size: larger;
                   5234:   font-weight: bold;
                   5235: }
                   5236: 
1.346     albertel 5237: td.LC_menubuttons_text {
1.911     bisitz   5238:   color: $font;
1.346     albertel 5239: }
1.706     harmsja  5240: 
1.346     albertel 5241: .LC_current_location {
                   5242:   background: $tabbg;
                   5243: }
1.795     www      5244: 
1.938     bisitz   5245: table.LC_data_table {
1.347     albertel 5246:   border: 1px solid #000000;
1.402     albertel 5247:   border-collapse: separate;
1.426     albertel 5248:   border-spacing: 1px;
1.610     albertel 5249:   background: $pgbg;
1.347     albertel 5250: }
1.795     www      5251: 
1.422     albertel 5252: .LC_data_table_dense {
                   5253:   font-size: small;
                   5254: }
1.795     www      5255: 
1.507     raeburn  5256: table.LC_nested_outer {
                   5257:   border: 1px solid #000000;
1.589     raeburn  5258:   border-collapse: collapse;
1.803     bisitz   5259:   border-spacing: 0;
1.507     raeburn  5260:   width: 100%;
                   5261: }
1.795     www      5262: 
1.879     raeburn  5263: table.LC_innerpickbox,
1.507     raeburn  5264: table.LC_nested {
1.803     bisitz   5265:   border: none;
1.589     raeburn  5266:   border-collapse: collapse;
1.803     bisitz   5267:   border-spacing: 0;
1.507     raeburn  5268:   width: 100%;
                   5269: }
1.795     www      5270: 
1.911     bisitz   5271: table.LC_data_table tr th,
                   5272: table.LC_calendar tr th,
1.879     raeburn  5273: table.LC_prior_tries tr th,
                   5274: table.LC_innerpickbox tr th {
1.349     albertel 5275:   font-weight: bold;
                   5276:   background-color: $data_table_head;
1.801     tempelho 5277:   color:$fontmenu;
1.701     harmsja  5278:   font-size:90%;
1.347     albertel 5279: }
1.795     www      5280: 
1.879     raeburn  5281: table.LC_innerpickbox tr th,
                   5282: table.LC_innerpickbox tr td {
                   5283:   vertical-align: top;
                   5284: }
                   5285: 
1.711     raeburn  5286: table.LC_data_table tr.LC_info_row > td {
1.735     bisitz   5287:   background-color: #CCCCCC;
1.711     raeburn  5288:   font-weight: bold;
                   5289:   text-align: left;
                   5290: }
1.795     www      5291: 
1.912     bisitz   5292: table.LC_data_table tr.LC_odd_row > td {
                   5293:   background-color: $data_table_light;
                   5294:   padding: 2px;
                   5295:   vertical-align: top;
                   5296: }
                   5297: 
1.809     bisitz   5298: table.LC_pick_box tr > td.LC_odd_row {
1.349     albertel 5299:   background-color: $data_table_light;
1.912     bisitz   5300:   vertical-align: top;
                   5301: }
                   5302: 
                   5303: table.LC_data_table tr.LC_even_row > td {
                   5304:   background-color: $data_table_dark;
1.425     albertel 5305:   padding: 2px;
1.900     bisitz   5306:   vertical-align: top;
1.347     albertel 5307: }
1.795     www      5308: 
1.809     bisitz   5309: table.LC_pick_box tr > td.LC_even_row {
1.349     albertel 5310:   background-color: $data_table_dark;
1.900     bisitz   5311:   vertical-align: top;
1.347     albertel 5312: }
1.795     www      5313: 
1.425     albertel 5314: table.LC_data_table tr.LC_data_table_highlight td {
                   5315:   background-color: $data_table_darker;
                   5316: }
1.795     www      5317: 
1.639     raeburn  5318: table.LC_data_table tr td.LC_leftcol_header {
                   5319:   background-color: $data_table_head;
                   5320:   font-weight: bold;
                   5321: }
1.795     www      5322: 
1.451     albertel 5323: table.LC_data_table tr.LC_empty_row td,
1.507     raeburn  5324: table.LC_nested tr.LC_empty_row td {
1.421     albertel 5325:   font-weight: bold;
                   5326:   font-style: italic;
                   5327:   text-align: center;
                   5328:   padding: 8px;
1.347     albertel 5329: }
1.795     www      5330: 
1.940     bisitz   5331: table.LC_data_table tr.LC_empty_row td {
                   5332:   background-color: $sidebg;
                   5333: }
                   5334: 
                   5335: table.LC_nested tr.LC_empty_row td {
                   5336:   background-color: #FFFFFF;
                   5337: }
                   5338: 
1.890     droeschl 5339: table.LC_caption {
                   5340: }
                   5341: 
1.507     raeburn  5342: table.LC_nested tr.LC_empty_row td {
1.465     albertel 5343:   padding: 4ex
                   5344: }
1.795     www      5345: 
1.507     raeburn  5346: table.LC_nested_outer tr th {
                   5347:   font-weight: bold;
1.801     tempelho 5348:   color:$fontmenu;
1.507     raeburn  5349:   background-color: $data_table_head;
1.701     harmsja  5350:   font-size: small;
1.507     raeburn  5351:   border-bottom: 1px solid #000000;
                   5352: }
1.795     www      5353: 
1.507     raeburn  5354: table.LC_nested_outer tr td.LC_subheader {
                   5355:   background-color: $data_table_head;
                   5356:   font-weight: bold;
                   5357:   font-size: small;
                   5358:   border-bottom: 1px solid #000000;
                   5359:   text-align: right;
1.451     albertel 5360: }
1.795     www      5361: 
1.507     raeburn  5362: table.LC_nested tr.LC_info_row td {
1.735     bisitz   5363:   background-color: #CCCCCC;
1.451     albertel 5364:   font-weight: bold;
                   5365:   font-size: small;
1.507     raeburn  5366:   text-align: center;
                   5367: }
1.795     www      5368: 
1.589     raeburn  5369: table.LC_nested tr.LC_info_row td.LC_left_item,
                   5370: table.LC_nested_outer tr th.LC_left_item {
1.507     raeburn  5371:   text-align: left;
1.451     albertel 5372: }
1.795     www      5373: 
1.507     raeburn  5374: table.LC_nested td {
1.735     bisitz   5375:   background-color: #FFFFFF;
1.451     albertel 5376:   font-size: small;
1.507     raeburn  5377: }
1.795     www      5378: 
1.507     raeburn  5379: table.LC_nested_outer tr th.LC_right_item,
                   5380: table.LC_nested tr.LC_info_row td.LC_right_item,
                   5381: table.LC_nested tr.LC_odd_row td.LC_right_item,
                   5382: table.LC_nested tr td.LC_right_item {
1.451     albertel 5383:   text-align: right;
                   5384: }
                   5385: 
1.507     raeburn  5386: table.LC_nested tr.LC_odd_row td {
1.735     bisitz   5387:   background-color: #EEEEEE;
1.451     albertel 5388: }
                   5389: 
1.473     raeburn  5390: table.LC_createuser {
                   5391: }
                   5392: 
                   5393: table.LC_createuser tr.LC_section_row td {
1.701     harmsja  5394:   font-size: small;
1.473     raeburn  5395: }
                   5396: 
                   5397: table.LC_createuser tr.LC_info_row td  {
1.735     bisitz   5398:   background-color: #CCCCCC;
1.473     raeburn  5399:   font-weight: bold;
                   5400:   text-align: center;
                   5401: }
                   5402: 
1.349     albertel 5403: table.LC_calendar {
                   5404:   border: 1px solid #000000;
                   5405:   border-collapse: collapse;
1.917     raeburn  5406:   width: 98%;
1.349     albertel 5407: }
1.795     www      5408: 
1.349     albertel 5409: table.LC_calendar_pickdate {
                   5410:   font-size: xx-small;
                   5411: }
1.795     www      5412: 
1.349     albertel 5413: table.LC_calendar tr td {
                   5414:   border: 1px solid #000000;
                   5415:   vertical-align: top;
1.917     raeburn  5416:   width: 14%;
1.349     albertel 5417: }
1.795     www      5418: 
1.349     albertel 5419: table.LC_calendar tr td.LC_calendar_day_empty {
                   5420:   background-color: $data_table_dark;
                   5421: }
1.795     www      5422: 
1.779     bisitz   5423: table.LC_calendar tr td.LC_calendar_day_current {
                   5424:   background-color: $data_table_highlight;
1.777     tempelho 5425: }
1.795     www      5426: 
1.938     bisitz   5427: table.LC_data_table tr td.LC_mail_new {
1.349     albertel 5428:   background-color: $mail_new;
                   5429: }
1.795     www      5430: 
1.938     bisitz   5431: table.LC_data_table tr.LC_mail_new:hover {
1.349     albertel 5432:   background-color: $mail_new_hover;
                   5433: }
1.795     www      5434: 
1.938     bisitz   5435: table.LC_data_table tr td.LC_mail_read {
1.349     albertel 5436:   background-color: $mail_read;
                   5437: }
1.795     www      5438: 
1.938     bisitz   5439: /*
                   5440: table.LC_data_table tr.LC_mail_read:hover {
1.349     albertel 5441:   background-color: $mail_read_hover;
                   5442: }
1.938     bisitz   5443: */
1.795     www      5444: 
1.938     bisitz   5445: table.LC_data_table tr td.LC_mail_replied {
1.349     albertel 5446:   background-color: $mail_replied;
                   5447: }
1.795     www      5448: 
1.938     bisitz   5449: /*
                   5450: table.LC_data_table tr.LC_mail_replied:hover {
1.349     albertel 5451:   background-color: $mail_replied_hover;
                   5452: }
1.938     bisitz   5453: */
1.795     www      5454: 
1.938     bisitz   5455: table.LC_data_table tr td.LC_mail_other {
1.349     albertel 5456:   background-color: $mail_other;
                   5457: }
1.795     www      5458: 
1.938     bisitz   5459: /*
                   5460: table.LC_data_table tr.LC_mail_other:hover {
1.349     albertel 5461:   background-color: $mail_other_hover;
                   5462: }
1.938     bisitz   5463: */
1.494     raeburn  5464: 
1.777     tempelho 5465: table.LC_data_table tr > td.LC_browser_file,
                   5466: table.LC_data_table tr > td.LC_browser_file_published {
1.899     bisitz   5467:   background: #AAEE77;
1.389     albertel 5468: }
1.795     www      5469: 
1.777     tempelho 5470: table.LC_data_table tr > td.LC_browser_file_locked,
                   5471: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389     albertel 5472:   background: #FFAA99;
1.387     albertel 5473: }
1.795     www      5474: 
1.777     tempelho 5475: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899     bisitz   5476:   background: #888888;
1.779     bisitz   5477: }
1.795     www      5478: 
1.777     tempelho 5479: table.LC_data_table tr > td.LC_browser_file_modified,
1.779     bisitz   5480: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899     bisitz   5481:   background: #F8F866;
1.777     tempelho 5482: }
1.795     www      5483: 
1.696     bisitz   5484: table.LC_data_table tr.LC_browser_folder > td {
1.899     bisitz   5485:   background: #E0E8FF;
1.387     albertel 5486: }
1.696     bisitz   5487: 
1.707     bisitz   5488: table.LC_data_table tr > td.LC_roles_is {
1.911     bisitz   5489:   /* background: #77FF77; */
1.707     bisitz   5490: }
1.795     www      5491: 
1.707     bisitz   5492: table.LC_data_table tr > td.LC_roles_future {
1.939     bisitz   5493:   border-right: 8px solid #FFFF77;
1.707     bisitz   5494: }
1.795     www      5495: 
1.707     bisitz   5496: table.LC_data_table tr > td.LC_roles_will {
1.939     bisitz   5497:   border-right: 8px solid #FFAA77;
1.707     bisitz   5498: }
1.795     www      5499: 
1.707     bisitz   5500: table.LC_data_table tr > td.LC_roles_expired {
1.939     bisitz   5501:   border-right: 8px solid #FF7777;
1.707     bisitz   5502: }
1.795     www      5503: 
1.707     bisitz   5504: table.LC_data_table tr > td.LC_roles_will_not {
1.939     bisitz   5505:   border-right: 8px solid #AAFF77;
1.707     bisitz   5506: }
1.795     www      5507: 
1.707     bisitz   5508: table.LC_data_table tr > td.LC_roles_selected {
1.939     bisitz   5509:   border-right: 8px solid #11CC55;
1.707     bisitz   5510: }
                   5511: 
1.388     albertel 5512: span.LC_current_location {
1.701     harmsja  5513:   font-size:larger;
1.388     albertel 5514:   background: $pgbg;
                   5515: }
1.387     albertel 5516: 
1.395     albertel 5517: span.LC_parm_menu_item {
                   5518:   font-size: larger;
                   5519: }
1.795     www      5520: 
1.395     albertel 5521: span.LC_parm_scope_all {
                   5522:   color: red;
                   5523: }
1.795     www      5524: 
1.395     albertel 5525: span.LC_parm_scope_folder {
                   5526:   color: green;
                   5527: }
1.795     www      5528: 
1.395     albertel 5529: span.LC_parm_scope_resource {
                   5530:   color: orange;
                   5531: }
1.795     www      5532: 
1.395     albertel 5533: span.LC_parm_part {
                   5534:   color: blue;
                   5535: }
1.795     www      5536: 
1.911     bisitz   5537: span.LC_parm_folder,
                   5538: span.LC_parm_symb {
1.395     albertel 5539:   font-size: x-small;
                   5540:   font-family: $mono;
                   5541:   color: #AAAAAA;
                   5542: }
                   5543: 
1.977     bisitz   5544: ul.LC_parm_parmlist li {
                   5545:   display: inline-block;
                   5546:   padding: 0.3em 0.8em;
                   5547:   vertical-align: top;
                   5548:   width: 150px;
                   5549:   border-top:1px solid $lg_border_color;
                   5550: }
                   5551: 
1.795     www      5552: td.LC_parm_overview_level_menu,
                   5553: td.LC_parm_overview_map_menu,
                   5554: td.LC_parm_overview_parm_selectors,
                   5555: td.LC_parm_overview_restrictions  {
1.396     albertel 5556:   border: 1px solid black;
                   5557:   border-collapse: collapse;
                   5558: }
1.795     www      5559: 
1.396     albertel 5560: table.LC_parm_overview_restrictions td {
                   5561:   border-width: 1px 4px 1px 4px;
                   5562:   border-style: solid;
                   5563:   border-color: $pgbg;
                   5564:   text-align: center;
                   5565: }
1.795     www      5566: 
1.396     albertel 5567: table.LC_parm_overview_restrictions th {
                   5568:   background: $tabbg;
                   5569:   border-width: 1px 4px 1px 4px;
                   5570:   border-style: solid;
                   5571:   border-color: $pgbg;
                   5572: }
1.795     www      5573: 
1.398     albertel 5574: table#LC_helpmenu {
1.803     bisitz   5575:   border: none;
1.398     albertel 5576:   height: 55px;
1.803     bisitz   5577:   border-spacing: 0;
1.398     albertel 5578: }
                   5579: 
                   5580: table#LC_helpmenu fieldset legend {
                   5581:   font-size: larger;
                   5582: }
1.795     www      5583: 
1.397     albertel 5584: table#LC_helpmenu_links {
                   5585:   width: 100%;
                   5586:   border: 1px solid black;
                   5587:   background: $pgbg;
1.803     bisitz   5588:   padding: 0;
1.397     albertel 5589:   border-spacing: 1px;
                   5590: }
1.795     www      5591: 
1.397     albertel 5592: table#LC_helpmenu_links tr td {
                   5593:   padding: 1px;
                   5594:   background: $tabbg;
1.399     albertel 5595:   text-align: center;
                   5596:   font-weight: bold;
1.397     albertel 5597: }
1.396     albertel 5598: 
1.795     www      5599: table#LC_helpmenu_links a:link,
                   5600: table#LC_helpmenu_links a:visited,
1.397     albertel 5601: table#LC_helpmenu_links a:active {
                   5602:   text-decoration: none;
                   5603:   color: $font;
                   5604: }
1.795     www      5605: 
1.397     albertel 5606: table#LC_helpmenu_links a:hover {
                   5607:   text-decoration: underline;
                   5608:   color: $vlink;
                   5609: }
1.396     albertel 5610: 
1.417     albertel 5611: .LC_chrt_popup_exists {
                   5612:   border: 1px solid #339933;
                   5613:   margin: -1px;
                   5614: }
1.795     www      5615: 
1.417     albertel 5616: .LC_chrt_popup_up {
                   5617:   border: 1px solid yellow;
                   5618:   margin: -1px;
                   5619: }
1.795     www      5620: 
1.417     albertel 5621: .LC_chrt_popup {
                   5622:   border: 1px solid #8888FF;
                   5623:   background: #CCCCFF;
                   5624: }
1.795     www      5625: 
1.421     albertel 5626: table.LC_pick_box {
                   5627:   border-collapse: separate;
                   5628:   background: white;
                   5629:   border: 1px solid black;
                   5630:   border-spacing: 1px;
                   5631: }
1.795     www      5632: 
1.421     albertel 5633: table.LC_pick_box td.LC_pick_box_title {
1.850     bisitz   5634:   background: $sidebg;
1.421     albertel 5635:   font-weight: bold;
1.900     bisitz   5636:   text-align: left;
1.740     bisitz   5637:   vertical-align: top;
1.421     albertel 5638:   width: 184px;
                   5639:   padding: 8px;
                   5640: }
1.795     www      5641: 
1.579     raeburn  5642: table.LC_pick_box td.LC_pick_box_value {
                   5643:   text-align: left;
                   5644:   padding: 8px;
                   5645: }
1.795     www      5646: 
1.579     raeburn  5647: table.LC_pick_box td.LC_pick_box_select {
                   5648:   text-align: left;
                   5649:   padding: 8px;
                   5650: }
1.795     www      5651: 
1.424     albertel 5652: table.LC_pick_box td.LC_pick_box_separator {
1.803     bisitz   5653:   padding: 0;
1.421     albertel 5654:   height: 1px;
                   5655:   background: black;
                   5656: }
1.795     www      5657: 
1.421     albertel 5658: table.LC_pick_box td.LC_pick_box_submit {
                   5659:   text-align: right;
                   5660: }
1.795     www      5661: 
1.579     raeburn  5662: table.LC_pick_box td.LC_evenrow_value {
                   5663:   text-align: left;
                   5664:   padding: 8px;
                   5665:   background-color: $data_table_light;
                   5666: }
1.795     www      5667: 
1.579     raeburn  5668: table.LC_pick_box td.LC_oddrow_value {
                   5669:   text-align: left;
                   5670:   padding: 8px;
                   5671:   background-color: $data_table_light;
                   5672: }
1.795     www      5673: 
1.579     raeburn  5674: span.LC_helpform_receipt_cat {
                   5675:   font-weight: bold;
                   5676: }
1.795     www      5677: 
1.424     albertel 5678: table.LC_group_priv_box {
                   5679:   background: white;
                   5680:   border: 1px solid black;
                   5681:   border-spacing: 1px;
                   5682: }
1.795     www      5683: 
1.424     albertel 5684: table.LC_group_priv_box td.LC_pick_box_title {
                   5685:   background: $tabbg;
                   5686:   font-weight: bold;
                   5687:   text-align: right;
                   5688:   width: 184px;
                   5689: }
1.795     www      5690: 
1.424     albertel 5691: table.LC_group_priv_box td.LC_groups_fixed {
                   5692:   background: $data_table_light;
                   5693:   text-align: center;
                   5694: }
1.795     www      5695: 
1.424     albertel 5696: table.LC_group_priv_box td.LC_groups_optional {
                   5697:   background: $data_table_dark;
                   5698:   text-align: center;
                   5699: }
1.795     www      5700: 
1.424     albertel 5701: table.LC_group_priv_box td.LC_groups_functionality {
                   5702:   background: $data_table_darker;
                   5703:   text-align: center;
                   5704:   font-weight: bold;
                   5705: }
1.795     www      5706: 
1.424     albertel 5707: table.LC_group_priv td {
                   5708:   text-align: left;
1.803     bisitz   5709:   padding: 0;
1.424     albertel 5710: }
                   5711: 
                   5712: .LC_navbuttons {
                   5713:   margin: 2ex 0ex 2ex 0ex;
                   5714: }
1.795     www      5715: 
1.423     albertel 5716: .LC_topic_bar {
                   5717:   font-weight: bold;
                   5718:   background: $tabbg;
1.918     wenzelju 5719:   margin: 1em 0em 1em 2em;
1.805     bisitz   5720:   padding: 3px;
1.918     wenzelju 5721:   font-size: 1.2em;
1.423     albertel 5722: }
1.795     www      5723: 
1.423     albertel 5724: .LC_topic_bar span {
1.918     wenzelju 5725:   left: 0.5em;
                   5726:   position: absolute;
1.423     albertel 5727:   vertical-align: middle;
1.918     wenzelju 5728:   font-size: 1.2em;
1.423     albertel 5729: }
1.795     www      5730: 
1.423     albertel 5731: table.LC_course_group_status {
                   5732:   margin: 20px;
                   5733: }
1.795     www      5734: 
1.423     albertel 5735: table.LC_status_selector td {
                   5736:   vertical-align: top;
                   5737:   text-align: center;
1.424     albertel 5738:   padding: 4px;
                   5739: }
1.795     www      5740: 
1.599     albertel 5741: div.LC_feedback_link {
1.616     albertel 5742:   clear: both;
1.829     kalberla 5743:   background: $sidebg;
1.779     bisitz   5744:   width: 100%;
1.829     kalberla 5745:   padding-bottom: 10px;
                   5746:   border: 1px $tabbg solid;
1.833     kalberla 5747:   height: 22px;
                   5748:   line-height: 22px;
                   5749:   padding-top: 5px;
                   5750: }
                   5751: 
                   5752: div.LC_feedback_link img {
                   5753:   height: 22px;
1.867     kalberla 5754:   vertical-align:middle;
1.829     kalberla 5755: }
                   5756: 
1.911     bisitz   5757: div.LC_feedback_link a {
1.829     kalberla 5758:   text-decoration: none;
1.489     raeburn  5759: }
1.795     www      5760: 
1.867     kalberla 5761: div.LC_comblock {
1.911     bisitz   5762:   display:inline;
1.867     kalberla 5763:   color:$font;
                   5764:   font-size:90%;
                   5765: }
                   5766: 
                   5767: div.LC_feedback_link div.LC_comblock {
                   5768:   padding-left:5px;
                   5769: }
                   5770: 
                   5771: div.LC_feedback_link div.LC_comblock a {
                   5772:   color:$font;
                   5773: }
                   5774: 
1.489     raeburn  5775: span.LC_feedback_link {
1.858     bisitz   5776:   /* background: $feedback_link_bg; */
1.599     albertel 5777:   font-size: larger;
                   5778: }
1.795     www      5779: 
1.599     albertel 5780: span.LC_message_link {
1.858     bisitz   5781:   /* background: $feedback_link_bg; */
1.599     albertel 5782:   font-size: larger;
                   5783:   position: absolute;
                   5784:   right: 1em;
1.489     raeburn  5785: }
1.421     albertel 5786: 
1.515     albertel 5787: table.LC_prior_tries {
1.524     albertel 5788:   border: 1px solid #000000;
                   5789:   border-collapse: separate;
                   5790:   border-spacing: 1px;
1.515     albertel 5791: }
1.523     albertel 5792: 
1.515     albertel 5793: table.LC_prior_tries td {
1.524     albertel 5794:   padding: 2px;
1.515     albertel 5795: }
1.523     albertel 5796: 
                   5797: .LC_answer_correct {
1.795     www      5798:   background: lightgreen;
                   5799:   color: darkgreen;
                   5800:   padding: 6px;
1.523     albertel 5801: }
1.795     www      5802: 
1.523     albertel 5803: .LC_answer_charged_try {
1.797     www      5804:   background: #FFAAAA;
1.795     www      5805:   color: darkred;
                   5806:   padding: 6px;
1.523     albertel 5807: }
1.795     www      5808: 
1.779     bisitz   5809: .LC_answer_not_charged_try,
1.523     albertel 5810: .LC_answer_no_grade,
                   5811: .LC_answer_late {
1.795     www      5812:   background: lightyellow;
1.523     albertel 5813:   color: black;
1.795     www      5814:   padding: 6px;
1.523     albertel 5815: }
1.795     www      5816: 
1.523     albertel 5817: .LC_answer_previous {
1.795     www      5818:   background: lightblue;
                   5819:   color: darkblue;
                   5820:   padding: 6px;
1.523     albertel 5821: }
1.795     www      5822: 
1.779     bisitz   5823: .LC_answer_no_message {
1.777     tempelho 5824:   background: #FFFFFF;
                   5825:   color: black;
1.795     www      5826:   padding: 6px;
1.779     bisitz   5827: }
1.795     www      5828: 
1.779     bisitz   5829: .LC_answer_unknown {
                   5830:   background: orange;
                   5831:   color: black;
1.795     www      5832:   padding: 6px;
1.777     tempelho 5833: }
1.795     www      5834: 
1.529     albertel 5835: span.LC_prior_numerical,
                   5836: span.LC_prior_string,
                   5837: span.LC_prior_custom,
                   5838: span.LC_prior_reaction,
                   5839: span.LC_prior_math {
1.925     bisitz   5840:   font-family: $mono;
1.523     albertel 5841:   white-space: pre;
                   5842: }
                   5843: 
1.525     albertel 5844: span.LC_prior_string {
1.925     bisitz   5845:   font-family: $mono;
1.525     albertel 5846:   white-space: pre;
                   5847: }
                   5848: 
1.523     albertel 5849: table.LC_prior_option {
                   5850:   width: 100%;
                   5851:   border-collapse: collapse;
                   5852: }
1.795     www      5853: 
1.911     bisitz   5854: table.LC_prior_rank,
1.795     www      5855: table.LC_prior_match {
1.528     albertel 5856:   border-collapse: collapse;
                   5857: }
1.795     www      5858: 
1.528     albertel 5859: table.LC_prior_option tr td,
                   5860: table.LC_prior_rank tr td,
                   5861: table.LC_prior_match tr td {
1.524     albertel 5862:   border: 1px solid #000000;
1.515     albertel 5863: }
                   5864: 
1.855     bisitz   5865: .LC_nobreak {
1.544     albertel 5866:   white-space: nowrap;
1.519     raeburn  5867: }
                   5868: 
1.576     raeburn  5869: span.LC_cusr_emph {
                   5870:   font-style: italic;
                   5871: }
                   5872: 
1.633     raeburn  5873: span.LC_cusr_subheading {
                   5874:   font-weight: normal;
                   5875:   font-size: 85%;
                   5876: }
                   5877: 
1.861     bisitz   5878: div.LC_docs_entry_move {
1.859     bisitz   5879:   border: 1px solid #BBBBBB;
1.545     albertel 5880:   background: #DDDDDD;
1.861     bisitz   5881:   width: 22px;
1.859     bisitz   5882:   padding: 1px;
                   5883:   margin: 0;
1.545     albertel 5884: }
                   5885: 
1.861     bisitz   5886: table.LC_data_table tr > td.LC_docs_entry_commands,
                   5887: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545     albertel 5888:   background: #DDDDDD;
                   5889:   font-size: x-small;
                   5890: }
1.795     www      5891: 
1.861     bisitz   5892: .LC_docs_entry_parameter {
                   5893:   white-space: nowrap;
                   5894: }
                   5895: 
1.544     albertel 5896: .LC_docs_copy {
1.545     albertel 5897:   color: #000099;
1.544     albertel 5898: }
1.795     www      5899: 
1.544     albertel 5900: .LC_docs_cut {
1.545     albertel 5901:   color: #550044;
1.544     albertel 5902: }
1.795     www      5903: 
1.544     albertel 5904: .LC_docs_rename {
1.545     albertel 5905:   color: #009900;
1.544     albertel 5906: }
1.795     www      5907: 
1.544     albertel 5908: .LC_docs_remove {
1.545     albertel 5909:   color: #990000;
                   5910: }
                   5911: 
1.547     albertel 5912: .LC_docs_reinit_warn,
                   5913: .LC_docs_ext_edit {
                   5914:   font-size: x-small;
                   5915: }
                   5916: 
1.545     albertel 5917: table.LC_docs_adddocs td,
                   5918: table.LC_docs_adddocs th {
                   5919:   border: 1px solid #BBBBBB;
                   5920:   padding: 4px;
                   5921:   background: #DDDDDD;
1.543     albertel 5922: }
                   5923: 
1.584     albertel 5924: table.LC_sty_begin {
                   5925:   background: #BBFFBB;
                   5926: }
1.795     www      5927: 
1.584     albertel 5928: table.LC_sty_end {
                   5929:   background: #FFBBBB;
                   5930: }
                   5931: 
1.589     raeburn  5932: table.LC_double_column {
1.803     bisitz   5933:   border-width: 0;
1.589     raeburn  5934:   border-collapse: collapse;
                   5935:   width: 100%;
                   5936:   padding: 2px;
                   5937: }
                   5938: 
                   5939: table.LC_double_column tr td.LC_left_col {
1.590     raeburn  5940:   top: 2px;
1.589     raeburn  5941:   left: 2px;
                   5942:   width: 47%;
                   5943:   vertical-align: top;
                   5944: }
                   5945: 
                   5946: table.LC_double_column tr td.LC_right_col {
                   5947:   top: 2px;
1.779     bisitz   5948:   right: 2px;
1.589     raeburn  5949:   width: 47%;
                   5950:   vertical-align: top;
                   5951: }
                   5952: 
1.591     raeburn  5953: div.LC_left_float {
                   5954:   float: left;
                   5955:   padding-right: 5%;
1.597     albertel 5956:   padding-bottom: 4px;
1.591     raeburn  5957: }
                   5958: 
                   5959: div.LC_clear_float_header {
1.597     albertel 5960:   padding-bottom: 2px;
1.591     raeburn  5961: }
                   5962: 
                   5963: div.LC_clear_float_footer {
1.597     albertel 5964:   padding-top: 10px;
1.591     raeburn  5965:   clear: both;
                   5966: }
                   5967: 
1.597     albertel 5968: div.LC_grade_show_user {
1.941     bisitz   5969: /*  border-left: 5px solid $sidebg; */
                   5970:   border-top: 5px solid #000000;
                   5971:   margin: 50px 0 0 0;
1.936     bisitz   5972:   padding: 15px 0 5px 10px;
1.597     albertel 5973: }
1.795     www      5974: 
1.936     bisitz   5975: div.LC_grade_show_user_odd_row {
1.941     bisitz   5976: /*  border-left: 5px solid #000000; */
                   5977: }
                   5978: 
                   5979: div.LC_grade_show_user div.LC_Box {
                   5980:   margin-right: 50px;
1.597     albertel 5981: }
                   5982: 
                   5983: div.LC_grade_submissions,
                   5984: div.LC_grade_message_center,
1.936     bisitz   5985: div.LC_grade_info_links {
1.597     albertel 5986:   margin: 5px;
                   5987:   width: 99%;
                   5988:   background: #FFFFFF;
                   5989: }
1.795     www      5990: 
1.597     albertel 5991: div.LC_grade_submissions_header,
1.936     bisitz   5992: div.LC_grade_message_center_header {
1.705     tempelho 5993:   font-weight: bold;
                   5994:   font-size: large;
1.597     albertel 5995: }
1.795     www      5996: 
1.597     albertel 5997: div.LC_grade_submissions_body,
1.936     bisitz   5998: div.LC_grade_message_center_body {
1.597     albertel 5999:   border: 1px solid black;
                   6000:   width: 99%;
                   6001:   background: #FFFFFF;
                   6002: }
1.795     www      6003: 
1.613     albertel 6004: table.LC_scantron_action {
                   6005:   width: 100%;
                   6006: }
1.795     www      6007: 
1.613     albertel 6008: table.LC_scantron_action tr th {
1.698     harmsja  6009:   font-weight:bold;
                   6010:   font-style:normal;
1.613     albertel 6011: }
1.795     www      6012: 
1.779     bisitz   6013: .LC_edit_problem_header,
1.614     albertel 6014: div.LC_edit_problem_footer {
1.705     tempelho 6015:   font-weight: normal;
                   6016:   font-size:  medium;
1.602     albertel 6017:   margin: 2px;
1.600     albertel 6018: }
1.795     www      6019: 
1.600     albertel 6020: div.LC_edit_problem_header,
1.602     albertel 6021: div.LC_edit_problem_header div,
1.614     albertel 6022: div.LC_edit_problem_footer,
                   6023: div.LC_edit_problem_footer div,
1.602     albertel 6024: div.LC_edit_problem_editxml_header,
                   6025: div.LC_edit_problem_editxml_header div {
1.600     albertel 6026:   margin-top: 5px;
                   6027: }
1.795     www      6028: 
1.600     albertel 6029: div.LC_edit_problem_header_title {
1.705     tempelho 6030:   font-weight: bold;
                   6031:   font-size: larger;
1.602     albertel 6032:   background: $tabbg;
                   6033:   padding: 3px;
                   6034: }
1.795     www      6035: 
1.602     albertel 6036: table.LC_edit_problem_header_title {
                   6037:   width: 100%;
1.600     albertel 6038:   background: $tabbg;
1.602     albertel 6039: }
                   6040: 
                   6041: div.LC_edit_problem_discards {
                   6042:   float: left;
                   6043:   padding-bottom: 5px;
                   6044: }
1.795     www      6045: 
1.602     albertel 6046: div.LC_edit_problem_saves {
                   6047:   float: right;
                   6048:   padding-bottom: 5px;
1.600     albertel 6049: }
1.795     www      6050: 
1.911     bisitz   6051: img.stift {
1.803     bisitz   6052:   border-width: 0;
                   6053:   vertical-align: middle;
1.677     riegler  6054: }
1.680     riegler  6055: 
1.923     bisitz   6056: table td.LC_mainmenu_col_fieldset {
1.680     riegler  6057:   vertical-align: top;
1.777     tempelho 6058: }
1.795     www      6059: 
1.716     raeburn  6060: div.LC_createcourse {
1.911     bisitz   6061:   margin: 10px 10px 10px 10px;
1.716     raeburn  6062: }
                   6063: 
1.917     raeburn  6064: .LC_dccid {
                   6065:   margin: 0.2em 0 0 0;
                   6066:   padding: 0;
                   6067:   font-size: 90%;
                   6068:   display:none;
                   6069: }
                   6070: 
1.698     harmsja  6071: a:hover,
1.897     wenzelju 6072: ol.LC_primary_menu a:hover,
1.721     harmsja  6073: ol#LC_MenuBreadcrumbs a:hover,
                   6074: ol#LC_PathBreadcrumbs a:hover,
1.897     wenzelju 6075: ul#LC_secondary_menu a:hover,
1.721     harmsja  6076: .LC_FormSectionClearButton input:hover
1.795     www      6077: ul.LC_TabContent   li:hover a {
1.952     onken    6078:   color:$button_hover;
1.911     bisitz   6079:   text-decoration:none;
1.693     droeschl 6080: }
                   6081: 
1.779     bisitz   6082: h1 {
1.911     bisitz   6083:   padding: 0;
                   6084:   line-height:130%;
1.693     droeschl 6085: }
1.698     harmsja  6086: 
1.911     bisitz   6087: h2,
                   6088: h3,
                   6089: h4,
                   6090: h5,
                   6091: h6 {
                   6092:   margin: 5px 0 5px 0;
                   6093:   padding: 0;
                   6094:   line-height:130%;
1.693     droeschl 6095: }
1.795     www      6096: 
                   6097: .LC_hcell {
1.911     bisitz   6098:   padding:3px 15px 3px 15px;
                   6099:   margin: 0;
                   6100:   background-color:$tabbg;
                   6101:   color:$fontmenu;
                   6102:   border-bottom:solid 1px $lg_border_color;
1.693     droeschl 6103: }
1.795     www      6104: 
1.840     bisitz   6105: .LC_Box > .LC_hcell {
1.911     bisitz   6106:   margin: 0 -10px 10px -10px;
1.835     bisitz   6107: }
                   6108: 
1.721     harmsja  6109: .LC_noBorder {
1.911     bisitz   6110:   border: 0;
1.698     harmsja  6111: }
1.693     droeschl 6112: 
1.721     harmsja  6113: .LC_FormSectionClearButton input {
1.911     bisitz   6114:   background-color:transparent;
                   6115:   border: none;
                   6116:   cursor:pointer;
                   6117:   text-decoration:underline;
1.693     droeschl 6118: }
1.763     bisitz   6119: 
                   6120: .LC_help_open_topic {
1.911     bisitz   6121:   color: #FFFFFF;
                   6122:   background-color: #EEEEFF;
                   6123:   margin: 1px;
                   6124:   padding: 4px;
                   6125:   border: 1px solid #000033;
                   6126:   white-space: nowrap;
                   6127:   /* vertical-align: middle; */
1.759     neumanie 6128: }
1.693     droeschl 6129: 
1.911     bisitz   6130: dl,
                   6131: ul,
                   6132: div,
                   6133: fieldset {
                   6134:   margin: 10px 10px 10px 0;
                   6135:   /* overflow: hidden; */
1.693     droeschl 6136: }
1.795     www      6137: 
1.838     bisitz   6138: fieldset > legend {
1.911     bisitz   6139:   font-weight: bold;
                   6140:   padding: 0 5px 0 5px;
1.838     bisitz   6141: }
                   6142: 
1.813     bisitz   6143: #LC_nav_bar {
1.911     bisitz   6144:   float: left;
1.995     raeburn  6145:   background-color: $pgbg_or_bgcolor;
1.966     bisitz   6146:   margin: 0 0 2px 0;
1.807     droeschl 6147: }
                   6148: 
1.916     droeschl 6149: #LC_realm {
                   6150:   margin: 0.2em 0 0 0;
                   6151:   padding: 0;
                   6152:   font-weight: bold;
                   6153:   text-align: center;
1.995     raeburn  6154:   background-color: $pgbg_or_bgcolor;
1.916     droeschl 6155: }
                   6156: 
1.911     bisitz   6157: #LC_nav_bar em {
                   6158:   font-weight: bold;
                   6159:   font-style: normal;
1.807     droeschl 6160: }
                   6161: 
1.897     wenzelju 6162: ol.LC_primary_menu {
1.911     bisitz   6163:   float: right;
1.934     droeschl 6164:   margin: 0;
1.995     raeburn  6165:   background-color: $pgbg_or_bgcolor;
1.807     droeschl 6166: }
                   6167: 
1.852     droeschl 6168: ol#LC_PathBreadcrumbs {
1.911     bisitz   6169:   margin: 0;
1.693     droeschl 6170: }
                   6171: 
1.897     wenzelju 6172: ol.LC_primary_menu li {
1.911     bisitz   6173:   display: inline;
                   6174:   padding: 5px 5px 0 10px;
                   6175:   vertical-align: top;
1.693     droeschl 6176: }
                   6177: 
1.897     wenzelju 6178: ol.LC_primary_menu li img {
1.911     bisitz   6179:   vertical-align: bottom;
1.934     droeschl 6180:   height: 1.1em;
1.693     droeschl 6181: }
                   6182: 
1.897     wenzelju 6183: ol.LC_primary_menu a {
1.911     bisitz   6184:   color: RGB(80, 80, 80);
                   6185:   text-decoration: none;
1.693     droeschl 6186: }
1.795     www      6187: 
1.949     droeschl 6188: ol.LC_primary_menu a.LC_new_message {
                   6189:   font-weight:bold;
                   6190:   color: darkred;
                   6191: }
                   6192: 
1.975     raeburn  6193: ol.LC_docs_parameters {
                   6194:   margin-left: 0;
                   6195:   padding: 0;
                   6196:   list-style: none;
                   6197: }
                   6198: 
                   6199: ol.LC_docs_parameters li {
                   6200:   margin: 0;
                   6201:   padding-right: 20px;
                   6202:   display: inline;
                   6203: }
                   6204: 
1.976     raeburn  6205: ol.LC_docs_parameters li:before {
                   6206:   content: "\\002022 \\0020";
                   6207: }
                   6208: 
                   6209: li.LC_docs_parameters_title {
                   6210:   font-weight: bold;
                   6211: }
                   6212: 
                   6213: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
                   6214:   content: "";
                   6215: }
                   6216: 
1.897     wenzelju 6217: ul#LC_secondary_menu {
1.911     bisitz   6218:   clear: both;
                   6219:   color: $fontmenu;
                   6220:   background: $tabbg;
                   6221:   list-style: none;
                   6222:   padding: 0;
                   6223:   margin: 0;
                   6224:   width: 100%;
1.995     raeburn  6225:   text-align: left;
1.808     droeschl 6226: }
                   6227: 
1.897     wenzelju 6228: ul#LC_secondary_menu li {
1.911     bisitz   6229:   font-weight: bold;
                   6230:   line-height: 1.8em;
                   6231:   padding: 0 0.8em;
                   6232:   border-right: 1px solid black;
                   6233:   display: inline;
                   6234:   vertical-align: middle;
1.807     droeschl 6235: }
                   6236: 
1.847     tempelho 6237: ul.LC_TabContent {
1.911     bisitz   6238:   display:block;
                   6239:   background: $sidebg;
                   6240:   border-bottom: solid 1px $lg_border_color;
                   6241:   list-style:none;
1.1020    raeburn  6242:   margin: -1px -10px 0 -10px;
1.911     bisitz   6243:   padding: 0;
1.693     droeschl 6244: }
                   6245: 
1.795     www      6246: ul.LC_TabContent li,
                   6247: ul.LC_TabContentBigger li {
1.911     bisitz   6248:   float:left;
1.741     harmsja  6249: }
1.795     www      6250: 
1.897     wenzelju 6251: ul#LC_secondary_menu li a {
1.911     bisitz   6252:   color: $fontmenu;
                   6253:   text-decoration: none;
1.693     droeschl 6254: }
1.795     www      6255: 
1.721     harmsja  6256: ul.LC_TabContent {
1.952     onken    6257:   min-height:20px;
1.721     harmsja  6258: }
1.795     www      6259: 
                   6260: ul.LC_TabContent li {
1.911     bisitz   6261:   vertical-align:middle;
1.959     onken    6262:   padding: 0 16px 0 10px;
1.911     bisitz   6263:   background-color:$tabbg;
                   6264:   border-bottom:solid 1px $lg_border_color;
1.1020    raeburn  6265:   border-left: solid 1px $font;
1.721     harmsja  6266: }
1.795     www      6267: 
1.847     tempelho 6268: ul.LC_TabContent .right {
1.911     bisitz   6269:   float:right;
1.847     tempelho 6270: }
                   6271: 
1.911     bisitz   6272: ul.LC_TabContent li a,
                   6273: ul.LC_TabContent li {
                   6274:   color:rgb(47,47,47);
                   6275:   text-decoration:none;
                   6276:   font-size:95%;
                   6277:   font-weight:bold;
1.952     onken    6278:   min-height:20px;
                   6279: }
                   6280: 
1.959     onken    6281: ul.LC_TabContent li a:hover,
                   6282: ul.LC_TabContent li a:focus {
1.952     onken    6283:   color: $button_hover;
1.959     onken    6284:   background:none;
                   6285:   outline:none;
1.952     onken    6286: }
                   6287: 
                   6288: ul.LC_TabContent li:hover {
                   6289:   color: $button_hover;
                   6290:   cursor:pointer;
1.721     harmsja  6291: }
1.795     www      6292: 
1.911     bisitz   6293: ul.LC_TabContent li.active {
1.952     onken    6294:   color: $font;
1.911     bisitz   6295:   background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952     onken    6296:   border-bottom:solid 1px #FFFFFF;
                   6297:   cursor: default;
1.744     ehlerst  6298: }
1.795     www      6299: 
1.959     onken    6300: ul.LC_TabContent li.active a {
                   6301:   color:$font;
                   6302:   background:#FFFFFF;
                   6303:   outline: none;
                   6304: }
1.870     tempelho 6305: #maincoursedoc {
1.911     bisitz   6306:   clear:both;
1.870     tempelho 6307: }
                   6308: 
                   6309: ul.LC_TabContentBigger {
1.911     bisitz   6310:   display:block;
                   6311:   list-style:none;
                   6312:   padding: 0;
1.870     tempelho 6313: }
                   6314: 
1.795     www      6315: ul.LC_TabContentBigger li {
1.911     bisitz   6316:   vertical-align:bottom;
                   6317:   height: 30px;
                   6318:   font-size:110%;
                   6319:   font-weight:bold;
                   6320:   color: #737373;
1.841     tempelho 6321: }
                   6322: 
1.957     onken    6323: ul.LC_TabContentBigger li.active {
                   6324:   position: relative;
                   6325:   top: 1px;
                   6326: }
                   6327: 
1.870     tempelho 6328: ul.LC_TabContentBigger li a {
1.911     bisitz   6329:   background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
                   6330:   height: 30px;
                   6331:   line-height: 30px;
                   6332:   text-align: center;
                   6333:   display: block;
                   6334:   text-decoration: none;
1.958     onken    6335:   outline: none;  
1.741     harmsja  6336: }
1.795     www      6337: 
1.870     tempelho 6338: ul.LC_TabContentBigger li.active a {
1.911     bisitz   6339:   background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
                   6340:   color:$font;
1.744     ehlerst  6341: }
1.795     www      6342: 
1.870     tempelho 6343: ul.LC_TabContentBigger li b {
1.911     bisitz   6344:   background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
                   6345:   display: block;
                   6346:   float: left;
                   6347:   padding: 0 30px;
1.957     onken    6348:   border-bottom: 1px solid $lg_border_color;
1.870     tempelho 6349: }
                   6350: 
1.956     onken    6351: ul.LC_TabContentBigger li:hover b {
                   6352:   color:$button_hover;
                   6353: }
                   6354: 
1.870     tempelho 6355: ul.LC_TabContentBigger li.active b {
1.911     bisitz   6356:   background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
                   6357:   color:$font;
1.957     onken    6358:   border: 0;
1.741     harmsja  6359: }
1.693     droeschl 6360: 
1.870     tempelho 6361: 
1.862     bisitz   6362: ul.LC_CourseBreadcrumbs {
                   6363:   background: $sidebg;
1.1020    raeburn  6364:   height: 2em;
1.862     bisitz   6365:   padding-left: 10px;
1.1020    raeburn  6366:   margin: 0;
1.862     bisitz   6367:   list-style-position: inside;
                   6368: }
                   6369: 
1.911     bisitz   6370: ol#LC_MenuBreadcrumbs,
1.862     bisitz   6371: ol#LC_PathBreadcrumbs {
1.911     bisitz   6372:   padding-left: 10px;
                   6373:   margin: 0;
1.933     droeschl 6374:   height: 2.5em;  /* equal to #LC_breadcrumbs line-height */
1.693     droeschl 6375: }
                   6376: 
1.911     bisitz   6377: ol#LC_MenuBreadcrumbs li,
                   6378: ol#LC_PathBreadcrumbs li,
1.862     bisitz   6379: ul.LC_CourseBreadcrumbs li {
1.911     bisitz   6380:   display: inline;
1.933     droeschl 6381:   white-space: normal;  
1.693     droeschl 6382: }
                   6383: 
1.823     bisitz   6384: ol#LC_MenuBreadcrumbs li a,
1.862     bisitz   6385: ul.LC_CourseBreadcrumbs li a {
1.911     bisitz   6386:   text-decoration: none;
                   6387:   font-size:90%;
1.693     droeschl 6388: }
1.795     www      6389: 
1.969     droeschl 6390: ol#LC_MenuBreadcrumbs h1 {
                   6391:   display: inline;
                   6392:   font-size: 90%;
                   6393:   line-height: 2.5em;
                   6394:   margin: 0;
                   6395:   padding: 0;
                   6396: }
                   6397: 
1.795     www      6398: ol#LC_PathBreadcrumbs li a {
1.911     bisitz   6399:   text-decoration:none;
                   6400:   font-size:100%;
                   6401:   font-weight:bold;
1.693     droeschl 6402: }
1.795     www      6403: 
1.840     bisitz   6404: .LC_Box {
1.911     bisitz   6405:   border: solid 1px $lg_border_color;
                   6406:   padding: 0 10px 10px 10px;
1.746     neumanie 6407: }
1.795     www      6408: 
1.1020    raeburn  6409: .LC_DocsBox {
                   6410:   border: solid 1px $lg_border_color;
                   6411:   padding: 0 0 10px 10px;
                   6412: }
                   6413: 
1.795     www      6414: .LC_AboutMe_Image {
1.911     bisitz   6415:   float:left;
                   6416:   margin-right:10px;
1.747     neumanie 6417: }
1.795     www      6418: 
                   6419: .LC_Clear_AboutMe_Image {
1.911     bisitz   6420:   clear:left;
1.747     neumanie 6421: }
1.795     www      6422: 
1.721     harmsja  6423: dl.LC_ListStyleClean dt {
1.911     bisitz   6424:   padding-right: 5px;
                   6425:   display: table-header-group;
1.693     droeschl 6426: }
                   6427: 
1.721     harmsja  6428: dl.LC_ListStyleClean dd {
1.911     bisitz   6429:   display: table-row;
1.693     droeschl 6430: }
                   6431: 
1.721     harmsja  6432: .LC_ListStyleClean,
                   6433: .LC_ListStyleSimple,
                   6434: .LC_ListStyleNormal,
1.795     www      6435: .LC_ListStyleSpecial {
1.911     bisitz   6436:   /* display:block; */
                   6437:   list-style-position: inside;
                   6438:   list-style-type: none;
                   6439:   overflow: hidden;
                   6440:   padding: 0;
1.693     droeschl 6441: }
                   6442: 
1.721     harmsja  6443: .LC_ListStyleSimple li,
                   6444: .LC_ListStyleSimple dd,
                   6445: .LC_ListStyleNormal li,
                   6446: .LC_ListStyleNormal dd,
                   6447: .LC_ListStyleSpecial li,
1.795     www      6448: .LC_ListStyleSpecial dd {
1.911     bisitz   6449:   margin: 0;
                   6450:   padding: 5px 5px 5px 10px;
                   6451:   clear: both;
1.693     droeschl 6452: }
                   6453: 
1.721     harmsja  6454: .LC_ListStyleClean li,
                   6455: .LC_ListStyleClean dd {
1.911     bisitz   6456:   padding-top: 0;
                   6457:   padding-bottom: 0;
1.693     droeschl 6458: }
                   6459: 
1.721     harmsja  6460: .LC_ListStyleSimple dd,
1.795     www      6461: .LC_ListStyleSimple li {
1.911     bisitz   6462:   border-bottom: solid 1px $lg_border_color;
1.693     droeschl 6463: }
                   6464: 
1.721     harmsja  6465: .LC_ListStyleSpecial li,
                   6466: .LC_ListStyleSpecial dd {
1.911     bisitz   6467:   list-style-type: none;
                   6468:   background-color: RGB(220, 220, 220);
                   6469:   margin-bottom: 4px;
1.693     droeschl 6470: }
                   6471: 
1.721     harmsja  6472: table.LC_SimpleTable {
1.911     bisitz   6473:   margin:5px;
                   6474:   border:solid 1px $lg_border_color;
1.795     www      6475: }
1.693     droeschl 6476: 
1.721     harmsja  6477: table.LC_SimpleTable tr {
1.911     bisitz   6478:   padding: 0;
                   6479:   border:solid 1px $lg_border_color;
1.693     droeschl 6480: }
1.795     www      6481: 
                   6482: table.LC_SimpleTable thead {
1.911     bisitz   6483:   background:rgb(220,220,220);
1.693     droeschl 6484: }
                   6485: 
1.721     harmsja  6486: div.LC_columnSection {
1.911     bisitz   6487:   display: block;
                   6488:   clear: both;
                   6489:   overflow: hidden;
                   6490:   margin: 0;
1.693     droeschl 6491: }
                   6492: 
1.721     harmsja  6493: div.LC_columnSection>* {
1.911     bisitz   6494:   float: left;
                   6495:   margin: 10px 20px 10px 0;
                   6496:   overflow:hidden;
1.693     droeschl 6497: }
1.721     harmsja  6498: 
1.795     www      6499: table em {
1.911     bisitz   6500:   font-weight: bold;
                   6501:   font-style: normal;
1.748     schulted 6502: }
1.795     www      6503: 
1.779     bisitz   6504: table.LC_tableBrowseRes,
1.795     www      6505: table.LC_tableOfContent {
1.911     bisitz   6506:   border:none;
                   6507:   border-spacing: 1px;
                   6508:   padding: 3px;
                   6509:   background-color: #FFFFFF;
                   6510:   font-size: 90%;
1.753     droeschl 6511: }
1.789     droeschl 6512: 
1.911     bisitz   6513: table.LC_tableOfContent {
                   6514:   border-collapse: collapse;
1.789     droeschl 6515: }
                   6516: 
1.771     droeschl 6517: table.LC_tableBrowseRes a,
1.768     schulted 6518: table.LC_tableOfContent a {
1.911     bisitz   6519:   background-color: transparent;
                   6520:   text-decoration: none;
1.753     droeschl 6521: }
                   6522: 
1.795     www      6523: table.LC_tableOfContent img {
1.911     bisitz   6524:   border: none;
                   6525:   height: 1.3em;
                   6526:   vertical-align: text-bottom;
                   6527:   margin-right: 0.3em;
1.753     droeschl 6528: }
1.757     schulted 6529: 
1.795     www      6530: a#LC_content_toolbar_firsthomework {
1.911     bisitz   6531:   background-image:url(/res/adm/pages/open-first-problem.gif);
1.774     ehlerst  6532: }
                   6533: 
1.795     www      6534: a#LC_content_toolbar_everything {
1.911     bisitz   6535:   background-image:url(/res/adm/pages/show-all.gif);
1.774     ehlerst  6536: }
                   6537: 
1.795     www      6538: a#LC_content_toolbar_uncompleted {
1.911     bisitz   6539:   background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774     ehlerst  6540: }
                   6541: 
1.795     www      6542: #LC_content_toolbar_clearbubbles {
1.911     bisitz   6543:   background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774     ehlerst  6544: }
                   6545: 
1.795     www      6546: a#LC_content_toolbar_changefolder {
1.911     bisitz   6547:   background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757     schulted 6548: }
                   6549: 
1.795     www      6550: a#LC_content_toolbar_changefolder_toggled {
1.911     bisitz   6551:   background-image:url(/res/adm/pages/open-all-folders.gif);
1.757     schulted 6552: }
                   6553: 
1.795     www      6554: ul#LC_toolbar li a:hover {
1.911     bisitz   6555:   background-position: bottom center;
1.757     schulted 6556: }
                   6557: 
1.795     www      6558: ul#LC_toolbar {
1.911     bisitz   6559:   padding: 0;
                   6560:   margin: 2px;
                   6561:   list-style:none;
                   6562:   position:relative;
                   6563:   background-color:white;
1.757     schulted 6564: }
                   6565: 
1.795     www      6566: ul#LC_toolbar li {
1.911     bisitz   6567:   border:1px solid white;
                   6568:   padding: 0;
                   6569:   margin: 0;
                   6570:   float: left;
                   6571:   display:inline;
                   6572:   vertical-align:middle;
                   6573: }
1.757     schulted 6574: 
1.783     amueller 6575: 
1.795     www      6576: a.LC_toolbarItem {
1.911     bisitz   6577:   display:block;
                   6578:   padding: 0;
                   6579:   margin: 0;
                   6580:   height: 32px;
                   6581:   width: 32px;
                   6582:   color:white;
                   6583:   border: none;
                   6584:   background-repeat:no-repeat;
                   6585:   background-color:transparent;
1.757     schulted 6586: }
                   6587: 
1.915     droeschl 6588: ul.LC_funclist {
                   6589:     margin: 0;
                   6590:     padding: 0.5em 1em 0.5em 0;
                   6591: }
                   6592: 
1.933     droeschl 6593: ul.LC_funclist > li:first-child {
                   6594:     font-weight:bold; 
                   6595:     margin-left:0.8em;
                   6596: }
                   6597: 
1.915     droeschl 6598: ul.LC_funclist + ul.LC_funclist {
                   6599:     /* 
                   6600:        left border as a seperator if we have more than
                   6601:        one list 
                   6602:     */
                   6603:     border-left: 1px solid $sidebg;
                   6604:     /* 
                   6605:        this hides the left border behind the border of the 
                   6606:        outer box if element is wrapped to the next 'line' 
                   6607:     */
                   6608:     margin-left: -1px;
                   6609: }
                   6610: 
1.843     bisitz   6611: ul.LC_funclist li {
1.915     droeschl 6612:   display: inline;
1.782     bisitz   6613:   white-space: nowrap;
1.915     droeschl 6614:   margin: 0 0 0 25px;
                   6615:   line-height: 150%;
1.782     bisitz   6616: }
                   6617: 
1.974     wenzelju 6618: .LC_hidden {
                   6619:   display: none;
                   6620: }
                   6621: 
1.343     albertel 6622: END
                   6623: }
                   6624: 
1.306     albertel 6625: =pod
                   6626: 
                   6627: =item * &headtag()
                   6628: 
                   6629: Returns a uniform footer for LON-CAPA web pages.
                   6630: 
1.307     albertel 6631: Inputs: $title - optional title for the head
                   6632:         $head_extra - optional extra HTML to put inside the <head>
1.315     albertel 6633:         $args - optional arguments
1.319     albertel 6634:             force_register - if is true call registerurl so the remote is 
                   6635:                              informed
1.415     albertel 6636:             redirect       -> array ref of
                   6637:                                    1- seconds before redirect occurs
                   6638:                                    2- url to redirect to
                   6639:                                    3- whether the side effect should occur
1.315     albertel 6640:                            (side effect of setting 
                   6641:                                $env{'internal.head.redirect'} to the url 
                   6642:                                redirected too)
1.352     albertel 6643:             domain         -> force to color decorate a page for a specific
                   6644:                                domain
                   6645:             function       -> force usage of a specific rolish color scheme
                   6646:             bgcolor        -> override the default page bgcolor
1.460     albertel 6647:             no_auto_mt_title
                   6648:                            -> prevent &mt()ing the title arg
1.464     albertel 6649: 
1.306     albertel 6650: =cut
                   6651: 
                   6652: sub headtag {
1.313     albertel 6653:     my ($title,$head_extra,$args) = @_;
1.306     albertel 6654:     
1.363     albertel 6655:     my $function = $args->{'function'} || &get_users_function();
                   6656:     my $domain   = $args->{'domain'}   || &determinedomain();
                   6657:     my $bgcolor  = $args->{'bgcolor'}  || &designparm($function.'.pgbg',$domain);
1.418     albertel 6658:     my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458     albertel 6659: 		   $Apache::lonnet::perlvar{'lonVersion'},
1.531     albertel 6660: 		   #time(),
1.418     albertel 6661: 		   $env{'environment.color.timestamp'},
1.363     albertel 6662: 		   $function,$domain,$bgcolor);
                   6663: 
1.369     www      6664:     $url = '/adm/css/'.&escape($url).'.css';
1.363     albertel 6665: 
1.308     albertel 6666:     my $result =
                   6667: 	'<head>'.
1.461     albertel 6668: 	&font_settings();
1.319     albertel 6669: 
1.461     albertel 6670:     if (!$args->{'frameset'}) {
                   6671: 	$result .= &Apache::lonhtmlcommon::htmlareaheaders();
                   6672:     }
1.962     droeschl 6673:     if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
                   6674:         $result .= Apache::lonxml::display_title();
1.319     albertel 6675:     }
1.436     albertel 6676:     if (!$args->{'no_nav_bar'} 
                   6677: 	&& !$args->{'only_body'}
                   6678: 	&& !$args->{'frameset'}) {
                   6679: 	$result .= &help_menu_js();
                   6680:     }
1.319     albertel 6681: 
1.314     albertel 6682:     if (ref($args->{'redirect'})) {
1.414     albertel 6683: 	my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315     albertel 6684: 	$url = &Apache::lonenc::check_encrypt($url);
1.414     albertel 6685: 	if (!$inhibit_continue) {
                   6686: 	    $env{'internal.head.redirect'} = $url;
                   6687: 	}
1.313     albertel 6688: 	$result.=<<ADDMETA
                   6689: <meta http-equiv="pragma" content="no-cache" />
1.344     albertel 6690: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313     albertel 6691: ADDMETA
                   6692:     }
1.306     albertel 6693:     if (!defined($title)) {
                   6694: 	$title = 'The LearningOnline Network with CAPA';
                   6695:     }
1.460     albertel 6696:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
                   6697:     $result .= '<title> LON-CAPA '.$title.'</title>'
1.414     albertel 6698: 	.'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
                   6699: 	.$head_extra;
1.962     droeschl 6700:     return $result.'</head>';
1.306     albertel 6701: }
                   6702: 
                   6703: =pod
                   6704: 
1.340     albertel 6705: =item * &font_settings()
                   6706: 
                   6707: Returns neccessary <meta> to set the proper encoding
                   6708: 
                   6709: Inputs: none
                   6710: 
                   6711: =cut
                   6712: 
                   6713: sub font_settings {
                   6714:     my $headerstring='';
1.647     www      6715:     if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340     albertel 6716: 	$headerstring.=
                   6717: 	    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
                   6718:     }
                   6719:     return $headerstring;
                   6720: }
                   6721: 
1.341     albertel 6722: =pod
                   6723: 
                   6724: =item * &xml_begin()
                   6725: 
                   6726: Returns the needed doctype and <html>
                   6727: 
                   6728: Inputs: none
                   6729: 
                   6730: =cut
                   6731: 
                   6732: sub xml_begin {
                   6733:     my $output='';
                   6734: 
                   6735:     if ($env{'browser.mathml'}) {
                   6736: 	$output='<?xml version="1.0"?>'
                   6737:             #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
                   6738: #            .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
                   6739:             
                   6740: #	    .'<!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">] >'
                   6741: 	    .'<!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">'
                   6742:             .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" ' 
                   6743: 	    .'xmlns="http://www.w3.org/1999/xhtml">';
                   6744:     } else {
1.849     bisitz   6745: 	$output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
                   6746:            .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341     albertel 6747:     }
                   6748:     return $output;
                   6749: }
1.340     albertel 6750: 
                   6751: =pod
                   6752: 
1.306     albertel 6753: =item * &start_page()
                   6754: 
                   6755: Returns a complete <html> .. <body> section for LON-CAPA web pages.
                   6756: 
1.648     raeburn  6757: Inputs:
                   6758: 
                   6759: =over 4
                   6760: 
                   6761: $title - optional title for the page
                   6762: 
                   6763: $head_extra - optional extra HTML to incude inside the <head>
                   6764: 
                   6765: $args - additional optional args supported are:
                   6766: 
                   6767: =over 8
                   6768: 
                   6769:              only_body      -> is true will set &bodytag() onlybodytag
1.317     albertel 6770:                                     arg on
1.814     bisitz   6771:              no_nav_bar     -> is true will set &bodytag() no_nav_bar arg on
1.648     raeburn  6772:              add_entries    -> additional attributes to add to the  <body>
                   6773:              domain         -> force to color decorate a page for a 
1.317     albertel 6774:                                     specific domain
1.648     raeburn  6775:              function       -> force usage of a specific rolish color
1.317     albertel 6776:                                     scheme
1.648     raeburn  6777:              redirect       -> see &headtag()
                   6778:              bgcolor        -> override the default page bg color
                   6779:              js_ready       -> return a string ready for being used in 
1.317     albertel 6780:                                     a javascript writeln
1.648     raeburn  6781:              html_encode    -> return a string ready for being used in 
1.320     albertel 6782:                                     a html attribute
1.648     raeburn  6783:              force_register -> if is true will turn on the &bodytag()
1.317     albertel 6784:                                     $forcereg arg
1.648     raeburn  6785:              frameset       -> if true will start with a <frameset>
1.330     albertel 6786:                                     rather than <body>
1.648     raeburn  6787:              skip_phases    -> hash ref of 
1.338     albertel 6788:                                     head -> skip the <html><head> generation
                   6789:                                     body -> skip all <body> generation
1.648     raeburn  6790:              no_auto_mt_title -> prevent &mt()ing the title arg
                   6791:              inherit_jsmath -> when creating popup window in a page,
                   6792:                                     should it have jsmath forced on by the
                   6793:                                     current page
1.867     kalberla 6794:              bread_crumbs ->             Array containing breadcrumbs
1.983     raeburn  6795:              bread_crumbs_component ->  if exists show it as headline else show only the breadcrumbs
1.361     albertel 6796: 
1.648     raeburn  6797: =back
1.460     albertel 6798: 
1.648     raeburn  6799: =back
1.562     albertel 6800: 
1.306     albertel 6801: =cut
                   6802: 
                   6803: sub start_page {
1.309     albertel 6804:     my ($title,$head_extra,$args) = @_;
1.318     albertel 6805:     #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.964     droeschl 6806: #SD
                   6807: #I don't see why we copy certain elements of %$args to %head_args
                   6808: #head args is passed to headtag() and this routine only reads those
                   6809: #keys that are needed. There doesn't happen any writes or any processing
                   6810: #of other keys.
                   6811: #proposal: just pass $args to headtag instead of \%head_args and delete 
                   6812: #marked lines
                   6813: #<- MARK
1.313     albertel 6814:     my %head_args;
1.352     albertel 6815:     foreach my $arg ('redirect','force_register','domain','function',
1.460     albertel 6816: 		     'bgcolor','frameset','no_nav_bar','only_body',
                   6817: 		     'no_auto_mt_title') {
1.319     albertel 6818: 	if (defined($args->{$arg})) {
1.324     raeburn  6819: 	    $head_args{$arg} = $args->{$arg};
1.319     albertel 6820: 	}
1.313     albertel 6821:     }
1.964     droeschl 6822: #MARK ->
1.319     albertel 6823: 
1.315     albertel 6824:     $env{'internal.start_page'}++;
1.338     albertel 6825:     my $result;
1.964     droeschl 6826: 
1.338     albertel 6827:     if (! exists($args->{'skip_phases'}{'head'}) ) {
1.964     droeschl 6828:         $result .= 
                   6829:                   &xml_begin() . &headtag($title,$head_extra,\%head_args);
                   6830: #replace prev line by
                   6831: #                 &xml_begin() . &headtag($title, $head_extra, $args);
1.338     albertel 6832:     }
                   6833:     
                   6834:     if (! exists($args->{'skip_phases'}{'body'}) ) {
                   6835: 	if ($args->{'frameset'}) {
                   6836: 	    my $attr_string = &make_attr_string($args->{'force_register'},
                   6837: 						$args->{'add_entries'});
                   6838: 	    $result .= "\n<frameset $attr_string>\n";
1.831     bisitz   6839:         } else {
                   6840:             $result .=
                   6841:                 &bodytag($title, 
                   6842:                          $args->{'function'},       $args->{'add_entries'},
                   6843:                          $args->{'only_body'},      $args->{'domain'},
                   6844:                          $args->{'force_register'}, $args->{'no_nav_bar'},
1.962     droeschl 6845:                          $args->{'bgcolor'},        $args);
1.831     bisitz   6846:         }
1.330     albertel 6847:     }
1.338     albertel 6848: 
1.315     albertel 6849:     if ($args->{'js_ready'}) {
1.713     kaisler  6850: 		$result = &js_ready($result);
1.315     albertel 6851:     }
1.320     albertel 6852:     if ($args->{'html_encode'}) {
1.713     kaisler  6853: 		$result = &html_encode($result);
                   6854:     }
                   6855: 
1.813     bisitz   6856:     # Preparation for new and consistent functionlist at top of screen
                   6857:     # if ($args->{'functionlist'}) {
                   6858:     #            $result .= &build_functionlist();
                   6859:     #}
                   6860: 
1.964     droeschl 6861:     # Don't add anything more if only_body wanted or in const space
                   6862:     return $result if    $args->{'only_body'} 
                   6863:                       || $env{'request.state'} eq 'construct';
1.813     bisitz   6864: 
                   6865:     #Breadcrumbs
1.758     kaisler  6866:     if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
                   6867: 		&Apache::lonhtmlcommon::clear_breadcrumbs();
                   6868: 		#if any br links exists, add them to the breadcrumbs
                   6869: 		if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {         
                   6870: 			foreach my $crumb (@{$args->{'bread_crumbs'}}){
                   6871: 				&Apache::lonhtmlcommon::add_breadcrumb($crumb);
                   6872: 			}
                   6873: 		}
                   6874: 
                   6875: 		#if bread_crumbs_component exists show it as headline else show only the breadcrumbs
                   6876: 		if(exists($args->{'bread_crumbs_component'})){
                   6877: 			$result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
                   6878: 		}else{
                   6879: 			$result .= &Apache::lonhtmlcommon::breadcrumbs();
                   6880: 		}
1.320     albertel 6881:     }
1.315     albertel 6882:     return $result;
1.306     albertel 6883: }
                   6884: 
                   6885: sub end_page {
1.315     albertel 6886:     my ($args) = @_;
                   6887:     $env{'internal.end_page'}++;
1.330     albertel 6888:     my $result;
1.335     albertel 6889:     if ($args->{'discussion'}) {
                   6890: 	my ($target,$parser);
                   6891: 	if (ref($args->{'discussion'})) {
                   6892: 	    ($target,$parser) =($args->{'discussion'}{'target'},
                   6893: 				$args->{'discussion'}{'parser'});
                   6894: 	}
                   6895: 	$result .= &Apache::lonxml::xmlend($target,$parser);
                   6896:     }
                   6897: 
1.330     albertel 6898:     if ($args->{'frameset'}) {
                   6899: 	$result .= '</frameset>';
                   6900:     } else {
1.635     raeburn  6901: 	$result .= &endbodytag($args);
1.330     albertel 6902:     }
                   6903:     $result .= "\n</html>";
                   6904: 
1.315     albertel 6905:     if ($args->{'js_ready'}) {
1.317     albertel 6906: 	$result = &js_ready($result);
1.315     albertel 6907:     }
1.335     albertel 6908: 
1.320     albertel 6909:     if ($args->{'html_encode'}) {
                   6910: 	$result = &html_encode($result);
                   6911:     }
1.335     albertel 6912: 
1.315     albertel 6913:     return $result;
                   6914: }
                   6915: 
1.320     albertel 6916: sub html_encode {
                   6917:     my ($result) = @_;
                   6918: 
1.322     albertel 6919:     $result = &HTML::Entities::encode($result,'<>&"');
1.320     albertel 6920:     
                   6921:     return $result;
                   6922: }
1.317     albertel 6923: sub js_ready {
                   6924:     my ($result) = @_;
                   6925: 
1.323     albertel 6926:     $result =~ s/[\n\r]/ /xmsg;
                   6927:     $result =~ s/\\/\\\\/xmsg;
                   6928:     $result =~ s/'/\\'/xmsg;
1.372     albertel 6929:     $result =~ s{</}{<\\/}xmsg;
1.317     albertel 6930:     
                   6931:     return $result;
                   6932: }
                   6933: 
1.315     albertel 6934: sub validate_page {
                   6935:     if (  exists($env{'internal.start_page'})
1.316     albertel 6936: 	  &&     $env{'internal.start_page'} > 1) {
                   6937: 	&Apache::lonnet::logthis('start_page called multiple times '.
1.318     albertel 6938: 				 $env{'internal.start_page'}.' '.
1.316     albertel 6939: 				 $ENV{'request.filename'});
1.315     albertel 6940:     }
                   6941:     if (  exists($env{'internal.end_page'})
1.316     albertel 6942: 	  &&     $env{'internal.end_page'} > 1) {
                   6943: 	&Apache::lonnet::logthis('end_page called multiple times '.
1.318     albertel 6944: 				 $env{'internal.end_page'}.' '.
1.316     albertel 6945: 				 $env{'request.filename'});
1.315     albertel 6946:     }
                   6947:     if (     exists($env{'internal.start_page'})
                   6948: 	&& ! exists($env{'internal.end_page'})) {
1.316     albertel 6949: 	&Apache::lonnet::logthis('start_page called without end_page '.
                   6950: 				 $env{'request.filename'});
1.315     albertel 6951:     }
                   6952:     if (   ! exists($env{'internal.start_page'})
                   6953: 	&&   exists($env{'internal.end_page'})) {
1.316     albertel 6954: 	&Apache::lonnet::logthis('end_page called without start_page'.
                   6955: 				 $env{'request.filename'});
1.315     albertel 6956:     }
1.306     albertel 6957: }
1.315     albertel 6958: 
1.996     www      6959: 
                   6960: sub start_scrollbox {
1.1018    raeburn  6961:     my ($outerwidth,$width,$height,$id)=@_;
1.998     raeburn  6962:     unless ($outerwidth) { $outerwidth='520px'; }
                   6963:     unless ($width) { $width='500px'; }
                   6964:     unless ($height) { $height='200px'; }
1.1020    raeburn  6965:     my ($table_id,$div_id);
1.1018    raeburn  6966:     if ($id ne '') {
1.1020    raeburn  6967:         $table_id = " id='table_$id'";
                   6968:         $div_id = " id='div_$id'";
1.1018    raeburn  6969:     }
1.1020    raeburn  6970:     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      6971: }
                   6972: 
                   6973: sub end_scrollbox {
1.998     raeburn  6974:     return '</td></tr></table>';
1.996     www      6975: }
                   6976: 
1.318     albertel 6977: sub simple_error_page {
                   6978:     my ($r,$title,$msg) = @_;
                   6979:     my $page =
                   6980: 	&Apache::loncommon::start_page($title).
                   6981: 	&mt($msg).
                   6982: 	&Apache::loncommon::end_page();
                   6983:     if (ref($r)) {
                   6984: 	$r->print($page);
1.327     albertel 6985: 	return;
1.318     albertel 6986:     }
                   6987:     return $page;
                   6988: }
1.347     albertel 6989: 
                   6990: {
1.610     albertel 6991:     my @row_count;
1.961     onken    6992: 
                   6993:     sub start_data_table_count {
                   6994:         unshift(@row_count, 0);
                   6995:         return;
                   6996:     }
                   6997: 
                   6998:     sub end_data_table_count {
                   6999:         shift(@row_count);
                   7000:         return;
                   7001:     }
                   7002: 
1.347     albertel 7003:     sub start_data_table {
1.1018    raeburn  7004: 	my ($add_class,$id) = @_;
1.422     albertel 7005: 	my $css_class = (join(' ','LC_data_table',$add_class));
1.1018    raeburn  7006:         my $table_id;
                   7007:         if (defined($id)) {
                   7008:             $table_id = ' id="'.$id.'"';
                   7009:         }
1.961     onken    7010: 	&start_data_table_count();
1.1018    raeburn  7011: 	return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347     albertel 7012:     }
                   7013: 
                   7014:     sub end_data_table {
1.961     onken    7015: 	&end_data_table_count();
1.389     albertel 7016: 	return '</table>'."\n";;
1.347     albertel 7017:     }
                   7018: 
                   7019:     sub start_data_table_row {
1.974     wenzelju 7020: 	my ($add_class, $id) = @_;
1.610     albertel 7021: 	$row_count[0]++;
                   7022: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900     bisitz   7023: 	$css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974     wenzelju 7024:         $id = (' id="'.$id.'"') unless ($id eq '');
                   7025:         return  '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347     albertel 7026:     }
1.471     banghart 7027:     
                   7028:     sub continue_data_table_row {
1.974     wenzelju 7029: 	my ($add_class, $id) = @_;
1.610     albertel 7030: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974     wenzelju 7031: 	$css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
                   7032:         $id = (' id="'.$id.'"') unless ($id eq '');
                   7033:         return  '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471     banghart 7034:     }
1.347     albertel 7035: 
                   7036:     sub end_data_table_row {
1.389     albertel 7037: 	return '</tr>'."\n";;
1.347     albertel 7038:     }
1.367     www      7039: 
1.421     albertel 7040:     sub start_data_table_empty_row {
1.707     bisitz   7041: #	$row_count[0]++;
1.421     albertel 7042: 	return  '<tr class="LC_empty_row" >'."\n";;
                   7043:     }
                   7044: 
                   7045:     sub end_data_table_empty_row {
                   7046: 	return '</tr>'."\n";;
                   7047:     }
                   7048: 
1.367     www      7049:     sub start_data_table_header_row {
1.389     albertel 7050: 	return  '<tr class="LC_header_row">'."\n";;
1.367     www      7051:     }
                   7052: 
                   7053:     sub end_data_table_header_row {
1.389     albertel 7054: 	return '</tr>'."\n";;
1.367     www      7055:     }
1.890     droeschl 7056: 
                   7057:     sub data_table_caption {
                   7058:         my $caption = shift;
                   7059:         return "<caption class=\"LC_caption\">$caption</caption>";
                   7060:     }
1.347     albertel 7061: }
                   7062: 
1.548     albertel 7063: =pod
                   7064: 
                   7065: =item * &inhibit_menu_check($arg)
                   7066: 
                   7067: Checks for a inhibitmenu state and generates output to preserve it
                   7068: 
                   7069: Inputs:         $arg - can be any of
                   7070:                      - undef - in which case the return value is a string 
                   7071:                                to add  into arguments list of a uri
                   7072:                      - 'input' - in which case the return value is a HTML
                   7073:                                  <form> <input> field of type hidden to
                   7074:                                  preserve the value
                   7075:                      - a url - in which case the return value is the url with
                   7076:                                the neccesary cgi args added to preserve the
                   7077:                                inhibitmenu state
                   7078:                      - a ref to a url - no return value, but the string is
                   7079:                                         updated to include the neccessary cgi
                   7080:                                         args to preserve the inhibitmenu state
                   7081: 
                   7082: =cut
                   7083: 
                   7084: sub inhibit_menu_check {
                   7085:     my ($arg) = @_;
                   7086:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   7087:     if ($arg eq 'input') {
                   7088: 	if ($env{'form.inhibitmenu'}) {
                   7089: 	    return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
                   7090: 	} else {
                   7091: 	    return
                   7092: 	}
                   7093:     }
                   7094:     if ($env{'form.inhibitmenu'}) {
                   7095: 	if (ref($arg)) {
                   7096: 	    $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   7097: 	} elsif ($arg eq '') {
                   7098: 	    $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
                   7099: 	} else {
                   7100: 	    $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   7101: 	}
                   7102:     }
                   7103:     if (!ref($arg)) {
                   7104: 	return $arg;
                   7105:     }
                   7106: }
                   7107: 
1.251     albertel 7108: ###############################################
1.182     matthew  7109: 
                   7110: =pod
                   7111: 
1.549     albertel 7112: =back
                   7113: 
                   7114: =head1 User Information Routines
                   7115: 
                   7116: =over 4
                   7117: 
1.405     albertel 7118: =item * &get_users_function()
1.182     matthew  7119: 
                   7120: Used by &bodytag to determine the current users primary role.
                   7121: Returns either 'student','coordinator','admin', or 'author'.
                   7122: 
                   7123: =cut
                   7124: 
                   7125: ###############################################
                   7126: sub get_users_function {
1.815     tempelho 7127:     my $function = 'norole';
1.818     tempelho 7128:     if ($env{'request.role'}=~/^(st)/) {
                   7129:         $function='student';
                   7130:     }
1.907     raeburn  7131:     if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182     matthew  7132:         $function='coordinator';
                   7133:     }
1.258     albertel 7134:     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182     matthew  7135:         $function='admin';
                   7136:     }
1.826     bisitz   7137:     if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025    raeburn  7138:         ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182     matthew  7139:         $function='author';
                   7140:     }
                   7141:     return $function;
1.54      www      7142: }
1.99      www      7143: 
                   7144: ###############################################
                   7145: 
1.233     raeburn  7146: =pod
                   7147: 
1.821     raeburn  7148: =item * &show_course()
                   7149: 
                   7150: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
                   7151: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
                   7152: 
                   7153: Inputs:
                   7154: None
                   7155: 
                   7156: Outputs:
                   7157: Scalar: 1 if 'Course' to be used, 0 otherwise.
                   7158: 
                   7159: =cut
                   7160: 
                   7161: ###############################################
                   7162: sub show_course {
                   7163:     my $course = !$env{'user.adv'};
                   7164:     if (!$env{'user.adv'}) {
                   7165:         foreach my $env (keys(%env)) {
                   7166:             next if ($env !~ m/^user\.priv\./);
                   7167:             if ($env !~ m/^user\.priv\.(?:st|cm)/) {
                   7168:                 $course = 0;
                   7169:                 last;
                   7170:             }
                   7171:         }
                   7172:     }
                   7173:     return $course;
                   7174: }
                   7175: 
                   7176: ###############################################
                   7177: 
                   7178: =pod
                   7179: 
1.542     raeburn  7180: =item * &check_user_status()
1.274     raeburn  7181: 
                   7182: Determines current status of supplied role for a
                   7183: specific user. Roles can be active, previous or future.
                   7184: 
                   7185: Inputs: 
                   7186: user's domain, user's username, course's domain,
1.375     raeburn  7187: course's number, optional section ID.
1.274     raeburn  7188: 
                   7189: Outputs:
                   7190: role status: active, previous or future. 
                   7191: 
                   7192: =cut
                   7193: 
                   7194: sub check_user_status {
1.412     raeburn  7195:     my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.982     raeburn  7196:     my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
                   7197:     my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname,'.',undef,$extra);
1.274     raeburn  7198:     my @uroles = keys %userinfo;
                   7199:     my $srchstr;
                   7200:     my $active_chk = 'none';
1.412     raeburn  7201:     my $now = time;
1.274     raeburn  7202:     if (@uroles > 0) {
1.908     raeburn  7203:         if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274     raeburn  7204:             $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
                   7205:         } else {
1.412     raeburn  7206:             $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
                   7207:         }
                   7208:         if (grep/^\Q$srchstr\E$/,@uroles) {
1.274     raeburn  7209:             my $role_end = 0;
                   7210:             my $role_start = 0;
                   7211:             $active_chk = 'active';
1.412     raeburn  7212:             if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
                   7213:                 $role_end = $1;
                   7214:                 if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
                   7215:                     $role_start = $1;
1.274     raeburn  7216:                 }
                   7217:             }
                   7218:             if ($role_start > 0) {
1.412     raeburn  7219:                 if ($now < $role_start) {
1.274     raeburn  7220:                     $active_chk = 'future';
                   7221:                 }
                   7222:             }
                   7223:             if ($role_end > 0) {
1.412     raeburn  7224:                 if ($now > $role_end) {
1.274     raeburn  7225:                     $active_chk = 'previous';
                   7226:                 }
                   7227:             }
                   7228:         }
                   7229:     }
                   7230:     return $active_chk;
                   7231: }
                   7232: 
                   7233: ###############################################
                   7234: 
                   7235: =pod
                   7236: 
1.405     albertel 7237: =item * &get_sections()
1.233     raeburn  7238: 
                   7239: Determines all the sections for a course including
                   7240: sections with students and sections containing other roles.
1.419     raeburn  7241: Incoming parameters: 
                   7242: 
                   7243: 1. domain
                   7244: 2. course number 
                   7245: 3. reference to array containing roles for which sections should 
                   7246: be gathered (optional).
                   7247: 4. reference to array containing status types for which sections 
                   7248: should be gathered (optional).
                   7249: 
                   7250: If the third argument is undefined, sections are gathered for any role. 
                   7251: If the fourth argument is undefined, sections are gathered for any status.
                   7252: Permissible values are 'active' or 'future' or 'previous'.
1.233     raeburn  7253:  
1.374     raeburn  7254: Returns section hash (keys are section IDs, values are
                   7255: number of users in each section), subject to the
1.419     raeburn  7256: optional roles filter, optional status filter 
1.233     raeburn  7257: 
                   7258: =cut
                   7259: 
                   7260: ###############################################
                   7261: sub get_sections {
1.419     raeburn  7262:     my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366     albertel 7263:     if (!defined($cdom) || !defined($cnum)) {
                   7264:         my $cid =  $env{'request.course.id'};
                   7265: 
                   7266: 	return if (!defined($cid));
                   7267: 
                   7268:         $cdom = $env{'course.'.$cid.'.domain'};
                   7269:         $cnum = $env{'course.'.$cid.'.num'};
                   7270:     }
                   7271: 
                   7272:     my %sectioncount;
1.419     raeburn  7273:     my $now = time;
1.240     albertel 7274: 
1.366     albertel 7275:     if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276     albertel 7276: 	my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240     albertel 7277: 	my $sec_index = &Apache::loncoursedata::CL_SECTION();
                   7278: 	my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419     raeburn  7279:         my $start_index = &Apache::loncoursedata::CL_START();
                   7280:         my $end_index = &Apache::loncoursedata::CL_END();
                   7281:         my $status;
1.366     albertel 7282: 	while (my ($student,$data) = each(%$classlist)) {
1.419     raeburn  7283: 	    my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
                   7284: 				                     $data->[$status_index],
                   7285:                                                      $data->[$start_index],
                   7286:                                                      $data->[$end_index]);
                   7287:             if ($stu_status eq 'Active') {
                   7288:                 $status = 'active';
                   7289:             } elsif ($end < $now) {
                   7290:                 $status = 'previous';
                   7291:             } elsif ($start > $now) {
                   7292:                 $status = 'future';
                   7293:             } 
                   7294: 	    if ($section ne '-1' && $section !~ /^\s*$/) {
                   7295:                 if ((!defined($possible_status)) || (($status ne '') && 
                   7296:                     (grep/^\Q$status\E$/,@{$possible_status}))) { 
                   7297: 		    $sectioncount{$section}++;
                   7298:                 }
1.240     albertel 7299: 	    }
                   7300: 	}
                   7301:     }
                   7302:     my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7303:     foreach my $user (sort(keys(%courseroles))) {
                   7304: 	if ($user !~ /^(\w{2})/) { next; }
                   7305: 	my ($role) = ($user =~ /^(\w{2})/);
                   7306: 	if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419     raeburn  7307: 	my ($section,$status);
1.240     albertel 7308: 	if ($role eq 'cr' &&
                   7309: 	    $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
                   7310: 	    $section=$1;
                   7311: 	}
                   7312: 	if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
                   7313: 	if (!defined($section) || $section eq '-1') { next; }
1.419     raeburn  7314:         my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
                   7315:         if ($end == -1 && $start == -1) {
                   7316:             next; #deleted role
                   7317:         }
                   7318:         if (!defined($possible_status)) { 
                   7319:             $sectioncount{$section}++;
                   7320:         } else {
                   7321:             if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
                   7322:                 $status = 'active';
                   7323:             } elsif ($end < $now) {
                   7324:                 $status = 'future';
                   7325:             } elsif ($start > $now) {
                   7326:                 $status = 'previous';
                   7327:             }
                   7328:             if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
                   7329:                 $sectioncount{$section}++;
                   7330:             }
                   7331:         }
1.233     raeburn  7332:     }
1.366     albertel 7333:     return %sectioncount;
1.233     raeburn  7334: }
                   7335: 
1.274     raeburn  7336: ###############################################
1.294     raeburn  7337: 
                   7338: =pod
1.405     albertel 7339: 
                   7340: =item * &get_course_users()
                   7341: 
1.275     raeburn  7342: Retrieves usernames:domains for users in the specified course
                   7343: with specific role(s), and access status. 
                   7344: 
                   7345: Incoming parameters:
1.277     albertel 7346: 1. course domain
                   7347: 2. course number
                   7348: 3. access status: users must have - either active, 
1.275     raeburn  7349: previous, future, or all.
1.277     albertel 7350: 4. reference to array of permissible roles
1.288     raeburn  7351: 5. reference to array of section restrictions (optional)
                   7352: 6. reference to results object (hash of hashes).
                   7353: 7. reference to optional userdata hash
1.609     raeburn  7354: 8. reference to optional statushash
1.630     raeburn  7355: 9. flag if privileged users (except those set to unhide in
                   7356:    course settings) should be excluded    
1.609     raeburn  7357: Keys of top level results hash are roles.
1.275     raeburn  7358: Keys of inner hashes are username:domain, with 
                   7359: values set to access type.
1.288     raeburn  7360: Optional userdata hash returns an array with arguments in the 
                   7361: same order as loncoursedata::get_classlist() for student data.
                   7362: 
1.609     raeburn  7363: Optional statushash returns
                   7364: 
1.288     raeburn  7365: Entries for end, start, section and status are blank because
                   7366: of the possibility of multiple values for non-student roles.
                   7367: 
1.275     raeburn  7368: =cut
1.405     albertel 7369: 
1.275     raeburn  7370: ###############################################
1.405     albertel 7371: 
1.275     raeburn  7372: sub get_course_users {
1.630     raeburn  7373:     my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288     raeburn  7374:     my %idx = ();
1.419     raeburn  7375:     my %seclists;
1.288     raeburn  7376: 
                   7377:     $idx{udom} = &Apache::loncoursedata::CL_SDOM();
                   7378:     $idx{uname} =  &Apache::loncoursedata::CL_SNAME();
                   7379:     $idx{end} = &Apache::loncoursedata::CL_END();
                   7380:     $idx{start} = &Apache::loncoursedata::CL_START();
                   7381:     $idx{id} = &Apache::loncoursedata::CL_ID();
                   7382:     $idx{section} = &Apache::loncoursedata::CL_SECTION();
                   7383:     $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
                   7384:     $idx{status} = &Apache::loncoursedata::CL_STATUS();
                   7385: 
1.290     albertel 7386:     if (grep(/^st$/,@{$roles})) {
1.276     albertel 7387:         my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278     raeburn  7388:         my $now = time;
1.277     albertel 7389:         foreach my $student (keys(%{$classlist})) {
1.288     raeburn  7390:             my $match = 0;
1.412     raeburn  7391:             my $secmatch = 0;
1.419     raeburn  7392:             my $section = $$classlist{$student}[$idx{section}];
1.609     raeburn  7393:             my $status = $$classlist{$student}[$idx{status}];
1.419     raeburn  7394:             if ($section eq '') {
                   7395:                 $section = 'none';
                   7396:             }
1.291     albertel 7397:             if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 7398:                 if (grep(/^all$/,@{$sections})) {
1.412     raeburn  7399:                     $secmatch = 1;
                   7400:                 } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420     albertel 7401:                     if (grep(/^none$/,@{$sections})) {
1.412     raeburn  7402:                         $secmatch = 1;
                   7403:                     }
                   7404:                 } else {  
1.419     raeburn  7405: 		    if (grep(/^\Q$section\E$/,@{$sections})) {
1.412     raeburn  7406: 		        $secmatch = 1;
                   7407:                     }
1.290     albertel 7408: 		}
1.412     raeburn  7409:                 if (!$secmatch) {
                   7410:                     next;
                   7411:                 }
1.419     raeburn  7412:             }
1.275     raeburn  7413:             if (defined($$types{'active'})) {
1.288     raeburn  7414:                 if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275     raeburn  7415:                     push(@{$$users{st}{$student}},'active');
1.288     raeburn  7416:                     $match = 1;
1.275     raeburn  7417:                 }
                   7418:             }
                   7419:             if (defined($$types{'previous'})) {
1.609     raeburn  7420:                 if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275     raeburn  7421:                     push(@{$$users{st}{$student}},'previous');
1.288     raeburn  7422:                     $match = 1;
1.275     raeburn  7423:                 }
                   7424:             }
                   7425:             if (defined($$types{'future'})) {
1.609     raeburn  7426:                 if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275     raeburn  7427:                     push(@{$$users{st}{$student}},'future');
1.288     raeburn  7428:                     $match = 1;
1.275     raeburn  7429:                 }
                   7430:             }
1.609     raeburn  7431:             if ($match) {
                   7432:                 push(@{$seclists{$student}},$section);
                   7433:                 if (ref($userdata) eq 'HASH') {
                   7434:                     $$userdata{$student} = $$classlist{$student};
                   7435:                 }
                   7436:                 if (ref($statushash) eq 'HASH') {
                   7437:                     $statushash->{$student}{'st'}{$section} = $status;
                   7438:                 }
1.288     raeburn  7439:             }
1.275     raeburn  7440:         }
                   7441:     }
1.412     raeburn  7442:     if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439     raeburn  7443:         my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7444:         my $now = time;
1.609     raeburn  7445:         my %displaystatus = ( previous => 'Expired',
                   7446:                               active   => 'Active',
                   7447:                               future   => 'Future',
                   7448:                             );
1.630     raeburn  7449:         my %nothide;
                   7450:         if ($hidepriv) {
                   7451:             my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
                   7452:             foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
                   7453:                 if ($user !~ /:/) {
                   7454:                     $nothide{join(':',split(/[\@]/,$user))}=1;
                   7455:                 } else {
                   7456:                     $nothide{$user} = 1;
                   7457:                 }
                   7458:             }
                   7459:         }
1.439     raeburn  7460:         foreach my $person (sort(keys(%coursepersonnel))) {
1.288     raeburn  7461:             my $match = 0;
1.412     raeburn  7462:             my $secmatch = 0;
1.439     raeburn  7463:             my $status;
1.412     raeburn  7464:             my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275     raeburn  7465:             $user =~ s/:$//;
1.439     raeburn  7466:             my ($end,$start) = split(/:/,$coursepersonnel{$person});
                   7467:             if ($end == -1 || $start == -1) {
                   7468:                 next;
                   7469:             }
                   7470:             if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
                   7471:                 (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412     raeburn  7472:                 my ($uname,$udom) = split(/:/,$user);
                   7473:                 if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 7474:                     if (grep(/^all$/,@{$sections})) {
1.412     raeburn  7475:                         $secmatch = 1;
                   7476:                     } elsif ($usec eq '') {
1.420     albertel 7477:                         if (grep(/^none$/,@{$sections})) {
1.412     raeburn  7478:                             $secmatch = 1;
                   7479:                         }
                   7480:                     } else {
                   7481:                         if (grep(/^\Q$usec\E$/,@{$sections})) {
                   7482:                             $secmatch = 1;
                   7483:                         }
                   7484:                     }
                   7485:                     if (!$secmatch) {
                   7486:                         next;
                   7487:                     }
1.288     raeburn  7488:                 }
1.419     raeburn  7489:                 if ($usec eq '') {
                   7490:                     $usec = 'none';
                   7491:                 }
1.275     raeburn  7492:                 if ($uname ne '' && $udom ne '') {
1.630     raeburn  7493:                     if ($hidepriv) {
                   7494:                         if ((&Apache::lonnet::privileged($uname,$udom)) &&
                   7495:                             (!$nothide{$uname.':'.$udom})) {
                   7496:                             next;
                   7497:                         }
                   7498:                     }
1.503     raeburn  7499:                     if ($end > 0 && $end < $now) {
1.439     raeburn  7500:                         $status = 'previous';
                   7501:                     } elsif ($start > $now) {
                   7502:                         $status = 'future';
                   7503:                     } else {
                   7504:                         $status = 'active';
                   7505:                     }
1.277     albertel 7506:                     foreach my $type (keys(%{$types})) { 
1.275     raeburn  7507:                         if ($status eq $type) {
1.420     albertel 7508:                             if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419     raeburn  7509:                                 push(@{$$users{$role}{$user}},$type);
                   7510:                             }
1.288     raeburn  7511:                             $match = 1;
                   7512:                         }
                   7513:                     }
1.419     raeburn  7514:                     if (($match) && (ref($userdata) eq 'HASH')) {
                   7515:                         if (!exists($$userdata{$uname.':'.$udom})) {
                   7516: 			    &get_user_info($udom,$uname,\%idx,$userdata);
                   7517:                         }
1.420     albertel 7518:                         if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419     raeburn  7519:                             push(@{$seclists{$uname.':'.$udom}},$usec);
                   7520:                         }
1.609     raeburn  7521:                         if (ref($statushash) eq 'HASH') {
                   7522:                             $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
                   7523:                         }
1.275     raeburn  7524:                     }
                   7525:                 }
                   7526:             }
                   7527:         }
1.290     albertel 7528:         if (grep(/^ow$/,@{$roles})) {
1.279     raeburn  7529:             if ((defined($cdom)) && (defined($cnum))) {
                   7530:                 my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
                   7531:                 if ( defined($csettings{'internal.courseowner'}) ) {
                   7532:                     my $owner = $csettings{'internal.courseowner'};
1.609     raeburn  7533:                     next if ($owner eq '');
                   7534:                     my ($ownername,$ownerdom);
                   7535:                     if ($owner =~ /^([^:]+):([^:]+)$/) {
                   7536:                         $ownername = $1;
                   7537:                         $ownerdom = $2;
                   7538:                     } else {
                   7539:                         $ownername = $owner;
                   7540:                         $ownerdom = $cdom;
                   7541:                         $owner = $ownername.':'.$ownerdom;
1.439     raeburn  7542:                     }
                   7543:                     @{$$users{'ow'}{$owner}} = 'any';
1.290     albertel 7544:                     if (defined($userdata) && 
1.609     raeburn  7545: 			!exists($$userdata{$owner})) {
                   7546: 			&get_user_info($ownerdom,$ownername,\%idx,$userdata);
                   7547:                         if (!grep(/^none$/,@{$seclists{$owner}})) {
                   7548:                             push(@{$seclists{$owner}},'none');
                   7549:                         }
                   7550:                         if (ref($statushash) eq 'HASH') {
                   7551:                             $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419     raeburn  7552:                         }
1.290     albertel 7553: 		    }
1.279     raeburn  7554:                 }
                   7555:             }
                   7556:         }
1.419     raeburn  7557:         foreach my $user (keys(%seclists)) {
                   7558:             @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
                   7559:             $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
                   7560:         }
1.275     raeburn  7561:     }
                   7562:     return;
                   7563: }
                   7564: 
1.288     raeburn  7565: sub get_user_info {
                   7566:     my ($udom,$uname,$idx,$userdata) = @_;
1.289     albertel 7567:     $$userdata{$uname.':'.$udom}[$$idx{fullname}] = 
                   7568: 	&plainname($uname,$udom,'lastname');
1.291     albertel 7569:     $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297     raeburn  7570:     $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609     raeburn  7571:     my %idhash =  &Apache::lonnet::idrget($udom,($uname));
                   7572:     $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname}; 
1.288     raeburn  7573:     return;
                   7574: }
1.275     raeburn  7575: 
1.472     raeburn  7576: ###############################################
                   7577: 
                   7578: =pod
                   7579: 
                   7580: =item * &get_user_quota()
                   7581: 
                   7582: Retrieves quota assigned for storage of portfolio files for a user  
                   7583: 
                   7584: Incoming parameters:
                   7585: 1. user's username
                   7586: 2. user's domain
                   7587: 
                   7588: Returns:
1.536     raeburn  7589: 1. Disk quota (in Mb) assigned to student.
                   7590: 2. (Optional) Type of setting: custom or default
                   7591:    (individually assigned or default for user's 
                   7592:    institutional status).
                   7593: 3. (Optional) - User's institutional status (e.g., faculty, staff
                   7594:    or student - types as defined in localenroll::inst_usertypes 
                   7595:    for user's domain, which determines default quota for user.
                   7596: 4. (Optional) - Default quota which would apply to the user.
1.472     raeburn  7597: 
                   7598: If a value has been stored in the user's environment, 
1.536     raeburn  7599: it will return that, otherwise it returns the maximal default
                   7600: defined for the user's instituional status(es) in the domain.
1.472     raeburn  7601: 
                   7602: =cut
                   7603: 
                   7604: ###############################################
                   7605: 
                   7606: 
                   7607: sub get_user_quota {
                   7608:     my ($uname,$udom) = @_;
1.536     raeburn  7609:     my ($quota,$quotatype,$settingstatus,$defquota);
1.472     raeburn  7610:     if (!defined($udom)) {
                   7611:         $udom = $env{'user.domain'};
                   7612:     }
                   7613:     if (!defined($uname)) {
                   7614:         $uname = $env{'user.name'};
                   7615:     }
                   7616:     if (($udom eq '' || $uname eq '') ||
                   7617:         ($udom eq 'public') && ($uname eq 'public')) {
                   7618:         $quota = 0;
1.536     raeburn  7619:         $quotatype = 'default';
                   7620:         $defquota = 0; 
1.472     raeburn  7621:     } else {
1.536     raeburn  7622:         my $inststatus;
1.472     raeburn  7623:         if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
                   7624:             $quota = $env{'environment.portfolioquota'};
1.536     raeburn  7625:             $inststatus = $env{'environment.inststatus'};
1.472     raeburn  7626:         } else {
1.536     raeburn  7627:             my %userenv = 
                   7628:                 &Apache::lonnet::get('environment',['portfolioquota',
                   7629:                                      'inststatus'],$udom,$uname);
1.472     raeburn  7630:             my ($tmp) = keys(%userenv);
                   7631:             if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   7632:                 $quota = $userenv{'portfolioquota'};
1.536     raeburn  7633:                 $inststatus = $userenv{'inststatus'};
1.472     raeburn  7634:             } else {
                   7635:                 undef(%userenv);
                   7636:             }
                   7637:         }
1.536     raeburn  7638:         ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472     raeburn  7639:         if ($quota eq '') {
1.536     raeburn  7640:             $quota = $defquota;
                   7641:             $quotatype = 'default';
                   7642:         } else {
                   7643:             $quotatype = 'custom';
1.472     raeburn  7644:         }
                   7645:     }
1.536     raeburn  7646:     if (wantarray) {
                   7647:         return ($quota,$quotatype,$settingstatus,$defquota);
                   7648:     } else {
                   7649:         return $quota;
                   7650:     }
1.472     raeburn  7651: }
                   7652: 
                   7653: ###############################################
                   7654: 
                   7655: =pod
                   7656: 
                   7657: =item * &default_quota()
                   7658: 
1.536     raeburn  7659: Retrieves default quota assigned for storage of user portfolio files,
                   7660: given an (optional) user's institutional status.
1.472     raeburn  7661: 
                   7662: Incoming parameters:
                   7663: 1. domain
1.536     raeburn  7664: 2. (Optional) institutional status(es).  This is a : separated list of 
                   7665:    status types (e.g., faculty, staff, student etc.)
                   7666:    which apply to the user for whom the default is being retrieved.
                   7667:    If the institutional status string in undefined, the domain
                   7668:    default quota will be returned. 
1.472     raeburn  7669: 
                   7670: Returns:
                   7671: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536     raeburn  7672: 2. (Optional) institutional type which determined the value of the
                   7673:    default quota.
1.472     raeburn  7674: 
                   7675: If a value has been stored in the domain's configuration db,
                   7676: it will return that, otherwise it returns 20 (for backwards 
                   7677: compatibility with domains which have not set up a configuration
                   7678: db file; the original statically defined portfolio quota was 20 Mb). 
                   7679: 
1.536     raeburn  7680: If the user's status includes multiple types (e.g., staff and student),
                   7681: the largest default quota which applies to the user determines the
                   7682: default quota returned.
                   7683: 
1.780     raeburn  7684: =back
                   7685: 
1.472     raeburn  7686: =cut
                   7687: 
                   7688: ###############################################
                   7689: 
                   7690: 
                   7691: sub default_quota {
1.536     raeburn  7692:     my ($udom,$inststatus) = @_;
                   7693:     my ($defquota,$settingstatus);
                   7694:     my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622     raeburn  7695:                                             ['quotas'],$udom);
                   7696:     if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536     raeburn  7697:         if ($inststatus ne '') {
1.765     raeburn  7698:             my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536     raeburn  7699:             foreach my $item (@statuses) {
1.711     raeburn  7700:                 if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7701:                     if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
                   7702:                         if ($defquota eq '') {
                   7703:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7704:                             $settingstatus = $item;
                   7705:                         } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
                   7706:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7707:                             $settingstatus = $item;
                   7708:                         }
                   7709:                     }
                   7710:                 } else {
                   7711:                     if ($quotahash{'quotas'}{$item} ne '') {
                   7712:                         if ($defquota eq '') {
                   7713:                             $defquota = $quotahash{'quotas'}{$item};
                   7714:                             $settingstatus = $item;
                   7715:                         } elsif ($quotahash{'quotas'}{$item} > $defquota) {
                   7716:                             $defquota = $quotahash{'quotas'}{$item};
                   7717:                             $settingstatus = $item;
                   7718:                         }
1.536     raeburn  7719:                     }
                   7720:                 }
                   7721:             }
                   7722:         }
                   7723:         if ($defquota eq '') {
1.711     raeburn  7724:             if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7725:                 $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
                   7726:             } else {
                   7727:                 $defquota = $quotahash{'quotas'}{'default'};
                   7728:             }
1.536     raeburn  7729:             $settingstatus = 'default';
                   7730:         }
                   7731:     } else {
                   7732:         $settingstatus = 'default';
                   7733:         $defquota = 20;
                   7734:     }
                   7735:     if (wantarray) {
                   7736:         return ($defquota,$settingstatus);
1.472     raeburn  7737:     } else {
1.536     raeburn  7738:         return $defquota;
1.472     raeburn  7739:     }
                   7740: }
                   7741: 
1.384     raeburn  7742: sub get_secgrprole_info {
                   7743:     my ($cdom,$cnum,$needroles,$type)  = @_;
                   7744:     my %sections_count = &get_sections($cdom,$cnum);
                   7745:     my @sections =  (sort {$a <=> $b} keys(%sections_count));
                   7746:     my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
                   7747:     my @groups = sort(keys(%curr_groups));
                   7748:     my $allroles = [];
                   7749:     my $rolehash;
                   7750:     my $accesshash = {
                   7751:                      active => 'Currently has access',
                   7752:                      future => 'Will have future access',
                   7753:                      previous => 'Previously had access',
                   7754:                   };
                   7755:     if ($needroles) {
                   7756:         $rolehash = {'all' => 'all'};
1.385     albertel 7757:         my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7758: 	if (&Apache::lonnet::error(%user_roles)) {
                   7759: 	    undef(%user_roles);
                   7760: 	}
                   7761:         foreach my $item (keys(%user_roles)) {
1.384     raeburn  7762:             my ($role)=split(/\:/,$item,2);
                   7763:             if ($role eq 'cr') { next; }
                   7764:             if ($role =~ /^cr/) {
                   7765:                 $$rolehash{$role} = (split('/',$role))[3];
                   7766:             } else {
                   7767:                 $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
                   7768:             }
                   7769:         }
                   7770:         foreach my $key (sort(keys(%{$rolehash}))) {
                   7771:             push(@{$allroles},$key);
                   7772:         }
                   7773:         push (@{$allroles},'st');
                   7774:         $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
                   7775:     }
                   7776:     return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
                   7777: }
                   7778: 
1.555     raeburn  7779: sub user_picker {
1.994     raeburn  7780:     my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555     raeburn  7781:     my $currdom = $dom;
                   7782:     my %curr_selected = (
                   7783:                         srchin => 'dom',
1.580     raeburn  7784:                         srchby => 'lastname',
1.555     raeburn  7785:                       );
                   7786:     my $srchterm;
1.625     raeburn  7787:     if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555     raeburn  7788:         if ($srch->{'srchby'} ne '') {
                   7789:             $curr_selected{'srchby'} = $srch->{'srchby'};
                   7790:         }
                   7791:         if ($srch->{'srchin'} ne '') {
                   7792:             $curr_selected{'srchin'} = $srch->{'srchin'};
                   7793:         }
                   7794:         if ($srch->{'srchtype'} ne '') {
                   7795:             $curr_selected{'srchtype'} = $srch->{'srchtype'};
                   7796:         }
                   7797:         if ($srch->{'srchdomain'} ne '') {
                   7798:             $currdom = $srch->{'srchdomain'};
                   7799:         }
                   7800:         $srchterm = $srch->{'srchterm'};
                   7801:     }
                   7802:     my %lt=&Apache::lonlocal::texthash(
1.573     raeburn  7803:                     'usr'       => 'Search criteria',
1.563     raeburn  7804:                     'doma'      => 'Domain/institution to search',
1.558     albertel 7805:                     'uname'     => 'username',
                   7806:                     'lastname'  => 'last name',
1.555     raeburn  7807:                     'lastfirst' => 'last name, first name',
1.558     albertel 7808:                     'crs'       => 'in this course',
1.576     raeburn  7809:                     'dom'       => 'in selected LON-CAPA domain', 
1.558     albertel 7810:                     'alc'       => 'all LON-CAPA',
1.573     raeburn  7811:                     'instd'     => 'in institutional directory for selected domain',
1.558     albertel 7812:                     'exact'     => 'is',
                   7813:                     'contains'  => 'contains',
1.569     raeburn  7814:                     'begins'    => 'begins with',
1.571     raeburn  7815:                     'youm'      => "You must include some text to search for.",
                   7816:                     'thte'      => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
                   7817:                     'thet'      => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
                   7818:                     'yomc'      => "You must choose a domain when using an institutional directory search.",
                   7819:                     'ymcd'      => "You must choose a domain when using a domain search.",
                   7820:                     'whus'      => "When using searching by last,first you must include a comma as separator between last name and first name.",
                   7821:                     'whse'      => "When searching by last,first you must include at least one character in the first name.",
                   7822:                      'thfo'     => "The following need to be corrected before the search can be run:",
1.555     raeburn  7823:                                        );
1.563     raeburn  7824:     my $domform = &select_dom_form($currdom,'srchdomain',1,1);
                   7825:     my $srchinsel = ' <select name="srchin">';
1.555     raeburn  7826: 
                   7827:     my @srchins = ('crs','dom','alc','instd');
                   7828: 
                   7829:     foreach my $option (@srchins) {
                   7830:         # FIXME 'alc' option unavailable until 
                   7831:         #       loncreateuser::print_user_query_page()
                   7832:         #       has been completed.
                   7833:         next if ($option eq 'alc');
1.880     raeburn  7834:         next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));  
1.555     raeburn  7835:         next if ($option eq 'crs' && !$env{'request.course.id'});
1.563     raeburn  7836:         if ($curr_selected{'srchin'} eq $option) {
                   7837:             $srchinsel .= ' 
                   7838:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7839:         } else {
                   7840:             $srchinsel .= '
                   7841:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7842:         }
1.555     raeburn  7843:     }
1.563     raeburn  7844:     $srchinsel .= "\n  </select>\n";
1.555     raeburn  7845: 
                   7846:     my $srchbysel =  ' <select name="srchby">';
1.580     raeburn  7847:     foreach my $option ('lastname','lastfirst','uname') {
1.555     raeburn  7848:         if ($curr_selected{'srchby'} eq $option) {
                   7849:             $srchbysel .= '
                   7850:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7851:         } else {
                   7852:             $srchbysel .= '
                   7853:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7854:          }
                   7855:     }
                   7856:     $srchbysel .= "\n  </select>\n";
                   7857: 
                   7858:     my $srchtypesel = ' <select name="srchtype">';
1.580     raeburn  7859:     foreach my $option ('begins','contains','exact') {
1.555     raeburn  7860:         if ($curr_selected{'srchtype'} eq $option) {
                   7861:             $srchtypesel .= '
                   7862:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7863:         } else {
                   7864:             $srchtypesel .= '
                   7865:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7866:         }
                   7867:     }
                   7868:     $srchtypesel .= "\n  </select>\n";
                   7869: 
1.558     albertel 7870:     my ($newuserscript,$new_user_create);
1.994     raeburn  7871:     my $context_dom = $env{'request.role.domain'};
                   7872:     if ($context eq 'requestcrs') {
                   7873:         if ($env{'form.coursedom'} ne '') { 
                   7874:             $context_dom = $env{'form.coursedom'};
                   7875:         }
                   7876:     }
1.556     raeburn  7877:     if ($forcenewuser) {
1.576     raeburn  7878:         if (ref($srch) eq 'HASH') {
1.994     raeburn  7879:             if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627     raeburn  7880:                 if ($cancreate) {
                   7881:                     $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>';
                   7882:                 } else {
1.799     bisitz   7883:                     my $helplink = 'javascript:helpMenu('."'display'".')';
1.627     raeburn  7884:                     my %usertypetext = (
                   7885:                         official   => 'institutional',
                   7886:                         unofficial => 'non-institutional',
                   7887:                     );
1.799     bisitz   7888:                     $new_user_create = '<p class="LC_warning">'
                   7889:                                       .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
                   7890:                                       .' '
                   7891:                                       .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
                   7892:                                           ,'<a href="'.$helplink.'">','</a>')
                   7893:                                       .'</p><br />';
1.627     raeburn  7894:                 }
1.576     raeburn  7895:             }
                   7896:         }
                   7897: 
1.556     raeburn  7898:         $newuserscript = <<"ENDSCRIPT";
                   7899: 
1.570     raeburn  7900: function setSearch(createnew,callingForm) {
1.556     raeburn  7901:     if (createnew == 1) {
1.570     raeburn  7902:         for (var i=0; i<callingForm.srchby.length; i++) {
                   7903:             if (callingForm.srchby.options[i].value == 'uname') {
                   7904:                 callingForm.srchby.selectedIndex = i;
1.556     raeburn  7905:             }
                   7906:         }
1.570     raeburn  7907:         for (var i=0; i<callingForm.srchin.length; i++) {
                   7908:             if ( callingForm.srchin.options[i].value == 'dom') {
                   7909: 		callingForm.srchin.selectedIndex = i;
1.556     raeburn  7910:             }
                   7911:         }
1.570     raeburn  7912:         for (var i=0; i<callingForm.srchtype.length; i++) {
                   7913:             if (callingForm.srchtype.options[i].value == 'exact') {
                   7914:                 callingForm.srchtype.selectedIndex = i;
1.556     raeburn  7915:             }
                   7916:         }
1.570     raeburn  7917:         for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994     raeburn  7918:             if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570     raeburn  7919:                 callingForm.srchdomain.selectedIndex = i;
1.556     raeburn  7920:             }
                   7921:         }
                   7922:     }
                   7923: }
                   7924: ENDSCRIPT
1.558     albertel 7925: 
1.556     raeburn  7926:     }
                   7927: 
1.555     raeburn  7928:     my $output = <<"END_BLOCK";
1.556     raeburn  7929: <script type="text/javascript">
1.824     bisitz   7930: // <![CDATA[
1.570     raeburn  7931: function validateEntry(callingForm) {
1.558     albertel 7932: 
1.556     raeburn  7933:     var checkok = 1;
1.558     albertel 7934:     var srchin;
1.570     raeburn  7935:     for (var i=0; i<callingForm.srchin.length; i++) {
                   7936: 	if ( callingForm.srchin[i].checked ) {
                   7937: 	    srchin = callingForm.srchin[i].value;
1.558     albertel 7938: 	}
                   7939:     }
                   7940: 
1.570     raeburn  7941:     var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
                   7942:     var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
                   7943:     var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
                   7944:     var srchterm =  callingForm.srchterm.value;
                   7945:     var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556     raeburn  7946:     var msg = "";
                   7947: 
                   7948:     if (srchterm == "") {
                   7949:         checkok = 0;
1.571     raeburn  7950:         msg += "$lt{'youm'}\\n";
1.556     raeburn  7951:     }
                   7952: 
1.569     raeburn  7953:     if (srchtype== 'begins') {
                   7954:         if (srchterm.length < 2) {
                   7955:             checkok = 0;
1.571     raeburn  7956:             msg += "$lt{'thte'}\\n";
1.569     raeburn  7957:         }
                   7958:     }
                   7959: 
1.556     raeburn  7960:     if (srchtype== 'contains') {
                   7961:         if (srchterm.length < 3) {
                   7962:             checkok = 0;
1.571     raeburn  7963:             msg += "$lt{'thet'}\\n";
1.556     raeburn  7964:         }
                   7965:     }
                   7966:     if (srchin == 'instd') {
                   7967:         if (srchdomain == '') {
                   7968:             checkok = 0;
1.571     raeburn  7969:             msg += "$lt{'yomc'}\\n";
1.556     raeburn  7970:         }
                   7971:     }
                   7972:     if (srchin == 'dom') {
                   7973:         if (srchdomain == '') {
                   7974:             checkok = 0;
1.571     raeburn  7975:             msg += "$lt{'ymcd'}\\n";
1.556     raeburn  7976:         }
                   7977:     }
                   7978:     if (srchby == 'lastfirst') {
                   7979:         if (srchterm.indexOf(",") == -1) {
                   7980:             checkok = 0;
1.571     raeburn  7981:             msg += "$lt{'whus'}\\n";
1.556     raeburn  7982:         }
                   7983:         if (srchterm.indexOf(",") == srchterm.length -1) {
                   7984:             checkok = 0;
1.571     raeburn  7985:             msg += "$lt{'whse'}\\n";
1.556     raeburn  7986:         }
                   7987:     }
                   7988:     if (checkok == 0) {
1.571     raeburn  7989:         alert("$lt{'thfo'}\\n"+msg);
1.556     raeburn  7990:         return;
                   7991:     }
                   7992:     if (checkok == 1) {
1.570     raeburn  7993:         callingForm.submit();
1.556     raeburn  7994:     }
                   7995: }
                   7996: 
                   7997: $newuserscript
                   7998: 
1.824     bisitz   7999: // ]]>
1.556     raeburn  8000: </script>
1.558     albertel 8001: 
                   8002: $new_user_create
                   8003: 
1.555     raeburn  8004: END_BLOCK
1.558     albertel 8005: 
1.876     raeburn  8006:     $output .= &Apache::lonhtmlcommon::start_pick_box().
                   8007:                &Apache::lonhtmlcommon::row_title($lt{'doma'}).
                   8008:                $domform.
                   8009:                &Apache::lonhtmlcommon::row_closure().
                   8010:                &Apache::lonhtmlcommon::row_title($lt{'usr'}).
                   8011:                $srchbysel.
                   8012:                $srchtypesel. 
                   8013:                '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
                   8014:                $srchinsel.
                   8015:                &Apache::lonhtmlcommon::row_closure(1). 
                   8016:                &Apache::lonhtmlcommon::end_pick_box().
                   8017:                '<br />';
1.555     raeburn  8018:     return $output;
                   8019: }
                   8020: 
1.612     raeburn  8021: sub user_rule_check {
1.615     raeburn  8022:     my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612     raeburn  8023:     my $response;
                   8024:     if (ref($usershash) eq 'HASH') {
                   8025:         foreach my $user (keys(%{$usershash})) {
                   8026:             my ($uname,$udom) = split(/:/,$user);
                   8027:             next if ($udom eq '' || $uname eq '');
1.615     raeburn  8028:             my ($id,$newuser);
1.612     raeburn  8029:             if (ref($usershash->{$user}) eq 'HASH') {
1.615     raeburn  8030:                 $newuser = $usershash->{$user}->{'newuser'};
1.612     raeburn  8031:                 $id = $usershash->{$user}->{'id'};
                   8032:             }
                   8033:             my $inst_response;
                   8034:             if (ref($checks) eq 'HASH') {
                   8035:                 if (defined($checks->{'username'})) {
1.615     raeburn  8036:                     ($inst_response,%{$inst_results->{$user}}) = 
1.612     raeburn  8037:                         &Apache::lonnet::get_instuser($udom,$uname);
                   8038:                 } elsif (defined($checks->{'id'})) {
1.615     raeburn  8039:                     ($inst_response,%{$inst_results->{$user}}) =
1.612     raeburn  8040:                         &Apache::lonnet::get_instuser($udom,undef,$id);
                   8041:                 }
1.615     raeburn  8042:             } else {
                   8043:                 ($inst_response,%{$inst_results->{$user}}) =
                   8044:                     &Apache::lonnet::get_instuser($udom,$uname);
                   8045:                 return;
1.612     raeburn  8046:             }
1.615     raeburn  8047:             if (!$got_rules->{$udom}) {
1.612     raeburn  8048:                 my %domconfig = &Apache::lonnet::get_dom('configuration',
                   8049:                                                   ['usercreation'],$udom);
                   8050:                 if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615     raeburn  8051:                     foreach my $item ('username','id') {
1.612     raeburn  8052:                         if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
                   8053:                             $$curr_rules{$udom}{$item} = 
                   8054:                                 $domconfig{'usercreation'}{$item.'_rule'};
1.585     raeburn  8055:                         }
                   8056:                     }
                   8057:                 }
1.615     raeburn  8058:                 $got_rules->{$udom} = 1;  
1.585     raeburn  8059:             }
1.612     raeburn  8060:             foreach my $item (keys(%{$checks})) {
                   8061:                 if (ref($$curr_rules{$udom}) eq 'HASH') {
                   8062:                     if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
                   8063:                         if (@{$$curr_rules{$udom}{$item}} > 0) {
                   8064:                             my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
                   8065:                             foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
                   8066:                                 if ($rule_check{$rule}) {
                   8067:                                     $$rulematch{$user}{$item} = $rule;
                   8068:                                     if ($inst_response eq 'ok') {
1.615     raeburn  8069:                                         if (ref($inst_results) eq 'HASH') {
                   8070:                                             if (ref($inst_results->{$user}) eq 'HASH') {
                   8071:                                                 if (keys(%{$inst_results->{$user}}) == 0) {
                   8072:                                                     $$alerts{$item}{$udom}{$uname} = 1;
                   8073:                                                 }
1.612     raeburn  8074:                                             }
                   8075:                                         }
1.615     raeburn  8076:                                     }
                   8077:                                     last;
1.585     raeburn  8078:                                 }
                   8079:                             }
                   8080:                         }
                   8081:                     }
                   8082:                 }
                   8083:             }
                   8084:         }
                   8085:     }
1.612     raeburn  8086:     return;
                   8087: }
                   8088: 
                   8089: sub user_rule_formats {
                   8090:     my ($domain,$domdesc,$curr_rules,$check) = @_;
                   8091:     my %text = ( 
                   8092:                  'username' => 'Usernames',
                   8093:                  'id'       => 'IDs',
                   8094:                );
                   8095:     my $output;
                   8096:     my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
                   8097:     if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
                   8098:         if (@{$ruleorder} > 0) {
                   8099:             $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>';
                   8100:             foreach my $rule (@{$ruleorder}) {
                   8101:                 if (ref($curr_rules) eq 'ARRAY') {
                   8102:                     if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
                   8103:                         if (ref($rules->{$rule}) eq 'HASH') {
                   8104:                             $output .= '<li>'.$rules->{$rule}{'name'}.': '.
                   8105:                                         $rules->{$rule}{'desc'}.'</li>';
                   8106:                         }
                   8107:                     }
                   8108:                 }
                   8109:             }
                   8110:             $output .= '</ul>';
                   8111:         }
                   8112:     }
                   8113:     return $output;
                   8114: }
                   8115: 
                   8116: sub instrule_disallow_msg {
1.615     raeburn  8117:     my ($checkitem,$domdesc,$count,$mode) = @_;
1.612     raeburn  8118:     my $response;
                   8119:     my %text = (
                   8120:                   item   => 'username',
                   8121:                   items  => 'usernames',
                   8122:                   match  => 'matches',
                   8123:                   do     => 'does',
                   8124:                   action => 'a username',
                   8125:                   one    => 'one',
                   8126:                );
                   8127:     if ($count > 1) {
                   8128:         $text{'item'} = 'usernames';
                   8129:         $text{'match'} ='match';
                   8130:         $text{'do'} = 'do';
                   8131:         $text{'action'} = 'usernames',
                   8132:         $text{'one'} = 'ones';
                   8133:     }
                   8134:     if ($checkitem eq 'id') {
                   8135:         $text{'items'} = 'IDs';
                   8136:         $text{'item'} = 'ID';
                   8137:         $text{'action'} = 'an ID';
1.615     raeburn  8138:         if ($count > 1) {
                   8139:             $text{'item'} = 'IDs';
                   8140:             $text{'action'} = 'IDs';
                   8141:         }
1.612     raeburn  8142:     }
1.674     bisitz   8143:     $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  8144:     if ($mode eq 'upload') {
                   8145:         if ($checkitem eq 'username') {
                   8146:             $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'}.");
                   8147:         } elsif ($checkitem eq 'id') {
1.674     bisitz   8148:             $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  8149:         }
1.669     raeburn  8150:     } elsif ($mode eq 'selfcreate') {
                   8151:         if ($checkitem eq 'id') {
                   8152:             $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.");
                   8153:         }
1.615     raeburn  8154:     } else {
                   8155:         if ($checkitem eq 'username') {
                   8156:             $response .= &mt("You must choose $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
                   8157:         } elsif ($checkitem eq 'id') {
                   8158:             $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.");
                   8159:         }
1.612     raeburn  8160:     }
                   8161:     return $response;
1.585     raeburn  8162: }
                   8163: 
1.624     raeburn  8164: sub personal_data_fieldtitles {
                   8165:     my %fieldtitles = &Apache::lonlocal::texthash (
                   8166:                         id => 'Student/Employee ID',
                   8167:                         permanentemail => 'E-mail address',
                   8168:                         lastname => 'Last Name',
                   8169:                         firstname => 'First Name',
                   8170:                         middlename => 'Middle Name',
                   8171:                         generation => 'Generation',
                   8172:                         gen => 'Generation',
1.765     raeburn  8173:                         inststatus => 'Affiliation',
1.624     raeburn  8174:                    );
                   8175:     return %fieldtitles;
                   8176: }
                   8177: 
1.642     raeburn  8178: sub sorted_inst_types {
                   8179:     my ($dom) = @_;
                   8180:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
                   8181:     my $othertitle = &mt('All users');
                   8182:     if ($env{'request.course.id'}) {
1.668     raeburn  8183:         $othertitle  = &mt('Any users');
1.642     raeburn  8184:     }
                   8185:     my @types;
                   8186:     if (ref($order) eq 'ARRAY') {
                   8187:         @types = @{$order};
                   8188:     }
                   8189:     if (@types == 0) {
                   8190:         if (ref($usertypes) eq 'HASH') {
                   8191:             @types = sort(keys(%{$usertypes}));
                   8192:         }
                   8193:     }
                   8194:     if (keys(%{$usertypes}) > 0) {
                   8195:         $othertitle = &mt('Other users');
                   8196:     }
                   8197:     return ($othertitle,$usertypes,\@types);
                   8198: }
                   8199: 
1.645     raeburn  8200: sub get_institutional_codes {
                   8201:     my ($settings,$allcourses,$LC_code) = @_;
                   8202: # Get complete list of course sections to update
                   8203:     my @currsections = ();
                   8204:     my @currxlists = ();
                   8205:     my $coursecode = $$settings{'internal.coursecode'};
                   8206: 
                   8207:     if ($$settings{'internal.sectionnums'} ne '') {
                   8208:         @currsections = split(/,/,$$settings{'internal.sectionnums'});
                   8209:     }
                   8210: 
                   8211:     if ($$settings{'internal.crosslistings'} ne '') {
                   8212:         @currxlists = split(/,/,$$settings{'internal.crosslistings'});
                   8213:     }
                   8214: 
                   8215:     if (@currxlists > 0) {
                   8216:         foreach (@currxlists) {
                   8217:             if (m/^([^:]+):(\w*)$/) {
                   8218:                 unless (grep/^$1$/,@{$allcourses}) {
                   8219:                     push @{$allcourses},$1;
                   8220:                     $$LC_code{$1} = $2;
                   8221:                 }
                   8222:             }
                   8223:         }
                   8224:     }
                   8225:  
                   8226:     if (@currsections > 0) {
                   8227:         foreach (@currsections) {
                   8228:             if (m/^(\w+):(\w*)$/) {
                   8229:                 my $sec = $coursecode.$1;
                   8230:                 my $lc_sec = $2;
                   8231:                 unless (grep/^$sec$/,@{$allcourses}) {
                   8232:                     push @{$allcourses},$sec;
                   8233:                     $$LC_code{$sec} = $lc_sec;
                   8234:                 }
                   8235:             }
                   8236:         }
                   8237:     }
                   8238:     return;
                   8239: }
                   8240: 
1.971     raeburn  8241: sub get_standard_codeitems {
                   8242:     return ('Year','Semester','Department','Number','Section');
                   8243: }
                   8244: 
1.112     bowersj2 8245: =pod
                   8246: 
1.780     raeburn  8247: =head1 Slot Helpers
                   8248: 
                   8249: =over 4
                   8250: 
                   8251: =item * sorted_slots()
                   8252: 
                   8253: Sorts an array of slot names in order of slot start time (earliest first). 
                   8254: 
                   8255: Inputs:
                   8256: 
                   8257: =over 4
                   8258: 
                   8259: slotsarr  - Reference to array of unsorted slot names.
                   8260: 
                   8261: slots     - Reference to hash of hash, where outer hash keys are slot names.
                   8262: 
1.549     albertel 8263: =back
                   8264: 
1.780     raeburn  8265: Returns:
                   8266: 
                   8267: =over 4
                   8268: 
                   8269: sorted   - An array of slot names sorted by the start time of the slot.
                   8270: 
                   8271: =back
                   8272: 
                   8273: =back
                   8274: 
                   8275: =cut
                   8276: 
                   8277: 
                   8278: sub sorted_slots {
                   8279:     my ($slotsarr,$slots) = @_;
                   8280:     my @sorted;
                   8281:     if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
                   8282:         @sorted =
                   8283:             sort {
                   8284:                      if (ref($slots->{$a}) && ref($slots->{$b})) {
                   8285:                          return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
                   8286:                      }
                   8287:                      if (ref($slots->{$a})) { return -1;}
                   8288:                      if (ref($slots->{$b})) { return 1;}
                   8289:                      return 0;
                   8290:                  } @{$slotsarr};
                   8291:     }
                   8292:     return @sorted;
                   8293: }
                   8294: 
                   8295: 
                   8296: =pod
                   8297: 
1.549     albertel 8298: =head1 HTTP Helpers
                   8299: 
                   8300: =over 4
                   8301: 
1.648     raeburn  8302: =item * &get_unprocessed_cgi($query,$possible_names)
1.112     bowersj2 8303: 
1.258     albertel 8304: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112     bowersj2 8305: $query.  The parameters listed in $possible_names (an array reference),
1.258     albertel 8306: will be set in $env{'form.name'} if they do not already exist.
1.112     bowersj2 8307: 
                   8308: Typically called with $ENV{'QUERY_STRING'} as the first parameter.  
                   8309: $possible_names is an ref to an array of form element names.  As an example:
                   8310: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258     albertel 8311: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112     bowersj2 8312: 
                   8313: =cut
1.1       albertel 8314: 
1.6       albertel 8315: sub get_unprocessed_cgi {
1.25      albertel 8316:   my ($query,$possible_names)= @_;
1.26      matthew  8317:   # $Apache::lonxml::debug=1;
1.356     albertel 8318:   foreach my $pair (split(/&/,$query)) {
                   8319:     my ($name, $value) = split(/=/,$pair);
1.369     www      8320:     $name = &unescape($name);
1.25      albertel 8321:     if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
                   8322:       $value =~ tr/+/ /;
                   8323:       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258     albertel 8324:       unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25      albertel 8325:     }
1.16      harris41 8326:   }
1.6       albertel 8327: }
                   8328: 
1.112     bowersj2 8329: =pod
                   8330: 
1.648     raeburn  8331: =item * &cacheheader() 
1.112     bowersj2 8332: 
                   8333: returns cache-controlling header code
                   8334: 
                   8335: =cut
                   8336: 
1.7       albertel 8337: sub cacheheader {
1.258     albertel 8338:     unless ($env{'request.method'} eq 'GET') { return ''; }
1.216     albertel 8339:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
                   8340:     my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7       albertel 8341:                 <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
                   8342:                 <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216     albertel 8343:     return $output;
1.7       albertel 8344: }
                   8345: 
1.112     bowersj2 8346: =pod
                   8347: 
1.648     raeburn  8348: =item * &no_cache($r) 
1.112     bowersj2 8349: 
                   8350: specifies header code to not have cache
                   8351: 
                   8352: =cut
                   8353: 
1.9       albertel 8354: sub no_cache {
1.216     albertel 8355:     my ($r) = @_;
                   8356:     if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258     albertel 8357: 	$env{'request.method'} ne 'GET') { return ''; }
1.216     albertel 8358:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
                   8359:     $r->no_cache(1);
                   8360:     $r->header_out("Expires" => $date);
                   8361:     $r->header_out("Pragma" => "no-cache");
1.123     www      8362: }
                   8363: 
                   8364: sub content_type {
1.181     albertel 8365:     my ($r,$type,$charset) = @_;
1.299     foxr     8366:     if ($r) {
                   8367: 	#  Note that printout.pl calls this with undef for $r.
                   8368: 	&no_cache($r);
                   8369:     }
1.258     albertel 8370:     if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181     albertel 8371:     unless ($charset) {
                   8372: 	$charset=&Apache::lonlocal::current_encoding;
                   8373:     }
                   8374:     if ($charset) { $type.='; charset='.$charset; }
                   8375:     if ($r) {
                   8376: 	$r->content_type($type);
                   8377:     } else {
                   8378: 	print("Content-type: $type\n\n");
                   8379:     }
1.9       albertel 8380: }
1.25      albertel 8381: 
1.112     bowersj2 8382: =pod
                   8383: 
1.648     raeburn  8384: =item * &add_to_env($name,$value) 
1.112     bowersj2 8385: 
1.258     albertel 8386: adds $name to the %env hash with value
1.112     bowersj2 8387: $value, if $name already exists, the entry is converted to an array
                   8388: reference and $value is added to the array.
                   8389: 
                   8390: =cut
                   8391: 
1.25      albertel 8392: sub add_to_env {
                   8393:   my ($name,$value)=@_;
1.258     albertel 8394:   if (defined($env{$name})) {
                   8395:     if (ref($env{$name})) {
1.25      albertel 8396:       #already have multiple values
1.258     albertel 8397:       push(@{ $env{$name} },$value);
1.25      albertel 8398:     } else {
                   8399:       #first time seeing multiple values, convert hash entry to an arrayref
1.258     albertel 8400:       my $first=$env{$name};
                   8401:       undef($env{$name});
                   8402:       push(@{ $env{$name} },$first,$value);
1.25      albertel 8403:     }
                   8404:   } else {
1.258     albertel 8405:     $env{$name}=$value;
1.25      albertel 8406:   }
1.31      albertel 8407: }
1.149     albertel 8408: 
                   8409: =pod
                   8410: 
1.648     raeburn  8411: =item * &get_env_multiple($name) 
1.149     albertel 8412: 
1.258     albertel 8413: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149     albertel 8414: values may be defined and end up as an array ref.
                   8415: 
                   8416: returns an array of values
                   8417: 
                   8418: =cut
                   8419: 
                   8420: sub get_env_multiple {
                   8421:     my ($name) = @_;
                   8422:     my @values;
1.258     albertel 8423:     if (defined($env{$name})) {
1.149     albertel 8424:         # exists is it an array
1.258     albertel 8425:         if (ref($env{$name})) {
                   8426:             @values=@{ $env{$name} };
1.149     albertel 8427:         } else {
1.258     albertel 8428:             $values[0]=$env{$name};
1.149     albertel 8429:         }
                   8430:     }
                   8431:     return(@values);
                   8432: }
                   8433: 
1.660     raeburn  8434: sub ask_for_embedded_content {
                   8435:     my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.987     raeburn  8436:     my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges);
1.660     raeburn  8437:     my $num = 0;
1.987     raeburn  8438:     my $numremref = 0;
                   8439:     my $numinvalid = 0;
                   8440:     my $numpathchg = 0;
                   8441:     my $numexisting = 0;
                   8442:     my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath);
1.984     raeburn  8443:     if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
                   8444:         my $current_path='/';
                   8445:         if ($env{'form.currentpath'}) {
                   8446:             $current_path = $env{'form.currentpath'};
                   8447:         }
                   8448:         if ($actionurl eq '/adm/coursegrp_portfolio') {
                   8449:             $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   8450:             $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
                   8451:             $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
                   8452:         } else {
                   8453:             $udom = $env{'user.domain'};
                   8454:             $uname = $env{'user.name'};
                   8455:             $url = '/userfiles/portfolio';
                   8456:         }
1.987     raeburn  8457:         $toplevel = $url.'/';
1.984     raeburn  8458:         $url .= $current_path;
                   8459:         $getpropath = 1;
1.987     raeburn  8460:     } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
                   8461:              ($actionurl eq '/adm/imsimport')) { 
1.1022    www      8462:         my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026    raeburn  8463:         $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987     raeburn  8464:         $toplevel = $url;
1.984     raeburn  8465:         if ($rest ne '') {
1.987     raeburn  8466:             $url .= $rest;
                   8467:         }
                   8468:     } elsif ($actionurl eq '/adm/coursedocs') {
                   8469:         if (ref($args) eq 'HASH') {
                   8470:            $url = $args->{'docs_url'};
                   8471:            $toplevel = $url;
                   8472:         }
                   8473:     }
                   8474:     my $now = time();
                   8475:     foreach my $embed_file (keys(%{$allfiles})) {
                   8476:         my $absolutepath;
                   8477:         if ($embed_file =~ m{^\w+://}) {
                   8478:             $newfiles{$embed_file} = 1;
                   8479:             $mapping{$embed_file} = $embed_file;
                   8480:         } else {
                   8481:             if ($embed_file =~ m{^/}) {
                   8482:                 $absolutepath = $embed_file;
                   8483:                 $embed_file =~ s{^(/+)}{};
                   8484:             }
                   8485:             if ($embed_file =~ m{/}) {
                   8486:                 my ($path,$fname) = ($embed_file =~ m{^(.+)/([^/]*)$});
                   8487:                 $path = &check_for_traversal($path,$url,$toplevel);
                   8488:                 my $item = $fname;
                   8489:                 if ($path ne '') {
                   8490:                     $item = $path.'/'.$fname;
                   8491:                     $subdependencies{$path}{$fname} = 1;
                   8492:                 } else {
                   8493:                     $dependencies{$item} = 1;
                   8494:                 }
                   8495:                 if ($absolutepath) {
                   8496:                     $mapping{$item} = $absolutepath;
                   8497:                 } else {
                   8498:                     $mapping{$item} = $embed_file;
                   8499:                 }
                   8500:             } else {
                   8501:                 $dependencies{$embed_file} = 1;
                   8502:                 if ($absolutepath) {
                   8503:                     $mapping{$embed_file} = $absolutepath;
                   8504:                 } else {
                   8505:                     $mapping{$embed_file} = $embed_file;
                   8506:                 }
                   8507:             }
1.984     raeburn  8508:         }
                   8509:     }
                   8510:     foreach my $path (keys(%subdependencies)) {
                   8511:         my %currsubfile;
                   8512:         if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) { 
1.1021    raeburn  8513:             my ($sublistref,$listerror) =
                   8514:                 &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
                   8515:             if (ref($sublistref) eq 'ARRAY') {
                   8516:                 foreach my $line (@{$sublistref}) {
                   8517:                     my ($file_name,$rest) = split(/\&/,$line,2);
                   8518:                     $currsubfile{$file_name} = 1;
                   8519:                 }
1.984     raeburn  8520:             }
1.987     raeburn  8521:         } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984     raeburn  8522:             if (opendir(my $dir,$url.'/'.$path)) {
                   8523:                 my @subdir_list = grep(!/^\./,readdir($dir));
                   8524:                 map {$currsubfile{$_} = 1;} @subdir_list;
                   8525:             }
                   8526:         }
                   8527:         foreach my $file (keys(%{$subdependencies{$path}})) {
1.987     raeburn  8528:             if ($currsubfile{$file}) {
                   8529:                 my $item = $path.'/'.$file;
                   8530:                 unless ($mapping{$item} eq $item) {
                   8531:                     $pathchanges{$item} = 1;
                   8532:                 }
                   8533:                 $existing{$item} = 1;
                   8534:                 $numexisting ++;
                   8535:             } else {
                   8536:                 $newfiles{$path.'/'.$file} = 1;
1.984     raeburn  8537:             }
                   8538:         }
                   8539:     }
1.987     raeburn  8540:     my %currfile;
1.984     raeburn  8541:     if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021    raeburn  8542:         my ($dirlistref,$listerror) =
                   8543:             &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
                   8544:         if (ref($dirlistref) eq 'ARRAY') {
                   8545:             foreach my $line (@{$dirlistref}) {
                   8546:                 my ($file_name,$rest) = split(/\&/,$line,2);
                   8547:                 $currfile{$file_name} = 1;
                   8548:             }
1.984     raeburn  8549:         }
1.987     raeburn  8550:     } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984     raeburn  8551:         if (opendir(my $dir,$url)) {
1.987     raeburn  8552:             my @dir_list = grep(!/^\./,readdir($dir));
1.984     raeburn  8553:             map {$currfile{$_} = 1;} @dir_list;
                   8554:         }
                   8555:     }
                   8556:     foreach my $file (keys(%dependencies)) {
1.987     raeburn  8557:         if ($currfile{$file}) {
                   8558:             unless ($mapping{$file} eq $file) {
                   8559:                 $pathchanges{$file} = 1;
                   8560:             }
                   8561:             $existing{$file} = 1;
                   8562:             $numexisting ++;
                   8563:         } else {
1.984     raeburn  8564:             $newfiles{$file} = 1;
                   8565:         }
                   8566:     }
                   8567:     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.660     raeburn  8568:         $upload_output .= &start_data_table_row().
1.987     raeburn  8569:                           '<td><span class="LC_filename">'.$embed_file.'</span>';
                   8570:         unless ($mapping{$embed_file} eq $embed_file) {
                   8571:             $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.&mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
                   8572:         }
                   8573:         $upload_output .= '</td><td>';
1.660     raeburn  8574:         if ($args->{'ignore_remote_references'}
                   8575:             && $embed_file =~ m{^\w+://}) {
                   8576:             $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
1.987     raeburn  8577:             $numremref++;
1.660     raeburn  8578:         } elsif ($args->{'error_on_invalid_names'}
                   8579:             && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
                   8580: 
1.987     raeburn  8581:             $upload_output.='<span class="LC_warning">'.&mt('Invalid characters').'</span>';
                   8582:             $numinvalid++;
1.660     raeburn  8583:         } else {
1.987     raeburn  8584:             $upload_output .= &embedded_file_element('upload_embedded',$num,
                   8585:                                                      $embed_file,\%mapping,
                   8586:                                                      $allfiles,$codebase);
                   8587:             $num++;
                   8588:         }
                   8589:         $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
                   8590:     }
                   8591:     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
                   8592:         $upload_output .= &start_data_table_row().
                   8593:                           '<td><span class="LC_filename">'.$embed_file.'</span></td>'.
                   8594:                           '<td><span class="LC_warning">'.&mt('Already exists').'</span></td>'.
                   8595:                           &Apache::loncommon::end_data_table_row()."\n";
                   8596:     }
                   8597:     if ($upload_output) {
                   8598:         $upload_output = &start_data_table().
                   8599:                          $upload_output.
                   8600:                          &end_data_table()."\n";
                   8601:     }
                   8602:     my $applies = 0;
                   8603:     if ($numremref) {
                   8604:         $applies ++;
                   8605:     }
                   8606:     if ($numinvalid) {
                   8607:         $applies ++;
                   8608:     }
                   8609:     if ($numexisting) {
                   8610:         $applies ++;
                   8611:     }
                   8612:     if ($num) {
                   8613:         $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
                   8614:                   ' method="post" enctype="multipart/form-data">'."\n".
                   8615:                   $state.
                   8616:                   '<h3>'.&mt('Upload embedded files').
                   8617:                   ':</h3>'.$upload_output.'<br />'."\n".
                   8618:                   '<input type ="hidden" name="number_embedded_items" value="'.
                   8619:                   $num.'" />'."\n";
                   8620:         if ($actionurl eq '') {
                   8621:             $output .=  '<input type="hidden" name="phase" value="three" />';
                   8622:         }
                   8623:     } elsif ($applies) {
                   8624:         $output = '<b>'.&mt('Referenced files').'</b>:<br />';
                   8625:         if ($applies > 1) {
                   8626:             $output .=  
                   8627:                 &mt('No files need to be uploaded, as one of the following applies to each reference:').'<ul>';
                   8628:             if ($numremref) {
                   8629:                 $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
                   8630:             }
                   8631:             if ($numinvalid) {
                   8632:                 $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
                   8633:             }
                   8634:             if ($numexisting) {
                   8635:                 $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
                   8636:             }
                   8637:             $output .= '</ul><br />';
                   8638:         } elsif ($numremref) {
                   8639:             $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
                   8640:         } elsif ($numinvalid) {
                   8641:             $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
                   8642:         } elsif ($numexisting) {
                   8643:             $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
                   8644:         }
                   8645:         $output .= $upload_output.'<br />';
                   8646:     }
                   8647:     my ($pathchange_output,$chgcount);
                   8648:     $chgcount = $num;
                   8649:     if (keys(%pathchanges) > 0) {
                   8650:         foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
                   8651:             if ($num) {
                   8652:                 $output .= &embedded_file_element('pathchange',$chgcount,
                   8653:                                                   $embed_file,\%mapping,
                   8654:                                                   $allfiles,$codebase);
                   8655:             } else {
                   8656:                 $pathchange_output .= 
                   8657:                     &start_data_table_row().
                   8658:                     '<td><input type ="checkbox" name="namechange" value="'.
                   8659:                     $chgcount.'" checked="checked" /></td>'.
                   8660:                     '<td>'.$mapping{$embed_file}.'</td>'.
                   8661:                     '<td>'.$embed_file.
                   8662:                     &embedded_file_element('pathchange',$numpathchg,$embed_file,
                   8663:                                            \%mapping,$allfiles,$codebase).
                   8664:                     '</td>'.&end_data_table_row();
1.660     raeburn  8665:             }
1.987     raeburn  8666:             $numpathchg ++;
                   8667:             $chgcount ++;
1.660     raeburn  8668:         }
                   8669:     }
1.984     raeburn  8670:     if ($num) {
1.987     raeburn  8671:         if ($numpathchg) {
                   8672:             $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
                   8673:                        $numpathchg.'" />'."\n";
                   8674:         }
                   8675:         if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') || 
                   8676:             ($actionurl eq '/adm/imsimport')) {
                   8677:             $output .= '<input type="hidden" name="phase" value="three" />'."\n";
                   8678:         } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
                   8679:             $output .= '<input type="hidden" name="action" value="upload_embedded" />';
                   8680:         }
                   8681:         $output .=  '<input type ="submit" value="'.&mt('Upload Listed Files').'" />'."\n".
                   8682:                     &mt('(only files for which a location has been provided will be uploaded)').'</form>'."\n";
                   8683:     } elsif ($numpathchg) {
                   8684:         my %pathchange = ();
                   8685:         $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
                   8686:         if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
                   8687:             $output .= '<p>'.&mt('or').'</p>'; 
                   8688:         } 
                   8689:     }
                   8690:     return ($output,$num,$numpathchg);
                   8691: }
                   8692: 
                   8693: sub embedded_file_element {
                   8694:     my ($context,$num,$embed_file,$mapping,$allfiles,$codebase) = @_;
                   8695:     return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
                   8696:                    (ref($codebase) eq 'HASH'));
                   8697:     my $output;
                   8698:     if ($context eq 'upload_embedded') {
                   8699:        $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
                   8700:     }
                   8701:     $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
                   8702:                &escape($embed_file).'" />';
                   8703:     unless (($context eq 'upload_embedded') && 
                   8704:             ($mapping->{$embed_file} eq $embed_file)) {
                   8705:         $output .='
                   8706:         <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
                   8707:     }
                   8708:     my $attrib;
                   8709:     if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
                   8710:         $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
                   8711:     }
                   8712:     $output .=
                   8713:         "\n\t\t".
                   8714:         '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
                   8715:         $attrib.'" />';
                   8716:     if (exists($codebase->{$mapping->{$embed_file}})) {
                   8717:         $output .=
                   8718:             "\n\t\t".
                   8719:             '<input name="codebase_'.$num.'" type="hidden" value="'.
                   8720:             &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984     raeburn  8721:     }
1.987     raeburn  8722:     return $output;
1.660     raeburn  8723: }
                   8724: 
1.661     raeburn  8725: sub upload_embedded {
                   8726:     my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987     raeburn  8727:         $current_disk_usage,$hiddenstate,$actionurl) = @_;
                   8728:     my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661     raeburn  8729:     for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
                   8730:         next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
                   8731:         my $orig_uploaded_filename =
                   8732:             $env{'form.embedded_item_'.$i.'.filename'};
1.987     raeburn  8733:         foreach my $type ('orig','ref','attrib','codebase') {
                   8734:             if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
                   8735:                 $env{'form.embedded_'.$type.'_'.$i} =
                   8736:                     &unescape($env{'form.embedded_'.$type.'_'.$i});
                   8737:             }
                   8738:         }
1.661     raeburn  8739:         my ($path,$fname) =
                   8740:             ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
                   8741:         # no path, whole string is fname
                   8742:         if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
                   8743:         $fname = &Apache::lonnet::clean_filename($fname);
                   8744:         # See if there is anything left
                   8745:         next if ($fname eq '');
                   8746: 
                   8747:         # Check if file already exists as a file or directory.
                   8748:         my ($state,$msg);
                   8749:         if ($context eq 'portfolio') {
                   8750:             my $port_path = $dirpath;
                   8751:             if ($group ne '') {
                   8752:                 $port_path = "groups/$group/$port_path";
                   8753:             }
1.987     raeburn  8754:             ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
                   8755:                                               $fname,$group,'embedded_item_'.$i,
1.661     raeburn  8756:                                               $dir_root,$port_path,$disk_quota,
                   8757:                                               $current_disk_usage,$uname,$udom);
                   8758:             if ($state eq 'will_exceed_quota'
1.984     raeburn  8759:                 || $state eq 'file_locked') {
1.661     raeburn  8760:                 $output .= $msg;
                   8761:                 next;
                   8762:             }
                   8763:         } elsif (($context eq 'author') || ($context eq 'testbank')) {
                   8764:             ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
                   8765:             if ($state eq 'exists') {
                   8766:                 $output .= $msg;
                   8767:                 next;
                   8768:             }
                   8769:         }
                   8770:         # Check if extension is valid
                   8771:         if (($fname =~ /\.(\w+)$/) &&
                   8772:             (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.987     raeburn  8773:             $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  8774:             next;
                   8775:         } elsif (($fname =~ /\.(\w+)$/) &&
                   8776:                  (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987     raeburn  8777:             $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661     raeburn  8778:             next;
                   8779:         } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.987     raeburn  8780:             $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  8781:             next;
                   8782:         }
                   8783: 
                   8784:         $env{'form.embedded_item_'.$i.'.filename'}=$fname;
                   8785:         if ($context eq 'portfolio') {
1.984     raeburn  8786:             my $result;
                   8787:             if ($state eq 'existingfile') {
                   8788:                 $result=
                   8789:                     &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.987     raeburn  8790:                                                     $dirpath.$env{'form.currentpath'}.$path);
1.661     raeburn  8791:             } else {
1.984     raeburn  8792:                 $result=
                   8793:                     &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987     raeburn  8794:                                                     $dirpath.
                   8795:                                                     $env{'form.currentpath'}.$path);
1.984     raeburn  8796:                 if ($result !~ m|^/uploaded/|) {
                   8797:                     $output .= '<span class="LC_error">'
                   8798:                                .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
                   8799:                                ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
                   8800:                                .'</span><br />';
                   8801:                     next;
                   8802:                 } else {
1.987     raeburn  8803:                     $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
                   8804:                                $path.$fname.'</span>').'<br />';     
1.984     raeburn  8805:                 }
1.661     raeburn  8806:             }
1.987     raeburn  8807:         } elsif ($context eq 'coursedoc') {
                   8808:             my $result =
                   8809:                 &Apache::lonnet::userfileupload('embedded_item_'.$i,'coursedoc',
                   8810:                                                 $dirpath.'/'.$path);
                   8811:             if ($result !~ m|^/uploaded/|) {
                   8812:                 $output .= '<span class="LC_error">'
                   8813:                            .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
                   8814:                            ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
                   8815:                            .'</span><br />';
                   8816:                     next;
                   8817:             } else {
                   8818:                 $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
                   8819:                            $path.$fname.'</span>').'<br />';
                   8820:             }
1.661     raeburn  8821:         } else {
                   8822: # Save the file
                   8823:             my $target = $env{'form.embedded_item_'.$i};
                   8824:             my $fullpath = $dir_root.$dirpath.'/'.$path;
                   8825:             my $dest = $fullpath.$fname;
                   8826:             my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027  ! raeburn  8827:             my @parts=split(/\//,"$dirpath/$path");
1.661     raeburn  8828:             my $count;
                   8829:             my $filepath = $dir_root;
1.1027  ! raeburn  8830:             foreach my $subdir (@parts) {
        !          8831:                 $filepath .= "/$subdir";
        !          8832:                 if (!-e $filepath) {
1.661     raeburn  8833:                     mkdir($filepath,0770);
                   8834:                 }
                   8835:             }
                   8836:             my $fh;
                   8837:             if (!open($fh,'>'.$dest)) {
                   8838:                 &Apache::lonnet::logthis('Failed to create '.$dest);
                   8839:                 $output .= '<span class="LC_error">'.
                   8840:                            &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   8841:                            '</span><br />';
                   8842:             } else {
                   8843:                 if (!print $fh $env{'form.embedded_item_'.$i}) {
                   8844:                     &Apache::lonnet::logthis('Failed to write to '.$dest);
                   8845:                     $output .= '<span class="LC_error">'.
                   8846:                               &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   8847:                               '</span><br />';
                   8848:                 } else {
1.987     raeburn  8849:                     $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
                   8850:                                $url.'</span>').'<br />';
                   8851:                     unless ($context eq 'testbank') {
                   8852:                         $footer .= &mt('View embedded file: [_1]',
                   8853:                                        '<a href="'.$url.'">'.$fname.'</a>').'<br />';
                   8854:                     }
                   8855:                 }
                   8856:                 close($fh);
                   8857:             }
                   8858:         }
                   8859:         if ($env{'form.embedded_ref_'.$i}) {
                   8860:             $pathchange{$i} = 1;
                   8861:         }
                   8862:     }
                   8863:     if ($output) {
                   8864:         $output = '<p>'.$output.'</p>';
                   8865:     }
                   8866:     $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
                   8867:     $returnflag = 'ok';
                   8868:     if (keys(%pathchange) > 0) {
                   8869:         if ($context eq 'portfolio') {
                   8870:             $output .= '<p>'.&mt('or').'</p>';
                   8871:         } elsif ($context eq 'testbank') {
1.988     raeburn  8872:             $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  8873:             $returnflag = 'modify_orightml';
                   8874:         }
                   8875:     }
                   8876:     return ($output.$footer,$returnflag);
                   8877: }
                   8878: 
                   8879: sub modify_html_form {
                   8880:     my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
                   8881:     my $end = 0;
                   8882:     my $modifyform;
                   8883:     if ($context eq 'upload_embedded') {
                   8884:         return unless (ref($pathchange) eq 'HASH');
                   8885:         if ($env{'form.number_embedded_items'}) {
                   8886:             $end += $env{'form.number_embedded_items'};
                   8887:         }
                   8888:         if ($env{'form.number_pathchange_items'}) {
                   8889:             $end += $env{'form.number_pathchange_items'};
                   8890:         }
                   8891:         if ($end) {
                   8892:             for (my $i=0; $i<$end; $i++) {
                   8893:                 if ($i < $env{'form.number_embedded_items'}) {
                   8894:                     next unless($pathchange->{$i});
                   8895:                 }
                   8896:                 $modifyform .=
                   8897:                     &start_data_table_row().
                   8898:                     '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
                   8899:                     'checked="checked" /></td>'.
                   8900:                     '<td>'.$env{'form.embedded_ref_'.$i}.
                   8901:                     '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
                   8902:                     &escape($env{'form.embedded_ref_'.$i}).'" />'.
                   8903:                     '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
                   8904:                     &escape($env{'form.embedded_codebase_'.$i}).'" />'.
                   8905:                     '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
                   8906:                     &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
                   8907:                     '<td>'.$env{'form.embedded_orig_'.$i}.
                   8908:                     '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
                   8909:                     &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
                   8910:                     &end_data_table_row();
                   8911:             } 
                   8912:         }
                   8913:     } else {
                   8914:         $modifyform = $pathchgtable;
                   8915:         if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
                   8916:             $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
                   8917:         } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
                   8918:             $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
                   8919:         }
                   8920:     }
                   8921:     if ($modifyform) {
                   8922:         return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
                   8923:                '<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".
                   8924:                '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
                   8925:                '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
                   8926:                '</ol></p>'."\n".'<p>'.
                   8927:                &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
                   8928:                '<form method="post" name="refchanger" action="'.$actionurl.'">'.
                   8929:                &start_data_table()."\n".
                   8930:                &start_data_table_header_row().
                   8931:                '<th>'.&mt('Change?').'</th>'.
                   8932:                '<th>'.&mt('Current reference').'</th>'.
                   8933:                '<th>'.&mt('Required reference').'</th>'.
                   8934:                &end_data_table_header_row()."\n".
                   8935:                $modifyform.
                   8936:                &end_data_table().'<br />'."\n".$hiddenstate.
                   8937:                '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
                   8938:                '</form>'."\n";
                   8939:     }
                   8940:     return;
                   8941: }
                   8942: 
                   8943: sub modify_html_refs {
                   8944:     my ($context,$dirpath,$uname,$udom,$dir_root) = @_;
                   8945:     my $container;
                   8946:     if ($context eq 'portfolio') {
                   8947:         $container = $env{'form.container'};
                   8948:     } elsif ($context eq 'coursedoc') {
                   8949:         $container = $env{'form.primaryurl'};
                   8950:     } else {
1.1027  ! raeburn  8951:         $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987     raeburn  8952:     }
                   8953:     my (%allfiles,%codebase,$output,$content);
                   8954:     my @changes = &get_env_multiple('form.namechange');
                   8955:     return unless (@changes > 0);
                   8956:     if (($context eq 'portfolio') || ($context eq 'coursedoc')) {
                   8957:         return unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/});
                   8958:         $content = &Apache::lonnet::getfile($container);
                   8959:         return if ($content eq '-1');
                   8960:     } else {
                   8961:         return unless ($container =~ /^\Q$dir_root\E/); 
                   8962:         if (open(my $fh,"<$container")) {
                   8963:             $content = join('', <$fh>);
                   8964:             close($fh);
                   8965:         } else {
                   8966:             return;
                   8967:         }
                   8968:     }
                   8969:     my ($count,$codebasecount) = (0,0);
                   8970:     my $mm = new File::MMagic;
                   8971:     my $mime_type = $mm->checktype_contents($content);
                   8972:     if ($mime_type eq 'text/html') {
                   8973:         my $parse_result = 
                   8974:             &Apache::lonnet::extract_embedded_items($container,\%allfiles,
                   8975:                                                     \%codebase,\$content);
                   8976:         if ($parse_result eq 'ok') {
                   8977:             foreach my $i (@changes) {
                   8978:                 my $orig = &unescape($env{'form.embedded_orig_'.$i});
                   8979:                 my $ref = &unescape($env{'form.embedded_ref_'.$i});
                   8980:                 if ($allfiles{$ref}) {
                   8981:                     my $newname =  $orig;
                   8982:                     my ($attrib_regexp,$codebase);
1.1006    raeburn  8983:                     $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987     raeburn  8984:                     if ($attrib_regexp =~ /:/) {
                   8985:                         $attrib_regexp =~ s/\:/|/g;
                   8986:                     }
                   8987:                     if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
                   8988:                         my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
                   8989:                         $count += $numchg;
                   8990:                     }
                   8991:                     if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006    raeburn  8992:                         $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987     raeburn  8993:                         my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
                   8994:                         $codebasecount ++;
                   8995:                     }
                   8996:                 }
                   8997:             }
                   8998:             if ($count || $codebasecount) {
                   8999:                 my $saveresult;
                   9000:                 if ($context eq 'portfolio' || $context eq 'coursedoc') {
                   9001:                     my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
                   9002:                     if ($url eq $container) {
                   9003:                         my ($fname) = ($container =~ m{/([^/]+)$});
                   9004:                         $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
                   9005:                                             $count,'<span class="LC_filename">'.
                   9006:                                             $fname.'</span>').'</p>'; 
                   9007:                     } else {
                   9008:                          $output = '<p class="LC_error">'.
                   9009:                                    &mt('Error: update failed for: [_1].',
                   9010:                                    '<span class="LC_filename">'.
                   9011:                                    $container.'</span>').'</p>';
                   9012:                     }
                   9013:                 } else {
                   9014:                     if (open(my $fh,">$container")) {
                   9015:                         print $fh $content;
                   9016:                         close($fh);
                   9017:                         $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
                   9018:                                   $count,'<span class="LC_filename">'.
                   9019:                                   $container.'</span>').'</p>';
1.661     raeburn  9020:                     } else {
1.987     raeburn  9021:                          $output = '<p class="LC_error">'.
                   9022:                                    &mt('Error: could not update [_1].',
                   9023:                                    '<span class="LC_filename">'.
                   9024:                                    $container.'</span>').'</p>';
1.661     raeburn  9025:                     }
                   9026:                 }
                   9027:             }
1.987     raeburn  9028:         } else {
                   9029:             &logthis('Failed to parse '.$container.
                   9030:                      ' to modify references: '.$parse_result);
1.661     raeburn  9031:         }
                   9032:     }
                   9033:     return $output;
                   9034: }
                   9035: 
                   9036: sub check_for_existing {
                   9037:     my ($path,$fname,$element) = @_;
                   9038:     my ($state,$msg);
                   9039:     if (-d $path.'/'.$fname) {
                   9040:         $state = 'exists';
                   9041:         $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   9042:     } elsif (-e $path.'/'.$fname) {
                   9043:         $state = 'exists';
                   9044:         $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   9045:     }
                   9046:     if ($state eq 'exists') {
                   9047:         $msg = '<span class="LC_error">'.$msg.'</span><br />';
                   9048:     }
                   9049:     return ($state,$msg);
                   9050: }
                   9051: 
                   9052: sub check_for_upload {
                   9053:     my ($path,$fname,$group,$element,$portfolio_root,$port_path,
                   9054:         $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985     raeburn  9055:     my $filesize = length($env{'form.'.$element});
                   9056:     if (!$filesize) {
                   9057:         my $msg = '<span class="LC_error">'.
                   9058:                   &mt('Unable to upload [_1]. (size = [_2] bytes)', 
                   9059:                       '<span class="LC_filename">'.$fname.'</span>',
                   9060:                       $filesize).'<br />'.
1.1007    raeburn  9061:                   &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985     raeburn  9062:                   '</span>';
                   9063:         return ('zero_bytes',$msg);
                   9064:     }
                   9065:     $filesize =  $filesize/1000; #express in k (1024?)
1.661     raeburn  9066:     my $getpropath = 1;
1.1021    raeburn  9067:     my ($dirlistref,$listerror) =
                   9068:          &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661     raeburn  9069:     my $found_file = 0;
                   9070:     my $locked_file = 0;
1.991     raeburn  9071:     my @lockers;
                   9072:     my $navmap;
                   9073:     if ($env{'request.course.id'}) {
                   9074:         $navmap = Apache::lonnavmaps::navmap->new();
                   9075:     }
1.1021    raeburn  9076:     if (ref($dirlistref) eq 'ARRAY') {
                   9077:         foreach my $line (@{$dirlistref}) {
                   9078:             my ($file_name,$rest)=split(/\&/,$line,2);
                   9079:             if ($file_name eq $fname){
                   9080:                 $file_name = $path.$file_name;
                   9081:                 if ($group ne '') {
                   9082:                     $file_name = $group.$file_name;
                   9083:                 }
                   9084:                 $found_file = 1;
                   9085:                 if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
                   9086:                     foreach my $lock (@lockers) {
                   9087:                         if (ref($lock) eq 'ARRAY') {
                   9088:                             my ($symb,$crsid) = @{$lock};
                   9089:                             if ($crsid eq $env{'request.course.id'}) {
                   9090:                                 if (ref($navmap)) {
                   9091:                                     my $res = $navmap->getBySymb($symb);
                   9092:                                     foreach my $part (@{$res->parts()}) { 
                   9093:                                         my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
                   9094:                                         unless (($slot_status == $res->RESERVED) ||
                   9095:                                                 ($slot_status == $res->RESERVED_LOCATION)) {
                   9096:                                             $locked_file = 1;
                   9097:                                         }
1.991     raeburn  9098:                                     }
1.1021    raeburn  9099:                                 } else {
                   9100:                                     $locked_file = 1;
1.991     raeburn  9101:                                 }
                   9102:                             } else {
                   9103:                                 $locked_file = 1;
                   9104:                             }
                   9105:                         }
1.1021    raeburn  9106:                    }
                   9107:                 } else {
                   9108:                     my @info = split(/\&/,$rest);
                   9109:                     my $currsize = $info[6]/1000;
                   9110:                     if ($currsize < $filesize) {
                   9111:                         my $extra = $filesize - $currsize;
                   9112:                         if (($current_disk_usage + $extra) > $disk_quota) {
                   9113:                             my $msg = '<span class="LC_error">'.
                   9114:                                       &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.',
                   9115:                                           '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
                   9116:                                       '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
                   9117:                                                    $disk_quota,$current_disk_usage);
                   9118:                             return ('will_exceed_quota',$msg);
                   9119:                         }
1.984     raeburn  9120:                     }
                   9121:                 }
1.661     raeburn  9122:             }
                   9123:         }
                   9124:     }
                   9125:     if (($current_disk_usage + $filesize) > $disk_quota){
                   9126:         my $msg = '<span class="LC_error">'.
                   9127:                 &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
                   9128:                   '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
                   9129:         return ('will_exceed_quota',$msg);
                   9130:     } elsif ($found_file) {
                   9131:         if ($locked_file) {
                   9132:             my $msg = '<span class="LC_error">';
                   9133:             $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>');
                   9134:             $msg .= '</span><br />';
                   9135:             $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
                   9136:             return ('file_locked',$msg);
                   9137:         } else {
                   9138:             my $msg = '<span class="LC_error">';
1.984     raeburn  9139:             $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  9140:             $msg .= '</span>';
1.984     raeburn  9141:             return ('existingfile',$msg);
1.661     raeburn  9142:         }
                   9143:     }
                   9144: }
                   9145: 
1.987     raeburn  9146: sub check_for_traversal {
                   9147:     my ($path,$url,$toplevel) = @_;
                   9148:     my @parts=split(/\//,$path);
                   9149:     my $cleanpath;
                   9150:     my $fullpath = $url;
                   9151:     for (my $i=0;$i<@parts;$i++) {
                   9152:         next if ($parts[$i] eq '.');
                   9153:         if ($parts[$i] eq '..') {
                   9154:             $fullpath =~ s{([^/]+/)$}{};
                   9155:         } else {
                   9156:             $fullpath .= $parts[$i].'/';
                   9157:         }
                   9158:     }
                   9159:     if ($fullpath =~ /^\Q$url\E(.*)$/) {
                   9160:         $cleanpath = $1;
                   9161:     } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
                   9162:         my $curr_toprel = $1;
                   9163:         my @parts = split(/\//,$curr_toprel);
                   9164:         my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
                   9165:         my @urlparts = split(/\//,$url_toprel);
                   9166:         my $doubledots;
                   9167:         my $startdiff = -1;
                   9168:         for (my $i=0; $i<@urlparts; $i++) {
                   9169:             if ($startdiff == -1) {
                   9170:                 unless ($urlparts[$i] eq $parts[$i]) {
                   9171:                     $startdiff = $i;
                   9172:                     $doubledots .= '../';
                   9173:                 }
                   9174:             } else {
                   9175:                 $doubledots .= '../';
                   9176:             }
                   9177:         }
                   9178:         if ($startdiff > -1) {
                   9179:             $cleanpath = $doubledots;
                   9180:             for (my $i=$startdiff; $i<@parts; $i++) {
                   9181:                 $cleanpath .= $parts[$i].'/';
                   9182:             }
                   9183:         }
                   9184:     }
                   9185:     $cleanpath =~ s{(/)$}{};
                   9186:     return $cleanpath;
                   9187: }
1.31      albertel 9188: 
1.41      ng       9189: =pod
1.45      matthew  9190: 
1.1015    raeburn  9191: =item * &get_turnedin_filepath()
                   9192: 
                   9193: Determines path in a user's portfolio file for storage of files uploaded
                   9194: to a specific essayresponse or dropbox item.
                   9195: 
                   9196: Inputs: 3 required + 1 optional.
                   9197: $symb is symb for resource, $uname and $udom are for current user (required).
                   9198: $caller is optional (can be "submission", if routine is called when storing
                   9199: an upoaded file when "Submit Answer" button was pressed).
                   9200: 
                   9201: Returns array containing $path and $multiresp. 
                   9202: $path is path in portfolio.  $multiresp is 1 if this resource contains more
                   9203: than one file upload item.  Callers of routine should append partid as a 
                   9204: subdirectory to $path in cases where $multiresp is 1.
                   9205: 
                   9206: Called by: homework/essayresponse.pm and homework/structuretags.pm
                   9207: 
                   9208: =cut
                   9209: 
                   9210: sub get_turnedin_filepath {
                   9211:     my ($symb,$uname,$udom,$caller) = @_;
                   9212:     my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
                   9213:     my $turnindir;
                   9214:     my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
                   9215:     $turnindir = $userhash{'turnindir'};
                   9216:     my ($path,$multiresp);
                   9217:     if ($turnindir eq '') {
                   9218:         if ($caller eq 'submission') {
                   9219:             $turnindir = &mt('turned in');
                   9220:             $turnindir =~ s/\W+/_/g;
                   9221:             my %newhash = (
                   9222:                             'turnindir' => $turnindir,
                   9223:                           );
                   9224:             &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
                   9225:         }
                   9226:     }
                   9227:     if ($turnindir ne '') {
                   9228:         $path = '/'.$turnindir.'/';
                   9229:         my ($multipart,$turnin,@pathitems);
                   9230:         my $navmap = Apache::lonnavmaps::navmap->new();
                   9231:         if (defined($navmap)) {
                   9232:             my $mapres = $navmap->getResourceByUrl($map);
                   9233:             if (ref($mapres)) {
                   9234:                 my $pcslist = $mapres->map_hierarchy();
                   9235:                 if ($pcslist ne '') {
                   9236:                     foreach my $pc (split(/,/,$pcslist)) {
                   9237:                         my $res = $navmap->getByMapPc($pc);
                   9238:                         if (ref($res)) {
                   9239:                             my $title = $res->compTitle();
                   9240:                             $title =~ s/\W+/_/g;
                   9241:                             if ($title ne '') {
                   9242:                                 push(@pathitems,$title);
                   9243:                             }
                   9244:                         }
                   9245:                     }
                   9246:                 }
                   9247:                 my $maptitle = $mapres->compTitle();
                   9248:                 $maptitle =~ s/\W+/_/g;
                   9249:                 if ($maptitle ne '') {
                   9250:                     push(@pathitems,$maptitle);
                   9251:                 }
                   9252:                 unless ($env{'request.state'} eq 'construct') {
                   9253:                     my $res = $navmap->getBySymb($symb);
                   9254:                     if (ref($res)) {
                   9255:                         my $partlist = $res->parts();
                   9256:                         my $totaluploads = 0;
                   9257:                         if (ref($partlist) eq 'ARRAY') {
                   9258:                             foreach my $part (@{$partlist}) {
                   9259:                                 my @types = $res->responseType($part);
                   9260:                                 my @ids = $res->responseIds($part);
                   9261:                                 for (my $i=0; $i < scalar(@ids); $i++) {
                   9262:                                     if ($types[$i] eq 'essay') {
                   9263:                                         my $partid = $part.'_'.$ids[$i];
                   9264:                                         if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
                   9265:                                             $totaluploads ++;
                   9266:                                         }
                   9267:                                     }
                   9268:                                 }
                   9269:                             }
                   9270:                             if ($totaluploads > 1) {
                   9271:                                 $multiresp = 1;
                   9272:                             }
                   9273:                         }
                   9274:                     }
                   9275:                 }
                   9276:             } else {
                   9277:                 return;
                   9278:             }
                   9279:         } else {
                   9280:             return;
                   9281:         }
                   9282:         my $restitle=&Apache::lonnet::gettitle($symb);
                   9283:         $restitle =~ s/\W+/_/g;
                   9284:         if ($restitle eq '') {
                   9285:             $restitle = ($resurl =~ m{/[^/]+$});
                   9286:             if ($restitle eq '') {
                   9287:                 $restitle = time;
                   9288:             }
                   9289:         }
                   9290:         push(@pathitems,$restitle);
                   9291:         $path .= join('/',@pathitems);
                   9292:     }
                   9293:     return ($path,$multiresp);
                   9294: }
                   9295: 
                   9296: =pod
                   9297: 
1.464     albertel 9298: =back
1.41      ng       9299: 
1.112     bowersj2 9300: =head1 CSV Upload/Handling functions
1.38      albertel 9301: 
1.41      ng       9302: =over 4
                   9303: 
1.648     raeburn  9304: =item * &upfile_store($r)
1.41      ng       9305: 
                   9306: Store uploaded file, $r should be the HTTP Request object,
1.258     albertel 9307: needs $env{'form.upfile'}
1.41      ng       9308: returns $datatoken to be put into hidden field
                   9309: 
                   9310: =cut
1.31      albertel 9311: 
                   9312: sub upfile_store {
                   9313:     my $r=shift;
1.258     albertel 9314:     $env{'form.upfile'}=~s/\r/\n/gs;
                   9315:     $env{'form.upfile'}=~s/\f/\n/gs;
                   9316:     $env{'form.upfile'}=~s/\n+/\n/gs;
                   9317:     $env{'form.upfile'}=~s/\n+$//gs;
1.31      albertel 9318: 
1.258     albertel 9319:     my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
                   9320: 	'_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31      albertel 9321:     {
1.158     raeburn  9322:         my $datafile = $r->dir_config('lonDaemons').
                   9323:                            '/tmp/'.$datatoken.'.tmp';
                   9324:         if ( open(my $fh,">$datafile") ) {
1.258     albertel 9325:             print $fh $env{'form.upfile'};
1.158     raeburn  9326:             close($fh);
                   9327:         }
1.31      albertel 9328:     }
                   9329:     return $datatoken;
                   9330: }
                   9331: 
1.56      matthew  9332: =pod
                   9333: 
1.648     raeburn  9334: =item * &load_tmp_file($r)
1.41      ng       9335: 
                   9336: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258     albertel 9337: needs $env{'form.datatoken'},
                   9338: sets $env{'form.upfile'} to the contents of the file
1.41      ng       9339: 
                   9340: =cut
1.31      albertel 9341: 
                   9342: sub load_tmp_file {
                   9343:     my $r=shift;
                   9344:     my @studentdata=();
                   9345:     {
1.158     raeburn  9346:         my $studentfile = $r->dir_config('lonDaemons').
1.258     albertel 9347:                               '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158     raeburn  9348:         if ( open(my $fh,"<$studentfile") ) {
                   9349:             @studentdata=<$fh>;
                   9350:             close($fh);
                   9351:         }
1.31      albertel 9352:     }
1.258     albertel 9353:     $env{'form.upfile'}=join('',@studentdata);
1.31      albertel 9354: }
                   9355: 
1.56      matthew  9356: =pod
                   9357: 
1.648     raeburn  9358: =item * &upfile_record_sep()
1.41      ng       9359: 
                   9360: Separate uploaded file into records
                   9361: returns array of records,
1.258     albertel 9362: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41      ng       9363: 
                   9364: =cut
1.31      albertel 9365: 
                   9366: sub upfile_record_sep {
1.258     albertel 9367:     if ($env{'form.upfiletype'} eq 'xml') {
1.31      albertel 9368:     } else {
1.248     albertel 9369: 	my @records;
1.258     albertel 9370: 	foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248     albertel 9371: 	    if ($line=~/^\s*$/) { next; }
                   9372: 	    push(@records,$line);
                   9373: 	}
                   9374: 	return @records;
1.31      albertel 9375:     }
                   9376: }
                   9377: 
1.56      matthew  9378: =pod
                   9379: 
1.648     raeburn  9380: =item * &record_sep($record)
1.41      ng       9381: 
1.258     albertel 9382: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41      ng       9383: 
                   9384: =cut
                   9385: 
1.263     www      9386: sub takeleft {
                   9387:     my $index=shift;
                   9388:     return substr('0000'.$index,-4,4);
                   9389: }
                   9390: 
1.31      albertel 9391: sub record_sep {
                   9392:     my $record=shift;
                   9393:     my %components=();
1.258     albertel 9394:     if ($env{'form.upfiletype'} eq 'xml') {
                   9395:     } elsif ($env{'form.upfiletype'} eq 'space') {
1.31      albertel 9396:         my $i=0;
1.356     albertel 9397:         foreach my $field (split(/\s+/,$record)) {
1.31      albertel 9398:             $field=~s/^(\"|\')//;
                   9399:             $field=~s/(\"|\')$//;
1.263     www      9400:             $components{&takeleft($i)}=$field;
1.31      albertel 9401:             $i++;
                   9402:         }
1.258     albertel 9403:     } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31      albertel 9404:         my $i=0;
1.356     albertel 9405:         foreach my $field (split(/\t/,$record)) {
1.31      albertel 9406:             $field=~s/^(\"|\')//;
                   9407:             $field=~s/(\"|\')$//;
1.263     www      9408:             $components{&takeleft($i)}=$field;
1.31      albertel 9409:             $i++;
                   9410:         }
                   9411:     } else {
1.561     www      9412:         my $separator=',';
1.480     banghart 9413:         if ($env{'form.upfiletype'} eq 'semisv') {
1.561     www      9414:             $separator=';';
1.480     banghart 9415:         }
1.31      albertel 9416:         my $i=0;
1.561     www      9417: # the character we are looking for to indicate the end of a quote or a record 
                   9418:         my $looking_for=$separator;
                   9419: # do not add the characters to the fields
                   9420:         my $ignore=0;
                   9421: # we just encountered a separator (or the beginning of the record)
                   9422:         my $just_found_separator=1;
                   9423: # store the field we are working on here
                   9424:         my $field='';
                   9425: # work our way through all characters in record
                   9426:         foreach my $character ($record=~/(.)/g) {
                   9427:             if ($character eq $looking_for) {
                   9428:                if ($character ne $separator) {
                   9429: # Found the end of a quote, again looking for separator
                   9430:                   $looking_for=$separator;
                   9431:                   $ignore=1;
                   9432:                } else {
                   9433: # Found a separator, store away what we got
                   9434:                   $components{&takeleft($i)}=$field;
                   9435: 	          $i++;
                   9436:                   $just_found_separator=1;
                   9437:                   $ignore=0;
                   9438:                   $field='';
                   9439:                }
                   9440:                next;
                   9441:             }
                   9442: # single or double quotation marks after a separator indicate beginning of a quote
                   9443: # we are now looking for the end of the quote and need to ignore separators
                   9444:             if ((($character eq '"') || ($character eq "'")) && ($just_found_separator))  {
                   9445:                $looking_for=$character;
                   9446:                next;
                   9447:             }
                   9448: # ignore would be true after we reached the end of a quote
                   9449:             if ($ignore) { next; }
                   9450:             if (($just_found_separator) && ($character=~/\s/)) { next; }
                   9451:             $field.=$character;
                   9452:             $just_found_separator=0; 
1.31      albertel 9453:         }
1.561     www      9454: # catch the very last entry, since we never encountered the separator
                   9455:         $components{&takeleft($i)}=$field;
1.31      albertel 9456:     }
                   9457:     return %components;
                   9458: }
                   9459: 
1.144     matthew  9460: ######################################################
                   9461: ######################################################
                   9462: 
1.56      matthew  9463: =pod
                   9464: 
1.648     raeburn  9465: =item * &upfile_select_html()
1.41      ng       9466: 
1.144     matthew  9467: Return HTML code to select a file from the users machine and specify 
                   9468: the file type.
1.41      ng       9469: 
                   9470: =cut
                   9471: 
1.144     matthew  9472: ######################################################
                   9473: ######################################################
1.31      albertel 9474: sub upfile_select_html {
1.144     matthew  9475:     my %Types = (
                   9476:                  csv   => &mt('CSV (comma separated values, spreadsheet)'),
1.480     banghart 9477:                  semisv => &mt('Semicolon separated values'),
1.144     matthew  9478:                  space => &mt('Space separated'),
                   9479:                  tab   => &mt('Tabulator separated'),
                   9480: #                 xml   => &mt('HTML/XML'),
                   9481:                  );
                   9482:     my $Str = '<input type="file" name="upfile" size="50" />'.
1.727     riegler  9483:         '<br />'.&mt('Type').': <select name="upfiletype">';
1.144     matthew  9484:     foreach my $type (sort(keys(%Types))) {
                   9485:         $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
                   9486:     }
                   9487:     $Str .= "</select>\n";
                   9488:     return $Str;
1.31      albertel 9489: }
                   9490: 
1.301     albertel 9491: sub get_samples {
                   9492:     my ($records,$toget) = @_;
                   9493:     my @samples=({});
                   9494:     my $got=0;
                   9495:     foreach my $rec (@$records) {
                   9496: 	my %temp = &record_sep($rec);
                   9497: 	if (! grep(/\S/, values(%temp))) { next; }
                   9498: 	if (%temp) {
                   9499: 	    $samples[$got]=\%temp;
                   9500: 	    $got++;
                   9501: 	    if ($got == $toget) { last; }
                   9502: 	}
                   9503:     }
                   9504:     return \@samples;
                   9505: }
                   9506: 
1.144     matthew  9507: ######################################################
                   9508: ######################################################
                   9509: 
1.56      matthew  9510: =pod
                   9511: 
1.648     raeburn  9512: =item * &csv_print_samples($r,$records)
1.41      ng       9513: 
                   9514: Prints a table of sample values from each column uploaded $r is an
                   9515: Apache Request ref, $records is an arrayref from
                   9516: &Apache::loncommon::upfile_record_sep
                   9517: 
                   9518: =cut
                   9519: 
1.144     matthew  9520: ######################################################
                   9521: ######################################################
1.31      albertel 9522: sub csv_print_samples {
                   9523:     my ($r,$records) = @_;
1.662     bisitz   9524:     my $samples = &get_samples($records,5);
1.301     albertel 9525: 
1.594     raeburn  9526:     $r->print(&mt('Samples').'<br />'.&start_data_table().
                   9527:               &start_data_table_header_row());
1.356     albertel 9528:     foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) { 
1.845     bisitz   9529:         $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594     raeburn  9530:     $r->print(&end_data_table_header_row());
1.301     albertel 9531:     foreach my $hash (@$samples) {
1.594     raeburn  9532: 	$r->print(&start_data_table_row());
1.356     albertel 9533: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31      albertel 9534: 	    $r->print('<td>');
1.356     albertel 9535: 	    if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31      albertel 9536: 	    $r->print('</td>');
                   9537: 	}
1.594     raeburn  9538: 	$r->print(&end_data_table_row());
1.31      albertel 9539:     }
1.594     raeburn  9540:     $r->print(&end_data_table().'<br />'."\n");
1.31      albertel 9541: }
                   9542: 
1.144     matthew  9543: ######################################################
                   9544: ######################################################
                   9545: 
1.56      matthew  9546: =pod
                   9547: 
1.648     raeburn  9548: =item * &csv_print_select_table($r,$records,$d)
1.41      ng       9549: 
                   9550: Prints a table to create associations between values and table columns.
1.144     matthew  9551: 
1.41      ng       9552: $r is an Apache Request ref,
                   9553: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174     matthew  9554: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41      ng       9555: 
                   9556: =cut
                   9557: 
1.144     matthew  9558: ######################################################
                   9559: ######################################################
1.31      albertel 9560: sub csv_print_select_table {
                   9561:     my ($r,$records,$d) = @_;
1.301     albertel 9562:     my $i=0;
                   9563:     my $samples = &get_samples($records,1);
1.144     matthew  9564:     $r->print(&mt('Associate columns with student attributes.')."\n".
1.594     raeburn  9565: 	      &start_data_table().&start_data_table_header_row().
1.144     matthew  9566:               '<th>'.&mt('Attribute').'</th>'.
1.594     raeburn  9567:               '<th>'.&mt('Column').'</th>'.
                   9568:               &end_data_table_header_row()."\n");
1.356     albertel 9569:     foreach my $array_ref (@$d) {
                   9570: 	my ($value,$display,$defaultcol)=@{ $array_ref };
1.729     raeburn  9571: 	$r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31      albertel 9572: 
1.875     bisitz   9573: 	$r->print('<td><select name="f'.$i.'"'.
1.32      matthew  9574: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.31      albertel 9575: 	$r->print('<option value="none"></option>');
1.356     albertel 9576: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
                   9577: 	    $r->print('<option value="'.$sample.'"'.
                   9578:                       ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662     bisitz   9579:                       '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31      albertel 9580: 	}
1.594     raeburn  9581: 	$r->print('</select></td>'.&end_data_table_row()."\n");
1.31      albertel 9582: 	$i++;
                   9583:     }
1.594     raeburn  9584:     $r->print(&end_data_table());
1.31      albertel 9585:     $i--;
                   9586:     return $i;
                   9587: }
1.56      matthew  9588: 
1.144     matthew  9589: ######################################################
                   9590: ######################################################
                   9591: 
1.56      matthew  9592: =pod
1.31      albertel 9593: 
1.648     raeburn  9594: =item * &csv_samples_select_table($r,$records,$d)
1.41      ng       9595: 
                   9596: Prints a table of sample values from the upload and can make associate samples to internal names.
                   9597: 
                   9598: $r is an Apache Request ref,
                   9599: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
                   9600: $d is an array of 2 element arrays (internal name, displayed name)
                   9601: 
                   9602: =cut
                   9603: 
1.144     matthew  9604: ######################################################
                   9605: ######################################################
1.31      albertel 9606: sub csv_samples_select_table {
                   9607:     my ($r,$records,$d) = @_;
                   9608:     my $i=0;
1.144     matthew  9609:     #
1.662     bisitz   9610:     my $max_samples = 5;
                   9611:     my $samples = &get_samples($records,$max_samples);
1.594     raeburn  9612:     $r->print(&start_data_table().
                   9613:               &start_data_table_header_row().'<th>'.
                   9614:               &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
                   9615:               &end_data_table_header_row());
1.301     albertel 9616: 
                   9617:     foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594     raeburn  9618: 	$r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32      matthew  9619: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.301     albertel 9620: 	foreach my $option (@$d) {
                   9621: 	    my ($value,$display,$defaultcol)=@{ $option };
1.174     matthew  9622: 	    $r->print('<option value="'.$value.'"'.
1.253     albertel 9623:                       ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174     matthew  9624:                       $display.'</option>');
1.31      albertel 9625: 	}
                   9626: 	$r->print('</select></td><td>');
1.662     bisitz   9627: 	foreach my $line (0..($max_samples-1)) {
1.301     albertel 9628: 	    if (defined($samples->[$line]{$key})) { 
                   9629: 		$r->print($samples->[$line]{$key}."<br />\n"); 
                   9630: 	    }
                   9631: 	}
1.594     raeburn  9632: 	$r->print('</td>'.&end_data_table_row());
1.31      albertel 9633: 	$i++;
                   9634:     }
1.594     raeburn  9635:     $r->print(&end_data_table());
1.31      albertel 9636:     $i--;
                   9637:     return($i);
1.115     matthew  9638: }
                   9639: 
1.144     matthew  9640: ######################################################
                   9641: ######################################################
                   9642: 
1.115     matthew  9643: =pod
                   9644: 
1.648     raeburn  9645: =item * &clean_excel_name($name)
1.115     matthew  9646: 
                   9647: Returns a replacement for $name which does not contain any illegal characters.
                   9648: 
                   9649: =cut
                   9650: 
1.144     matthew  9651: ######################################################
                   9652: ######################################################
1.115     matthew  9653: sub clean_excel_name {
                   9654:     my ($name) = @_;
                   9655:     $name =~ s/[:\*\?\/\\]//g;
                   9656:     if (length($name) > 31) {
                   9657:         $name = substr($name,0,31);
                   9658:     }
                   9659:     return $name;
1.25      albertel 9660: }
1.84      albertel 9661: 
1.85      albertel 9662: =pod
                   9663: 
1.648     raeburn  9664: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85      albertel 9665: 
                   9666: Returns either 1 or undef
                   9667: 
                   9668: 1 if the part is to be hidden, undef if it is to be shown
                   9669: 
                   9670: Arguments are:
                   9671: 
                   9672: $id the id of the part to be checked
                   9673: $symb, optional the symb of the resource to check
                   9674: $udom, optional the domain of the user to check for
                   9675: $uname, optional the username of the user to check for
                   9676: 
                   9677: =cut
1.84      albertel 9678: 
                   9679: sub check_if_partid_hidden {
                   9680:     my ($id,$symb,$udom,$uname) = @_;
1.133     albertel 9681:     my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84      albertel 9682: 					 $symb,$udom,$uname);
1.141     albertel 9683:     my $truth=1;
                   9684:     #if the string starts with !, then the list is the list to show not hide
                   9685:     if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84      albertel 9686:     my @hiddenlist=split(/,/,$hiddenparts);
                   9687:     foreach my $checkid (@hiddenlist) {
1.141     albertel 9688: 	if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84      albertel 9689:     }
1.141     albertel 9690:     return !$truth;
1.84      albertel 9691: }
1.127     matthew  9692: 
1.138     matthew  9693: 
                   9694: ############################################################
                   9695: ############################################################
                   9696: 
                   9697: =pod
                   9698: 
1.157     matthew  9699: =back 
                   9700: 
1.138     matthew  9701: =head1 cgi-bin script and graphing routines
                   9702: 
1.157     matthew  9703: =over 4
                   9704: 
1.648     raeburn  9705: =item * &get_cgi_id()
1.138     matthew  9706: 
                   9707: Inputs: none
                   9708: 
                   9709: Returns an id which can be used to pass environment variables
                   9710: to various cgi-bin scripts.  These environment variables will
                   9711: be removed from the users environment after a given time by
                   9712: the routine &Apache::lonnet::transfer_profile_to_env.
                   9713: 
                   9714: =cut
                   9715: 
                   9716: ############################################################
                   9717: ############################################################
1.152     albertel 9718: my $uniq=0;
1.136     matthew  9719: sub get_cgi_id {
1.154     albertel 9720:     $uniq=($uniq+1)%100000;
1.280     albertel 9721:     return (time.'_'.$$.'_'.$uniq);
1.136     matthew  9722: }
                   9723: 
1.127     matthew  9724: ############################################################
                   9725: ############################################################
                   9726: 
                   9727: =pod
                   9728: 
1.648     raeburn  9729: =item * &DrawBarGraph()
1.127     matthew  9730: 
1.138     matthew  9731: Facilitates the plotting of data in a (stacked) bar graph.
                   9732: Puts plot definition data into the users environment in order for 
                   9733: graph.png to plot it.  Returns an <img> tag for the plot.
                   9734: The bars on the plot are labeled '1','2',...,'n'.
                   9735: 
                   9736: Inputs:
                   9737: 
                   9738: =over 4
                   9739: 
                   9740: =item $Title: string, the title of the plot
                   9741: 
                   9742: =item $xlabel: string, text describing the X-axis of the plot
                   9743: 
                   9744: =item $ylabel: string, text describing the Y-axis of the plot
                   9745: 
                   9746: =item $Max: scalar, the maximum Y value to use in the plot
                   9747: If $Max is < any data point, the graph will not be rendered.
                   9748: 
1.140     matthew  9749: =item $colors: array ref holding the colors to be used for the data sets when
1.138     matthew  9750: they are plotted.  If undefined, default values will be used.
                   9751: 
1.178     matthew  9752: =item $labels: array ref holding the labels to use on the x-axis for the bars.
                   9753: 
1.138     matthew  9754: =item @Values: An array of array references.  Each array reference holds data
                   9755: to be plotted in a stacked bar chart.
                   9756: 
1.239     matthew  9757: =item If the final element of @Values is a hash reference the key/value
                   9758: pairs will be added to the graph definition.
                   9759: 
1.138     matthew  9760: =back
                   9761: 
                   9762: Returns:
                   9763: 
                   9764: An <img> tag which references graph.png and the appropriate identifying
                   9765: information for the plot.
                   9766: 
1.127     matthew  9767: =cut
                   9768: 
                   9769: ############################################################
                   9770: ############################################################
1.134     matthew  9771: sub DrawBarGraph {
1.178     matthew  9772:     my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134     matthew  9773:     #
                   9774:     if (! defined($colors)) {
                   9775:         $colors = ['#33ff00', 
                   9776:                   '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
                   9777:                   '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
                   9778:                   ]; 
                   9779:     }
1.228     matthew  9780:     my $extra_settings = {};
                   9781:     if (ref($Values[-1]) eq 'HASH') {
                   9782:         $extra_settings = pop(@Values);
                   9783:     }
1.127     matthew  9784:     #
1.136     matthew  9785:     my $identifier = &get_cgi_id();
                   9786:     my $id = 'cgi.'.$identifier;        
1.129     matthew  9787:     if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127     matthew  9788:         return '';
                   9789:     }
1.225     matthew  9790:     #
                   9791:     my @Labels;
                   9792:     if (defined($labels)) {
                   9793:         @Labels = @$labels;
                   9794:     } else {
                   9795:         for (my $i=0;$i<@{$Values[0]};$i++) {
                   9796:             push (@Labels,$i+1);
                   9797:         }
                   9798:     }
                   9799:     #
1.129     matthew  9800:     my $NumBars = scalar(@{$Values[0]});
1.225     matthew  9801:     if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129     matthew  9802:     my %ValuesHash;
                   9803:     my $NumSets=1;
                   9804:     foreach my $array (@Values) {
                   9805:         next if (! ref($array));
1.136     matthew  9806:         $ValuesHash{$id.'.data.'.$NumSets++} = 
1.132     matthew  9807:             join(',',@$array);
1.129     matthew  9808:     }
1.127     matthew  9809:     #
1.136     matthew  9810:     my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225     matthew  9811:     if ($NumBars < 3) {
                   9812:         $width = 120+$NumBars*32;
1.220     matthew  9813:         $xskip = 1;
1.225     matthew  9814:         $bar_width = 30;
                   9815:     } elsif ($NumBars < 5) {
                   9816:         $width = 120+$NumBars*20;
                   9817:         $xskip = 1;
                   9818:         $bar_width = 20;
1.220     matthew  9819:     } elsif ($NumBars < 10) {
1.136     matthew  9820:         $width = 120+$NumBars*15;
                   9821:         $xskip = 1;
                   9822:         $bar_width = 15;
                   9823:     } elsif ($NumBars <= 25) {
                   9824:         $width = 120+$NumBars*11;
                   9825:         $xskip = 5;
                   9826:         $bar_width = 8;
                   9827:     } elsif ($NumBars <= 50) {
                   9828:         $width = 120+$NumBars*8;
                   9829:         $xskip = 5;
                   9830:         $bar_width = 4;
                   9831:     } else {
                   9832:         $width = 120+$NumBars*8;
                   9833:         $xskip = 5;
                   9834:         $bar_width = 4;
                   9835:     }
                   9836:     #
1.137     matthew  9837:     $Max = 1 if ($Max < 1);
                   9838:     if ( int($Max) < $Max ) {
                   9839:         $Max++;
                   9840:         $Max = int($Max);
                   9841:     }
1.127     matthew  9842:     $Title  = '' if (! defined($Title));
                   9843:     $xlabel = '' if (! defined($xlabel));
                   9844:     $ylabel = '' if (! defined($ylabel));
1.369     www      9845:     $ValuesHash{$id.'.title'}    = &escape($Title);
                   9846:     $ValuesHash{$id.'.xlabel'}   = &escape($xlabel);
                   9847:     $ValuesHash{$id.'.ylabel'}   = &escape($ylabel);
1.137     matthew  9848:     $ValuesHash{$id.'.y_max_value'} = $Max;
1.136     matthew  9849:     $ValuesHash{$id.'.NumBars'}  = $NumBars;
                   9850:     $ValuesHash{$id.'.NumSets'}  = $NumSets;
                   9851:     $ValuesHash{$id.'.PlotType'} = 'bar';
                   9852:     $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   9853:     $ValuesHash{$id.'.height'}   = $height;
                   9854:     $ValuesHash{$id.'.width'}    = $width;
                   9855:     $ValuesHash{$id.'.xskip'}    = $xskip;
                   9856:     $ValuesHash{$id.'.bar_width'} = $bar_width;
                   9857:     $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127     matthew  9858:     #
1.228     matthew  9859:     # Deal with other parameters
                   9860:     while (my ($key,$value) = each(%$extra_settings)) {
                   9861:         $ValuesHash{$id.'.'.$key} = $value;
                   9862:     }
                   9863:     #
1.646     raeburn  9864:     &Apache::lonnet::appenv(\%ValuesHash);
1.137     matthew  9865:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   9866: }
                   9867: 
                   9868: ############################################################
                   9869: ############################################################
                   9870: 
                   9871: =pod
                   9872: 
1.648     raeburn  9873: =item * &DrawXYGraph()
1.137     matthew  9874: 
1.138     matthew  9875: Facilitates the plotting of data in an XY graph.
                   9876: Puts plot definition data into the users environment in order for 
                   9877: graph.png to plot it.  Returns an <img> tag for the plot.
                   9878: 
                   9879: Inputs:
                   9880: 
                   9881: =over 4
                   9882: 
                   9883: =item $Title: string, the title of the plot
                   9884: 
                   9885: =item $xlabel: string, text describing the X-axis of the plot
                   9886: 
                   9887: =item $ylabel: string, text describing the Y-axis of the plot
                   9888: 
                   9889: =item $Max: scalar, the maximum Y value to use in the plot
                   9890: If $Max is < any data point, the graph will not be rendered.
                   9891: 
                   9892: =item $colors: Array ref containing the hex color codes for the data to be 
                   9893: plotted in.  If undefined, default values will be used.
                   9894: 
                   9895: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   9896: 
                   9897: =item $Ydata: Array ref containing Array refs.  
1.185     www      9898: Each of the contained arrays will be plotted as a separate curve.
1.138     matthew  9899: 
                   9900: =item %Values: hash indicating or overriding any default values which are 
                   9901: passed to graph.png.  
                   9902: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   9903: 
                   9904: =back
                   9905: 
                   9906: Returns:
                   9907: 
                   9908: An <img> tag which references graph.png and the appropriate identifying
                   9909: information for the plot.
                   9910: 
1.137     matthew  9911: =cut
                   9912: 
                   9913: ############################################################
                   9914: ############################################################
                   9915: sub DrawXYGraph {
                   9916:     my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
                   9917:     #
                   9918:     # Create the identifier for the graph
                   9919:     my $identifier = &get_cgi_id();
                   9920:     my $id = 'cgi.'.$identifier;
                   9921:     #
                   9922:     $Title  = '' if (! defined($Title));
                   9923:     $xlabel = '' if (! defined($xlabel));
                   9924:     $ylabel = '' if (! defined($ylabel));
                   9925:     my %ValuesHash = 
                   9926:         (
1.369     www      9927:          $id.'.title'  => &escape($Title),
                   9928:          $id.'.xlabel' => &escape($xlabel),
                   9929:          $id.'.ylabel' => &escape($ylabel),
1.137     matthew  9930:          $id.'.y_max_value'=> $Max,
                   9931:          $id.'.labels'     => join(',',@$Xlabels),
                   9932:          $id.'.PlotType'   => 'XY',
                   9933:          );
                   9934:     #
                   9935:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   9936:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   9937:     }
                   9938:     #
                   9939:     if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
                   9940:         return '';
                   9941:     }
                   9942:     my $NumSets=1;
1.138     matthew  9943:     foreach my $array (@{$Ydata}){
1.137     matthew  9944:         next if (! ref($array));
                   9945:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
                   9946:     }
1.138     matthew  9947:     $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137     matthew  9948:     #
                   9949:     # Deal with other parameters
                   9950:     while (my ($key,$value) = each(%Values)) {
                   9951:         $ValuesHash{$id.'.'.$key} = $value;
1.127     matthew  9952:     }
                   9953:     #
1.646     raeburn  9954:     &Apache::lonnet::appenv(\%ValuesHash);
1.136     matthew  9955:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   9956: }
                   9957: 
                   9958: ############################################################
                   9959: ############################################################
                   9960: 
                   9961: =pod
                   9962: 
1.648     raeburn  9963: =item * &DrawXYYGraph()
1.138     matthew  9964: 
                   9965: Facilitates the plotting of data in an XY graph with two Y axes.
                   9966: Puts plot definition data into the users environment in order for 
                   9967: graph.png to plot it.  Returns an <img> tag for the plot.
                   9968: 
                   9969: Inputs:
                   9970: 
                   9971: =over 4
                   9972: 
                   9973: =item $Title: string, the title of the plot
                   9974: 
                   9975: =item $xlabel: string, text describing the X-axis of the plot
                   9976: 
                   9977: =item $ylabel: string, text describing the Y-axis of the plot
                   9978: 
                   9979: =item $colors: Array ref containing the hex color codes for the data to be 
                   9980: plotted in.  If undefined, default values will be used.
                   9981: 
                   9982: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   9983: 
                   9984: =item $Ydata1: The first data set
                   9985: 
                   9986: =item $Min1: The minimum value of the left Y-axis
                   9987: 
                   9988: =item $Max1: The maximum value of the left Y-axis
                   9989: 
                   9990: =item $Ydata2: The second data set
                   9991: 
                   9992: =item $Min2: The minimum value of the right Y-axis
                   9993: 
                   9994: =item $Max2: The maximum value of the left Y-axis
                   9995: 
                   9996: =item %Values: hash indicating or overriding any default values which are 
                   9997: passed to graph.png.  
                   9998: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   9999: 
                   10000: =back
                   10001: 
                   10002: Returns:
                   10003: 
                   10004: An <img> tag which references graph.png and the appropriate identifying
                   10005: information for the plot.
1.136     matthew  10006: 
                   10007: =cut
                   10008: 
                   10009: ############################################################
                   10010: ############################################################
1.137     matthew  10011: sub DrawXYYGraph {
                   10012:     my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
                   10013:                                         $Ydata2,$Min2,$Max2,%Values)=@_;
1.136     matthew  10014:     #
                   10015:     # Create the identifier for the graph
                   10016:     my $identifier = &get_cgi_id();
                   10017:     my $id = 'cgi.'.$identifier;
                   10018:     #
                   10019:     $Title  = '' if (! defined($Title));
                   10020:     $xlabel = '' if (! defined($xlabel));
                   10021:     $ylabel = '' if (! defined($ylabel));
                   10022:     my %ValuesHash = 
                   10023:         (
1.369     www      10024:          $id.'.title'  => &escape($Title),
                   10025:          $id.'.xlabel' => &escape($xlabel),
                   10026:          $id.'.ylabel' => &escape($ylabel),
1.136     matthew  10027:          $id.'.labels' => join(',',@$Xlabels),
                   10028:          $id.'.PlotType' => 'XY',
                   10029:          $id.'.NumSets' => 2,
1.137     matthew  10030:          $id.'.two_axes' => 1,
                   10031:          $id.'.y1_max_value' => $Max1,
                   10032:          $id.'.y1_min_value' => $Min1,
                   10033:          $id.'.y2_max_value' => $Max2,
                   10034:          $id.'.y2_min_value' => $Min2,
1.136     matthew  10035:          );
                   10036:     #
1.137     matthew  10037:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   10038:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   10039:     }
                   10040:     #
                   10041:     if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
                   10042:         ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136     matthew  10043:         return '';
                   10044:     }
                   10045:     my $NumSets=1;
1.137     matthew  10046:     foreach my $array ($Ydata1,$Ydata2){
1.136     matthew  10047:         next if (! ref($array));
                   10048:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137     matthew  10049:     }
                   10050:     #
                   10051:     # Deal with other parameters
                   10052:     while (my ($key,$value) = each(%Values)) {
                   10053:         $ValuesHash{$id.'.'.$key} = $value;
1.136     matthew  10054:     }
                   10055:     #
1.646     raeburn  10056:     &Apache::lonnet::appenv(\%ValuesHash);
1.130     albertel 10057:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139     matthew  10058: }
                   10059: 
                   10060: ############################################################
                   10061: ############################################################
                   10062: 
                   10063: =pod
                   10064: 
1.157     matthew  10065: =back 
                   10066: 
1.139     matthew  10067: =head1 Statistics helper routines?  
                   10068: 
                   10069: Bad place for them but what the hell.
                   10070: 
1.157     matthew  10071: =over 4
                   10072: 
1.648     raeburn  10073: =item * &chartlink()
1.139     matthew  10074: 
                   10075: Returns a link to the chart for a specific student.  
                   10076: 
                   10077: Inputs:
                   10078: 
                   10079: =over 4
                   10080: 
                   10081: =item $linktext: The text of the link
                   10082: 
                   10083: =item $sname: The students username
                   10084: 
                   10085: =item $sdomain: The students domain
                   10086: 
                   10087: =back
                   10088: 
1.157     matthew  10089: =back
                   10090: 
1.139     matthew  10091: =cut
                   10092: 
                   10093: ############################################################
                   10094: ############################################################
                   10095: sub chartlink {
                   10096:     my ($linktext, $sname, $sdomain) = @_;
                   10097:     my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369     www      10098:         '&amp;SelectedStudent='.&escape($sname.':'.$sdomain).
1.219     albertel 10099:         '&amp;chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139     matthew  10100:        '">'.$linktext.'</a>';
1.153     matthew  10101: }
                   10102: 
                   10103: #######################################################
                   10104: #######################################################
                   10105: 
                   10106: =pod
                   10107: 
                   10108: =head1 Course Environment Routines
1.157     matthew  10109: 
                   10110: =over 4
1.153     matthew  10111: 
1.648     raeburn  10112: =item * &restore_course_settings()
1.153     matthew  10113: 
1.648     raeburn  10114: =item * &store_course_settings()
1.153     matthew  10115: 
                   10116: Restores/Store indicated form parameters from the course environment.
                   10117: Will not overwrite existing values of the form parameters.
                   10118: 
                   10119: Inputs: 
                   10120: a scalar describing the data (e.g. 'chart', 'problem_analysis')
                   10121: 
                   10122: a hash ref describing the data to be stored.  For example:
                   10123:    
                   10124: %Save_Parameters = ('Status' => 'scalar',
                   10125:     'chartoutputmode' => 'scalar',
                   10126:     'chartoutputdata' => 'scalar',
                   10127:     'Section' => 'array',
1.373     raeburn  10128:     'Group' => 'array',
1.153     matthew  10129:     'StudentData' => 'array',
                   10130:     'Maps' => 'array');
                   10131: 
                   10132: Returns: both routines return nothing
                   10133: 
1.631     raeburn  10134: =back
                   10135: 
1.153     matthew  10136: =cut
                   10137: 
                   10138: #######################################################
                   10139: #######################################################
                   10140: sub store_course_settings {
1.496     albertel 10141:     return &store_settings($env{'request.course.id'},@_);
                   10142: }
                   10143: 
                   10144: sub store_settings {
1.153     matthew  10145:     # save to the environment
                   10146:     # appenv the same items, just to be safe
1.300     albertel 10147:     my $udom  = $env{'user.domain'};
                   10148:     my $uname = $env{'user.name'};
1.496     albertel 10149:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  10150:     my %SaveHash;
                   10151:     my %AppHash;
                   10152:     while (my ($setting,$type) = each(%$Settings)) {
1.496     albertel 10153:         my $basename = join('.','internal',$context,$prefix,$setting);
1.300     albertel 10154:         my $envname = 'environment.'.$basename;
1.258     albertel 10155:         if (exists($env{'form.'.$setting})) {
1.153     matthew  10156:             # Save this value away
                   10157:             if ($type eq 'scalar' &&
1.258     albertel 10158:                 (! exists($env{$envname}) || 
                   10159:                  $env{$envname} ne $env{'form.'.$setting})) {
                   10160:                 $SaveHash{$basename} = $env{'form.'.$setting};
                   10161:                 $AppHash{$envname}   = $env{'form.'.$setting};
1.153     matthew  10162:             } elsif ($type eq 'array') {
                   10163:                 my $stored_form;
1.258     albertel 10164:                 if (ref($env{'form.'.$setting})) {
1.153     matthew  10165:                     $stored_form = join(',',
                   10166:                                         map {
1.369     www      10167:                                             &escape($_);
1.258     albertel 10168:                                         } sort(@{$env{'form.'.$setting}}));
1.153     matthew  10169:                 } else {
                   10170:                     $stored_form = 
1.369     www      10171:                         &escape($env{'form.'.$setting});
1.153     matthew  10172:                 }
                   10173:                 # Determine if the array contents are the same.
1.258     albertel 10174:                 if ($stored_form ne $env{$envname}) {
1.153     matthew  10175:                     $SaveHash{$basename} = $stored_form;
                   10176:                     $AppHash{$envname}   = $stored_form;
                   10177:                 }
                   10178:             }
                   10179:         }
                   10180:     }
                   10181:     my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300     albertel 10182:                                           $udom,$uname);
1.153     matthew  10183:     if ($put_result !~ /^(ok|delayed)/) {
                   10184:         &Apache::lonnet::logthis('unable to save form parameters, '.
                   10185:                                  'got error:'.$put_result);
                   10186:     }
                   10187:     # Make sure these settings stick around in this session, too
1.646     raeburn  10188:     &Apache::lonnet::appenv(\%AppHash);
1.153     matthew  10189:     return;
                   10190: }
                   10191: 
                   10192: sub restore_course_settings {
1.499     albertel 10193:     return &restore_settings($env{'request.course.id'},@_);
1.496     albertel 10194: }
                   10195: 
                   10196: sub restore_settings {
                   10197:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  10198:     while (my ($setting,$type) = each(%$Settings)) {
1.258     albertel 10199:         next if (exists($env{'form.'.$setting}));
1.496     albertel 10200:         my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153     matthew  10201:             '.'.$setting;
1.258     albertel 10202:         if (exists($env{$envname})) {
1.153     matthew  10203:             if ($type eq 'scalar') {
1.258     albertel 10204:                 $env{'form.'.$setting} = $env{$envname};
1.153     matthew  10205:             } elsif ($type eq 'array') {
1.258     albertel 10206:                 $env{'form.'.$setting} = [ 
1.153     matthew  10207:                                            map { 
1.369     www      10208:                                                &unescape($_); 
1.258     albertel 10209:                                            } split(',',$env{$envname})
1.153     matthew  10210:                                            ];
                   10211:             }
                   10212:         }
                   10213:     }
1.127     matthew  10214: }
                   10215: 
1.618     raeburn  10216: #######################################################
                   10217: #######################################################
                   10218: 
                   10219: =pod
                   10220: 
                   10221: =head1 Domain E-mail Routines  
                   10222: 
                   10223: =over 4
                   10224: 
1.648     raeburn  10225: =item * &build_recipient_list()
1.618     raeburn  10226: 
1.884     raeburn  10227: Build recipient lists for five types of e-mail:
1.766     raeburn  10228: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884     raeburn  10229: (d) Help requests, (e) Course requests needing approval,  generated by
                   10230: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
                   10231: loncoursequeueadmin.pm respectively.
1.618     raeburn  10232: 
                   10233: Inputs:
1.619     raeburn  10234: defmail (scalar - email address of default recipient), 
1.618     raeburn  10235: mailing type (scalar - errormail, packagesmail, or helpdeskmail), 
1.619     raeburn  10236: defdom (domain for which to retrieve configuration settings),
                   10237: origmail (scalar - email address of recipient from loncapa.conf, 
                   10238: i.e., predates configuration by DC via domainprefs.pm 
1.618     raeburn  10239: 
1.655     raeburn  10240: Returns: comma separated list of addresses to which to send e-mail.
                   10241: 
                   10242: =back
1.618     raeburn  10243: 
                   10244: =cut
                   10245: 
                   10246: ############################################################
                   10247: ############################################################
                   10248: sub build_recipient_list {
1.619     raeburn  10249:     my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618     raeburn  10250:     my @recipients;
                   10251:     my $otheremails;
                   10252:     my %domconfig =
                   10253:          &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
                   10254:     if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766     raeburn  10255:         if (exists($domconfig{'contacts'}{$mailing})) {
                   10256:             if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
                   10257:                 my @contacts = ('adminemail','supportemail');
                   10258:                 foreach my $item (@contacts) {
                   10259:                     if ($domconfig{'contacts'}{$mailing}{$item}) {
                   10260:                         my $addr = $domconfig{'contacts'}{$item}; 
                   10261:                         if (!grep(/^\Q$addr\E$/,@recipients)) {
                   10262:                             push(@recipients,$addr);
                   10263:                         }
1.619     raeburn  10264:                     }
1.766     raeburn  10265:                     $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618     raeburn  10266:                 }
                   10267:             }
1.766     raeburn  10268:         } elsif ($origmail ne '') {
                   10269:             push(@recipients,$origmail);
1.618     raeburn  10270:         }
1.619     raeburn  10271:     } elsif ($origmail ne '') {
                   10272:         push(@recipients,$origmail);
1.618     raeburn  10273:     }
1.688     raeburn  10274:     if (defined($defmail)) {
                   10275:         if ($defmail ne '') {
                   10276:             push(@recipients,$defmail);
                   10277:         }
1.618     raeburn  10278:     }
                   10279:     if ($otheremails) {
1.619     raeburn  10280:         my @others;
                   10281:         if ($otheremails =~ /,/) {
                   10282:             @others = split(/,/,$otheremails);
1.618     raeburn  10283:         } else {
1.619     raeburn  10284:             push(@others,$otheremails);
                   10285:         }
                   10286:         foreach my $addr (@others) {
                   10287:             if (!grep(/^\Q$addr\E$/,@recipients)) {
                   10288:                 push(@recipients,$addr);
                   10289:             }
1.618     raeburn  10290:         }
                   10291:     }
1.619     raeburn  10292:     my $recipientlist = join(',',@recipients); 
1.618     raeburn  10293:     return $recipientlist;
                   10294: }
                   10295: 
1.127     matthew  10296: ############################################################
                   10297: ############################################################
1.154     albertel 10298: 
1.655     raeburn  10299: =pod
                   10300: 
                   10301: =head1 Course Catalog Routines
                   10302: 
                   10303: =over 4
                   10304: 
                   10305: =item * &gather_categories()
                   10306: 
                   10307: Converts category definitions - keys of categories hash stored in  
                   10308: coursecategories in configuration.db on the primary library server in a 
                   10309: domain - to an array.  Also generates javascript and idx hash used to 
                   10310: generate Domain Coordinator interface for editing Course Categories.
                   10311: 
                   10312: Inputs:
1.663     raeburn  10313: 
1.655     raeburn  10314: categories (reference to hash of category definitions).
1.663     raeburn  10315: 
1.655     raeburn  10316: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   10317:       categories and subcategories).
1.663     raeburn  10318: 
1.655     raeburn  10319: idx (reference to hash of counters used in Domain Coordinator interface for 
                   10320:       editing Course Categories).
1.663     raeburn  10321: 
1.655     raeburn  10322: jsarray (reference to array of categories used to create Javascript arrays for
                   10323:          Domain Coordinator interface for editing Course Categories).
                   10324: 
                   10325: Returns: nothing
                   10326: 
                   10327: Side effects: populates cats, idx and jsarray. 
                   10328: 
                   10329: =cut
                   10330: 
                   10331: sub gather_categories {
                   10332:     my ($categories,$cats,$idx,$jsarray) = @_;
                   10333:     my %counters;
                   10334:     my $num = 0;
                   10335:     foreach my $item (keys(%{$categories})) {
                   10336:         my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   10337:         if ($container eq '' && $depth == 0) {
                   10338:             $cats->[$depth][$categories->{$item}] = $cat;
                   10339:         } else {
                   10340:             $cats->[$depth]{$container}[$categories->{$item}] = $cat;
                   10341:         }
                   10342:         my ($escitem,$tail) = split(/:/,$item,2);
                   10343:         if ($counters{$tail} eq '') {
                   10344:             $counters{$tail} = $num;
                   10345:             $num ++;
                   10346:         }
                   10347:         if (ref($idx) eq 'HASH') {
                   10348:             $idx->{$item} = $counters{$tail};
                   10349:         }
                   10350:         if (ref($jsarray) eq 'ARRAY') {
                   10351:             push(@{$jsarray->[$counters{$tail}]},$item);
                   10352:         }
                   10353:     }
                   10354:     return;
                   10355: }
                   10356: 
                   10357: =pod
                   10358: 
                   10359: =item * &extract_categories()
                   10360: 
                   10361: Used to generate breadcrumb trails for course categories.
                   10362: 
                   10363: Inputs:
1.663     raeburn  10364: 
1.655     raeburn  10365: categories (reference to hash of category definitions).
1.663     raeburn  10366: 
1.655     raeburn  10367: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   10368:       categories and subcategories).
1.663     raeburn  10369: 
1.655     raeburn  10370: trails (reference to array of breacrumb trails for each category).
1.663     raeburn  10371: 
1.655     raeburn  10372: allitems (reference to hash - key is category key 
                   10373:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  10374: 
1.655     raeburn  10375: idx (reference to hash of counters used in Domain Coordinator interface for
                   10376:       editing Course Categories).
1.663     raeburn  10377: 
1.655     raeburn  10378: jsarray (reference to array of categories used to create Javascript arrays for
                   10379:          Domain Coordinator interface for editing Course Categories).
                   10380: 
1.665     raeburn  10381: subcats (reference to hash of arrays containing all subcategories within each 
                   10382:          category, -recursive)
                   10383: 
1.655     raeburn  10384: Returns: nothing
                   10385: 
                   10386: Side effects: populates trails and allitems hash references.
                   10387: 
                   10388: =cut
                   10389: 
                   10390: sub extract_categories {
1.665     raeburn  10391:     my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655     raeburn  10392:     if (ref($categories) eq 'HASH') {
                   10393:         &gather_categories($categories,$cats,$idx,$jsarray);
                   10394:         if (ref($cats->[0]) eq 'ARRAY') {
                   10395:             for (my $i=0; $i<@{$cats->[0]}; $i++) {
                   10396:                 my $name = $cats->[0][$i];
                   10397:                 my $item = &escape($name).'::0';
                   10398:                 my $trailstr;
                   10399:                 if ($name eq 'instcode') {
                   10400:                     $trailstr = &mt('Official courses (with institutional codes)');
1.919     raeburn  10401:                 } elsif ($name eq 'communities') {
                   10402:                     $trailstr = &mt('Communities');
1.655     raeburn  10403:                 } else {
                   10404:                     $trailstr = $name;
                   10405:                 }
                   10406:                 if ($allitems->{$item} eq '') {
                   10407:                     push(@{$trails},$trailstr);
                   10408:                     $allitems->{$item} = scalar(@{$trails})-1;
                   10409:                 }
                   10410:                 my @parents = ($name);
                   10411:                 if (ref($cats->[1]{$name}) eq 'ARRAY') {
                   10412:                     for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
                   10413:                         my $category = $cats->[1]{$name}[$j];
1.665     raeburn  10414:                         if (ref($subcats) eq 'HASH') {
                   10415:                             push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
                   10416:                         }
                   10417:                         &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
                   10418:                     }
                   10419:                 } else {
                   10420:                     if (ref($subcats) eq 'HASH') {
                   10421:                         $subcats->{$item} = [];
1.655     raeburn  10422:                     }
                   10423:                 }
                   10424:             }
                   10425:         }
                   10426:     }
                   10427:     return;
                   10428: }
                   10429: 
                   10430: =pod
                   10431: 
                   10432: =item *&recurse_categories()
                   10433: 
                   10434: Recursively used to generate breadcrumb trails for course categories.
                   10435: 
                   10436: Inputs:
1.663     raeburn  10437: 
1.655     raeburn  10438: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   10439:       categories and subcategories).
1.663     raeburn  10440: 
1.655     raeburn  10441: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663     raeburn  10442: 
                   10443: category (current course category, for which breadcrumb trail is being generated).
                   10444: 
                   10445: trails (reference to array of breadcrumb trails for each category).
                   10446: 
1.655     raeburn  10447: allitems (reference to hash - key is category key
                   10448:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  10449: 
1.655     raeburn  10450: parents (array containing containers directories for current category, 
                   10451:          back to top level). 
                   10452: 
                   10453: Returns: nothing
                   10454: 
                   10455: Side effects: populates trails and allitems hash references
                   10456: 
                   10457: =cut
                   10458: 
                   10459: sub recurse_categories {
1.665     raeburn  10460:     my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655     raeburn  10461:     my $shallower = $depth - 1;
                   10462:     if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
                   10463:         for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
                   10464:             my $name = $cats->[$depth]{$category}[$k];
                   10465:             my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   10466:             my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   10467:             if ($allitems->{$item} eq '') {
                   10468:                 push(@{$trails},$trailstr);
                   10469:                 $allitems->{$item} = scalar(@{$trails})-1;
                   10470:             }
                   10471:             my $deeper = $depth+1;
                   10472:             push(@{$parents},$category);
1.665     raeburn  10473:             if (ref($subcats) eq 'HASH') {
                   10474:                 my $subcat = &escape($name).':'.$category.':'.$depth;
                   10475:                 for (my $j=@{$parents}; $j>=0; $j--) {
                   10476:                     my $higher;
                   10477:                     if ($j > 0) {
                   10478:                         $higher = &escape($parents->[$j]).':'.
                   10479:                                   &escape($parents->[$j-1]).':'.$j;
                   10480:                     } else {
                   10481:                         $higher = &escape($parents->[$j]).'::'.$j;
                   10482:                     }
                   10483:                     push(@{$subcats->{$higher}},$subcat);
                   10484:                 }
                   10485:             }
                   10486:             &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
                   10487:                                 $subcats);
1.655     raeburn  10488:             pop(@{$parents});
                   10489:         }
                   10490:     } else {
                   10491:         my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   10492:         my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   10493:         if ($allitems->{$item} eq '') {
                   10494:             push(@{$trails},$trailstr);
                   10495:             $allitems->{$item} = scalar(@{$trails})-1;
                   10496:         }
                   10497:     }
                   10498:     return;
                   10499: }
                   10500: 
1.663     raeburn  10501: =pod
                   10502: 
                   10503: =item *&assign_categories_table()
                   10504: 
                   10505: Create a datatable for display of hierarchical categories in a domain,
                   10506: with checkboxes to allow a course to be categorized. 
                   10507: 
                   10508: Inputs:
                   10509: 
                   10510: cathash - reference to hash of categories defined for the domain (from
                   10511:           configuration.db)
                   10512: 
                   10513: currcat - scalar with an & separated list of categories assigned to a course. 
                   10514: 
1.919     raeburn  10515: type    - scalar contains course type (Course or Community).
                   10516: 
1.663     raeburn  10517: Returns: $output (markup to be displayed) 
                   10518: 
                   10519: =cut
                   10520: 
                   10521: sub assign_categories_table {
1.919     raeburn  10522:     my ($cathash,$currcat,$type) = @_;
1.663     raeburn  10523:     my $output;
                   10524:     if (ref($cathash) eq 'HASH') {
                   10525:         my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
                   10526:         &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
                   10527:         $maxdepth = scalar(@cats);
                   10528:         if (@cats > 0) {
                   10529:             my $itemcount = 0;
                   10530:             if (ref($cats[0]) eq 'ARRAY') {
                   10531:                 my @currcategories;
                   10532:                 if ($currcat ne '') {
                   10533:                     @currcategories = split('&',$currcat);
                   10534:                 }
1.919     raeburn  10535:                 my $table;
1.663     raeburn  10536:                 for (my $i=0; $i<@{$cats[0]}; $i++) {
                   10537:                     my $parent = $cats[0][$i];
1.919     raeburn  10538:                     next if ($parent eq 'instcode');
                   10539:                     if ($type eq 'Community') {
                   10540:                         next unless ($parent eq 'communities');
                   10541:                     } else {
                   10542:                         next if ($parent eq 'communities');
                   10543:                     }
1.663     raeburn  10544:                     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   10545:                     my $item = &escape($parent).'::0';
                   10546:                     my $checked = '';
                   10547:                     if (@currcategories > 0) {
                   10548:                         if (grep(/^\Q$item\E$/,@currcategories)) {
1.772     bisitz   10549:                             $checked = ' checked="checked"';
1.663     raeburn  10550:                         }
                   10551:                     }
1.919     raeburn  10552:                     my $parent_title = $parent;
                   10553:                     if ($parent eq 'communities') {
                   10554:                         $parent_title = &mt('Communities');
                   10555:                     }
                   10556:                     $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
                   10557:                               '<input type="checkbox" name="usecategory" value="'.
                   10558:                               $item.'"'.$checked.' />'.$parent_title.'</span>'.
                   10559:                               '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663     raeburn  10560:                     my $depth = 1;
                   10561:                     push(@path,$parent);
1.919     raeburn  10562:                     $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663     raeburn  10563:                     pop(@path);
1.919     raeburn  10564:                     $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663     raeburn  10565:                     $itemcount ++;
                   10566:                 }
1.919     raeburn  10567:                 if ($itemcount) {
                   10568:                     $output = &Apache::loncommon::start_data_table().
                   10569:                               $table.
                   10570:                               &Apache::loncommon::end_data_table();
                   10571:                 }
1.663     raeburn  10572:             }
                   10573:         }
                   10574:     }
                   10575:     return $output;
                   10576: }
                   10577: 
                   10578: =pod
                   10579: 
                   10580: =item *&assign_category_rows()
                   10581: 
                   10582: Create a datatable row for display of nested categories in a domain,
                   10583: with checkboxes to allow a course to be categorized,called recursively.
                   10584: 
                   10585: Inputs:
                   10586: 
                   10587: itemcount - track row number for alternating colors
                   10588: 
                   10589: cats - reference to array of arrays/hashes which encapsulates hierarchy of
                   10590:       categories and subcategories.
                   10591: 
                   10592: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
                   10593: 
                   10594: parent - parent of current category item
                   10595: 
                   10596: path - Array containing all categories back up through the hierarchy from the
                   10597:        current category to the top level.
                   10598: 
                   10599: currcategories - reference to array of current categories assigned to the course
                   10600: 
                   10601: Returns: $output (markup to be displayed).
                   10602: 
                   10603: =cut
                   10604: 
                   10605: sub assign_category_rows {
                   10606:     my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
                   10607:     my ($text,$name,$item,$chgstr);
                   10608:     if (ref($cats) eq 'ARRAY') {
                   10609:         my $maxdepth = scalar(@{$cats});
                   10610:         if (ref($cats->[$depth]) eq 'HASH') {
                   10611:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   10612:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   10613:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   10614:                 $text .= '<td><table class="LC_datatable">';
                   10615:                 for (my $j=0; $j<$numchildren; $j++) {
                   10616:                     $name = $cats->[$depth]{$parent}[$j];
                   10617:                     $item = &escape($name).':'.&escape($parent).':'.$depth;
                   10618:                     my $deeper = $depth+1;
                   10619:                     my $checked = '';
                   10620:                     if (ref($currcategories) eq 'ARRAY') {
                   10621:                         if (@{$currcategories} > 0) {
                   10622:                             if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772     bisitz   10623:                                 $checked = ' checked="checked"';
1.663     raeburn  10624:                             }
                   10625:                         }
                   10626:                     }
1.664     raeburn  10627:                     $text .= '<tr><td><span class="LC_nobreak"><label>'.
                   10628:                              '<input type="checkbox" name="usecategory" value="'.
1.675     raeburn  10629:                              $item.'"'.$checked.' />'.$name.'</label></span>'.
                   10630:                              '<input type="hidden" name="catname" value="'.$name.'" />'.
                   10631:                              '</td><td>';
1.663     raeburn  10632:                     if (ref($path) eq 'ARRAY') {
                   10633:                         push(@{$path},$name);
                   10634:                         $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
                   10635:                         pop(@{$path});
                   10636:                     }
                   10637:                     $text .= '</td></tr>';
                   10638:                 }
                   10639:                 $text .= '</table></td>';
                   10640:             }
                   10641:         }
                   10642:     }
                   10643:     return $text;
                   10644: }
                   10645: 
1.655     raeburn  10646: ############################################################
                   10647: ############################################################
                   10648: 
                   10649: 
1.443     albertel 10650: sub commit_customrole {
1.664     raeburn  10651:     my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630     raeburn  10652:     my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443     albertel 10653:                          ($start?', '.&mt('starting').' '.localtime($start):'').
                   10654:                          ($end?', ending '.localtime($end):'').': <b>'.
                   10655:               &Apache::lonnet::assigncustomrole(
1.664     raeburn  10656:                  $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443     albertel 10657:                  '</b><br />';
                   10658:     return $output;
                   10659: }
                   10660: 
                   10661: sub commit_standardrole {
1.541     raeburn  10662:     my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
                   10663:     my ($output,$logmsg,$linefeed);
                   10664:     if ($context eq 'auto') {
                   10665:         $linefeed = "\n";
                   10666:     } else {
                   10667:         $linefeed = "<br />\n";
                   10668:     }  
1.443     albertel 10669:     if ($three eq 'st') {
1.541     raeburn  10670:         my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
                   10671:                                          $one,$two,$sec,$context);
                   10672:         if (($result =~ /^error/) || ($result eq 'not_in_class') || 
1.626     raeburn  10673:             ($result eq 'unknown_course') || ($result eq 'refused')) {
                   10674:             $output = $logmsg.' '.&mt('Error: ').$result."\n"; 
1.443     albertel 10675:         } else {
1.541     raeburn  10676:             $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443     albertel 10677:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  10678:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
                   10679:             if ($context eq 'auto') {
                   10680:                 $output .= $result.$linefeed.&mt('Add to classlist').': ok';
                   10681:             } else {
                   10682:                $output .= '<b>'.$result.'</b>'.$linefeed.
                   10683:                &mt('Add to classlist').': <b>ok</b>';
                   10684:             }
                   10685:             $output .= $linefeed;
1.443     albertel 10686:         }
                   10687:     } else {
                   10688:         $output = &mt('Assigning').' '.$three.' in '.$url.
                   10689:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  10690:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652     raeburn  10691:         my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541     raeburn  10692:         if ($context eq 'auto') {
                   10693:             $output .= $result.$linefeed;
                   10694:         } else {
                   10695:             $output .= '<b>'.$result.'</b>'.$linefeed;
                   10696:         }
1.443     albertel 10697:     }
                   10698:     return $output;
                   10699: }
                   10700: 
                   10701: sub commit_studentrole {
1.541     raeburn  10702:     my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626     raeburn  10703:     my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541     raeburn  10704:     if ($context eq 'auto') {
                   10705:         $linefeed = "\n";
                   10706:     } else {
                   10707:         $linefeed = '<br />'."\n";
                   10708:     }
1.443     albertel 10709:     if (defined($one) && defined($two)) {
                   10710:         my $cid=$one.'_'.$two;
                   10711:         my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
                   10712:         my $secchange = 0;
                   10713:         my $expire_role_result;
                   10714:         my $modify_section_result;
1.628     raeburn  10715:         if ($oldsec ne '-1') { 
                   10716:             if ($oldsec ne $sec) {
1.443     albertel 10717:                 $secchange = 1;
1.628     raeburn  10718:                 my $now = time;
1.443     albertel 10719:                 my $uurl='/'.$cid;
                   10720:                 $uurl=~s/\_/\//g;
                   10721:                 if ($oldsec) {
                   10722:                     $uurl.='/'.$oldsec;
                   10723:                 }
1.626     raeburn  10724:                 $oldsecurl = $uurl;
1.628     raeburn  10725:                 $expire_role_result = 
1.652     raeburn  10726:                     &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628     raeburn  10727:                 if ($env{'request.course.sec'} ne '') { 
                   10728:                     if ($expire_role_result eq 'refused') {
                   10729:                         my @roles = ('st');
                   10730:                         my @statuses = ('previous');
                   10731:                         my @roledoms = ($one);
                   10732:                         my $withsec = 1;
                   10733:                         my %roleshash = 
                   10734:                             &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
                   10735:                                               \@statuses,\@roles,\@roledoms,$withsec);
                   10736:                         if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
                   10737:                             my ($oldstart,$oldend) = 
                   10738:                                 split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
                   10739:                             if ($oldend > 0 && $oldend <= $now) {
                   10740:                                 $expire_role_result = 'ok';
                   10741:                             }
                   10742:                         }
                   10743:                     }
                   10744:                 }
1.443     albertel 10745:                 $result = $expire_role_result;
                   10746:             }
                   10747:         }
                   10748:         if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652     raeburn  10749:             $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443     albertel 10750:             if ($modify_section_result =~ /^ok/) {
                   10751:                 if ($secchange == 1) {
1.628     raeburn  10752:                     if ($sec eq '') {
                   10753:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
                   10754:                     } else {
                   10755:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
                   10756:                     }
1.443     albertel 10757:                 } elsif ($oldsec eq '-1') {
1.628     raeburn  10758:                     if ($sec eq '') {
                   10759:                         $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
                   10760:                     } else {
                   10761:                         $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   10762:                     }
1.443     albertel 10763:                 } else {
1.628     raeburn  10764:                     if ($sec eq '') {
                   10765:                         $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
                   10766:                     } else {
                   10767:                         $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   10768:                     }
1.443     albertel 10769:                 }
                   10770:             } else {
1.628     raeburn  10771:                 if ($secchange) {       
                   10772:                     $$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;
                   10773:                 } else {
                   10774:                     $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
                   10775:                 }
1.443     albertel 10776:             }
                   10777:             $result = $modify_section_result;
                   10778:         } elsif ($secchange == 1) {
1.628     raeburn  10779:             if ($oldsec eq '') {
                   10780:                 $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
                   10781:             } else {
                   10782:                 $$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;
                   10783:             }
1.626     raeburn  10784:             if ($expire_role_result eq 'refused') {
                   10785:                 my $newsecurl = '/'.$cid;
                   10786:                 $newsecurl =~ s/\_/\//g;
                   10787:                 if ($sec ne '') {
                   10788:                     $newsecurl.='/'.$sec;
                   10789:                 }
                   10790:                 if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
                   10791:                     if ($sec eq '') {
                   10792:                         $$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;
                   10793:                     } else {
                   10794:                         $$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;
                   10795:                     }
                   10796:                 }
                   10797:             }
1.443     albertel 10798:         }
                   10799:     } else {
1.626     raeburn  10800:         $$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 10801:         $result = "error: incomplete course id\n";
                   10802:     }
                   10803:     return $result;
                   10804: }
                   10805: 
                   10806: ############################################################
                   10807: ############################################################
                   10808: 
1.566     albertel 10809: sub check_clone {
1.578     raeburn  10810:     my ($args,$linefeed) = @_;
1.566     albertel 10811:     my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
                   10812:     my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
                   10813:     my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
                   10814:     my $clonemsg;
                   10815:     my $can_clone = 0;
1.944     raeburn  10816:     my $lctype = lc($args->{'crstype'});
1.908     raeburn  10817:     if ($lctype ne 'community') {
                   10818:         $lctype = 'course';
                   10819:     }
1.566     albertel 10820:     if ($clonehome eq 'no_host') {
1.944     raeburn  10821:         if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  10822:             $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'});
                   10823:         } else {
                   10824:             $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'});
                   10825:         }     
1.566     albertel 10826:     } else {
                   10827: 	my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944     raeburn  10828:         if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  10829:             if ($clonedesc{'type'} ne 'Community') {
                   10830:                  $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'});
                   10831:                 return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   10832:             }
                   10833:         }
1.882     raeburn  10834: 	if (($env{'request.role.domain'} eq $args->{'clonedomain'}) && 
                   10835:             (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566     albertel 10836: 	    $can_clone = 1;
                   10837: 	} else {
                   10838: 	    my %clonehash = &Apache::lonnet::get('environment',['cloners'],
                   10839: 						 $args->{'clonedomain'},$args->{'clonecourse'});
                   10840: 	    my @cloners = split(/,/,$clonehash{'cloners'});
1.578     raeburn  10841:             if (grep(/^\*$/,@cloners)) {
                   10842:                 $can_clone = 1;
                   10843:             } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
                   10844:                 $can_clone = 1;
                   10845:             } else {
1.908     raeburn  10846:                 my $ccrole = 'cc';
1.944     raeburn  10847:                 if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  10848:                     $ccrole = 'co';
                   10849:                 }
1.578     raeburn  10850: 	        my %roleshash =
                   10851: 		    &Apache::lonnet::get_my_roles($args->{'ccuname'},
                   10852: 					 $args->{'ccdomain'},
1.908     raeburn  10853:                                          'userroles',['active'],[$ccrole],
1.578     raeburn  10854: 					 [$args->{'clonedomain'}]);
1.908     raeburn  10855: 	        if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942     raeburn  10856:                     $can_clone = 1;
                   10857:                 } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
                   10858:                     $can_clone = 1;
                   10859:                 } else {
1.944     raeburn  10860:                     if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  10861:                         $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'});
                   10862:                     } else {
                   10863:                         $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'});
                   10864:                     }
1.578     raeburn  10865: 	        }
1.566     albertel 10866: 	    }
1.578     raeburn  10867:         }
1.566     albertel 10868:     }
                   10869:     return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   10870: }
                   10871: 
1.444     albertel 10872: sub construct_course {
1.885     raeburn  10873:     my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444     albertel 10874:     my $outcome;
1.541     raeburn  10875:     my $linefeed =  '<br />'."\n";
                   10876:     if ($context eq 'auto') {
                   10877:         $linefeed = "\n";
                   10878:     }
1.566     albertel 10879: 
                   10880: #
                   10881: # Are we cloning?
                   10882: #
                   10883:     my ($can_clone, $clonemsg, $cloneid, $clonehome);
                   10884:     if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578     raeburn  10885: 	($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566     albertel 10886: 	if ($context ne 'auto') {
1.578     raeburn  10887:             if ($clonemsg ne '') {
                   10888: 	        $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
                   10889:             }
1.566     albertel 10890: 	}
                   10891: 	$outcome .= $clonemsg.$linefeed;
                   10892: 
                   10893:         if (!$can_clone) {
                   10894: 	    return (0,$outcome);
                   10895: 	}
                   10896:     }
                   10897: 
1.444     albertel 10898: #
                   10899: # Open course
                   10900: #
                   10901:     my $crstype = lc($args->{'crstype'});
                   10902:     my %cenv=();
                   10903:     $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
                   10904:                                              $args->{'cdescr'},
                   10905:                                              $args->{'curl'},
                   10906:                                              $args->{'course_home'},
                   10907:                                              $args->{'nonstandard'},
                   10908:                                              $args->{'crscode'},
                   10909:                                              $args->{'ccuname'}.':'.
                   10910:                                              $args->{'ccdomain'},
1.882     raeburn  10911:                                              $args->{'crstype'},
1.885     raeburn  10912:                                              $cnum,$context,$category);
1.444     albertel 10913: 
                   10914:     # Note: The testing routines depend on this being output; see 
                   10915:     # Utils::Course. This needs to at least be output as a comment
                   10916:     # if anyone ever decides to not show this, and Utils::Course::new
                   10917:     # will need to be suitably modified.
1.541     raeburn  10918:     $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943     raeburn  10919:     if ($$courseid =~ /^error:/) {
                   10920:         return (0,$outcome);
                   10921:     }
                   10922: 
1.444     albertel 10923: #
                   10924: # Check if created correctly
                   10925: #
1.479     albertel 10926:     ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444     albertel 10927:     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943     raeburn  10928:     if ($crsuhome eq 'no_host') {
                   10929:         $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
                   10930:         return (0,$outcome);
                   10931:     }
1.541     raeburn  10932:     $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566     albertel 10933: 
1.444     albertel 10934: #
1.566     albertel 10935: # Do the cloning
                   10936: #   
                   10937:     if ($can_clone && $cloneid) {
                   10938: 	$clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
                   10939: 	if ($context ne 'auto') {
                   10940: 	    $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
                   10941: 	}
                   10942: 	$outcome .= $clonemsg.$linefeed;
                   10943: 	my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444     albertel 10944: # Copy all files
1.637     www      10945: 	&Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444     albertel 10946: # Restore URL
1.566     albertel 10947: 	$cenv{'url'}=$oldcenv{'url'};
1.444     albertel 10948: # Restore title
1.566     albertel 10949: 	$cenv{'description'}=$oldcenv{'description'};
1.955     raeburn  10950: # Restore creation date, creator and creation context.
                   10951:         $cenv{'internal.created'}=$oldcenv{'internal.created'};
                   10952:         $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
                   10953:         $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444     albertel 10954: # Mark as cloned
1.566     albertel 10955: 	$cenv{'clonedfrom'}=$cloneid;
1.638     www      10956: # Need to clone grading mode
                   10957:         my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
                   10958:         $cenv{'grading'}=$newenv{'grading'};
                   10959: # Do not clone these environment entries
                   10960:         &Apache::lonnet::del('environment',
                   10961:                   ['default_enrollment_start_date',
                   10962:                    'default_enrollment_end_date',
                   10963:                    'question.email',
                   10964:                    'policy.email',
                   10965:                    'comment.email',
                   10966:                    'pch.users.denied',
1.725     raeburn  10967:                    'plc.users.denied',
                   10968:                    'hidefromcat',
                   10969:                    'categories'],
1.638     www      10970:                    $$crsudom,$$crsunum);
1.444     albertel 10971:     }
1.566     albertel 10972: 
1.444     albertel 10973: #
                   10974: # Set environment (will override cloned, if existing)
                   10975: #
                   10976:     my @sections = ();
                   10977:     my @xlists = ();
                   10978:     if ($args->{'crstype'}) {
                   10979:         $cenv{'type'}=$args->{'crstype'};
                   10980:     }
                   10981:     if ($args->{'crsid'}) {
                   10982:         $cenv{'courseid'}=$args->{'crsid'};
                   10983:     }
                   10984:     if ($args->{'crscode'}) {
                   10985:         $cenv{'internal.coursecode'}=$args->{'crscode'};
                   10986:     }
                   10987:     if ($args->{'crsquota'} ne '') {
                   10988:         $cenv{'internal.coursequota'}=$args->{'crsquota'};
                   10989:     } else {
                   10990:         $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
                   10991:     }
                   10992:     if ($args->{'ccuname'}) {
                   10993:         $cenv{'internal.courseowner'} = $args->{'ccuname'}.
                   10994:                                         ':'.$args->{'ccdomain'};
                   10995:     } else {
                   10996:         $cenv{'internal.courseowner'} = $args->{'curruser'};
                   10997:     }
                   10998:     my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
                   10999:     if ($args->{'crssections'}) {
                   11000:         $cenv{'internal.sectionnums'} = '';
                   11001:         if ($args->{'crssections'} =~ m/,/) {
                   11002:             @sections = split/,/,$args->{'crssections'};
                   11003:         } else {
                   11004:             $sections[0] = $args->{'crssections'};
                   11005:         }
                   11006:         if (@sections > 0) {
                   11007:             foreach my $item (@sections) {
                   11008:                 my ($sec,$gp) = split/:/,$item;
                   11009:                 my $class = $args->{'crscode'}.$sec;
                   11010:                 my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
                   11011:                 $cenv{'internal.sectionnums'} .= $item.',';
                   11012:                 unless ($addcheck eq 'ok') {
                   11013:                     push @badclasses, $class;
                   11014:                 }
                   11015:             }
                   11016:             $cenv{'internal.sectionnums'} =~ s/,$//;
                   11017:         }
                   11018:     }
                   11019: # do not hide course coordinator from staff listing, 
                   11020: # even if privileged
                   11021:     $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   11022: # add crosslistings
                   11023:     if ($args->{'crsxlist'}) {
                   11024:         $cenv{'internal.crosslistings'}='';
                   11025:         if ($args->{'crsxlist'} =~ m/,/) {
                   11026:             @xlists = split/,/,$args->{'crsxlist'};
                   11027:         } else {
                   11028:             $xlists[0] = $args->{'crsxlist'};
                   11029:         }
                   11030:         if (@xlists > 0) {
                   11031:             foreach my $item (@xlists) {
                   11032:                 my ($xl,$gp) = split/:/,$item;
                   11033:                 my $addcheck =  &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
                   11034:                 $cenv{'internal.crosslistings'} .= $item.',';
                   11035:                 unless ($addcheck eq 'ok') {
                   11036:                     push @badclasses, $xl;
                   11037:                 }
                   11038:             }
                   11039:             $cenv{'internal.crosslistings'} =~ s/,$//;
                   11040:         }
                   11041:     }
                   11042:     if ($args->{'autoadds'}) {
                   11043:         $cenv{'internal.autoadds'}=$args->{'autoadds'};
                   11044:     }
                   11045:     if ($args->{'autodrops'}) {
                   11046:         $cenv{'internal.autodrops'}=$args->{'autodrops'};
                   11047:     }
                   11048: # check for notification of enrollment changes
                   11049:     my @notified = ();
                   11050:     if ($args->{'notify_owner'}) {
                   11051:         if ($args->{'ccuname'} ne '') {
                   11052:             push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
                   11053:         }
                   11054:     }
                   11055:     if ($args->{'notify_dc'}) {
                   11056:         if ($uname ne '') { 
1.630     raeburn  11057:             push(@notified,$uname.':'.$udom);
1.444     albertel 11058:         }
                   11059:     }
                   11060:     if (@notified > 0) {
                   11061:         my $notifylist;
                   11062:         if (@notified > 1) {
                   11063:             $notifylist = join(',',@notified);
                   11064:         } else {
                   11065:             $notifylist = $notified[0];
                   11066:         }
                   11067:         $cenv{'internal.notifylist'} = $notifylist;
                   11068:     }
                   11069:     if (@badclasses > 0) {
                   11070:         my %lt=&Apache::lonlocal::texthash(
                   11071:                 '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',
                   11072:                 'dnhr' => 'does not have rights to access enrollment in these classes',
                   11073:                 'adby' => 'as determined by the policies of your institution on access to official classlists'
                   11074:         );
1.541     raeburn  11075:         my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
                   11076:                            ' ('.$lt{'adby'}.')';
                   11077:         if ($context eq 'auto') {
                   11078:             $outcome .= $badclass_msg.$linefeed;
1.566     albertel 11079:             $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541     raeburn  11080:             foreach my $item (@badclasses) {
                   11081:                 if ($context eq 'auto') {
                   11082:                     $outcome .= " - $item\n";
                   11083:                 } else {
                   11084:                     $outcome .= "<li>$item</li>\n";
                   11085:                 }
                   11086:             }
                   11087:             if ($context eq 'auto') {
                   11088:                 $outcome .= $linefeed;
                   11089:             } else {
1.566     albertel 11090:                 $outcome .= "</ul><br /><br /></div>\n";
1.541     raeburn  11091:             }
                   11092:         } 
1.444     albertel 11093:     }
                   11094:     if ($args->{'no_end_date'}) {
                   11095:         $args->{'endaccess'} = 0;
                   11096:     }
                   11097:     $cenv{'internal.autostart'}=$args->{'enrollstart'};
                   11098:     $cenv{'internal.autoend'}=$args->{'enrollend'};
                   11099:     $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
                   11100:     $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
                   11101:     if ($args->{'showphotos'}) {
                   11102:       $cenv{'internal.showphotos'}=$args->{'showphotos'};
                   11103:     }
                   11104:     $cenv{'internal.authtype'} = $args->{'authtype'};
                   11105:     $cenv{'internal.autharg'} = $args->{'autharg'}; 
                   11106:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
                   11107:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
1.541     raeburn  11108:             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'); 
                   11109:             if ($context eq 'auto') {
                   11110:                 $outcome .= $krb_msg;
                   11111:             } else {
1.566     albertel 11112:                 $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541     raeburn  11113:             }
                   11114:             $outcome .= $linefeed;
1.444     albertel 11115:         }
                   11116:     }
                   11117:     if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
                   11118:        if ($args->{'setpolicy'}) {
                   11119:            $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   11120:        }
                   11121:        if ($args->{'setcontent'}) {
                   11122:            $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   11123:        }
                   11124:     }
                   11125:     if ($args->{'reshome'}) {
                   11126: 	$cenv{'reshome'}=$args->{'reshome'}.'/';
                   11127: 	$cenv{'reshome'}=~s/\/+$/\//;
                   11128:     }
                   11129: #
                   11130: # course has keyed access
                   11131: #
                   11132:     if ($args->{'setkeys'}) {
                   11133:        $cenv{'keyaccess'}='yes';
                   11134:     }
                   11135: # if specified, key authority is not course, but user
                   11136: # only active if keyaccess is yes
                   11137:     if ($args->{'keyauth'}) {
1.487     albertel 11138: 	my ($user,$domain) = split(':',$args->{'keyauth'});
                   11139: 	$user = &LONCAPA::clean_username($user);
                   11140: 	$domain = &LONCAPA::clean_username($domain);
1.488     foxr     11141: 	if ($user ne '' && $domain ne '') {
1.487     albertel 11142: 	    $cenv{'keyauth'}=$user.':'.$domain;
1.444     albertel 11143: 	}
                   11144:     }
                   11145: 
                   11146:     if ($args->{'disresdis'}) {
                   11147:         $cenv{'pch.roles.denied'}='st';
                   11148:     }
                   11149:     if ($args->{'disablechat'}) {
                   11150:         $cenv{'plc.roles.denied'}='st';
                   11151:     }
                   11152: 
                   11153:     # Record we've not yet viewed the Course Initialization Helper for this 
                   11154:     # course
                   11155:     $cenv{'course.helper.not.run'} = 1;
                   11156:     #
                   11157:     # Use new Randomseed
                   11158:     #
                   11159:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
                   11160:     $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
                   11161:     #
                   11162:     # The encryption code and receipt prefix for this course
                   11163:     #
                   11164:     $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
                   11165:     $cenv{'internal.encpref'}=100+int(9*rand(99));
                   11166:     #
                   11167:     # By default, use standard grading
                   11168:     if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
                   11169: 
1.541     raeburn  11170:     $outcome .= $linefeed.&mt('Setting environment').': '.                 
                   11171:           &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 11172: #
                   11173: # Open all assignments
                   11174: #
                   11175:     if ($args->{'openall'}) {
                   11176:        my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
                   11177:        my %storecontent = ($storeunder         => time,
                   11178:                            $storeunder.'.type' => 'date_start');
                   11179:        
                   11180:        $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541     raeburn  11181:                  ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 11182:    }
                   11183: #
                   11184: # Set first page
                   11185: #
                   11186:     unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
                   11187: 	    || ($cloneid)) {
1.445     albertel 11188: 	use LONCAPA::map;
1.444     albertel 11189: 	$outcome .= &mt('Setting first resource').': ';
1.445     albertel 11190: 
                   11191: 	my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
                   11192:         my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
                   11193: 
1.444     albertel 11194:         $outcome .= ($fatal?$errtext:'read ok').' - ';
                   11195:         my $title; my $url;
                   11196:         if ($args->{'firstres'} eq 'syl') {
1.690     bisitz   11197: 	    $title=&mt('Syllabus');
1.444     albertel 11198:             $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
                   11199:         } else {
1.963     raeburn  11200:             $title=&mt('Table of Contents');
1.444     albertel 11201:             $url='/adm/navmaps';
                   11202:         }
1.445     albertel 11203: 
                   11204:         $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
                   11205: 	(my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
                   11206: 
                   11207: 	if ($errtext) { $fatal=2; }
1.541     raeburn  11208:         $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444     albertel 11209:     }
1.566     albertel 11210: 
                   11211:     return (1,$outcome);
1.444     albertel 11212: }
                   11213: 
                   11214: ############################################################
                   11215: ############################################################
                   11216: 
1.953     droeschl 11217: #SD
                   11218: # only Community and Course, or anything else?
1.378     raeburn  11219: sub course_type {
                   11220:     my ($cid) = @_;
                   11221:     if (!defined($cid)) {
                   11222:         $cid = $env{'request.course.id'};
                   11223:     }
1.404     albertel 11224:     if (defined($env{'course.'.$cid.'.type'})) {
                   11225:         return $env{'course.'.$cid.'.type'};
1.378     raeburn  11226:     } else {
                   11227:         return 'Course';
1.377     raeburn  11228:     }
                   11229: }
1.156     albertel 11230: 
1.406     raeburn  11231: sub group_term {
                   11232:     my $crstype = &course_type();
                   11233:     my %names = (
                   11234:                   'Course' => 'group',
1.865     raeburn  11235:                   'Community' => 'group',
1.406     raeburn  11236:                 );
                   11237:     return $names{$crstype};
                   11238: }
                   11239: 
1.902     raeburn  11240: sub course_types {
                   11241:     my @types = ('official','unofficial','community');
                   11242:     my %typename = (
                   11243:                          official   => 'Official course',
                   11244:                          unofficial => 'Unofficial course',
                   11245:                          community  => 'Community',
                   11246:                    );
                   11247:     return (\@types,\%typename);
                   11248: }
                   11249: 
1.156     albertel 11250: sub icon {
                   11251:     my ($file)=@_;
1.505     albertel 11252:     my $curfext = lc((split(/\./,$file))[-1]);
1.168     albertel 11253:     my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156     albertel 11254:     my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168     albertel 11255:     if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
                   11256: 	if (-e  $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
                   11257: 	          $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   11258: 	            $curfext.".gif") {
                   11259: 	    $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   11260: 		$curfext.".gif";
                   11261: 	}
                   11262:     }
1.249     albertel 11263:     return &lonhttpdurl($iconname);
1.154     albertel 11264: } 
1.84      albertel 11265: 
1.575     albertel 11266: sub lonhttpdurl {
1.692     www      11267: #
                   11268: # Had been used for "small fry" static images on separate port 8080.
                   11269: # Modify here if lightweight http functionality desired again.
                   11270: # Currently eliminated due to increasing firewall issues.
                   11271: #
1.575     albertel 11272:     my ($url)=@_;
1.692     www      11273:     return $url;
1.215     albertel 11274: }
                   11275: 
1.213     albertel 11276: sub connection_aborted {
                   11277:     my ($r)=@_;
                   11278:     $r->print(" ");$r->rflush();
                   11279:     my $c = $r->connection;
                   11280:     return $c->aborted();
                   11281: }
                   11282: 
1.221     foxr     11283: #    Escapes strings that may have embedded 's that will be put into
1.222     foxr     11284: #    strings as 'strings'.
                   11285: sub escape_single {
1.221     foxr     11286:     my ($input) = @_;
1.223     albertel 11287:     $input =~ s/\\/\\\\/g;	# Escape the \'s..(must be first)>
1.221     foxr     11288:     $input =~ s/\'/\\\'/g;	# Esacpe the 's....
                   11289:     return $input;
                   11290: }
1.223     albertel 11291: 
1.222     foxr     11292: #  Same as escape_single, but escape's "'s  This 
                   11293: #  can be used for  "strings"
                   11294: sub escape_double {
                   11295:     my ($input) = @_;
                   11296:     $input =~ s/\\/\\\\/g;	# Escape the /'s..(must be first)>
                   11297:     $input =~ s/\"/\\\"/g;	# Esacpe the "s....
                   11298:     return $input;
                   11299: }
1.223     albertel 11300:  
1.222     foxr     11301: #   Escapes the last element of a full URL.
                   11302: sub escape_url {
                   11303:     my ($url)   = @_;
1.238     raeburn  11304:     my @urlslices = split(/\//, $url,-1);
1.369     www      11305:     my $lastitem = &escape(pop(@urlslices));
1.223     albertel 11306:     return join('/',@urlslices).'/'.$lastitem;
1.222     foxr     11307: }
1.462     albertel 11308: 
1.820     raeburn  11309: sub compare_arrays {
                   11310:     my ($arrayref1,$arrayref2) = @_;
                   11311:     my (@difference,%count);
                   11312:     @difference = ();
                   11313:     %count = ();
                   11314:     if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
                   11315:         foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
                   11316:         foreach my $element (keys(%count)) {
                   11317:             if ($count{$element} == 1) {
                   11318:                 push(@difference,$element);
                   11319:             }
                   11320:         }
                   11321:     }
                   11322:     return @difference;
                   11323: }
                   11324: 
1.817     bisitz   11325: # -------------------------------------------------------- Initialize user login
1.462     albertel 11326: sub init_user_environment {
1.463     albertel 11327:     my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462     albertel 11328:     my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
                   11329: 
                   11330:     my $public=($username eq 'public' && $domain eq 'public');
                   11331: 
                   11332: # See if old ID present, if so, remove
                   11333: 
                   11334:     my ($filename,$cookie,$userroles);
                   11335:     my $now=time;
                   11336: 
                   11337:     if ($public) {
                   11338: 	my $max_public=100;
                   11339: 	my $oldest;
                   11340: 	my $oldest_time=0;
                   11341: 	for(my $next=1;$next<=$max_public;$next++) {
                   11342: 	    if (-e $lonids."/publicuser_$next.id") {
                   11343: 		my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
                   11344: 		if ($mtime<$oldest_time || !$oldest_time) {
                   11345: 		    $oldest_time=$mtime;
                   11346: 		    $oldest=$next;
                   11347: 		}
                   11348: 	    } else {
                   11349: 		$cookie="publicuser_$next";
                   11350: 		last;
                   11351: 	    }
                   11352: 	}
                   11353: 	if (!$cookie) { $cookie="publicuser_$oldest"; }
                   11354:     } else {
1.463     albertel 11355: 	# if this isn't a robot, kill any existing non-robot sessions
                   11356: 	if (!$args->{'robot'}) {
                   11357: 	    opendir(DIR,$lonids);
                   11358: 	    while ($filename=readdir(DIR)) {
                   11359: 		if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
                   11360: 		    unlink($lonids.'/'.$filename);
                   11361: 		}
1.462     albertel 11362: 	    }
1.463     albertel 11363: 	    closedir(DIR);
1.462     albertel 11364: 	}
                   11365: # Give them a new cookie
1.463     albertel 11366: 	my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684     www      11367: 		                   : $now.$$.int(rand(10000)));
1.463     albertel 11368: 	$cookie="$username\_$id\_$domain\_$authhost";
1.462     albertel 11369:     
                   11370: # Initialize roles
                   11371: 
                   11372: 	$userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
                   11373:     }
                   11374: # ------------------------------------ Check browser type and MathML capability
                   11375: 
                   11376:     my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   11377:         $clientunicode,$clientos) = &decode_user_agent($r);
                   11378: 
                   11379: # ------------------------------------------------------------- Get environment
                   11380: 
                   11381:     my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
                   11382:     my ($tmp) = keys(%userenv);
                   11383:     if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   11384:     } else {
                   11385: 	undef(%userenv);
                   11386:     }
                   11387:     if (($userenv{'interface'}) && (!$form->{'interface'})) {
                   11388: 	$form->{'interface'}=$userenv{'interface'};
                   11389:     }
                   11390:     if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
                   11391: 
                   11392: # --------------- Do not trust query string to be put directly into environment
1.817     bisitz   11393:     foreach my $option ('interface','localpath','localres') {
                   11394:         $form->{$option}=~s/[\n\r\=]//gs;
1.462     albertel 11395:     }
                   11396: # --------------------------------------------------------- Write first profile
                   11397: 
                   11398:     {
                   11399: 	my %initial_env = 
                   11400: 	    ("user.name"          => $username,
                   11401: 	     "user.domain"        => $domain,
                   11402: 	     "user.home"          => $authhost,
                   11403: 	     "browser.type"       => $clientbrowser,
                   11404: 	     "browser.version"    => $clientversion,
                   11405: 	     "browser.mathml"     => $clientmathml,
                   11406: 	     "browser.unicode"    => $clientunicode,
                   11407: 	     "browser.os"         => $clientos,
                   11408: 	     "server.domain"      => $Apache::lonnet::perlvar{'lonDefDomain'},
                   11409: 	     "request.course.fn"  => '',
                   11410: 	     "request.course.uri" => '',
                   11411: 	     "request.course.sec" => '',
                   11412: 	     "request.role"       => 'cm',
                   11413: 	     "request.role.adv"   => $env{'user.adv'},
                   11414: 	     "request.host"       => $ENV{'REMOTE_ADDR'},);
                   11415: 
                   11416:         if ($form->{'localpath'}) {
                   11417: 	    $initial_env{"browser.localpath"}  = $form->{'localpath'};
                   11418: 	    $initial_env{"browser.localres"}   = $form->{'localres'};
                   11419:         }
                   11420: 	
                   11421: 	if ($form->{'interface'}) {
                   11422: 	    $form->{'interface'}=~s/\W//gs;
                   11423: 	    $initial_env{"browser.interface"} = $form->{'interface'};
                   11424: 	    $env{'browser.interface'}=$form->{'interface'};
                   11425: 	}
                   11426: 
1.981     raeburn  11427:         my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016    raeburn  11428:         my %domdef;
                   11429:         unless ($domain eq 'public') {
                   11430:             %domdef = &Apache::lonnet::get_domain_defaults($domain);
                   11431:         }
1.980     raeburn  11432: 
1.724     raeburn  11433:         foreach my $tool ('aboutme','blog','portfolio') {
                   11434:             $userenv{'availabletools.'.$tool} = 
1.980     raeburn  11435:                 &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
                   11436:                                                   undef,\%userenv,\%domdef,\%is_adv);
1.724     raeburn  11437:         }
                   11438: 
1.864     raeburn  11439:         foreach my $crstype ('official','unofficial','community') {
1.765     raeburn  11440:             $userenv{'canrequest.'.$crstype} =
                   11441:                 &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980     raeburn  11442:                                                   'reload','requestcourses',
                   11443:                                                   \%userenv,\%domdef,\%is_adv);
1.765     raeburn  11444:         }
                   11445: 
1.462     albertel 11446: 	$env{'user.environment'} = "$lonids/$cookie.id";
                   11447: 	
                   11448: 	if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
                   11449: 		 &GDBM_WRCREAT(),0640)) {
                   11450: 	    &_add_to_env(\%disk_env,\%initial_env);
                   11451: 	    &_add_to_env(\%disk_env,\%userenv,'environment.');
                   11452: 	    &_add_to_env(\%disk_env,$userroles);
1.463     albertel 11453: 	    if (ref($args->{'extra_env'})) {
                   11454: 		&_add_to_env(\%disk_env,$args->{'extra_env'});
                   11455: 	    }
1.462     albertel 11456: 	    untie(%disk_env);
                   11457: 	} else {
1.705     tempelho 11458: 	    &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
                   11459: 			   'Could not create environment storage in lonauth: '.$!.'</span>');
1.462     albertel 11460: 	    return 'error: '.$!;
                   11461: 	}
                   11462:     }
                   11463:     $env{'request.role'}='cm';
                   11464:     $env{'request.role.adv'}=$env{'user.adv'};
                   11465:     $env{'browser.type'}=$clientbrowser;
                   11466: 
                   11467:     return $cookie;
                   11468: 
                   11469: }
                   11470: 
                   11471: sub _add_to_env {
                   11472:     my ($idf,$env_data,$prefix) = @_;
1.676     raeburn  11473:     if (ref($env_data) eq 'HASH') {
                   11474:         while (my ($key,$value) = each(%$env_data)) {
                   11475: 	    $idf->{$prefix.$key} = $value;
                   11476: 	    $env{$prefix.$key}   = $value;
                   11477:         }
1.462     albertel 11478:     }
                   11479: }
                   11480: 
1.685     tempelho 11481: # --- Get the symbolic name of a problem and the url
                   11482: sub get_symb {
                   11483:     my ($request,$silent) = @_;
1.726     raeburn  11484:     (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685     tempelho 11485:     my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
                   11486:     if ($symb eq '') {
                   11487:         if (!$silent) {
                   11488:             $request->print("Unable to handle ambiguous references:$url:.");
                   11489:             return ();
                   11490:         }
                   11491:     }
                   11492:     &Apache::lonenc::check_decrypt(\$symb);
                   11493:     return ($symb);
                   11494: }
                   11495: 
                   11496: # --------------------------------------------------------------Get annotation
                   11497: 
                   11498: sub get_annotation {
                   11499:     my ($symb,$enc) = @_;
                   11500: 
                   11501:     my $key = $symb;
                   11502:     if (!$enc) {
                   11503:         $key =
                   11504:             &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
                   11505:     }
                   11506:     my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
                   11507:     return $annotation{$key};
                   11508: }
                   11509: 
                   11510: sub clean_symb {
1.731     raeburn  11511:     my ($symb,$delete_enc) = @_;
1.685     tempelho 11512: 
                   11513:     &Apache::lonenc::check_decrypt(\$symb);
                   11514:     my $enc = $env{'request.enc'};
1.731     raeburn  11515:     if ($delete_enc) {
1.730     raeburn  11516:         delete($env{'request.enc'});
                   11517:     }
1.685     tempelho 11518: 
                   11519:     return ($symb,$enc);
                   11520: }
1.462     albertel 11521: 
1.990     raeburn  11522: sub build_release_hashes {
                   11523:     my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
                   11524:     return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
                   11525:                   (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
                   11526:                   (ref($randomizetry) eq 'HASH'));
                   11527:     foreach my $key (keys(%Apache::lonnet::needsrelease)) {
                   11528:         my ($item,$name,$value) = split(/:/,$key);
                   11529:         if ($item eq 'parameter') {
                   11530:             if (ref($checkparms->{$name}) eq 'ARRAY') {
                   11531:                 unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
                   11532:                     push(@{$checkparms->{$name}},$value);
                   11533:                 }
                   11534:             } else {
                   11535:                 push(@{$checkparms->{$name}},$value);
                   11536:             }
                   11537:         } elsif ($item eq 'resourcetag') {
                   11538:             if ($name eq 'responsetype') {
                   11539:                 $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
                   11540:             }
                   11541:         } elsif ($item eq 'course') {
                   11542:             if ($name eq 'crstype') {
                   11543:                 $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
                   11544:             }
                   11545:         }
                   11546:     }
                   11547:     ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
                   11548:     ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
                   11549:     return;
                   11550: }
                   11551: 
1.41      ng       11552: =pod
                   11553: 
                   11554: =back
                   11555: 
1.112     bowersj2 11556: =cut
1.41      ng       11557: 
1.112     bowersj2 11558: 1;
                   11559: __END__;
1.41      ng       11560: 

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