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

1.10      albertel    1: # The LearningOnline Network with CAPA
1.1       albertel    2: # a pile of common routines
1.10      albertel    3: #
1.1008  ! www         4: # $Id: loncommon.pm,v 1.1007 2011/05/27 22:58:13 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.793     raeburn   478:        $callargs .= ",1"; 
                    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: 
                    635: sub userbrowser_javascript {
                    636:     my $id_functions = &javascript_index_functions();
                    637:     return <<"ENDUSERBRW";
                    638: 
1.888     raeburn   639: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876     raeburn   640:     var url = '/adm/pickuser?';
                    641:     var userdom = getDomainFromSelectbox(formname,udom);
                    642:     if (userdom != null) {
                    643:        if (userdom != '') {
                    644:            url += 'srchdom='+userdom+'&';
                    645:        }
                    646:     }
                    647:     url += 'form=' + formname + '&unameelement='+uname+
                    648:                                 '&udomelement='+udom+
                    649:                                 '&ulastelement='+ulast+
                    650:                                 '&ufirstelement='+ufirst+
                    651:                                 '&uemailelement='+uemail+
1.881     raeburn   652:                                 '&hideudomelement='+hideudom+
                    653:                                 '&coursedom='+crsdom;
1.888     raeburn   654:     if ((caller != null) && (caller != undefined)) {
                    655:         url += '&caller='+caller;
                    656:     }
1.876     raeburn   657:     var title = 'User_Browser';
                    658:     var options = 'scrollbars=1,resizable=1,menubar=0';
                    659:     options += ',width=700,height=600';
                    660:     var stdeditbrowser = open(url,title,options,'1');
                    661:     stdeditbrowser.focus();
                    662: }
                    663: 
1.888     raeburn   664: function fix_domain (formname,udom,origdom,uname) {
1.876     raeburn   665:     var formid = getFormIdByName(formname);
                    666:     if (formid > -1) {
1.888     raeburn   667:         var unameid = getIndexByName(formid,uname);
1.876     raeburn   668:         var domid = getIndexByName(formid,udom);
                    669:         var hidedomid = getIndexByName(formid,origdom);
                    670:         if (hidedomid > -1) {
                    671:             var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888     raeburn   672:             var unameval = document.forms[formid].elements[unameid].value;
                    673:             if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
                    674:                 if (domid > -1) {
                    675:                     var slct = document.forms[formid].elements[domid];
                    676:                     if (slct.type == 'select-one') {
                    677:                         var i;
                    678:                         for (i=0;i<slct.length;i++) {
                    679:                             if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
                    680:                         }
                    681:                     }
                    682:                     if (slct.type == 'hidden') {
                    683:                         slct.value = fixeddom;
1.876     raeburn   684:                     }
                    685:                 }
1.468     raeburn   686:             }
                    687:         }
                    688:     }
1.876     raeburn   689:     return;
                    690: }
                    691: 
                    692: $id_functions
                    693: ENDUSERBRW
1.468     raeburn   694: }
                    695: 
                    696: sub setsec_javascript {
1.905     raeburn   697:     my ($sec_element,$formname,$role_element) = @_;
                    698:     my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
                    699:         $communityrolestr);
                    700:     if ($role_element ne '') {
                    701:         my @allroles = ('st','ta','ep','in','ad');
                    702:         foreach my $crstype ('Course','Community') {
                    703:             if ($crstype eq 'Community') {
                    704:                 foreach my $role (@allroles) {
                    705:                     push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
                    706:                 }
                    707:                 push(@communityrolenames,&Apache::lonnet::plaintext('co'));
                    708:             } else {
                    709:                 foreach my $role (@allroles) {
                    710:                     push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
                    711:                 }
                    712:                 push(@courserolenames,&Apache::lonnet::plaintext('cc'));
                    713:             }
                    714:         }
                    715:         $rolestr = '"'.join('","',@allroles).'"';
                    716:         $courserolestr = '"'.join('","',@courserolenames).'"';
                    717:         $communityrolestr = '"'.join('","',@communityrolenames).'"';
                    718:     }
1.468     raeburn   719:     my $setsections = qq|
                    720: function setSect(sectionlist) {
1.629     raeburn   721:     var sectionsArray = new Array();
                    722:     if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
                    723:         sectionsArray = sectionlist.split(",");
                    724:     }
1.468     raeburn   725:     var numSections = sectionsArray.length;
                    726:     document.$formname.$sec_element.length = 0;
                    727:     if (numSections == 0) {
                    728:         document.$formname.$sec_element.multiple=false;
                    729:         document.$formname.$sec_element.size=1;
                    730:         document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
                    731:     } else {
                    732:         if (numSections == 1) {
                    733:             document.$formname.$sec_element.multiple=false;
                    734:             document.$formname.$sec_element.size=1;
                    735:             document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
                    736:             document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
                    737:             document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
                    738:         } else {
                    739:             for (var i=0; i<numSections; i++) {
                    740:                 document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
                    741:             }
                    742:             document.$formname.$sec_element.multiple=true
                    743:             if (numSections < 3) {
                    744:                 document.$formname.$sec_element.size=numSections;
                    745:             } else {
                    746:                 document.$formname.$sec_element.size=3;
                    747:             }
                    748:             document.$formname.$sec_element.options[0].selected = false
                    749:         }
                    750:     }
1.91      www       751: }
1.905     raeburn   752: 
                    753: function setRole(crstype) {
1.468     raeburn   754: |;
1.905     raeburn   755:     if ($role_element eq '') {
                    756:         $setsections .= '    return;
                    757: }
                    758: ';
                    759:     } else {
                    760:         $setsections .= qq|
                    761:     var elementLength = document.$formname.$role_element.length;
                    762:     var allroles = Array($rolestr);
                    763:     var courserolenames = Array($courserolestr);
                    764:     var communityrolenames = Array($communityrolestr);
                    765:     if (elementLength != undefined) {
                    766:         if (document.$formname.$role_element.options[5].value == 'cc') {
                    767:             if (crstype == 'Course') {
                    768:                 return;
                    769:             } else {
                    770:                 allroles[5] = 'co';
                    771:                 for (var i=0; i<6; i++) {
                    772:                     document.$formname.$role_element.options[i].value = allroles[i];
                    773:                     document.$formname.$role_element.options[i].text = communityrolenames[i];
                    774:                 }
                    775:             }
                    776:         } else {
                    777:             if (crstype == 'Community') {
                    778:                 return;
                    779:             } else {
                    780:                 allroles[5] = 'cc';
                    781:                 for (var i=0; i<6; i++) {
                    782:                     document.$formname.$role_element.options[i].value = allroles[i];
                    783:                     document.$formname.$role_element.options[i].text = courserolenames[i];
                    784:                 }
                    785:             }
                    786:         }
                    787:     }
                    788:     return;
                    789: }
                    790: |;
                    791:     }
1.468     raeburn   792:     return $setsections;
                    793: }
                    794: 
1.91      www       795: sub selectcourse_link {
1.909     raeburn   796:    my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
                    797:        $typeelement) = @_;
                    798:    my $type = $selecttype;
1.871     raeburn   799:    my $linktext = &mt('Select Course');
                    800:    if ($selecttype eq 'Community') {
1.909     raeburn   801:        $linktext = &mt('Select Community');
1.906     raeburn   802:    } elsif ($selecttype eq 'Course/Community') {
                    803:        $linktext = &mt('Select Course/Community');
1.909     raeburn   804:        $type = '';
1.871     raeburn   805:    }
1.787     bisitz    806:    return '<span class="LC_nobreak">'
                    807:          ."<a href='"
                    808:          .'javascript:opencrsbrowser("'.$form.'","'.$unameele
                    809:          .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909     raeburn   810:          .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871     raeburn   811:          ."'>".$linktext.'</a>'
1.787     bisitz    812:          .'</span>';
1.74      www       813: }
1.42      matthew   814: 
1.653     raeburn   815: sub selectauthor_link {
                    816:    my ($form,$udom)=@_;
                    817:    return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
                    818:           &mt('Select Author').'</a>';
                    819: }
                    820: 
1.876     raeburn   821: sub selectuser_link {
1.881     raeburn   822:     my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888     raeburn   823:         $coursedom,$linktext,$caller) = @_;
1.876     raeburn   824:     return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888     raeburn   825:            "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881     raeburn   826:            ');">'.$linktext.'</a>';
1.876     raeburn   827: }
                    828: 
1.273     raeburn   829: sub check_uncheck_jscript {
                    830:     my $jscript = <<"ENDSCRT";
                    831: function checkAll(field) {
                    832:     if (field.length > 0) {
                    833:         for (i = 0; i < field.length; i++) {
                    834:             field[i].checked = true ;
                    835:         }
                    836:     } else {
                    837:         field.checked = true
                    838:     }
                    839: }
                    840:  
                    841: function uncheckAll(field) {
                    842:     if (field.length > 0) {
                    843:         for (i = 0; i < field.length; i++) {
                    844:             field[i].checked = false ;
1.543     albertel  845:         }
                    846:     } else {
1.273     raeburn   847:         field.checked = false ;
                    848:     }
                    849: }
                    850: ENDSCRT
                    851:     return $jscript;
                    852: }
                    853: 
1.656     www       854: sub select_timezone {
1.659     raeburn   855:    my ($name,$selected,$onchange,$includeempty)=@_;
                    856:    my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    857:    if ($includeempty) {
                    858:        $output .= '<option value=""';
                    859:        if (($selected eq '') || ($selected eq 'local')) {
                    860:            $output .= ' selected="selected" ';
                    861:        }
                    862:        $output .= '> </option>';
                    863:    }
1.657     raeburn   864:    my @timezones = DateTime::TimeZone->all_names;
                    865:    foreach my $tzone (@timezones) {
                    866:        $output.= '<option value="'.$tzone.'"';
                    867:        if ($tzone eq $selected) {
                    868:            $output.=' selected="selected"';
                    869:        }
                    870:        $output.=">$tzone</option>\n";
1.656     www       871:    }
                    872:    $output.="</select>";
                    873:    return $output;
                    874: }
1.273     raeburn   875: 
1.687     raeburn   876: sub select_datelocale {
                    877:     my ($name,$selected,$onchange,$includeempty)=@_;
                    878:     my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    879:     if ($includeempty) {
                    880:         $output .= '<option value=""';
                    881:         if ($selected eq '') {
                    882:             $output .= ' selected="selected" ';
                    883:         }
                    884:         $output .= '> </option>';
                    885:     }
                    886:     my (@possibles,%locale_names);
                    887:     my @locales = DateTime::Locale::Catalog::Locales;
                    888:     foreach my $locale (@locales) {
                    889:         if (ref($locale) eq 'HASH') {
                    890:             my $id = $locale->{'id'};
                    891:             if ($id ne '') {
                    892:                 my $en_terr = $locale->{'en_territory'};
                    893:                 my $native_terr = $locale->{'native_territory'};
1.695     raeburn   894:                 my @languages = &Apache::lonlocal::preferred_languages();
1.687     raeburn   895:                 if (grep(/^en$/,@languages) || !@languages) {
                    896:                     if ($en_terr ne '') {
                    897:                         $locale_names{$id} = '('.$en_terr.')';
                    898:                     } elsif ($native_terr ne '') {
                    899:                         $locale_names{$id} = $native_terr;
                    900:                     }
                    901:                 } else {
                    902:                     if ($native_terr ne '') {
                    903:                         $locale_names{$id} = $native_terr.' ';
                    904:                     } elsif ($en_terr ne '') {
                    905:                         $locale_names{$id} = '('.$en_terr.')';
                    906:                     }
                    907:                 }
                    908:                 push (@possibles,$id);
                    909:             }
                    910:         }
                    911:     }
                    912:     foreach my $item (sort(@possibles)) {
                    913:         $output.= '<option value="'.$item.'"';
                    914:         if ($item eq $selected) {
                    915:             $output.=' selected="selected"';
                    916:         }
                    917:         $output.=">$item";
                    918:         if ($locale_names{$item} ne '') {
                    919:             $output.="  $locale_names{$item}</option>\n";
                    920:         }
                    921:         $output.="</option>\n";
                    922:     }
                    923:     $output.="</select>";
                    924:     return $output;
                    925: }
                    926: 
1.792     raeburn   927: sub select_language {
                    928:     my ($name,$selected,$includeempty) = @_;
                    929:     my %langchoices;
                    930:     if ($includeempty) {
                    931:         %langchoices = ('' => 'No language preference');
                    932:     }
                    933:     foreach my $id (&languageids()) {
                    934:         my $code = &supportedlanguagecode($id);
                    935:         if ($code) {
                    936:             $langchoices{$code} = &plainlanguagedescription($id);
                    937:         }
                    938:     }
1.970     raeburn   939:     return &select_form($selected,$name,\%langchoices);
1.792     raeburn   940: }
                    941: 
1.42      matthew   942: =pod
1.36      matthew   943: 
1.648     raeburn   944: =item * &linked_select_forms(...)
1.36      matthew   945: 
                    946: linked_select_forms returns a string containing a <script></script> block
                    947: and html for two <select> menus.  The select menus will be linked in that
                    948: changing the value of the first menu will result in new values being placed
                    949: in the second menu.  The values in the select menu will appear in alphabetical
1.609     raeburn   950: order unless a defined order is provided.
1.36      matthew   951: 
                    952: linked_select_forms takes the following ordered inputs:
                    953: 
                    954: =over 4
                    955: 
1.112     bowersj2  956: =item * $formname, the name of the <form> tag
1.36      matthew   957: 
1.112     bowersj2  958: =item * $middletext, the text which appears between the <select> tags
1.36      matthew   959: 
1.112     bowersj2  960: =item * $firstdefault, the default value for the first menu
1.36      matthew   961: 
1.112     bowersj2  962: =item * $firstselectname, the name of the first <select> tag
1.36      matthew   963: 
1.112     bowersj2  964: =item * $secondselectname, the name of the second <select> tag
1.36      matthew   965: 
1.112     bowersj2  966: =item * $hashref, a reference to a hash containing the data for the menus.
1.36      matthew   967: 
1.609     raeburn   968: =item * $menuorder, the order of values in the first menu
                    969: 
1.41      ng        970: =back 
                    971: 
1.36      matthew   972: Below is an example of such a hash.  Only the 'text', 'default', and 
                    973: 'select2' keys must appear as stated.  keys(%menu) are the possible 
                    974: values for the first select menu.  The text that coincides with the 
1.41      ng        975: first menu value is given in $menu{$choice1}->{'text'}.  The values 
1.36      matthew   976: and text for the second menu are given in the hash pointed to by 
                    977: $menu{$choice1}->{'select2'}.  
                    978: 
1.112     bowersj2  979:  my %menu = ( A1 => { text =>"Choice A1" ,
                    980:                        default => "B3",
                    981:                        select2 => { 
                    982:                            B1 => "Choice B1",
                    983:                            B2 => "Choice B2",
                    984:                            B3 => "Choice B3",
                    985:                            B4 => "Choice B4"
1.609     raeburn   986:                            },
                    987:                        order => ['B4','B3','B1','B2'],
1.112     bowersj2  988:                    },
                    989:                A2 => { text =>"Choice A2" ,
                    990:                        default => "C2",
                    991:                        select2 => { 
                    992:                            C1 => "Choice C1",
                    993:                            C2 => "Choice C2",
                    994:                            C3 => "Choice C3"
1.609     raeburn   995:                            },
                    996:                        order => ['C2','C1','C3'],
1.112     bowersj2  997:                    },
                    998:                A3 => { text =>"Choice A3" ,
                    999:                        default => "D6",
                   1000:                        select2 => { 
                   1001:                            D1 => "Choice D1",
                   1002:                            D2 => "Choice D2",
                   1003:                            D3 => "Choice D3",
                   1004:                            D4 => "Choice D4",
                   1005:                            D5 => "Choice D5",
                   1006:                            D6 => "Choice D6",
                   1007:                            D7 => "Choice D7"
1.609     raeburn  1008:                            },
                   1009:                        order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112     bowersj2 1010:                    }
                   1011:                );
1.36      matthew  1012: 
                   1013: =cut
                   1014: 
                   1015: sub linked_select_forms {
                   1016:     my ($formname,
                   1017:         $middletext,
                   1018:         $firstdefault,
                   1019:         $firstselectname,
                   1020:         $secondselectname, 
1.609     raeburn  1021:         $hashref,
                   1022:         $menuorder,
1.36      matthew  1023:         ) = @_;
                   1024:     my $second = "document.$formname.$secondselectname";
                   1025:     my $first = "document.$formname.$firstselectname";
                   1026:     # output the javascript to do the changing
                   1027:     my $result = '';
1.776     bisitz   1028:     $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824     bisitz   1029:     $result.="// <![CDATA[\n";
1.36      matthew  1030:     $result.="var select2data = new Object();\n";
                   1031:     $" = '","';
                   1032:     my $debug = '';
                   1033:     foreach my $s1 (sort(keys(%$hashref))) {
                   1034:         $result.="select2data.d_$s1 = new Object();\n";        
                   1035:         $result.="select2data.d_$s1.def = new String('".
                   1036:             $hashref->{$s1}->{'default'}."');\n";
1.609     raeburn  1037:         $result.="select2data.d_$s1.values = new Array(";
1.36      matthew  1038:         my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609     raeburn  1039:         if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
                   1040:             @s2values = @{$hashref->{$s1}->{'order'}};
                   1041:         }
1.36      matthew  1042:         $result.="\"@s2values\");\n";
                   1043:         $result.="select2data.d_$s1.texts = new Array(";        
                   1044:         my @s2texts;
                   1045:         foreach my $value (@s2values) {
                   1046:             push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
                   1047:         }
                   1048:         $result.="\"@s2texts\");\n";
                   1049:     }
                   1050:     $"=' ';
                   1051:     $result.= <<"END";
                   1052: 
                   1053: function select1_changed() {
                   1054:     // Determine new choice
                   1055:     var newvalue = "d_" + $first.value;
                   1056:     // update select2
                   1057:     var values     = select2data[newvalue].values;
                   1058:     var texts      = select2data[newvalue].texts;
                   1059:     var select2def = select2data[newvalue].def;
                   1060:     var i;
                   1061:     // out with the old
                   1062:     for (i = 0; i < $second.options.length; i++) {
                   1063:         $second.options[i] = null;
                   1064:     }
                   1065:     // in with the nuclear
                   1066:     for (i=0;i<values.length; i++) {
                   1067:         $second.options[i] = new Option(values[i]);
1.143     matthew  1068:         $second.options[i].value = values[i];
1.36      matthew  1069:         $second.options[i].text = texts[i];
                   1070:         if (values[i] == select2def) {
                   1071:             $second.options[i].selected = true;
                   1072:         }
                   1073:     }
                   1074: }
1.824     bisitz   1075: // ]]>
1.36      matthew  1076: </script>
                   1077: END
                   1078:     # output the initial values for the selection lists
                   1079:     $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609     raeburn  1080:     my @order = sort(keys(%{$hashref}));
                   1081:     if (ref($menuorder) eq 'ARRAY') {
                   1082:         @order = @{$menuorder};
                   1083:     }
                   1084:     foreach my $value (@order) {
1.36      matthew  1085:         $result.="    <option value=\"$value\" ";
1.253     albertel 1086:         $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119     www      1087:         $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36      matthew  1088:     }
                   1089:     $result .= "</select>\n";
                   1090:     my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
                   1091:     $result .= $middletext;
                   1092:     $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
                   1093:     my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609     raeburn  1094:     
                   1095:     my @secondorder = sort(keys(%select2));
                   1096:     if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
                   1097:         @secondorder = @{$hashref->{$firstdefault}->{'order'}};
                   1098:     }
                   1099:     foreach my $value (@secondorder) {
1.36      matthew  1100:         $result.="    <option value=\"$value\" ";        
1.253     albertel 1101:         $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119     www      1102:         $result.=">".&mt($select2{$value})."</option>\n";
1.36      matthew  1103:     }
                   1104:     $result .= "</select>\n";
                   1105:     #    return $debug;
                   1106:     return $result;
                   1107: }   #  end of sub linked_select_forms {
                   1108: 
1.45      matthew  1109: =pod
1.44      bowersj2 1110: 
1.973     raeburn  1111: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44      bowersj2 1112: 
1.112     bowersj2 1113: Returns a string corresponding to an HTML link to the given help
                   1114: $topic, where $topic corresponds to the name of a .tex file in
                   1115: /home/httpd/html/adm/help/tex, with underscores replaced by
                   1116: spaces. 
                   1117: 
                   1118: $text will optionally be linked to the same topic, allowing you to
                   1119: link text in addition to the graphic. If you do not want to link
                   1120: text, but wish to specify one of the later parameters, pass an
                   1121: empty string. 
                   1122: 
                   1123: $stayOnPage is a value that will be interpreted as a boolean. If true,
                   1124: the link will not open a new window. If false, the link will open
                   1125: a new window using Javascript. (Default is false.) 
                   1126: 
                   1127: $width and $height are optional numerical parameters that will
                   1128: override the width and height of the popped up window, which may
1.973     raeburn  1129: be useful for certain help topics with big pictures included.
                   1130: 
                   1131: $imgid is the id of the img tag used for the help icon. This may be
                   1132: used in a javascript call to switch the image src.  See 
                   1133: lonhtmlcommon::htmlareaselectactive() for an example.
1.44      bowersj2 1134: 
                   1135: =cut
                   1136: 
                   1137: sub help_open_topic {
1.973     raeburn  1138:     my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48      bowersj2 1139:     $text = "" if (not defined $text);
1.44      bowersj2 1140:     $stayOnPage = 0 if (not defined $stayOnPage);
                   1141:     $width = 350 if (not defined $width);
                   1142:     $height = 400 if (not defined $height);
                   1143:     my $filename = $topic;
                   1144:     $filename =~ s/ /_/g;
                   1145: 
1.48      bowersj2 1146:     my $template = "";
                   1147:     my $link;
1.572     banghart 1148:     
1.159     www      1149:     $topic=~s/\W/\_/g;
1.44      bowersj2 1150: 
1.572     banghart 1151:     if (!$stayOnPage) {
1.72      bowersj2 1152: 	$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 1153:     } else {
1.48      bowersj2 1154: 	$link = "/adm/help/${filename}.hlp";
                   1155:     }
                   1156: 
                   1157:     # Add the text
1.755     neumanie 1158:     if ($text ne "") {	
1.763     bisitz   1159: 	$template.='<span class="LC_help_open_topic">'
                   1160:                   .'<a target="_top" href="'.$link.'">'
                   1161:                   .$text.'</a>';
1.48      bowersj2 1162:     }
                   1163: 
1.763     bisitz   1164:     # (Always) Add the graphic
1.179     matthew  1165:     my $title = &mt('Online Help');
1.667     raeburn  1166:     my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973     raeburn  1167:     if ($imgid ne '') {
                   1168:         $imgid = ' id="'.$imgid.'"';
                   1169:     }
1.763     bisitz   1170:     $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
                   1171:               .'<img src="'.$helpicon.'" border="0"'
                   1172:               .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973     raeburn  1173:               .' title="'.$title.'" style="vertical-align:middle;"'.$imgid 
1.763     bisitz   1174:               .' /></a>';
                   1175:     if ($text ne "") {	
                   1176:         $template.='</span>';
                   1177:     }
1.44      bowersj2 1178:     return $template;
                   1179: 
1.106     bowersj2 1180: }
                   1181: 
                   1182: # This is a quicky function for Latex cheatsheet editing, since it 
                   1183: # appears in at least four places
                   1184: sub helpLatexCheatsheet {
1.732     raeburn  1185:     my ($topic,$text,$not_author) = @_;
                   1186:     my $out;
1.106     bowersj2 1187:     my $addOther = '';
1.732     raeburn  1188:     if ($topic) {
1.763     bisitz   1189: 	$addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
                   1190: 							       undef, undef, 600).
                   1191: 								   '</span> ';
                   1192:     }
                   1193:     $out = '<span>' # Start cheatsheet
                   1194: 	  .$addOther
                   1195:           .'<span>'
                   1196: 	  .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
                   1197: 					       undef,undef,600)
                   1198: 	  .'</span> <span>'
                   1199: 	  .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
                   1200: 					       undef,undef,600)
                   1201: 	  .'</span>';
1.732     raeburn  1202:     unless ($not_author) {
1.763     bisitz   1203:         $out .= ' <span>'
                   1204: 	       .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
                   1205: 	                                            undef,undef,600)
                   1206: 	       .'</span>';
1.732     raeburn  1207:     }
1.763     bisitz   1208:     $out .= '</span>'; # End cheatsheet
1.732     raeburn  1209:     return $out;
1.172     www      1210: }
                   1211: 
1.430     albertel 1212: sub general_help {
                   1213:     my $helptopic='Student_Intro';
                   1214:     if ($env{'request.role'}=~/^(ca|au)/) {
                   1215: 	$helptopic='Authoring_Intro';
1.907     raeburn  1216:     } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430     albertel 1217: 	$helptopic='Course_Coordination_Intro';
1.672     raeburn  1218:     } elsif ($env{'request.role'}=~/^dc/) {
                   1219:         $helptopic='Domain_Coordination_Intro';
1.430     albertel 1220:     }
                   1221:     return $helptopic;
                   1222: }
                   1223: 
                   1224: sub update_help_link {
                   1225:     my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
                   1226:     my $origurl = $ENV{'REQUEST_URI'};
                   1227:     $origurl=~s|^/~|/priv/|;
                   1228:     my $timestamp = time;
                   1229:     foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
                   1230:         $$datum = &escape($$datum);
                   1231:     }
                   1232: 
                   1233:     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";
                   1234:     my $output .= <<"ENDOUTPUT";
                   1235: <script type="text/javascript">
1.824     bisitz   1236: // <![CDATA[
1.430     albertel 1237: banner_link = '$banner_link';
1.824     bisitz   1238: // ]]>
1.430     albertel 1239: </script>
                   1240: ENDOUTPUT
                   1241:     return $output;
                   1242: }
                   1243: 
                   1244: # now just updates the help link and generates a blue icon
1.193     raeburn  1245: sub help_open_menu {
1.430     albertel 1246:     my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text) 
1.552     banghart 1247: 	= @_;    
1.949     droeschl 1248:     $stayOnPage = 1;
1.430     albertel 1249:     my $output;
                   1250:     if ($component_help) {
                   1251: 	if (!$text) {
                   1252: 	    $output=&help_open_topic($component_help,undef,$stayOnPage,
                   1253: 				       $width,$height);
                   1254: 	} else {
                   1255: 	    my $help_text;
                   1256: 	    $help_text=&unescape($topic);
                   1257: 	    $output='<table><tr><td>'.
                   1258: 		&help_open_topic($component_help,$help_text,$stayOnPage,
                   1259: 				 $width,$height).'</td></tr></table>';
                   1260: 	}
                   1261:     }
                   1262:     my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
                   1263:     return $output.$banner_link;
                   1264: }
                   1265: 
                   1266: sub top_nav_help {
                   1267:     my ($text) = @_;
1.436     albertel 1268:     $text = &mt($text);
1.949     droeschl 1269:     my $stay_on_page = 1;
                   1270: 
1.572     banghart 1271:     my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436     albertel 1272: 	                     : "javascript:helpMenu('open')";
1.572     banghart 1273:     my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436     albertel 1274: 
1.201     raeburn  1275:     my $title = &mt('Get help');
1.436     albertel 1276: 
                   1277:     return <<"END";
                   1278: $banner_link
                   1279:  <a href="$link" title="$title">$text</a>
                   1280: END
                   1281: }
                   1282: 
                   1283: sub help_menu_js {
                   1284:     my ($text) = @_;
1.949     droeschl 1285:     my $stayOnPage = 1;
1.436     albertel 1286:     my $width = 620;
                   1287:     my $height = 600;
1.430     albertel 1288:     my $helptopic=&general_help();
                   1289:     my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261     albertel 1290:     my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331     albertel 1291:     my $start_page =
                   1292:         &Apache::loncommon::start_page('Help Menu', undef,
                   1293: 				       {'frameset'    => 1,
                   1294: 					'js_ready'    => 1,
                   1295: 					'add_entries' => {
                   1296: 					    'border' => '0',
1.579     raeburn  1297: 					    'rows'   => "110,*",},});
1.331     albertel 1298:     my $end_page =
                   1299:         &Apache::loncommon::end_page({'frameset' => 1,
                   1300: 				      'js_ready' => 1,});
                   1301: 
1.436     albertel 1302:     my $template .= <<"ENDTEMPLATE";
                   1303: <script type="text/javascript">
1.877     bisitz   1304: // <![CDATA[
1.253     albertel 1305: // <!-- BEGIN LON-CAPA Internal
1.430     albertel 1306: var banner_link = '';
1.243     raeburn  1307: function helpMenu(target) {
                   1308:     var caller = this;
                   1309:     if (target == 'open') {
                   1310:         var newWindow = null;
                   1311:         try {
1.262     albertel 1312:             newWindow =  window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243     raeburn  1313:         }
                   1314:         catch(error) {
                   1315:             writeHelp(caller);
                   1316:             return;
                   1317:         }
                   1318:         if (newWindow) {
                   1319:             caller = newWindow;
                   1320:         }
1.193     raeburn  1321:     }
1.243     raeburn  1322:     writeHelp(caller);
                   1323:     return;
                   1324: }
                   1325: function writeHelp(caller) {
1.430     albertel 1326:     caller.document.writeln('$start_page<frame name="bannerframe"  src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243     raeburn  1327:     caller.document.close()
                   1328:     caller.focus()
1.193     raeburn  1329: }
1.877     bisitz   1330: // END LON-CAPA Internal -->
1.253     albertel 1331: // ]]>
1.436     albertel 1332: </script>
1.193     raeburn  1333: ENDTEMPLATE
                   1334:     return $template;
                   1335: }
                   1336: 
1.172     www      1337: sub help_open_bug {
                   1338:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1339:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1340:     unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
                   1341:     $text = "" if (not defined $text);
                   1342: 	$stayOnPage=1;
1.184     albertel 1343:     $width = 600 if (not defined $width);
                   1344:     $height = 600 if (not defined $height);
1.172     www      1345: 
                   1346:     $topic=~s/\W+/\+/g;
                   1347:     my $link='';
                   1348:     my $template='';
1.379     albertel 1349:     my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&amp;bug_file_loc='.
                   1350: 	&escape($ENV{'REQUEST_URI'}).'&amp;component='.$topic;
1.172     www      1351:     if (!$stayOnPage)
                   1352:     {
                   1353: 	$link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1354:     }
                   1355:     else
                   1356:     {
                   1357: 	$link = $url;
                   1358:     }
                   1359:     # Add the text
                   1360:     if ($text ne "")
                   1361:     {
                   1362: 	$template .= 
                   1363:   "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1364:   "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172     www      1365:     }
                   1366: 
                   1367:     # Add the graphic
1.179     matthew  1368:     my $title = &mt('Report a Bug');
1.215     albertel 1369:     my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172     www      1370:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1371:  <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172     www      1372: ENDTEMPLATE
                   1373:     if ($text ne '') { $template.='</td></tr></table>' };
                   1374:     return $template;
                   1375: 
                   1376: }
                   1377: 
                   1378: sub help_open_faq {
                   1379:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1380:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1381:     unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
                   1382:     $text = "" if (not defined $text);
                   1383: 	$stayOnPage=1;
                   1384:     $width = 350 if (not defined $width);
                   1385:     $height = 400 if (not defined $height);
                   1386: 
                   1387:     $topic=~s/\W+/\+/g;
                   1388:     my $link='';
                   1389:     my $template='';
                   1390:     my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
                   1391:     if (!$stayOnPage)
                   1392:     {
                   1393: 	$link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1394:     }
                   1395:     else
                   1396:     {
                   1397: 	$link = $url;
                   1398:     }
                   1399: 
                   1400:     # Add the text
                   1401:     if ($text ne "")
                   1402:     {
                   1403: 	$template .= 
1.173     www      1404:   "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1405:   "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172     www      1406:     }
                   1407: 
                   1408:     # Add the graphic
1.179     matthew  1409:     my $title = &mt('View the FAQ');
1.215     albertel 1410:     my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172     www      1411:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1412:  <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172     www      1413: ENDTEMPLATE
                   1414:     if ($text ne '') { $template.='</td></tr></table>' };
                   1415:     return $template;
                   1416: 
1.44      bowersj2 1417: }
1.37      matthew  1418: 
1.180     matthew  1419: ###############################################################
                   1420: ###############################################################
                   1421: 
1.45      matthew  1422: =pod
                   1423: 
1.648     raeburn  1424: =item * &change_content_javascript():
1.256     matthew  1425: 
                   1426: This and the next function allow you to create small sections of an
                   1427: otherwise static HTML page that you can update on the fly with
                   1428: Javascript, even in Netscape 4.
                   1429: 
                   1430: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
                   1431: must be written to the HTML page once. It will prove the Javascript
                   1432: function "change(name, content)". Calling the change function with the
                   1433: name of the section 
                   1434: you want to update, matching the name passed to C<changable_area>, and
                   1435: the new content you want to put in there, will put the content into
                   1436: that area.
                   1437: 
                   1438: B<Note>: Netscape 4 only reserves enough space for the changable area
                   1439: to contain room for the original contents. You need to "make space"
                   1440: for whatever changes you wish to make, and be B<sure> to check your
                   1441: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
                   1442: it's adequate for updating a one-line status display, but little more.
                   1443: This script will set the space to 100% width, so you only need to
                   1444: worry about height in Netscape 4.
                   1445: 
                   1446: Modern browsers are much less limiting, and if you can commit to the
                   1447: user not using Netscape 4, this feature may be used freely with
                   1448: pretty much any HTML.
                   1449: 
                   1450: =cut
                   1451: 
                   1452: sub change_content_javascript {
                   1453:     # If we're on Netscape 4, we need to use Layer-based code
1.258     albertel 1454:     if ($env{'browser.type'} eq 'netscape' &&
                   1455: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1456: 	return (<<NETSCAPE4);
                   1457: 	function change(name, content) {
                   1458: 	    doc = document.layers[name+"___escape"].layers[0].document;
                   1459: 	    doc.open();
                   1460: 	    doc.write(content);
                   1461: 	    doc.close();
                   1462: 	}
                   1463: NETSCAPE4
                   1464:     } else {
                   1465: 	# Otherwise, we need to use semi-standards-compliant code
                   1466: 	# (technically, "innerHTML" isn't standard but the equivalent
                   1467: 	# is really scary, and every useful browser supports it
                   1468: 	return (<<DOMBASED);
                   1469: 	function change(name, content) {
                   1470: 	    element = document.getElementById(name);
                   1471: 	    element.innerHTML = content;
                   1472: 	}
                   1473: DOMBASED
                   1474:     }
                   1475: }
                   1476: 
                   1477: =pod
                   1478: 
1.648     raeburn  1479: =item * &changable_area($name,$origContent):
1.256     matthew  1480: 
                   1481: This provides a "changable area" that can be modified on the fly via
                   1482: the Javascript code provided in C<change_content_javascript>. $name is
                   1483: the name you will use to reference the area later; do not repeat the
                   1484: same name on a given HTML page more then once. $origContent is what
                   1485: the area will originally contain, which can be left blank.
                   1486: 
                   1487: =cut
                   1488: 
                   1489: sub changable_area {
                   1490:     my ($name, $origContent) = @_;
                   1491: 
1.258     albertel 1492:     if ($env{'browser.type'} eq 'netscape' &&
                   1493: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1494: 	# If this is netscape 4, we need to use the Layer tag
                   1495: 	return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
                   1496:     } else {
                   1497: 	return "<span id='$name'>$origContent</span>";
                   1498:     }
                   1499: }
                   1500: 
                   1501: =pod
                   1502: 
1.648     raeburn  1503: =item * &viewport_geometry_js 
1.590     raeburn  1504: 
                   1505: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
                   1506: 
                   1507: =cut
                   1508: 
                   1509: 
                   1510: sub viewport_geometry_js { 
                   1511:     return <<"GEOMETRY";
                   1512: var Geometry = {};
                   1513: function init_geometry() {
                   1514:     if (Geometry.init) { return };
                   1515:     Geometry.init=1;
                   1516:     if (window.innerHeight) {
                   1517:         Geometry.getViewportHeight   = function() { return window.innerHeight; };
                   1518:         Geometry.getViewportWidth   = function() { return window.innerWidth; };
                   1519:         Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
                   1520:         Geometry.getVerticalScroll   = function() { return window.pageYOffset; };
                   1521:     }
                   1522:     else if (document.documentElement && document.documentElement.clientHeight) {
                   1523:         Geometry.getViewportHeight =
                   1524:             function() { return document.documentElement.clientHeight; };
                   1525:         Geometry.getViewportWidth =
                   1526:             function() { return document.documentElement.clientWidth; };
                   1527: 
                   1528:         Geometry.getHorizontalScroll =
                   1529:             function() { return document.documentElement.scrollLeft; };
                   1530:         Geometry.getVerticalScroll =
                   1531:             function() { return document.documentElement.scrollTop; };
                   1532:     }
                   1533:     else if (document.body.clientHeight) {
                   1534:         Geometry.getViewportHeight =
                   1535:             function() { return document.body.clientHeight; };
                   1536:         Geometry.getViewportWidth =
                   1537:             function() { return document.body.clientWidth; };
                   1538:         Geometry.getHorizontalScroll =
                   1539:             function() { return document.body.scrollLeft; };
                   1540:         Geometry.getVerticalScroll =
                   1541:             function() { return document.body.scrollTop; };
                   1542:     }
                   1543: }
                   1544: 
                   1545: GEOMETRY
                   1546: }
                   1547: 
                   1548: =pod
                   1549: 
1.648     raeburn  1550: =item * &viewport_size_js()
1.590     raeburn  1551: 
                   1552: 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. 
                   1553: 
                   1554: =cut
                   1555: 
                   1556: sub viewport_size_js {
                   1557:     my $geometry = &viewport_geometry_js();
                   1558:     return <<"DIMS";
                   1559: 
                   1560: $geometry
                   1561: 
                   1562: function getViewportDims(width,height) {
                   1563:     init_geometry();
                   1564:     width.value = Geometry.getViewportWidth();
                   1565:     height.value = Geometry.getViewportHeight();
                   1566:     return;
                   1567: }
                   1568: 
                   1569: DIMS
                   1570: }
                   1571: 
                   1572: =pod
                   1573: 
1.648     raeburn  1574: =item * &resize_textarea_js()
1.565     albertel 1575: 
                   1576: emits the needed javascript to resize a textarea to be as big as possible
                   1577: 
                   1578: creates a function resize_textrea that takes two IDs first should be
                   1579: the id of the element to resize, second should be the id of a div that
                   1580: surrounds everything that comes after the textarea, this routine needs
                   1581: to be attached to the <body> for the onload and onresize events.
                   1582: 
1.648     raeburn  1583: =back
1.565     albertel 1584: 
                   1585: =cut
                   1586: 
                   1587: sub resize_textarea_js {
1.590     raeburn  1588:     my $geometry = &viewport_geometry_js();
1.565     albertel 1589:     return <<"RESIZE";
                   1590:     <script type="text/javascript">
1.824     bisitz   1591: // <![CDATA[
1.590     raeburn  1592: $geometry
1.565     albertel 1593: 
1.588     albertel 1594: function getX(element) {
                   1595:     var x = 0;
                   1596:     while (element) {
                   1597: 	x += element.offsetLeft;
                   1598: 	element = element.offsetParent;
                   1599:     }
                   1600:     return x;
                   1601: }
                   1602: function getY(element) {
                   1603:     var y = 0;
                   1604:     while (element) {
                   1605: 	y += element.offsetTop;
                   1606: 	element = element.offsetParent;
                   1607:     }
                   1608:     return y;
                   1609: }
                   1610: 
                   1611: 
1.565     albertel 1612: function resize_textarea(textarea_id,bottom_id) {
                   1613:     init_geometry();
                   1614:     var textarea        = document.getElementById(textarea_id);
                   1615:     //alert(textarea);
                   1616: 
1.588     albertel 1617:     var textarea_top    = getY(textarea);
1.565     albertel 1618:     var textarea_height = textarea.offsetHeight;
                   1619:     var bottom          = document.getElementById(bottom_id);
1.588     albertel 1620:     var bottom_top      = getY(bottom);
1.565     albertel 1621:     var bottom_height   = bottom.offsetHeight;
                   1622:     var window_height   = Geometry.getViewportHeight();
1.588     albertel 1623:     var fudge           = 23;
1.565     albertel 1624:     var new_height      = window_height-fudge-textarea_top-bottom_height;
                   1625:     if (new_height < 300) {
                   1626: 	new_height = 300;
                   1627:     }
                   1628:     textarea.style.height=new_height+'px';
                   1629: }
1.824     bisitz   1630: // ]]>
1.565     albertel 1631: </script>
                   1632: RESIZE
                   1633: 
                   1634: }
                   1635: 
                   1636: =pod
                   1637: 
1.256     matthew  1638: =head1 Excel and CSV file utility routines
                   1639: 
                   1640: =over 4
                   1641: 
                   1642: =cut
                   1643: 
                   1644: ###############################################################
                   1645: ###############################################################
                   1646: 
                   1647: =pod
                   1648: 
1.648     raeburn  1649: =item * &csv_translate($text) 
1.37      matthew  1650: 
1.185     www      1651: Translate $text to allow it to be output as a 'comma separated values' 
1.37      matthew  1652: format.
                   1653: 
                   1654: =cut
                   1655: 
1.180     matthew  1656: ###############################################################
                   1657: ###############################################################
1.37      matthew  1658: sub csv_translate {
                   1659:     my $text = shift;
                   1660:     $text =~ s/\"/\"\"/g;
1.209     albertel 1661:     $text =~ s/\n/ /g;
1.37      matthew  1662:     return $text;
                   1663: }
1.180     matthew  1664: 
                   1665: ###############################################################
                   1666: ###############################################################
                   1667: 
                   1668: =pod
                   1669: 
1.648     raeburn  1670: =item * &define_excel_formats()
1.180     matthew  1671: 
                   1672: Define some commonly used Excel cell formats.
                   1673: 
                   1674: Currently supported formats:
                   1675: 
                   1676: =over 4
                   1677: 
                   1678: =item header
                   1679: 
                   1680: =item bold
                   1681: 
                   1682: =item h1
                   1683: 
                   1684: =item h2
                   1685: 
                   1686: =item h3
                   1687: 
1.256     matthew  1688: =item h4
                   1689: 
                   1690: =item i
                   1691: 
1.180     matthew  1692: =item date
                   1693: 
                   1694: =back
                   1695: 
                   1696: Inputs: $workbook
                   1697: 
                   1698: Returns: $format, a hash reference.
                   1699: 
                   1700: =cut
                   1701: 
                   1702: ###############################################################
                   1703: ###############################################################
                   1704: sub define_excel_formats {
                   1705:     my ($workbook) = @_;
                   1706:     my $format;
                   1707:     $format->{'header'} = $workbook->add_format(bold      => 1, 
                   1708:                                                 bottom    => 1,
                   1709:                                                 align     => 'center');
                   1710:     $format->{'bold'} = $workbook->add_format(bold=>1);
                   1711:     $format->{'h1'}   = $workbook->add_format(bold=>1, size=>18);
                   1712:     $format->{'h2'}   = $workbook->add_format(bold=>1, size=>16);
                   1713:     $format->{'h3'}   = $workbook->add_format(bold=>1, size=>14);
1.255     matthew  1714:     $format->{'h4'}   = $workbook->add_format(bold=>1, size=>12);
1.246     matthew  1715:     $format->{'i'}    = $workbook->add_format(italic=>1);
1.180     matthew  1716:     $format->{'date'} = $workbook->add_format(num_format=>
1.207     matthew  1717:                                             'mm/dd/yyyy hh:mm:ss');
1.180     matthew  1718:     return $format;
                   1719: }
                   1720: 
                   1721: ###############################################################
                   1722: ###############################################################
1.113     bowersj2 1723: 
                   1724: =pod
                   1725: 
1.648     raeburn  1726: =item * &create_workbook()
1.255     matthew  1727: 
                   1728: Create an Excel worksheet.  If it fails, output message on the
                   1729: request object and return undefs.
                   1730: 
                   1731: Inputs: Apache request object
                   1732: 
                   1733: Returns (undef) on failure, 
                   1734:     Excel worksheet object, scalar with filename, and formats 
                   1735:     from &Apache::loncommon::define_excel_formats on success
                   1736: 
                   1737: =cut
                   1738: 
                   1739: ###############################################################
                   1740: ###############################################################
                   1741: sub create_workbook {
                   1742:     my ($r) = @_;
                   1743:         #
                   1744:     # Create the excel spreadsheet
                   1745:     my $filename = '/prtspool/'.
1.258     albertel 1746:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255     matthew  1747:         time.'_'.rand(1000000000).'.xls';
                   1748:     my $workbook  = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
                   1749:     if (! defined($workbook)) {
                   1750:         $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928     bisitz   1751:         $r->print(
                   1752:             '<p class="LC_error">'
                   1753:            .&mt('Problems occurred in creating the new Excel file.')
                   1754:            .' '.&mt('This error has been logged.')
                   1755:            .' '.&mt('Please alert your LON-CAPA administrator.')
                   1756:            .'</p>'
                   1757:         );
1.255     matthew  1758:         return (undef);
                   1759:     }
                   1760:     #
                   1761:     $workbook->set_tempdir('/home/httpd/perl/tmp');
                   1762:     #
                   1763:     my $format = &Apache::loncommon::define_excel_formats($workbook);
                   1764:     return ($workbook,$filename,$format);
                   1765: }
                   1766: 
                   1767: ###############################################################
                   1768: ###############################################################
                   1769: 
                   1770: =pod
                   1771: 
1.648     raeburn  1772: =item * &create_text_file()
1.113     bowersj2 1773: 
1.542     raeburn  1774: Create a file to write to and eventually make available to the user.
1.256     matthew  1775: If file creation fails, outputs an error message on the request object and 
                   1776: return undefs.
1.113     bowersj2 1777: 
1.256     matthew  1778: Inputs: Apache request object, and file suffix
1.113     bowersj2 1779: 
1.256     matthew  1780: Returns (undef) on failure, 
                   1781:     Filehandle and filename on success.
1.113     bowersj2 1782: 
                   1783: =cut
                   1784: 
1.256     matthew  1785: ###############################################################
                   1786: ###############################################################
                   1787: sub create_text_file {
                   1788:     my ($r,$suffix) = @_;
                   1789:     if (! defined($suffix)) { $suffix = 'txt'; };
                   1790:     my $fh;
                   1791:     my $filename = '/prtspool/'.
1.258     albertel 1792:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256     matthew  1793:         time.'_'.rand(1000000000).'.'.$suffix;
                   1794:     $fh = Apache::File->new('>/home/httpd'.$filename);
                   1795:     if (! defined($fh)) {
                   1796:         $r->log_error("Couldn't open $filename for output $!");
1.928     bisitz   1797:         $r->print(
                   1798:             '<p class="LC_error">'
                   1799:            .&mt('Problems occurred in creating the output file.')
                   1800:            .' '.&mt('This error has been logged.')
                   1801:            .' '.&mt('Please alert your LON-CAPA administrator.')
                   1802:            .'</p>'
                   1803:         );
1.113     bowersj2 1804:     }
1.256     matthew  1805:     return ($fh,$filename)
1.113     bowersj2 1806: }
                   1807: 
                   1808: 
1.256     matthew  1809: =pod 
1.113     bowersj2 1810: 
                   1811: =back
                   1812: 
                   1813: =cut
1.37      matthew  1814: 
                   1815: ###############################################################
1.33      matthew  1816: ##        Home server <option> list generating code          ##
                   1817: ###############################################################
1.35      matthew  1818: 
1.169     www      1819: # ------------------------------------------
                   1820: 
                   1821: sub domain_select {
                   1822:     my ($name,$value,$multiple)=@_;
                   1823:     my %domains=map { 
1.514     albertel 1824: 	$_ => $_.' '. &Apache::lonnet::domain($_,'description') 
1.512     albertel 1825:     } &Apache::lonnet::all_domains();
1.169     www      1826:     if ($multiple) {
                   1827: 	$domains{''}=&mt('Any domain');
1.550     albertel 1828: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287     albertel 1829: 	return &multiple_select_form($name,$value,4,\%domains);
1.169     www      1830:     } else {
1.550     albertel 1831: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970     raeburn  1832: 	return &select_form($name,$value,\%domains);
1.169     www      1833:     }
                   1834: }
                   1835: 
1.282     albertel 1836: #-------------------------------------------
                   1837: 
                   1838: =pod
                   1839: 
1.519     raeburn  1840: =head1 Routines for form select boxes
                   1841: 
                   1842: =over 4
                   1843: 
1.648     raeburn  1844: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282     albertel 1845: 
                   1846: Returns a string containing a <select> element int multiple mode
                   1847: 
                   1848: 
                   1849: Args:
                   1850:   $name - name of the <select> element
1.506     raeburn  1851:   $value - scalar or array ref of values that should already be selected
1.282     albertel 1852:   $size - number of rows long the select element is
1.283     albertel 1853:   $hash - the elements should be 'option' => 'shown text'
1.282     albertel 1854:           (shown text should already have been &mt())
1.506     raeburn  1855:   $order - (optional) array ref of the order to show the elements in
1.283     albertel 1856: 
1.282     albertel 1857: =cut
                   1858: 
                   1859: #-------------------------------------------
1.169     www      1860: sub multiple_select_form {
1.284     albertel 1861:     my ($name,$value,$size,$hash,$order)=@_;
1.169     www      1862:     my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
                   1863:     my $output='';
1.191     matthew  1864:     if (! defined($size)) {
                   1865:         $size = 4;
1.283     albertel 1866:         if (scalar(keys(%$hash))<4) {
                   1867:             $size = scalar(keys(%$hash));
1.191     matthew  1868:         }
                   1869:     }
1.734     bisitz   1870:     $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501     banghart 1871:     my @order;
1.506     raeburn  1872:     if (ref($order) eq 'ARRAY')  {
                   1873:         @order = @{$order};
                   1874:     } else {
                   1875:         @order = sort(keys(%$hash));
1.501     banghart 1876:     }
                   1877:     if (exists($$hash{'select_form_order'})) {
                   1878:         @order = @{$$hash{'select_form_order'}};
                   1879:     }
                   1880:         
1.284     albertel 1881:     foreach my $key (@order) {
1.356     albertel 1882:         $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284     albertel 1883:         $output.='selected="selected" ' if ($selected{$key});
                   1884:         $output.='>'.$hash->{$key}."</option>\n";
1.169     www      1885:     }
                   1886:     $output.="</select>\n";
                   1887:     return $output;
                   1888: }
                   1889: 
1.88      www      1890: #-------------------------------------------
                   1891: 
                   1892: =pod
                   1893: 
1.970     raeburn  1894: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88      www      1895: 
                   1896: Returns a string containing a <select name='$name' size='1'> form to 
1.970     raeburn  1897: allow a user to select options from a ref to a hash containing:
                   1898: option_name => displayed text. An optional $onchange can include
                   1899: a javascript onchange item, e.g., onchange="this.form.submit();"  
                   1900: 
1.88      www      1901: See lonrights.pm for an example invocation and use.
                   1902: 
                   1903: =cut
                   1904: 
                   1905: #-------------------------------------------
                   1906: sub select_form {
1.970     raeburn  1907:     my ($def,$name,$hashref,$onchange) = @_;
                   1908:     return unless (ref($hashref) eq 'HASH');
                   1909:     if ($onchange) {
                   1910:         $onchange = ' onchange="'.$onchange.'"';
                   1911:     }
                   1912:     my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128     albertel 1913:     my @keys;
1.970     raeburn  1914:     if (exists($hashref->{'select_form_order'})) {
                   1915: 	@keys=@{$hashref->{'select_form_order'}};
1.128     albertel 1916:     } else {
1.970     raeburn  1917: 	@keys=sort(keys(%{$hashref}));
1.128     albertel 1918:     }
1.356     albertel 1919:     foreach my $key (@keys) {
                   1920:         $selectform.=
                   1921: 	    '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
                   1922:             ($key eq $def ? 'selected="selected" ' : '').
1.970     raeburn  1923:                 ">".$hashref->{$key}."</option>\n";
1.88      www      1924:     }
                   1925:     $selectform.="</select>";
                   1926:     return $selectform;
                   1927: }
                   1928: 
1.475     www      1929: # For display filters
                   1930: 
                   1931: sub display_filter {
                   1932:     if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477     www      1933:     if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714     bisitz   1934:     return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475     www      1935: 			       &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
                   1936: 							   (&mt('all'),10,20,50,100,1000,10000))).
1.714     bisitz   1937: 	   '</label></span> <span class="LC_nobreak">'.
1.475     www      1938:            &mt('Filter [_1]',
1.477     www      1939: 	   &select_form($env{'form.displayfilter'},
                   1940: 			'displayfilter',
1.970     raeburn  1941: 			{'currentfolder' => 'Current folder/page',
1.477     www      1942: 			 'containing' => 'Containing phrase',
1.970     raeburn  1943: 			 'none' => 'None'})).
1.714     bisitz   1944: 			 '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475     www      1945: }
                   1946: 
1.167     www      1947: sub gradeleveldescription {
                   1948:     my $gradelevel=shift;
                   1949:     my %gradelevels=(0 => 'Not specified',
                   1950: 		     1 => 'Grade 1',
                   1951: 		     2 => 'Grade 2',
                   1952: 		     3 => 'Grade 3',
                   1953: 		     4 => 'Grade 4',
                   1954: 		     5 => 'Grade 5',
                   1955: 		     6 => 'Grade 6',
                   1956: 		     7 => 'Grade 7',
                   1957: 		     8 => 'Grade 8',
                   1958: 		     9 => 'Grade 9',
                   1959: 		     10 => 'Grade 10',
                   1960: 		     11 => 'Grade 11',
                   1961: 		     12 => 'Grade 12',
                   1962: 		     13 => 'Grade 13',
                   1963: 		     14 => '100 Level',
                   1964: 		     15 => '200 Level',
                   1965: 		     16 => '300 Level',
                   1966: 		     17 => '400 Level',
                   1967: 		     18 => 'Graduate Level');
                   1968:     return &mt($gradelevels{$gradelevel});
                   1969: }
                   1970: 
1.163     www      1971: sub select_level_form {
                   1972:     my ($deflevel,$name)=@_;
                   1973:     unless ($deflevel) { $deflevel=0; }
1.167     www      1974:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
                   1975:     for (my $i=0; $i<=18; $i++) {
                   1976:         $selectform.="<option value=\"$i\" ".
1.253     albertel 1977:             ($i==$deflevel ? 'selected="selected" ' : '').
1.167     www      1978:                 ">".&gradeleveldescription($i)."</option>\n";
                   1979:     }
                   1980:     $selectform.="</select>";
                   1981:     return $selectform;
1.163     www      1982: }
1.167     www      1983: 
1.35      matthew  1984: #-------------------------------------------
                   1985: 
1.45      matthew  1986: =pod
                   1987: 
1.910     raeburn  1988: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms)
1.35      matthew  1989: 
                   1990: Returns a string containing a <select name='$name' size='1'> form to 
                   1991: allow a user to select the domain to preform an operation in.  
                   1992: See loncreateuser.pm for an example invocation and use.
                   1993: 
1.90      www      1994: If the $includeempty flag is set, it also includes an empty choice ("no domain
                   1995: selected");
                   1996: 
1.743     raeburn  1997: If the $showdomdesc flag is set, the domain name is followed by the domain description.
                   1998: 
1.910     raeburn  1999: 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.
                   2000: 
                   2001: The optional $incdoms is a reference to an array of domains which will be the only available options. 
1.563     raeburn  2002: 
1.35      matthew  2003: =cut
                   2004: 
                   2005: #-------------------------------------------
1.34      matthew  2006: sub select_dom_form {
1.910     raeburn  2007:     my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms) = @_;
1.872     raeburn  2008:     if ($onchange) {
1.874     raeburn  2009:         $onchange = ' onchange="'.$onchange.'"';
1.743     raeburn  2010:     }
1.910     raeburn  2011:     my @domains;
                   2012:     if (ref($incdoms) eq 'ARRAY') {
                   2013:         @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
                   2014:     } else {
                   2015:         @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
                   2016:     }
1.90      www      2017:     if ($includeempty) { @domains=('',@domains); }
1.743     raeburn  2018:     my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356     albertel 2019:     foreach my $dom (@domains) {
                   2020:         $selectdomain.="<option value=\"$dom\" ".
1.563     raeburn  2021:             ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
                   2022:         if ($showdomdesc) {
                   2023:             if ($dom ne '') {
                   2024:                 my $domdesc = &Apache::lonnet::domain($dom,'description');
                   2025:                 if ($domdesc ne '') {
                   2026:                     $selectdomain .= ' ('.$domdesc.')';
                   2027:                 }
                   2028:             } 
                   2029:         }
                   2030:         $selectdomain .= "</option>\n";
1.34      matthew  2031:     }
                   2032:     $selectdomain.="</select>";
                   2033:     return $selectdomain;
                   2034: }
                   2035: 
1.35      matthew  2036: #-------------------------------------------
                   2037: 
1.45      matthew  2038: =pod
                   2039: 
1.648     raeburn  2040: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35      matthew  2041: 
1.586     raeburn  2042: input: 4 arguments (two required, two optional) - 
                   2043:     $domain - domain of new user
                   2044:     $name - name of form element
                   2045:     $default - Value of 'default' causes a default item to be first 
                   2046:                             option, and selected by default. 
                   2047:     $hide - Value of 'hide' causes hiding of the name of the server, 
                   2048:                             if 1 server found, or default, if 0 found.
1.594     raeburn  2049: output: returns 2 items: 
1.586     raeburn  2050: (a) form element which contains either:
                   2051:    (i) <select name="$name">
                   2052:         <option value="$hostid1">$hostid $servers{$hostid}</option>
                   2053:         <option value="$hostid2">$hostid $servers{$hostid}</option>       
                   2054:        </select>
                   2055:        form item if there are multiple library servers in $domain, or
                   2056:    (ii) an <input type="hidden" name="$name" value="$hostid" /> form item 
                   2057:        if there is only one library server in $domain.
                   2058: 
                   2059: (b) number of library servers found.
                   2060: 
                   2061: See loncreateuser.pm for example of use.
1.35      matthew  2062: 
                   2063: =cut
                   2064: 
                   2065: #-------------------------------------------
1.586     raeburn  2066: sub home_server_form_item {
                   2067:     my ($domain,$name,$default,$hide) = @_;
1.513     albertel 2068:     my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586     raeburn  2069:     my $result;
                   2070:     my $numlib = keys(%servers);
                   2071:     if ($numlib > 1) {
                   2072:         $result .= '<select name="'.$name.'" />'."\n";
                   2073:         if ($default) {
1.804     bisitz   2074:             $result .= '<option value="default" selected="selected">'.&mt('default').
1.586     raeburn  2075:                        '</option>'."\n";
                   2076:         }
                   2077:         foreach my $hostid (sort(keys(%servers))) {
                   2078:             $result.= '<option value="'.$hostid.'">'.
                   2079: 	              $hostid.' '.$servers{$hostid}."</option>\n";
                   2080:         }
                   2081:         $result .= '</select>'."\n";
                   2082:     } elsif ($numlib == 1) {
                   2083:         my $hostid;
                   2084:         foreach my $item (keys(%servers)) {
                   2085:             $hostid = $item;
                   2086:         }
                   2087:         $result .= '<input type="hidden" name="'.$name.'" value="'.
                   2088:                    $hostid.'" />';
                   2089:                    if (!$hide) {
                   2090:                        $result .= $hostid.' '.$servers{$hostid};
                   2091:                    }
                   2092:                    $result .= "\n";
                   2093:     } elsif ($default) {
                   2094:         $result .= '<input type="hidden" name="'.$name.
                   2095:                    '" value="default" />';
                   2096:                    if (!$hide) {
                   2097:                        $result .= &mt('default');
                   2098:                    }
                   2099:                    $result .= "\n";
1.33      matthew  2100:     }
1.586     raeburn  2101:     return ($result,$numlib);
1.33      matthew  2102: }
1.112     bowersj2 2103: 
                   2104: =pod
                   2105: 
1.534     albertel 2106: =back 
                   2107: 
1.112     bowersj2 2108: =cut
1.87      matthew  2109: 
                   2110: ###############################################################
1.112     bowersj2 2111: ##                  Decoding User Agent                      ##
1.87      matthew  2112: ###############################################################
                   2113: 
                   2114: =pod
                   2115: 
1.112     bowersj2 2116: =head1 Decoding the User Agent
                   2117: 
                   2118: =over 4
                   2119: 
                   2120: =item * &decode_user_agent()
1.87      matthew  2121: 
                   2122: Inputs: $r
                   2123: 
                   2124: Outputs:
                   2125: 
                   2126: =over 4
                   2127: 
1.112     bowersj2 2128: =item * $httpbrowser
1.87      matthew  2129: 
1.112     bowersj2 2130: =item * $clientbrowser
1.87      matthew  2131: 
1.112     bowersj2 2132: =item * $clientversion
1.87      matthew  2133: 
1.112     bowersj2 2134: =item * $clientmathml
1.87      matthew  2135: 
1.112     bowersj2 2136: =item * $clientunicode
1.87      matthew  2137: 
1.112     bowersj2 2138: =item * $clientos
1.87      matthew  2139: 
                   2140: =back
                   2141: 
1.157     matthew  2142: =back 
                   2143: 
1.87      matthew  2144: =cut
                   2145: 
                   2146: ###############################################################
                   2147: ###############################################################
                   2148: sub decode_user_agent {
1.247     albertel 2149:     my ($r)=@_;
1.87      matthew  2150:     my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
                   2151:     my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
                   2152:     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247     albertel 2153:     if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87      matthew  2154:     my $clientbrowser='unknown';
                   2155:     my $clientversion='0';
                   2156:     my $clientmathml='';
                   2157:     my $clientunicode='0';
                   2158:     for (my $i=0;$i<=$#browsertype;$i++) {
                   2159:         my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
                   2160: 	if (($httpbrowser=~/$match/i)  && ($httpbrowser!~/$notmatch/i)) {
                   2161: 	    $clientbrowser=$bname;
                   2162:             $httpbrowser=~/$vreg/i;
                   2163: 	    $clientversion=$1;
                   2164:             $clientmathml=($clientversion>=$minv);
                   2165:             $clientunicode=($clientversion>=$univ);
                   2166: 	}
                   2167:     }
                   2168:     my $clientos='unknown';
                   2169:     if (($httpbrowser=~/linux/i) ||
                   2170:         ($httpbrowser=~/unix/i) ||
                   2171:         ($httpbrowser=~/ux/i) ||
                   2172:         ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
                   2173:     if (($httpbrowser=~/vax/i) ||
                   2174:         ($httpbrowser=~/vms/i)) { $clientos='vms'; }
                   2175:     if ($httpbrowser=~/next/i) { $clientos='next'; }
                   2176:     if (($httpbrowser=~/mac/i) ||
                   2177:         ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
                   2178:     if ($httpbrowser=~/win/i) { $clientos='win'; }
                   2179:     if ($httpbrowser=~/embed/i) { $clientos='pda'; }
                   2180:     return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   2181:             $clientunicode,$clientos,);
                   2182: }
                   2183: 
1.32      matthew  2184: ###############################################################
                   2185: ##    Authentication changing form generation subroutines    ##
                   2186: ###############################################################
                   2187: ##
                   2188: ## All of the authform_xxxxxxx subroutines take their inputs in a
                   2189: ## hash, and have reasonable default values.
                   2190: ##
                   2191: ##    formname = the name given in the <form> tag.
1.35      matthew  2192: #-------------------------------------------
                   2193: 
1.45      matthew  2194: =pod
                   2195: 
1.112     bowersj2 2196: =head1 Authentication Routines
                   2197: 
                   2198: =over 4
                   2199: 
1.648     raeburn  2200: =item * &authform_xxxxxx()
1.35      matthew  2201: 
                   2202: The authform_xxxxxx subroutines provide javascript and html forms which 
                   2203: handle some of the conveniences required for authentication forms.  
                   2204: This is not an optimal method, but it works.  
                   2205: 
                   2206: =over 4
                   2207: 
1.112     bowersj2 2208: =item * authform_header
1.35      matthew  2209: 
1.112     bowersj2 2210: =item * authform_authorwarning
1.35      matthew  2211: 
1.112     bowersj2 2212: =item * authform_nochange
1.35      matthew  2213: 
1.112     bowersj2 2214: =item * authform_kerberos
1.35      matthew  2215: 
1.112     bowersj2 2216: =item * authform_internal
1.35      matthew  2217: 
1.112     bowersj2 2218: =item * authform_filesystem
1.35      matthew  2219: 
                   2220: =back
                   2221: 
1.648     raeburn  2222: See loncreateuser.pm for invocation and use examples.
1.157     matthew  2223: 
1.35      matthew  2224: =cut
                   2225: 
                   2226: #-------------------------------------------
1.32      matthew  2227: sub authform_header{  
                   2228:     my %in = (
                   2229:         formname => 'cu',
1.80      albertel 2230:         kerb_def_dom => '',
1.32      matthew  2231:         @_,
                   2232:     );
                   2233:     $in{'formname'} = 'document.' . $in{'formname'};
                   2234:     my $result='';
1.80      albertel 2235: 
                   2236: #---------------------------------------------- Code for upper case translation
                   2237:     my $Javascript_toUpperCase;
                   2238:     unless ($in{kerb_def_dom}) {
                   2239:         $Javascript_toUpperCase =<<"END";
                   2240:         switch (choice) {
                   2241:            case 'krb': currentform.elements[choicearg].value =
                   2242:                currentform.elements[choicearg].value.toUpperCase();
                   2243:                break;
                   2244:            default:
                   2245:         }
                   2246: END
                   2247:     } else {
                   2248:         $Javascript_toUpperCase = "";
                   2249:     }
                   2250: 
1.165     raeburn  2251:     my $radioval = "'nochange'";
1.591     raeburn  2252:     if (defined($in{'curr_authtype'})) {
                   2253:         if ($in{'curr_authtype'} ne '') {
                   2254:             $radioval = "'".$in{'curr_authtype'}."arg'";
                   2255:         }
1.174     matthew  2256:     }
1.165     raeburn  2257:     my $argfield = 'null';
1.591     raeburn  2258:     if (defined($in{'mode'})) {
1.165     raeburn  2259:         if ($in{'mode'} eq 'modifycourse')  {
1.591     raeburn  2260:             if (defined($in{'curr_autharg'})) {
                   2261:                 if ($in{'curr_autharg'} ne '') {
1.165     raeburn  2262:                     $argfield = "'$in{'curr_autharg'}'";
                   2263:                 }
                   2264:             }
                   2265:         }
                   2266:     }
                   2267: 
1.32      matthew  2268:     $result.=<<"END";
                   2269: var current = new Object();
1.165     raeburn  2270: current.radiovalue = $radioval;
                   2271: current.argfield = $argfield;
1.32      matthew  2272: 
                   2273: function changed_radio(choice,currentform) {
                   2274:     var choicearg = choice + 'arg';
                   2275:     // If a radio button in changed, we need to change the argfield
                   2276:     if (current.radiovalue != choice) {
                   2277:         current.radiovalue = choice;
                   2278:         if (current.argfield != null) {
                   2279:             currentform.elements[current.argfield].value = '';
                   2280:         }
                   2281:         if (choice == 'nochange') {
                   2282:             current.argfield = null;
                   2283:         } else {
                   2284:             current.argfield = choicearg;
                   2285:             switch(choice) {
                   2286:                 case 'krb': 
                   2287:                     currentform.elements[current.argfield].value = 
                   2288:                         "$in{'kerb_def_dom'}";
                   2289:                 break;
                   2290:               default:
                   2291:                 break;
                   2292:             }
                   2293:         }
                   2294:     }
                   2295:     return;
                   2296: }
1.22      www      2297: 
1.32      matthew  2298: function changed_text(choice,currentform) {
                   2299:     var choicearg = choice + 'arg';
                   2300:     if (currentform.elements[choicearg].value !='') {
1.80      albertel 2301:         $Javascript_toUpperCase
1.32      matthew  2302:         // clear old field
                   2303:         if ((current.argfield != choicearg) && (current.argfield != null)) {
                   2304:             currentform.elements[current.argfield].value = '';
                   2305:         }
                   2306:         current.argfield = choicearg;
                   2307:     }
                   2308:     set_auth_radio_buttons(choice,currentform);
                   2309:     return;
1.20      www      2310: }
1.32      matthew  2311: 
                   2312: function set_auth_radio_buttons(newvalue,currentform) {
1.986     raeburn  2313:     var numauthchoices = currentform.login.length;
                   2314:     if (typeof numauthchoices  == "undefined") {
                   2315:         return;
                   2316:     } 
1.32      matthew  2317:     var i=0;
1.986     raeburn  2318:     while (i < numauthchoices) {
1.32      matthew  2319:         if (currentform.login[i].value == newvalue) { break; }
                   2320:         i++;
                   2321:     }
1.986     raeburn  2322:     if (i == numauthchoices) {
1.32      matthew  2323:         return;
                   2324:     }
                   2325:     current.radiovalue = newvalue;
                   2326:     currentform.login[i].checked = true;
                   2327:     return;
                   2328: }
                   2329: END
                   2330:     return $result;
                   2331: }
                   2332: 
                   2333: sub authform_authorwarning{
                   2334:     my $result='';
1.144     matthew  2335:     $result='<i>'.
                   2336:         &mt('As a general rule, only authors or co-authors should be '.
                   2337:             'filesystem authenticated '.
                   2338:             '(which allows access to the server filesystem).')."</i>\n";
1.32      matthew  2339:     return $result;
                   2340: }
                   2341: 
                   2342: sub authform_nochange{  
                   2343:     my %in = (
                   2344:               formname => 'document.cu',
                   2345:               kerb_def_dom => 'MSU.EDU',
                   2346:               @_,
                   2347:           );
1.586     raeburn  2348:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'}); 
                   2349:     my $result;
                   2350:     if (keys(%can_assign) == 0) {
                   2351:         $result = &mt('Under you current role you are not permitted to change login settings for this user');  
                   2352:     } else {
                   2353:         $result = '<label>'.&mt('[_1] Do not change login data',
                   2354:                   '<input type="radio" name="login" value="nochange" '.
                   2355:                   'checked="checked" onclick="'.
1.281     albertel 2356:             "javascript:changed_radio('nochange',$in{'formname'});".'" />').
                   2357: 	    '</label>';
1.586     raeburn  2358:     }
1.32      matthew  2359:     return $result;
                   2360: }
                   2361: 
1.591     raeburn  2362: sub authform_kerberos {
1.32      matthew  2363:     my %in = (
                   2364:               formname => 'document.cu',
                   2365:               kerb_def_dom => 'MSU.EDU',
1.80      albertel 2366:               kerb_def_auth => 'krb4',
1.32      matthew  2367:               @_,
                   2368:               );
1.586     raeburn  2369:     my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
                   2370:         $autharg,$jscall);
                   2371:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.80      albertel 2372:     if ($in{'kerb_def_auth'} eq 'krb5') {
1.772     bisitz   2373:        $check5 = ' checked="checked"';
1.80      albertel 2374:     } else {
1.772     bisitz   2375:        $check4 = ' checked="checked"';
1.80      albertel 2376:     }
1.165     raeburn  2377:     $krbarg = $in{'kerb_def_dom'};
1.591     raeburn  2378:     if (defined($in{'curr_authtype'})) {
                   2379:         if ($in{'curr_authtype'} eq 'krb') {
1.772     bisitz   2380:             $krbcheck = ' checked="checked"';
1.623     raeburn  2381:             if (defined($in{'mode'})) {
                   2382:                 if ($in{'mode'} eq 'modifyuser') {
                   2383:                     $krbcheck = '';
                   2384:                 }
                   2385:             }
1.591     raeburn  2386:             if (defined($in{'curr_kerb_ver'})) {
                   2387:                 if ($in{'curr_krb_ver'} eq '5') {
1.772     bisitz   2388:                     $check5 = ' checked="checked"';
1.591     raeburn  2389:                     $check4 = '';
                   2390:                 } else {
1.772     bisitz   2391:                     $check4 = ' checked="checked"';
1.591     raeburn  2392:                     $check5 = '';
                   2393:                 }
1.586     raeburn  2394:             }
1.591     raeburn  2395:             if (defined($in{'curr_autharg'})) {
1.165     raeburn  2396:                 $krbarg = $in{'curr_autharg'};
                   2397:             }
1.586     raeburn  2398:             if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591     raeburn  2399:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2400:                     $result = 
                   2401:     &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
                   2402:         $in{'curr_autharg'},$krbver);
                   2403:                 } else {
                   2404:                     $result =
                   2405:     &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
                   2406:                 }
                   2407:                 return $result; 
                   2408:             }
                   2409:         }
                   2410:     } else {
                   2411:         if ($authnum == 1) {
1.784     bisitz   2412:             $authtype = '<input type="hidden" name="login" value="krb" />';
1.165     raeburn  2413:         }
                   2414:     }
1.586     raeburn  2415:     if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
                   2416:         return;
1.587     raeburn  2417:     } elsif ($authtype eq '') {
1.591     raeburn  2418:         if (defined($in{'mode'})) {
1.587     raeburn  2419:             if ($in{'mode'} eq 'modifycourse') {
                   2420:                 if ($authnum == 1) {
1.784     bisitz   2421:                     $authtype = '<input type="hidden" name="login" value="krb" />';
1.587     raeburn  2422:                 }
                   2423:             }
                   2424:         }
1.586     raeburn  2425:     }
                   2426:     $jscall = "javascript:changed_radio('krb',$in{'formname'});";
                   2427:     if ($authtype eq '') {
                   2428:         $authtype = '<input type="radio" name="login" value="krb" '.
                   2429:                     'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
                   2430:                     $krbcheck.' />';
                   2431:     }
                   2432:     if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
                   2433:         ($can_assign{'krb4'} && !$can_assign{'krb5'} && 
                   2434:          $in{'curr_authtype'} eq 'krb5') ||
                   2435:         (!$can_assign{'krb4'} && $can_assign{'krb5'} && 
                   2436:          $in{'curr_authtype'} eq 'krb4')) {
                   2437:         $result .= &mt
1.144     matthew  2438:         ('[_1] Kerberos authenticated with domain [_2] '.
1.281     albertel 2439:          '[_3] Version 4 [_4] Version 5 [_5]',
1.586     raeburn  2440:          '<label>'.$authtype,
1.281     albertel 2441:          '</label><input type="text" size="10" name="krbarg" '.
1.165     raeburn  2442:              'value="'.$krbarg.'" '.
1.144     matthew  2443:              'onchange="'.$jscall.'" />',
1.281     albertel 2444:          '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
                   2445:          '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
                   2446: 	 '</label>');
1.586     raeburn  2447:     } elsif ($can_assign{'krb4'}) {
                   2448:         $result .= &mt
                   2449:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2450:          '[_3] Version 4 [_4]',
                   2451:          '<label>'.$authtype,
                   2452:          '</label><input type="text" size="10" name="krbarg" '.
                   2453:              'value="'.$krbarg.'" '.
                   2454:              'onchange="'.$jscall.'" />',
                   2455:          '<label><input type="hidden" name="krbver" value="4" />',
                   2456:          '</label>');
                   2457:     } elsif ($can_assign{'krb5'}) {
                   2458:         $result .= &mt
                   2459:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2460:          '[_3] Version 5 [_4]',
                   2461:          '<label>'.$authtype,
                   2462:          '</label><input type="text" size="10" name="krbarg" '.
                   2463:              'value="'.$krbarg.'" '.
                   2464:              'onchange="'.$jscall.'" />',
                   2465:          '<label><input type="hidden" name="krbver" value="5" />',
                   2466:          '</label>');
                   2467:     }
1.32      matthew  2468:     return $result;
                   2469: }
                   2470: 
                   2471: sub authform_internal{  
1.586     raeburn  2472:     my %in = (
1.32      matthew  2473:                 formname => 'document.cu',
                   2474:                 kerb_def_dom => 'MSU.EDU',
                   2475:                 @_,
                   2476:                 );
1.586     raeburn  2477:     my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
                   2478:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2479:     if (defined($in{'curr_authtype'})) {
                   2480:         if ($in{'curr_authtype'} eq 'int') {
1.586     raeburn  2481:             if ($can_assign{'int'}) {
1.772     bisitz   2482:                 $intcheck = 'checked="checked" ';
1.623     raeburn  2483:                 if (defined($in{'mode'})) {
                   2484:                     if ($in{'mode'} eq 'modifyuser') {
                   2485:                         $intcheck = '';
                   2486:                     }
                   2487:                 }
1.591     raeburn  2488:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2489:                     $intarg = $in{'curr_autharg'};
                   2490:                 }
                   2491:             } else {
                   2492:                 $result = &mt('Currently internally authenticated.');
                   2493:                 return $result;
1.165     raeburn  2494:             }
                   2495:         }
1.586     raeburn  2496:     } else {
                   2497:         if ($authnum == 1) {
1.784     bisitz   2498:             $authtype = '<input type="hidden" name="login" value="int" />';
1.586     raeburn  2499:         }
                   2500:     }
                   2501:     if (!$can_assign{'int'}) {
                   2502:         return;
1.587     raeburn  2503:     } elsif ($authtype eq '') {
1.591     raeburn  2504:         if (defined($in{'mode'})) {
1.587     raeburn  2505:             if ($in{'mode'} eq 'modifycourse') {
                   2506:                 if ($authnum == 1) {
1.784     bisitz   2507:                     $authtype = '<input type="hidden" name="login" value="int" />';
1.587     raeburn  2508:                 }
                   2509:             }
                   2510:         }
1.165     raeburn  2511:     }
1.586     raeburn  2512:     $jscall = "javascript:changed_radio('int',$in{'formname'});";
                   2513:     if ($authtype eq '') {
                   2514:         $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
                   2515:                     ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
                   2516:     }
1.605     bisitz   2517:     $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586     raeburn  2518:                $intarg.'" onchange="'.$jscall.'" />';
                   2519:     $result = &mt
1.144     matthew  2520:         ('[_1] Internally authenticated (with initial password [_2])',
1.586     raeburn  2521:          '<label>'.$authtype,'</label>'.$autharg);
1.824     bisitz   2522:     $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  2523:     return $result;
                   2524: }
                   2525: 
                   2526: sub authform_local{  
                   2527:     my %in = (
                   2528:               formname => 'document.cu',
                   2529:               kerb_def_dom => 'MSU.EDU',
                   2530:               @_,
                   2531:               );
1.586     raeburn  2532:     my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
                   2533:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2534:     if (defined($in{'curr_authtype'})) {
                   2535:         if ($in{'curr_authtype'} eq 'loc') {
1.586     raeburn  2536:             if ($can_assign{'loc'}) {
1.772     bisitz   2537:                 $loccheck = 'checked="checked" ';
1.623     raeburn  2538:                 if (defined($in{'mode'})) {
                   2539:                     if ($in{'mode'} eq 'modifyuser') {
                   2540:                         $loccheck = '';
                   2541:                     }
                   2542:                 }
1.591     raeburn  2543:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2544:                     $locarg = $in{'curr_autharg'};
                   2545:                 }
                   2546:             } else {
                   2547:                 $result = &mt('Currently using local (institutional) authentication.');
                   2548:                 return $result;
1.165     raeburn  2549:             }
                   2550:         }
1.586     raeburn  2551:     } else {
                   2552:         if ($authnum == 1) {
1.784     bisitz   2553:             $authtype = '<input type="hidden" name="login" value="loc" />';
1.586     raeburn  2554:         }
                   2555:     }
                   2556:     if (!$can_assign{'loc'}) {
                   2557:         return;
1.587     raeburn  2558:     } elsif ($authtype eq '') {
1.591     raeburn  2559:         if (defined($in{'mode'})) {
1.587     raeburn  2560:             if ($in{'mode'} eq 'modifycourse') {
                   2561:                 if ($authnum == 1) {
1.784     bisitz   2562:                     $authtype = '<input type="hidden" name="login" value="loc" />';
1.587     raeburn  2563:                 }
                   2564:             }
                   2565:         }
1.165     raeburn  2566:     }
1.586     raeburn  2567:     $jscall = "javascript:changed_radio('loc',$in{'formname'});";
                   2568:     if ($authtype eq '') {
                   2569:         $authtype = '<input type="radio" name="login" value="loc" '.
                   2570:                     $loccheck.' onchange="'.$jscall.'" onclick="'.
                   2571:                     $jscall.'" />';
                   2572:     }
                   2573:     $autharg = '<input type="text" size="10" name="locarg" value="'.
                   2574:                $locarg.'" onchange="'.$jscall.'" />';
                   2575:     $result = &mt('[_1] Local Authentication with argument [_2]',
                   2576:                   '<label>'.$authtype,'</label>'.$autharg);
1.32      matthew  2577:     return $result;
                   2578: }
                   2579: 
                   2580: sub authform_filesystem{  
                   2581:     my %in = (
                   2582:               formname => 'document.cu',
                   2583:               kerb_def_dom => 'MSU.EDU',
                   2584:               @_,
                   2585:               );
1.586     raeburn  2586:     my ($fsyscheck,$result,$authtype,$autharg,$jscall);
                   2587:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2588:     if (defined($in{'curr_authtype'})) {
                   2589:         if ($in{'curr_authtype'} eq 'fsys') {
1.586     raeburn  2590:             if ($can_assign{'fsys'}) {
1.772     bisitz   2591:                 $fsyscheck = 'checked="checked" ';
1.623     raeburn  2592:                 if (defined($in{'mode'})) {
                   2593:                     if ($in{'mode'} eq 'modifyuser') {
                   2594:                         $fsyscheck = '';
                   2595:                     }
                   2596:                 }
1.586     raeburn  2597:             } else {
                   2598:                 $result = &mt('Currently Filesystem Authenticated.');
                   2599:                 return $result;
                   2600:             }           
                   2601:         }
                   2602:     } else {
                   2603:         if ($authnum == 1) {
1.784     bisitz   2604:             $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586     raeburn  2605:         }
                   2606:     }
                   2607:     if (!$can_assign{'fsys'}) {
                   2608:         return;
1.587     raeburn  2609:     } elsif ($authtype eq '') {
1.591     raeburn  2610:         if (defined($in{'mode'})) {
1.587     raeburn  2611:             if ($in{'mode'} eq 'modifycourse') {
                   2612:                 if ($authnum == 1) {
1.784     bisitz   2613:                     $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587     raeburn  2614:                 }
                   2615:             }
                   2616:         }
1.586     raeburn  2617:     }
                   2618:     $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
                   2619:     if ($authtype eq '') {
                   2620:         $authtype = '<input type="radio" name="login" value="fsys" '.
                   2621:                     $fsyscheck.' onchange="'.$jscall.'" onclick="'.
                   2622:                     $jscall.'" />';
                   2623:     }
                   2624:     $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
                   2625:                ' onchange="'.$jscall.'" />';
                   2626:     $result = &mt
1.144     matthew  2627:         ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281     albertel 2628:          '<label><input type="radio" name="login" value="fsys" '.
1.586     raeburn  2629:          $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605     bisitz   2630:          '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144     matthew  2631:                   'onchange="'.$jscall.'" />');
1.32      matthew  2632:     return $result;
                   2633: }
                   2634: 
1.586     raeburn  2635: sub get_assignable_auth {
                   2636:     my ($dom) = @_;
                   2637:     if ($dom eq '') {
                   2638:         $dom = $env{'request.role.domain'};
                   2639:     }
                   2640:     my %can_assign = (
                   2641:                           krb4 => 1,
                   2642:                           krb5 => 1,
                   2643:                           int  => 1,
                   2644:                           loc  => 1,
                   2645:                      );
                   2646:     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
                   2647:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   2648:         if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
                   2649:             my $authhash = $domconfig{'usercreation'}{'authtypes'};
                   2650:             my $context;
                   2651:             if ($env{'request.role'} =~ /^au/) {
                   2652:                 $context = 'author';
                   2653:             } elsif ($env{'request.role'} =~ /^dc/) {
                   2654:                 $context = 'domain';
                   2655:             } elsif ($env{'request.course.id'}) {
                   2656:                 $context = 'course';
                   2657:             }
                   2658:             if ($context) {
                   2659:                 if (ref($authhash->{$context}) eq 'HASH') {
                   2660:                    %can_assign = %{$authhash->{$context}}; 
                   2661:                 }
                   2662:             }
                   2663:         }
                   2664:     }
                   2665:     my $authnum = 0;
                   2666:     foreach my $key (keys(%can_assign)) {
                   2667:         if ($can_assign{$key}) {
                   2668:             $authnum ++;
                   2669:         }
                   2670:     }
                   2671:     if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
                   2672:         $authnum --;
                   2673:     }
                   2674:     return ($authnum,%can_assign);
                   2675: }
                   2676: 
1.80      albertel 2677: ###############################################################
                   2678: ##    Get Kerberos Defaults for Domain                 ##
                   2679: ###############################################################
                   2680: ##
                   2681: ## Returns default kerberos version and an associated argument
                   2682: ## as listed in file domain.tab. If not listed, provides
                   2683: ## appropriate default domain and kerberos version.
                   2684: ##
                   2685: #-------------------------------------------
                   2686: 
                   2687: =pod
                   2688: 
1.648     raeburn  2689: =item * &get_kerberos_defaults()
1.80      albertel 2690: 
                   2691: get_kerberos_defaults($target_domain) returns the default kerberos
1.641     raeburn  2692: version and domain. If not found, it defaults to version 4 and the 
                   2693: domain of the server.
1.80      albertel 2694: 
1.648     raeburn  2695: =over 4
                   2696: 
1.80      albertel 2697: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
                   2698: 
1.648     raeburn  2699: =back
                   2700: 
                   2701: =back
                   2702: 
1.80      albertel 2703: =cut
                   2704: 
                   2705: #-------------------------------------------
                   2706: sub get_kerberos_defaults {
                   2707:     my $domain=shift;
1.641     raeburn  2708:     my ($krbdef,$krbdefdom);
                   2709:     my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
                   2710:     if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
                   2711:         $krbdef = $domdefaults{'auth_def'};
                   2712:         $krbdefdom = $domdefaults{'auth_arg_def'};
                   2713:     } else {
1.80      albertel 2714:         $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
                   2715:         my $krbdefdom=$1;
                   2716:         $krbdefdom=~tr/a-z/A-Z/;
                   2717:         $krbdef = "krb4";
                   2718:     }
                   2719:     return ($krbdef,$krbdefdom);
                   2720: }
1.112     bowersj2 2721: 
1.32      matthew  2722: 
1.46      matthew  2723: ###############################################################
                   2724: ##                Thesaurus Functions                        ##
                   2725: ###############################################################
1.20      www      2726: 
1.46      matthew  2727: =pod
1.20      www      2728: 
1.112     bowersj2 2729: =head1 Thesaurus Functions
                   2730: 
                   2731: =over 4
                   2732: 
1.648     raeburn  2733: =item * &initialize_keywords()
1.46      matthew  2734: 
                   2735: Initializes the package variable %Keywords if it is empty.  Uses the
                   2736: package variable $thesaurus_db_file.
                   2737: 
                   2738: =cut
                   2739: 
                   2740: ###################################################
                   2741: 
                   2742: sub initialize_keywords {
                   2743:     return 1 if (scalar keys(%Keywords));
                   2744:     # If we are here, %Keywords is empty, so fill it up
                   2745:     #   Make sure the file we need exists...
                   2746:     if (! -e $thesaurus_db_file) {
                   2747:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
                   2748:                                  " failed because it does not exist");
                   2749:         return 0;
                   2750:     }
                   2751:     #   Set up the hash as a database
                   2752:     my %thesaurus_db;
                   2753:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2754:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2755:         &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
                   2756:                                  $thesaurus_db_file);
                   2757:         return 0;
                   2758:     } 
                   2759:     #  Get the average number of appearances of a word.
                   2760:     my $avecount = $thesaurus_db{'average.count'};
                   2761:     #  Put keywords (those that appear > average) into %Keywords
                   2762:     while (my ($word,$data)=each (%thesaurus_db)) {
                   2763:         my ($count,undef) = split /:/,$data;
                   2764:         $Keywords{$word}++ if ($count > $avecount);
                   2765:     }
                   2766:     untie %thesaurus_db;
                   2767:     # Remove special values from %Keywords.
1.356     albertel 2768:     foreach my $value ('total.count','average.count') {
                   2769:         delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586     raeburn  2770:   }
1.46      matthew  2771:     return 1;
                   2772: }
                   2773: 
                   2774: ###################################################
                   2775: 
                   2776: =pod
                   2777: 
1.648     raeburn  2778: =item * &keyword($word)
1.46      matthew  2779: 
                   2780: Returns true if $word is a keyword.  A keyword is a word that appears more 
                   2781: than the average number of times in the thesaurus database.  Calls 
                   2782: &initialize_keywords
                   2783: 
                   2784: =cut
                   2785: 
                   2786: ###################################################
1.20      www      2787: 
                   2788: sub keyword {
1.46      matthew  2789:     return if (!&initialize_keywords());
                   2790:     my $word=lc(shift());
                   2791:     $word=~s/\W//g;
                   2792:     return exists($Keywords{$word});
1.20      www      2793: }
1.46      matthew  2794: 
                   2795: ###############################################################
                   2796: 
                   2797: =pod 
1.20      www      2798: 
1.648     raeburn  2799: =item * &get_related_words()
1.46      matthew  2800: 
1.160     matthew  2801: Look up a word in the thesaurus.  Takes a scalar argument and returns
1.46      matthew  2802: an array of words.  If the keyword is not in the thesaurus, an empty array
                   2803: will be returned.  The order of the words returned is determined by the
                   2804: database which holds them.
                   2805: 
                   2806: Uses global $thesaurus_db_file.
                   2807: 
                   2808: =cut
                   2809: 
                   2810: ###############################################################
                   2811: sub get_related_words {
                   2812:     my $keyword = shift;
                   2813:     my %thesaurus_db;
                   2814:     if (! -e $thesaurus_db_file) {
                   2815:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
                   2816:                                  "failed because the file does not exist");
                   2817:         return ();
                   2818:     }
                   2819:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2820:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2821:         return ();
                   2822:     } 
                   2823:     my @Words=();
1.429     www      2824:     my $count=0;
1.46      matthew  2825:     if (exists($thesaurus_db{$keyword})) {
1.356     albertel 2826: 	# The first element is the number of times
                   2827: 	# the word appears.  We do not need it now.
1.429     www      2828: 	my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
                   2829: 	my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
                   2830: 	my $threshold=$mostfrequentcount/10;
                   2831:         foreach my $possibleword (@RelatedWords) {
                   2832:             my ($word,$wordcount)=split(/\,/,$possibleword);
                   2833:             if ($wordcount>$threshold) {
                   2834: 		push(@Words,$word);
                   2835:                 $count++;
                   2836:                 if ($count>10) { last; }
                   2837: 	    }
1.20      www      2838:         }
                   2839:     }
1.46      matthew  2840:     untie %thesaurus_db;
                   2841:     return @Words;
1.14      harris41 2842: }
1.46      matthew  2843: 
1.112     bowersj2 2844: =pod
                   2845: 
                   2846: =back
                   2847: 
                   2848: =cut
1.61      www      2849: 
                   2850: # -------------------------------------------------------------- Plaintext name
1.81      albertel 2851: =pod
                   2852: 
1.112     bowersj2 2853: =head1 User Name Functions
                   2854: 
                   2855: =over 4
                   2856: 
1.648     raeburn  2857: =item * &plainname($uname,$udom,$first)
1.81      albertel 2858: 
1.112     bowersj2 2859: Takes a users logon name and returns it as a string in
1.226     albertel 2860: "first middle last generation" form 
                   2861: if $first is set to 'lastname' then it returns it as
                   2862: 'lastname generation, firstname middlename' if their is a lastname
1.81      albertel 2863: 
                   2864: =cut
1.61      www      2865: 
1.295     www      2866: 
1.81      albertel 2867: ###############################################################
1.61      www      2868: sub plainname {
1.226     albertel 2869:     my ($uname,$udom,$first)=@_;
1.537     albertel 2870:     return if (!defined($uname) || !defined($udom));
1.295     www      2871:     my %names=&getnames($uname,$udom);
1.226     albertel 2872:     my $name=&Apache::lonnet::format_name($names{'firstname'},
                   2873: 					  $names{'middlename'},
                   2874: 					  $names{'lastname'},
                   2875: 					  $names{'generation'},$first);
                   2876:     $name=~s/^\s+//;
1.62      www      2877:     $name=~s/\s+$//;
                   2878:     $name=~s/\s+/ /g;
1.353     albertel 2879:     if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62      www      2880:     return $name;
1.61      www      2881: }
1.66      www      2882: 
                   2883: # -------------------------------------------------------------------- Nickname
1.81      albertel 2884: =pod
                   2885: 
1.648     raeburn  2886: =item * &nickname($uname,$udom)
1.81      albertel 2887: 
                   2888: Gets a users name and returns it as a string as
                   2889: 
                   2890: "&quot;nickname&quot;"
1.66      www      2891: 
1.81      albertel 2892: if the user has a nickname or
                   2893: 
                   2894: "first middle last generation"
                   2895: 
                   2896: if the user does not
                   2897: 
                   2898: =cut
1.66      www      2899: 
                   2900: sub nickname {
                   2901:     my ($uname,$udom)=@_;
1.537     albertel 2902:     return if (!defined($uname) || !defined($udom));
1.295     www      2903:     my %names=&getnames($uname,$udom);
1.68      albertel 2904:     my $name=$names{'nickname'};
1.66      www      2905:     if ($name) {
                   2906:        $name='&quot;'.$name.'&quot;'; 
                   2907:     } else {
                   2908:        $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
                   2909: 	     $names{'lastname'}.' '.$names{'generation'};
                   2910:        $name=~s/\s+$//;
                   2911:        $name=~s/\s+/ /g;
                   2912:     }
                   2913:     return $name;
                   2914: }
                   2915: 
1.295     www      2916: sub getnames {
                   2917:     my ($uname,$udom)=@_;
1.537     albertel 2918:     return if (!defined($uname) || !defined($udom));
1.433     albertel 2919:     if ($udom eq 'public' && $uname eq 'public') {
                   2920: 	return ('lastname' => &mt('Public'));
                   2921:     }
1.295     www      2922:     my $id=$uname.':'.$udom;
                   2923:     my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
                   2924:     if ($cached) {
                   2925: 	return %{$names};
                   2926:     } else {
                   2927: 	my %loadnames=&Apache::lonnet::get('environment',
                   2928:                     ['firstname','middlename','lastname','generation','nickname'],
                   2929: 					 $udom,$uname);
                   2930: 	&Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
                   2931: 	return %loadnames;
                   2932:     }
                   2933: }
1.61      www      2934: 
1.542     raeburn  2935: # -------------------------------------------------------------------- getemails
1.648     raeburn  2936: 
1.542     raeburn  2937: =pod
                   2938: 
1.648     raeburn  2939: =item * &getemails($uname,$udom)
1.542     raeburn  2940: 
                   2941: Gets a user's email information and returns it as a hash with keys:
                   2942: notification, critnotification, permanentemail
                   2943: 
                   2944: For notification and critnotification, values are comma-separated lists 
1.648     raeburn  2945: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542     raeburn  2946:  
1.648     raeburn  2947: 
1.542     raeburn  2948: =cut
                   2949: 
1.648     raeburn  2950: 
1.466     albertel 2951: sub getemails {
                   2952:     my ($uname,$udom)=@_;
                   2953:     if ($udom eq 'public' && $uname eq 'public') {
                   2954: 	return;
                   2955:     }
1.467     www      2956:     if (!$udom) { $udom=$env{'user.domain'}; }
                   2957:     if (!$uname) { $uname=$env{'user.name'}; }
1.466     albertel 2958:     my $id=$uname.':'.$udom;
                   2959:     my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
                   2960:     if ($cached) {
                   2961: 	return %{$names};
                   2962:     } else {
                   2963: 	my %loadnames=&Apache::lonnet::get('environment',
                   2964:                     			   ['notification','critnotification',
                   2965: 					    'permanentemail'],
                   2966: 					   $udom,$uname);
                   2967: 	&Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
                   2968: 	return %loadnames;
                   2969:     }
                   2970: }
                   2971: 
1.551     albertel 2972: sub flush_email_cache {
                   2973:     my ($uname,$udom)=@_;
                   2974:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2975:     if (!$uname) { $uname=$env{'user.name'};   }
                   2976:     return if ($udom eq 'public' && $uname eq 'public');
                   2977:     my $id=$uname.':'.$udom;
                   2978:     &Apache::lonnet::devalidate_cache_new('emailscache',$id);
                   2979: }
                   2980: 
1.728     raeburn  2981: # -------------------------------------------------------------------- getlangs
                   2982: 
                   2983: =pod
                   2984: 
                   2985: =item * &getlangs($uname,$udom)
                   2986: 
                   2987: Gets a user's language preference and returns it as a hash with key:
                   2988: language.
                   2989: 
                   2990: =cut
                   2991: 
                   2992: 
                   2993: sub getlangs {
                   2994:     my ($uname,$udom) = @_;
                   2995:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2996:     if (!$uname) { $uname=$env{'user.name'};   }
                   2997:     my $id=$uname.':'.$udom;
                   2998:     my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
                   2999:     if ($cached) {
                   3000:         return %{$langs};
                   3001:     } else {
                   3002:         my %loadlangs=&Apache::lonnet::get('environment',['languages'],
                   3003:                                            $udom,$uname);
                   3004:         &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
                   3005:         return %loadlangs;
                   3006:     }
                   3007: }
                   3008: 
                   3009: sub flush_langs_cache {
                   3010:     my ($uname,$udom)=@_;
                   3011:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   3012:     if (!$uname) { $uname=$env{'user.name'};   }
                   3013:     return if ($udom eq 'public' && $uname eq 'public');
                   3014:     my $id=$uname.':'.$udom;
                   3015:     &Apache::lonnet::devalidate_cache_new('userlangs',$id);
                   3016: }
                   3017: 
1.61      www      3018: # ------------------------------------------------------------------ Screenname
1.81      albertel 3019: 
                   3020: =pod
                   3021: 
1.648     raeburn  3022: =item * &screenname($uname,$udom)
1.81      albertel 3023: 
                   3024: Gets a users screenname and returns it as a string
                   3025: 
                   3026: =cut
1.61      www      3027: 
                   3028: sub screenname {
                   3029:     my ($uname,$udom)=@_;
1.258     albertel 3030:     if ($uname eq $env{'user.name'} &&
                   3031: 	$udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212     albertel 3032:     my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68      albertel 3033:     return $names{'screenname'};
1.62      www      3034: }
                   3035: 
1.212     albertel 3036: 
1.802     bisitz   3037: # ------------------------------------------------------------- Confirm Wrapper
                   3038: =pod
                   3039: 
                   3040: =item confirmwrapper
                   3041: 
                   3042: Wrap messages about completion of operation in box
                   3043: 
                   3044: =cut
                   3045: 
                   3046: sub confirmwrapper {
                   3047:     my ($message)=@_;
                   3048:     if ($message) {
                   3049:         return "\n".'<div class="LC_confirm_box">'."\n"
                   3050:                .$message."\n"
                   3051:                .'</div>'."\n";
                   3052:     } else {
                   3053:         return $message;
                   3054:     }
                   3055: }
                   3056: 
1.62      www      3057: # ------------------------------------------------------------- Message Wrapper
                   3058: 
                   3059: sub messagewrapper {
1.369     www      3060:     my ($link,$username,$domain,$subject,$text)=@_;
1.62      www      3061:     return 
1.441     albertel 3062:         '<a href="/adm/email?compose=individual&amp;'.
                   3063:         'recname='.$username.'&amp;recdom='.$domain.
                   3064: 	'&amp;subject='.&escape($subject).'&amp;text='.&escape($text).'" '.
1.200     matthew  3065:         'title="'.&mt('Send message').'">'.$link.'</a>';
1.74      www      3066: }
1.802     bisitz   3067: 
1.74      www      3068: # --------------------------------------------------------------- Notes Wrapper
                   3069: 
                   3070: sub noteswrapper {
                   3071:     my ($link,$un,$do)=@_;
                   3072:     return 
1.896     amueller 3073: "<a href='/adm/email?recordftf=retrieve&amp;recname=$un&amp;recdom=$do'>$link</a>";
1.62      www      3074: }
1.802     bisitz   3075: 
1.62      www      3076: # ------------------------------------------------------------- Aboutme Wrapper
                   3077: 
                   3078: sub aboutmewrapper {
1.166     www      3079:     my ($link,$username,$domain,$target)=@_;
1.447     raeburn  3080:     if (!defined($username)  && !defined($domain)) {
                   3081:         return;
                   3082:     }
1.892     amueller 3083:     return '<a href="/adm/'.$domain.'/'.$username.'/aboutme?forcestudent=1"'.
1.756     weissno  3084: 	($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62      www      3085: }
                   3086: 
                   3087: # ------------------------------------------------------------ Syllabus Wrapper
                   3088: 
                   3089: sub syllabuswrapper {
1.707     bisitz   3090:     my ($linktext,$coursedir,$domain)=@_;
1.208     matthew  3091:     return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61      www      3092: }
1.14      harris41 3093: 
1.802     bisitz   3094: # -----------------------------------------------------------------------------
                   3095: 
1.208     matthew  3096: sub track_student_link {
1.887     raeburn  3097:     my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268     albertel 3098:     my $link ="/adm/trackstudent?";
1.208     matthew  3099:     my $title = 'View recent activity';
                   3100:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   3101:         defined($sdom)  && $sdom  !~ /^\s*$/) {
1.268     albertel 3102:         $link .= "selected_student=$sname:$sdom";
1.208     matthew  3103:         $title .= ' of this student';
1.268     albertel 3104:     } 
1.208     matthew  3105:     if (defined($target) && $target !~ /^\s*$/) {
                   3106:         $target = qq{target="$target"};
                   3107:     } else {
                   3108:         $target = '';
                   3109:     }
1.268     albertel 3110:     if ($start) { $link.='&amp;start='.$start; }
1.887     raeburn  3111:     if ($only_body) { $link .= '&amp;only_body=1'; }
1.554     albertel 3112:     $title = &mt($title);
                   3113:     $linktext = &mt($linktext);
1.448     albertel 3114:     return qq{<a href="$link" title="$title" $target>$linktext</a>}.
                   3115: 	&help_open_topic('View_recent_activity');
1.208     matthew  3116: }
                   3117: 
1.781     raeburn  3118: sub slot_reservations_link {
                   3119:     my ($linktext,$sname,$sdom,$target) = @_;
                   3120:     my $link ="/adm/slotrequest?command=showresv&amp;origin=aboutme";
                   3121:     my $title = 'View slot reservation history';
                   3122:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   3123:         defined($sdom)  && $sdom  !~ /^\s*$/) {
                   3124:         $link .= "&amp;uname=$sname&amp;udom=$sdom";
                   3125:         $title .= ' of this student';
                   3126:     }
                   3127:     if (defined($target) && $target !~ /^\s*$/) {
                   3128:         $target = qq{target="$target"};
                   3129:     } else {
                   3130:         $target = '';
                   3131:     }
                   3132:     $title = &mt($title);
                   3133:     $linktext = &mt($linktext);
                   3134:     return qq{<a href="$link" title="$title" $target>$linktext</a>};
                   3135: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
                   3136: 
                   3137: }
                   3138: 
1.508     www      3139: # ===================================================== Display a student photo
                   3140: 
                   3141: 
1.509     albertel 3142: sub student_image_tag {
1.508     www      3143:     my ($domain,$user)=@_;
                   3144:     my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
                   3145:     if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
                   3146: 	return '<img src="'.$imgsrc.'" align="right" />';
                   3147:     } else {
                   3148: 	return '';
                   3149:     }
                   3150: }
                   3151: 
1.112     bowersj2 3152: =pod
                   3153: 
                   3154: =back
                   3155: 
                   3156: =head1 Access .tab File Data
                   3157: 
                   3158: =over 4
                   3159: 
1.648     raeburn  3160: =item * &languageids() 
1.112     bowersj2 3161: 
                   3162: returns list of all language ids
                   3163: 
                   3164: =cut
                   3165: 
1.14      harris41 3166: sub languageids {
1.16      harris41 3167:     return sort(keys(%language));
1.14      harris41 3168: }
                   3169: 
1.112     bowersj2 3170: =pod
                   3171: 
1.648     raeburn  3172: =item * &languagedescription() 
1.112     bowersj2 3173: 
                   3174: returns description of a specified language id
                   3175: 
                   3176: =cut
                   3177: 
1.14      harris41 3178: sub languagedescription {
1.125     www      3179:     my $code=shift;
                   3180:     return  ($supported_language{$code}?'* ':'').
                   3181:             $language{$code}.
1.126     www      3182: 	    ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145     www      3183: }
                   3184: 
                   3185: sub plainlanguagedescription {
                   3186:     my $code=shift;
                   3187:     return $language{$code};
                   3188: }
                   3189: 
                   3190: sub supportedlanguagecode {
                   3191:     my $code=shift;
                   3192:     return $supported_language{$code};
1.97      www      3193: }
                   3194: 
1.112     bowersj2 3195: =pod
                   3196: 
1.648     raeburn  3197: =item * &copyrightids() 
1.112     bowersj2 3198: 
                   3199: returns list of all copyrights
                   3200: 
                   3201: =cut
                   3202: 
                   3203: sub copyrightids {
                   3204:     return sort(keys(%cprtag));
                   3205: }
                   3206: 
                   3207: =pod
                   3208: 
1.648     raeburn  3209: =item * &copyrightdescription() 
1.112     bowersj2 3210: 
                   3211: returns description of a specified copyright id
                   3212: 
                   3213: =cut
                   3214: 
                   3215: sub copyrightdescription {
1.166     www      3216:     return &mt($cprtag{shift(@_)});
1.112     bowersj2 3217: }
1.197     matthew  3218: 
                   3219: =pod
                   3220: 
1.648     raeburn  3221: =item * &source_copyrightids() 
1.192     taceyjo1 3222: 
                   3223: returns list of all source copyrights
                   3224: 
                   3225: =cut
                   3226: 
                   3227: sub source_copyrightids {
                   3228:     return sort(keys(%scprtag));
                   3229: }
                   3230: 
                   3231: =pod
                   3232: 
1.648     raeburn  3233: =item * &source_copyrightdescription() 
1.192     taceyjo1 3234: 
                   3235: returns description of a specified source copyright id
                   3236: 
                   3237: =cut
                   3238: 
                   3239: sub source_copyrightdescription {
                   3240:     return &mt($scprtag{shift(@_)});
                   3241: }
1.112     bowersj2 3242: 
                   3243: =pod
                   3244: 
1.648     raeburn  3245: =item * &filecategories() 
1.112     bowersj2 3246: 
                   3247: returns list of all file categories
                   3248: 
                   3249: =cut
                   3250: 
                   3251: sub filecategories {
                   3252:     return sort(keys(%category_extensions));
                   3253: }
                   3254: 
                   3255: =pod
                   3256: 
1.648     raeburn  3257: =item * &filecategorytypes() 
1.112     bowersj2 3258: 
                   3259: returns list of file types belonging to a given file
                   3260: category
                   3261: 
                   3262: =cut
                   3263: 
                   3264: sub filecategorytypes {
1.356     albertel 3265:     my ($cat) = @_;
                   3266:     return @{$category_extensions{lc($cat)}};
1.112     bowersj2 3267: }
                   3268: 
                   3269: =pod
                   3270: 
1.648     raeburn  3271: =item * &fileembstyle() 
1.112     bowersj2 3272: 
                   3273: returns embedding style for a specified file type
                   3274: 
                   3275: =cut
                   3276: 
                   3277: sub fileembstyle {
                   3278:     return $fe{lc(shift(@_))};
1.169     www      3279: }
                   3280: 
1.351     www      3281: sub filemimetype {
                   3282:     return $fm{lc(shift(@_))};
                   3283: }
                   3284: 
1.169     www      3285: 
                   3286: sub filecategoryselect {
                   3287:     my ($name,$value)=@_;
1.189     matthew  3288:     return &select_form($value,$name,
1.970     raeburn  3289:                         {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112     bowersj2 3290: }
                   3291: 
                   3292: =pod
                   3293: 
1.648     raeburn  3294: =item * &filedescription() 
1.112     bowersj2 3295: 
                   3296: returns description for a specified file type
                   3297: 
                   3298: =cut
                   3299: 
                   3300: sub filedescription {
1.188     matthew  3301:     my $file_description = $fd{lc(shift())};
                   3302:     $file_description =~ s:([\[\]]):~$1:g;
                   3303:     return &mt($file_description);
1.112     bowersj2 3304: }
                   3305: 
                   3306: =pod
                   3307: 
1.648     raeburn  3308: =item * &filedescriptionex() 
1.112     bowersj2 3309: 
                   3310: returns description for a specified file type with
                   3311: extra formatting
                   3312: 
                   3313: =cut
                   3314: 
                   3315: sub filedescriptionex {
                   3316:     my $ex=shift;
1.188     matthew  3317:     my $file_description = $fd{lc($ex)};
                   3318:     $file_description =~ s:([\[\]]):~$1:g;
                   3319:     return '.'.$ex.' '.&mt($file_description);
1.112     bowersj2 3320: }
                   3321: 
                   3322: # End of .tab access
                   3323: =pod
                   3324: 
                   3325: =back
                   3326: 
                   3327: =cut
                   3328: 
                   3329: # ------------------------------------------------------------------ File Types
                   3330: sub fileextensions {
                   3331:     return sort(keys(%fe));
                   3332: }
                   3333: 
1.97      www      3334: # ----------------------------------------------------------- Display Languages
                   3335: # returns a hash with all desired display languages
                   3336: #
                   3337: 
                   3338: sub display_languages {
                   3339:     my %languages=();
1.695     raeburn  3340:     foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356     albertel 3341: 	$languages{$lang}=1;
1.97      www      3342:     }
                   3343:     &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258     albertel 3344:     if ($env{'form.displaylanguage'}) {
1.356     albertel 3345: 	foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
                   3346: 	    $languages{$lang}=1;
1.97      www      3347:         }
                   3348:     }
                   3349:     return %languages;
1.14      harris41 3350: }
                   3351: 
1.582     albertel 3352: sub languages {
                   3353:     my ($possible_langs) = @_;
1.695     raeburn  3354:     my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582     albertel 3355:     if (!ref($possible_langs)) {
                   3356: 	if( wantarray ) {
                   3357: 	    return @preferred_langs;
                   3358: 	} else {
                   3359: 	    return $preferred_langs[0];
                   3360: 	}
                   3361:     }
                   3362:     my %possibilities = map { $_ => 1 } (@$possible_langs);
                   3363:     my @preferred_possibilities;
                   3364:     foreach my $preferred_lang (@preferred_langs) {
                   3365: 	if (exists($possibilities{$preferred_lang})) {
                   3366: 	    push(@preferred_possibilities, $preferred_lang);
                   3367: 	}
                   3368:     }
                   3369:     if( wantarray ) {
                   3370: 	return @preferred_possibilities;
                   3371:     }
                   3372:     return $preferred_possibilities[0];
                   3373: }
                   3374: 
1.742     raeburn  3375: sub user_lang {
                   3376:     my ($touname,$toudom,$fromcid) = @_;
                   3377:     my @userlangs;
                   3378:     if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
                   3379:         @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
                   3380:                     $env{'course.'.$fromcid.'.languages'}));
                   3381:     } else {
                   3382:         my %langhash = &getlangs($touname,$toudom);
                   3383:         if ($langhash{'languages'} ne '') {
                   3384:             @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
                   3385:         } else {
                   3386:             my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
                   3387:             if ($domdefs{'lang_def'} ne '') {
                   3388:                 @userlangs = ($domdefs{'lang_def'});
                   3389:             }
                   3390:         }
                   3391:     }
                   3392:     my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
                   3393:     my $user_lh = Apache::localize->get_handle(@languages);
                   3394:     return $user_lh;
                   3395: }
                   3396: 
                   3397: 
1.112     bowersj2 3398: ###############################################################
                   3399: ##               Student Answer Attempts                     ##
                   3400: ###############################################################
                   3401: 
                   3402: =pod
                   3403: 
                   3404: =head1 Alternate Problem Views
                   3405: 
                   3406: =over 4
                   3407: 
1.648     raeburn  3408: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112     bowersj2 3409:     $getattempt, $regexp, $gradesub)
                   3410: 
                   3411: Return string with previous attempt on problem. Arguments:
                   3412: 
                   3413: =over 4
                   3414: 
                   3415: =item * $symb: Problem, including path
                   3416: 
                   3417: =item * $username: username of the desired student
                   3418: 
                   3419: =item * $domain: domain of the desired student
1.14      harris41 3420: 
1.112     bowersj2 3421: =item * $course: Course ID
1.14      harris41 3422: 
1.112     bowersj2 3423: =item * $getattempt: Leave blank for all attempts, otherwise put
                   3424:     something
1.14      harris41 3425: 
1.112     bowersj2 3426: =item * $regexp: if string matches this regexp, the string will be
                   3427:     sent to $gradesub
1.14      harris41 3428: 
1.112     bowersj2 3429: =item * $gradesub: routine that processes the string if it matches $regexp
1.14      harris41 3430: 
1.112     bowersj2 3431: =back
1.14      harris41 3432: 
1.112     bowersj2 3433: The output string is a table containing all desired attempts, if any.
1.16      harris41 3434: 
1.112     bowersj2 3435: =cut
1.1       albertel 3436: 
                   3437: sub get_previous_attempt {
1.43      ng       3438:   my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1       albertel 3439:   my $prevattempts='';
1.43      ng       3440:   no strict 'refs';
1.1       albertel 3441:   if ($symb) {
1.3       albertel 3442:     my (%returnhash)=
                   3443:       &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1       albertel 3444:     if ($returnhash{'version'}) {
                   3445:       my %lasthash=();
                   3446:       my $version;
                   3447:       for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356     albertel 3448:         foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
                   3449: 	  $lasthash{$key}=$returnhash{$version.':'.$key};
1.19      harris41 3450:         }
1.1       albertel 3451:       }
1.596     albertel 3452:       $prevattempts=&start_data_table().&start_data_table_header_row();
                   3453:       $prevattempts.='<th>'.&mt('History').'</th>';
1.978     raeburn  3454:       my (%typeparts,%lasthidden);
1.945     raeburn  3455:       my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356     albertel 3456:       foreach my $key (sort(keys(%lasthash))) {
                   3457: 	my ($ign,@parts) = split(/\./,$key);
1.41      ng       3458: 	if ($#parts > 0) {
1.31      albertel 3459: 	  my $data=$parts[-1];
1.989     raeburn  3460:           next if ($data eq 'foilorder');
1.31      albertel 3461: 	  pop(@parts);
1.945     raeburn  3462:           if ($data eq 'type') {
                   3463:               unless ($showsurv) {
                   3464:                   my $id = join(',',@parts);
                   3465:                   $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978     raeburn  3466:                   if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
                   3467:                       $lasthidden{$ign.'.'.$id} = 1;
                   3468:                   }
1.945     raeburn  3469:               }
                   3470:               delete($lasthash{$key});
                   3471:           } else {
                   3472: 	      $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.'&nbsp;</th>';
                   3473:           }
1.31      albertel 3474: 	} else {
1.41      ng       3475: 	  if ($#parts == 0) {
                   3476: 	    $prevattempts.='<th>'.$parts[0].'</th>';
                   3477: 	  } else {
                   3478: 	    $prevattempts.='<th>'.$ign.'</th>';
                   3479: 	  }
1.31      albertel 3480: 	}
1.16      harris41 3481:       }
1.596     albertel 3482:       $prevattempts.=&end_data_table_header_row();
1.40      ng       3483:       if ($getattempt eq '') {
                   3484: 	for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945     raeburn  3485:             my @hidden;
                   3486:             if (%typeparts) {
                   3487:                 foreach my $id (keys(%typeparts)) {
                   3488:                     if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
                   3489:                         push(@hidden,$id);
                   3490:                     }
                   3491:                 }
                   3492:             }
                   3493:             $prevattempts.=&start_data_table_row().
                   3494:                            '<td>'.&mt('Transaction [_1]',$version).'</td>';
                   3495:             if (@hidden) {
                   3496:                 foreach my $key (sort(keys(%lasthash))) {
1.989     raeburn  3497:                     next if ($key =~ /\.foilorder$/);
1.945     raeburn  3498:                     my $hide;
                   3499:                     foreach my $id (@hidden) {
                   3500:                         if ($key =~ /^\Q$id\E/) {
                   3501:                             $hide = 1;
                   3502:                             last;
                   3503:                         }
                   3504:                     }
                   3505:                     if ($hide) {
                   3506:                         my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
                   3507:                         if (($data eq 'award') || ($data eq 'awarddetail')) {
                   3508:                             my $value = &format_previous_attempt_value($key,
                   3509:                                              $returnhash{$version.':'.$key});
                   3510:                             $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3511:                         } else {
                   3512:                             $prevattempts.='<td>&nbsp;</td>';
                   3513:                         }
                   3514:                     } else {
                   3515:                         if ($key =~ /\./) {
                   3516:                             my $value = &format_previous_attempt_value($key,
                   3517:                                               $returnhash{$version.':'.$key});
                   3518:                             $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3519:                         } else {
                   3520:                             $prevattempts.='<td>&nbsp;</td>';
                   3521:                         }
                   3522:                     }
                   3523:                 }
                   3524:             } else {
                   3525: 	        foreach my $key (sort(keys(%lasthash))) {
1.989     raeburn  3526:                     next if ($key =~ /\.foilorder$/);
1.945     raeburn  3527: 		    my $value = &format_previous_attempt_value($key,
                   3528: 			            $returnhash{$version.':'.$key});
                   3529: 		    $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3530: 	        }
                   3531:             }
                   3532: 	    $prevattempts.=&end_data_table_row();
1.40      ng       3533: 	 }
1.1       albertel 3534:       }
1.945     raeburn  3535:       my @currhidden = keys(%lasthidden);
1.596     albertel 3536:       $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356     albertel 3537:       foreach my $key (sort(keys(%lasthash))) {
1.989     raeburn  3538:           next if ($key =~ /\.foilorder$/);
1.945     raeburn  3539:           if (%typeparts) {
                   3540:               my $hidden;
                   3541:               foreach my $id (@currhidden) {
                   3542:                   if ($key =~ /^\Q$id\E/) {
                   3543:                       $hidden = 1;
                   3544:                       last;
                   3545:                   }
                   3546:               }
                   3547:               if ($hidden) {
                   3548:                   my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
                   3549:                   if (($data eq 'award') || ($data eq 'awarddetail')) {
                   3550:                       my $value = &format_previous_attempt_value($key,$lasthash{$key});
                   3551:                       if ($key =~/$regexp$/ && (defined &$gradesub)) {
                   3552:                           $value = &$gradesub($value);
                   3553:                       }
                   3554:                       $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3555:                   } else {
                   3556:                       $prevattempts.='<td>&nbsp;</td>';
                   3557:                   }
                   3558:               } else {
                   3559:                   my $value = &format_previous_attempt_value($key,$lasthash{$key});
                   3560:                   if ($key =~/$regexp$/ && (defined &$gradesub)) {
                   3561:                       $value = &$gradesub($value);
                   3562:                   }
                   3563:                   $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3564:               }
                   3565:           } else {
                   3566: 	      my $value = &format_previous_attempt_value($key,$lasthash{$key});
                   3567: 	      if ($key =~/$regexp$/ && (defined &$gradesub)) {
                   3568:                   $value = &$gradesub($value);
                   3569:               }
                   3570: 	      $prevattempts.='<td>'.$value.'&nbsp;</td>';
                   3571:           }
1.16      harris41 3572:       }
1.596     albertel 3573:       $prevattempts.= &end_data_table_row().&end_data_table();
1.1       albertel 3574:     } else {
1.596     albertel 3575:       $prevattempts=
                   3576: 	  &start_data_table().&start_data_table_row().
                   3577: 	  '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
                   3578: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3579:     }
                   3580:   } else {
1.596     albertel 3581:     $prevattempts=
                   3582: 	  &start_data_table().&start_data_table_row().
                   3583: 	  '<td>'.&mt('No data.').'</td>'.
                   3584: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3585:   }
1.10      albertel 3586: }
                   3587: 
1.581     albertel 3588: sub format_previous_attempt_value {
                   3589:     my ($key,$value) = @_;
                   3590:     if ($key =~ /timestamp/) {
                   3591: 	$value = &Apache::lonlocal::locallocaltime($value);
                   3592:     } elsif (ref($value) eq 'ARRAY') {
                   3593: 	$value = '('.join(', ', @{ $value }).')';
1.988     raeburn  3594:     } elsif ($key =~ /answerstring$/) {
                   3595:         my %answers = &Apache::lonnet::str2hash($value);
                   3596:         my @anskeys = sort(keys(%answers));
                   3597:         if (@anskeys == 1) {
                   3598:             my $answer = $answers{$anskeys[0]};
1.1001    raeburn  3599:             if ($answer =~ m{\0}) {
                   3600:                 $answer =~ s{\0}{,}g;
1.988     raeburn  3601:             }
                   3602:             my $tag_internal_answer_name = 'INTERNAL';
                   3603:             if ($anskeys[0] eq $tag_internal_answer_name) {
                   3604:                 $value = $answer; 
                   3605:             } else {
                   3606:                 $value = $anskeys[0].'='.$answer;
                   3607:             }
                   3608:         } else {
                   3609:             foreach my $ans (@anskeys) {
                   3610:                 my $answer = $answers{$ans};
1.1001    raeburn  3611:                 if ($answer =~ m{\0}) {
                   3612:                     $answer =~ s{\0}{,}g;
1.988     raeburn  3613:                 }
                   3614:                 $value .=  $ans.'='.$answer.'<br />';;
                   3615:             } 
                   3616:         }
1.581     albertel 3617:     } else {
                   3618: 	$value = &unescape($value);
                   3619:     }
                   3620:     return $value;
                   3621: }
                   3622: 
                   3623: 
1.107     albertel 3624: sub relative_to_absolute {
                   3625:     my ($url,$output)=@_;
                   3626:     my $parser=HTML::TokeParser->new(\$output);
                   3627:     my $token;
                   3628:     my $thisdir=$url;
                   3629:     my @rlinks=();
                   3630:     while ($token=$parser->get_token) {
                   3631: 	if ($token->[0] eq 'S') {
                   3632: 	    if ($token->[1] eq 'a') {
                   3633: 		if ($token->[2]->{'href'}) {
                   3634: 		    $rlinks[$#rlinks+1]=$token->[2]->{'href'};
                   3635: 		}
                   3636: 	    } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
                   3637: 		$rlinks[$#rlinks+1]=$token->[2]->{'src'};
                   3638: 	    } elsif ($token->[1] eq 'base') {
                   3639: 		$thisdir=$token->[2]->{'href'};
                   3640: 	    }
                   3641: 	}
                   3642:     }
                   3643:     $thisdir=~s-/[^/]*$--;
1.356     albertel 3644:     foreach my $link (@rlinks) {
1.726     raeburn  3645: 	unless (($link=~/^https?\:\/\//i) ||
1.356     albertel 3646: 		($link=~/^\//) ||
                   3647: 		($link=~/^javascript:/i) ||
                   3648: 		($link=~/^mailto:/i) ||
                   3649: 		($link=~/^\#/)) {
                   3650: 	    my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
                   3651: 	    $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107     albertel 3652: 	}
                   3653:     }
                   3654: # -------------------------------------------------- Deal with Applet codebases
                   3655:     $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
                   3656:     return $output;
                   3657: }
                   3658: 
1.112     bowersj2 3659: =pod
                   3660: 
1.648     raeburn  3661: =item * &get_student_view()
1.112     bowersj2 3662: 
                   3663: show a snapshot of what student was looking at
                   3664: 
                   3665: =cut
                   3666: 
1.10      albertel 3667: sub get_student_view {
1.186     albertel 3668:   my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114     www      3669:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3670:   my (%form);
1.10      albertel 3671:   my @elements=('symb','courseid','domain','username');
                   3672:   foreach my $element (@elements) {
1.186     albertel 3673:       $form{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3674:   }
1.186     albertel 3675:   if (defined($moreenv)) {
                   3676:       %form=(%form,%{$moreenv});
                   3677:   }
1.236     albertel 3678:   if (defined($target)) { $form{'grade_target'} = $target; }
1.107     albertel 3679:   $feedurl=&Apache::lonnet::clutter($feedurl);
1.650     www      3680:   my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11      albertel 3681:   $userview=~s/\<body[^\>]*\>//gi;
                   3682:   $userview=~s/\<\/body\>//gi;
                   3683:   $userview=~s/\<html\>//gi;
                   3684:   $userview=~s/\<\/html\>//gi;
                   3685:   $userview=~s/\<head\>//gi;
                   3686:   $userview=~s/\<\/head\>//gi;
                   3687:   $userview=~s/action\s*\=/would_be_action\=/gi;
1.107     albertel 3688:   $userview=&relative_to_absolute($feedurl,$userview);
1.650     www      3689:   if (wantarray) {
                   3690:      return ($userview,$response);
                   3691:   } else {
                   3692:      return $userview;
                   3693:   }
                   3694: }
                   3695: 
                   3696: sub get_student_view_with_retries {
                   3697:   my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
                   3698: 
                   3699:     my $ok = 0;                 # True if we got a good response.
                   3700:     my $content;
                   3701:     my $response;
                   3702: 
                   3703:     # Try to get the student_view done. within the retries count:
                   3704:     
                   3705:     do {
                   3706:          ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
                   3707:          $ok      = $response->is_success;
                   3708:          if (!$ok) {
                   3709:             &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
                   3710:          }
                   3711:          $retries--;
                   3712:     } while (!$ok && ($retries > 0));
                   3713:     
                   3714:     if (!$ok) {
                   3715:        $content = '';          # On error return an empty content.
                   3716:     }
1.651     www      3717:     if (wantarray) {
                   3718:        return ($content, $response);
                   3719:     } else {
                   3720:        return $content;
                   3721:     }
1.11      albertel 3722: }
                   3723: 
1.112     bowersj2 3724: =pod
                   3725: 
1.648     raeburn  3726: =item * &get_student_answers() 
1.112     bowersj2 3727: 
                   3728: show a snapshot of how student was answering problem
                   3729: 
                   3730: =cut
                   3731: 
1.11      albertel 3732: sub get_student_answers {
1.100     sakharuk 3733:   my ($symb,$username,$domain,$courseid,%form) = @_;
1.114     www      3734:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3735:   my (%moreenv);
1.11      albertel 3736:   my @elements=('symb','courseid','domain','username');
                   3737:   foreach my $element (@elements) {
1.186     albertel 3738:     $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3739:   }
1.186     albertel 3740:   $moreenv{'grade_target'}='answer';
                   3741:   %moreenv=(%form,%moreenv);
1.497     raeburn  3742:   $feedurl = &Apache::lonnet::clutter($feedurl);
                   3743:   my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10      albertel 3744:   return $userview;
1.1       albertel 3745: }
1.116     albertel 3746: 
                   3747: =pod
                   3748: 
                   3749: =item * &submlink()
                   3750: 
1.242     albertel 3751: Inputs: $text $uname $udom $symb $target
1.116     albertel 3752: 
                   3753: Returns: A link to grades.pm such as to see the SUBM view of a student
                   3754: 
                   3755: =cut
                   3756: 
                   3757: ###############################################
                   3758: sub submlink {
1.242     albertel 3759:     my ($text,$uname,$udom,$symb,$target)=@_;
1.116     albertel 3760:     if (!($uname && $udom)) {
                   3761: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3762: 	    &Apache::lonnet::whichuser($symb);
1.116     albertel 3763: 	if (!$symb) { $symb=$cursymb; }
                   3764:     }
1.254     matthew  3765:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3766:     $symb=&escape($symb);
1.960     bisitz   3767:     if ($target) { $target=" target=\"$target\""; }
                   3768:     return
                   3769:         '<a href="/adm/grades?command=submission'.
                   3770:         '&amp;symb='.$symb.
                   3771:         '&amp;student='.$uname.
                   3772:         '&amp;userdom='.$udom.'"'.
                   3773:         $target.'>'.$text.'</a>';
1.242     albertel 3774: }
                   3775: ##############################################
                   3776: 
                   3777: =pod
                   3778: 
                   3779: =item * &pgrdlink()
                   3780: 
                   3781: Inputs: $text $uname $udom $symb $target
                   3782: 
                   3783: Returns: A link to grades.pm such as to see the PGRD view of a student
                   3784: 
                   3785: =cut
                   3786: 
                   3787: ###############################################
                   3788: sub pgrdlink {
                   3789:     my $link=&submlink(@_);
                   3790:     $link=~s/(&command=submission)/$1&showgrading=yes/;
                   3791:     return $link;
                   3792: }
                   3793: ##############################################
                   3794: 
                   3795: =pod
                   3796: 
                   3797: =item * &pprmlink()
                   3798: 
                   3799: Inputs: $text $uname $udom $symb $target
                   3800: 
                   3801: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283     albertel 3802: student and a specific resource
1.242     albertel 3803: 
                   3804: =cut
                   3805: 
                   3806: ###############################################
                   3807: sub pprmlink {
                   3808:     my ($text,$uname,$udom,$symb,$target)=@_;
                   3809:     if (!($uname && $udom)) {
                   3810: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3811: 	    &Apache::lonnet::whichuser($symb);
1.242     albertel 3812: 	if (!$symb) { $symb=$cursymb; }
                   3813:     }
1.254     matthew  3814:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3815:     $symb=&escape($symb);
1.242     albertel 3816:     if ($target) { $target="target=\"$target\""; }
1.595     albertel 3817:     return '<a href="/adm/parmset?command=set&amp;'.
                   3818: 	'symb='.$symb.'&amp;uname='.$uname.
                   3819: 	'&amp;udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116     albertel 3820: }
                   3821: ##############################################
1.37      matthew  3822: 
1.112     bowersj2 3823: =pod
                   3824: 
                   3825: =back
                   3826: 
                   3827: =cut
                   3828: 
1.37      matthew  3829: ###############################################
1.51      www      3830: 
                   3831: 
                   3832: sub timehash {
1.687     raeburn  3833:     my ($thistime) = @_;
                   3834:     my $timezone = &Apache::lonlocal::gettimezone();
                   3835:     my $dt = DateTime->from_epoch(epoch => $thistime)
                   3836:                      ->set_time_zone($timezone);
                   3837:     my $wday = $dt->day_of_week();
                   3838:     if ($wday == 7) { $wday = 0; }
                   3839:     return ( 'second' => $dt->second(),
                   3840:              'minute' => $dt->minute(),
                   3841:              'hour'   => $dt->hour(),
                   3842:              'day'     => $dt->day_of_month(),
                   3843:              'month'   => $dt->month(),
                   3844:              'year'    => $dt->year(),
                   3845:              'weekday' => $wday,
                   3846:              'dayyear' => $dt->day_of_year(),
                   3847:              'dlsav'   => $dt->is_dst() );
1.51      www      3848: }
                   3849: 
1.370     www      3850: sub utc_string {
                   3851:     my ($date)=@_;
1.371     www      3852:     return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370     www      3853: }
                   3854: 
1.51      www      3855: sub maketime {
                   3856:     my %th=@_;
1.687     raeburn  3857:     my ($epoch_time,$timezone,$dt);
                   3858:     $timezone = &Apache::lonlocal::gettimezone();
                   3859:     eval {
                   3860:         $dt = DateTime->new( year   => $th{'year'},
                   3861:                              month  => $th{'month'},
                   3862:                              day    => $th{'day'},
                   3863:                              hour   => $th{'hour'},
                   3864:                              minute => $th{'minute'},
                   3865:                              second => $th{'second'},
                   3866:                              time_zone => $timezone,
                   3867:                          );
                   3868:     };
                   3869:     if (!$@) {
                   3870:         $epoch_time = $dt->epoch;
                   3871:         if ($epoch_time) {
                   3872:             return $epoch_time;
                   3873:         }
                   3874:     }
1.51      www      3875:     return POSIX::mktime(
                   3876:         ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210     www      3877:          $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70      www      3878: }
                   3879: 
                   3880: #########################################
1.51      www      3881: 
                   3882: sub findallcourses {
1.482     raeburn  3883:     my ($roles,$uname,$udom) = @_;
1.355     albertel 3884:     my %roles;
                   3885:     if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348     albertel 3886:     my %courses;
1.51      www      3887:     my $now=time;
1.482     raeburn  3888:     if (!defined($uname)) {
                   3889:         $uname = $env{'user.name'};
                   3890:     }
                   3891:     if (!defined($udom)) {
                   3892:         $udom = $env{'user.domain'};
                   3893:     }
                   3894:     if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.982     raeburn  3895:         my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
                   3896:         my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname,'.',undef,
                   3897:                                               $extra);
1.482     raeburn  3898:         if (!%roles) {
                   3899:             %roles = (
                   3900:                        cc => 1,
1.907     raeburn  3901:                        co => 1,
1.482     raeburn  3902:                        in => 1,
                   3903:                        ep => 1,
                   3904:                        ta => 1,
                   3905:                        cr => 1,
                   3906:                        st => 1,
                   3907:              );
                   3908:         }
                   3909:         foreach my $entry (keys(%roleshash)) {
                   3910:             my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
                   3911:             if ($trole =~ /^cr/) { 
                   3912:                 next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
                   3913:             } else {
                   3914:                 next if (!exists($roles{$trole}));
                   3915:             }
                   3916:             if ($tend) {
                   3917:                 next if ($tend < $now);
                   3918:             }
                   3919:             if ($tstart) {
                   3920:                 next if ($tstart > $now);
                   3921:             }
                   3922:             my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
                   3923:             (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
                   3924:             if ($secpart eq '') {
                   3925:                 ($cnum,$role) = split(/_/,$cnumpart); 
                   3926:                 $sec = 'none';
                   3927:                 $realsec = '';
                   3928:             } else {
                   3929:                 $cnum = $cnumpart;
                   3930:                 ($sec,$role) = split(/_/,$secpart);
                   3931:                 $realsec = $sec;
1.490     raeburn  3932:             }
1.482     raeburn  3933:             $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
                   3934:         }
                   3935:     } else {
                   3936:         foreach my $key (keys(%env)) {
1.483     albertel 3937: 	    if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
                   3938:                  $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482     raeburn  3939: 	        my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
                   3940: 	        next if ($role eq 'ca' || $role eq 'aa');
                   3941: 	        next if (%roles && !exists($roles{$role}));
                   3942: 	        my ($starttime,$endtime)=split(/\./,$env{$key});
                   3943:                 my $active=1;
                   3944:                 if ($starttime) {
                   3945: 		    if ($now<$starttime) { $active=0; }
                   3946:                 }
                   3947:                 if ($endtime) {
                   3948:                     if ($now>$endtime) { $active=0; }
                   3949:                 }
                   3950:                 if ($active) {
                   3951:                     if ($sec eq '') {
                   3952:                         $sec = 'none';
                   3953:                     }
                   3954:                     $courses{$cdom.'_'.$cnum}{$sec} = 
                   3955:                                      $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474     raeburn  3956:                 }
                   3957:             }
1.51      www      3958:         }
                   3959:     }
1.474     raeburn  3960:     return %courses;
1.51      www      3961: }
1.37      matthew  3962: 
1.54      www      3963: ###############################################
1.474     raeburn  3964: 
                   3965: sub blockcheck {
1.482     raeburn  3966:     my ($setters,$activity,$uname,$udom) = @_;
1.490     raeburn  3967: 
                   3968:     if (!defined($udom)) {
                   3969:         $udom = $env{'user.domain'};
                   3970:     }
                   3971:     if (!defined($uname)) {
                   3972:         $uname = $env{'user.name'};
                   3973:     }
                   3974: 
                   3975:     # If uname and udom are for a course, check for blocks in the course.
                   3976: 
                   3977:     if (&Apache::lonnet::is_course($udom,$uname)) {
                   3978:         my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502     raeburn  3979:         my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490     raeburn  3980:         return ($startblock,$endblock);
                   3981:     }
1.474     raeburn  3982: 
1.502     raeburn  3983:     my $startblock = 0;
                   3984:     my $endblock = 0;
1.482     raeburn  3985:     my %live_courses = &findallcourses(undef,$uname,$udom);
1.474     raeburn  3986: 
1.490     raeburn  3987:     # If uname is for a user, and activity is course-specific, i.e.,
                   3988:     # boards, chat or groups, check for blocking in current course only.
1.474     raeburn  3989: 
1.490     raeburn  3990:     if (($activity eq 'boards' || $activity eq 'chat' ||
                   3991:          $activity eq 'groups') && ($env{'request.course.id'})) {
                   3992:         foreach my $key (keys(%live_courses)) {
                   3993:             if ($key ne $env{'request.course.id'}) {
                   3994:                 delete($live_courses{$key});
                   3995:             }
                   3996:         }
                   3997:     }
                   3998: 
                   3999:     my $otheruser = 0;
                   4000:     my %own_courses;
                   4001:     if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
                   4002:         # Resource belongs to user other than current user.
                   4003:         $otheruser = 1;
                   4004:         # Gather courses for current user
                   4005:         %own_courses = 
                   4006:             &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
                   4007:     }
                   4008: 
                   4009:     # Gather active course roles - course coordinator, instructor, 
                   4010:     # exam proctor, ta, student, or custom role.
1.474     raeburn  4011: 
                   4012:     foreach my $course (keys(%live_courses)) {
1.482     raeburn  4013:         my ($cdom,$cnum);
                   4014:         if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
                   4015:             $cdom = $env{'course.'.$course.'.domain'};
                   4016:             $cnum = $env{'course.'.$course.'.num'};
                   4017:         } else {
1.490     raeburn  4018:             ($cdom,$cnum) = split(/_/,$course); 
1.482     raeburn  4019:         }
                   4020:         my $no_ownblock = 0;
                   4021:         my $no_userblock = 0;
1.533     raeburn  4022:         if ($otheruser && $activity ne 'com') {
1.490     raeburn  4023:             # Check if current user has 'evb' priv for this
                   4024:             if (defined($own_courses{$course})) {
                   4025:                 foreach my $sec (keys(%{$own_courses{$course}})) {
                   4026:                     my $checkrole = 'cm./'.$cdom.'/'.$cnum;
                   4027:                     if ($sec ne 'none') {
                   4028:                         $checkrole .= '/'.$sec;
                   4029:                     }
                   4030:                     if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   4031:                         $no_ownblock = 1;
                   4032:                         last;
                   4033:                     }
                   4034:                 }
                   4035:             }
                   4036:             # if they have 'evb' priv and are currently not playing student
                   4037:             next if (($no_ownblock) &&
                   4038:                  ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
                   4039:         }
1.474     raeburn  4040:         foreach my $sec (keys(%{$live_courses{$course}})) {
1.482     raeburn  4041:             my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474     raeburn  4042:             if ($sec ne 'none') {
1.482     raeburn  4043:                 $checkrole .= '/'.$sec;
1.474     raeburn  4044:             }
1.490     raeburn  4045:             if ($otheruser) {
                   4046:                 # Resource belongs to user other than current user.
                   4047:                 # Assemble privs for that user, and check for 'evb' priv.
1.482     raeburn  4048:                 my ($trole,$tdom,$tnum,$tsec);
                   4049:                 my $entry = $live_courses{$course}{$sec};
                   4050:                 if ($entry =~ /^cr/) {
                   4051:                     ($trole,$tdom,$tnum,$tsec) = 
                   4052:                       ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
                   4053:                 } else {
                   4054:                     ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
                   4055:                 }
                   4056:                 my ($spec,$area,$trest,%allroles,%userroles);
                   4057:                 $area = '/'.$tdom.'/'.$tnum;
                   4058:                 $trest = $tnum;
                   4059:                 if ($tsec ne '') {
                   4060:                     $area .= '/'.$tsec;
                   4061:                     $trest .= '/'.$tsec;
                   4062:                 }
                   4063:                 $spec = $trole.'.'.$area;
                   4064:                 if ($trole =~ /^cr/) {
                   4065:                     &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
                   4066:                                                       $tdom,$spec,$trest,$area);
                   4067:                 } else {
                   4068:                     &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
                   4069:                                                        $tdom,$spec,$trest,$area);
                   4070:                 }
                   4071:                 my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486     raeburn  4072:                 if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
                   4073:                     if ($1) {
                   4074:                         $no_userblock = 1;
                   4075:                         last;
                   4076:                     }
                   4077:                 }
1.490     raeburn  4078:             } else {
                   4079:                 # Resource belongs to current user
                   4080:                 # Check for 'evb' priv via lonnet::allowed().
1.482     raeburn  4081:                 if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   4082:                     $no_ownblock = 1;
                   4083:                     last;
                   4084:                 }
1.474     raeburn  4085:             }
                   4086:         }
                   4087:         # if they have the evb priv and are currently not playing student
1.482     raeburn  4088:         next if (($no_ownblock) &&
1.491     albertel 4089:                  ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482     raeburn  4090:         next if ($no_userblock);
1.474     raeburn  4091: 
1.866     kalberla 4092:         # Retrieve blocking times and identity of locker for course
1.490     raeburn  4093:         # of specified user, unless user has 'evb' privilege.
1.502     raeburn  4094:         
                   4095:         my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
                   4096:         if (($start != 0) && 
                   4097:             (($startblock == 0) || ($startblock > $start))) {
                   4098:             $startblock = $start;
                   4099:         }
                   4100:         if (($end != 0)  &&
                   4101:             (($endblock == 0) || ($endblock < $end))) {
                   4102:             $endblock = $end;
                   4103:         }
1.490     raeburn  4104:     }
                   4105:     return ($startblock,$endblock);
                   4106: }
                   4107: 
                   4108: sub get_blocks {
                   4109:     my ($setters,$activity,$cdom,$cnum) = @_;
                   4110:     my $startblock = 0;
                   4111:     my $endblock = 0;
                   4112:     my $course = $cdom.'_'.$cnum;
                   4113:     $setters->{$course} = {};
                   4114:     $setters->{$course}{'staff'} = [];
                   4115:     $setters->{$course}{'times'} = [];
                   4116:     my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
                   4117:     foreach my $record (keys(%records)) {
                   4118:         my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
                   4119:         if ($start <= time && $end >= time) {
                   4120:             my ($staff_name,$staff_dom,$title,$blocks) =
                   4121:                 &parse_block_record($records{$record});
                   4122:             if ($blocks->{$activity} eq 'on') {
                   4123:                 push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
                   4124:                 push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491     albertel 4125:                 if ( ($startblock == 0) || ($startblock > $start) ) {
                   4126:                     $startblock = $start;
1.490     raeburn  4127:                 }
1.491     albertel 4128:                 if ( ($endblock == 0) || ($endblock < $end) ) {
                   4129:                     $endblock = $end;
1.474     raeburn  4130:                 }
                   4131:             }
                   4132:         }
                   4133:     }
                   4134:     return ($startblock,$endblock);
                   4135: }
                   4136: 
                   4137: sub parse_block_record {
                   4138:     my ($record) = @_;
                   4139:     my ($setuname,$setudom,$title,$blocks);
                   4140:     if (ref($record) eq 'HASH') {
                   4141:         ($setuname,$setudom) = split(/:/,$record->{'setter'});
                   4142:         $title = &unescape($record->{'event'});
                   4143:         $blocks = $record->{'blocks'};
                   4144:     } else {
                   4145:         my @data = split(/:/,$record,3);
                   4146:         if (scalar(@data) eq 2) {
                   4147:             $title = $data[1];
                   4148:             ($setuname,$setudom) = split(/@/,$data[0]);
                   4149:         } else {
                   4150:             ($setuname,$setudom,$title) = @data;
                   4151:         }
                   4152:         $blocks = { 'com' => 'on' };
                   4153:     }
                   4154:     return ($setuname,$setudom,$title,$blocks);
                   4155: }
                   4156: 
1.854     kalberla 4157: sub blocking_status {
                   4158:   my ($activity,$uname,$udom) = @_;
1.867     kalberla 4159:   my %setters;
1.890     droeschl 4160: 
                   4161:   # check for active blocking
1.867     kalberla 4162:   my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
1.854     kalberla 4163: 
1.890     droeschl 4164:   my $blocked = $startblock && $endblock ? 1 : 0;
                   4165: 
                   4166:   # caller just wants to know whether a block is active
                   4167:   if (!wantarray) { return $blocked; }
                   4168: 
                   4169:   # build a link to a popup window containing the details
                   4170:   my $querystring  = "?activity=$activity";
                   4171:   # $uname and $udom decide whose portfolio the user is trying to look at
                   4172:      $querystring .= "&amp;udom=$udom"      if $udom;
                   4173:      $querystring .= "&amp;uname=$uname"    if $uname;
                   4174: 
                   4175:   my $output .= <<'END_MYBLOCK';
1.854     kalberla 4176:     function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
                   4177:         var options = "width=" + w + ",height=" + h + ",";
                   4178:         options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
                   4179:         options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
                   4180:         var newWin = window.open(url, wdwName, options);
                   4181:         newWin.focus();
                   4182:     }
1.890     droeschl 4183: END_MYBLOCK
1.854     kalberla 4184: 
1.890     droeschl 4185:   $output = Apache::lonhtmlcommon::scripttag($output);
                   4186:   
1.854     kalberla 4187:   my $popupUrl = "/adm/blockingstatus/$querystring";
1.890     droeschl 4188:   my $text = mt('Communication Blocked');
                   4189: 
1.867     kalberla 4190:   $output .= <<"END_BLOCK";
                   4191: <div class='LC_comblock'>
1.869     kalberla 4192:   <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890     droeschl 4193:   title='$text'>
                   4194:   <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869     kalberla 4195:   <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring' 
1.890     droeschl 4196:   title='$text'>$text</a>
1.867     kalberla 4197: </div>
                   4198: 
                   4199: END_BLOCK
1.474     raeburn  4200: 
1.854     kalberla 4201:   return ($blocked, $output);
                   4202: }
1.490     raeburn  4203: 
1.60      matthew  4204: ###############################################
                   4205: 
1.682     raeburn  4206: sub check_ip_acc {
                   4207:     my ($acc)=@_;
                   4208:     &Apache::lonxml::debug("acc is $acc");
                   4209:     if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
                   4210:         return 1;
                   4211:     }
                   4212:     my $allowed=0;
                   4213:     my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
                   4214: 
                   4215:     my $name;
                   4216:     foreach my $pattern (split(',',$acc)) {
                   4217:         $pattern =~ s/^\s*//;
                   4218:         $pattern =~ s/\s*$//;
                   4219:         if ($pattern =~ /\*$/) {
                   4220:             #35.8.*
                   4221:             $pattern=~s/\*//;
                   4222:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   4223:         } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
                   4224:             #35.8.3.[34-56]
                   4225:             my $low=$2;
                   4226:             my $high=$3;
                   4227:             $pattern=$1;
                   4228:             if ($ip =~ /^\Q$pattern\E/) {
                   4229:                 my $last=(split(/\./,$ip))[3];
                   4230:                 if ($last <=$high && $last >=$low) { $allowed=1; }
                   4231:             }
                   4232:         } elsif ($pattern =~ /^\*/) {
                   4233:             #*.msu.edu
                   4234:             $pattern=~s/\*//;
                   4235:             if (!defined($name)) {
                   4236:                 use Socket;
                   4237:                 my $netaddr=inet_aton($ip);
                   4238:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   4239:             }
                   4240:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   4241:         } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
                   4242:             #127.0.0.1
                   4243:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   4244:         } else {
                   4245:             #some.name.com
                   4246:             if (!defined($name)) {
                   4247:                 use Socket;
                   4248:                 my $netaddr=inet_aton($ip);
                   4249:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   4250:             }
                   4251:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   4252:         }
                   4253:         if ($allowed) { last; }
                   4254:     }
                   4255:     return $allowed;
                   4256: }
                   4257: 
                   4258: ###############################################
                   4259: 
1.60      matthew  4260: =pod
                   4261: 
1.112     bowersj2 4262: =head1 Domain Template Functions
                   4263: 
                   4264: =over 4
                   4265: 
                   4266: =item * &determinedomain()
1.60      matthew  4267: 
                   4268: Inputs: $domain (usually will be undef)
                   4269: 
1.63      www      4270: Returns: Determines which domain should be used for designs
1.60      matthew  4271: 
                   4272: =cut
1.54      www      4273: 
1.60      matthew  4274: ###############################################
1.63      www      4275: sub determinedomain {
                   4276:     my $domain=shift;
1.531     albertel 4277:     if (! $domain) {
1.60      matthew  4278:         # Determine domain if we have not been given one
1.893     raeburn  4279:         $domain = &Apache::lonnet::default_login_domain();
1.258     albertel 4280:         if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
                   4281:         if ($env{'request.role.domain'}) { 
                   4282:             $domain=$env{'request.role.domain'}; 
1.60      matthew  4283:         }
                   4284:     }
1.63      www      4285:     return $domain;
                   4286: }
                   4287: ###############################################
1.517     raeburn  4288: 
1.518     albertel 4289: sub devalidate_domconfig_cache {
                   4290:     my ($udom)=@_;
                   4291:     &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
                   4292: }
                   4293: 
                   4294: # ---------------------- Get domain configuration for a domain
                   4295: sub get_domainconf {
                   4296:     my ($udom) = @_;
                   4297:     my $cachetime=1800;
                   4298:     my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
                   4299:     if (defined($cached)) { return %{$result}; }
                   4300: 
                   4301:     my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948     raeburn  4302: 					     ['login','rolecolors','autoenroll'],$udom);
1.632     raeburn  4303:     my (%designhash,%legacy);
1.518     albertel 4304:     if (keys(%domconfig) > 0) {
                   4305:         if (ref($domconfig{'login'}) eq 'HASH') {
1.632     raeburn  4306:             if (keys(%{$domconfig{'login'}})) {
                   4307:                 foreach my $key (keys(%{$domconfig{'login'}})) {
1.699     raeburn  4308:                     if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946     raeburn  4309:                         if ($key eq 'loginvia') {
                   4310:                             if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
                   4311:                                 my @ids = &Apache::lonnet::current_machine_ids();
                   4312:                                 foreach my $hostname (@ids) {
1.948     raeburn  4313:                                     if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
                   4314:                                         if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
                   4315:                                             my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
                   4316:                                             $designhash{$udom.'.login.loginvia'} = $server;
                   4317:                                             if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
                   4318: 
                   4319:                                                 $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
                   4320:                                             } else {
                   4321:                                                  $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
                   4322:                                             }
                   4323:                                             if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
                   4324:                                                 $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
                   4325:                                             }
1.946     raeburn  4326:                                         }
                   4327:                                     }
                   4328:                                 }
                   4329:                             }
                   4330:                         } else {
                   4331:                             foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
                   4332:                                 $designhash{$udom.'.login.'.$key.'_'.$img} = 
                   4333:                                     $domconfig{'login'}{$key}{$img};
                   4334:                             }
1.699     raeburn  4335:                         }
                   4336:                     } else {
                   4337:                         $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
                   4338:                     }
1.632     raeburn  4339:                 }
                   4340:             } else {
                   4341:                 $legacy{'login'} = 1;
1.518     albertel 4342:             }
1.632     raeburn  4343:         } else {
                   4344:             $legacy{'login'} = 1;
1.518     albertel 4345:         }
                   4346:         if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632     raeburn  4347:             if (keys(%{$domconfig{'rolecolors'}})) {
                   4348:                 foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
                   4349:                     if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
                   4350:                         foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
                   4351:                             $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
                   4352:                         }
1.518     albertel 4353:                     }
                   4354:                 }
1.632     raeburn  4355:             } else {
                   4356:                 $legacy{'rolecolors'} = 1;
1.518     albertel 4357:             }
1.632     raeburn  4358:         } else {
                   4359:             $legacy{'rolecolors'} = 1;
1.518     albertel 4360:         }
1.948     raeburn  4361:         if (ref($domconfig{'autoenroll'}) eq 'HASH') {
                   4362:             if ($domconfig{'autoenroll'}{'co-owners'}) {
                   4363:                 $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
                   4364:             }
                   4365:         }
1.632     raeburn  4366:         if (keys(%legacy) > 0) {
                   4367:             my %legacyhash = &get_legacy_domconf($udom);
                   4368:             foreach my $item (keys(%legacyhash)) {
                   4369:                 if ($item =~ /^\Q$udom\E\.login/) {
                   4370:                     if ($legacy{'login'}) { 
                   4371:                         $designhash{$item} = $legacyhash{$item};
                   4372:                     }
                   4373:                 } else {
                   4374:                     if ($legacy{'rolecolors'}) {
                   4375:                         $designhash{$item} = $legacyhash{$item};
                   4376:                     }
1.518     albertel 4377:                 }
                   4378:             }
                   4379:         }
1.632     raeburn  4380:     } else {
                   4381:         %designhash = &get_legacy_domconf($udom); 
1.518     albertel 4382:     }
                   4383:     &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
                   4384: 				  $cachetime);
                   4385:     return %designhash;
                   4386: }
                   4387: 
1.632     raeburn  4388: sub get_legacy_domconf {
                   4389:     my ($udom) = @_;
                   4390:     my %legacyhash;
                   4391:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
                   4392:     my $designfile =  $designdir.'/'.$udom.'.tab';
                   4393:     if (-e $designfile) {
                   4394:         if ( open (my $fh,"<$designfile") ) {
                   4395:             while (my $line = <$fh>) {
                   4396:                 next if ($line =~ /^\#/);
                   4397:                 chomp($line);
                   4398:                 my ($key,$val)=(split(/\=/,$line));
                   4399:                 if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
                   4400:             }
                   4401:             close($fh);
                   4402:         }
                   4403:     }
                   4404:     if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
                   4405:         $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
                   4406:     }
                   4407:     return %legacyhash;
                   4408: }
                   4409: 
1.63      www      4410: =pod
                   4411: 
1.112     bowersj2 4412: =item * &domainlogo()
1.63      www      4413: 
                   4414: Inputs: $domain (usually will be undef)
                   4415: 
                   4416: Returns: A link to a domain logo, if the domain logo exists.
                   4417: If the domain logo does not exist, a description of the domain.
                   4418: 
                   4419: =cut
1.112     bowersj2 4420: 
1.63      www      4421: ###############################################
                   4422: sub domainlogo {
1.517     raeburn  4423:     my $domain = &determinedomain(shift);
1.518     albertel 4424:     my %designhash = &get_domainconf($domain);    
1.517     raeburn  4425:     # See if there is a logo
                   4426:     if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519     raeburn  4427:         my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538     albertel 4428:         if ($imgsrc =~ m{^/(adm|res)/}) {
                   4429: 	    if ($imgsrc =~ m{^/res/}) {
                   4430: 		my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
                   4431: 		&Apache::lonnet::repcopy($local_name);
                   4432: 	    }
                   4433: 	   $imgsrc = &lonhttpdurl($imgsrc);
1.519     raeburn  4434:         } 
                   4435:         return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514     albertel 4436:     } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
                   4437:         return &Apache::lonnet::domain($domain,'description');
1.59      www      4438:     } else {
1.60      matthew  4439:         return '';
1.59      www      4440:     }
                   4441: }
1.63      www      4442: ##############################################
                   4443: 
                   4444: =pod
                   4445: 
1.112     bowersj2 4446: =item * &designparm()
1.63      www      4447: 
                   4448: Inputs: $which parameter; $domain (usually will be undef)
                   4449: 
                   4450: Returns: value of designparamter $which
                   4451: 
                   4452: =cut
1.112     bowersj2 4453: 
1.397     albertel 4454: 
1.400     albertel 4455: ##############################################
1.397     albertel 4456: sub designparm {
                   4457:     my ($which,$domain)=@_;
                   4458:     if (exists($env{'environment.color.'.$which})) {
1.817     bisitz   4459:         return $env{'environment.color.'.$which};
1.96      www      4460:     }
1.63      www      4461:     $domain=&determinedomain($domain);
1.518     albertel 4462:     my %domdesign = &get_domainconf($domain);
1.520     raeburn  4463:     my $output;
1.517     raeburn  4464:     if ($domdesign{$domain.'.'.$which} ne '') {
1.817     bisitz   4465:         $output = $domdesign{$domain.'.'.$which};
1.63      www      4466:     } else {
1.520     raeburn  4467:         $output = $defaultdesign{$which};
                   4468:     }
                   4469:     if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635     raeburn  4470:         ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538     albertel 4471:         if ($output =~ m{^/(adm|res)/}) {
1.817     bisitz   4472:             if ($output =~ m{^/res/}) {
                   4473:                 my $local_name = &Apache::lonnet::filelocation('',$output);
                   4474:                 &Apache::lonnet::repcopy($local_name);
                   4475:             }
1.520     raeburn  4476:             $output = &lonhttpdurl($output);
                   4477:         }
1.63      www      4478:     }
1.520     raeburn  4479:     return $output;
1.63      www      4480: }
1.59      www      4481: 
1.822     bisitz   4482: ##############################################
                   4483: =pod
                   4484: 
1.832     bisitz   4485: =item * &authorspace()
                   4486: 
                   4487: Inputs: ./.
                   4488: 
                   4489: Returns: Path to the Construction Space of the current user's
                   4490:          accessed author space
                   4491:          The author space will be that of the current user
                   4492:          when accessing the own author space
                   4493:          and that of the co-author/assistent co-author
                   4494:          when accessing the co-author's/assistent co-author's
                   4495:          space
                   4496: 
                   4497: =cut
                   4498: 
                   4499: sub authorspace {
                   4500:     my $caname = '';
                   4501:     if ($env{'request.role'} =~ /^ca|^aa/) {
                   4502:         (undef,$caname) =
                   4503:             ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
                   4504:     } else {
                   4505:         $caname = $env{'user.name'};
                   4506:     }
                   4507:     return '/priv/'.$caname.'/';
                   4508: }
                   4509: 
                   4510: ##############################################
                   4511: =pod
                   4512: 
1.822     bisitz   4513: =item * &head_subbox()
                   4514: 
                   4515: Inputs: $content (contains HTML code with page functions, etc.)
                   4516: 
                   4517: Returns: HTML div with $content
                   4518:          To be included in page header
                   4519: 
                   4520: =cut
                   4521: 
                   4522: sub head_subbox {
                   4523:     my ($content)=@_;
                   4524:     my $output =
1.993     raeburn  4525:         '<div class="LC_head_subbox">'
1.822     bisitz   4526:        .$content
                   4527:        .'</div>'
                   4528: }
                   4529: 
                   4530: ##############################################
                   4531: =pod
                   4532: 
                   4533: =item * &CSTR_pageheader()
                   4534: 
                   4535: Inputs: ./.
                   4536: 
                   4537: Returns: HTML div with CSTR path and recent box
                   4538:          To be included on Construction Space pages
                   4539: 
                   4540: =cut
                   4541: 
                   4542: sub CSTR_pageheader {
                   4543:     # this is for resources; directories have customtitle, and crumbs
                   4544:             # and select recent are created in lonpubdir.pm  
                   4545:     my ($uname,$thisdisfn)=
                   4546:         ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
                   4547:     my $formaction='/priv/'.$uname.'/'.$thisdisfn;
                   4548:     $formaction=~s/\/+/\//g;
                   4549: 
                   4550:     my $parentpath = '';
                   4551:     my $lastitem = '';
                   4552:     if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
                   4553:         $parentpath = $1;
                   4554:         $lastitem = $2;
                   4555:     } else {
                   4556:         $lastitem = $thisdisfn;
                   4557:     }
1.921     bisitz   4558: 
                   4559:     my $output =
1.822     bisitz   4560:          '<div>'
                   4561:         .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
                   4562:         .'<b>'.&mt('Construction Space:').'</b> '
                   4563:         .'<form name="dirs" method="post" action="'.$formaction
1.921     bisitz   4564:         .'" target="_top">' #FIXME lonpubdir: target="_parent"
                   4565:         .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv',undef,undef);
                   4566: 
                   4567:     if ($lastitem) {
                   4568:         $output .=
                   4569:              '<span class="LC_filename">'
                   4570:             .$lastitem
                   4571:             .'</span>';
                   4572:     }
                   4573:     $output .=
                   4574:          '<br />'
1.822     bisitz   4575:         #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
                   4576:         .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
                   4577:         .'</form>'
                   4578:         .&Apache::lonmenu::constspaceform()
                   4579:         .'</div>';
1.921     bisitz   4580: 
                   4581:     return $output;
1.822     bisitz   4582: }
                   4583: 
1.60      matthew  4584: ###############################################
                   4585: ###############################################
                   4586: 
                   4587: =pod
                   4588: 
1.112     bowersj2 4589: =back
                   4590: 
1.549     albertel 4591: =head1 HTML Helpers
1.112     bowersj2 4592: 
                   4593: =over 4
                   4594: 
                   4595: =item * &bodytag()
1.60      matthew  4596: 
                   4597: Returns a uniform header for LON-CAPA web pages.
                   4598: 
                   4599: Inputs: 
                   4600: 
1.112     bowersj2 4601: =over 4
                   4602: 
                   4603: =item * $title, A title to be displayed on the page.
                   4604: 
                   4605: =item * $function, the current role (can be undef).
                   4606: 
                   4607: =item * $addentries, extra parameters for the <body> tag.
                   4608: 
                   4609: =item * $bodyonly, if defined, only return the <body> tag.
                   4610: 
                   4611: =item * $domain, if defined, force a given domain.
                   4612: 
                   4613: =item * $forcereg, if page should register as content page (relevant for 
1.86      www      4614:             text interface only)
1.60      matthew  4615: 
1.814     bisitz   4616: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
                   4617:                      navigational links
1.317     albertel 4618: 
1.338     albertel 4619: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
                   4620: 
1.460     albertel 4621: =item * $args, optional argument valid values are
                   4622:             no_auto_mt_title -> prevents &mt()ing the title arg
1.562     albertel 4623:             inherit_jsmath -> when creating popup window in a page,
                   4624:                               should it have jsmath forced on by the
                   4625:                               current page
1.460     albertel 4626: 
1.112     bowersj2 4627: =back
                   4628: 
1.60      matthew  4629: Returns: A uniform header for LON-CAPA web pages.  
                   4630: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
                   4631: If $bodyonly is undef or zero, an html string containing a <body> tag and 
                   4632: other decorations will be returned.
                   4633: 
                   4634: =cut
                   4635: 
1.54      www      4636: sub bodytag {
1.831     bisitz   4637:     my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.962     droeschl 4638:         $no_nav_bar,$bgcolor,$args)=@_;
1.339     albertel 4639: 
1.954     raeburn  4640:     my $public;
                   4641:     if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
                   4642:         || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
                   4643:         $public = 1;
                   4644:     }
1.460     albertel 4645:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339     albertel 4646: 
1.183     matthew  4647:     $function = &get_users_function() if (!$function);
1.339     albertel 4648:     my $img =    &designparm($function.'.img',$domain);
                   4649:     my $font =   &designparm($function.'.font',$domain);
                   4650:     my $pgbg   = $bgcolor || &designparm($function.'.pgbg',$domain);
                   4651: 
1.803     bisitz   4652:     my %design = ( 'style'   => 'margin-top: 0',
1.535     albertel 4653: 		   'bgcolor' => $pgbg,
1.339     albertel 4654: 		   'text'    => $font,
                   4655:                    'alink'   => &designparm($function.'.alink',$domain),
                   4656: 		   'vlink'   => &designparm($function.'.vlink',$domain),
                   4657: 		   'link'    => &designparm($function.'.link',$domain),);
1.438     albertel 4658:     @design{keys(%$addentries)} = @$addentries{keys(%$addentries)}; 
1.339     albertel 4659: 
1.63      www      4660:  # role and realm
1.378     raeburn  4661:     my ($role,$realm) = split(/\./,$env{'request.role'},2);
                   4662:     if ($role  eq 'ca') {
1.479     albertel 4663:         my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500     albertel 4664:         $realm = &plainname($rname,$rdom);
1.378     raeburn  4665:     } 
1.55      www      4666: # realm
1.258     albertel 4667:     if ($env{'request.course.id'}) {
1.378     raeburn  4668:         if ($env{'request.role'} !~ /^cr/) {
                   4669:             $role = &Apache::lonnet::plaintext($role,&course_type());
                   4670:         }
1.898     raeburn  4671:         if ($env{'request.course.sec'}) {
                   4672:             $role .= ('&nbsp;'x2).'-&nbsp;'.&mt('section:').'&nbsp;'.$env{'request.course.sec'};
                   4673:         }   
1.359     albertel 4674: 	$realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378     raeburn  4675:     } else {
                   4676:         $role = &Apache::lonnet::plaintext($role);
1.54      www      4677:     }
1.433     albertel 4678: 
1.359     albertel 4679:     if (!$realm) { $realm='&nbsp;'; }
1.330     albertel 4680: 
1.438     albertel 4681:     my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329     albertel 4682: 
1.101     www      4683: # construct main body tag
1.359     albertel 4684:     my $bodytag = "<body $extra_body_attr>".
1.562     albertel 4685: 	&Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252     albertel 4686: 
1.530     albertel 4687:     if ($bodyonly) {
1.60      matthew  4688:         return $bodytag;
1.798     tempelho 4689:     } 
1.359     albertel 4690: 
1.410     albertel 4691:     my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.954     raeburn  4692:     if ($public) {
1.433     albertel 4693: 	undef($role);
1.434     albertel 4694:     } else {
                   4695: 	$name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433     albertel 4696:     }
1.359     albertel 4697:     
1.762     bisitz   4698:     my $titleinfo = '<h1>'.$title.'</h1>';
1.359     albertel 4699:     #
                   4700:     # Extra info if you are the DC
                   4701:     my $dc_info = '';
                   4702:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   4703:                         $env{'course.'.$env{'request.course.id'}.
                   4704:                                  '.domain'}.'/'})) {
                   4705:         my $cid = $env{'request.course.id'};
1.917     raeburn  4706:         $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380     www      4707:         $dc_info =~ s/\s+$//;
1.359     albertel 4708:     }
                   4709: 
1.898     raeburn  4710:     $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853     droeschl 4711:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   4712: 
1.916     droeschl 4713:         if ($no_nav_bar || $env{'form.inhibitmenu'} eq 'yes') { 
                   4714:             return $bodytag; 
                   4715:         } 
1.903     droeschl 4716: 
                   4717:         if ($env{'request.state'} eq 'construct') { $forcereg=1; }
                   4718: 
                   4719:         #    if ($env{'request.state'} eq 'construct') {
                   4720:         #        $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
                   4721:         #    }
                   4722: 
1.359     albertel 4723: 
                   4724: 
1.916     droeschl 4725:         if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917     raeburn  4726:              if ($dc_info) {
                   4727:                  $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
                   4728:              }
1.916     droeschl 4729:              $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
                   4730:                 <em>$realm</em> $dc_info</div>|;
1.903     droeschl 4731:             return $bodytag;
                   4732:         }
1.894     droeschl 4733: 
1.927     raeburn  4734:         unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
                   4735:             $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>|;
                   4736:         }
1.916     droeschl 4737: 
1.903     droeschl 4738:         $bodytag .= Apache::lonhtmlcommon::scripttag(
                   4739:             Apache::lonmenu::utilityfunctions(), 'start');
1.816     bisitz   4740: 
1.903     droeschl 4741:         $bodytag .= Apache::lonmenu::primary_menu();
1.852     droeschl 4742: 
1.917     raeburn  4743:         if ($dc_info) {
                   4744:             $dc_info = &dc_courseid_toggle($dc_info);
                   4745:         }
                   4746:         $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916     droeschl 4747: 
1.903     droeschl 4748:         #don't show menus for public users
1.954     raeburn  4749:         if (!$public){
1.903     droeschl 4750:             $bodytag .= Apache::lonmenu::secondary_menu();
                   4751:             $bodytag .= Apache::lonmenu::serverform();
1.920     raeburn  4752:             $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
                   4753:             if ($env{'request.state'} eq 'construct') {
1.962     droeschl 4754:                 $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920     raeburn  4755:                                 $args->{'bread_crumbs'});
                   4756:             } elsif ($forcereg) { 
                   4757:                 $bodytag .= &Apache::lonmenu::innerregister($forcereg);
                   4758:             }
1.903     droeschl 4759:         }else{
                   4760:             # this is to seperate menu from content when there's no secondary
                   4761:             # menu. Especially needed for public accessible ressources.
                   4762:             $bodytag .= '<hr style="clear:both" />';
                   4763:             $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end'); 
1.235     raeburn  4764:         }
1.903     droeschl 4765: 
1.235     raeburn  4766:         return $bodytag;
1.182     matthew  4767: }
                   4768: 
1.917     raeburn  4769: sub dc_courseid_toggle {
                   4770:     my ($dc_info) = @_;
1.980     raeburn  4771:     return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.917     raeburn  4772:            '<a href="javascript:showCourseID();">'.
                   4773:            &mt('(More ...)').'</a></span>'.
                   4774:            '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
                   4775: }
                   4776: 
1.330     albertel 4777: sub make_attr_string {
                   4778:     my ($register,$attr_ref) = @_;
                   4779: 
                   4780:     if ($attr_ref && !ref($attr_ref)) {
                   4781: 	die("addentries Must be a hash ref ".
                   4782: 	    join(':',caller(1))." ".
                   4783: 	    join(':',caller(0))." ");
                   4784:     }
                   4785: 
                   4786:     if ($register) {
1.339     albertel 4787: 	my ($on_load,$on_unload);
                   4788: 	foreach my $key (keys(%{$attr_ref})) {
                   4789: 	    if      (lc($key) eq 'onload') {
                   4790: 		$on_load.=$attr_ref->{$key}.';';
                   4791: 		delete($attr_ref->{$key});
                   4792: 
                   4793: 	    } elsif (lc($key) eq 'onunload') {
                   4794: 		$on_unload.=$attr_ref->{$key}.';';
                   4795: 		delete($attr_ref->{$key});
                   4796: 	    }
                   4797: 	}
1.953     droeschl 4798: 	$attr_ref->{'onload'}  = $on_load;
                   4799: 	$attr_ref->{'onunload'}= $on_unload;
1.330     albertel 4800:     }
1.339     albertel 4801: 
1.330     albertel 4802:     my $attr_string;
                   4803:     foreach my $attr (keys(%$attr_ref)) {
                   4804: 	$attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
                   4805:     }
                   4806:     return $attr_string;
                   4807: }
                   4808: 
                   4809: 
1.182     matthew  4810: ###############################################
1.251     albertel 4811: ###############################################
                   4812: 
                   4813: =pod
                   4814: 
                   4815: =item * &endbodytag()
                   4816: 
                   4817: Returns a uniform footer for LON-CAPA web pages.
                   4818: 
1.635     raeburn  4819: Inputs: 1 - optional reference to an args hash
                   4820: If in the hash, key for noredirectlink has a value which evaluates to true,
                   4821: a 'Continue' link is not displayed if the page contains an
                   4822: internal redirect in the <head></head> section,
                   4823: i.e., $env{'internal.head.redirect'} exists   
1.251     albertel 4824: 
                   4825: =cut
                   4826: 
                   4827: sub endbodytag {
1.635     raeburn  4828:     my ($args) = @_;
1.251     albertel 4829:     my $endbodytag='</body>';
1.269     albertel 4830:     $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315     albertel 4831:     if ( exists( $env{'internal.head.redirect'} ) ) {
1.635     raeburn  4832:         if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
                   4833: 	    $endbodytag=
                   4834: 	        "<br /><a href=\"$env{'internal.head.redirect'}\">".
                   4835: 	        &mt('Continue').'</a>'.
                   4836: 	        $endbodytag;
                   4837:         }
1.315     albertel 4838:     }
1.251     albertel 4839:     return $endbodytag;
                   4840: }
                   4841: 
1.352     albertel 4842: =pod
                   4843: 
                   4844: =item * &standard_css()
                   4845: 
                   4846: Returns a style sheet
                   4847: 
                   4848: Inputs: (all optional)
                   4849:             domain         -> force to color decorate a page for a specific
                   4850:                                domain
                   4851:             function       -> force usage of a specific rolish color scheme
                   4852:             bgcolor        -> override the default page bgcolor
                   4853: 
                   4854: =cut
                   4855: 
1.343     albertel 4856: sub standard_css {
1.345     albertel 4857:     my ($function,$domain,$bgcolor) = @_;
1.352     albertel 4858:     $function  = &get_users_function() if (!$function);
                   4859:     my $img    = &designparm($function.'.img',   $domain);
                   4860:     my $tabbg  = &designparm($function.'.tabbg', $domain);
                   4861:     my $font   = &designparm($function.'.font',  $domain);
1.801     tempelho 4862:     my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791     tempelho 4863: #second colour for later usage
1.345     albertel 4864:     my $sidebg = &designparm($function.'.sidebg',$domain);
1.382     albertel 4865:     my $pgbg_or_bgcolor =
                   4866: 	         $bgcolor ||
1.352     albertel 4867: 	         &designparm($function.'.pgbg',  $domain);
1.382     albertel 4868:     my $pgbg   = &designparm($function.'.pgbg',  $domain);
1.352     albertel 4869:     my $alink  = &designparm($function.'.alink', $domain);
                   4870:     my $vlink  = &designparm($function.'.vlink', $domain);
                   4871:     my $link   = &designparm($function.'.link',  $domain);
                   4872: 
1.602     albertel 4873:     my $sans                 = 'Verdana,Arial,Helvetica,sans-serif';
1.395     albertel 4874:     my $mono                 = 'monospace';
1.850     bisitz   4875:     my $data_table_head      = $sidebg;
                   4876:     my $data_table_light     = '#FAFAFA';
                   4877:     my $data_table_dark      = '#F0F0F0';
1.470     banghart 4878:     my $data_table_darker    = '#CCCCCC';
1.349     albertel 4879:     my $data_table_highlight = '#FFFF00';
1.352     albertel 4880:     my $mail_new             = '#FFBB77';
                   4881:     my $mail_new_hover       = '#DD9955';
                   4882:     my $mail_read            = '#BBBB77';
                   4883:     my $mail_read_hover      = '#999944';
                   4884:     my $mail_replied         = '#AAAA88';
                   4885:     my $mail_replied_hover   = '#888855';
                   4886:     my $mail_other           = '#99BBBB';
                   4887:     my $mail_other_hover     = '#669999';
1.391     albertel 4888:     my $table_header         = '#DDDDDD';
1.489     raeburn  4889:     my $feedback_link_bg     = '#BBBBBB';
1.911     bisitz   4890:     my $lg_border_color      = '#C8C8C8';
1.952     onken    4891:     my $button_hover         = '#BF2317';
1.392     albertel 4892: 
1.608     albertel 4893:     my $border = ($env{'browser.type'} eq 'explorer' ||
1.911     bisitz   4894:       $env{'browser.type'} eq 'safari'     ) ? '0 2px 0 2px'
                   4895:                                              : '0 3px 0 4px';
1.448     albertel 4896: 
1.523     albertel 4897: 
1.343     albertel 4898:     return <<END;
1.947     droeschl 4899: 
                   4900: /* needed for iframe to allow 100% height in FF */
                   4901: body, html { 
                   4902:     margin: 0;
                   4903:     padding: 0 0.5%;
                   4904:     height: 99%; /* to avoid scrollbars */
                   4905: }
                   4906: 
1.795     www      4907: body {
1.911     bisitz   4908:   font-family: $sans;
                   4909:   line-height:130%;
                   4910:   font-size:0.83em;
                   4911:   color:$font;
1.795     www      4912: }
                   4913: 
1.959     onken    4914: a:focus,
                   4915: a:focus img {
1.795     www      4916:   color: red;
1.911     bisitz   4917:   background: yellow;
1.795     www      4918: }
1.698     harmsja  4919: 
1.911     bisitz   4920: form, .inline {
                   4921:   display: inline;
1.795     www      4922: }
1.721     harmsja  4923: 
1.795     www      4924: .LC_right {
1.911     bisitz   4925:   text-align:right;
1.795     www      4926: }
                   4927: 
                   4928: .LC_middle {
1.911     bisitz   4929:   vertical-align:middle;
1.795     www      4930: }
1.721     harmsja  4931: 
1.911     bisitz   4932: .LC_400Box {
                   4933:   width:400px;
                   4934: }
1.721     harmsja  4935: 
1.947     droeschl 4936: .LC_iframecontainer {
                   4937:     width: 98%;
                   4938:     margin: 0;
                   4939:     position: fixed;
                   4940:     top: 8.5em;
                   4941:     bottom: 0;
                   4942: }
                   4943: 
                   4944: .LC_iframecontainer iframe{
                   4945:     border: none;
                   4946:     width: 100%;
                   4947:     height: 100%;
                   4948: }
                   4949: 
1.778     bisitz   4950: .LC_filename {
                   4951:   font-family: $mono;
                   4952:   white-space:pre;
1.921     bisitz   4953:   font-size: 120%;
1.778     bisitz   4954: }
                   4955: 
                   4956: .LC_fileicon {
                   4957:   border: none;
                   4958:   height: 1.3em;
                   4959:   vertical-align: text-bottom;
                   4960:   margin-right: 0.3em;
                   4961:   text-decoration:none;
                   4962: }
                   4963: 
1.1008  ! www      4964: .LC_setting {
        !          4965:   text-decoration:underline;
        !          4966: }
        !          4967: 
1.350     albertel 4968: .LC_error {
                   4969:   color: red;
                   4970:   font-size: larger;
                   4971: }
1.795     www      4972: 
1.457     albertel 4973: .LC_warning,
                   4974: .LC_diff_removed {
1.733     bisitz   4975:   color: red;
1.394     albertel 4976: }
1.532     albertel 4977: 
                   4978: .LC_info,
1.457     albertel 4979: .LC_success,
                   4980: .LC_diff_added {
1.350     albertel 4981:   color: green;
                   4982: }
1.795     www      4983: 
1.802     bisitz   4984: div.LC_confirm_box {
                   4985:   background-color: #FAFAFA;
                   4986:   border: 1px solid $lg_border_color;
                   4987:   margin-right: 0;
                   4988:   padding: 5px;
                   4989: }
                   4990: 
                   4991: div.LC_confirm_box .LC_error img,
                   4992: div.LC_confirm_box .LC_success img {
                   4993:   vertical-align: middle;
                   4994: }
                   4995: 
1.440     albertel 4996: .LC_icon {
1.771     droeschl 4997:   border: none;
1.790     droeschl 4998:   vertical-align: middle;
1.771     droeschl 4999: }
                   5000: 
1.543     albertel 5001: .LC_docs_spacer {
                   5002:   width: 25px;
                   5003:   height: 1px;
1.771     droeschl 5004:   border: none;
1.543     albertel 5005: }
1.346     albertel 5006: 
1.532     albertel 5007: .LC_internal_info {
1.735     bisitz   5008:   color: #999999;
1.532     albertel 5009: }
                   5010: 
1.794     www      5011: .LC_discussion {
1.911     bisitz   5012:   background: $tabbg;
                   5013:   border: 1px solid black;
                   5014:   margin: 2px;
1.794     www      5015: }
                   5016: 
                   5017: .LC_disc_action_links_bar {
1.911     bisitz   5018:   background: $tabbg;
                   5019:   border: none;
                   5020:   margin: 4px;
1.794     www      5021: }
                   5022: 
                   5023: .LC_disc_action_left {
1.911     bisitz   5024:   text-align: left;
1.794     www      5025: }
                   5026: 
                   5027: .LC_disc_action_right {
1.911     bisitz   5028:   text-align: right;
1.794     www      5029: }
                   5030: 
                   5031: .LC_disc_new_item {
1.911     bisitz   5032:   background: white;
                   5033:   border: 2px solid red;
                   5034:   margin: 2px;
1.794     www      5035: }
                   5036: 
                   5037: .LC_disc_old_item {
1.911     bisitz   5038:   background: white;
                   5039:   border: 1px solid black;
                   5040:   margin: 2px;
1.794     www      5041: }
                   5042: 
1.458     albertel 5043: table.LC_pastsubmission {
                   5044:   border: 1px solid black;
                   5045:   margin: 2px;
                   5046: }
                   5047: 
1.924     bisitz   5048: table#LC_menubuttons {
1.345     albertel 5049:   width: 100%;
                   5050:   background: $pgbg;
1.392     albertel 5051:   border: 2px;
1.402     albertel 5052:   border-collapse: separate;
1.803     bisitz   5053:   padding: 0;
1.345     albertel 5054: }
1.392     albertel 5055: 
1.801     tempelho 5056: table#LC_title_bar a {
                   5057:   color: $fontmenu;
                   5058: }
1.836     bisitz   5059: 
1.807     droeschl 5060: table#LC_title_bar {
1.819     tempelho 5061:   clear: both;
1.836     bisitz   5062:   display: none;
1.807     droeschl 5063: }
                   5064: 
1.795     www      5065: table#LC_title_bar,
1.933     droeschl 5066: table.LC_breadcrumbs, /* obsolete? */
1.393     albertel 5067: table#LC_title_bar.LC_with_remote {
1.359     albertel 5068:   width: 100%;
1.392     albertel 5069:   border-color: $pgbg;
                   5070:   border-style: solid;
                   5071:   border-width: $border;
1.379     albertel 5072:   background: $pgbg;
1.801     tempelho 5073:   color: $fontmenu;
1.392     albertel 5074:   border-collapse: collapse;
1.803     bisitz   5075:   padding: 0;
1.819     tempelho 5076:   margin: 0;
1.359     albertel 5077: }
1.795     www      5078: 
1.933     droeschl 5079: ul.LC_breadcrumb_tools_outerlist {
1.913     droeschl 5080:     margin: 0;
                   5081:     padding: 0;
1.933     droeschl 5082:     position: relative;
                   5083:     list-style: none;
1.913     droeschl 5084: }
1.933     droeschl 5085: ul.LC_breadcrumb_tools_outerlist li {
1.913     droeschl 5086:     display: inline;
                   5087: }
1.933     droeschl 5088: 
                   5089: .LC_breadcrumb_tools_navigation {
1.913     droeschl 5090:     padding: 0;
1.933     droeschl 5091:     margin: 0;
                   5092:     float: left;
1.913     droeschl 5093: }
1.933     droeschl 5094: .LC_breadcrumb_tools_tools {
                   5095:     padding: 0;
                   5096:     margin: 0;
1.913     droeschl 5097:     float: right;
                   5098: }
                   5099: 
1.359     albertel 5100: table#LC_title_bar td {
                   5101:   background: $tabbg;
                   5102: }
1.795     www      5103: 
1.911     bisitz   5104: table#LC_menubuttons img {
1.803     bisitz   5105:   border: none;
1.346     albertel 5106: }
1.795     www      5107: 
1.842     droeschl 5108: .LC_breadcrumbs_component {
1.911     bisitz   5109:   float: right;
                   5110:   margin: 0 1em;
1.357     albertel 5111: }
1.842     droeschl 5112: .LC_breadcrumbs_component img {
1.911     bisitz   5113:   vertical-align: middle;
1.777     tempelho 5114: }
1.795     www      5115: 
1.383     albertel 5116: td.LC_table_cell_checkbox {
                   5117:   text-align: center;
                   5118: }
1.795     www      5119: 
                   5120: .LC_fontsize_small {
1.911     bisitz   5121:   font-size: 70%;
1.705     tempelho 5122: }
                   5123: 
1.844     bisitz   5124: #LC_breadcrumbs {
1.911     bisitz   5125:   clear:both;
                   5126:   background: $sidebg;
                   5127:   border-bottom: 1px solid $lg_border_color;
                   5128:   line-height: 2.5em;
1.933     droeschl 5129:   overflow: hidden;
1.911     bisitz   5130:   margin: 0;
                   5131:   padding: 0;
1.995     raeburn  5132:   text-align: left;
1.819     tempelho 5133: }
1.862     bisitz   5134: 
1.993     raeburn  5135: .LC_head_subbox {
1.911     bisitz   5136:   clear:both;
                   5137:   background: #F8F8F8; /* $sidebg; */
1.915     droeschl 5138:   border: 1px solid $sidebg;
                   5139:   margin: 0 0 10px 0;      
1.966     bisitz   5140:   padding: 3px;
1.995     raeburn  5141:   text-align: left;
1.822     bisitz   5142: }
                   5143: 
1.795     www      5144: .LC_fontsize_medium {
1.911     bisitz   5145:   font-size: 85%;
1.705     tempelho 5146: }
                   5147: 
1.795     www      5148: .LC_fontsize_large {
1.911     bisitz   5149:   font-size: 120%;
1.705     tempelho 5150: }
                   5151: 
1.346     albertel 5152: .LC_menubuttons_inline_text {
                   5153:   color: $font;
1.698     harmsja  5154:   font-size: 90%;
1.701     harmsja  5155:   padding-left:3px;
1.346     albertel 5156: }
                   5157: 
1.934     droeschl 5158: .LC_menubuttons_inline_text img{
                   5159:   vertical-align: middle;
                   5160: }
                   5161: 
1.951     onken    5162: li.LC_menubuttons_inline_text img,a {
                   5163:   cursor:pointer;
1.1002    droeschl 5164:   text-decoration: none;
1.951     onken    5165: }
                   5166: 
1.526     www      5167: .LC_menubuttons_link {
                   5168:   text-decoration: none;
                   5169: }
1.795     www      5170: 
1.522     albertel 5171: .LC_menubuttons_category {
1.521     www      5172:   color: $font;
1.526     www      5173:   background: $pgbg;
1.521     www      5174:   font-size: larger;
                   5175:   font-weight: bold;
                   5176: }
                   5177: 
1.346     albertel 5178: td.LC_menubuttons_text {
1.911     bisitz   5179:   color: $font;
1.346     albertel 5180: }
1.706     harmsja  5181: 
1.346     albertel 5182: .LC_current_location {
                   5183:   background: $tabbg;
                   5184: }
1.795     www      5185: 
1.938     bisitz   5186: table.LC_data_table {
1.347     albertel 5187:   border: 1px solid #000000;
1.402     albertel 5188:   border-collapse: separate;
1.426     albertel 5189:   border-spacing: 1px;
1.610     albertel 5190:   background: $pgbg;
1.347     albertel 5191: }
1.795     www      5192: 
1.422     albertel 5193: .LC_data_table_dense {
                   5194:   font-size: small;
                   5195: }
1.795     www      5196: 
1.507     raeburn  5197: table.LC_nested_outer {
                   5198:   border: 1px solid #000000;
1.589     raeburn  5199:   border-collapse: collapse;
1.803     bisitz   5200:   border-spacing: 0;
1.507     raeburn  5201:   width: 100%;
                   5202: }
1.795     www      5203: 
1.879     raeburn  5204: table.LC_innerpickbox,
1.507     raeburn  5205: table.LC_nested {
1.803     bisitz   5206:   border: none;
1.589     raeburn  5207:   border-collapse: collapse;
1.803     bisitz   5208:   border-spacing: 0;
1.507     raeburn  5209:   width: 100%;
                   5210: }
1.795     www      5211: 
1.930     faziophi 5212: .ui-accordion,
                   5213: .ui-accordion table.LC_data_table,
                   5214: .ui-accordion table.LC_nested_outer{
                   5215:   border: 0px;
                   5216:   border-spacing: 0px;
                   5217:   margin: 3px;
                   5218: }
                   5219: 
1.911     bisitz   5220: table.LC_data_table tr th,
                   5221: table.LC_calendar tr th,
1.879     raeburn  5222: table.LC_prior_tries tr th,
                   5223: table.LC_innerpickbox tr th {
1.349     albertel 5224:   font-weight: bold;
                   5225:   background-color: $data_table_head;
1.801     tempelho 5226:   color:$fontmenu;
1.701     harmsja  5227:   font-size:90%;
1.347     albertel 5228: }
1.795     www      5229: 
1.879     raeburn  5230: table.LC_innerpickbox tr th,
                   5231: table.LC_innerpickbox tr td {
                   5232:   vertical-align: top;
                   5233: }
                   5234: 
1.711     raeburn  5235: table.LC_data_table tr.LC_info_row > td {
1.735     bisitz   5236:   background-color: #CCCCCC;
1.711     raeburn  5237:   font-weight: bold;
                   5238:   text-align: left;
                   5239: }
1.795     www      5240: 
1.912     bisitz   5241: table.LC_data_table tr.LC_odd_row > td {
                   5242:   background-color: $data_table_light;
                   5243:   padding: 2px;
                   5244:   vertical-align: top;
                   5245: }
                   5246: 
1.809     bisitz   5247: table.LC_pick_box tr > td.LC_odd_row {
1.349     albertel 5248:   background-color: $data_table_light;
1.912     bisitz   5249:   vertical-align: top;
                   5250: }
                   5251: 
                   5252: table.LC_data_table tr.LC_even_row > td {
                   5253:   background-color: $data_table_dark;
1.425     albertel 5254:   padding: 2px;
1.900     bisitz   5255:   vertical-align: top;
1.347     albertel 5256: }
1.795     www      5257: 
1.809     bisitz   5258: table.LC_pick_box tr > td.LC_even_row {
1.349     albertel 5259:   background-color: $data_table_dark;
1.900     bisitz   5260:   vertical-align: top;
1.347     albertel 5261: }
1.795     www      5262: 
1.425     albertel 5263: table.LC_data_table tr.LC_data_table_highlight td {
                   5264:   background-color: $data_table_darker;
                   5265: }
1.795     www      5266: 
1.639     raeburn  5267: table.LC_data_table tr td.LC_leftcol_header {
                   5268:   background-color: $data_table_head;
                   5269:   font-weight: bold;
                   5270: }
1.795     www      5271: 
1.451     albertel 5272: table.LC_data_table tr.LC_empty_row td,
1.507     raeburn  5273: table.LC_nested tr.LC_empty_row td {
1.421     albertel 5274:   font-weight: bold;
                   5275:   font-style: italic;
                   5276:   text-align: center;
                   5277:   padding: 8px;
1.347     albertel 5278: }
1.795     www      5279: 
1.940     bisitz   5280: table.LC_data_table tr.LC_empty_row td {
                   5281:   background-color: $sidebg;
                   5282: }
                   5283: 
                   5284: table.LC_nested tr.LC_empty_row td {
                   5285:   background-color: #FFFFFF;
                   5286: }
                   5287: 
1.890     droeschl 5288: table.LC_caption {
                   5289: }
                   5290: 
1.507     raeburn  5291: table.LC_nested tr.LC_empty_row td {
1.465     albertel 5292:   padding: 4ex
                   5293: }
1.795     www      5294: 
1.507     raeburn  5295: table.LC_nested_outer tr th {
                   5296:   font-weight: bold;
1.801     tempelho 5297:   color:$fontmenu;
1.507     raeburn  5298:   background-color: $data_table_head;
1.701     harmsja  5299:   font-size: small;
1.507     raeburn  5300:   border-bottom: 1px solid #000000;
                   5301: }
1.795     www      5302: 
1.507     raeburn  5303: table.LC_nested_outer tr td.LC_subheader {
                   5304:   background-color: $data_table_head;
                   5305:   font-weight: bold;
                   5306:   font-size: small;
                   5307:   border-bottom: 1px solid #000000;
                   5308:   text-align: right;
1.451     albertel 5309: }
1.795     www      5310: 
1.507     raeburn  5311: table.LC_nested tr.LC_info_row td {
1.735     bisitz   5312:   background-color: #CCCCCC;
1.451     albertel 5313:   font-weight: bold;
                   5314:   font-size: small;
1.507     raeburn  5315:   text-align: center;
                   5316: }
1.795     www      5317: 
1.589     raeburn  5318: table.LC_nested tr.LC_info_row td.LC_left_item,
                   5319: table.LC_nested_outer tr th.LC_left_item {
1.507     raeburn  5320:   text-align: left;
1.451     albertel 5321: }
1.795     www      5322: 
1.507     raeburn  5323: table.LC_nested td {
1.735     bisitz   5324:   background-color: #FFFFFF;
1.451     albertel 5325:   font-size: small;
1.507     raeburn  5326: }
1.795     www      5327: 
1.507     raeburn  5328: table.LC_nested_outer tr th.LC_right_item,
                   5329: table.LC_nested tr.LC_info_row td.LC_right_item,
                   5330: table.LC_nested tr.LC_odd_row td.LC_right_item,
                   5331: table.LC_nested tr td.LC_right_item {
1.451     albertel 5332:   text-align: right;
                   5333: }
                   5334: 
1.930     faziophi 5335: .ui-accordion table.LC_nested tr.LC_odd_row td.LC_left_item,
                   5336: .ui-accordion table.LC_nested tr.LC_even_row td.LC_left_item {
                   5337:   text-align: right;
                   5338:   width: 40%;
                   5339:   padding-right:10px;
                   5340:   vertical-align: top;
                   5341:   padding: 5px;
                   5342: }
                   5343: 
                   5344: .ui-accordion table.LC_nested tr.LC_odd_row td.LC_right_item,
                   5345: .ui-accordion table.LC_nested tr.LC_even_row td.LC_right_item {
                   5346:   text-align: left;
                   5347:   width: 60%;
                   5348:   padding: 2px 4px;
                   5349: }
                   5350: 
1.507     raeburn  5351: table.LC_nested tr.LC_odd_row td {
1.735     bisitz   5352:   background-color: #EEEEEE;
1.451     albertel 5353: }
                   5354: 
1.473     raeburn  5355: table.LC_createuser {
                   5356: }
                   5357: 
                   5358: table.LC_createuser tr.LC_section_row td {
1.701     harmsja  5359:   font-size: small;
1.473     raeburn  5360: }
                   5361: 
                   5362: table.LC_createuser tr.LC_info_row td  {
1.735     bisitz   5363:   background-color: #CCCCCC;
1.473     raeburn  5364:   font-weight: bold;
                   5365:   text-align: center;
                   5366: }
                   5367: 
1.349     albertel 5368: table.LC_calendar {
                   5369:   border: 1px solid #000000;
                   5370:   border-collapse: collapse;
1.917     raeburn  5371:   width: 98%;
1.349     albertel 5372: }
1.795     www      5373: 
1.349     albertel 5374: table.LC_calendar_pickdate {
                   5375:   font-size: xx-small;
                   5376: }
1.795     www      5377: 
1.349     albertel 5378: table.LC_calendar tr td {
                   5379:   border: 1px solid #000000;
                   5380:   vertical-align: top;
1.917     raeburn  5381:   width: 14%;
1.349     albertel 5382: }
1.795     www      5383: 
1.349     albertel 5384: table.LC_calendar tr td.LC_calendar_day_empty {
                   5385:   background-color: $data_table_dark;
                   5386: }
1.795     www      5387: 
1.779     bisitz   5388: table.LC_calendar tr td.LC_calendar_day_current {
                   5389:   background-color: $data_table_highlight;
1.777     tempelho 5390: }
1.795     www      5391: 
1.938     bisitz   5392: table.LC_data_table tr td.LC_mail_new {
1.349     albertel 5393:   background-color: $mail_new;
                   5394: }
1.795     www      5395: 
1.938     bisitz   5396: table.LC_data_table tr.LC_mail_new:hover {
1.349     albertel 5397:   background-color: $mail_new_hover;
                   5398: }
1.795     www      5399: 
1.938     bisitz   5400: table.LC_data_table tr td.LC_mail_read {
1.349     albertel 5401:   background-color: $mail_read;
                   5402: }
1.795     www      5403: 
1.938     bisitz   5404: /*
                   5405: table.LC_data_table tr.LC_mail_read:hover {
1.349     albertel 5406:   background-color: $mail_read_hover;
                   5407: }
1.938     bisitz   5408: */
1.795     www      5409: 
1.938     bisitz   5410: table.LC_data_table tr td.LC_mail_replied {
1.349     albertel 5411:   background-color: $mail_replied;
                   5412: }
1.795     www      5413: 
1.938     bisitz   5414: /*
                   5415: table.LC_data_table tr.LC_mail_replied:hover {
1.349     albertel 5416:   background-color: $mail_replied_hover;
                   5417: }
1.938     bisitz   5418: */
1.795     www      5419: 
1.938     bisitz   5420: table.LC_data_table tr td.LC_mail_other {
1.349     albertel 5421:   background-color: $mail_other;
                   5422: }
1.795     www      5423: 
1.938     bisitz   5424: /*
                   5425: table.LC_data_table tr.LC_mail_other:hover {
1.349     albertel 5426:   background-color: $mail_other_hover;
                   5427: }
1.938     bisitz   5428: */
1.494     raeburn  5429: 
1.777     tempelho 5430: table.LC_data_table tr > td.LC_browser_file,
                   5431: table.LC_data_table tr > td.LC_browser_file_published {
1.899     bisitz   5432:   background: #AAEE77;
1.389     albertel 5433: }
1.795     www      5434: 
1.777     tempelho 5435: table.LC_data_table tr > td.LC_browser_file_locked,
                   5436: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389     albertel 5437:   background: #FFAA99;
1.387     albertel 5438: }
1.795     www      5439: 
1.777     tempelho 5440: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899     bisitz   5441:   background: #888888;
1.779     bisitz   5442: }
1.795     www      5443: 
1.777     tempelho 5444: table.LC_data_table tr > td.LC_browser_file_modified,
1.779     bisitz   5445: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899     bisitz   5446:   background: #F8F866;
1.777     tempelho 5447: }
1.795     www      5448: 
1.696     bisitz   5449: table.LC_data_table tr.LC_browser_folder > td {
1.899     bisitz   5450:   background: #E0E8FF;
1.387     albertel 5451: }
1.696     bisitz   5452: 
1.707     bisitz   5453: table.LC_data_table tr > td.LC_roles_is {
1.911     bisitz   5454:   /* background: #77FF77; */
1.707     bisitz   5455: }
1.795     www      5456: 
1.707     bisitz   5457: table.LC_data_table tr > td.LC_roles_future {
1.939     bisitz   5458:   border-right: 8px solid #FFFF77;
1.707     bisitz   5459: }
1.795     www      5460: 
1.707     bisitz   5461: table.LC_data_table tr > td.LC_roles_will {
1.939     bisitz   5462:   border-right: 8px solid #FFAA77;
1.707     bisitz   5463: }
1.795     www      5464: 
1.707     bisitz   5465: table.LC_data_table tr > td.LC_roles_expired {
1.939     bisitz   5466:   border-right: 8px solid #FF7777;
1.707     bisitz   5467: }
1.795     www      5468: 
1.707     bisitz   5469: table.LC_data_table tr > td.LC_roles_will_not {
1.939     bisitz   5470:   border-right: 8px solid #AAFF77;
1.707     bisitz   5471: }
1.795     www      5472: 
1.707     bisitz   5473: table.LC_data_table tr > td.LC_roles_selected {
1.939     bisitz   5474:   border-right: 8px solid #11CC55;
1.707     bisitz   5475: }
                   5476: 
1.388     albertel 5477: span.LC_current_location {
1.701     harmsja  5478:   font-size:larger;
1.388     albertel 5479:   background: $pgbg;
                   5480: }
1.387     albertel 5481: 
1.395     albertel 5482: span.LC_parm_menu_item {
                   5483:   font-size: larger;
                   5484: }
1.795     www      5485: 
1.395     albertel 5486: span.LC_parm_scope_all {
                   5487:   color: red;
                   5488: }
1.795     www      5489: 
1.395     albertel 5490: span.LC_parm_scope_folder {
                   5491:   color: green;
                   5492: }
1.795     www      5493: 
1.395     albertel 5494: span.LC_parm_scope_resource {
                   5495:   color: orange;
                   5496: }
1.795     www      5497: 
1.395     albertel 5498: span.LC_parm_part {
                   5499:   color: blue;
                   5500: }
1.795     www      5501: 
1.911     bisitz   5502: span.LC_parm_folder,
                   5503: span.LC_parm_symb {
1.395     albertel 5504:   font-size: x-small;
                   5505:   font-family: $mono;
                   5506:   color: #AAAAAA;
                   5507: }
                   5508: 
1.977     bisitz   5509: ul.LC_parm_parmlist li {
                   5510:   display: inline-block;
                   5511:   padding: 0.3em 0.8em;
                   5512:   vertical-align: top;
                   5513:   width: 150px;
                   5514:   border-top:1px solid $lg_border_color;
                   5515: }
                   5516: 
1.795     www      5517: td.LC_parm_overview_level_menu,
                   5518: td.LC_parm_overview_map_menu,
                   5519: td.LC_parm_overview_parm_selectors,
                   5520: td.LC_parm_overview_restrictions  {
1.396     albertel 5521:   border: 1px solid black;
                   5522:   border-collapse: collapse;
                   5523: }
1.795     www      5524: 
1.396     albertel 5525: table.LC_parm_overview_restrictions td {
                   5526:   border-width: 1px 4px 1px 4px;
                   5527:   border-style: solid;
                   5528:   border-color: $pgbg;
                   5529:   text-align: center;
                   5530: }
1.795     www      5531: 
1.396     albertel 5532: table.LC_parm_overview_restrictions th {
                   5533:   background: $tabbg;
                   5534:   border-width: 1px 4px 1px 4px;
                   5535:   border-style: solid;
                   5536:   border-color: $pgbg;
                   5537: }
1.795     www      5538: 
1.398     albertel 5539: table#LC_helpmenu {
1.803     bisitz   5540:   border: none;
1.398     albertel 5541:   height: 55px;
1.803     bisitz   5542:   border-spacing: 0;
1.398     albertel 5543: }
                   5544: 
                   5545: table#LC_helpmenu fieldset legend {
                   5546:   font-size: larger;
                   5547: }
1.795     www      5548: 
1.397     albertel 5549: table#LC_helpmenu_links {
                   5550:   width: 100%;
                   5551:   border: 1px solid black;
                   5552:   background: $pgbg;
1.803     bisitz   5553:   padding: 0;
1.397     albertel 5554:   border-spacing: 1px;
                   5555: }
1.795     www      5556: 
1.397     albertel 5557: table#LC_helpmenu_links tr td {
                   5558:   padding: 1px;
                   5559:   background: $tabbg;
1.399     albertel 5560:   text-align: center;
                   5561:   font-weight: bold;
1.397     albertel 5562: }
1.396     albertel 5563: 
1.795     www      5564: table#LC_helpmenu_links a:link,
                   5565: table#LC_helpmenu_links a:visited,
1.397     albertel 5566: table#LC_helpmenu_links a:active {
                   5567:   text-decoration: none;
                   5568:   color: $font;
                   5569: }
1.795     www      5570: 
1.397     albertel 5571: table#LC_helpmenu_links a:hover {
                   5572:   text-decoration: underline;
                   5573:   color: $vlink;
                   5574: }
1.396     albertel 5575: 
1.417     albertel 5576: .LC_chrt_popup_exists {
                   5577:   border: 1px solid #339933;
                   5578:   margin: -1px;
                   5579: }
1.795     www      5580: 
1.417     albertel 5581: .LC_chrt_popup_up {
                   5582:   border: 1px solid yellow;
                   5583:   margin: -1px;
                   5584: }
1.795     www      5585: 
1.417     albertel 5586: .LC_chrt_popup {
                   5587:   border: 1px solid #8888FF;
                   5588:   background: #CCCCFF;
                   5589: }
1.795     www      5590: 
1.421     albertel 5591: table.LC_pick_box {
                   5592:   border-collapse: separate;
                   5593:   background: white;
                   5594:   border: 1px solid black;
                   5595:   border-spacing: 1px;
                   5596: }
1.795     www      5597: 
1.421     albertel 5598: table.LC_pick_box td.LC_pick_box_title {
1.850     bisitz   5599:   background: $sidebg;
1.421     albertel 5600:   font-weight: bold;
1.900     bisitz   5601:   text-align: left;
1.740     bisitz   5602:   vertical-align: top;
1.421     albertel 5603:   width: 184px;
                   5604:   padding: 8px;
                   5605: }
1.795     www      5606: 
1.579     raeburn  5607: table.LC_pick_box td.LC_pick_box_value {
                   5608:   text-align: left;
                   5609:   padding: 8px;
                   5610: }
1.795     www      5611: 
1.579     raeburn  5612: table.LC_pick_box td.LC_pick_box_select {
                   5613:   text-align: left;
                   5614:   padding: 8px;
                   5615: }
1.795     www      5616: 
1.424     albertel 5617: table.LC_pick_box td.LC_pick_box_separator {
1.803     bisitz   5618:   padding: 0;
1.421     albertel 5619:   height: 1px;
                   5620:   background: black;
                   5621: }
1.795     www      5622: 
1.421     albertel 5623: table.LC_pick_box td.LC_pick_box_submit {
                   5624:   text-align: right;
                   5625: }
1.795     www      5626: 
1.579     raeburn  5627: table.LC_pick_box td.LC_evenrow_value {
                   5628:   text-align: left;
                   5629:   padding: 8px;
                   5630:   background-color: $data_table_light;
                   5631: }
1.795     www      5632: 
1.579     raeburn  5633: table.LC_pick_box td.LC_oddrow_value {
                   5634:   text-align: left;
                   5635:   padding: 8px;
                   5636:   background-color: $data_table_light;
                   5637: }
1.795     www      5638: 
1.579     raeburn  5639: span.LC_helpform_receipt_cat {
                   5640:   font-weight: bold;
                   5641: }
1.795     www      5642: 
1.424     albertel 5643: table.LC_group_priv_box {
                   5644:   background: white;
                   5645:   border: 1px solid black;
                   5646:   border-spacing: 1px;
                   5647: }
1.795     www      5648: 
1.424     albertel 5649: table.LC_group_priv_box td.LC_pick_box_title {
                   5650:   background: $tabbg;
                   5651:   font-weight: bold;
                   5652:   text-align: right;
                   5653:   width: 184px;
                   5654: }
1.795     www      5655: 
1.424     albertel 5656: table.LC_group_priv_box td.LC_groups_fixed {
                   5657:   background: $data_table_light;
                   5658:   text-align: center;
                   5659: }
1.795     www      5660: 
1.424     albertel 5661: table.LC_group_priv_box td.LC_groups_optional {
                   5662:   background: $data_table_dark;
                   5663:   text-align: center;
                   5664: }
1.795     www      5665: 
1.424     albertel 5666: table.LC_group_priv_box td.LC_groups_functionality {
                   5667:   background: $data_table_darker;
                   5668:   text-align: center;
                   5669:   font-weight: bold;
                   5670: }
1.795     www      5671: 
1.424     albertel 5672: table.LC_group_priv td {
                   5673:   text-align: left;
1.803     bisitz   5674:   padding: 0;
1.424     albertel 5675: }
                   5676: 
                   5677: .LC_navbuttons {
                   5678:   margin: 2ex 0ex 2ex 0ex;
                   5679: }
1.795     www      5680: 
1.423     albertel 5681: .LC_topic_bar {
                   5682:   font-weight: bold;
                   5683:   background: $tabbg;
1.918     wenzelju 5684:   margin: 1em 0em 1em 2em;
1.805     bisitz   5685:   padding: 3px;
1.918     wenzelju 5686:   font-size: 1.2em;
1.423     albertel 5687: }
1.795     www      5688: 
1.423     albertel 5689: .LC_topic_bar span {
1.918     wenzelju 5690:   left: 0.5em;
                   5691:   position: absolute;
1.423     albertel 5692:   vertical-align: middle;
1.918     wenzelju 5693:   font-size: 1.2em;
1.423     albertel 5694: }
1.795     www      5695: 
1.423     albertel 5696: table.LC_course_group_status {
                   5697:   margin: 20px;
                   5698: }
1.795     www      5699: 
1.423     albertel 5700: table.LC_status_selector td {
                   5701:   vertical-align: top;
                   5702:   text-align: center;
1.424     albertel 5703:   padding: 4px;
                   5704: }
1.795     www      5705: 
1.599     albertel 5706: div.LC_feedback_link {
1.616     albertel 5707:   clear: both;
1.829     kalberla 5708:   background: $sidebg;
1.779     bisitz   5709:   width: 100%;
1.829     kalberla 5710:   padding-bottom: 10px;
                   5711:   border: 1px $tabbg solid;
1.833     kalberla 5712:   height: 22px;
                   5713:   line-height: 22px;
                   5714:   padding-top: 5px;
                   5715: }
                   5716: 
                   5717: div.LC_feedback_link img {
                   5718:   height: 22px;
1.867     kalberla 5719:   vertical-align:middle;
1.829     kalberla 5720: }
                   5721: 
1.911     bisitz   5722: div.LC_feedback_link a {
1.829     kalberla 5723:   text-decoration: none;
1.489     raeburn  5724: }
1.795     www      5725: 
1.867     kalberla 5726: div.LC_comblock {
1.911     bisitz   5727:   display:inline;
1.867     kalberla 5728:   color:$font;
                   5729:   font-size:90%;
                   5730: }
                   5731: 
                   5732: div.LC_feedback_link div.LC_comblock {
                   5733:   padding-left:5px;
                   5734: }
                   5735: 
                   5736: div.LC_feedback_link div.LC_comblock a {
                   5737:   color:$font;
                   5738: }
                   5739: 
1.489     raeburn  5740: span.LC_feedback_link {
1.858     bisitz   5741:   /* background: $feedback_link_bg; */
1.599     albertel 5742:   font-size: larger;
                   5743: }
1.795     www      5744: 
1.599     albertel 5745: span.LC_message_link {
1.858     bisitz   5746:   /* background: $feedback_link_bg; */
1.599     albertel 5747:   font-size: larger;
                   5748:   position: absolute;
                   5749:   right: 1em;
1.489     raeburn  5750: }
1.421     albertel 5751: 
1.515     albertel 5752: table.LC_prior_tries {
1.524     albertel 5753:   border: 1px solid #000000;
                   5754:   border-collapse: separate;
                   5755:   border-spacing: 1px;
1.515     albertel 5756: }
1.523     albertel 5757: 
1.515     albertel 5758: table.LC_prior_tries td {
1.524     albertel 5759:   padding: 2px;
1.515     albertel 5760: }
1.523     albertel 5761: 
                   5762: .LC_answer_correct {
1.795     www      5763:   background: lightgreen;
                   5764:   color: darkgreen;
                   5765:   padding: 6px;
1.523     albertel 5766: }
1.795     www      5767: 
1.523     albertel 5768: .LC_answer_charged_try {
1.797     www      5769:   background: #FFAAAA;
1.795     www      5770:   color: darkred;
                   5771:   padding: 6px;
1.523     albertel 5772: }
1.795     www      5773: 
1.779     bisitz   5774: .LC_answer_not_charged_try,
1.523     albertel 5775: .LC_answer_no_grade,
                   5776: .LC_answer_late {
1.795     www      5777:   background: lightyellow;
1.523     albertel 5778:   color: black;
1.795     www      5779:   padding: 6px;
1.523     albertel 5780: }
1.795     www      5781: 
1.523     albertel 5782: .LC_answer_previous {
1.795     www      5783:   background: lightblue;
                   5784:   color: darkblue;
                   5785:   padding: 6px;
1.523     albertel 5786: }
1.795     www      5787: 
1.779     bisitz   5788: .LC_answer_no_message {
1.777     tempelho 5789:   background: #FFFFFF;
                   5790:   color: black;
1.795     www      5791:   padding: 6px;
1.779     bisitz   5792: }
1.795     www      5793: 
1.779     bisitz   5794: .LC_answer_unknown {
                   5795:   background: orange;
                   5796:   color: black;
1.795     www      5797:   padding: 6px;
1.777     tempelho 5798: }
1.795     www      5799: 
1.529     albertel 5800: span.LC_prior_numerical,
                   5801: span.LC_prior_string,
                   5802: span.LC_prior_custom,
                   5803: span.LC_prior_reaction,
                   5804: span.LC_prior_math {
1.925     bisitz   5805:   font-family: $mono;
1.523     albertel 5806:   white-space: pre;
                   5807: }
                   5808: 
1.525     albertel 5809: span.LC_prior_string {
1.925     bisitz   5810:   font-family: $mono;
1.525     albertel 5811:   white-space: pre;
                   5812: }
                   5813: 
1.523     albertel 5814: table.LC_prior_option {
                   5815:   width: 100%;
                   5816:   border-collapse: collapse;
                   5817: }
1.795     www      5818: 
1.911     bisitz   5819: table.LC_prior_rank,
1.795     www      5820: table.LC_prior_match {
1.528     albertel 5821:   border-collapse: collapse;
                   5822: }
1.795     www      5823: 
1.528     albertel 5824: table.LC_prior_option tr td,
                   5825: table.LC_prior_rank tr td,
                   5826: table.LC_prior_match tr td {
1.524     albertel 5827:   border: 1px solid #000000;
1.515     albertel 5828: }
                   5829: 
1.855     bisitz   5830: .LC_nobreak {
1.544     albertel 5831:   white-space: nowrap;
1.519     raeburn  5832: }
                   5833: 
1.576     raeburn  5834: span.LC_cusr_emph {
                   5835:   font-style: italic;
                   5836: }
                   5837: 
1.633     raeburn  5838: span.LC_cusr_subheading {
                   5839:   font-weight: normal;
                   5840:   font-size: 85%;
                   5841: }
                   5842: 
1.861     bisitz   5843: div.LC_docs_entry_move {
1.859     bisitz   5844:   border: 1px solid #BBBBBB;
1.545     albertel 5845:   background: #DDDDDD;
1.861     bisitz   5846:   width: 22px;
1.859     bisitz   5847:   padding: 1px;
                   5848:   margin: 0;
1.545     albertel 5849: }
                   5850: 
1.861     bisitz   5851: table.LC_data_table tr > td.LC_docs_entry_commands,
                   5852: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545     albertel 5853:   background: #DDDDDD;
                   5854:   font-size: x-small;
                   5855: }
1.795     www      5856: 
1.861     bisitz   5857: .LC_docs_entry_parameter {
                   5858:   white-space: nowrap;
                   5859: }
                   5860: 
1.544     albertel 5861: .LC_docs_copy {
1.545     albertel 5862:   color: #000099;
1.544     albertel 5863: }
1.795     www      5864: 
1.544     albertel 5865: .LC_docs_cut {
1.545     albertel 5866:   color: #550044;
1.544     albertel 5867: }
1.795     www      5868: 
1.544     albertel 5869: .LC_docs_rename {
1.545     albertel 5870:   color: #009900;
1.544     albertel 5871: }
1.795     www      5872: 
1.544     albertel 5873: .LC_docs_remove {
1.545     albertel 5874:   color: #990000;
                   5875: }
                   5876: 
1.547     albertel 5877: .LC_docs_reinit_warn,
                   5878: .LC_docs_ext_edit {
                   5879:   font-size: x-small;
                   5880: }
                   5881: 
1.545     albertel 5882: table.LC_docs_adddocs td,
                   5883: table.LC_docs_adddocs th {
                   5884:   border: 1px solid #BBBBBB;
                   5885:   padding: 4px;
                   5886:   background: #DDDDDD;
1.543     albertel 5887: }
                   5888: 
1.584     albertel 5889: table.LC_sty_begin {
                   5890:   background: #BBFFBB;
                   5891: }
1.795     www      5892: 
1.584     albertel 5893: table.LC_sty_end {
                   5894:   background: #FFBBBB;
                   5895: }
                   5896: 
1.589     raeburn  5897: table.LC_double_column {
1.803     bisitz   5898:   border-width: 0;
1.589     raeburn  5899:   border-collapse: collapse;
                   5900:   width: 100%;
                   5901:   padding: 2px;
                   5902: }
                   5903: 
                   5904: table.LC_double_column tr td.LC_left_col {
1.590     raeburn  5905:   top: 2px;
1.589     raeburn  5906:   left: 2px;
                   5907:   width: 47%;
                   5908:   vertical-align: top;
                   5909: }
                   5910: 
                   5911: table.LC_double_column tr td.LC_right_col {
                   5912:   top: 2px;
1.779     bisitz   5913:   right: 2px;
1.589     raeburn  5914:   width: 47%;
                   5915:   vertical-align: top;
                   5916: }
                   5917: 
1.591     raeburn  5918: div.LC_left_float {
                   5919:   float: left;
                   5920:   padding-right: 5%;
1.597     albertel 5921:   padding-bottom: 4px;
1.591     raeburn  5922: }
                   5923: 
                   5924: div.LC_clear_float_header {
1.597     albertel 5925:   padding-bottom: 2px;
1.591     raeburn  5926: }
                   5927: 
                   5928: div.LC_clear_float_footer {
1.597     albertel 5929:   padding-top: 10px;
1.591     raeburn  5930:   clear: both;
                   5931: }
                   5932: 
1.597     albertel 5933: div.LC_grade_show_user {
1.941     bisitz   5934: /*  border-left: 5px solid $sidebg; */
                   5935:   border-top: 5px solid #000000;
                   5936:   margin: 50px 0 0 0;
1.936     bisitz   5937:   padding: 15px 0 5px 10px;
1.597     albertel 5938: }
1.795     www      5939: 
1.936     bisitz   5940: div.LC_grade_show_user_odd_row {
1.941     bisitz   5941: /*  border-left: 5px solid #000000; */
                   5942: }
                   5943: 
                   5944: div.LC_grade_show_user div.LC_Box {
                   5945:   margin-right: 50px;
1.597     albertel 5946: }
                   5947: 
                   5948: div.LC_grade_submissions,
                   5949: div.LC_grade_message_center,
1.936     bisitz   5950: div.LC_grade_info_links {
1.597     albertel 5951:   margin: 5px;
                   5952:   width: 99%;
                   5953:   background: #FFFFFF;
                   5954: }
1.795     www      5955: 
1.597     albertel 5956: div.LC_grade_submissions_header,
1.936     bisitz   5957: div.LC_grade_message_center_header {
1.705     tempelho 5958:   font-weight: bold;
                   5959:   font-size: large;
1.597     albertel 5960: }
1.795     www      5961: 
1.597     albertel 5962: div.LC_grade_submissions_body,
1.936     bisitz   5963: div.LC_grade_message_center_body {
1.597     albertel 5964:   border: 1px solid black;
                   5965:   width: 99%;
                   5966:   background: #FFFFFF;
                   5967: }
1.795     www      5968: 
1.613     albertel 5969: table.LC_scantron_action {
                   5970:   width: 100%;
                   5971: }
1.795     www      5972: 
1.613     albertel 5973: table.LC_scantron_action tr th {
1.698     harmsja  5974:   font-weight:bold;
                   5975:   font-style:normal;
1.613     albertel 5976: }
1.795     www      5977: 
1.779     bisitz   5978: .LC_edit_problem_header,
1.614     albertel 5979: div.LC_edit_problem_footer {
1.705     tempelho 5980:   font-weight: normal;
                   5981:   font-size:  medium;
1.602     albertel 5982:   margin: 2px;
1.600     albertel 5983: }
1.795     www      5984: 
1.600     albertel 5985: div.LC_edit_problem_header,
1.602     albertel 5986: div.LC_edit_problem_header div,
1.614     albertel 5987: div.LC_edit_problem_footer,
                   5988: div.LC_edit_problem_footer div,
1.602     albertel 5989: div.LC_edit_problem_editxml_header,
                   5990: div.LC_edit_problem_editxml_header div {
1.600     albertel 5991:   margin-top: 5px;
                   5992: }
1.795     www      5993: 
1.600     albertel 5994: div.LC_edit_problem_header_title {
1.705     tempelho 5995:   font-weight: bold;
                   5996:   font-size: larger;
1.602     albertel 5997:   background: $tabbg;
                   5998:   padding: 3px;
                   5999: }
1.795     www      6000: 
1.602     albertel 6001: table.LC_edit_problem_header_title {
                   6002:   width: 100%;
1.600     albertel 6003:   background: $tabbg;
1.602     albertel 6004: }
                   6005: 
                   6006: div.LC_edit_problem_discards {
                   6007:   float: left;
                   6008:   padding-bottom: 5px;
                   6009: }
1.795     www      6010: 
1.602     albertel 6011: div.LC_edit_problem_saves {
                   6012:   float: right;
                   6013:   padding-bottom: 5px;
1.600     albertel 6014: }
1.795     www      6015: 
1.911     bisitz   6016: img.stift {
1.803     bisitz   6017:   border-width: 0;
                   6018:   vertical-align: middle;
1.677     riegler  6019: }
1.680     riegler  6020: 
1.923     bisitz   6021: table td.LC_mainmenu_col_fieldset {
1.680     riegler  6022:   vertical-align: top;
1.777     tempelho 6023: }
1.795     www      6024: 
1.716     raeburn  6025: div.LC_createcourse {
1.911     bisitz   6026:   margin: 10px 10px 10px 10px;
1.716     raeburn  6027: }
                   6028: 
1.917     raeburn  6029: .LC_dccid {
                   6030:   margin: 0.2em 0 0 0;
                   6031:   padding: 0;
                   6032:   font-size: 90%;
                   6033:   display:none;
                   6034: }
                   6035: 
1.698     harmsja  6036: a:hover,
1.897     wenzelju 6037: ol.LC_primary_menu a:hover,
1.721     harmsja  6038: ol#LC_MenuBreadcrumbs a:hover,
                   6039: ol#LC_PathBreadcrumbs a:hover,
1.897     wenzelju 6040: ul#LC_secondary_menu a:hover,
1.721     harmsja  6041: .LC_FormSectionClearButton input:hover
1.795     www      6042: ul.LC_TabContent   li:hover a {
1.952     onken    6043:   color:$button_hover;
1.911     bisitz   6044:   text-decoration:none;
1.693     droeschl 6045: }
                   6046: 
1.779     bisitz   6047: h1 {
1.911     bisitz   6048:   padding: 0;
                   6049:   line-height:130%;
1.693     droeschl 6050: }
1.698     harmsja  6051: 
1.911     bisitz   6052: h2,
                   6053: h3,
                   6054: h4,
                   6055: h5,
                   6056: h6 {
                   6057:   margin: 5px 0 5px 0;
                   6058:   padding: 0;
                   6059:   line-height:130%;
1.693     droeschl 6060: }
1.795     www      6061: 
                   6062: .LC_hcell {
1.911     bisitz   6063:   padding:3px 15px 3px 15px;
                   6064:   margin: 0;
                   6065:   background-color:$tabbg;
                   6066:   color:$fontmenu;
                   6067:   border-bottom:solid 1px $lg_border_color;
1.693     droeschl 6068: }
1.795     www      6069: 
1.840     bisitz   6070: .LC_Box > .LC_hcell {
1.911     bisitz   6071:   margin: 0 -10px 10px -10px;
1.835     bisitz   6072: }
                   6073: 
1.721     harmsja  6074: .LC_noBorder {
1.911     bisitz   6075:   border: 0;
1.698     harmsja  6076: }
1.693     droeschl 6077: 
1.721     harmsja  6078: .LC_FormSectionClearButton input {
1.911     bisitz   6079:   background-color:transparent;
                   6080:   border: none;
                   6081:   cursor:pointer;
                   6082:   text-decoration:underline;
1.693     droeschl 6083: }
1.763     bisitz   6084: 
                   6085: .LC_help_open_topic {
1.911     bisitz   6086:   color: #FFFFFF;
                   6087:   background-color: #EEEEFF;
                   6088:   margin: 1px;
                   6089:   padding: 4px;
                   6090:   border: 1px solid #000033;
                   6091:   white-space: nowrap;
                   6092:   /* vertical-align: middle; */
1.759     neumanie 6093: }
1.693     droeschl 6094: 
1.911     bisitz   6095: dl,
                   6096: ul,
                   6097: div,
                   6098: fieldset {
                   6099:   margin: 10px 10px 10px 0;
                   6100:   /* overflow: hidden; */
1.693     droeschl 6101: }
1.795     www      6102: 
1.838     bisitz   6103: fieldset > legend {
1.911     bisitz   6104:   font-weight: bold;
                   6105:   padding: 0 5px 0 5px;
1.838     bisitz   6106: }
                   6107: 
1.813     bisitz   6108: #LC_nav_bar {
1.911     bisitz   6109:   float: left;
1.995     raeburn  6110:   background-color: $pgbg_or_bgcolor;
1.966     bisitz   6111:   margin: 0 0 2px 0;
1.807     droeschl 6112: }
                   6113: 
1.916     droeschl 6114: #LC_realm {
                   6115:   margin: 0.2em 0 0 0;
                   6116:   padding: 0;
                   6117:   font-weight: bold;
                   6118:   text-align: center;
1.995     raeburn  6119:   background-color: $pgbg_or_bgcolor;
1.916     droeschl 6120: }
                   6121: 
1.911     bisitz   6122: #LC_nav_bar em {
                   6123:   font-weight: bold;
                   6124:   font-style: normal;
1.807     droeschl 6125: }
                   6126: 
1.897     wenzelju 6127: ol.LC_primary_menu {
1.911     bisitz   6128:   float: right;
1.934     droeschl 6129:   margin: 0;
1.995     raeburn  6130:   background-color: $pgbg_or_bgcolor;
1.807     droeschl 6131: }
                   6132: 
1.852     droeschl 6133: ol#LC_PathBreadcrumbs {
1.911     bisitz   6134:   margin: 0;
1.693     droeschl 6135: }
                   6136: 
1.897     wenzelju 6137: ol.LC_primary_menu li {
1.911     bisitz   6138:   display: inline;
                   6139:   padding: 5px 5px 0 10px;
                   6140:   vertical-align: top;
1.693     droeschl 6141: }
                   6142: 
1.897     wenzelju 6143: ol.LC_primary_menu li img {
1.911     bisitz   6144:   vertical-align: bottom;
1.934     droeschl 6145:   height: 1.1em;
1.693     droeschl 6146: }
                   6147: 
1.897     wenzelju 6148: ol.LC_primary_menu a {
1.911     bisitz   6149:   color: RGB(80, 80, 80);
                   6150:   text-decoration: none;
1.693     droeschl 6151: }
1.795     www      6152: 
1.949     droeschl 6153: ol.LC_primary_menu a.LC_new_message {
                   6154:   font-weight:bold;
                   6155:   color: darkred;
                   6156: }
                   6157: 
1.975     raeburn  6158: ol.LC_docs_parameters {
                   6159:   margin-left: 0;
                   6160:   padding: 0;
                   6161:   list-style: none;
                   6162: }
                   6163: 
                   6164: ol.LC_docs_parameters li {
                   6165:   margin: 0;
                   6166:   padding-right: 20px;
                   6167:   display: inline;
                   6168: }
                   6169: 
1.976     raeburn  6170: ol.LC_docs_parameters li:before {
                   6171:   content: "\\002022 \\0020";
                   6172: }
                   6173: 
                   6174: li.LC_docs_parameters_title {
                   6175:   font-weight: bold;
                   6176: }
                   6177: 
                   6178: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
                   6179:   content: "";
                   6180: }
                   6181: 
1.897     wenzelju 6182: ul#LC_secondary_menu {
1.911     bisitz   6183:   clear: both;
                   6184:   color: $fontmenu;
                   6185:   background: $tabbg;
                   6186:   list-style: none;
                   6187:   padding: 0;
                   6188:   margin: 0;
                   6189:   width: 100%;
1.995     raeburn  6190:   text-align: left;
1.808     droeschl 6191: }
                   6192: 
1.897     wenzelju 6193: ul#LC_secondary_menu li {
1.911     bisitz   6194:   font-weight: bold;
                   6195:   line-height: 1.8em;
                   6196:   padding: 0 0.8em;
                   6197:   border-right: 1px solid black;
                   6198:   display: inline;
                   6199:   vertical-align: middle;
1.807     droeschl 6200: }
                   6201: 
1.847     tempelho 6202: ul.LC_TabContent {
1.911     bisitz   6203:   display:block;
                   6204:   background: $sidebg;
                   6205:   border-bottom: solid 1px $lg_border_color;
                   6206:   list-style:none;
                   6207:   margin: 0 -10px;
                   6208:   padding: 0;
1.693     droeschl 6209: }
                   6210: 
1.795     www      6211: ul.LC_TabContent li,
                   6212: ul.LC_TabContentBigger li {
1.911     bisitz   6213:   float:left;
1.741     harmsja  6214: }
1.795     www      6215: 
1.897     wenzelju 6216: ul#LC_secondary_menu li a {
1.911     bisitz   6217:   color: $fontmenu;
                   6218:   text-decoration: none;
1.693     droeschl 6219: }
1.795     www      6220: 
1.721     harmsja  6221: ul.LC_TabContent {
1.952     onken    6222:   min-height:20px;
1.721     harmsja  6223: }
1.795     www      6224: 
                   6225: ul.LC_TabContent li {
1.911     bisitz   6226:   vertical-align:middle;
1.959     onken    6227:   padding: 0 16px 0 10px;
1.911     bisitz   6228:   background-color:$tabbg;
                   6229:   border-bottom:solid 1px $lg_border_color;
1.952     onken    6230:   border-right: solid 1px $font;
1.721     harmsja  6231: }
1.795     www      6232: 
1.847     tempelho 6233: ul.LC_TabContent .right {
1.911     bisitz   6234:   float:right;
1.847     tempelho 6235: }
                   6236: 
1.911     bisitz   6237: ul.LC_TabContent li a,
                   6238: ul.LC_TabContent li {
                   6239:   color:rgb(47,47,47);
                   6240:   text-decoration:none;
                   6241:   font-size:95%;
                   6242:   font-weight:bold;
1.952     onken    6243:   min-height:20px;
                   6244: }
                   6245: 
1.959     onken    6246: ul.LC_TabContent li a:hover,
                   6247: ul.LC_TabContent li a:focus {
1.952     onken    6248:   color: $button_hover;
1.959     onken    6249:   background:none;
                   6250:   outline:none;
1.952     onken    6251: }
                   6252: 
                   6253: ul.LC_TabContent li:hover {
                   6254:   color: $button_hover;
                   6255:   cursor:pointer;
1.721     harmsja  6256: }
1.795     www      6257: 
1.911     bisitz   6258: ul.LC_TabContent li.active {
1.952     onken    6259:   color: $font;
1.911     bisitz   6260:   background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952     onken    6261:   border-bottom:solid 1px #FFFFFF;
                   6262:   cursor: default;
1.744     ehlerst  6263: }
1.795     www      6264: 
1.959     onken    6265: ul.LC_TabContent li.active a {
                   6266:   color:$font;
                   6267:   background:#FFFFFF;
                   6268:   outline: none;
                   6269: }
1.870     tempelho 6270: #maincoursedoc {
1.911     bisitz   6271:   clear:both;
1.870     tempelho 6272: }
                   6273: 
                   6274: ul.LC_TabContentBigger {
1.911     bisitz   6275:   display:block;
                   6276:   list-style:none;
                   6277:   padding: 0;
1.870     tempelho 6278: }
                   6279: 
1.795     www      6280: ul.LC_TabContentBigger li {
1.911     bisitz   6281:   vertical-align:bottom;
                   6282:   height: 30px;
                   6283:   font-size:110%;
                   6284:   font-weight:bold;
                   6285:   color: #737373;
1.841     tempelho 6286: }
                   6287: 
1.957     onken    6288: ul.LC_TabContentBigger li.active {
                   6289:   position: relative;
                   6290:   top: 1px;
                   6291: }
                   6292: 
1.870     tempelho 6293: ul.LC_TabContentBigger li a {
1.911     bisitz   6294:   background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
                   6295:   height: 30px;
                   6296:   line-height: 30px;
                   6297:   text-align: center;
                   6298:   display: block;
                   6299:   text-decoration: none;
1.958     onken    6300:   outline: none;  
1.741     harmsja  6301: }
1.795     www      6302: 
1.870     tempelho 6303: ul.LC_TabContentBigger li.active a {
1.911     bisitz   6304:   background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
                   6305:   color:$font;
1.744     ehlerst  6306: }
1.795     www      6307: 
1.870     tempelho 6308: ul.LC_TabContentBigger li b {
1.911     bisitz   6309:   background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
                   6310:   display: block;
                   6311:   float: left;
                   6312:   padding: 0 30px;
1.957     onken    6313:   border-bottom: 1px solid $lg_border_color;
1.870     tempelho 6314: }
                   6315: 
1.956     onken    6316: ul.LC_TabContentBigger li:hover b {
                   6317:   color:$button_hover;
                   6318: }
                   6319: 
1.870     tempelho 6320: ul.LC_TabContentBigger li.active b {
1.911     bisitz   6321:   background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
                   6322:   color:$font;
1.957     onken    6323:   border: 0;
1.741     harmsja  6324: }
1.693     droeschl 6325: 
1.870     tempelho 6326: 
1.862     bisitz   6327: ul.LC_CourseBreadcrumbs {
                   6328:   background: $sidebg;
                   6329:   line-height: 32px;
                   6330:   padding-left: 10px;
                   6331:   margin: 0 0 10px 0;
                   6332:   list-style-position: inside;
                   6333: 
                   6334: }
                   6335: 
1.911     bisitz   6336: ol#LC_MenuBreadcrumbs,
1.862     bisitz   6337: ol#LC_PathBreadcrumbs {
1.911     bisitz   6338:   padding-left: 10px;
                   6339:   margin: 0;
1.933     droeschl 6340:   height: 2.5em;  /* equal to #LC_breadcrumbs line-height */
1.693     droeschl 6341: }
                   6342: 
1.911     bisitz   6343: ol#LC_MenuBreadcrumbs li,
                   6344: ol#LC_PathBreadcrumbs li,
1.862     bisitz   6345: ul.LC_CourseBreadcrumbs li {
1.911     bisitz   6346:   display: inline;
1.933     droeschl 6347:   white-space: normal;  
1.693     droeschl 6348: }
                   6349: 
1.823     bisitz   6350: ol#LC_MenuBreadcrumbs li a,
1.862     bisitz   6351: ul.LC_CourseBreadcrumbs li a {
1.911     bisitz   6352:   text-decoration: none;
                   6353:   font-size:90%;
1.693     droeschl 6354: }
1.795     www      6355: 
1.969     droeschl 6356: ol#LC_MenuBreadcrumbs h1 {
                   6357:   display: inline;
                   6358:   font-size: 90%;
                   6359:   line-height: 2.5em;
                   6360:   margin: 0;
                   6361:   padding: 0;
                   6362: }
                   6363: 
1.795     www      6364: ol#LC_PathBreadcrumbs li a {
1.911     bisitz   6365:   text-decoration:none;
                   6366:   font-size:100%;
                   6367:   font-weight:bold;
1.693     droeschl 6368: }
1.795     www      6369: 
1.840     bisitz   6370: .LC_Box {
1.911     bisitz   6371:   border: solid 1px $lg_border_color;
                   6372:   padding: 0 10px 10px 10px;
1.746     neumanie 6373: }
1.795     www      6374: 
                   6375: .LC_AboutMe_Image {
1.911     bisitz   6376:   float:left;
                   6377:   margin-right:10px;
1.747     neumanie 6378: }
1.795     www      6379: 
                   6380: .LC_Clear_AboutMe_Image {
1.911     bisitz   6381:   clear:left;
1.747     neumanie 6382: }
1.795     www      6383: 
1.721     harmsja  6384: dl.LC_ListStyleClean dt {
1.911     bisitz   6385:   padding-right: 5px;
                   6386:   display: table-header-group;
1.693     droeschl 6387: }
                   6388: 
1.721     harmsja  6389: dl.LC_ListStyleClean dd {
1.911     bisitz   6390:   display: table-row;
1.693     droeschl 6391: }
                   6392: 
1.721     harmsja  6393: .LC_ListStyleClean,
                   6394: .LC_ListStyleSimple,
                   6395: .LC_ListStyleNormal,
1.795     www      6396: .LC_ListStyleSpecial {
1.911     bisitz   6397:   /* display:block; */
                   6398:   list-style-position: inside;
                   6399:   list-style-type: none;
                   6400:   overflow: hidden;
                   6401:   padding: 0;
1.693     droeschl 6402: }
                   6403: 
1.721     harmsja  6404: .LC_ListStyleSimple li,
                   6405: .LC_ListStyleSimple dd,
                   6406: .LC_ListStyleNormal li,
                   6407: .LC_ListStyleNormal dd,
                   6408: .LC_ListStyleSpecial li,
1.795     www      6409: .LC_ListStyleSpecial dd {
1.911     bisitz   6410:   margin: 0;
                   6411:   padding: 5px 5px 5px 10px;
                   6412:   clear: both;
1.693     droeschl 6413: }
                   6414: 
1.721     harmsja  6415: .LC_ListStyleClean li,
                   6416: .LC_ListStyleClean dd {
1.911     bisitz   6417:   padding-top: 0;
                   6418:   padding-bottom: 0;
1.693     droeschl 6419: }
                   6420: 
1.721     harmsja  6421: .LC_ListStyleSimple dd,
1.795     www      6422: .LC_ListStyleSimple li {
1.911     bisitz   6423:   border-bottom: solid 1px $lg_border_color;
1.693     droeschl 6424: }
                   6425: 
1.721     harmsja  6426: .LC_ListStyleSpecial li,
                   6427: .LC_ListStyleSpecial dd {
1.911     bisitz   6428:   list-style-type: none;
                   6429:   background-color: RGB(220, 220, 220);
                   6430:   margin-bottom: 4px;
1.693     droeschl 6431: }
                   6432: 
1.721     harmsja  6433: table.LC_SimpleTable {
1.911     bisitz   6434:   margin:5px;
                   6435:   border:solid 1px $lg_border_color;
1.795     www      6436: }
1.693     droeschl 6437: 
1.721     harmsja  6438: table.LC_SimpleTable tr {
1.911     bisitz   6439:   padding: 0;
                   6440:   border:solid 1px $lg_border_color;
1.693     droeschl 6441: }
1.795     www      6442: 
                   6443: table.LC_SimpleTable thead {
1.911     bisitz   6444:   background:rgb(220,220,220);
1.693     droeschl 6445: }
                   6446: 
1.721     harmsja  6447: div.LC_columnSection {
1.911     bisitz   6448:   display: block;
                   6449:   clear: both;
                   6450:   overflow: hidden;
                   6451:   margin: 0;
1.693     droeschl 6452: }
                   6453: 
1.721     harmsja  6454: div.LC_columnSection>* {
1.911     bisitz   6455:   float: left;
                   6456:   margin: 10px 20px 10px 0;
                   6457:   overflow:hidden;
1.693     droeschl 6458: }
1.721     harmsja  6459: 
1.795     www      6460: table em {
1.911     bisitz   6461:   font-weight: bold;
                   6462:   font-style: normal;
1.748     schulted 6463: }
1.795     www      6464: 
1.779     bisitz   6465: table.LC_tableBrowseRes,
1.795     www      6466: table.LC_tableOfContent {
1.911     bisitz   6467:   border:none;
                   6468:   border-spacing: 1px;
                   6469:   padding: 3px;
                   6470:   background-color: #FFFFFF;
                   6471:   font-size: 90%;
1.753     droeschl 6472: }
1.789     droeschl 6473: 
1.911     bisitz   6474: table.LC_tableOfContent {
                   6475:   border-collapse: collapse;
1.789     droeschl 6476: }
                   6477: 
1.771     droeschl 6478: table.LC_tableBrowseRes a,
1.768     schulted 6479: table.LC_tableOfContent a {
1.911     bisitz   6480:   background-color: transparent;
                   6481:   text-decoration: none;
1.753     droeschl 6482: }
                   6483: 
1.795     www      6484: table.LC_tableOfContent img {
1.911     bisitz   6485:   border: none;
                   6486:   height: 1.3em;
                   6487:   vertical-align: text-bottom;
                   6488:   margin-right: 0.3em;
1.753     droeschl 6489: }
1.757     schulted 6490: 
1.795     www      6491: a#LC_content_toolbar_firsthomework {
1.911     bisitz   6492:   background-image:url(/res/adm/pages/open-first-problem.gif);
1.774     ehlerst  6493: }
                   6494: 
1.795     www      6495: a#LC_content_toolbar_everything {
1.911     bisitz   6496:   background-image:url(/res/adm/pages/show-all.gif);
1.774     ehlerst  6497: }
                   6498: 
1.795     www      6499: a#LC_content_toolbar_uncompleted {
1.911     bisitz   6500:   background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774     ehlerst  6501: }
                   6502: 
1.795     www      6503: #LC_content_toolbar_clearbubbles {
1.911     bisitz   6504:   background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774     ehlerst  6505: }
                   6506: 
1.795     www      6507: a#LC_content_toolbar_changefolder {
1.911     bisitz   6508:   background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757     schulted 6509: }
                   6510: 
1.795     www      6511: a#LC_content_toolbar_changefolder_toggled {
1.911     bisitz   6512:   background-image:url(/res/adm/pages/open-all-folders.gif);
1.757     schulted 6513: }
                   6514: 
1.795     www      6515: ul#LC_toolbar li a:hover {
1.911     bisitz   6516:   background-position: bottom center;
1.757     schulted 6517: }
                   6518: 
1.795     www      6519: ul#LC_toolbar {
1.911     bisitz   6520:   padding: 0;
                   6521:   margin: 2px;
                   6522:   list-style:none;
                   6523:   position:relative;
                   6524:   background-color:white;
1.757     schulted 6525: }
                   6526: 
1.795     www      6527: ul#LC_toolbar li {
1.911     bisitz   6528:   border:1px solid white;
                   6529:   padding: 0;
                   6530:   margin: 0;
                   6531:   float: left;
                   6532:   display:inline;
                   6533:   vertical-align:middle;
                   6534: }
1.757     schulted 6535: 
1.783     amueller 6536: 
1.795     www      6537: a.LC_toolbarItem {
1.911     bisitz   6538:   display:block;
                   6539:   padding: 0;
                   6540:   margin: 0;
                   6541:   height: 32px;
                   6542:   width: 32px;
                   6543:   color:white;
                   6544:   border: none;
                   6545:   background-repeat:no-repeat;
                   6546:   background-color:transparent;
1.757     schulted 6547: }
                   6548: 
1.915     droeschl 6549: ul.LC_funclist {
                   6550:     margin: 0;
                   6551:     padding: 0.5em 1em 0.5em 0;
                   6552: }
                   6553: 
1.933     droeschl 6554: ul.LC_funclist > li:first-child {
                   6555:     font-weight:bold; 
                   6556:     margin-left:0.8em;
                   6557: }
                   6558: 
1.915     droeschl 6559: ul.LC_funclist + ul.LC_funclist {
                   6560:     /* 
                   6561:        left border as a seperator if we have more than
                   6562:        one list 
                   6563:     */
                   6564:     border-left: 1px solid $sidebg;
                   6565:     /* 
                   6566:        this hides the left border behind the border of the 
                   6567:        outer box if element is wrapped to the next 'line' 
                   6568:     */
                   6569:     margin-left: -1px;
                   6570: }
                   6571: 
1.843     bisitz   6572: ul.LC_funclist li {
1.915     droeschl 6573:   display: inline;
1.782     bisitz   6574:   white-space: nowrap;
1.915     droeschl 6575:   margin: 0 0 0 25px;
                   6576:   line-height: 150%;
1.782     bisitz   6577: }
                   6578: 
1.930     faziophi 6579: .ui-accordion .LC_advanced_toggle {
                   6580:   float: right;
                   6581:   font-size: 90%;
                   6582:   padding: 0px 4px
                   6583: }
1.757     schulted 6584: 
1.974     wenzelju 6585: .LC_hidden {
                   6586:   display: none;
                   6587: }
                   6588: 
1.343     albertel 6589: END
                   6590: }
                   6591: 
1.306     albertel 6592: =pod
                   6593: 
                   6594: =item * &headtag()
                   6595: 
                   6596: Returns a uniform footer for LON-CAPA web pages.
                   6597: 
1.307     albertel 6598: Inputs: $title - optional title for the head
                   6599:         $head_extra - optional extra HTML to put inside the <head>
1.315     albertel 6600:         $args - optional arguments
1.319     albertel 6601:             force_register - if is true call registerurl so the remote is 
                   6602:                              informed
1.415     albertel 6603:             redirect       -> array ref of
                   6604:                                    1- seconds before redirect occurs
                   6605:                                    2- url to redirect to
                   6606:                                    3- whether the side effect should occur
1.315     albertel 6607:                            (side effect of setting 
                   6608:                                $env{'internal.head.redirect'} to the url 
                   6609:                                redirected too)
1.352     albertel 6610:             domain         -> force to color decorate a page for a specific
                   6611:                                domain
                   6612:             function       -> force usage of a specific rolish color scheme
                   6613:             bgcolor        -> override the default page bgcolor
1.460     albertel 6614:             no_auto_mt_title
                   6615:                            -> prevent &mt()ing the title arg
1.464     albertel 6616: 
1.306     albertel 6617: =cut
                   6618: 
                   6619: sub headtag {
1.313     albertel 6620:     my ($title,$head_extra,$args) = @_;
1.306     albertel 6621:     
1.363     albertel 6622:     my $function = $args->{'function'} || &get_users_function();
                   6623:     my $domain   = $args->{'domain'}   || &determinedomain();
                   6624:     my $bgcolor  = $args->{'bgcolor'}  || &designparm($function.'.pgbg',$domain);
1.418     albertel 6625:     my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458     albertel 6626: 		   $Apache::lonnet::perlvar{'lonVersion'},
1.531     albertel 6627: 		   #time(),
1.418     albertel 6628: 		   $env{'environment.color.timestamp'},
1.363     albertel 6629: 		   $function,$domain,$bgcolor);
                   6630: 
1.369     www      6631:     $url = '/adm/css/'.&escape($url).'.css';
1.363     albertel 6632: 
1.308     albertel 6633:     my $result =
                   6634: 	'<head>'.
1.461     albertel 6635: 	&font_settings();
1.319     albertel 6636: 
1.461     albertel 6637:     if (!$args->{'frameset'}) {
                   6638: 	$result .= &Apache::lonhtmlcommon::htmlareaheaders();
                   6639:     }
1.962     droeschl 6640:     if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
                   6641:         $result .= Apache::lonxml::display_title();
1.319     albertel 6642:     }
1.436     albertel 6643:     if (!$args->{'no_nav_bar'} 
                   6644: 	&& !$args->{'only_body'}
                   6645: 	&& !$args->{'frameset'}) {
                   6646: 	$result .= &help_menu_js();
                   6647:     }
1.319     albertel 6648: 
1.314     albertel 6649:     if (ref($args->{'redirect'})) {
1.414     albertel 6650: 	my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315     albertel 6651: 	$url = &Apache::lonenc::check_encrypt($url);
1.414     albertel 6652: 	if (!$inhibit_continue) {
                   6653: 	    $env{'internal.head.redirect'} = $url;
                   6654: 	}
1.313     albertel 6655: 	$result.=<<ADDMETA
                   6656: <meta http-equiv="pragma" content="no-cache" />
1.344     albertel 6657: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313     albertel 6658: ADDMETA
                   6659:     }
1.306     albertel 6660:     if (!defined($title)) {
                   6661: 	$title = 'The LearningOnline Network with CAPA';
                   6662:     }
1.460     albertel 6663:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
                   6664:     $result .= '<title> LON-CAPA '.$title.'</title>'
1.414     albertel 6665: 	.'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
                   6666: 	.$head_extra;
1.962     droeschl 6667:     return $result.'</head>';
1.306     albertel 6668: }
                   6669: 
                   6670: =pod
                   6671: 
1.340     albertel 6672: =item * &font_settings()
                   6673: 
                   6674: Returns neccessary <meta> to set the proper encoding
                   6675: 
                   6676: Inputs: none
                   6677: 
                   6678: =cut
                   6679: 
                   6680: sub font_settings {
                   6681:     my $headerstring='';
1.647     www      6682:     if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340     albertel 6683: 	$headerstring.=
                   6684: 	    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
                   6685:     }
                   6686:     return $headerstring;
                   6687: }
                   6688: 
1.341     albertel 6689: =pod
                   6690: 
                   6691: =item * &xml_begin()
                   6692: 
                   6693: Returns the needed doctype and <html>
                   6694: 
                   6695: Inputs: none
                   6696: 
                   6697: =cut
                   6698: 
                   6699: sub xml_begin {
                   6700:     my $output='';
                   6701: 
                   6702:     if ($env{'browser.mathml'}) {
                   6703: 	$output='<?xml version="1.0"?>'
                   6704:             #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
                   6705: #            .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
                   6706:             
                   6707: #	    .'<!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">] >'
                   6708: 	    .'<!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">'
                   6709:             .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" ' 
                   6710: 	    .'xmlns="http://www.w3.org/1999/xhtml">';
                   6711:     } else {
1.849     bisitz   6712: 	$output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
                   6713:            .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341     albertel 6714:     }
                   6715:     return $output;
                   6716: }
1.340     albertel 6717: 
                   6718: =pod
                   6719: 
1.306     albertel 6720: =item * &start_page()
                   6721: 
                   6722: Returns a complete <html> .. <body> section for LON-CAPA web pages.
                   6723: 
1.648     raeburn  6724: Inputs:
                   6725: 
                   6726: =over 4
                   6727: 
                   6728: $title - optional title for the page
                   6729: 
                   6730: $head_extra - optional extra HTML to incude inside the <head>
                   6731: 
                   6732: $args - additional optional args supported are:
                   6733: 
                   6734: =over 8
                   6735: 
                   6736:              only_body      -> is true will set &bodytag() onlybodytag
1.317     albertel 6737:                                     arg on
1.814     bisitz   6738:              no_nav_bar     -> is true will set &bodytag() no_nav_bar arg on
1.648     raeburn  6739:              add_entries    -> additional attributes to add to the  <body>
                   6740:              domain         -> force to color decorate a page for a 
1.317     albertel 6741:                                     specific domain
1.648     raeburn  6742:              function       -> force usage of a specific rolish color
1.317     albertel 6743:                                     scheme
1.648     raeburn  6744:              redirect       -> see &headtag()
                   6745:              bgcolor        -> override the default page bg color
                   6746:              js_ready       -> return a string ready for being used in 
1.317     albertel 6747:                                     a javascript writeln
1.648     raeburn  6748:              html_encode    -> return a string ready for being used in 
1.320     albertel 6749:                                     a html attribute
1.648     raeburn  6750:              force_register -> if is true will turn on the &bodytag()
1.317     albertel 6751:                                     $forcereg arg
1.648     raeburn  6752:              frameset       -> if true will start with a <frameset>
1.330     albertel 6753:                                     rather than <body>
1.648     raeburn  6754:              skip_phases    -> hash ref of 
1.338     albertel 6755:                                     head -> skip the <html><head> generation
                   6756:                                     body -> skip all <body> generation
1.648     raeburn  6757:              no_auto_mt_title -> prevent &mt()ing the title arg
                   6758:              inherit_jsmath -> when creating popup window in a page,
                   6759:                                     should it have jsmath forced on by the
                   6760:                                     current page
1.867     kalberla 6761:              bread_crumbs ->             Array containing breadcrumbs
1.983     raeburn  6762:              bread_crumbs_component ->  if exists show it as headline else show only the breadcrumbs
1.361     albertel 6763: 
1.648     raeburn  6764: =back
1.460     albertel 6765: 
1.648     raeburn  6766: =back
1.562     albertel 6767: 
1.306     albertel 6768: =cut
                   6769: 
                   6770: sub start_page {
1.309     albertel 6771:     my ($title,$head_extra,$args) = @_;
1.318     albertel 6772:     #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.964     droeschl 6773: #SD
                   6774: #I don't see why we copy certain elements of %$args to %head_args
                   6775: #head args is passed to headtag() and this routine only reads those
                   6776: #keys that are needed. There doesn't happen any writes or any processing
                   6777: #of other keys.
                   6778: #proposal: just pass $args to headtag instead of \%head_args and delete 
                   6779: #marked lines
                   6780: #<- MARK
1.313     albertel 6781:     my %head_args;
1.352     albertel 6782:     foreach my $arg ('redirect','force_register','domain','function',
1.460     albertel 6783: 		     'bgcolor','frameset','no_nav_bar','only_body',
                   6784: 		     'no_auto_mt_title') {
1.319     albertel 6785: 	if (defined($args->{$arg})) {
1.324     raeburn  6786: 	    $head_args{$arg} = $args->{$arg};
1.319     albertel 6787: 	}
1.313     albertel 6788:     }
1.964     droeschl 6789: #MARK ->
1.319     albertel 6790: 
1.315     albertel 6791:     $env{'internal.start_page'}++;
1.338     albertel 6792:     my $result;
1.964     droeschl 6793: 
1.338     albertel 6794:     if (! exists($args->{'skip_phases'}{'head'}) ) {
1.964     droeschl 6795:         $result .= 
                   6796:                   &xml_begin() . &headtag($title,$head_extra,\%head_args);
                   6797: #replace prev line by
                   6798: #                 &xml_begin() . &headtag($title, $head_extra, $args);
1.338     albertel 6799:     }
                   6800:     
                   6801:     if (! exists($args->{'skip_phases'}{'body'}) ) {
                   6802: 	if ($args->{'frameset'}) {
                   6803: 	    my $attr_string = &make_attr_string($args->{'force_register'},
                   6804: 						$args->{'add_entries'});
                   6805: 	    $result .= "\n<frameset $attr_string>\n";
1.831     bisitz   6806:         } else {
                   6807:             $result .=
                   6808:                 &bodytag($title, 
                   6809:                          $args->{'function'},       $args->{'add_entries'},
                   6810:                          $args->{'only_body'},      $args->{'domain'},
                   6811:                          $args->{'force_register'}, $args->{'no_nav_bar'},
1.962     droeschl 6812:                          $args->{'bgcolor'},        $args);
1.831     bisitz   6813:         }
1.330     albertel 6814:     }
1.338     albertel 6815: 
1.315     albertel 6816:     if ($args->{'js_ready'}) {
1.713     kaisler  6817: 		$result = &js_ready($result);
1.315     albertel 6818:     }
1.320     albertel 6819:     if ($args->{'html_encode'}) {
1.713     kaisler  6820: 		$result = &html_encode($result);
                   6821:     }
                   6822: 
1.813     bisitz   6823:     # Preparation for new and consistent functionlist at top of screen
                   6824:     # if ($args->{'functionlist'}) {
                   6825:     #            $result .= &build_functionlist();
                   6826:     #}
                   6827: 
1.964     droeschl 6828:     # Don't add anything more if only_body wanted or in const space
                   6829:     return $result if    $args->{'only_body'} 
                   6830:                       || $env{'request.state'} eq 'construct';
1.813     bisitz   6831: 
                   6832:     #Breadcrumbs
1.758     kaisler  6833:     if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
                   6834: 		&Apache::lonhtmlcommon::clear_breadcrumbs();
                   6835: 		#if any br links exists, add them to the breadcrumbs
                   6836: 		if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {         
                   6837: 			foreach my $crumb (@{$args->{'bread_crumbs'}}){
                   6838: 				&Apache::lonhtmlcommon::add_breadcrumb($crumb);
                   6839: 			}
                   6840: 		}
                   6841: 
                   6842: 		#if bread_crumbs_component exists show it as headline else show only the breadcrumbs
                   6843: 		if(exists($args->{'bread_crumbs_component'})){
                   6844: 			$result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
                   6845: 		}else{
                   6846: 			$result .= &Apache::lonhtmlcommon::breadcrumbs();
                   6847: 		}
1.320     albertel 6848:     }
1.315     albertel 6849:     return $result;
1.306     albertel 6850: }
                   6851: 
                   6852: sub end_page {
1.315     albertel 6853:     my ($args) = @_;
                   6854:     $env{'internal.end_page'}++;
1.330     albertel 6855:     my $result;
1.335     albertel 6856:     if ($args->{'discussion'}) {
                   6857: 	my ($target,$parser);
                   6858: 	if (ref($args->{'discussion'})) {
                   6859: 	    ($target,$parser) =($args->{'discussion'}{'target'},
                   6860: 				$args->{'discussion'}{'parser'});
                   6861: 	}
                   6862: 	$result .= &Apache::lonxml::xmlend($target,$parser);
                   6863:     }
                   6864: 
1.330     albertel 6865:     if ($args->{'frameset'}) {
                   6866: 	$result .= '</frameset>';
                   6867:     } else {
1.635     raeburn  6868: 	$result .= &endbodytag($args);
1.330     albertel 6869:     }
                   6870:     $result .= "\n</html>";
                   6871: 
1.315     albertel 6872:     if ($args->{'js_ready'}) {
1.317     albertel 6873: 	$result = &js_ready($result);
1.315     albertel 6874:     }
1.335     albertel 6875: 
1.320     albertel 6876:     if ($args->{'html_encode'}) {
                   6877: 	$result = &html_encode($result);
                   6878:     }
1.335     albertel 6879: 
1.315     albertel 6880:     return $result;
                   6881: }
                   6882: 
1.320     albertel 6883: sub html_encode {
                   6884:     my ($result) = @_;
                   6885: 
1.322     albertel 6886:     $result = &HTML::Entities::encode($result,'<>&"');
1.320     albertel 6887:     
                   6888:     return $result;
                   6889: }
1.317     albertel 6890: sub js_ready {
                   6891:     my ($result) = @_;
                   6892: 
1.323     albertel 6893:     $result =~ s/[\n\r]/ /xmsg;
                   6894:     $result =~ s/\\/\\\\/xmsg;
                   6895:     $result =~ s/'/\\'/xmsg;
1.372     albertel 6896:     $result =~ s{</}{<\\/}xmsg;
1.317     albertel 6897:     
                   6898:     return $result;
                   6899: }
                   6900: 
1.315     albertel 6901: sub validate_page {
                   6902:     if (  exists($env{'internal.start_page'})
1.316     albertel 6903: 	  &&     $env{'internal.start_page'} > 1) {
                   6904: 	&Apache::lonnet::logthis('start_page called multiple times '.
1.318     albertel 6905: 				 $env{'internal.start_page'}.' '.
1.316     albertel 6906: 				 $ENV{'request.filename'});
1.315     albertel 6907:     }
                   6908:     if (  exists($env{'internal.end_page'})
1.316     albertel 6909: 	  &&     $env{'internal.end_page'} > 1) {
                   6910: 	&Apache::lonnet::logthis('end_page called multiple times '.
1.318     albertel 6911: 				 $env{'internal.end_page'}.' '.
1.316     albertel 6912: 				 $env{'request.filename'});
1.315     albertel 6913:     }
                   6914:     if (     exists($env{'internal.start_page'})
                   6915: 	&& ! exists($env{'internal.end_page'})) {
1.316     albertel 6916: 	&Apache::lonnet::logthis('start_page called without end_page '.
                   6917: 				 $env{'request.filename'});
1.315     albertel 6918:     }
                   6919:     if (   ! exists($env{'internal.start_page'})
                   6920: 	&&   exists($env{'internal.end_page'})) {
1.316     albertel 6921: 	&Apache::lonnet::logthis('end_page called without start_page'.
                   6922: 				 $env{'request.filename'});
1.315     albertel 6923:     }
1.306     albertel 6924: }
1.315     albertel 6925: 
1.996     www      6926: 
                   6927: sub start_scrollbox {
1.998     raeburn  6928:     my ($outerwidth,$width,$height)=@_;
                   6929:     unless ($outerwidth) { $outerwidth='520px'; }
                   6930:     unless ($width) { $width='500px'; }
                   6931:     unless ($height) { $height='200px'; }
                   6932:     return "<table style='width: $outerwidth; border: 1px solid black;'><tr><td style='width: $width;' bgcolor='#FFFFFF'><div style='overflow:auto; width:$width; height: $height;'>";
1.996     www      6933: }
                   6934: 
                   6935: sub end_scrollbox {
1.998     raeburn  6936:     return '</td></tr></table>';
1.996     www      6937: }
                   6938: 
1.318     albertel 6939: sub simple_error_page {
                   6940:     my ($r,$title,$msg) = @_;
                   6941:     my $page =
                   6942: 	&Apache::loncommon::start_page($title).
                   6943: 	&mt($msg).
                   6944: 	&Apache::loncommon::end_page();
                   6945:     if (ref($r)) {
                   6946: 	$r->print($page);
1.327     albertel 6947: 	return;
1.318     albertel 6948:     }
                   6949:     return $page;
                   6950: }
1.347     albertel 6951: 
                   6952: {
1.610     albertel 6953:     my @row_count;
1.961     onken    6954: 
                   6955:     sub start_data_table_count {
                   6956:         unshift(@row_count, 0);
                   6957:         return;
                   6958:     }
                   6959: 
                   6960:     sub end_data_table_count {
                   6961:         shift(@row_count);
                   6962:         return;
                   6963:     }
                   6964: 
1.347     albertel 6965:     sub start_data_table {
1.422     albertel 6966: 	my ($add_class) = @_;
                   6967: 	my $css_class = (join(' ','LC_data_table',$add_class));
1.961     onken    6968: 	&start_data_table_count();
1.422     albertel 6969: 	return '<table class="'.$css_class.'">'."\n";
1.347     albertel 6970:     }
                   6971: 
                   6972:     sub end_data_table {
1.961     onken    6973: 	&end_data_table_count();
1.389     albertel 6974: 	return '</table>'."\n";;
1.347     albertel 6975:     }
                   6976: 
                   6977:     sub start_data_table_row {
1.974     wenzelju 6978: 	my ($add_class, $id) = @_;
1.610     albertel 6979: 	$row_count[0]++;
                   6980: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900     bisitz   6981: 	$css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974     wenzelju 6982:         $id = (' id="'.$id.'"') unless ($id eq '');
                   6983:         return  '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347     albertel 6984:     }
1.471     banghart 6985:     
                   6986:     sub continue_data_table_row {
1.974     wenzelju 6987: 	my ($add_class, $id) = @_;
1.610     albertel 6988: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974     wenzelju 6989: 	$css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
                   6990:         $id = (' id="'.$id.'"') unless ($id eq '');
                   6991:         return  '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471     banghart 6992:     }
1.347     albertel 6993: 
                   6994:     sub end_data_table_row {
1.389     albertel 6995: 	return '</tr>'."\n";;
1.347     albertel 6996:     }
1.367     www      6997: 
1.421     albertel 6998:     sub start_data_table_empty_row {
1.707     bisitz   6999: #	$row_count[0]++;
1.421     albertel 7000: 	return  '<tr class="LC_empty_row" >'."\n";;
                   7001:     }
                   7002: 
                   7003:     sub end_data_table_empty_row {
                   7004: 	return '</tr>'."\n";;
                   7005:     }
                   7006: 
1.367     www      7007:     sub start_data_table_header_row {
1.389     albertel 7008: 	return  '<tr class="LC_header_row">'."\n";;
1.367     www      7009:     }
                   7010: 
                   7011:     sub end_data_table_header_row {
1.389     albertel 7012: 	return '</tr>'."\n";;
1.367     www      7013:     }
1.890     droeschl 7014: 
                   7015:     sub data_table_caption {
                   7016:         my $caption = shift;
                   7017:         return "<caption class=\"LC_caption\">$caption</caption>";
                   7018:     }
1.347     albertel 7019: }
                   7020: 
1.548     albertel 7021: =pod
                   7022: 
                   7023: =item * &inhibit_menu_check($arg)
                   7024: 
                   7025: Checks for a inhibitmenu state and generates output to preserve it
                   7026: 
                   7027: Inputs:         $arg - can be any of
                   7028:                      - undef - in which case the return value is a string 
                   7029:                                to add  into arguments list of a uri
                   7030:                      - 'input' - in which case the return value is a HTML
                   7031:                                  <form> <input> field of type hidden to
                   7032:                                  preserve the value
                   7033:                      - a url - in which case the return value is the url with
                   7034:                                the neccesary cgi args added to preserve the
                   7035:                                inhibitmenu state
                   7036:                      - a ref to a url - no return value, but the string is
                   7037:                                         updated to include the neccessary cgi
                   7038:                                         args to preserve the inhibitmenu state
                   7039: 
                   7040: =cut
                   7041: 
                   7042: sub inhibit_menu_check {
                   7043:     my ($arg) = @_;
                   7044:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   7045:     if ($arg eq 'input') {
                   7046: 	if ($env{'form.inhibitmenu'}) {
                   7047: 	    return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
                   7048: 	} else {
                   7049: 	    return
                   7050: 	}
                   7051:     }
                   7052:     if ($env{'form.inhibitmenu'}) {
                   7053: 	if (ref($arg)) {
                   7054: 	    $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   7055: 	} elsif ($arg eq '') {
                   7056: 	    $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
                   7057: 	} else {
                   7058: 	    $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   7059: 	}
                   7060:     }
                   7061:     if (!ref($arg)) {
                   7062: 	return $arg;
                   7063:     }
                   7064: }
                   7065: 
1.251     albertel 7066: ###############################################
1.182     matthew  7067: 
                   7068: =pod
                   7069: 
1.549     albertel 7070: =back
                   7071: 
                   7072: =head1 User Information Routines
                   7073: 
                   7074: =over 4
                   7075: 
1.405     albertel 7076: =item * &get_users_function()
1.182     matthew  7077: 
                   7078: Used by &bodytag to determine the current users primary role.
                   7079: Returns either 'student','coordinator','admin', or 'author'.
                   7080: 
                   7081: =cut
                   7082: 
                   7083: ###############################################
                   7084: sub get_users_function {
1.815     tempelho 7085:     my $function = 'norole';
1.818     tempelho 7086:     if ($env{'request.role'}=~/^(st)/) {
                   7087:         $function='student';
                   7088:     }
1.907     raeburn  7089:     if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182     matthew  7090:         $function='coordinator';
                   7091:     }
1.258     albertel 7092:     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182     matthew  7093:         $function='admin';
                   7094:     }
1.826     bisitz   7095:     if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.182     matthew  7096:         ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
                   7097:         $function='author';
                   7098:     }
                   7099:     return $function;
1.54      www      7100: }
1.99      www      7101: 
                   7102: ###############################################
                   7103: 
1.233     raeburn  7104: =pod
                   7105: 
1.821     raeburn  7106: =item * &show_course()
                   7107: 
                   7108: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
                   7109: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
                   7110: 
                   7111: Inputs:
                   7112: None
                   7113: 
                   7114: Outputs:
                   7115: Scalar: 1 if 'Course' to be used, 0 otherwise.
                   7116: 
                   7117: =cut
                   7118: 
                   7119: ###############################################
                   7120: sub show_course {
                   7121:     my $course = !$env{'user.adv'};
                   7122:     if (!$env{'user.adv'}) {
                   7123:         foreach my $env (keys(%env)) {
                   7124:             next if ($env !~ m/^user\.priv\./);
                   7125:             if ($env !~ m/^user\.priv\.(?:st|cm)/) {
                   7126:                 $course = 0;
                   7127:                 last;
                   7128:             }
                   7129:         }
                   7130:     }
                   7131:     return $course;
                   7132: }
                   7133: 
                   7134: ###############################################
                   7135: 
                   7136: =pod
                   7137: 
1.542     raeburn  7138: =item * &check_user_status()
1.274     raeburn  7139: 
                   7140: Determines current status of supplied role for a
                   7141: specific user. Roles can be active, previous or future.
                   7142: 
                   7143: Inputs: 
                   7144: user's domain, user's username, course's domain,
1.375     raeburn  7145: course's number, optional section ID.
1.274     raeburn  7146: 
                   7147: Outputs:
                   7148: role status: active, previous or future. 
                   7149: 
                   7150: =cut
                   7151: 
                   7152: sub check_user_status {
1.412     raeburn  7153:     my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.982     raeburn  7154:     my $extra = &Apache::lonnet::freeze_escape({'skipcheck' => 1});
                   7155:     my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname,'.',undef,$extra);
1.274     raeburn  7156:     my @uroles = keys %userinfo;
                   7157:     my $srchstr;
                   7158:     my $active_chk = 'none';
1.412     raeburn  7159:     my $now = time;
1.274     raeburn  7160:     if (@uroles > 0) {
1.908     raeburn  7161:         if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274     raeburn  7162:             $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
                   7163:         } else {
1.412     raeburn  7164:             $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
                   7165:         }
                   7166:         if (grep/^\Q$srchstr\E$/,@uroles) {
1.274     raeburn  7167:             my $role_end = 0;
                   7168:             my $role_start = 0;
                   7169:             $active_chk = 'active';
1.412     raeburn  7170:             if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
                   7171:                 $role_end = $1;
                   7172:                 if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
                   7173:                     $role_start = $1;
1.274     raeburn  7174:                 }
                   7175:             }
                   7176:             if ($role_start > 0) {
1.412     raeburn  7177:                 if ($now < $role_start) {
1.274     raeburn  7178:                     $active_chk = 'future';
                   7179:                 }
                   7180:             }
                   7181:             if ($role_end > 0) {
1.412     raeburn  7182:                 if ($now > $role_end) {
1.274     raeburn  7183:                     $active_chk = 'previous';
                   7184:                 }
                   7185:             }
                   7186:         }
                   7187:     }
                   7188:     return $active_chk;
                   7189: }
                   7190: 
                   7191: ###############################################
                   7192: 
                   7193: =pod
                   7194: 
1.405     albertel 7195: =item * &get_sections()
1.233     raeburn  7196: 
                   7197: Determines all the sections for a course including
                   7198: sections with students and sections containing other roles.
1.419     raeburn  7199: Incoming parameters: 
                   7200: 
                   7201: 1. domain
                   7202: 2. course number 
                   7203: 3. reference to array containing roles for which sections should 
                   7204: be gathered (optional).
                   7205: 4. reference to array containing status types for which sections 
                   7206: should be gathered (optional).
                   7207: 
                   7208: If the third argument is undefined, sections are gathered for any role. 
                   7209: If the fourth argument is undefined, sections are gathered for any status.
                   7210: Permissible values are 'active' or 'future' or 'previous'.
1.233     raeburn  7211:  
1.374     raeburn  7212: Returns section hash (keys are section IDs, values are
                   7213: number of users in each section), subject to the
1.419     raeburn  7214: optional roles filter, optional status filter 
1.233     raeburn  7215: 
                   7216: =cut
                   7217: 
                   7218: ###############################################
                   7219: sub get_sections {
1.419     raeburn  7220:     my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366     albertel 7221:     if (!defined($cdom) || !defined($cnum)) {
                   7222:         my $cid =  $env{'request.course.id'};
                   7223: 
                   7224: 	return if (!defined($cid));
                   7225: 
                   7226:         $cdom = $env{'course.'.$cid.'.domain'};
                   7227:         $cnum = $env{'course.'.$cid.'.num'};
                   7228:     }
                   7229: 
                   7230:     my %sectioncount;
1.419     raeburn  7231:     my $now = time;
1.240     albertel 7232: 
1.366     albertel 7233:     if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276     albertel 7234: 	my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240     albertel 7235: 	my $sec_index = &Apache::loncoursedata::CL_SECTION();
                   7236: 	my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419     raeburn  7237:         my $start_index = &Apache::loncoursedata::CL_START();
                   7238:         my $end_index = &Apache::loncoursedata::CL_END();
                   7239:         my $status;
1.366     albertel 7240: 	while (my ($student,$data) = each(%$classlist)) {
1.419     raeburn  7241: 	    my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
                   7242: 				                     $data->[$status_index],
                   7243:                                                      $data->[$start_index],
                   7244:                                                      $data->[$end_index]);
                   7245:             if ($stu_status eq 'Active') {
                   7246:                 $status = 'active';
                   7247:             } elsif ($end < $now) {
                   7248:                 $status = 'previous';
                   7249:             } elsif ($start > $now) {
                   7250:                 $status = 'future';
                   7251:             } 
                   7252: 	    if ($section ne '-1' && $section !~ /^\s*$/) {
                   7253:                 if ((!defined($possible_status)) || (($status ne '') && 
                   7254:                     (grep/^\Q$status\E$/,@{$possible_status}))) { 
                   7255: 		    $sectioncount{$section}++;
                   7256:                 }
1.240     albertel 7257: 	    }
                   7258: 	}
                   7259:     }
                   7260:     my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7261:     foreach my $user (sort(keys(%courseroles))) {
                   7262: 	if ($user !~ /^(\w{2})/) { next; }
                   7263: 	my ($role) = ($user =~ /^(\w{2})/);
                   7264: 	if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419     raeburn  7265: 	my ($section,$status);
1.240     albertel 7266: 	if ($role eq 'cr' &&
                   7267: 	    $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
                   7268: 	    $section=$1;
                   7269: 	}
                   7270: 	if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
                   7271: 	if (!defined($section) || $section eq '-1') { next; }
1.419     raeburn  7272:         my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
                   7273:         if ($end == -1 && $start == -1) {
                   7274:             next; #deleted role
                   7275:         }
                   7276:         if (!defined($possible_status)) { 
                   7277:             $sectioncount{$section}++;
                   7278:         } else {
                   7279:             if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
                   7280:                 $status = 'active';
                   7281:             } elsif ($end < $now) {
                   7282:                 $status = 'future';
                   7283:             } elsif ($start > $now) {
                   7284:                 $status = 'previous';
                   7285:             }
                   7286:             if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
                   7287:                 $sectioncount{$section}++;
                   7288:             }
                   7289:         }
1.233     raeburn  7290:     }
1.366     albertel 7291:     return %sectioncount;
1.233     raeburn  7292: }
                   7293: 
1.274     raeburn  7294: ###############################################
1.294     raeburn  7295: 
                   7296: =pod
1.405     albertel 7297: 
                   7298: =item * &get_course_users()
                   7299: 
1.275     raeburn  7300: Retrieves usernames:domains for users in the specified course
                   7301: with specific role(s), and access status. 
                   7302: 
                   7303: Incoming parameters:
1.277     albertel 7304: 1. course domain
                   7305: 2. course number
                   7306: 3. access status: users must have - either active, 
1.275     raeburn  7307: previous, future, or all.
1.277     albertel 7308: 4. reference to array of permissible roles
1.288     raeburn  7309: 5. reference to array of section restrictions (optional)
                   7310: 6. reference to results object (hash of hashes).
                   7311: 7. reference to optional userdata hash
1.609     raeburn  7312: 8. reference to optional statushash
1.630     raeburn  7313: 9. flag if privileged users (except those set to unhide in
                   7314:    course settings) should be excluded    
1.609     raeburn  7315: Keys of top level results hash are roles.
1.275     raeburn  7316: Keys of inner hashes are username:domain, with 
                   7317: values set to access type.
1.288     raeburn  7318: Optional userdata hash returns an array with arguments in the 
                   7319: same order as loncoursedata::get_classlist() for student data.
                   7320: 
1.609     raeburn  7321: Optional statushash returns
                   7322: 
1.288     raeburn  7323: Entries for end, start, section and status are blank because
                   7324: of the possibility of multiple values for non-student roles.
                   7325: 
1.275     raeburn  7326: =cut
1.405     albertel 7327: 
1.275     raeburn  7328: ###############################################
1.405     albertel 7329: 
1.275     raeburn  7330: sub get_course_users {
1.630     raeburn  7331:     my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288     raeburn  7332:     my %idx = ();
1.419     raeburn  7333:     my %seclists;
1.288     raeburn  7334: 
                   7335:     $idx{udom} = &Apache::loncoursedata::CL_SDOM();
                   7336:     $idx{uname} =  &Apache::loncoursedata::CL_SNAME();
                   7337:     $idx{end} = &Apache::loncoursedata::CL_END();
                   7338:     $idx{start} = &Apache::loncoursedata::CL_START();
                   7339:     $idx{id} = &Apache::loncoursedata::CL_ID();
                   7340:     $idx{section} = &Apache::loncoursedata::CL_SECTION();
                   7341:     $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
                   7342:     $idx{status} = &Apache::loncoursedata::CL_STATUS();
                   7343: 
1.290     albertel 7344:     if (grep(/^st$/,@{$roles})) {
1.276     albertel 7345:         my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278     raeburn  7346:         my $now = time;
1.277     albertel 7347:         foreach my $student (keys(%{$classlist})) {
1.288     raeburn  7348:             my $match = 0;
1.412     raeburn  7349:             my $secmatch = 0;
1.419     raeburn  7350:             my $section = $$classlist{$student}[$idx{section}];
1.609     raeburn  7351:             my $status = $$classlist{$student}[$idx{status}];
1.419     raeburn  7352:             if ($section eq '') {
                   7353:                 $section = 'none';
                   7354:             }
1.291     albertel 7355:             if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 7356:                 if (grep(/^all$/,@{$sections})) {
1.412     raeburn  7357:                     $secmatch = 1;
                   7358:                 } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420     albertel 7359:                     if (grep(/^none$/,@{$sections})) {
1.412     raeburn  7360:                         $secmatch = 1;
                   7361:                     }
                   7362:                 } else {  
1.419     raeburn  7363: 		    if (grep(/^\Q$section\E$/,@{$sections})) {
1.412     raeburn  7364: 		        $secmatch = 1;
                   7365:                     }
1.290     albertel 7366: 		}
1.412     raeburn  7367:                 if (!$secmatch) {
                   7368:                     next;
                   7369:                 }
1.419     raeburn  7370:             }
1.275     raeburn  7371:             if (defined($$types{'active'})) {
1.288     raeburn  7372:                 if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275     raeburn  7373:                     push(@{$$users{st}{$student}},'active');
1.288     raeburn  7374:                     $match = 1;
1.275     raeburn  7375:                 }
                   7376:             }
                   7377:             if (defined($$types{'previous'})) {
1.609     raeburn  7378:                 if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275     raeburn  7379:                     push(@{$$users{st}{$student}},'previous');
1.288     raeburn  7380:                     $match = 1;
1.275     raeburn  7381:                 }
                   7382:             }
                   7383:             if (defined($$types{'future'})) {
1.609     raeburn  7384:                 if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275     raeburn  7385:                     push(@{$$users{st}{$student}},'future');
1.288     raeburn  7386:                     $match = 1;
1.275     raeburn  7387:                 }
                   7388:             }
1.609     raeburn  7389:             if ($match) {
                   7390:                 push(@{$seclists{$student}},$section);
                   7391:                 if (ref($userdata) eq 'HASH') {
                   7392:                     $$userdata{$student} = $$classlist{$student};
                   7393:                 }
                   7394:                 if (ref($statushash) eq 'HASH') {
                   7395:                     $statushash->{$student}{'st'}{$section} = $status;
                   7396:                 }
1.288     raeburn  7397:             }
1.275     raeburn  7398:         }
                   7399:     }
1.412     raeburn  7400:     if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439     raeburn  7401:         my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7402:         my $now = time;
1.609     raeburn  7403:         my %displaystatus = ( previous => 'Expired',
                   7404:                               active   => 'Active',
                   7405:                               future   => 'Future',
                   7406:                             );
1.630     raeburn  7407:         my %nothide;
                   7408:         if ($hidepriv) {
                   7409:             my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
                   7410:             foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
                   7411:                 if ($user !~ /:/) {
                   7412:                     $nothide{join(':',split(/[\@]/,$user))}=1;
                   7413:                 } else {
                   7414:                     $nothide{$user} = 1;
                   7415:                 }
                   7416:             }
                   7417:         }
1.439     raeburn  7418:         foreach my $person (sort(keys(%coursepersonnel))) {
1.288     raeburn  7419:             my $match = 0;
1.412     raeburn  7420:             my $secmatch = 0;
1.439     raeburn  7421:             my $status;
1.412     raeburn  7422:             my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275     raeburn  7423:             $user =~ s/:$//;
1.439     raeburn  7424:             my ($end,$start) = split(/:/,$coursepersonnel{$person});
                   7425:             if ($end == -1 || $start == -1) {
                   7426:                 next;
                   7427:             }
                   7428:             if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
                   7429:                 (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412     raeburn  7430:                 my ($uname,$udom) = split(/:/,$user);
                   7431:                 if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 7432:                     if (grep(/^all$/,@{$sections})) {
1.412     raeburn  7433:                         $secmatch = 1;
                   7434:                     } elsif ($usec eq '') {
1.420     albertel 7435:                         if (grep(/^none$/,@{$sections})) {
1.412     raeburn  7436:                             $secmatch = 1;
                   7437:                         }
                   7438:                     } else {
                   7439:                         if (grep(/^\Q$usec\E$/,@{$sections})) {
                   7440:                             $secmatch = 1;
                   7441:                         }
                   7442:                     }
                   7443:                     if (!$secmatch) {
                   7444:                         next;
                   7445:                     }
1.288     raeburn  7446:                 }
1.419     raeburn  7447:                 if ($usec eq '') {
                   7448:                     $usec = 'none';
                   7449:                 }
1.275     raeburn  7450:                 if ($uname ne '' && $udom ne '') {
1.630     raeburn  7451:                     if ($hidepriv) {
                   7452:                         if ((&Apache::lonnet::privileged($uname,$udom)) &&
                   7453:                             (!$nothide{$uname.':'.$udom})) {
                   7454:                             next;
                   7455:                         }
                   7456:                     }
1.503     raeburn  7457:                     if ($end > 0 && $end < $now) {
1.439     raeburn  7458:                         $status = 'previous';
                   7459:                     } elsif ($start > $now) {
                   7460:                         $status = 'future';
                   7461:                     } else {
                   7462:                         $status = 'active';
                   7463:                     }
1.277     albertel 7464:                     foreach my $type (keys(%{$types})) { 
1.275     raeburn  7465:                         if ($status eq $type) {
1.420     albertel 7466:                             if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419     raeburn  7467:                                 push(@{$$users{$role}{$user}},$type);
                   7468:                             }
1.288     raeburn  7469:                             $match = 1;
                   7470:                         }
                   7471:                     }
1.419     raeburn  7472:                     if (($match) && (ref($userdata) eq 'HASH')) {
                   7473:                         if (!exists($$userdata{$uname.':'.$udom})) {
                   7474: 			    &get_user_info($udom,$uname,\%idx,$userdata);
                   7475:                         }
1.420     albertel 7476:                         if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419     raeburn  7477:                             push(@{$seclists{$uname.':'.$udom}},$usec);
                   7478:                         }
1.609     raeburn  7479:                         if (ref($statushash) eq 'HASH') {
                   7480:                             $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
                   7481:                         }
1.275     raeburn  7482:                     }
                   7483:                 }
                   7484:             }
                   7485:         }
1.290     albertel 7486:         if (grep(/^ow$/,@{$roles})) {
1.279     raeburn  7487:             if ((defined($cdom)) && (defined($cnum))) {
                   7488:                 my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
                   7489:                 if ( defined($csettings{'internal.courseowner'}) ) {
                   7490:                     my $owner = $csettings{'internal.courseowner'};
1.609     raeburn  7491:                     next if ($owner eq '');
                   7492:                     my ($ownername,$ownerdom);
                   7493:                     if ($owner =~ /^([^:]+):([^:]+)$/) {
                   7494:                         $ownername = $1;
                   7495:                         $ownerdom = $2;
                   7496:                     } else {
                   7497:                         $ownername = $owner;
                   7498:                         $ownerdom = $cdom;
                   7499:                         $owner = $ownername.':'.$ownerdom;
1.439     raeburn  7500:                     }
                   7501:                     @{$$users{'ow'}{$owner}} = 'any';
1.290     albertel 7502:                     if (defined($userdata) && 
1.609     raeburn  7503: 			!exists($$userdata{$owner})) {
                   7504: 			&get_user_info($ownerdom,$ownername,\%idx,$userdata);
                   7505:                         if (!grep(/^none$/,@{$seclists{$owner}})) {
                   7506:                             push(@{$seclists{$owner}},'none');
                   7507:                         }
                   7508:                         if (ref($statushash) eq 'HASH') {
                   7509:                             $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419     raeburn  7510:                         }
1.290     albertel 7511: 		    }
1.279     raeburn  7512:                 }
                   7513:             }
                   7514:         }
1.419     raeburn  7515:         foreach my $user (keys(%seclists)) {
                   7516:             @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
                   7517:             $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
                   7518:         }
1.275     raeburn  7519:     }
                   7520:     return;
                   7521: }
                   7522: 
1.288     raeburn  7523: sub get_user_info {
                   7524:     my ($udom,$uname,$idx,$userdata) = @_;
1.289     albertel 7525:     $$userdata{$uname.':'.$udom}[$$idx{fullname}] = 
                   7526: 	&plainname($uname,$udom,'lastname');
1.291     albertel 7527:     $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297     raeburn  7528:     $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609     raeburn  7529:     my %idhash =  &Apache::lonnet::idrget($udom,($uname));
                   7530:     $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname}; 
1.288     raeburn  7531:     return;
                   7532: }
1.275     raeburn  7533: 
1.472     raeburn  7534: ###############################################
                   7535: 
                   7536: =pod
                   7537: 
                   7538: =item * &get_user_quota()
                   7539: 
                   7540: Retrieves quota assigned for storage of portfolio files for a user  
                   7541: 
                   7542: Incoming parameters:
                   7543: 1. user's username
                   7544: 2. user's domain
                   7545: 
                   7546: Returns:
1.536     raeburn  7547: 1. Disk quota (in Mb) assigned to student.
                   7548: 2. (Optional) Type of setting: custom or default
                   7549:    (individually assigned or default for user's 
                   7550:    institutional status).
                   7551: 3. (Optional) - User's institutional status (e.g., faculty, staff
                   7552:    or student - types as defined in localenroll::inst_usertypes 
                   7553:    for user's domain, which determines default quota for user.
                   7554: 4. (Optional) - Default quota which would apply to the user.
1.472     raeburn  7555: 
                   7556: If a value has been stored in the user's environment, 
1.536     raeburn  7557: it will return that, otherwise it returns the maximal default
                   7558: defined for the user's instituional status(es) in the domain.
1.472     raeburn  7559: 
                   7560: =cut
                   7561: 
                   7562: ###############################################
                   7563: 
                   7564: 
                   7565: sub get_user_quota {
                   7566:     my ($uname,$udom) = @_;
1.536     raeburn  7567:     my ($quota,$quotatype,$settingstatus,$defquota);
1.472     raeburn  7568:     if (!defined($udom)) {
                   7569:         $udom = $env{'user.domain'};
                   7570:     }
                   7571:     if (!defined($uname)) {
                   7572:         $uname = $env{'user.name'};
                   7573:     }
                   7574:     if (($udom eq '' || $uname eq '') ||
                   7575:         ($udom eq 'public') && ($uname eq 'public')) {
                   7576:         $quota = 0;
1.536     raeburn  7577:         $quotatype = 'default';
                   7578:         $defquota = 0; 
1.472     raeburn  7579:     } else {
1.536     raeburn  7580:         my $inststatus;
1.472     raeburn  7581:         if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
                   7582:             $quota = $env{'environment.portfolioquota'};
1.536     raeburn  7583:             $inststatus = $env{'environment.inststatus'};
1.472     raeburn  7584:         } else {
1.536     raeburn  7585:             my %userenv = 
                   7586:                 &Apache::lonnet::get('environment',['portfolioquota',
                   7587:                                      'inststatus'],$udom,$uname);
1.472     raeburn  7588:             my ($tmp) = keys(%userenv);
                   7589:             if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   7590:                 $quota = $userenv{'portfolioquota'};
1.536     raeburn  7591:                 $inststatus = $userenv{'inststatus'};
1.472     raeburn  7592:             } else {
                   7593:                 undef(%userenv);
                   7594:             }
                   7595:         }
1.536     raeburn  7596:         ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472     raeburn  7597:         if ($quota eq '') {
1.536     raeburn  7598:             $quota = $defquota;
                   7599:             $quotatype = 'default';
                   7600:         } else {
                   7601:             $quotatype = 'custom';
1.472     raeburn  7602:         }
                   7603:     }
1.536     raeburn  7604:     if (wantarray) {
                   7605:         return ($quota,$quotatype,$settingstatus,$defquota);
                   7606:     } else {
                   7607:         return $quota;
                   7608:     }
1.472     raeburn  7609: }
                   7610: 
                   7611: ###############################################
                   7612: 
                   7613: =pod
                   7614: 
                   7615: =item * &default_quota()
                   7616: 
1.536     raeburn  7617: Retrieves default quota assigned for storage of user portfolio files,
                   7618: given an (optional) user's institutional status.
1.472     raeburn  7619: 
                   7620: Incoming parameters:
                   7621: 1. domain
1.536     raeburn  7622: 2. (Optional) institutional status(es).  This is a : separated list of 
                   7623:    status types (e.g., faculty, staff, student etc.)
                   7624:    which apply to the user for whom the default is being retrieved.
                   7625:    If the institutional status string in undefined, the domain
                   7626:    default quota will be returned. 
1.472     raeburn  7627: 
                   7628: Returns:
                   7629: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536     raeburn  7630: 2. (Optional) institutional type which determined the value of the
                   7631:    default quota.
1.472     raeburn  7632: 
                   7633: If a value has been stored in the domain's configuration db,
                   7634: it will return that, otherwise it returns 20 (for backwards 
                   7635: compatibility with domains which have not set up a configuration
                   7636: db file; the original statically defined portfolio quota was 20 Mb). 
                   7637: 
1.536     raeburn  7638: If the user's status includes multiple types (e.g., staff and student),
                   7639: the largest default quota which applies to the user determines the
                   7640: default quota returned.
                   7641: 
1.780     raeburn  7642: =back
                   7643: 
1.472     raeburn  7644: =cut
                   7645: 
                   7646: ###############################################
                   7647: 
                   7648: 
                   7649: sub default_quota {
1.536     raeburn  7650:     my ($udom,$inststatus) = @_;
                   7651:     my ($defquota,$settingstatus);
                   7652:     my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622     raeburn  7653:                                             ['quotas'],$udom);
                   7654:     if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536     raeburn  7655:         if ($inststatus ne '') {
1.765     raeburn  7656:             my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536     raeburn  7657:             foreach my $item (@statuses) {
1.711     raeburn  7658:                 if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7659:                     if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
                   7660:                         if ($defquota eq '') {
                   7661:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7662:                             $settingstatus = $item;
                   7663:                         } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
                   7664:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7665:                             $settingstatus = $item;
                   7666:                         }
                   7667:                     }
                   7668:                 } else {
                   7669:                     if ($quotahash{'quotas'}{$item} ne '') {
                   7670:                         if ($defquota eq '') {
                   7671:                             $defquota = $quotahash{'quotas'}{$item};
                   7672:                             $settingstatus = $item;
                   7673:                         } elsif ($quotahash{'quotas'}{$item} > $defquota) {
                   7674:                             $defquota = $quotahash{'quotas'}{$item};
                   7675:                             $settingstatus = $item;
                   7676:                         }
1.536     raeburn  7677:                     }
                   7678:                 }
                   7679:             }
                   7680:         }
                   7681:         if ($defquota eq '') {
1.711     raeburn  7682:             if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7683:                 $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
                   7684:             } else {
                   7685:                 $defquota = $quotahash{'quotas'}{'default'};
                   7686:             }
1.536     raeburn  7687:             $settingstatus = 'default';
                   7688:         }
                   7689:     } else {
                   7690:         $settingstatus = 'default';
                   7691:         $defquota = 20;
                   7692:     }
                   7693:     if (wantarray) {
                   7694:         return ($defquota,$settingstatus);
1.472     raeburn  7695:     } else {
1.536     raeburn  7696:         return $defquota;
1.472     raeburn  7697:     }
                   7698: }
                   7699: 
1.384     raeburn  7700: sub get_secgrprole_info {
                   7701:     my ($cdom,$cnum,$needroles,$type)  = @_;
                   7702:     my %sections_count = &get_sections($cdom,$cnum);
                   7703:     my @sections =  (sort {$a <=> $b} keys(%sections_count));
                   7704:     my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
                   7705:     my @groups = sort(keys(%curr_groups));
                   7706:     my $allroles = [];
                   7707:     my $rolehash;
                   7708:     my $accesshash = {
                   7709:                      active => 'Currently has access',
                   7710:                      future => 'Will have future access',
                   7711:                      previous => 'Previously had access',
                   7712:                   };
                   7713:     if ($needroles) {
                   7714:         $rolehash = {'all' => 'all'};
1.385     albertel 7715:         my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7716: 	if (&Apache::lonnet::error(%user_roles)) {
                   7717: 	    undef(%user_roles);
                   7718: 	}
                   7719:         foreach my $item (keys(%user_roles)) {
1.384     raeburn  7720:             my ($role)=split(/\:/,$item,2);
                   7721:             if ($role eq 'cr') { next; }
                   7722:             if ($role =~ /^cr/) {
                   7723:                 $$rolehash{$role} = (split('/',$role))[3];
                   7724:             } else {
                   7725:                 $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
                   7726:             }
                   7727:         }
                   7728:         foreach my $key (sort(keys(%{$rolehash}))) {
                   7729:             push(@{$allroles},$key);
                   7730:         }
                   7731:         push (@{$allroles},'st');
                   7732:         $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
                   7733:     }
                   7734:     return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
                   7735: }
                   7736: 
1.555     raeburn  7737: sub user_picker {
1.994     raeburn  7738:     my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555     raeburn  7739:     my $currdom = $dom;
                   7740:     my %curr_selected = (
                   7741:                         srchin => 'dom',
1.580     raeburn  7742:                         srchby => 'lastname',
1.555     raeburn  7743:                       );
                   7744:     my $srchterm;
1.625     raeburn  7745:     if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555     raeburn  7746:         if ($srch->{'srchby'} ne '') {
                   7747:             $curr_selected{'srchby'} = $srch->{'srchby'};
                   7748:         }
                   7749:         if ($srch->{'srchin'} ne '') {
                   7750:             $curr_selected{'srchin'} = $srch->{'srchin'};
                   7751:         }
                   7752:         if ($srch->{'srchtype'} ne '') {
                   7753:             $curr_selected{'srchtype'} = $srch->{'srchtype'};
                   7754:         }
                   7755:         if ($srch->{'srchdomain'} ne '') {
                   7756:             $currdom = $srch->{'srchdomain'};
                   7757:         }
                   7758:         $srchterm = $srch->{'srchterm'};
                   7759:     }
                   7760:     my %lt=&Apache::lonlocal::texthash(
1.573     raeburn  7761:                     'usr'       => 'Search criteria',
1.563     raeburn  7762:                     'doma'      => 'Domain/institution to search',
1.558     albertel 7763:                     'uname'     => 'username',
                   7764:                     'lastname'  => 'last name',
1.555     raeburn  7765:                     'lastfirst' => 'last name, first name',
1.558     albertel 7766:                     'crs'       => 'in this course',
1.576     raeburn  7767:                     'dom'       => 'in selected LON-CAPA domain', 
1.558     albertel 7768:                     'alc'       => 'all LON-CAPA',
1.573     raeburn  7769:                     'instd'     => 'in institutional directory for selected domain',
1.558     albertel 7770:                     'exact'     => 'is',
                   7771:                     'contains'  => 'contains',
1.569     raeburn  7772:                     'begins'    => 'begins with',
1.571     raeburn  7773:                     'youm'      => "You must include some text to search for.",
                   7774:                     'thte'      => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
                   7775:                     'thet'      => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
                   7776:                     'yomc'      => "You must choose a domain when using an institutional directory search.",
                   7777:                     'ymcd'      => "You must choose a domain when using a domain search.",
                   7778:                     'whus'      => "When using searching by last,first you must include a comma as separator between last name and first name.",
                   7779:                     'whse'      => "When searching by last,first you must include at least one character in the first name.",
                   7780:                      'thfo'     => "The following need to be corrected before the search can be run:",
1.555     raeburn  7781:                                        );
1.563     raeburn  7782:     my $domform = &select_dom_form($currdom,'srchdomain',1,1);
                   7783:     my $srchinsel = ' <select name="srchin">';
1.555     raeburn  7784: 
                   7785:     my @srchins = ('crs','dom','alc','instd');
                   7786: 
                   7787:     foreach my $option (@srchins) {
                   7788:         # FIXME 'alc' option unavailable until 
                   7789:         #       loncreateuser::print_user_query_page()
                   7790:         #       has been completed.
                   7791:         next if ($option eq 'alc');
1.880     raeburn  7792:         next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));  
1.555     raeburn  7793:         next if ($option eq 'crs' && !$env{'request.course.id'});
1.563     raeburn  7794:         if ($curr_selected{'srchin'} eq $option) {
                   7795:             $srchinsel .= ' 
                   7796:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7797:         } else {
                   7798:             $srchinsel .= '
                   7799:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7800:         }
1.555     raeburn  7801:     }
1.563     raeburn  7802:     $srchinsel .= "\n  </select>\n";
1.555     raeburn  7803: 
                   7804:     my $srchbysel =  ' <select name="srchby">';
1.580     raeburn  7805:     foreach my $option ('lastname','lastfirst','uname') {
1.555     raeburn  7806:         if ($curr_selected{'srchby'} eq $option) {
                   7807:             $srchbysel .= '
                   7808:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7809:         } else {
                   7810:             $srchbysel .= '
                   7811:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7812:          }
                   7813:     }
                   7814:     $srchbysel .= "\n  </select>\n";
                   7815: 
                   7816:     my $srchtypesel = ' <select name="srchtype">';
1.580     raeburn  7817:     foreach my $option ('begins','contains','exact') {
1.555     raeburn  7818:         if ($curr_selected{'srchtype'} eq $option) {
                   7819:             $srchtypesel .= '
                   7820:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7821:         } else {
                   7822:             $srchtypesel .= '
                   7823:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7824:         }
                   7825:     }
                   7826:     $srchtypesel .= "\n  </select>\n";
                   7827: 
1.558     albertel 7828:     my ($newuserscript,$new_user_create);
1.994     raeburn  7829:     my $context_dom = $env{'request.role.domain'};
                   7830:     if ($context eq 'requestcrs') {
                   7831:         if ($env{'form.coursedom'} ne '') { 
                   7832:             $context_dom = $env{'form.coursedom'};
                   7833:         }
                   7834:     }
1.556     raeburn  7835:     if ($forcenewuser) {
1.576     raeburn  7836:         if (ref($srch) eq 'HASH') {
1.994     raeburn  7837:             if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627     raeburn  7838:                 if ($cancreate) {
                   7839:                     $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>';
                   7840:                 } else {
1.799     bisitz   7841:                     my $helplink = 'javascript:helpMenu('."'display'".')';
1.627     raeburn  7842:                     my %usertypetext = (
                   7843:                         official   => 'institutional',
                   7844:                         unofficial => 'non-institutional',
                   7845:                     );
1.799     bisitz   7846:                     $new_user_create = '<p class="LC_warning">'
                   7847:                                       .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
                   7848:                                       .' '
                   7849:                                       .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
                   7850:                                           ,'<a href="'.$helplink.'">','</a>')
                   7851:                                       .'</p><br />';
1.627     raeburn  7852:                 }
1.576     raeburn  7853:             }
                   7854:         }
                   7855: 
1.556     raeburn  7856:         $newuserscript = <<"ENDSCRIPT";
                   7857: 
1.570     raeburn  7858: function setSearch(createnew,callingForm) {
1.556     raeburn  7859:     if (createnew == 1) {
1.570     raeburn  7860:         for (var i=0; i<callingForm.srchby.length; i++) {
                   7861:             if (callingForm.srchby.options[i].value == 'uname') {
                   7862:                 callingForm.srchby.selectedIndex = i;
1.556     raeburn  7863:             }
                   7864:         }
1.570     raeburn  7865:         for (var i=0; i<callingForm.srchin.length; i++) {
                   7866:             if ( callingForm.srchin.options[i].value == 'dom') {
                   7867: 		callingForm.srchin.selectedIndex = i;
1.556     raeburn  7868:             }
                   7869:         }
1.570     raeburn  7870:         for (var i=0; i<callingForm.srchtype.length; i++) {
                   7871:             if (callingForm.srchtype.options[i].value == 'exact') {
                   7872:                 callingForm.srchtype.selectedIndex = i;
1.556     raeburn  7873:             }
                   7874:         }
1.570     raeburn  7875:         for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994     raeburn  7876:             if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570     raeburn  7877:                 callingForm.srchdomain.selectedIndex = i;
1.556     raeburn  7878:             }
                   7879:         }
                   7880:     }
                   7881: }
                   7882: ENDSCRIPT
1.558     albertel 7883: 
1.556     raeburn  7884:     }
                   7885: 
1.555     raeburn  7886:     my $output = <<"END_BLOCK";
1.556     raeburn  7887: <script type="text/javascript">
1.824     bisitz   7888: // <![CDATA[
1.570     raeburn  7889: function validateEntry(callingForm) {
1.558     albertel 7890: 
1.556     raeburn  7891:     var checkok = 1;
1.558     albertel 7892:     var srchin;
1.570     raeburn  7893:     for (var i=0; i<callingForm.srchin.length; i++) {
                   7894: 	if ( callingForm.srchin[i].checked ) {
                   7895: 	    srchin = callingForm.srchin[i].value;
1.558     albertel 7896: 	}
                   7897:     }
                   7898: 
1.570     raeburn  7899:     var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
                   7900:     var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
                   7901:     var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
                   7902:     var srchterm =  callingForm.srchterm.value;
                   7903:     var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556     raeburn  7904:     var msg = "";
                   7905: 
                   7906:     if (srchterm == "") {
                   7907:         checkok = 0;
1.571     raeburn  7908:         msg += "$lt{'youm'}\\n";
1.556     raeburn  7909:     }
                   7910: 
1.569     raeburn  7911:     if (srchtype== 'begins') {
                   7912:         if (srchterm.length < 2) {
                   7913:             checkok = 0;
1.571     raeburn  7914:             msg += "$lt{'thte'}\\n";
1.569     raeburn  7915:         }
                   7916:     }
                   7917: 
1.556     raeburn  7918:     if (srchtype== 'contains') {
                   7919:         if (srchterm.length < 3) {
                   7920:             checkok = 0;
1.571     raeburn  7921:             msg += "$lt{'thet'}\\n";
1.556     raeburn  7922:         }
                   7923:     }
                   7924:     if (srchin == 'instd') {
                   7925:         if (srchdomain == '') {
                   7926:             checkok = 0;
1.571     raeburn  7927:             msg += "$lt{'yomc'}\\n";
1.556     raeburn  7928:         }
                   7929:     }
                   7930:     if (srchin == 'dom') {
                   7931:         if (srchdomain == '') {
                   7932:             checkok = 0;
1.571     raeburn  7933:             msg += "$lt{'ymcd'}\\n";
1.556     raeburn  7934:         }
                   7935:     }
                   7936:     if (srchby == 'lastfirst') {
                   7937:         if (srchterm.indexOf(",") == -1) {
                   7938:             checkok = 0;
1.571     raeburn  7939:             msg += "$lt{'whus'}\\n";
1.556     raeburn  7940:         }
                   7941:         if (srchterm.indexOf(",") == srchterm.length -1) {
                   7942:             checkok = 0;
1.571     raeburn  7943:             msg += "$lt{'whse'}\\n";
1.556     raeburn  7944:         }
                   7945:     }
                   7946:     if (checkok == 0) {
1.571     raeburn  7947:         alert("$lt{'thfo'}\\n"+msg);
1.556     raeburn  7948:         return;
                   7949:     }
                   7950:     if (checkok == 1) {
1.570     raeburn  7951:         callingForm.submit();
1.556     raeburn  7952:     }
                   7953: }
                   7954: 
                   7955: $newuserscript
                   7956: 
1.824     bisitz   7957: // ]]>
1.556     raeburn  7958: </script>
1.558     albertel 7959: 
                   7960: $new_user_create
                   7961: 
1.555     raeburn  7962: END_BLOCK
1.558     albertel 7963: 
1.876     raeburn  7964:     $output .= &Apache::lonhtmlcommon::start_pick_box().
                   7965:                &Apache::lonhtmlcommon::row_title($lt{'doma'}).
                   7966:                $domform.
                   7967:                &Apache::lonhtmlcommon::row_closure().
                   7968:                &Apache::lonhtmlcommon::row_title($lt{'usr'}).
                   7969:                $srchbysel.
                   7970:                $srchtypesel. 
                   7971:                '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
                   7972:                $srchinsel.
                   7973:                &Apache::lonhtmlcommon::row_closure(1). 
                   7974:                &Apache::lonhtmlcommon::end_pick_box().
                   7975:                '<br />';
1.555     raeburn  7976:     return $output;
                   7977: }
                   7978: 
1.612     raeburn  7979: sub user_rule_check {
1.615     raeburn  7980:     my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612     raeburn  7981:     my $response;
                   7982:     if (ref($usershash) eq 'HASH') {
                   7983:         foreach my $user (keys(%{$usershash})) {
                   7984:             my ($uname,$udom) = split(/:/,$user);
                   7985:             next if ($udom eq '' || $uname eq '');
1.615     raeburn  7986:             my ($id,$newuser);
1.612     raeburn  7987:             if (ref($usershash->{$user}) eq 'HASH') {
1.615     raeburn  7988:                 $newuser = $usershash->{$user}->{'newuser'};
1.612     raeburn  7989:                 $id = $usershash->{$user}->{'id'};
                   7990:             }
                   7991:             my $inst_response;
                   7992:             if (ref($checks) eq 'HASH') {
                   7993:                 if (defined($checks->{'username'})) {
1.615     raeburn  7994:                     ($inst_response,%{$inst_results->{$user}}) = 
1.612     raeburn  7995:                         &Apache::lonnet::get_instuser($udom,$uname);
                   7996:                 } elsif (defined($checks->{'id'})) {
1.615     raeburn  7997:                     ($inst_response,%{$inst_results->{$user}}) =
1.612     raeburn  7998:                         &Apache::lonnet::get_instuser($udom,undef,$id);
                   7999:                 }
1.615     raeburn  8000:             } else {
                   8001:                 ($inst_response,%{$inst_results->{$user}}) =
                   8002:                     &Apache::lonnet::get_instuser($udom,$uname);
                   8003:                 return;
1.612     raeburn  8004:             }
1.615     raeburn  8005:             if (!$got_rules->{$udom}) {
1.612     raeburn  8006:                 my %domconfig = &Apache::lonnet::get_dom('configuration',
                   8007:                                                   ['usercreation'],$udom);
                   8008:                 if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615     raeburn  8009:                     foreach my $item ('username','id') {
1.612     raeburn  8010:                         if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
                   8011:                             $$curr_rules{$udom}{$item} = 
                   8012:                                 $domconfig{'usercreation'}{$item.'_rule'};
1.585     raeburn  8013:                         }
                   8014:                     }
                   8015:                 }
1.615     raeburn  8016:                 $got_rules->{$udom} = 1;  
1.585     raeburn  8017:             }
1.612     raeburn  8018:             foreach my $item (keys(%{$checks})) {
                   8019:                 if (ref($$curr_rules{$udom}) eq 'HASH') {
                   8020:                     if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
                   8021:                         if (@{$$curr_rules{$udom}{$item}} > 0) {
                   8022:                             my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
                   8023:                             foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
                   8024:                                 if ($rule_check{$rule}) {
                   8025:                                     $$rulematch{$user}{$item} = $rule;
                   8026:                                     if ($inst_response eq 'ok') {
1.615     raeburn  8027:                                         if (ref($inst_results) eq 'HASH') {
                   8028:                                             if (ref($inst_results->{$user}) eq 'HASH') {
                   8029:                                                 if (keys(%{$inst_results->{$user}}) == 0) {
                   8030:                                                     $$alerts{$item}{$udom}{$uname} = 1;
                   8031:                                                 }
1.612     raeburn  8032:                                             }
                   8033:                                         }
1.615     raeburn  8034:                                     }
                   8035:                                     last;
1.585     raeburn  8036:                                 }
                   8037:                             }
                   8038:                         }
                   8039:                     }
                   8040:                 }
                   8041:             }
                   8042:         }
                   8043:     }
1.612     raeburn  8044:     return;
                   8045: }
                   8046: 
                   8047: sub user_rule_formats {
                   8048:     my ($domain,$domdesc,$curr_rules,$check) = @_;
                   8049:     my %text = ( 
                   8050:                  'username' => 'Usernames',
                   8051:                  'id'       => 'IDs',
                   8052:                );
                   8053:     my $output;
                   8054:     my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
                   8055:     if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
                   8056:         if (@{$ruleorder} > 0) {
                   8057:             $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>';
                   8058:             foreach my $rule (@{$ruleorder}) {
                   8059:                 if (ref($curr_rules) eq 'ARRAY') {
                   8060:                     if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
                   8061:                         if (ref($rules->{$rule}) eq 'HASH') {
                   8062:                             $output .= '<li>'.$rules->{$rule}{'name'}.': '.
                   8063:                                         $rules->{$rule}{'desc'}.'</li>';
                   8064:                         }
                   8065:                     }
                   8066:                 }
                   8067:             }
                   8068:             $output .= '</ul>';
                   8069:         }
                   8070:     }
                   8071:     return $output;
                   8072: }
                   8073: 
                   8074: sub instrule_disallow_msg {
1.615     raeburn  8075:     my ($checkitem,$domdesc,$count,$mode) = @_;
1.612     raeburn  8076:     my $response;
                   8077:     my %text = (
                   8078:                   item   => 'username',
                   8079:                   items  => 'usernames',
                   8080:                   match  => 'matches',
                   8081:                   do     => 'does',
                   8082:                   action => 'a username',
                   8083:                   one    => 'one',
                   8084:                );
                   8085:     if ($count > 1) {
                   8086:         $text{'item'} = 'usernames';
                   8087:         $text{'match'} ='match';
                   8088:         $text{'do'} = 'do';
                   8089:         $text{'action'} = 'usernames',
                   8090:         $text{'one'} = 'ones';
                   8091:     }
                   8092:     if ($checkitem eq 'id') {
                   8093:         $text{'items'} = 'IDs';
                   8094:         $text{'item'} = 'ID';
                   8095:         $text{'action'} = 'an ID';
1.615     raeburn  8096:         if ($count > 1) {
                   8097:             $text{'item'} = 'IDs';
                   8098:             $text{'action'} = 'IDs';
                   8099:         }
1.612     raeburn  8100:     }
1.674     bisitz   8101:     $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  8102:     if ($mode eq 'upload') {
                   8103:         if ($checkitem eq 'username') {
                   8104:             $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'}.");
                   8105:         } elsif ($checkitem eq 'id') {
1.674     bisitz   8106:             $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  8107:         }
1.669     raeburn  8108:     } elsif ($mode eq 'selfcreate') {
                   8109:         if ($checkitem eq 'id') {
                   8110:             $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.");
                   8111:         }
1.615     raeburn  8112:     } else {
                   8113:         if ($checkitem eq 'username') {
                   8114:             $response .= &mt("You must choose $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
                   8115:         } elsif ($checkitem eq 'id') {
                   8116:             $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.");
                   8117:         }
1.612     raeburn  8118:     }
                   8119:     return $response;
1.585     raeburn  8120: }
                   8121: 
1.624     raeburn  8122: sub personal_data_fieldtitles {
                   8123:     my %fieldtitles = &Apache::lonlocal::texthash (
                   8124:                         id => 'Student/Employee ID',
                   8125:                         permanentemail => 'E-mail address',
                   8126:                         lastname => 'Last Name',
                   8127:                         firstname => 'First Name',
                   8128:                         middlename => 'Middle Name',
                   8129:                         generation => 'Generation',
                   8130:                         gen => 'Generation',
1.765     raeburn  8131:                         inststatus => 'Affiliation',
1.624     raeburn  8132:                    );
                   8133:     return %fieldtitles;
                   8134: }
                   8135: 
1.642     raeburn  8136: sub sorted_inst_types {
                   8137:     my ($dom) = @_;
                   8138:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
                   8139:     my $othertitle = &mt('All users');
                   8140:     if ($env{'request.course.id'}) {
1.668     raeburn  8141:         $othertitle  = &mt('Any users');
1.642     raeburn  8142:     }
                   8143:     my @types;
                   8144:     if (ref($order) eq 'ARRAY') {
                   8145:         @types = @{$order};
                   8146:     }
                   8147:     if (@types == 0) {
                   8148:         if (ref($usertypes) eq 'HASH') {
                   8149:             @types = sort(keys(%{$usertypes}));
                   8150:         }
                   8151:     }
                   8152:     if (keys(%{$usertypes}) > 0) {
                   8153:         $othertitle = &mt('Other users');
                   8154:     }
                   8155:     return ($othertitle,$usertypes,\@types);
                   8156: }
                   8157: 
1.645     raeburn  8158: sub get_institutional_codes {
                   8159:     my ($settings,$allcourses,$LC_code) = @_;
                   8160: # Get complete list of course sections to update
                   8161:     my @currsections = ();
                   8162:     my @currxlists = ();
                   8163:     my $coursecode = $$settings{'internal.coursecode'};
                   8164: 
                   8165:     if ($$settings{'internal.sectionnums'} ne '') {
                   8166:         @currsections = split(/,/,$$settings{'internal.sectionnums'});
                   8167:     }
                   8168: 
                   8169:     if ($$settings{'internal.crosslistings'} ne '') {
                   8170:         @currxlists = split(/,/,$$settings{'internal.crosslistings'});
                   8171:     }
                   8172: 
                   8173:     if (@currxlists > 0) {
                   8174:         foreach (@currxlists) {
                   8175:             if (m/^([^:]+):(\w*)$/) {
                   8176:                 unless (grep/^$1$/,@{$allcourses}) {
                   8177:                     push @{$allcourses},$1;
                   8178:                     $$LC_code{$1} = $2;
                   8179:                 }
                   8180:             }
                   8181:         }
                   8182:     }
                   8183:  
                   8184:     if (@currsections > 0) {
                   8185:         foreach (@currsections) {
                   8186:             if (m/^(\w+):(\w*)$/) {
                   8187:                 my $sec = $coursecode.$1;
                   8188:                 my $lc_sec = $2;
                   8189:                 unless (grep/^$sec$/,@{$allcourses}) {
                   8190:                     push @{$allcourses},$sec;
                   8191:                     $$LC_code{$sec} = $lc_sec;
                   8192:                 }
                   8193:             }
                   8194:         }
                   8195:     }
                   8196:     return;
                   8197: }
                   8198: 
1.971     raeburn  8199: sub get_standard_codeitems {
                   8200:     return ('Year','Semester','Department','Number','Section');
                   8201: }
                   8202: 
1.112     bowersj2 8203: =pod
                   8204: 
1.780     raeburn  8205: =head1 Slot Helpers
                   8206: 
                   8207: =over 4
                   8208: 
                   8209: =item * sorted_slots()
                   8210: 
                   8211: Sorts an array of slot names in order of slot start time (earliest first). 
                   8212: 
                   8213: Inputs:
                   8214: 
                   8215: =over 4
                   8216: 
                   8217: slotsarr  - Reference to array of unsorted slot names.
                   8218: 
                   8219: slots     - Reference to hash of hash, where outer hash keys are slot names.
                   8220: 
1.549     albertel 8221: =back
                   8222: 
1.780     raeburn  8223: Returns:
                   8224: 
                   8225: =over 4
                   8226: 
                   8227: sorted   - An array of slot names sorted by the start time of the slot.
                   8228: 
                   8229: =back
                   8230: 
                   8231: =back
                   8232: 
                   8233: =cut
                   8234: 
                   8235: 
                   8236: sub sorted_slots {
                   8237:     my ($slotsarr,$slots) = @_;
                   8238:     my @sorted;
                   8239:     if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
                   8240:         @sorted =
                   8241:             sort {
                   8242:                      if (ref($slots->{$a}) && ref($slots->{$b})) {
                   8243:                          return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
                   8244:                      }
                   8245:                      if (ref($slots->{$a})) { return -1;}
                   8246:                      if (ref($slots->{$b})) { return 1;}
                   8247:                      return 0;
                   8248:                  } @{$slotsarr};
                   8249:     }
                   8250:     return @sorted;
                   8251: }
                   8252: 
                   8253: 
                   8254: =pod
                   8255: 
1.549     albertel 8256: =head1 HTTP Helpers
                   8257: 
                   8258: =over 4
                   8259: 
1.648     raeburn  8260: =item * &get_unprocessed_cgi($query,$possible_names)
1.112     bowersj2 8261: 
1.258     albertel 8262: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112     bowersj2 8263: $query.  The parameters listed in $possible_names (an array reference),
1.258     albertel 8264: will be set in $env{'form.name'} if they do not already exist.
1.112     bowersj2 8265: 
                   8266: Typically called with $ENV{'QUERY_STRING'} as the first parameter.  
                   8267: $possible_names is an ref to an array of form element names.  As an example:
                   8268: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258     albertel 8269: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112     bowersj2 8270: 
                   8271: =cut
1.1       albertel 8272: 
1.6       albertel 8273: sub get_unprocessed_cgi {
1.25      albertel 8274:   my ($query,$possible_names)= @_;
1.26      matthew  8275:   # $Apache::lonxml::debug=1;
1.356     albertel 8276:   foreach my $pair (split(/&/,$query)) {
                   8277:     my ($name, $value) = split(/=/,$pair);
1.369     www      8278:     $name = &unescape($name);
1.25      albertel 8279:     if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
                   8280:       $value =~ tr/+/ /;
                   8281:       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258     albertel 8282:       unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25      albertel 8283:     }
1.16      harris41 8284:   }
1.6       albertel 8285: }
                   8286: 
1.112     bowersj2 8287: =pod
                   8288: 
1.648     raeburn  8289: =item * &cacheheader() 
1.112     bowersj2 8290: 
                   8291: returns cache-controlling header code
                   8292: 
                   8293: =cut
                   8294: 
1.7       albertel 8295: sub cacheheader {
1.258     albertel 8296:     unless ($env{'request.method'} eq 'GET') { return ''; }
1.216     albertel 8297:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
                   8298:     my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7       albertel 8299:                 <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
                   8300:                 <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216     albertel 8301:     return $output;
1.7       albertel 8302: }
                   8303: 
1.112     bowersj2 8304: =pod
                   8305: 
1.648     raeburn  8306: =item * &no_cache($r) 
1.112     bowersj2 8307: 
                   8308: specifies header code to not have cache
                   8309: 
                   8310: =cut
                   8311: 
1.9       albertel 8312: sub no_cache {
1.216     albertel 8313:     my ($r) = @_;
                   8314:     if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258     albertel 8315: 	$env{'request.method'} ne 'GET') { return ''; }
1.216     albertel 8316:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
                   8317:     $r->no_cache(1);
                   8318:     $r->header_out("Expires" => $date);
                   8319:     $r->header_out("Pragma" => "no-cache");
1.123     www      8320: }
                   8321: 
                   8322: sub content_type {
1.181     albertel 8323:     my ($r,$type,$charset) = @_;
1.299     foxr     8324:     if ($r) {
                   8325: 	#  Note that printout.pl calls this with undef for $r.
                   8326: 	&no_cache($r);
                   8327:     }
1.258     albertel 8328:     if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181     albertel 8329:     unless ($charset) {
                   8330: 	$charset=&Apache::lonlocal::current_encoding;
                   8331:     }
                   8332:     if ($charset) { $type.='; charset='.$charset; }
                   8333:     if ($r) {
                   8334: 	$r->content_type($type);
                   8335:     } else {
                   8336: 	print("Content-type: $type\n\n");
                   8337:     }
1.9       albertel 8338: }
1.25      albertel 8339: 
1.112     bowersj2 8340: =pod
                   8341: 
1.648     raeburn  8342: =item * &add_to_env($name,$value) 
1.112     bowersj2 8343: 
1.258     albertel 8344: adds $name to the %env hash with value
1.112     bowersj2 8345: $value, if $name already exists, the entry is converted to an array
                   8346: reference and $value is added to the array.
                   8347: 
                   8348: =cut
                   8349: 
1.25      albertel 8350: sub add_to_env {
                   8351:   my ($name,$value)=@_;
1.258     albertel 8352:   if (defined($env{$name})) {
                   8353:     if (ref($env{$name})) {
1.25      albertel 8354:       #already have multiple values
1.258     albertel 8355:       push(@{ $env{$name} },$value);
1.25      albertel 8356:     } else {
                   8357:       #first time seeing multiple values, convert hash entry to an arrayref
1.258     albertel 8358:       my $first=$env{$name};
                   8359:       undef($env{$name});
                   8360:       push(@{ $env{$name} },$first,$value);
1.25      albertel 8361:     }
                   8362:   } else {
1.258     albertel 8363:     $env{$name}=$value;
1.25      albertel 8364:   }
1.31      albertel 8365: }
1.149     albertel 8366: 
                   8367: =pod
                   8368: 
1.648     raeburn  8369: =item * &get_env_multiple($name) 
1.149     albertel 8370: 
1.258     albertel 8371: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149     albertel 8372: values may be defined and end up as an array ref.
                   8373: 
                   8374: returns an array of values
                   8375: 
                   8376: =cut
                   8377: 
                   8378: sub get_env_multiple {
                   8379:     my ($name) = @_;
                   8380:     my @values;
1.258     albertel 8381:     if (defined($env{$name})) {
1.149     albertel 8382:         # exists is it an array
1.258     albertel 8383:         if (ref($env{$name})) {
                   8384:             @values=@{ $env{$name} };
1.149     albertel 8385:         } else {
1.258     albertel 8386:             $values[0]=$env{$name};
1.149     albertel 8387:         }
                   8388:     }
                   8389:     return(@values);
                   8390: }
                   8391: 
1.660     raeburn  8392: sub ask_for_embedded_content {
                   8393:     my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.987     raeburn  8394:     my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges);
1.660     raeburn  8395:     my $num = 0;
1.987     raeburn  8396:     my $numremref = 0;
                   8397:     my $numinvalid = 0;
                   8398:     my $numpathchg = 0;
                   8399:     my $numexisting = 0;
                   8400:     my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath);
1.984     raeburn  8401:     if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
                   8402:         my $current_path='/';
                   8403:         if ($env{'form.currentpath'}) {
                   8404:             $current_path = $env{'form.currentpath'};
                   8405:         }
                   8406:         if ($actionurl eq '/adm/coursegrp_portfolio') {
                   8407:             $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
                   8408:             $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
                   8409:             $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
                   8410:         } else {
                   8411:             $udom = $env{'user.domain'};
                   8412:             $uname = $env{'user.name'};
                   8413:             $url = '/userfiles/portfolio';
                   8414:         }
1.987     raeburn  8415:         $toplevel = $url.'/';
1.984     raeburn  8416:         $url .= $current_path;
                   8417:         $getpropath = 1;
1.987     raeburn  8418:     } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
                   8419:              ($actionurl eq '/adm/imsimport')) { 
1.984     raeburn  8420:         ($uname,my $rest) = ($args->{'current_path'} =~ m{/priv/($match_username)/?(.*)$});
1.987     raeburn  8421:         $url = '/home/'.$uname.'/public_html/';
                   8422:         $toplevel = $url;
1.984     raeburn  8423:         if ($rest ne '') {
1.987     raeburn  8424:             $url .= $rest;
                   8425:         }
                   8426:     } elsif ($actionurl eq '/adm/coursedocs') {
                   8427:         if (ref($args) eq 'HASH') {
                   8428:            $url = $args->{'docs_url'};
                   8429:            $toplevel = $url;
                   8430:         }
                   8431:     }
                   8432:     my $now = time();
                   8433:     foreach my $embed_file (keys(%{$allfiles})) {
                   8434:         my $absolutepath;
                   8435:         if ($embed_file =~ m{^\w+://}) {
                   8436:             $newfiles{$embed_file} = 1;
                   8437:             $mapping{$embed_file} = $embed_file;
                   8438:         } else {
                   8439:             if ($embed_file =~ m{^/}) {
                   8440:                 $absolutepath = $embed_file;
                   8441:                 $embed_file =~ s{^(/+)}{};
                   8442:             }
                   8443:             if ($embed_file =~ m{/}) {
                   8444:                 my ($path,$fname) = ($embed_file =~ m{^(.+)/([^/]*)$});
                   8445:                 $path = &check_for_traversal($path,$url,$toplevel);
                   8446:                 my $item = $fname;
                   8447:                 if ($path ne '') {
                   8448:                     $item = $path.'/'.$fname;
                   8449:                     $subdependencies{$path}{$fname} = 1;
                   8450:                 } else {
                   8451:                     $dependencies{$item} = 1;
                   8452:                 }
                   8453:                 if ($absolutepath) {
                   8454:                     $mapping{$item} = $absolutepath;
                   8455:                 } else {
                   8456:                     $mapping{$item} = $embed_file;
                   8457:                 }
                   8458:             } else {
                   8459:                 $dependencies{$embed_file} = 1;
                   8460:                 if ($absolutepath) {
                   8461:                     $mapping{$embed_file} = $absolutepath;
                   8462:                 } else {
                   8463:                     $mapping{$embed_file} = $embed_file;
                   8464:                 }
                   8465:             }
1.984     raeburn  8466:         }
                   8467:     }
                   8468:     foreach my $path (keys(%subdependencies)) {
                   8469:         my %currsubfile;
                   8470:         if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) { 
                   8471:             my @subdir_list = &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
                   8472:             foreach my $line (@subdir_list) {
                   8473:                 my ($file_name,$rest) = split(/\&/,$line,2);
                   8474:                 $currsubfile{$file_name} = 1;
                   8475:             }
1.987     raeburn  8476:         } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984     raeburn  8477:             if (opendir(my $dir,$url.'/'.$path)) {
                   8478:                 my @subdir_list = grep(!/^\./,readdir($dir));
                   8479:                 map {$currsubfile{$_} = 1;} @subdir_list;
                   8480:             }
                   8481:         }
                   8482:         foreach my $file (keys(%{$subdependencies{$path}})) {
1.987     raeburn  8483:             if ($currsubfile{$file}) {
                   8484:                 my $item = $path.'/'.$file;
                   8485:                 unless ($mapping{$item} eq $item) {
                   8486:                     $pathchanges{$item} = 1;
                   8487:                 }
                   8488:                 $existing{$item} = 1;
                   8489:                 $numexisting ++;
                   8490:             } else {
                   8491:                 $newfiles{$path.'/'.$file} = 1;
1.984     raeburn  8492:             }
                   8493:         }
                   8494:     }
1.987     raeburn  8495:     my %currfile;
1.984     raeburn  8496:     if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
                   8497:         my @dir_list = &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
                   8498:         foreach my $line (@dir_list) {
                   8499:             my ($file_name,$rest) = split(/\&/,$line,2);
                   8500:             $currfile{$file_name} = 1;
                   8501:         }
1.987     raeburn  8502:     } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984     raeburn  8503:         if (opendir(my $dir,$url)) {
1.987     raeburn  8504:             my @dir_list = grep(!/^\./,readdir($dir));
1.984     raeburn  8505:             map {$currfile{$_} = 1;} @dir_list;
                   8506:         }
                   8507:     }
                   8508:     foreach my $file (keys(%dependencies)) {
1.987     raeburn  8509:         if ($currfile{$file}) {
                   8510:             unless ($mapping{$file} eq $file) {
                   8511:                 $pathchanges{$file} = 1;
                   8512:             }
                   8513:             $existing{$file} = 1;
                   8514:             $numexisting ++;
                   8515:         } else {
1.984     raeburn  8516:             $newfiles{$file} = 1;
                   8517:         }
                   8518:     }
                   8519:     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.660     raeburn  8520:         $upload_output .= &start_data_table_row().
1.987     raeburn  8521:                           '<td><span class="LC_filename">'.$embed_file.'</span>';
                   8522:         unless ($mapping{$embed_file} eq $embed_file) {
                   8523:             $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.&mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
                   8524:         }
                   8525:         $upload_output .= '</td><td>';
1.660     raeburn  8526:         if ($args->{'ignore_remote_references'}
                   8527:             && $embed_file =~ m{^\w+://}) {
                   8528:             $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
1.987     raeburn  8529:             $numremref++;
1.660     raeburn  8530:         } elsif ($args->{'error_on_invalid_names'}
                   8531:             && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
                   8532: 
1.987     raeburn  8533:             $upload_output.='<span class="LC_warning">'.&mt('Invalid characters').'</span>';
                   8534:             $numinvalid++;
1.660     raeburn  8535:         } else {
1.987     raeburn  8536:             $upload_output .= &embedded_file_element('upload_embedded',$num,
                   8537:                                                      $embed_file,\%mapping,
                   8538:                                                      $allfiles,$codebase);
                   8539:             $num++;
                   8540:         }
                   8541:         $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
                   8542:     }
                   8543:     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
                   8544:         $upload_output .= &start_data_table_row().
                   8545:                           '<td><span class="LC_filename">'.$embed_file.'</span></td>'.
                   8546:                           '<td><span class="LC_warning">'.&mt('Already exists').'</span></td>'.
                   8547:                           &Apache::loncommon::end_data_table_row()."\n";
                   8548:     }
                   8549:     if ($upload_output) {
                   8550:         $upload_output = &start_data_table().
                   8551:                          $upload_output.
                   8552:                          &end_data_table()."\n";
                   8553:     }
                   8554:     my $applies = 0;
                   8555:     if ($numremref) {
                   8556:         $applies ++;
                   8557:     }
                   8558:     if ($numinvalid) {
                   8559:         $applies ++;
                   8560:     }
                   8561:     if ($numexisting) {
                   8562:         $applies ++;
                   8563:     }
                   8564:     if ($num) {
                   8565:         $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
                   8566:                   ' method="post" enctype="multipart/form-data">'."\n".
                   8567:                   $state.
                   8568:                   '<h3>'.&mt('Upload embedded files').
                   8569:                   ':</h3>'.$upload_output.'<br />'."\n".
                   8570:                   '<input type ="hidden" name="number_embedded_items" value="'.
                   8571:                   $num.'" />'."\n";
                   8572:         if ($actionurl eq '') {
                   8573:             $output .=  '<input type="hidden" name="phase" value="three" />';
                   8574:         }
                   8575:     } elsif ($applies) {
                   8576:         $output = '<b>'.&mt('Referenced files').'</b>:<br />';
                   8577:         if ($applies > 1) {
                   8578:             $output .=  
                   8579:                 &mt('No files need to be uploaded, as one of the following applies to each reference:').'<ul>';
                   8580:             if ($numremref) {
                   8581:                 $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
                   8582:             }
                   8583:             if ($numinvalid) {
                   8584:                 $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
                   8585:             }
                   8586:             if ($numexisting) {
                   8587:                 $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
                   8588:             }
                   8589:             $output .= '</ul><br />';
                   8590:         } elsif ($numremref) {
                   8591:             $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
                   8592:         } elsif ($numinvalid) {
                   8593:             $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
                   8594:         } elsif ($numexisting) {
                   8595:             $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
                   8596:         }
                   8597:         $output .= $upload_output.'<br />';
                   8598:     }
                   8599:     my ($pathchange_output,$chgcount);
                   8600:     $chgcount = $num;
                   8601:     if (keys(%pathchanges) > 0) {
                   8602:         foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
                   8603:             if ($num) {
                   8604:                 $output .= &embedded_file_element('pathchange',$chgcount,
                   8605:                                                   $embed_file,\%mapping,
                   8606:                                                   $allfiles,$codebase);
                   8607:             } else {
                   8608:                 $pathchange_output .= 
                   8609:                     &start_data_table_row().
                   8610:                     '<td><input type ="checkbox" name="namechange" value="'.
                   8611:                     $chgcount.'" checked="checked" /></td>'.
                   8612:                     '<td>'.$mapping{$embed_file}.'</td>'.
                   8613:                     '<td>'.$embed_file.
                   8614:                     &embedded_file_element('pathchange',$numpathchg,$embed_file,
                   8615:                                            \%mapping,$allfiles,$codebase).
                   8616:                     '</td>'.&end_data_table_row();
1.660     raeburn  8617:             }
1.987     raeburn  8618:             $numpathchg ++;
                   8619:             $chgcount ++;
1.660     raeburn  8620:         }
                   8621:     }
1.984     raeburn  8622:     if ($num) {
1.987     raeburn  8623:         if ($numpathchg) {
                   8624:             $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
                   8625:                        $numpathchg.'" />'."\n";
                   8626:         }
                   8627:         if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') || 
                   8628:             ($actionurl eq '/adm/imsimport')) {
                   8629:             $output .= '<input type="hidden" name="phase" value="three" />'."\n";
                   8630:         } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
                   8631:             $output .= '<input type="hidden" name="action" value="upload_embedded" />';
                   8632:         }
                   8633:         $output .=  '<input type ="submit" value="'.&mt('Upload Listed Files').'" />'."\n".
                   8634:                     &mt('(only files for which a location has been provided will be uploaded)').'</form>'."\n";
                   8635:     } elsif ($numpathchg) {
                   8636:         my %pathchange = ();
                   8637:         $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
                   8638:         if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
                   8639:             $output .= '<p>'.&mt('or').'</p>'; 
                   8640:         } 
                   8641:     }
                   8642:     return ($output,$num,$numpathchg);
                   8643: }
                   8644: 
                   8645: sub embedded_file_element {
                   8646:     my ($context,$num,$embed_file,$mapping,$allfiles,$codebase) = @_;
                   8647:     return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
                   8648:                    (ref($codebase) eq 'HASH'));
                   8649:     my $output;
                   8650:     if ($context eq 'upload_embedded') {
                   8651:        $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
                   8652:     }
                   8653:     $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
                   8654:                &escape($embed_file).'" />';
                   8655:     unless (($context eq 'upload_embedded') && 
                   8656:             ($mapping->{$embed_file} eq $embed_file)) {
                   8657:         $output .='
                   8658:         <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
                   8659:     }
                   8660:     my $attrib;
                   8661:     if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
                   8662:         $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
                   8663:     }
                   8664:     $output .=
                   8665:         "\n\t\t".
                   8666:         '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
                   8667:         $attrib.'" />';
                   8668:     if (exists($codebase->{$mapping->{$embed_file}})) {
                   8669:         $output .=
                   8670:             "\n\t\t".
                   8671:             '<input name="codebase_'.$num.'" type="hidden" value="'.
                   8672:             &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984     raeburn  8673:     }
1.987     raeburn  8674:     return $output;
1.660     raeburn  8675: }
                   8676: 
1.661     raeburn  8677: sub upload_embedded {
                   8678:     my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987     raeburn  8679:         $current_disk_usage,$hiddenstate,$actionurl) = @_;
                   8680:     my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661     raeburn  8681:     for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
                   8682:         next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
                   8683:         my $orig_uploaded_filename =
                   8684:             $env{'form.embedded_item_'.$i.'.filename'};
1.987     raeburn  8685:         foreach my $type ('orig','ref','attrib','codebase') {
                   8686:             if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
                   8687:                 $env{'form.embedded_'.$type.'_'.$i} =
                   8688:                     &unescape($env{'form.embedded_'.$type.'_'.$i});
                   8689:             }
                   8690:         }
1.661     raeburn  8691:         my ($path,$fname) =
                   8692:             ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
                   8693:         # no path, whole string is fname
                   8694:         if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
                   8695:         $fname = &Apache::lonnet::clean_filename($fname);
                   8696:         # See if there is anything left
                   8697:         next if ($fname eq '');
                   8698: 
                   8699:         # Check if file already exists as a file or directory.
                   8700:         my ($state,$msg);
                   8701:         if ($context eq 'portfolio') {
                   8702:             my $port_path = $dirpath;
                   8703:             if ($group ne '') {
                   8704:                 $port_path = "groups/$group/$port_path";
                   8705:             }
1.987     raeburn  8706:             ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
                   8707:                                               $fname,$group,'embedded_item_'.$i,
1.661     raeburn  8708:                                               $dir_root,$port_path,$disk_quota,
                   8709:                                               $current_disk_usage,$uname,$udom);
                   8710:             if ($state eq 'will_exceed_quota'
1.984     raeburn  8711:                 || $state eq 'file_locked') {
1.661     raeburn  8712:                 $output .= $msg;
                   8713:                 next;
                   8714:             }
                   8715:         } elsif (($context eq 'author') || ($context eq 'testbank')) {
                   8716:             ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
                   8717:             if ($state eq 'exists') {
                   8718:                 $output .= $msg;
                   8719:                 next;
                   8720:             }
                   8721:         }
                   8722:         # Check if extension is valid
                   8723:         if (($fname =~ /\.(\w+)$/) &&
                   8724:             (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.987     raeburn  8725:             $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  8726:             next;
                   8727:         } elsif (($fname =~ /\.(\w+)$/) &&
                   8728:                  (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987     raeburn  8729:             $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661     raeburn  8730:             next;
                   8731:         } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.987     raeburn  8732:             $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  8733:             next;
                   8734:         }
                   8735: 
                   8736:         $env{'form.embedded_item_'.$i.'.filename'}=$fname;
                   8737:         if ($context eq 'portfolio') {
1.984     raeburn  8738:             my $result;
                   8739:             if ($state eq 'existingfile') {
                   8740:                 $result=
                   8741:                     &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.987     raeburn  8742:                                                     $dirpath.$env{'form.currentpath'}.$path);
1.661     raeburn  8743:             } else {
1.984     raeburn  8744:                 $result=
                   8745:                     &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987     raeburn  8746:                                                     $dirpath.
                   8747:                                                     $env{'form.currentpath'}.$path);
1.984     raeburn  8748:                 if ($result !~ m|^/uploaded/|) {
                   8749:                     $output .= '<span class="LC_error">'
                   8750:                                .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
                   8751:                                ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
                   8752:                                .'</span><br />';
                   8753:                     next;
                   8754:                 } else {
1.987     raeburn  8755:                     $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
                   8756:                                $path.$fname.'</span>').'<br />';     
1.984     raeburn  8757:                 }
1.661     raeburn  8758:             }
1.987     raeburn  8759:         } elsif ($context eq 'coursedoc') {
                   8760:             my $result =
                   8761:                 &Apache::lonnet::userfileupload('embedded_item_'.$i,'coursedoc',
                   8762:                                                 $dirpath.'/'.$path);
                   8763:             if ($result !~ m|^/uploaded/|) {
                   8764:                 $output .= '<span class="LC_error">'
                   8765:                            .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
                   8766:                            ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
                   8767:                            .'</span><br />';
                   8768:                     next;
                   8769:             } else {
                   8770:                 $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
                   8771:                            $path.$fname.'</span>').'<br />';
                   8772:             }
1.661     raeburn  8773:         } else {
                   8774: # Save the file
                   8775:             my $target = $env{'form.embedded_item_'.$i};
                   8776:             my $fullpath = $dir_root.$dirpath.'/'.$path;
                   8777:             my $dest = $fullpath.$fname;
                   8778:             my $url = $url_root.$dirpath.'/'.$path.$fname;
                   8779:             my @parts=split(/\//,$fullpath);
                   8780:             my $count;
                   8781:             my $filepath = $dir_root;
                   8782:             for ($count=4;$count<=$#parts;$count++) {
                   8783:                 $filepath .= "/$parts[$count]";
                   8784:                 if ((-e $filepath)!=1) {
                   8785:                     mkdir($filepath,0770);
                   8786:                 }
                   8787:             }
                   8788:             my $fh;
                   8789:             if (!open($fh,'>'.$dest)) {
                   8790:                 &Apache::lonnet::logthis('Failed to create '.$dest);
                   8791:                 $output .= '<span class="LC_error">'.
                   8792:                            &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   8793:                            '</span><br />';
                   8794:             } else {
                   8795:                 if (!print $fh $env{'form.embedded_item_'.$i}) {
                   8796:                     &Apache::lonnet::logthis('Failed to write to '.$dest);
                   8797:                     $output .= '<span class="LC_error">'.
                   8798:                               &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   8799:                               '</span><br />';
                   8800:                 } else {
1.987     raeburn  8801:                     $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
                   8802:                                $url.'</span>').'<br />';
                   8803:                     unless ($context eq 'testbank') {
                   8804:                         $footer .= &mt('View embedded file: [_1]',
                   8805:                                        '<a href="'.$url.'">'.$fname.'</a>').'<br />';
                   8806:                     }
                   8807:                 }
                   8808:                 close($fh);
                   8809:             }
                   8810:         }
                   8811:         if ($env{'form.embedded_ref_'.$i}) {
                   8812:             $pathchange{$i} = 1;
                   8813:         }
                   8814:     }
                   8815:     if ($output) {
                   8816:         $output = '<p>'.$output.'</p>';
                   8817:     }
                   8818:     $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
                   8819:     $returnflag = 'ok';
                   8820:     if (keys(%pathchange) > 0) {
                   8821:         if ($context eq 'portfolio') {
                   8822:             $output .= '<p>'.&mt('or').'</p>';
                   8823:         } elsif ($context eq 'testbank') {
1.988     raeburn  8824:             $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  8825:             $returnflag = 'modify_orightml';
                   8826:         }
                   8827:     }
                   8828:     return ($output.$footer,$returnflag);
                   8829: }
                   8830: 
                   8831: sub modify_html_form {
                   8832:     my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
                   8833:     my $end = 0;
                   8834:     my $modifyform;
                   8835:     if ($context eq 'upload_embedded') {
                   8836:         return unless (ref($pathchange) eq 'HASH');
                   8837:         if ($env{'form.number_embedded_items'}) {
                   8838:             $end += $env{'form.number_embedded_items'};
                   8839:         }
                   8840:         if ($env{'form.number_pathchange_items'}) {
                   8841:             $end += $env{'form.number_pathchange_items'};
                   8842:         }
                   8843:         if ($end) {
                   8844:             for (my $i=0; $i<$end; $i++) {
                   8845:                 if ($i < $env{'form.number_embedded_items'}) {
                   8846:                     next unless($pathchange->{$i});
                   8847:                 }
                   8848:                 $modifyform .=
                   8849:                     &start_data_table_row().
                   8850:                     '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
                   8851:                     'checked="checked" /></td>'.
                   8852:                     '<td>'.$env{'form.embedded_ref_'.$i}.
                   8853:                     '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
                   8854:                     &escape($env{'form.embedded_ref_'.$i}).'" />'.
                   8855:                     '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
                   8856:                     &escape($env{'form.embedded_codebase_'.$i}).'" />'.
                   8857:                     '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
                   8858:                     &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
                   8859:                     '<td>'.$env{'form.embedded_orig_'.$i}.
                   8860:                     '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
                   8861:                     &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
                   8862:                     &end_data_table_row();
                   8863:             } 
                   8864:         }
                   8865:     } else {
                   8866:         $modifyform = $pathchgtable;
                   8867:         if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
                   8868:             $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
                   8869:         } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
                   8870:             $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
                   8871:         }
                   8872:     }
                   8873:     if ($modifyform) {
                   8874:         return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
                   8875:                '<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".
                   8876:                '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
                   8877:                '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
                   8878:                '</ol></p>'."\n".'<p>'.
                   8879:                &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
                   8880:                '<form method="post" name="refchanger" action="'.$actionurl.'">'.
                   8881:                &start_data_table()."\n".
                   8882:                &start_data_table_header_row().
                   8883:                '<th>'.&mt('Change?').'</th>'.
                   8884:                '<th>'.&mt('Current reference').'</th>'.
                   8885:                '<th>'.&mt('Required reference').'</th>'.
                   8886:                &end_data_table_header_row()."\n".
                   8887:                $modifyform.
                   8888:                &end_data_table().'<br />'."\n".$hiddenstate.
                   8889:                '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
                   8890:                '</form>'."\n";
                   8891:     }
                   8892:     return;
                   8893: }
                   8894: 
                   8895: sub modify_html_refs {
                   8896:     my ($context,$dirpath,$uname,$udom,$dir_root) = @_;
                   8897:     my $container;
                   8898:     if ($context eq 'portfolio') {
                   8899:         $container = $env{'form.container'};
                   8900:     } elsif ($context eq 'coursedoc') {
                   8901:         $container = $env{'form.primaryurl'};
                   8902:     } else {
                   8903:         $container = $env{'form.filename'};
                   8904:         $container =~ s{^/priv/(\Q$uname\E)/(.*)}{/home/$1/public_html/$2};
                   8905:     }
                   8906:     my (%allfiles,%codebase,$output,$content);
                   8907:     my @changes = &get_env_multiple('form.namechange');
                   8908:     return unless (@changes > 0);
                   8909:     if (($context eq 'portfolio') || ($context eq 'coursedoc')) {
                   8910:         return unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/});
                   8911:         $content = &Apache::lonnet::getfile($container);
                   8912:         return if ($content eq '-1');
                   8913:     } else {
                   8914:         return unless ($container =~ /^\Q$dir_root\E/); 
                   8915:         if (open(my $fh,"<$container")) {
                   8916:             $content = join('', <$fh>);
                   8917:             close($fh);
                   8918:         } else {
                   8919:             return;
                   8920:         }
                   8921:     }
                   8922:     my ($count,$codebasecount) = (0,0);
                   8923:     my $mm = new File::MMagic;
                   8924:     my $mime_type = $mm->checktype_contents($content);
                   8925:     if ($mime_type eq 'text/html') {
                   8926:         my $parse_result = 
                   8927:             &Apache::lonnet::extract_embedded_items($container,\%allfiles,
                   8928:                                                     \%codebase,\$content);
                   8929:         if ($parse_result eq 'ok') {
                   8930:             foreach my $i (@changes) {
                   8931:                 my $orig = &unescape($env{'form.embedded_orig_'.$i});
                   8932:                 my $ref = &unescape($env{'form.embedded_ref_'.$i});
                   8933:                 if ($allfiles{$ref}) {
                   8934:                     my $newname =  $orig;
                   8935:                     my ($attrib_regexp,$codebase);
1.1006    raeburn  8936:                     $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987     raeburn  8937:                     if ($attrib_regexp =~ /:/) {
                   8938:                         $attrib_regexp =~ s/\:/|/g;
                   8939:                     }
                   8940:                     if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
                   8941:                         my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
                   8942:                         $count += $numchg;
                   8943:                     }
                   8944:                     if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006    raeburn  8945:                         $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987     raeburn  8946:                         my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
                   8947:                         $codebasecount ++;
                   8948:                     }
                   8949:                 }
                   8950:             }
                   8951:             if ($count || $codebasecount) {
                   8952:                 my $saveresult;
                   8953:                 if ($context eq 'portfolio' || $context eq 'coursedoc') {
                   8954:                     my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
                   8955:                     if ($url eq $container) {
                   8956:                         my ($fname) = ($container =~ m{/([^/]+)$});
                   8957:                         $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
                   8958:                                             $count,'<span class="LC_filename">'.
                   8959:                                             $fname.'</span>').'</p>'; 
                   8960:                     } else {
                   8961:                          $output = '<p class="LC_error">'.
                   8962:                                    &mt('Error: update failed for: [_1].',
                   8963:                                    '<span class="LC_filename">'.
                   8964:                                    $container.'</span>').'</p>';
                   8965:                     }
                   8966:                 } else {
                   8967:                     if (open(my $fh,">$container")) {
                   8968:                         print $fh $content;
                   8969:                         close($fh);
                   8970:                         $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
                   8971:                                   $count,'<span class="LC_filename">'.
                   8972:                                   $container.'</span>').'</p>';
1.661     raeburn  8973:                     } else {
1.987     raeburn  8974:                          $output = '<p class="LC_error">'.
                   8975:                                    &mt('Error: could not update [_1].',
                   8976:                                    '<span class="LC_filename">'.
                   8977:                                    $container.'</span>').'</p>';
1.661     raeburn  8978:                     }
                   8979:                 }
                   8980:             }
1.987     raeburn  8981:         } else {
                   8982:             &logthis('Failed to parse '.$container.
                   8983:                      ' to modify references: '.$parse_result);
1.661     raeburn  8984:         }
                   8985:     }
                   8986:     return $output;
                   8987: }
                   8988: 
                   8989: sub check_for_existing {
                   8990:     my ($path,$fname,$element) = @_;
                   8991:     my ($state,$msg);
                   8992:     if (-d $path.'/'.$fname) {
                   8993:         $state = 'exists';
                   8994:         $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   8995:     } elsif (-e $path.'/'.$fname) {
                   8996:         $state = 'exists';
                   8997:         $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   8998:     }
                   8999:     if ($state eq 'exists') {
                   9000:         $msg = '<span class="LC_error">'.$msg.'</span><br />';
                   9001:     }
                   9002:     return ($state,$msg);
                   9003: }
                   9004: 
                   9005: sub check_for_upload {
                   9006:     my ($path,$fname,$group,$element,$portfolio_root,$port_path,
                   9007:         $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985     raeburn  9008:     my $filesize = length($env{'form.'.$element});
                   9009:     if (!$filesize) {
                   9010:         my $msg = '<span class="LC_error">'.
                   9011:                   &mt('Unable to upload [_1]. (size = [_2] bytes)', 
                   9012:                       '<span class="LC_filename">'.$fname.'</span>',
                   9013:                       $filesize).'<br />'.
1.1007    raeburn  9014:                   &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985     raeburn  9015:                   '</span>';
                   9016:         return ('zero_bytes',$msg);
                   9017:     }
                   9018:     $filesize =  $filesize/1000; #express in k (1024?)
1.661     raeburn  9019:     my $getpropath = 1;
                   9020:     my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
                   9021:                                             $getpropath);
                   9022:     my $found_file = 0;
                   9023:     my $locked_file = 0;
1.991     raeburn  9024:     my @lockers;
                   9025:     my $navmap;
                   9026:     if ($env{'request.course.id'}) {
                   9027:         $navmap = Apache::lonnavmaps::navmap->new();
                   9028:     }
1.661     raeburn  9029:     foreach my $line (@dir_list) {
1.984     raeburn  9030:         my ($file_name,$rest)=split(/\&/,$line,2);
1.661     raeburn  9031:         if ($file_name eq $fname){
                   9032:             $file_name = $path.$file_name;
                   9033:             if ($group ne '') {
                   9034:                 $file_name = $group.$file_name;
                   9035:             }
                   9036:             $found_file = 1;
1.991     raeburn  9037:             if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
                   9038:                 foreach my $lock (@lockers) {
                   9039:                     if (ref($lock) eq 'ARRAY') {
                   9040:                         my ($symb,$crsid) = @{$lock};
                   9041:                         if ($crsid eq $env{'request.course.id'}) {
                   9042:                             if (ref($navmap)) {
                   9043:                                 my $res = $navmap->getBySymb($symb);
                   9044:                                 foreach my $part (@{$res->parts()}) { 
                   9045:                                     my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
                   9046:                                     unless (($slot_status == $res->RESERVED) ||
                   9047:                                             ($slot_status == $res->RESERVED_LOCATION)) {
                   9048:                                         $locked_file = 1;
                   9049:                                     }
                   9050:                                 }
                   9051:                             } else {
                   9052:                                 $locked_file = 1;
                   9053:                             }
                   9054:                         } else {
                   9055:                             $locked_file = 1;
                   9056:                         }
                   9057:                     }
                   9058:                 }
1.984     raeburn  9059:             } else {
                   9060:                 my @info = split(/\&/,$rest);
                   9061:                 my $currsize = $info[6]/1000;
                   9062:                 if ($currsize < $filesize) {
                   9063:                     my $extra = $filesize - $currsize;
                   9064:                     if (($current_disk_usage + $extra) > $disk_quota) {
                   9065:                         my $msg = '<span class="LC_error">'.
                   9066:                                   &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.',
                   9067:                                       '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</span>'.
                   9068:                                   '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
                   9069:                                                $disk_quota,$current_disk_usage);
                   9070:                         return ('will_exceed_quota',$msg);
                   9071:                     }
                   9072:                 }
1.661     raeburn  9073:             }
                   9074:         }
                   9075:     }
                   9076:     if (($current_disk_usage + $filesize) > $disk_quota){
                   9077:         my $msg = '<span class="LC_error">'.
                   9078:                 &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
                   9079:                   '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
                   9080:         return ('will_exceed_quota',$msg);
                   9081:     } elsif ($found_file) {
                   9082:         if ($locked_file) {
                   9083:             my $msg = '<span class="LC_error">';
                   9084:             $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>');
                   9085:             $msg .= '</span><br />';
                   9086:             $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
                   9087:             return ('file_locked',$msg);
                   9088:         } else {
                   9089:             my $msg = '<span class="LC_error">';
1.984     raeburn  9090:             $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  9091:             $msg .= '</span>';
1.984     raeburn  9092:             return ('existingfile',$msg);
1.661     raeburn  9093:         }
                   9094:     }
                   9095: }
                   9096: 
1.987     raeburn  9097: sub check_for_traversal {
                   9098:     my ($path,$url,$toplevel) = @_;
                   9099:     my @parts=split(/\//,$path);
                   9100:     my $cleanpath;
                   9101:     my $fullpath = $url;
                   9102:     for (my $i=0;$i<@parts;$i++) {
                   9103:         next if ($parts[$i] eq '.');
                   9104:         if ($parts[$i] eq '..') {
                   9105:             $fullpath =~ s{([^/]+/)$}{};
                   9106:         } else {
                   9107:             $fullpath .= $parts[$i].'/';
                   9108:         }
                   9109:     }
                   9110:     if ($fullpath =~ /^\Q$url\E(.*)$/) {
                   9111:         $cleanpath = $1;
                   9112:     } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
                   9113:         my $curr_toprel = $1;
                   9114:         my @parts = split(/\//,$curr_toprel);
                   9115:         my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
                   9116:         my @urlparts = split(/\//,$url_toprel);
                   9117:         my $doubledots;
                   9118:         my $startdiff = -1;
                   9119:         for (my $i=0; $i<@urlparts; $i++) {
                   9120:             if ($startdiff == -1) {
                   9121:                 unless ($urlparts[$i] eq $parts[$i]) {
                   9122:                     $startdiff = $i;
                   9123:                     $doubledots .= '../';
                   9124:                 }
                   9125:             } else {
                   9126:                 $doubledots .= '../';
                   9127:             }
                   9128:         }
                   9129:         if ($startdiff > -1) {
                   9130:             $cleanpath = $doubledots;
                   9131:             for (my $i=$startdiff; $i<@parts; $i++) {
                   9132:                 $cleanpath .= $parts[$i].'/';
                   9133:             }
                   9134:         }
                   9135:     }
                   9136:     $cleanpath =~ s{(/)$}{};
                   9137:     return $cleanpath;
                   9138: }
1.31      albertel 9139: 
1.41      ng       9140: =pod
1.45      matthew  9141: 
1.464     albertel 9142: =back
1.41      ng       9143: 
1.112     bowersj2 9144: =head1 CSV Upload/Handling functions
1.38      albertel 9145: 
1.41      ng       9146: =over 4
                   9147: 
1.648     raeburn  9148: =item * &upfile_store($r)
1.41      ng       9149: 
                   9150: Store uploaded file, $r should be the HTTP Request object,
1.258     albertel 9151: needs $env{'form.upfile'}
1.41      ng       9152: returns $datatoken to be put into hidden field
                   9153: 
                   9154: =cut
1.31      albertel 9155: 
                   9156: sub upfile_store {
                   9157:     my $r=shift;
1.258     albertel 9158:     $env{'form.upfile'}=~s/\r/\n/gs;
                   9159:     $env{'form.upfile'}=~s/\f/\n/gs;
                   9160:     $env{'form.upfile'}=~s/\n+/\n/gs;
                   9161:     $env{'form.upfile'}=~s/\n+$//gs;
1.31      albertel 9162: 
1.258     albertel 9163:     my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
                   9164: 	'_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31      albertel 9165:     {
1.158     raeburn  9166:         my $datafile = $r->dir_config('lonDaemons').
                   9167:                            '/tmp/'.$datatoken.'.tmp';
                   9168:         if ( open(my $fh,">$datafile") ) {
1.258     albertel 9169:             print $fh $env{'form.upfile'};
1.158     raeburn  9170:             close($fh);
                   9171:         }
1.31      albertel 9172:     }
                   9173:     return $datatoken;
                   9174: }
                   9175: 
1.56      matthew  9176: =pod
                   9177: 
1.648     raeburn  9178: =item * &load_tmp_file($r)
1.41      ng       9179: 
                   9180: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258     albertel 9181: needs $env{'form.datatoken'},
                   9182: sets $env{'form.upfile'} to the contents of the file
1.41      ng       9183: 
                   9184: =cut
1.31      albertel 9185: 
                   9186: sub load_tmp_file {
                   9187:     my $r=shift;
                   9188:     my @studentdata=();
                   9189:     {
1.158     raeburn  9190:         my $studentfile = $r->dir_config('lonDaemons').
1.258     albertel 9191:                               '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158     raeburn  9192:         if ( open(my $fh,"<$studentfile") ) {
                   9193:             @studentdata=<$fh>;
                   9194:             close($fh);
                   9195:         }
1.31      albertel 9196:     }
1.258     albertel 9197:     $env{'form.upfile'}=join('',@studentdata);
1.31      albertel 9198: }
                   9199: 
1.56      matthew  9200: =pod
                   9201: 
1.648     raeburn  9202: =item * &upfile_record_sep()
1.41      ng       9203: 
                   9204: Separate uploaded file into records
                   9205: returns array of records,
1.258     albertel 9206: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41      ng       9207: 
                   9208: =cut
1.31      albertel 9209: 
                   9210: sub upfile_record_sep {
1.258     albertel 9211:     if ($env{'form.upfiletype'} eq 'xml') {
1.31      albertel 9212:     } else {
1.248     albertel 9213: 	my @records;
1.258     albertel 9214: 	foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248     albertel 9215: 	    if ($line=~/^\s*$/) { next; }
                   9216: 	    push(@records,$line);
                   9217: 	}
                   9218: 	return @records;
1.31      albertel 9219:     }
                   9220: }
                   9221: 
1.56      matthew  9222: =pod
                   9223: 
1.648     raeburn  9224: =item * &record_sep($record)
1.41      ng       9225: 
1.258     albertel 9226: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41      ng       9227: 
                   9228: =cut
                   9229: 
1.263     www      9230: sub takeleft {
                   9231:     my $index=shift;
                   9232:     return substr('0000'.$index,-4,4);
                   9233: }
                   9234: 
1.31      albertel 9235: sub record_sep {
                   9236:     my $record=shift;
                   9237:     my %components=();
1.258     albertel 9238:     if ($env{'form.upfiletype'} eq 'xml') {
                   9239:     } elsif ($env{'form.upfiletype'} eq 'space') {
1.31      albertel 9240:         my $i=0;
1.356     albertel 9241:         foreach my $field (split(/\s+/,$record)) {
1.31      albertel 9242:             $field=~s/^(\"|\')//;
                   9243:             $field=~s/(\"|\')$//;
1.263     www      9244:             $components{&takeleft($i)}=$field;
1.31      albertel 9245:             $i++;
                   9246:         }
1.258     albertel 9247:     } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31      albertel 9248:         my $i=0;
1.356     albertel 9249:         foreach my $field (split(/\t/,$record)) {
1.31      albertel 9250:             $field=~s/^(\"|\')//;
                   9251:             $field=~s/(\"|\')$//;
1.263     www      9252:             $components{&takeleft($i)}=$field;
1.31      albertel 9253:             $i++;
                   9254:         }
                   9255:     } else {
1.561     www      9256:         my $separator=',';
1.480     banghart 9257:         if ($env{'form.upfiletype'} eq 'semisv') {
1.561     www      9258:             $separator=';';
1.480     banghart 9259:         }
1.31      albertel 9260:         my $i=0;
1.561     www      9261: # the character we are looking for to indicate the end of a quote or a record 
                   9262:         my $looking_for=$separator;
                   9263: # do not add the characters to the fields
                   9264:         my $ignore=0;
                   9265: # we just encountered a separator (or the beginning of the record)
                   9266:         my $just_found_separator=1;
                   9267: # store the field we are working on here
                   9268:         my $field='';
                   9269: # work our way through all characters in record
                   9270:         foreach my $character ($record=~/(.)/g) {
                   9271:             if ($character eq $looking_for) {
                   9272:                if ($character ne $separator) {
                   9273: # Found the end of a quote, again looking for separator
                   9274:                   $looking_for=$separator;
                   9275:                   $ignore=1;
                   9276:                } else {
                   9277: # Found a separator, store away what we got
                   9278:                   $components{&takeleft($i)}=$field;
                   9279: 	          $i++;
                   9280:                   $just_found_separator=1;
                   9281:                   $ignore=0;
                   9282:                   $field='';
                   9283:                }
                   9284:                next;
                   9285:             }
                   9286: # single or double quotation marks after a separator indicate beginning of a quote
                   9287: # we are now looking for the end of the quote and need to ignore separators
                   9288:             if ((($character eq '"') || ($character eq "'")) && ($just_found_separator))  {
                   9289:                $looking_for=$character;
                   9290:                next;
                   9291:             }
                   9292: # ignore would be true after we reached the end of a quote
                   9293:             if ($ignore) { next; }
                   9294:             if (($just_found_separator) && ($character=~/\s/)) { next; }
                   9295:             $field.=$character;
                   9296:             $just_found_separator=0; 
1.31      albertel 9297:         }
1.561     www      9298: # catch the very last entry, since we never encountered the separator
                   9299:         $components{&takeleft($i)}=$field;
1.31      albertel 9300:     }
                   9301:     return %components;
                   9302: }
                   9303: 
1.144     matthew  9304: ######################################################
                   9305: ######################################################
                   9306: 
1.56      matthew  9307: =pod
                   9308: 
1.648     raeburn  9309: =item * &upfile_select_html()
1.41      ng       9310: 
1.144     matthew  9311: Return HTML code to select a file from the users machine and specify 
                   9312: the file type.
1.41      ng       9313: 
                   9314: =cut
                   9315: 
1.144     matthew  9316: ######################################################
                   9317: ######################################################
1.31      albertel 9318: sub upfile_select_html {
1.144     matthew  9319:     my %Types = (
                   9320:                  csv   => &mt('CSV (comma separated values, spreadsheet)'),
1.480     banghart 9321:                  semisv => &mt('Semicolon separated values'),
1.144     matthew  9322:                  space => &mt('Space separated'),
                   9323:                  tab   => &mt('Tabulator separated'),
                   9324: #                 xml   => &mt('HTML/XML'),
                   9325:                  );
                   9326:     my $Str = '<input type="file" name="upfile" size="50" />'.
1.727     riegler  9327:         '<br />'.&mt('Type').': <select name="upfiletype">';
1.144     matthew  9328:     foreach my $type (sort(keys(%Types))) {
                   9329:         $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
                   9330:     }
                   9331:     $Str .= "</select>\n";
                   9332:     return $Str;
1.31      albertel 9333: }
                   9334: 
1.301     albertel 9335: sub get_samples {
                   9336:     my ($records,$toget) = @_;
                   9337:     my @samples=({});
                   9338:     my $got=0;
                   9339:     foreach my $rec (@$records) {
                   9340: 	my %temp = &record_sep($rec);
                   9341: 	if (! grep(/\S/, values(%temp))) { next; }
                   9342: 	if (%temp) {
                   9343: 	    $samples[$got]=\%temp;
                   9344: 	    $got++;
                   9345: 	    if ($got == $toget) { last; }
                   9346: 	}
                   9347:     }
                   9348:     return \@samples;
                   9349: }
                   9350: 
1.144     matthew  9351: ######################################################
                   9352: ######################################################
                   9353: 
1.56      matthew  9354: =pod
                   9355: 
1.648     raeburn  9356: =item * &csv_print_samples($r,$records)
1.41      ng       9357: 
                   9358: Prints a table of sample values from each column uploaded $r is an
                   9359: Apache Request ref, $records is an arrayref from
                   9360: &Apache::loncommon::upfile_record_sep
                   9361: 
                   9362: =cut
                   9363: 
1.144     matthew  9364: ######################################################
                   9365: ######################################################
1.31      albertel 9366: sub csv_print_samples {
                   9367:     my ($r,$records) = @_;
1.662     bisitz   9368:     my $samples = &get_samples($records,5);
1.301     albertel 9369: 
1.594     raeburn  9370:     $r->print(&mt('Samples').'<br />'.&start_data_table().
                   9371:               &start_data_table_header_row());
1.356     albertel 9372:     foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) { 
1.845     bisitz   9373:         $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594     raeburn  9374:     $r->print(&end_data_table_header_row());
1.301     albertel 9375:     foreach my $hash (@$samples) {
1.594     raeburn  9376: 	$r->print(&start_data_table_row());
1.356     albertel 9377: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31      albertel 9378: 	    $r->print('<td>');
1.356     albertel 9379: 	    if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31      albertel 9380: 	    $r->print('</td>');
                   9381: 	}
1.594     raeburn  9382: 	$r->print(&end_data_table_row());
1.31      albertel 9383:     }
1.594     raeburn  9384:     $r->print(&end_data_table().'<br />'."\n");
1.31      albertel 9385: }
                   9386: 
1.144     matthew  9387: ######################################################
                   9388: ######################################################
                   9389: 
1.56      matthew  9390: =pod
                   9391: 
1.648     raeburn  9392: =item * &csv_print_select_table($r,$records,$d)
1.41      ng       9393: 
                   9394: Prints a table to create associations between values and table columns.
1.144     matthew  9395: 
1.41      ng       9396: $r is an Apache Request ref,
                   9397: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174     matthew  9398: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41      ng       9399: 
                   9400: =cut
                   9401: 
1.144     matthew  9402: ######################################################
                   9403: ######################################################
1.31      albertel 9404: sub csv_print_select_table {
                   9405:     my ($r,$records,$d) = @_;
1.301     albertel 9406:     my $i=0;
                   9407:     my $samples = &get_samples($records,1);
1.144     matthew  9408:     $r->print(&mt('Associate columns with student attributes.')."\n".
1.594     raeburn  9409: 	      &start_data_table().&start_data_table_header_row().
1.144     matthew  9410:               '<th>'.&mt('Attribute').'</th>'.
1.594     raeburn  9411:               '<th>'.&mt('Column').'</th>'.
                   9412:               &end_data_table_header_row()."\n");
1.356     albertel 9413:     foreach my $array_ref (@$d) {
                   9414: 	my ($value,$display,$defaultcol)=@{ $array_ref };
1.729     raeburn  9415: 	$r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31      albertel 9416: 
1.875     bisitz   9417: 	$r->print('<td><select name="f'.$i.'"'.
1.32      matthew  9418: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.31      albertel 9419: 	$r->print('<option value="none"></option>');
1.356     albertel 9420: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
                   9421: 	    $r->print('<option value="'.$sample.'"'.
                   9422:                       ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662     bisitz   9423:                       '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31      albertel 9424: 	}
1.594     raeburn  9425: 	$r->print('</select></td>'.&end_data_table_row()."\n");
1.31      albertel 9426: 	$i++;
                   9427:     }
1.594     raeburn  9428:     $r->print(&end_data_table());
1.31      albertel 9429:     $i--;
                   9430:     return $i;
                   9431: }
1.56      matthew  9432: 
1.144     matthew  9433: ######################################################
                   9434: ######################################################
                   9435: 
1.56      matthew  9436: =pod
1.31      albertel 9437: 
1.648     raeburn  9438: =item * &csv_samples_select_table($r,$records,$d)
1.41      ng       9439: 
                   9440: Prints a table of sample values from the upload and can make associate samples to internal names.
                   9441: 
                   9442: $r is an Apache Request ref,
                   9443: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
                   9444: $d is an array of 2 element arrays (internal name, displayed name)
                   9445: 
                   9446: =cut
                   9447: 
1.144     matthew  9448: ######################################################
                   9449: ######################################################
1.31      albertel 9450: sub csv_samples_select_table {
                   9451:     my ($r,$records,$d) = @_;
                   9452:     my $i=0;
1.144     matthew  9453:     #
1.662     bisitz   9454:     my $max_samples = 5;
                   9455:     my $samples = &get_samples($records,$max_samples);
1.594     raeburn  9456:     $r->print(&start_data_table().
                   9457:               &start_data_table_header_row().'<th>'.
                   9458:               &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
                   9459:               &end_data_table_header_row());
1.301     albertel 9460: 
                   9461:     foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594     raeburn  9462: 	$r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32      matthew  9463: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.301     albertel 9464: 	foreach my $option (@$d) {
                   9465: 	    my ($value,$display,$defaultcol)=@{ $option };
1.174     matthew  9466: 	    $r->print('<option value="'.$value.'"'.
1.253     albertel 9467:                       ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174     matthew  9468:                       $display.'</option>');
1.31      albertel 9469: 	}
                   9470: 	$r->print('</select></td><td>');
1.662     bisitz   9471: 	foreach my $line (0..($max_samples-1)) {
1.301     albertel 9472: 	    if (defined($samples->[$line]{$key})) { 
                   9473: 		$r->print($samples->[$line]{$key}."<br />\n"); 
                   9474: 	    }
                   9475: 	}
1.594     raeburn  9476: 	$r->print('</td>'.&end_data_table_row());
1.31      albertel 9477: 	$i++;
                   9478:     }
1.594     raeburn  9479:     $r->print(&end_data_table());
1.31      albertel 9480:     $i--;
                   9481:     return($i);
1.115     matthew  9482: }
                   9483: 
1.144     matthew  9484: ######################################################
                   9485: ######################################################
                   9486: 
1.115     matthew  9487: =pod
                   9488: 
1.648     raeburn  9489: =item * &clean_excel_name($name)
1.115     matthew  9490: 
                   9491: Returns a replacement for $name which does not contain any illegal characters.
                   9492: 
                   9493: =cut
                   9494: 
1.144     matthew  9495: ######################################################
                   9496: ######################################################
1.115     matthew  9497: sub clean_excel_name {
                   9498:     my ($name) = @_;
                   9499:     $name =~ s/[:\*\?\/\\]//g;
                   9500:     if (length($name) > 31) {
                   9501:         $name = substr($name,0,31);
                   9502:     }
                   9503:     return $name;
1.25      albertel 9504: }
1.84      albertel 9505: 
1.85      albertel 9506: =pod
                   9507: 
1.648     raeburn  9508: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85      albertel 9509: 
                   9510: Returns either 1 or undef
                   9511: 
                   9512: 1 if the part is to be hidden, undef if it is to be shown
                   9513: 
                   9514: Arguments are:
                   9515: 
                   9516: $id the id of the part to be checked
                   9517: $symb, optional the symb of the resource to check
                   9518: $udom, optional the domain of the user to check for
                   9519: $uname, optional the username of the user to check for
                   9520: 
                   9521: =cut
1.84      albertel 9522: 
                   9523: sub check_if_partid_hidden {
                   9524:     my ($id,$symb,$udom,$uname) = @_;
1.133     albertel 9525:     my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84      albertel 9526: 					 $symb,$udom,$uname);
1.141     albertel 9527:     my $truth=1;
                   9528:     #if the string starts with !, then the list is the list to show not hide
                   9529:     if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84      albertel 9530:     my @hiddenlist=split(/,/,$hiddenparts);
                   9531:     foreach my $checkid (@hiddenlist) {
1.141     albertel 9532: 	if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84      albertel 9533:     }
1.141     albertel 9534:     return !$truth;
1.84      albertel 9535: }
1.127     matthew  9536: 
1.138     matthew  9537: 
                   9538: ############################################################
                   9539: ############################################################
                   9540: 
                   9541: =pod
                   9542: 
1.157     matthew  9543: =back 
                   9544: 
1.138     matthew  9545: =head1 cgi-bin script and graphing routines
                   9546: 
1.157     matthew  9547: =over 4
                   9548: 
1.648     raeburn  9549: =item * &get_cgi_id()
1.138     matthew  9550: 
                   9551: Inputs: none
                   9552: 
                   9553: Returns an id which can be used to pass environment variables
                   9554: to various cgi-bin scripts.  These environment variables will
                   9555: be removed from the users environment after a given time by
                   9556: the routine &Apache::lonnet::transfer_profile_to_env.
                   9557: 
                   9558: =cut
                   9559: 
                   9560: ############################################################
                   9561: ############################################################
1.152     albertel 9562: my $uniq=0;
1.136     matthew  9563: sub get_cgi_id {
1.154     albertel 9564:     $uniq=($uniq+1)%100000;
1.280     albertel 9565:     return (time.'_'.$$.'_'.$uniq);
1.136     matthew  9566: }
                   9567: 
1.127     matthew  9568: ############################################################
                   9569: ############################################################
                   9570: 
                   9571: =pod
                   9572: 
1.648     raeburn  9573: =item * &DrawBarGraph()
1.127     matthew  9574: 
1.138     matthew  9575: Facilitates the plotting of data in a (stacked) bar graph.
                   9576: Puts plot definition data into the users environment in order for 
                   9577: graph.png to plot it.  Returns an <img> tag for the plot.
                   9578: The bars on the plot are labeled '1','2',...,'n'.
                   9579: 
                   9580: Inputs:
                   9581: 
                   9582: =over 4
                   9583: 
                   9584: =item $Title: string, the title of the plot
                   9585: 
                   9586: =item $xlabel: string, text describing the X-axis of the plot
                   9587: 
                   9588: =item $ylabel: string, text describing the Y-axis of the plot
                   9589: 
                   9590: =item $Max: scalar, the maximum Y value to use in the plot
                   9591: If $Max is < any data point, the graph will not be rendered.
                   9592: 
1.140     matthew  9593: =item $colors: array ref holding the colors to be used for the data sets when
1.138     matthew  9594: they are plotted.  If undefined, default values will be used.
                   9595: 
1.178     matthew  9596: =item $labels: array ref holding the labels to use on the x-axis for the bars.
                   9597: 
1.138     matthew  9598: =item @Values: An array of array references.  Each array reference holds data
                   9599: to be plotted in a stacked bar chart.
                   9600: 
1.239     matthew  9601: =item If the final element of @Values is a hash reference the key/value
                   9602: pairs will be added to the graph definition.
                   9603: 
1.138     matthew  9604: =back
                   9605: 
                   9606: Returns:
                   9607: 
                   9608: An <img> tag which references graph.png and the appropriate identifying
                   9609: information for the plot.
                   9610: 
1.127     matthew  9611: =cut
                   9612: 
                   9613: ############################################################
                   9614: ############################################################
1.134     matthew  9615: sub DrawBarGraph {
1.178     matthew  9616:     my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134     matthew  9617:     #
                   9618:     if (! defined($colors)) {
                   9619:         $colors = ['#33ff00', 
                   9620:                   '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
                   9621:                   '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
                   9622:                   ]; 
                   9623:     }
1.228     matthew  9624:     my $extra_settings = {};
                   9625:     if (ref($Values[-1]) eq 'HASH') {
                   9626:         $extra_settings = pop(@Values);
                   9627:     }
1.127     matthew  9628:     #
1.136     matthew  9629:     my $identifier = &get_cgi_id();
                   9630:     my $id = 'cgi.'.$identifier;        
1.129     matthew  9631:     if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127     matthew  9632:         return '';
                   9633:     }
1.225     matthew  9634:     #
                   9635:     my @Labels;
                   9636:     if (defined($labels)) {
                   9637:         @Labels = @$labels;
                   9638:     } else {
                   9639:         for (my $i=0;$i<@{$Values[0]};$i++) {
                   9640:             push (@Labels,$i+1);
                   9641:         }
                   9642:     }
                   9643:     #
1.129     matthew  9644:     my $NumBars = scalar(@{$Values[0]});
1.225     matthew  9645:     if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129     matthew  9646:     my %ValuesHash;
                   9647:     my $NumSets=1;
                   9648:     foreach my $array (@Values) {
                   9649:         next if (! ref($array));
1.136     matthew  9650:         $ValuesHash{$id.'.data.'.$NumSets++} = 
1.132     matthew  9651:             join(',',@$array);
1.129     matthew  9652:     }
1.127     matthew  9653:     #
1.136     matthew  9654:     my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225     matthew  9655:     if ($NumBars < 3) {
                   9656:         $width = 120+$NumBars*32;
1.220     matthew  9657:         $xskip = 1;
1.225     matthew  9658:         $bar_width = 30;
                   9659:     } elsif ($NumBars < 5) {
                   9660:         $width = 120+$NumBars*20;
                   9661:         $xskip = 1;
                   9662:         $bar_width = 20;
1.220     matthew  9663:     } elsif ($NumBars < 10) {
1.136     matthew  9664:         $width = 120+$NumBars*15;
                   9665:         $xskip = 1;
                   9666:         $bar_width = 15;
                   9667:     } elsif ($NumBars <= 25) {
                   9668:         $width = 120+$NumBars*11;
                   9669:         $xskip = 5;
                   9670:         $bar_width = 8;
                   9671:     } elsif ($NumBars <= 50) {
                   9672:         $width = 120+$NumBars*8;
                   9673:         $xskip = 5;
                   9674:         $bar_width = 4;
                   9675:     } else {
                   9676:         $width = 120+$NumBars*8;
                   9677:         $xskip = 5;
                   9678:         $bar_width = 4;
                   9679:     }
                   9680:     #
1.137     matthew  9681:     $Max = 1 if ($Max < 1);
                   9682:     if ( int($Max) < $Max ) {
                   9683:         $Max++;
                   9684:         $Max = int($Max);
                   9685:     }
1.127     matthew  9686:     $Title  = '' if (! defined($Title));
                   9687:     $xlabel = '' if (! defined($xlabel));
                   9688:     $ylabel = '' if (! defined($ylabel));
1.369     www      9689:     $ValuesHash{$id.'.title'}    = &escape($Title);
                   9690:     $ValuesHash{$id.'.xlabel'}   = &escape($xlabel);
                   9691:     $ValuesHash{$id.'.ylabel'}   = &escape($ylabel);
1.137     matthew  9692:     $ValuesHash{$id.'.y_max_value'} = $Max;
1.136     matthew  9693:     $ValuesHash{$id.'.NumBars'}  = $NumBars;
                   9694:     $ValuesHash{$id.'.NumSets'}  = $NumSets;
                   9695:     $ValuesHash{$id.'.PlotType'} = 'bar';
                   9696:     $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   9697:     $ValuesHash{$id.'.height'}   = $height;
                   9698:     $ValuesHash{$id.'.width'}    = $width;
                   9699:     $ValuesHash{$id.'.xskip'}    = $xskip;
                   9700:     $ValuesHash{$id.'.bar_width'} = $bar_width;
                   9701:     $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127     matthew  9702:     #
1.228     matthew  9703:     # Deal with other parameters
                   9704:     while (my ($key,$value) = each(%$extra_settings)) {
                   9705:         $ValuesHash{$id.'.'.$key} = $value;
                   9706:     }
                   9707:     #
1.646     raeburn  9708:     &Apache::lonnet::appenv(\%ValuesHash);
1.137     matthew  9709:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   9710: }
                   9711: 
                   9712: ############################################################
                   9713: ############################################################
                   9714: 
                   9715: =pod
                   9716: 
1.648     raeburn  9717: =item * &DrawXYGraph()
1.137     matthew  9718: 
1.138     matthew  9719: Facilitates the plotting of data in an XY graph.
                   9720: Puts plot definition data into the users environment in order for 
                   9721: graph.png to plot it.  Returns an <img> tag for the plot.
                   9722: 
                   9723: Inputs:
                   9724: 
                   9725: =over 4
                   9726: 
                   9727: =item $Title: string, the title of the plot
                   9728: 
                   9729: =item $xlabel: string, text describing the X-axis of the plot
                   9730: 
                   9731: =item $ylabel: string, text describing the Y-axis of the plot
                   9732: 
                   9733: =item $Max: scalar, the maximum Y value to use in the plot
                   9734: If $Max is < any data point, the graph will not be rendered.
                   9735: 
                   9736: =item $colors: Array ref containing the hex color codes for the data to be 
                   9737: plotted in.  If undefined, default values will be used.
                   9738: 
                   9739: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   9740: 
                   9741: =item $Ydata: Array ref containing Array refs.  
1.185     www      9742: Each of the contained arrays will be plotted as a separate curve.
1.138     matthew  9743: 
                   9744: =item %Values: hash indicating or overriding any default values which are 
                   9745: passed to graph.png.  
                   9746: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   9747: 
                   9748: =back
                   9749: 
                   9750: Returns:
                   9751: 
                   9752: An <img> tag which references graph.png and the appropriate identifying
                   9753: information for the plot.
                   9754: 
1.137     matthew  9755: =cut
                   9756: 
                   9757: ############################################################
                   9758: ############################################################
                   9759: sub DrawXYGraph {
                   9760:     my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
                   9761:     #
                   9762:     # Create the identifier for the graph
                   9763:     my $identifier = &get_cgi_id();
                   9764:     my $id = 'cgi.'.$identifier;
                   9765:     #
                   9766:     $Title  = '' if (! defined($Title));
                   9767:     $xlabel = '' if (! defined($xlabel));
                   9768:     $ylabel = '' if (! defined($ylabel));
                   9769:     my %ValuesHash = 
                   9770:         (
1.369     www      9771:          $id.'.title'  => &escape($Title),
                   9772:          $id.'.xlabel' => &escape($xlabel),
                   9773:          $id.'.ylabel' => &escape($ylabel),
1.137     matthew  9774:          $id.'.y_max_value'=> $Max,
                   9775:          $id.'.labels'     => join(',',@$Xlabels),
                   9776:          $id.'.PlotType'   => 'XY',
                   9777:          );
                   9778:     #
                   9779:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   9780:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   9781:     }
                   9782:     #
                   9783:     if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
                   9784:         return '';
                   9785:     }
                   9786:     my $NumSets=1;
1.138     matthew  9787:     foreach my $array (@{$Ydata}){
1.137     matthew  9788:         next if (! ref($array));
                   9789:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
                   9790:     }
1.138     matthew  9791:     $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137     matthew  9792:     #
                   9793:     # Deal with other parameters
                   9794:     while (my ($key,$value) = each(%Values)) {
                   9795:         $ValuesHash{$id.'.'.$key} = $value;
1.127     matthew  9796:     }
                   9797:     #
1.646     raeburn  9798:     &Apache::lonnet::appenv(\%ValuesHash);
1.136     matthew  9799:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   9800: }
                   9801: 
                   9802: ############################################################
                   9803: ############################################################
                   9804: 
                   9805: =pod
                   9806: 
1.648     raeburn  9807: =item * &DrawXYYGraph()
1.138     matthew  9808: 
                   9809: Facilitates the plotting of data in an XY graph with two Y axes.
                   9810: Puts plot definition data into the users environment in order for 
                   9811: graph.png to plot it.  Returns an <img> tag for the plot.
                   9812: 
                   9813: Inputs:
                   9814: 
                   9815: =over 4
                   9816: 
                   9817: =item $Title: string, the title of the plot
                   9818: 
                   9819: =item $xlabel: string, text describing the X-axis of the plot
                   9820: 
                   9821: =item $ylabel: string, text describing the Y-axis of the plot
                   9822: 
                   9823: =item $colors: Array ref containing the hex color codes for the data to be 
                   9824: plotted in.  If undefined, default values will be used.
                   9825: 
                   9826: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   9827: 
                   9828: =item $Ydata1: The first data set
                   9829: 
                   9830: =item $Min1: The minimum value of the left Y-axis
                   9831: 
                   9832: =item $Max1: The maximum value of the left Y-axis
                   9833: 
                   9834: =item $Ydata2: The second data set
                   9835: 
                   9836: =item $Min2: The minimum value of the right Y-axis
                   9837: 
                   9838: =item $Max2: The maximum value of the left Y-axis
                   9839: 
                   9840: =item %Values: hash indicating or overriding any default values which are 
                   9841: passed to graph.png.  
                   9842: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   9843: 
                   9844: =back
                   9845: 
                   9846: Returns:
                   9847: 
                   9848: An <img> tag which references graph.png and the appropriate identifying
                   9849: information for the plot.
1.136     matthew  9850: 
                   9851: =cut
                   9852: 
                   9853: ############################################################
                   9854: ############################################################
1.137     matthew  9855: sub DrawXYYGraph {
                   9856:     my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
                   9857:                                         $Ydata2,$Min2,$Max2,%Values)=@_;
1.136     matthew  9858:     #
                   9859:     # Create the identifier for the graph
                   9860:     my $identifier = &get_cgi_id();
                   9861:     my $id = 'cgi.'.$identifier;
                   9862:     #
                   9863:     $Title  = '' if (! defined($Title));
                   9864:     $xlabel = '' if (! defined($xlabel));
                   9865:     $ylabel = '' if (! defined($ylabel));
                   9866:     my %ValuesHash = 
                   9867:         (
1.369     www      9868:          $id.'.title'  => &escape($Title),
                   9869:          $id.'.xlabel' => &escape($xlabel),
                   9870:          $id.'.ylabel' => &escape($ylabel),
1.136     matthew  9871:          $id.'.labels' => join(',',@$Xlabels),
                   9872:          $id.'.PlotType' => 'XY',
                   9873:          $id.'.NumSets' => 2,
1.137     matthew  9874:          $id.'.two_axes' => 1,
                   9875:          $id.'.y1_max_value' => $Max1,
                   9876:          $id.'.y1_min_value' => $Min1,
                   9877:          $id.'.y2_max_value' => $Max2,
                   9878:          $id.'.y2_min_value' => $Min2,
1.136     matthew  9879:          );
                   9880:     #
1.137     matthew  9881:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   9882:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   9883:     }
                   9884:     #
                   9885:     if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
                   9886:         ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136     matthew  9887:         return '';
                   9888:     }
                   9889:     my $NumSets=1;
1.137     matthew  9890:     foreach my $array ($Ydata1,$Ydata2){
1.136     matthew  9891:         next if (! ref($array));
                   9892:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137     matthew  9893:     }
                   9894:     #
                   9895:     # Deal with other parameters
                   9896:     while (my ($key,$value) = each(%Values)) {
                   9897:         $ValuesHash{$id.'.'.$key} = $value;
1.136     matthew  9898:     }
                   9899:     #
1.646     raeburn  9900:     &Apache::lonnet::appenv(\%ValuesHash);
1.130     albertel 9901:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139     matthew  9902: }
                   9903: 
                   9904: ############################################################
                   9905: ############################################################
                   9906: 
                   9907: =pod
                   9908: 
1.157     matthew  9909: =back 
                   9910: 
1.139     matthew  9911: =head1 Statistics helper routines?  
                   9912: 
                   9913: Bad place for them but what the hell.
                   9914: 
1.157     matthew  9915: =over 4
                   9916: 
1.648     raeburn  9917: =item * &chartlink()
1.139     matthew  9918: 
                   9919: Returns a link to the chart for a specific student.  
                   9920: 
                   9921: Inputs:
                   9922: 
                   9923: =over 4
                   9924: 
                   9925: =item $linktext: The text of the link
                   9926: 
                   9927: =item $sname: The students username
                   9928: 
                   9929: =item $sdomain: The students domain
                   9930: 
                   9931: =back
                   9932: 
1.157     matthew  9933: =back
                   9934: 
1.139     matthew  9935: =cut
                   9936: 
                   9937: ############################################################
                   9938: ############################################################
                   9939: sub chartlink {
                   9940:     my ($linktext, $sname, $sdomain) = @_;
                   9941:     my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369     www      9942:         '&amp;SelectedStudent='.&escape($sname.':'.$sdomain).
1.219     albertel 9943:         '&amp;chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139     matthew  9944:        '">'.$linktext.'</a>';
1.153     matthew  9945: }
                   9946: 
                   9947: #######################################################
                   9948: #######################################################
                   9949: 
                   9950: =pod
                   9951: 
                   9952: =head1 Course Environment Routines
1.157     matthew  9953: 
                   9954: =over 4
1.153     matthew  9955: 
1.648     raeburn  9956: =item * &restore_course_settings()
1.153     matthew  9957: 
1.648     raeburn  9958: =item * &store_course_settings()
1.153     matthew  9959: 
                   9960: Restores/Store indicated form parameters from the course environment.
                   9961: Will not overwrite existing values of the form parameters.
                   9962: 
                   9963: Inputs: 
                   9964: a scalar describing the data (e.g. 'chart', 'problem_analysis')
                   9965: 
                   9966: a hash ref describing the data to be stored.  For example:
                   9967:    
                   9968: %Save_Parameters = ('Status' => 'scalar',
                   9969:     'chartoutputmode' => 'scalar',
                   9970:     'chartoutputdata' => 'scalar',
                   9971:     'Section' => 'array',
1.373     raeburn  9972:     'Group' => 'array',
1.153     matthew  9973:     'StudentData' => 'array',
                   9974:     'Maps' => 'array');
                   9975: 
                   9976: Returns: both routines return nothing
                   9977: 
1.631     raeburn  9978: =back
                   9979: 
1.153     matthew  9980: =cut
                   9981: 
                   9982: #######################################################
                   9983: #######################################################
                   9984: sub store_course_settings {
1.496     albertel 9985:     return &store_settings($env{'request.course.id'},@_);
                   9986: }
                   9987: 
                   9988: sub store_settings {
1.153     matthew  9989:     # save to the environment
                   9990:     # appenv the same items, just to be safe
1.300     albertel 9991:     my $udom  = $env{'user.domain'};
                   9992:     my $uname = $env{'user.name'};
1.496     albertel 9993:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  9994:     my %SaveHash;
                   9995:     my %AppHash;
                   9996:     while (my ($setting,$type) = each(%$Settings)) {
1.496     albertel 9997:         my $basename = join('.','internal',$context,$prefix,$setting);
1.300     albertel 9998:         my $envname = 'environment.'.$basename;
1.258     albertel 9999:         if (exists($env{'form.'.$setting})) {
1.153     matthew  10000:             # Save this value away
                   10001:             if ($type eq 'scalar' &&
1.258     albertel 10002:                 (! exists($env{$envname}) || 
                   10003:                  $env{$envname} ne $env{'form.'.$setting})) {
                   10004:                 $SaveHash{$basename} = $env{'form.'.$setting};
                   10005:                 $AppHash{$envname}   = $env{'form.'.$setting};
1.153     matthew  10006:             } elsif ($type eq 'array') {
                   10007:                 my $stored_form;
1.258     albertel 10008:                 if (ref($env{'form.'.$setting})) {
1.153     matthew  10009:                     $stored_form = join(',',
                   10010:                                         map {
1.369     www      10011:                                             &escape($_);
1.258     albertel 10012:                                         } sort(@{$env{'form.'.$setting}}));
1.153     matthew  10013:                 } else {
                   10014:                     $stored_form = 
1.369     www      10015:                         &escape($env{'form.'.$setting});
1.153     matthew  10016:                 }
                   10017:                 # Determine if the array contents are the same.
1.258     albertel 10018:                 if ($stored_form ne $env{$envname}) {
1.153     matthew  10019:                     $SaveHash{$basename} = $stored_form;
                   10020:                     $AppHash{$envname}   = $stored_form;
                   10021:                 }
                   10022:             }
                   10023:         }
                   10024:     }
                   10025:     my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300     albertel 10026:                                           $udom,$uname);
1.153     matthew  10027:     if ($put_result !~ /^(ok|delayed)/) {
                   10028:         &Apache::lonnet::logthis('unable to save form parameters, '.
                   10029:                                  'got error:'.$put_result);
                   10030:     }
                   10031:     # Make sure these settings stick around in this session, too
1.646     raeburn  10032:     &Apache::lonnet::appenv(\%AppHash);
1.153     matthew  10033:     return;
                   10034: }
                   10035: 
                   10036: sub restore_course_settings {
1.499     albertel 10037:     return &restore_settings($env{'request.course.id'},@_);
1.496     albertel 10038: }
                   10039: 
                   10040: sub restore_settings {
                   10041:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  10042:     while (my ($setting,$type) = each(%$Settings)) {
1.258     albertel 10043:         next if (exists($env{'form.'.$setting}));
1.496     albertel 10044:         my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153     matthew  10045:             '.'.$setting;
1.258     albertel 10046:         if (exists($env{$envname})) {
1.153     matthew  10047:             if ($type eq 'scalar') {
1.258     albertel 10048:                 $env{'form.'.$setting} = $env{$envname};
1.153     matthew  10049:             } elsif ($type eq 'array') {
1.258     albertel 10050:                 $env{'form.'.$setting} = [ 
1.153     matthew  10051:                                            map { 
1.369     www      10052:                                                &unescape($_); 
1.258     albertel 10053:                                            } split(',',$env{$envname})
1.153     matthew  10054:                                            ];
                   10055:             }
                   10056:         }
                   10057:     }
1.127     matthew  10058: }
                   10059: 
1.618     raeburn  10060: #######################################################
                   10061: #######################################################
                   10062: 
                   10063: =pod
                   10064: 
                   10065: =head1 Domain E-mail Routines  
                   10066: 
                   10067: =over 4
                   10068: 
1.648     raeburn  10069: =item * &build_recipient_list()
1.618     raeburn  10070: 
1.884     raeburn  10071: Build recipient lists for five types of e-mail:
1.766     raeburn  10072: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884     raeburn  10073: (d) Help requests, (e) Course requests needing approval,  generated by
                   10074: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
                   10075: loncoursequeueadmin.pm respectively.
1.618     raeburn  10076: 
                   10077: Inputs:
1.619     raeburn  10078: defmail (scalar - email address of default recipient), 
1.618     raeburn  10079: mailing type (scalar - errormail, packagesmail, or helpdeskmail), 
1.619     raeburn  10080: defdom (domain for which to retrieve configuration settings),
                   10081: origmail (scalar - email address of recipient from loncapa.conf, 
                   10082: i.e., predates configuration by DC via domainprefs.pm 
1.618     raeburn  10083: 
1.655     raeburn  10084: Returns: comma separated list of addresses to which to send e-mail.
                   10085: 
                   10086: =back
1.618     raeburn  10087: 
                   10088: =cut
                   10089: 
                   10090: ############################################################
                   10091: ############################################################
                   10092: sub build_recipient_list {
1.619     raeburn  10093:     my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618     raeburn  10094:     my @recipients;
                   10095:     my $otheremails;
                   10096:     my %domconfig =
                   10097:          &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
                   10098:     if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766     raeburn  10099:         if (exists($domconfig{'contacts'}{$mailing})) {
                   10100:             if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
                   10101:                 my @contacts = ('adminemail','supportemail');
                   10102:                 foreach my $item (@contacts) {
                   10103:                     if ($domconfig{'contacts'}{$mailing}{$item}) {
                   10104:                         my $addr = $domconfig{'contacts'}{$item}; 
                   10105:                         if (!grep(/^\Q$addr\E$/,@recipients)) {
                   10106:                             push(@recipients,$addr);
                   10107:                         }
1.619     raeburn  10108:                     }
1.766     raeburn  10109:                     $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618     raeburn  10110:                 }
                   10111:             }
1.766     raeburn  10112:         } elsif ($origmail ne '') {
                   10113:             push(@recipients,$origmail);
1.618     raeburn  10114:         }
1.619     raeburn  10115:     } elsif ($origmail ne '') {
                   10116:         push(@recipients,$origmail);
1.618     raeburn  10117:     }
1.688     raeburn  10118:     if (defined($defmail)) {
                   10119:         if ($defmail ne '') {
                   10120:             push(@recipients,$defmail);
                   10121:         }
1.618     raeburn  10122:     }
                   10123:     if ($otheremails) {
1.619     raeburn  10124:         my @others;
                   10125:         if ($otheremails =~ /,/) {
                   10126:             @others = split(/,/,$otheremails);
1.618     raeburn  10127:         } else {
1.619     raeburn  10128:             push(@others,$otheremails);
                   10129:         }
                   10130:         foreach my $addr (@others) {
                   10131:             if (!grep(/^\Q$addr\E$/,@recipients)) {
                   10132:                 push(@recipients,$addr);
                   10133:             }
1.618     raeburn  10134:         }
                   10135:     }
1.619     raeburn  10136:     my $recipientlist = join(',',@recipients); 
1.618     raeburn  10137:     return $recipientlist;
                   10138: }
                   10139: 
1.127     matthew  10140: ############################################################
                   10141: ############################################################
1.154     albertel 10142: 
1.655     raeburn  10143: =pod
                   10144: 
                   10145: =head1 Course Catalog Routines
                   10146: 
                   10147: =over 4
                   10148: 
                   10149: =item * &gather_categories()
                   10150: 
                   10151: Converts category definitions - keys of categories hash stored in  
                   10152: coursecategories in configuration.db on the primary library server in a 
                   10153: domain - to an array.  Also generates javascript and idx hash used to 
                   10154: generate Domain Coordinator interface for editing Course Categories.
                   10155: 
                   10156: Inputs:
1.663     raeburn  10157: 
1.655     raeburn  10158: categories (reference to hash of category definitions).
1.663     raeburn  10159: 
1.655     raeburn  10160: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   10161:       categories and subcategories).
1.663     raeburn  10162: 
1.655     raeburn  10163: idx (reference to hash of counters used in Domain Coordinator interface for 
                   10164:       editing Course Categories).
1.663     raeburn  10165: 
1.655     raeburn  10166: jsarray (reference to array of categories used to create Javascript arrays for
                   10167:          Domain Coordinator interface for editing Course Categories).
                   10168: 
                   10169: Returns: nothing
                   10170: 
                   10171: Side effects: populates cats, idx and jsarray. 
                   10172: 
                   10173: =cut
                   10174: 
                   10175: sub gather_categories {
                   10176:     my ($categories,$cats,$idx,$jsarray) = @_;
                   10177:     my %counters;
                   10178:     my $num = 0;
                   10179:     foreach my $item (keys(%{$categories})) {
                   10180:         my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   10181:         if ($container eq '' && $depth == 0) {
                   10182:             $cats->[$depth][$categories->{$item}] = $cat;
                   10183:         } else {
                   10184:             $cats->[$depth]{$container}[$categories->{$item}] = $cat;
                   10185:         }
                   10186:         my ($escitem,$tail) = split(/:/,$item,2);
                   10187:         if ($counters{$tail} eq '') {
                   10188:             $counters{$tail} = $num;
                   10189:             $num ++;
                   10190:         }
                   10191:         if (ref($idx) eq 'HASH') {
                   10192:             $idx->{$item} = $counters{$tail};
                   10193:         }
                   10194:         if (ref($jsarray) eq 'ARRAY') {
                   10195:             push(@{$jsarray->[$counters{$tail}]},$item);
                   10196:         }
                   10197:     }
                   10198:     return;
                   10199: }
                   10200: 
                   10201: =pod
                   10202: 
                   10203: =item * &extract_categories()
                   10204: 
                   10205: Used to generate breadcrumb trails for course categories.
                   10206: 
                   10207: Inputs:
1.663     raeburn  10208: 
1.655     raeburn  10209: categories (reference to hash of category definitions).
1.663     raeburn  10210: 
1.655     raeburn  10211: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   10212:       categories and subcategories).
1.663     raeburn  10213: 
1.655     raeburn  10214: trails (reference to array of breacrumb trails for each category).
1.663     raeburn  10215: 
1.655     raeburn  10216: allitems (reference to hash - key is category key 
                   10217:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  10218: 
1.655     raeburn  10219: idx (reference to hash of counters used in Domain Coordinator interface for
                   10220:       editing Course Categories).
1.663     raeburn  10221: 
1.655     raeburn  10222: jsarray (reference to array of categories used to create Javascript arrays for
                   10223:          Domain Coordinator interface for editing Course Categories).
                   10224: 
1.665     raeburn  10225: subcats (reference to hash of arrays containing all subcategories within each 
                   10226:          category, -recursive)
                   10227: 
1.655     raeburn  10228: Returns: nothing
                   10229: 
                   10230: Side effects: populates trails and allitems hash references.
                   10231: 
                   10232: =cut
                   10233: 
                   10234: sub extract_categories {
1.665     raeburn  10235:     my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655     raeburn  10236:     if (ref($categories) eq 'HASH') {
                   10237:         &gather_categories($categories,$cats,$idx,$jsarray);
                   10238:         if (ref($cats->[0]) eq 'ARRAY') {
                   10239:             for (my $i=0; $i<@{$cats->[0]}; $i++) {
                   10240:                 my $name = $cats->[0][$i];
                   10241:                 my $item = &escape($name).'::0';
                   10242:                 my $trailstr;
                   10243:                 if ($name eq 'instcode') {
                   10244:                     $trailstr = &mt('Official courses (with institutional codes)');
1.919     raeburn  10245:                 } elsif ($name eq 'communities') {
                   10246:                     $trailstr = &mt('Communities');
1.655     raeburn  10247:                 } else {
                   10248:                     $trailstr = $name;
                   10249:                 }
                   10250:                 if ($allitems->{$item} eq '') {
                   10251:                     push(@{$trails},$trailstr);
                   10252:                     $allitems->{$item} = scalar(@{$trails})-1;
                   10253:                 }
                   10254:                 my @parents = ($name);
                   10255:                 if (ref($cats->[1]{$name}) eq 'ARRAY') {
                   10256:                     for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
                   10257:                         my $category = $cats->[1]{$name}[$j];
1.665     raeburn  10258:                         if (ref($subcats) eq 'HASH') {
                   10259:                             push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
                   10260:                         }
                   10261:                         &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
                   10262:                     }
                   10263:                 } else {
                   10264:                     if (ref($subcats) eq 'HASH') {
                   10265:                         $subcats->{$item} = [];
1.655     raeburn  10266:                     }
                   10267:                 }
                   10268:             }
                   10269:         }
                   10270:     }
                   10271:     return;
                   10272: }
                   10273: 
                   10274: =pod
                   10275: 
                   10276: =item *&recurse_categories()
                   10277: 
                   10278: Recursively used to generate breadcrumb trails for course categories.
                   10279: 
                   10280: Inputs:
1.663     raeburn  10281: 
1.655     raeburn  10282: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   10283:       categories and subcategories).
1.663     raeburn  10284: 
1.655     raeburn  10285: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663     raeburn  10286: 
                   10287: category (current course category, for which breadcrumb trail is being generated).
                   10288: 
                   10289: trails (reference to array of breadcrumb trails for each category).
                   10290: 
1.655     raeburn  10291: allitems (reference to hash - key is category key
                   10292:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  10293: 
1.655     raeburn  10294: parents (array containing containers directories for current category, 
                   10295:          back to top level). 
                   10296: 
                   10297: Returns: nothing
                   10298: 
                   10299: Side effects: populates trails and allitems hash references
                   10300: 
                   10301: =cut
                   10302: 
                   10303: sub recurse_categories {
1.665     raeburn  10304:     my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655     raeburn  10305:     my $shallower = $depth - 1;
                   10306:     if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
                   10307:         for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
                   10308:             my $name = $cats->[$depth]{$category}[$k];
                   10309:             my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   10310:             my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   10311:             if ($allitems->{$item} eq '') {
                   10312:                 push(@{$trails},$trailstr);
                   10313:                 $allitems->{$item} = scalar(@{$trails})-1;
                   10314:             }
                   10315:             my $deeper = $depth+1;
                   10316:             push(@{$parents},$category);
1.665     raeburn  10317:             if (ref($subcats) eq 'HASH') {
                   10318:                 my $subcat = &escape($name).':'.$category.':'.$depth;
                   10319:                 for (my $j=@{$parents}; $j>=0; $j--) {
                   10320:                     my $higher;
                   10321:                     if ($j > 0) {
                   10322:                         $higher = &escape($parents->[$j]).':'.
                   10323:                                   &escape($parents->[$j-1]).':'.$j;
                   10324:                     } else {
                   10325:                         $higher = &escape($parents->[$j]).'::'.$j;
                   10326:                     }
                   10327:                     push(@{$subcats->{$higher}},$subcat);
                   10328:                 }
                   10329:             }
                   10330:             &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
                   10331:                                 $subcats);
1.655     raeburn  10332:             pop(@{$parents});
                   10333:         }
                   10334:     } else {
                   10335:         my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   10336:         my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   10337:         if ($allitems->{$item} eq '') {
                   10338:             push(@{$trails},$trailstr);
                   10339:             $allitems->{$item} = scalar(@{$trails})-1;
                   10340:         }
                   10341:     }
                   10342:     return;
                   10343: }
                   10344: 
1.663     raeburn  10345: =pod
                   10346: 
                   10347: =item *&assign_categories_table()
                   10348: 
                   10349: Create a datatable for display of hierarchical categories in a domain,
                   10350: with checkboxes to allow a course to be categorized. 
                   10351: 
                   10352: Inputs:
                   10353: 
                   10354: cathash - reference to hash of categories defined for the domain (from
                   10355:           configuration.db)
                   10356: 
                   10357: currcat - scalar with an & separated list of categories assigned to a course. 
                   10358: 
1.919     raeburn  10359: type    - scalar contains course type (Course or Community).
                   10360: 
1.663     raeburn  10361: Returns: $output (markup to be displayed) 
                   10362: 
                   10363: =cut
                   10364: 
                   10365: sub assign_categories_table {
1.919     raeburn  10366:     my ($cathash,$currcat,$type) = @_;
1.663     raeburn  10367:     my $output;
                   10368:     if (ref($cathash) eq 'HASH') {
                   10369:         my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
                   10370:         &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
                   10371:         $maxdepth = scalar(@cats);
                   10372:         if (@cats > 0) {
                   10373:             my $itemcount = 0;
                   10374:             if (ref($cats[0]) eq 'ARRAY') {
                   10375:                 my @currcategories;
                   10376:                 if ($currcat ne '') {
                   10377:                     @currcategories = split('&',$currcat);
                   10378:                 }
1.919     raeburn  10379:                 my $table;
1.663     raeburn  10380:                 for (my $i=0; $i<@{$cats[0]}; $i++) {
                   10381:                     my $parent = $cats[0][$i];
1.919     raeburn  10382:                     next if ($parent eq 'instcode');
                   10383:                     if ($type eq 'Community') {
                   10384:                         next unless ($parent eq 'communities');
                   10385:                     } else {
                   10386:                         next if ($parent eq 'communities');
                   10387:                     }
1.663     raeburn  10388:                     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   10389:                     my $item = &escape($parent).'::0';
                   10390:                     my $checked = '';
                   10391:                     if (@currcategories > 0) {
                   10392:                         if (grep(/^\Q$item\E$/,@currcategories)) {
1.772     bisitz   10393:                             $checked = ' checked="checked"';
1.663     raeburn  10394:                         }
                   10395:                     }
1.919     raeburn  10396:                     my $parent_title = $parent;
                   10397:                     if ($parent eq 'communities') {
                   10398:                         $parent_title = &mt('Communities');
                   10399:                     }
                   10400:                     $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
                   10401:                               '<input type="checkbox" name="usecategory" value="'.
                   10402:                               $item.'"'.$checked.' />'.$parent_title.'</span>'.
                   10403:                               '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663     raeburn  10404:                     my $depth = 1;
                   10405:                     push(@path,$parent);
1.919     raeburn  10406:                     $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663     raeburn  10407:                     pop(@path);
1.919     raeburn  10408:                     $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663     raeburn  10409:                     $itemcount ++;
                   10410:                 }
1.919     raeburn  10411:                 if ($itemcount) {
                   10412:                     $output = &Apache::loncommon::start_data_table().
                   10413:                               $table.
                   10414:                               &Apache::loncommon::end_data_table();
                   10415:                 }
1.663     raeburn  10416:             }
                   10417:         }
                   10418:     }
                   10419:     return $output;
                   10420: }
                   10421: 
                   10422: =pod
                   10423: 
                   10424: =item *&assign_category_rows()
                   10425: 
                   10426: Create a datatable row for display of nested categories in a domain,
                   10427: with checkboxes to allow a course to be categorized,called recursively.
                   10428: 
                   10429: Inputs:
                   10430: 
                   10431: itemcount - track row number for alternating colors
                   10432: 
                   10433: cats - reference to array of arrays/hashes which encapsulates hierarchy of
                   10434:       categories and subcategories.
                   10435: 
                   10436: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
                   10437: 
                   10438: parent - parent of current category item
                   10439: 
                   10440: path - Array containing all categories back up through the hierarchy from the
                   10441:        current category to the top level.
                   10442: 
                   10443: currcategories - reference to array of current categories assigned to the course
                   10444: 
                   10445: Returns: $output (markup to be displayed).
                   10446: 
                   10447: =cut
                   10448: 
                   10449: sub assign_category_rows {
                   10450:     my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
                   10451:     my ($text,$name,$item,$chgstr);
                   10452:     if (ref($cats) eq 'ARRAY') {
                   10453:         my $maxdepth = scalar(@{$cats});
                   10454:         if (ref($cats->[$depth]) eq 'HASH') {
                   10455:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   10456:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   10457:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   10458:                 $text .= '<td><table class="LC_datatable">';
                   10459:                 for (my $j=0; $j<$numchildren; $j++) {
                   10460:                     $name = $cats->[$depth]{$parent}[$j];
                   10461:                     $item = &escape($name).':'.&escape($parent).':'.$depth;
                   10462:                     my $deeper = $depth+1;
                   10463:                     my $checked = '';
                   10464:                     if (ref($currcategories) eq 'ARRAY') {
                   10465:                         if (@{$currcategories} > 0) {
                   10466:                             if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772     bisitz   10467:                                 $checked = ' checked="checked"';
1.663     raeburn  10468:                             }
                   10469:                         }
                   10470:                     }
1.664     raeburn  10471:                     $text .= '<tr><td><span class="LC_nobreak"><label>'.
                   10472:                              '<input type="checkbox" name="usecategory" value="'.
1.675     raeburn  10473:                              $item.'"'.$checked.' />'.$name.'</label></span>'.
                   10474:                              '<input type="hidden" name="catname" value="'.$name.'" />'.
                   10475:                              '</td><td>';
1.663     raeburn  10476:                     if (ref($path) eq 'ARRAY') {
                   10477:                         push(@{$path},$name);
                   10478:                         $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
                   10479:                         pop(@{$path});
                   10480:                     }
                   10481:                     $text .= '</td></tr>';
                   10482:                 }
                   10483:                 $text .= '</table></td>';
                   10484:             }
                   10485:         }
                   10486:     }
                   10487:     return $text;
                   10488: }
                   10489: 
1.655     raeburn  10490: ############################################################
                   10491: ############################################################
                   10492: 
                   10493: 
1.443     albertel 10494: sub commit_customrole {
1.664     raeburn  10495:     my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630     raeburn  10496:     my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443     albertel 10497:                          ($start?', '.&mt('starting').' '.localtime($start):'').
                   10498:                          ($end?', ending '.localtime($end):'').': <b>'.
                   10499:               &Apache::lonnet::assigncustomrole(
1.664     raeburn  10500:                  $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443     albertel 10501:                  '</b><br />';
                   10502:     return $output;
                   10503: }
                   10504: 
                   10505: sub commit_standardrole {
1.541     raeburn  10506:     my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
                   10507:     my ($output,$logmsg,$linefeed);
                   10508:     if ($context eq 'auto') {
                   10509:         $linefeed = "\n";
                   10510:     } else {
                   10511:         $linefeed = "<br />\n";
                   10512:     }  
1.443     albertel 10513:     if ($three eq 'st') {
1.541     raeburn  10514:         my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
                   10515:                                          $one,$two,$sec,$context);
                   10516:         if (($result =~ /^error/) || ($result eq 'not_in_class') || 
1.626     raeburn  10517:             ($result eq 'unknown_course') || ($result eq 'refused')) {
                   10518:             $output = $logmsg.' '.&mt('Error: ').$result."\n"; 
1.443     albertel 10519:         } else {
1.541     raeburn  10520:             $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443     albertel 10521:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  10522:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
                   10523:             if ($context eq 'auto') {
                   10524:                 $output .= $result.$linefeed.&mt('Add to classlist').': ok';
                   10525:             } else {
                   10526:                $output .= '<b>'.$result.'</b>'.$linefeed.
                   10527:                &mt('Add to classlist').': <b>ok</b>';
                   10528:             }
                   10529:             $output .= $linefeed;
1.443     albertel 10530:         }
                   10531:     } else {
                   10532:         $output = &mt('Assigning').' '.$three.' in '.$url.
                   10533:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  10534:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652     raeburn  10535:         my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541     raeburn  10536:         if ($context eq 'auto') {
                   10537:             $output .= $result.$linefeed;
                   10538:         } else {
                   10539:             $output .= '<b>'.$result.'</b>'.$linefeed;
                   10540:         }
1.443     albertel 10541:     }
                   10542:     return $output;
                   10543: }
                   10544: 
                   10545: sub commit_studentrole {
1.541     raeburn  10546:     my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626     raeburn  10547:     my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541     raeburn  10548:     if ($context eq 'auto') {
                   10549:         $linefeed = "\n";
                   10550:     } else {
                   10551:         $linefeed = '<br />'."\n";
                   10552:     }
1.443     albertel 10553:     if (defined($one) && defined($two)) {
                   10554:         my $cid=$one.'_'.$two;
                   10555:         my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
                   10556:         my $secchange = 0;
                   10557:         my $expire_role_result;
                   10558:         my $modify_section_result;
1.628     raeburn  10559:         if ($oldsec ne '-1') { 
                   10560:             if ($oldsec ne $sec) {
1.443     albertel 10561:                 $secchange = 1;
1.628     raeburn  10562:                 my $now = time;
1.443     albertel 10563:                 my $uurl='/'.$cid;
                   10564:                 $uurl=~s/\_/\//g;
                   10565:                 if ($oldsec) {
                   10566:                     $uurl.='/'.$oldsec;
                   10567:                 }
1.626     raeburn  10568:                 $oldsecurl = $uurl;
1.628     raeburn  10569:                 $expire_role_result = 
1.652     raeburn  10570:                     &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628     raeburn  10571:                 if ($env{'request.course.sec'} ne '') { 
                   10572:                     if ($expire_role_result eq 'refused') {
                   10573:                         my @roles = ('st');
                   10574:                         my @statuses = ('previous');
                   10575:                         my @roledoms = ($one);
                   10576:                         my $withsec = 1;
                   10577:                         my %roleshash = 
                   10578:                             &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
                   10579:                                               \@statuses,\@roles,\@roledoms,$withsec);
                   10580:                         if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
                   10581:                             my ($oldstart,$oldend) = 
                   10582:                                 split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
                   10583:                             if ($oldend > 0 && $oldend <= $now) {
                   10584:                                 $expire_role_result = 'ok';
                   10585:                             }
                   10586:                         }
                   10587:                     }
                   10588:                 }
1.443     albertel 10589:                 $result = $expire_role_result;
                   10590:             }
                   10591:         }
                   10592:         if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652     raeburn  10593:             $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443     albertel 10594:             if ($modify_section_result =~ /^ok/) {
                   10595:                 if ($secchange == 1) {
1.628     raeburn  10596:                     if ($sec eq '') {
                   10597:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
                   10598:                     } else {
                   10599:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
                   10600:                     }
1.443     albertel 10601:                 } elsif ($oldsec eq '-1') {
1.628     raeburn  10602:                     if ($sec eq '') {
                   10603:                         $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
                   10604:                     } else {
                   10605:                         $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   10606:                     }
1.443     albertel 10607:                 } else {
1.628     raeburn  10608:                     if ($sec eq '') {
                   10609:                         $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
                   10610:                     } else {
                   10611:                         $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   10612:                     }
1.443     albertel 10613:                 }
                   10614:             } else {
1.628     raeburn  10615:                 if ($secchange) {       
                   10616:                     $$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;
                   10617:                 } else {
                   10618:                     $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
                   10619:                 }
1.443     albertel 10620:             }
                   10621:             $result = $modify_section_result;
                   10622:         } elsif ($secchange == 1) {
1.628     raeburn  10623:             if ($oldsec eq '') {
                   10624:                 $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
                   10625:             } else {
                   10626:                 $$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;
                   10627:             }
1.626     raeburn  10628:             if ($expire_role_result eq 'refused') {
                   10629:                 my $newsecurl = '/'.$cid;
                   10630:                 $newsecurl =~ s/\_/\//g;
                   10631:                 if ($sec ne '') {
                   10632:                     $newsecurl.='/'.$sec;
                   10633:                 }
                   10634:                 if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
                   10635:                     if ($sec eq '') {
                   10636:                         $$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;
                   10637:                     } else {
                   10638:                         $$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;
                   10639:                     }
                   10640:                 }
                   10641:             }
1.443     albertel 10642:         }
                   10643:     } else {
1.626     raeburn  10644:         $$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 10645:         $result = "error: incomplete course id\n";
                   10646:     }
                   10647:     return $result;
                   10648: }
                   10649: 
                   10650: ############################################################
                   10651: ############################################################
                   10652: 
1.566     albertel 10653: sub check_clone {
1.578     raeburn  10654:     my ($args,$linefeed) = @_;
1.566     albertel 10655:     my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
                   10656:     my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
                   10657:     my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
                   10658:     my $clonemsg;
                   10659:     my $can_clone = 0;
1.944     raeburn  10660:     my $lctype = lc($args->{'crstype'});
1.908     raeburn  10661:     if ($lctype ne 'community') {
                   10662:         $lctype = 'course';
                   10663:     }
1.566     albertel 10664:     if ($clonehome eq 'no_host') {
1.944     raeburn  10665:         if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  10666:             $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'});
                   10667:         } else {
                   10668:             $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'});
                   10669:         }     
1.566     albertel 10670:     } else {
                   10671: 	my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944     raeburn  10672:         if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  10673:             if ($clonedesc{'type'} ne 'Community') {
                   10674:                  $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'});
                   10675:                 return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   10676:             }
                   10677:         }
1.882     raeburn  10678: 	if (($env{'request.role.domain'} eq $args->{'clonedomain'}) && 
                   10679:             (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566     albertel 10680: 	    $can_clone = 1;
                   10681: 	} else {
                   10682: 	    my %clonehash = &Apache::lonnet::get('environment',['cloners'],
                   10683: 						 $args->{'clonedomain'},$args->{'clonecourse'});
                   10684: 	    my @cloners = split(/,/,$clonehash{'cloners'});
1.578     raeburn  10685:             if (grep(/^\*$/,@cloners)) {
                   10686:                 $can_clone = 1;
                   10687:             } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
                   10688:                 $can_clone = 1;
                   10689:             } else {
1.908     raeburn  10690:                 my $ccrole = 'cc';
1.944     raeburn  10691:                 if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  10692:                     $ccrole = 'co';
                   10693:                 }
1.578     raeburn  10694: 	        my %roleshash =
                   10695: 		    &Apache::lonnet::get_my_roles($args->{'ccuname'},
                   10696: 					 $args->{'ccdomain'},
1.908     raeburn  10697:                                          'userroles',['active'],[$ccrole],
1.578     raeburn  10698: 					 [$args->{'clonedomain'}]);
1.908     raeburn  10699: 	        if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942     raeburn  10700:                     $can_clone = 1;
                   10701:                 } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
                   10702:                     $can_clone = 1;
                   10703:                 } else {
1.944     raeburn  10704:                     if ($args->{'crstype'} eq 'Community') {
1.908     raeburn  10705:                         $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'});
                   10706:                     } else {
                   10707:                         $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'});
                   10708:                     }
1.578     raeburn  10709: 	        }
1.566     albertel 10710: 	    }
1.578     raeburn  10711:         }
1.566     albertel 10712:     }
                   10713:     return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   10714: }
                   10715: 
1.444     albertel 10716: sub construct_course {
1.885     raeburn  10717:     my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444     albertel 10718:     my $outcome;
1.541     raeburn  10719:     my $linefeed =  '<br />'."\n";
                   10720:     if ($context eq 'auto') {
                   10721:         $linefeed = "\n";
                   10722:     }
1.566     albertel 10723: 
                   10724: #
                   10725: # Are we cloning?
                   10726: #
                   10727:     my ($can_clone, $clonemsg, $cloneid, $clonehome);
                   10728:     if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578     raeburn  10729: 	($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566     albertel 10730: 	if ($context ne 'auto') {
1.578     raeburn  10731:             if ($clonemsg ne '') {
                   10732: 	        $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
                   10733:             }
1.566     albertel 10734: 	}
                   10735: 	$outcome .= $clonemsg.$linefeed;
                   10736: 
                   10737:         if (!$can_clone) {
                   10738: 	    return (0,$outcome);
                   10739: 	}
                   10740:     }
                   10741: 
1.444     albertel 10742: #
                   10743: # Open course
                   10744: #
                   10745:     my $crstype = lc($args->{'crstype'});
                   10746:     my %cenv=();
                   10747:     $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
                   10748:                                              $args->{'cdescr'},
                   10749:                                              $args->{'curl'},
                   10750:                                              $args->{'course_home'},
                   10751:                                              $args->{'nonstandard'},
                   10752:                                              $args->{'crscode'},
                   10753:                                              $args->{'ccuname'}.':'.
                   10754:                                              $args->{'ccdomain'},
1.882     raeburn  10755:                                              $args->{'crstype'},
1.885     raeburn  10756:                                              $cnum,$context,$category);
1.444     albertel 10757: 
                   10758:     # Note: The testing routines depend on this being output; see 
                   10759:     # Utils::Course. This needs to at least be output as a comment
                   10760:     # if anyone ever decides to not show this, and Utils::Course::new
                   10761:     # will need to be suitably modified.
1.541     raeburn  10762:     $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943     raeburn  10763:     if ($$courseid =~ /^error:/) {
                   10764:         return (0,$outcome);
                   10765:     }
                   10766: 
1.444     albertel 10767: #
                   10768: # Check if created correctly
                   10769: #
1.479     albertel 10770:     ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444     albertel 10771:     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943     raeburn  10772:     if ($crsuhome eq 'no_host') {
                   10773:         $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
                   10774:         return (0,$outcome);
                   10775:     }
1.541     raeburn  10776:     $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566     albertel 10777: 
1.444     albertel 10778: #
1.566     albertel 10779: # Do the cloning
                   10780: #   
                   10781:     if ($can_clone && $cloneid) {
                   10782: 	$clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
                   10783: 	if ($context ne 'auto') {
                   10784: 	    $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
                   10785: 	}
                   10786: 	$outcome .= $clonemsg.$linefeed;
                   10787: 	my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444     albertel 10788: # Copy all files
1.637     www      10789: 	&Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444     albertel 10790: # Restore URL
1.566     albertel 10791: 	$cenv{'url'}=$oldcenv{'url'};
1.444     albertel 10792: # Restore title
1.566     albertel 10793: 	$cenv{'description'}=$oldcenv{'description'};
1.955     raeburn  10794: # Restore creation date, creator and creation context.
                   10795:         $cenv{'internal.created'}=$oldcenv{'internal.created'};
                   10796:         $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
                   10797:         $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444     albertel 10798: # Mark as cloned
1.566     albertel 10799: 	$cenv{'clonedfrom'}=$cloneid;
1.638     www      10800: # Need to clone grading mode
                   10801:         my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
                   10802:         $cenv{'grading'}=$newenv{'grading'};
                   10803: # Do not clone these environment entries
                   10804:         &Apache::lonnet::del('environment',
                   10805:                   ['default_enrollment_start_date',
                   10806:                    'default_enrollment_end_date',
                   10807:                    'question.email',
                   10808:                    'policy.email',
                   10809:                    'comment.email',
                   10810:                    'pch.users.denied',
1.725     raeburn  10811:                    'plc.users.denied',
                   10812:                    'hidefromcat',
                   10813:                    'categories'],
1.638     www      10814:                    $$crsudom,$$crsunum);
1.444     albertel 10815:     }
1.566     albertel 10816: 
1.444     albertel 10817: #
                   10818: # Set environment (will override cloned, if existing)
                   10819: #
                   10820:     my @sections = ();
                   10821:     my @xlists = ();
                   10822:     if ($args->{'crstype'}) {
                   10823:         $cenv{'type'}=$args->{'crstype'};
                   10824:     }
                   10825:     if ($args->{'crsid'}) {
                   10826:         $cenv{'courseid'}=$args->{'crsid'};
                   10827:     }
                   10828:     if ($args->{'crscode'}) {
                   10829:         $cenv{'internal.coursecode'}=$args->{'crscode'};
                   10830:     }
                   10831:     if ($args->{'crsquota'} ne '') {
                   10832:         $cenv{'internal.coursequota'}=$args->{'crsquota'};
                   10833:     } else {
                   10834:         $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
                   10835:     }
                   10836:     if ($args->{'ccuname'}) {
                   10837:         $cenv{'internal.courseowner'} = $args->{'ccuname'}.
                   10838:                                         ':'.$args->{'ccdomain'};
                   10839:     } else {
                   10840:         $cenv{'internal.courseowner'} = $args->{'curruser'};
                   10841:     }
                   10842:     my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
                   10843:     if ($args->{'crssections'}) {
                   10844:         $cenv{'internal.sectionnums'} = '';
                   10845:         if ($args->{'crssections'} =~ m/,/) {
                   10846:             @sections = split/,/,$args->{'crssections'};
                   10847:         } else {
                   10848:             $sections[0] = $args->{'crssections'};
                   10849:         }
                   10850:         if (@sections > 0) {
                   10851:             foreach my $item (@sections) {
                   10852:                 my ($sec,$gp) = split/:/,$item;
                   10853:                 my $class = $args->{'crscode'}.$sec;
                   10854:                 my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
                   10855:                 $cenv{'internal.sectionnums'} .= $item.',';
                   10856:                 unless ($addcheck eq 'ok') {
                   10857:                     push @badclasses, $class;
                   10858:                 }
                   10859:             }
                   10860:             $cenv{'internal.sectionnums'} =~ s/,$//;
                   10861:         }
                   10862:     }
                   10863: # do not hide course coordinator from staff listing, 
                   10864: # even if privileged
                   10865:     $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   10866: # add crosslistings
                   10867:     if ($args->{'crsxlist'}) {
                   10868:         $cenv{'internal.crosslistings'}='';
                   10869:         if ($args->{'crsxlist'} =~ m/,/) {
                   10870:             @xlists = split/,/,$args->{'crsxlist'};
                   10871:         } else {
                   10872:             $xlists[0] = $args->{'crsxlist'};
                   10873:         }
                   10874:         if (@xlists > 0) {
                   10875:             foreach my $item (@xlists) {
                   10876:                 my ($xl,$gp) = split/:/,$item;
                   10877:                 my $addcheck =  &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
                   10878:                 $cenv{'internal.crosslistings'} .= $item.',';
                   10879:                 unless ($addcheck eq 'ok') {
                   10880:                     push @badclasses, $xl;
                   10881:                 }
                   10882:             }
                   10883:             $cenv{'internal.crosslistings'} =~ s/,$//;
                   10884:         }
                   10885:     }
                   10886:     if ($args->{'autoadds'}) {
                   10887:         $cenv{'internal.autoadds'}=$args->{'autoadds'};
                   10888:     }
                   10889:     if ($args->{'autodrops'}) {
                   10890:         $cenv{'internal.autodrops'}=$args->{'autodrops'};
                   10891:     }
                   10892: # check for notification of enrollment changes
                   10893:     my @notified = ();
                   10894:     if ($args->{'notify_owner'}) {
                   10895:         if ($args->{'ccuname'} ne '') {
                   10896:             push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
                   10897:         }
                   10898:     }
                   10899:     if ($args->{'notify_dc'}) {
                   10900:         if ($uname ne '') { 
1.630     raeburn  10901:             push(@notified,$uname.':'.$udom);
1.444     albertel 10902:         }
                   10903:     }
                   10904:     if (@notified > 0) {
                   10905:         my $notifylist;
                   10906:         if (@notified > 1) {
                   10907:             $notifylist = join(',',@notified);
                   10908:         } else {
                   10909:             $notifylist = $notified[0];
                   10910:         }
                   10911:         $cenv{'internal.notifylist'} = $notifylist;
                   10912:     }
                   10913:     if (@badclasses > 0) {
                   10914:         my %lt=&Apache::lonlocal::texthash(
                   10915:                 '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',
                   10916:                 'dnhr' => 'does not have rights to access enrollment in these classes',
                   10917:                 'adby' => 'as determined by the policies of your institution on access to official classlists'
                   10918:         );
1.541     raeburn  10919:         my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
                   10920:                            ' ('.$lt{'adby'}.')';
                   10921:         if ($context eq 'auto') {
                   10922:             $outcome .= $badclass_msg.$linefeed;
1.566     albertel 10923:             $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541     raeburn  10924:             foreach my $item (@badclasses) {
                   10925:                 if ($context eq 'auto') {
                   10926:                     $outcome .= " - $item\n";
                   10927:                 } else {
                   10928:                     $outcome .= "<li>$item</li>\n";
                   10929:                 }
                   10930:             }
                   10931:             if ($context eq 'auto') {
                   10932:                 $outcome .= $linefeed;
                   10933:             } else {
1.566     albertel 10934:                 $outcome .= "</ul><br /><br /></div>\n";
1.541     raeburn  10935:             }
                   10936:         } 
1.444     albertel 10937:     }
                   10938:     if ($args->{'no_end_date'}) {
                   10939:         $args->{'endaccess'} = 0;
                   10940:     }
                   10941:     $cenv{'internal.autostart'}=$args->{'enrollstart'};
                   10942:     $cenv{'internal.autoend'}=$args->{'enrollend'};
                   10943:     $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
                   10944:     $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
                   10945:     if ($args->{'showphotos'}) {
                   10946:       $cenv{'internal.showphotos'}=$args->{'showphotos'};
                   10947:     }
                   10948:     $cenv{'internal.authtype'} = $args->{'authtype'};
                   10949:     $cenv{'internal.autharg'} = $args->{'autharg'}; 
                   10950:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
                   10951:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
1.541     raeburn  10952:             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'); 
                   10953:             if ($context eq 'auto') {
                   10954:                 $outcome .= $krb_msg;
                   10955:             } else {
1.566     albertel 10956:                 $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541     raeburn  10957:             }
                   10958:             $outcome .= $linefeed;
1.444     albertel 10959:         }
                   10960:     }
                   10961:     if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
                   10962:        if ($args->{'setpolicy'}) {
                   10963:            $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   10964:        }
                   10965:        if ($args->{'setcontent'}) {
                   10966:            $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   10967:        }
                   10968:     }
                   10969:     if ($args->{'reshome'}) {
                   10970: 	$cenv{'reshome'}=$args->{'reshome'}.'/';
                   10971: 	$cenv{'reshome'}=~s/\/+$/\//;
                   10972:     }
                   10973: #
                   10974: # course has keyed access
                   10975: #
                   10976:     if ($args->{'setkeys'}) {
                   10977:        $cenv{'keyaccess'}='yes';
                   10978:     }
                   10979: # if specified, key authority is not course, but user
                   10980: # only active if keyaccess is yes
                   10981:     if ($args->{'keyauth'}) {
1.487     albertel 10982: 	my ($user,$domain) = split(':',$args->{'keyauth'});
                   10983: 	$user = &LONCAPA::clean_username($user);
                   10984: 	$domain = &LONCAPA::clean_username($domain);
1.488     foxr     10985: 	if ($user ne '' && $domain ne '') {
1.487     albertel 10986: 	    $cenv{'keyauth'}=$user.':'.$domain;
1.444     albertel 10987: 	}
                   10988:     }
                   10989: 
                   10990:     if ($args->{'disresdis'}) {
                   10991:         $cenv{'pch.roles.denied'}='st';
                   10992:     }
                   10993:     if ($args->{'disablechat'}) {
                   10994:         $cenv{'plc.roles.denied'}='st';
                   10995:     }
                   10996: 
                   10997:     # Record we've not yet viewed the Course Initialization Helper for this 
                   10998:     # course
                   10999:     $cenv{'course.helper.not.run'} = 1;
                   11000:     #
                   11001:     # Use new Randomseed
                   11002:     #
                   11003:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
                   11004:     $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
                   11005:     #
                   11006:     # The encryption code and receipt prefix for this course
                   11007:     #
                   11008:     $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
                   11009:     $cenv{'internal.encpref'}=100+int(9*rand(99));
                   11010:     #
                   11011:     # By default, use standard grading
                   11012:     if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
                   11013: 
1.541     raeburn  11014:     $outcome .= $linefeed.&mt('Setting environment').': '.                 
                   11015:           &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 11016: #
                   11017: # Open all assignments
                   11018: #
                   11019:     if ($args->{'openall'}) {
                   11020:        my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
                   11021:        my %storecontent = ($storeunder         => time,
                   11022:                            $storeunder.'.type' => 'date_start');
                   11023:        
                   11024:        $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541     raeburn  11025:                  ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 11026:    }
                   11027: #
                   11028: # Set first page
                   11029: #
                   11030:     unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
                   11031: 	    || ($cloneid)) {
1.445     albertel 11032: 	use LONCAPA::map;
1.444     albertel 11033: 	$outcome .= &mt('Setting first resource').': ';
1.445     albertel 11034: 
                   11035: 	my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
                   11036:         my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
                   11037: 
1.444     albertel 11038:         $outcome .= ($fatal?$errtext:'read ok').' - ';
                   11039:         my $title; my $url;
                   11040:         if ($args->{'firstres'} eq 'syl') {
1.690     bisitz   11041: 	    $title=&mt('Syllabus');
1.444     albertel 11042:             $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
                   11043:         } else {
1.963     raeburn  11044:             $title=&mt('Table of Contents');
1.444     albertel 11045:             $url='/adm/navmaps';
                   11046:         }
1.445     albertel 11047: 
                   11048:         $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
                   11049: 	(my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
                   11050: 
                   11051: 	if ($errtext) { $fatal=2; }
1.541     raeburn  11052:         $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444     albertel 11053:     }
1.566     albertel 11054: 
                   11055:     return (1,$outcome);
1.444     albertel 11056: }
                   11057: 
                   11058: ############################################################
                   11059: ############################################################
                   11060: 
1.953     droeschl 11061: #SD
                   11062: # only Community and Course, or anything else?
1.378     raeburn  11063: sub course_type {
                   11064:     my ($cid) = @_;
                   11065:     if (!defined($cid)) {
                   11066:         $cid = $env{'request.course.id'};
                   11067:     }
1.404     albertel 11068:     if (defined($env{'course.'.$cid.'.type'})) {
                   11069:         return $env{'course.'.$cid.'.type'};
1.378     raeburn  11070:     } else {
                   11071:         return 'Course';
1.377     raeburn  11072:     }
                   11073: }
1.156     albertel 11074: 
1.406     raeburn  11075: sub group_term {
                   11076:     my $crstype = &course_type();
                   11077:     my %names = (
                   11078:                   'Course' => 'group',
1.865     raeburn  11079:                   'Community' => 'group',
1.406     raeburn  11080:                 );
                   11081:     return $names{$crstype};
                   11082: }
                   11083: 
1.902     raeburn  11084: sub course_types {
                   11085:     my @types = ('official','unofficial','community');
                   11086:     my %typename = (
                   11087:                          official   => 'Official course',
                   11088:                          unofficial => 'Unofficial course',
                   11089:                          community  => 'Community',
                   11090:                    );
                   11091:     return (\@types,\%typename);
                   11092: }
                   11093: 
1.156     albertel 11094: sub icon {
                   11095:     my ($file)=@_;
1.505     albertel 11096:     my $curfext = lc((split(/\./,$file))[-1]);
1.168     albertel 11097:     my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156     albertel 11098:     my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168     albertel 11099:     if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
                   11100: 	if (-e  $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
                   11101: 	          $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   11102: 	            $curfext.".gif") {
                   11103: 	    $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   11104: 		$curfext.".gif";
                   11105: 	}
                   11106:     }
1.249     albertel 11107:     return &lonhttpdurl($iconname);
1.154     albertel 11108: } 
1.84      albertel 11109: 
1.575     albertel 11110: sub lonhttpdurl {
1.692     www      11111: #
                   11112: # Had been used for "small fry" static images on separate port 8080.
                   11113: # Modify here if lightweight http functionality desired again.
                   11114: # Currently eliminated due to increasing firewall issues.
                   11115: #
1.575     albertel 11116:     my ($url)=@_;
1.692     www      11117:     return $url;
1.215     albertel 11118: }
                   11119: 
1.213     albertel 11120: sub connection_aborted {
                   11121:     my ($r)=@_;
                   11122:     $r->print(" ");$r->rflush();
                   11123:     my $c = $r->connection;
                   11124:     return $c->aborted();
                   11125: }
                   11126: 
1.221     foxr     11127: #    Escapes strings that may have embedded 's that will be put into
1.222     foxr     11128: #    strings as 'strings'.
                   11129: sub escape_single {
1.221     foxr     11130:     my ($input) = @_;
1.223     albertel 11131:     $input =~ s/\\/\\\\/g;	# Escape the \'s..(must be first)>
1.221     foxr     11132:     $input =~ s/\'/\\\'/g;	# Esacpe the 's....
                   11133:     return $input;
                   11134: }
1.223     albertel 11135: 
1.222     foxr     11136: #  Same as escape_single, but escape's "'s  This 
                   11137: #  can be used for  "strings"
                   11138: sub escape_double {
                   11139:     my ($input) = @_;
                   11140:     $input =~ s/\\/\\\\/g;	# Escape the /'s..(must be first)>
                   11141:     $input =~ s/\"/\\\"/g;	# Esacpe the "s....
                   11142:     return $input;
                   11143: }
1.223     albertel 11144:  
1.222     foxr     11145: #   Escapes the last element of a full URL.
                   11146: sub escape_url {
                   11147:     my ($url)   = @_;
1.238     raeburn  11148:     my @urlslices = split(/\//, $url,-1);
1.369     www      11149:     my $lastitem = &escape(pop(@urlslices));
1.223     albertel 11150:     return join('/',@urlslices).'/'.$lastitem;
1.222     foxr     11151: }
1.462     albertel 11152: 
1.820     raeburn  11153: sub compare_arrays {
                   11154:     my ($arrayref1,$arrayref2) = @_;
                   11155:     my (@difference,%count);
                   11156:     @difference = ();
                   11157:     %count = ();
                   11158:     if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
                   11159:         foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
                   11160:         foreach my $element (keys(%count)) {
                   11161:             if ($count{$element} == 1) {
                   11162:                 push(@difference,$element);
                   11163:             }
                   11164:         }
                   11165:     }
                   11166:     return @difference;
                   11167: }
                   11168: 
1.817     bisitz   11169: # -------------------------------------------------------- Initialize user login
1.462     albertel 11170: sub init_user_environment {
1.463     albertel 11171:     my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462     albertel 11172:     my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
                   11173: 
                   11174:     my $public=($username eq 'public' && $domain eq 'public');
                   11175: 
                   11176: # See if old ID present, if so, remove
                   11177: 
                   11178:     my ($filename,$cookie,$userroles);
                   11179:     my $now=time;
                   11180: 
                   11181:     if ($public) {
                   11182: 	my $max_public=100;
                   11183: 	my $oldest;
                   11184: 	my $oldest_time=0;
                   11185: 	for(my $next=1;$next<=$max_public;$next++) {
                   11186: 	    if (-e $lonids."/publicuser_$next.id") {
                   11187: 		my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
                   11188: 		if ($mtime<$oldest_time || !$oldest_time) {
                   11189: 		    $oldest_time=$mtime;
                   11190: 		    $oldest=$next;
                   11191: 		}
                   11192: 	    } else {
                   11193: 		$cookie="publicuser_$next";
                   11194: 		last;
                   11195: 	    }
                   11196: 	}
                   11197: 	if (!$cookie) { $cookie="publicuser_$oldest"; }
                   11198:     } else {
1.463     albertel 11199: 	# if this isn't a robot, kill any existing non-robot sessions
                   11200: 	if (!$args->{'robot'}) {
                   11201: 	    opendir(DIR,$lonids);
                   11202: 	    while ($filename=readdir(DIR)) {
                   11203: 		if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
                   11204: 		    unlink($lonids.'/'.$filename);
                   11205: 		}
1.462     albertel 11206: 	    }
1.463     albertel 11207: 	    closedir(DIR);
1.462     albertel 11208: 	}
                   11209: # Give them a new cookie
1.463     albertel 11210: 	my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684     www      11211: 		                   : $now.$$.int(rand(10000)));
1.463     albertel 11212: 	$cookie="$username\_$id\_$domain\_$authhost";
1.462     albertel 11213:     
                   11214: # Initialize roles
                   11215: 
                   11216: 	$userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
                   11217:     }
                   11218: # ------------------------------------ Check browser type and MathML capability
                   11219: 
                   11220:     my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   11221:         $clientunicode,$clientos) = &decode_user_agent($r);
                   11222: 
                   11223: # ------------------------------------------------------------- Get environment
                   11224: 
                   11225:     my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
                   11226:     my ($tmp) = keys(%userenv);
                   11227:     if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   11228:     } else {
                   11229: 	undef(%userenv);
                   11230:     }
                   11231:     if (($userenv{'interface'}) && (!$form->{'interface'})) {
                   11232: 	$form->{'interface'}=$userenv{'interface'};
                   11233:     }
                   11234:     if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
                   11235: 
                   11236: # --------------- Do not trust query string to be put directly into environment
1.817     bisitz   11237:     foreach my $option ('interface','localpath','localres') {
                   11238:         $form->{$option}=~s/[\n\r\=]//gs;
1.462     albertel 11239:     }
                   11240: # --------------------------------------------------------- Write first profile
                   11241: 
                   11242:     {
                   11243: 	my %initial_env = 
                   11244: 	    ("user.name"          => $username,
                   11245: 	     "user.domain"        => $domain,
                   11246: 	     "user.home"          => $authhost,
                   11247: 	     "browser.type"       => $clientbrowser,
                   11248: 	     "browser.version"    => $clientversion,
                   11249: 	     "browser.mathml"     => $clientmathml,
                   11250: 	     "browser.unicode"    => $clientunicode,
                   11251: 	     "browser.os"         => $clientos,
                   11252: 	     "server.domain"      => $Apache::lonnet::perlvar{'lonDefDomain'},
                   11253: 	     "request.course.fn"  => '',
                   11254: 	     "request.course.uri" => '',
                   11255: 	     "request.course.sec" => '',
                   11256: 	     "request.role"       => 'cm',
                   11257: 	     "request.role.adv"   => $env{'user.adv'},
                   11258: 	     "request.host"       => $ENV{'REMOTE_ADDR'},);
                   11259: 
                   11260:         if ($form->{'localpath'}) {
                   11261: 	    $initial_env{"browser.localpath"}  = $form->{'localpath'};
                   11262: 	    $initial_env{"browser.localres"}   = $form->{'localres'};
                   11263:         }
                   11264: 	
                   11265: 	if ($form->{'interface'}) {
                   11266: 	    $form->{'interface'}=~s/\W//gs;
                   11267: 	    $initial_env{"browser.interface"} = $form->{'interface'};
                   11268: 	    $env{'browser.interface'}=$form->{'interface'};
                   11269: 	}
                   11270: 
1.981     raeburn  11271:         my %is_adv = ( is_adv => $env{'user.adv'} );
1.980     raeburn  11272:         my %domdef = &Apache::lonnet::get_domain_defaults($domain);
                   11273: 
1.724     raeburn  11274:         foreach my $tool ('aboutme','blog','portfolio') {
                   11275:             $userenv{'availabletools.'.$tool} = 
1.980     raeburn  11276:                 &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
                   11277:                                                   undef,\%userenv,\%domdef,\%is_adv);
1.724     raeburn  11278:         }
                   11279: 
1.864     raeburn  11280:         foreach my $crstype ('official','unofficial','community') {
1.765     raeburn  11281:             $userenv{'canrequest.'.$crstype} =
                   11282:                 &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980     raeburn  11283:                                                   'reload','requestcourses',
                   11284:                                                   \%userenv,\%domdef,\%is_adv);
1.765     raeburn  11285:         }
                   11286: 
1.462     albertel 11287: 	$env{'user.environment'} = "$lonids/$cookie.id";
                   11288: 	
                   11289: 	if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
                   11290: 		 &GDBM_WRCREAT(),0640)) {
                   11291: 	    &_add_to_env(\%disk_env,\%initial_env);
                   11292: 	    &_add_to_env(\%disk_env,\%userenv,'environment.');
                   11293: 	    &_add_to_env(\%disk_env,$userroles);
1.463     albertel 11294: 	    if (ref($args->{'extra_env'})) {
                   11295: 		&_add_to_env(\%disk_env,$args->{'extra_env'});
                   11296: 	    }
1.462     albertel 11297: 	    untie(%disk_env);
                   11298: 	} else {
1.705     tempelho 11299: 	    &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
                   11300: 			   'Could not create environment storage in lonauth: '.$!.'</span>');
1.462     albertel 11301: 	    return 'error: '.$!;
                   11302: 	}
                   11303:     }
                   11304:     $env{'request.role'}='cm';
                   11305:     $env{'request.role.adv'}=$env{'user.adv'};
                   11306:     $env{'browser.type'}=$clientbrowser;
                   11307: 
                   11308:     return $cookie;
                   11309: 
                   11310: }
                   11311: 
                   11312: sub _add_to_env {
                   11313:     my ($idf,$env_data,$prefix) = @_;
1.676     raeburn  11314:     if (ref($env_data) eq 'HASH') {
                   11315:         while (my ($key,$value) = each(%$env_data)) {
                   11316: 	    $idf->{$prefix.$key} = $value;
                   11317: 	    $env{$prefix.$key}   = $value;
                   11318:         }
1.462     albertel 11319:     }
                   11320: }
                   11321: 
1.685     tempelho 11322: # --- Get the symbolic name of a problem and the url
                   11323: sub get_symb {
                   11324:     my ($request,$silent) = @_;
1.726     raeburn  11325:     (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685     tempelho 11326:     my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
                   11327:     if ($symb eq '') {
                   11328:         if (!$silent) {
                   11329:             $request->print("Unable to handle ambiguous references:$url:.");
                   11330:             return ();
                   11331:         }
                   11332:     }
                   11333:     &Apache::lonenc::check_decrypt(\$symb);
                   11334:     return ($symb);
                   11335: }
                   11336: 
                   11337: # --------------------------------------------------------------Get annotation
                   11338: 
                   11339: sub get_annotation {
                   11340:     my ($symb,$enc) = @_;
                   11341: 
                   11342:     my $key = $symb;
                   11343:     if (!$enc) {
                   11344:         $key =
                   11345:             &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
                   11346:     }
                   11347:     my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
                   11348:     return $annotation{$key};
                   11349: }
                   11350: 
                   11351: sub clean_symb {
1.731     raeburn  11352:     my ($symb,$delete_enc) = @_;
1.685     tempelho 11353: 
                   11354:     &Apache::lonenc::check_decrypt(\$symb);
                   11355:     my $enc = $env{'request.enc'};
1.731     raeburn  11356:     if ($delete_enc) {
1.730     raeburn  11357:         delete($env{'request.enc'});
                   11358:     }
1.685     tempelho 11359: 
                   11360:     return ($symb,$enc);
                   11361: }
1.462     albertel 11362: 
1.990     raeburn  11363: sub build_release_hashes {
                   11364:     my ($checkparms,$checkresponsetypes,$checkcrstypes,$anonsurvey,$randomizetry) = @_;
                   11365:     return unless((ref($checkparms) eq 'HASH') && (ref($checkresponsetypes) eq 'HASH') &&
                   11366:                   (ref($checkcrstypes) eq 'HASH') && (ref($anonsurvey) eq 'HASH') &&
                   11367:                   (ref($randomizetry) eq 'HASH'));
                   11368:     foreach my $key (keys(%Apache::lonnet::needsrelease)) {
                   11369:         my ($item,$name,$value) = split(/:/,$key);
                   11370:         if ($item eq 'parameter') {
                   11371:             if (ref($checkparms->{$name}) eq 'ARRAY') {
                   11372:                 unless(grep(/^\Q$name\E$/,@{$checkparms->{$name}})) {
                   11373:                     push(@{$checkparms->{$name}},$value);
                   11374:                 }
                   11375:             } else {
                   11376:                 push(@{$checkparms->{$name}},$value);
                   11377:             }
                   11378:         } elsif ($item eq 'resourcetag') {
                   11379:             if ($name eq 'responsetype') {
                   11380:                 $checkresponsetypes->{$value} = $Apache::lonnet::needsrelease{$key}
                   11381:             }
                   11382:         } elsif ($item eq 'course') {
                   11383:             if ($name eq 'crstype') {
                   11384:                 $checkcrstypes->{$value} = $Apache::lonnet::needsrelease{$key};
                   11385:             }
                   11386:         }
                   11387:     }
                   11388:     ($anonsurvey->{major},$anonsurvey->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:anonsurvey'});
                   11389:     ($randomizetry->{major},$randomizetry->{minor}) = split(/\./,$Apache::lonnet::needsrelease{'parameter:type:randomizetry'});
                   11390:     return;
                   11391: }
                   11392: 
1.41      ng       11393: =pod
                   11394: 
                   11395: =back
                   11396: 
1.112     bowersj2 11397: =cut
1.41      ng       11398: 
1.112     bowersj2 11399: 1;
                   11400: __END__;
1.41      ng       11401: 

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