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

1.10      albertel    1: # The LearningOnline Network with CAPA
1.1       albertel    2: # a pile of common routines
1.10      albertel    3: #
1.801   ! tempelho    4: # $Id: loncommon.pm,v 1.800 2009/05/01 01:07:55 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.74      www       410:     var stdeditbrowser;
1.793     raeburn   411:     function openstdbrowser(formname,uname,udom,roleflag,ignorefilter,courseadvonly) {
1.74      www       412:         var url = '/adm/pickstudent?';
                    413:         var filter;
1.558     albertel  414: 	if (!ignorefilter) {
                    415: 	    eval('filter=document.'+formname+'.'+uname+'.value;');
                    416: 	}
1.74      www       417:         if (filter != null) {
                    418:            if (filter != '') {
                    419:                url += 'filter='+filter+'&';
                    420: 	   }
                    421:         }
                    422:         url += 'form=' + formname + '&unameelement='+uname+
                    423:                                     '&udomelement='+udom;
1.111     www       424: 	if (roleflag) { url+="&roles=1"; }
1.793     raeburn   425:         if (courseadvonly) { url+="&courseadvonly=1"; }
1.102     www       426:         var title = 'Student_Browser';
1.74      www       427:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    428:         options += ',width=700,height=600';
                    429:         stdeditbrowser = open(url,title,options,'1');
                    430:         stdeditbrowser.focus();
                    431:     }
                    432: </script>
                    433: ENDSTDBRW
                    434: }
1.42      matthew   435: 
1.74      www       436: sub selectstudent_link {
1.793     raeburn   437:    my ($form,$unameele,$udomele,$courseadvonly)=@_;
                    438:    my $callargs = "'".$form."','".$unameele."','".$udomele."'";
1.258     albertel  439:    if ($env{'request.course.id'}) {  
1.302     albertel  440:        if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    441: 	   && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                    442: 					'/'.$env{'request.course.sec'})) {
1.111     www       443: 	   return '';
                    444:        }
1.793     raeburn   445:        if ($courseadvonly)  {
                    446:            $callargs .= ",'',1,1";
                    447:        }
                    448:        return '<span class="LC_nobreak">'.
                    449:               '<a href="javascript:openstdbrowser('.$callargs.');">'.
                    450:               &mt('Select User').'</a></span>';
1.74      www       451:    }
1.258     albertel  452:    if ($env{'request.role'}=~/^(au|dc|su)/) {
1.793     raeburn   453:        $callargs .= ",1"; 
                    454:        return '<span class="LC_nobreak">'.
                    455:               '<a href="javascript:openstdbrowser('.$callargs.');">'.
                    456:               &mt('Select User').'</a></span>';
1.111     www       457:    }
                    458:    return '';
1.91      www       459: }
                    460: 
1.653     raeburn   461: sub authorbrowser_javascript {
                    462:     return <<"ENDAUTHORBRW";
1.776     bisitz    463: <script type="text/javascript" language="JavaScript">
1.653     raeburn   464: var stdeditbrowser;
                    465: 
                    466: function openauthorbrowser(formname,udom) {
                    467:     var url = '/adm/pickauthor?';
                    468:     url += 'form='+formname+'&roledom='+udom;
                    469:     var title = 'Author_Browser';
                    470:     var options = 'scrollbars=1,resizable=1,menubar=0';
                    471:     options += ',width=700,height=600';
                    472:     stdeditbrowser = open(url,title,options,'1');
                    473:     stdeditbrowser.focus();
                    474: }
                    475: 
                    476: </script>
                    477: ENDAUTHORBRW
                    478: }
                    479: 
1.91      www       480: sub coursebrowser_javascript {
1.468     raeburn   481:     my ($domainfilter,$sec_element,$formname)=@_;
1.377     raeburn   482:     my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Group - for which you wish to add/modify a user role');
1.468     raeburn   483:    my $output = '
1.776     bisitz    484: <script type="text/javascript" language="JavaScript">
1.468     raeburn   485:     var stdeditbrowser;'."\n";
                    486:    $output .= <<"ENDSTDBRW";
1.377     raeburn   487:     function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
1.91      www       488:         var url = '/adm/pickcourse?';
1.468     raeburn   489:         var domainfilter = '';
                    490:         var formid = getFormIdByName(formname);
                    491:         if (formid > -1) {
                    492:             var domid = getIndexByName(formid,udom);
                    493:             if (domid > -1) {
                    494:                 if (document.forms[formid].elements[domid].type == 'select-one') {
                    495:                     domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
                    496:                 }
                    497:                 if (document.forms[formid].elements[domid].type == 'hidden') {
                    498:                     domainfilter=document.forms[formid].elements[domid].value;
                    499:                 }
                    500:             }
1.91      www       501:         }
1.128     albertel  502:         if (domainfilter != null) {
                    503:            if (domainfilter != '') {
                    504:                url += 'domainfilter='+domainfilter+'&';
                    505: 	   }
                    506:         }
1.91      www       507:         url += 'form=' + formname + '&cnumelement='+uname+
1.187     albertel  508: 	                            '&cdomelement='+udom+
                    509:                                     '&cnameelement='+desc;
1.468     raeburn   510:         if (extra_element !=null && extra_element != '') {
1.594     raeburn   511:             if (formname == 'rolechoice' || formname == 'studentform') {
1.468     raeburn   512:                 url += '&roleelement='+extra_element;
                    513:                 if (domainfilter == null || domainfilter == '') {
                    514:                     url += '&domainfilter='+extra_element;
                    515:                 }
1.234     raeburn   516:             }
1.468     raeburn   517:             else {
                    518:                 if (formname == 'portform') {
                    519:                     url += '&setroles='+extra_element;
1.800     raeburn   520:                 } else {
                    521:                     if (formname == 'rules') {
                    522:                         url += '&fixeddom='+extra_element; 
                    523:                     }
1.468     raeburn   524:                 }
                    525:             }     
1.230     raeburn   526:         }
1.293     raeburn   527:         if (multflag !=null && multflag != '') {
                    528:             url += '&multiple='+multflag;
                    529:         }
1.377     raeburn   530:         if (crstype == 'Course/Group') {
                    531:             if (formname == 'cu') {
                    532:                 crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value; 
                    533:                 if (crstype == "") {
                    534:                     alert("$crs_or_grp_alert");
                    535:                     return;
                    536:                 }
                    537:             }
                    538:         }
                    539:         if (crstype !=null && crstype != '') {
                    540:             url += '&type='+crstype;
                    541:         }
1.102     www       542:         var title = 'Course_Browser';
1.91      www       543:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    544:         options += ',width=700,height=600';
                    545:         stdeditbrowser = open(url,title,options,'1');
                    546:         stdeditbrowser.focus();
                    547:     }
1.468     raeburn   548: 
                    549:     function getFormIdByName(formname) {
                    550:         for (var i=0;i<document.forms.length;i++) {
                    551:             if (document.forms[i].name == formname) {
                    552:                 return i;
                    553:             }
                    554:         }
                    555:         return -1; 
                    556:     }
                    557: 
                    558:     function getIndexByName(formid,item) {
                    559:         for (var i=0;i<document.forms[formid].elements.length;i++) {
                    560:             if (document.forms[formid].elements[i].name == item) {
                    561:                 return i;
                    562:             }
                    563:         }
                    564:         return -1;
                    565:     }
1.91      www       566: ENDSTDBRW
1.468     raeburn   567:     if ($sec_element ne '') {
                    568:         $output .= &setsec_javascript($sec_element,$formname);
                    569:     }
                    570:     $output .= '
                    571: </script>';
                    572:     return $output;
                    573: }
                    574: 
                    575: sub setsec_javascript {
                    576:     my ($sec_element,$formname) = @_;
                    577:     my $setsections = qq|
                    578: function setSect(sectionlist) {
1.629     raeburn   579:     var sectionsArray = new Array();
                    580:     if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
                    581:         sectionsArray = sectionlist.split(",");
                    582:     }
1.468     raeburn   583:     var numSections = sectionsArray.length;
                    584:     document.$formname.$sec_element.length = 0;
                    585:     if (numSections == 0) {
                    586:         document.$formname.$sec_element.multiple=false;
                    587:         document.$formname.$sec_element.size=1;
                    588:         document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
                    589:     } else {
                    590:         if (numSections == 1) {
                    591:             document.$formname.$sec_element.multiple=false;
                    592:             document.$formname.$sec_element.size=1;
                    593:             document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
                    594:             document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
                    595:             document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
                    596:         } else {
                    597:             for (var i=0; i<numSections; i++) {
                    598:                 document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
                    599:             }
                    600:             document.$formname.$sec_element.multiple=true
                    601:             if (numSections < 3) {
                    602:                 document.$formname.$sec_element.size=numSections;
                    603:             } else {
                    604:                 document.$formname.$sec_element.size=3;
                    605:             }
                    606:             document.$formname.$sec_element.options[0].selected = false
                    607:         }
                    608:     }
1.91      www       609: }
1.468     raeburn   610: |;
                    611:     return $setsections;
                    612: }
                    613: 
1.91      www       614: 
                    615: sub selectcourse_link {
1.377     raeburn   616:    my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.787     bisitz    617:    return '<span class="LC_nobreak">'
                    618:          ."<a href='"
                    619:          .'javascript:opencrsbrowser("'.$form.'","'.$unameele
                    620:          .'","'.$udomele.'","'.$desc.'","'.$extra_element
                    621:          .'","'.$multflag.'","'.$selecttype.'");'
                    622:          ."'>".&mt('Select Course').'</a>'
                    623:          .'</span>';
1.74      www       624: }
1.42      matthew   625: 
1.653     raeburn   626: sub selectauthor_link {
                    627:    my ($form,$udom)=@_;
                    628:    return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
                    629:           &mt('Select Author').'</a>';
                    630: }
                    631: 
1.273     raeburn   632: sub check_uncheck_jscript {
                    633:     my $jscript = <<"ENDSCRT";
                    634: function checkAll(field) {
                    635:     if (field.length > 0) {
                    636:         for (i = 0; i < field.length; i++) {
                    637:             field[i].checked = true ;
                    638:         }
                    639:     } else {
                    640:         field.checked = true
                    641:     }
                    642: }
                    643:  
                    644: function uncheckAll(field) {
                    645:     if (field.length > 0) {
                    646:         for (i = 0; i < field.length; i++) {
                    647:             field[i].checked = false ;
1.543     albertel  648:         }
                    649:     } else {
1.273     raeburn   650:         field.checked = false ;
                    651:     }
                    652: }
                    653: ENDSCRT
                    654:     return $jscript;
                    655: }
                    656: 
1.656     www       657: sub select_timezone {
1.659     raeburn   658:    my ($name,$selected,$onchange,$includeempty)=@_;
                    659:    my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    660:    if ($includeempty) {
                    661:        $output .= '<option value=""';
                    662:        if (($selected eq '') || ($selected eq 'local')) {
                    663:            $output .= ' selected="selected" ';
                    664:        }
                    665:        $output .= '> </option>';
                    666:    }
1.657     raeburn   667:    my @timezones = DateTime::TimeZone->all_names;
                    668:    foreach my $tzone (@timezones) {
                    669:        $output.= '<option value="'.$tzone.'"';
                    670:        if ($tzone eq $selected) {
                    671:            $output.=' selected="selected"';
                    672:        }
                    673:        $output.=">$tzone</option>\n";
1.656     www       674:    }
                    675:    $output.="</select>";
                    676:    return $output;
                    677: }
1.273     raeburn   678: 
1.687     raeburn   679: sub select_datelocale {
                    680:     my ($name,$selected,$onchange,$includeempty)=@_;
                    681:     my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    682:     if ($includeempty) {
                    683:         $output .= '<option value=""';
                    684:         if ($selected eq '') {
                    685:             $output .= ' selected="selected" ';
                    686:         }
                    687:         $output .= '> </option>';
                    688:     }
                    689:     my (@possibles,%locale_names);
                    690:     my @locales = DateTime::Locale::Catalog::Locales;
                    691:     foreach my $locale (@locales) {
                    692:         if (ref($locale) eq 'HASH') {
                    693:             my $id = $locale->{'id'};
                    694:             if ($id ne '') {
                    695:                 my $en_terr = $locale->{'en_territory'};
                    696:                 my $native_terr = $locale->{'native_territory'};
1.695     raeburn   697:                 my @languages = &Apache::lonlocal::preferred_languages();
1.687     raeburn   698:                 if (grep(/^en$/,@languages) || !@languages) {
                    699:                     if ($en_terr ne '') {
                    700:                         $locale_names{$id} = '('.$en_terr.')';
                    701:                     } elsif ($native_terr ne '') {
                    702:                         $locale_names{$id} = $native_terr;
                    703:                     }
                    704:                 } else {
                    705:                     if ($native_terr ne '') {
                    706:                         $locale_names{$id} = $native_terr.' ';
                    707:                     } elsif ($en_terr ne '') {
                    708:                         $locale_names{$id} = '('.$en_terr.')';
                    709:                     }
                    710:                 }
                    711:                 push (@possibles,$id);
                    712:             }
                    713:         }
                    714:     }
                    715:     foreach my $item (sort(@possibles)) {
                    716:         $output.= '<option value="'.$item.'"';
                    717:         if ($item eq $selected) {
                    718:             $output.=' selected="selected"';
                    719:         }
                    720:         $output.=">$item";
                    721:         if ($locale_names{$item} ne '') {
                    722:             $output.="  $locale_names{$item}</option>\n";
                    723:         }
                    724:         $output.="</option>\n";
                    725:     }
                    726:     $output.="</select>";
                    727:     return $output;
                    728: }
                    729: 
1.792     raeburn   730: sub select_language {
                    731:     my ($name,$selected,$includeempty) = @_;
                    732:     my %langchoices;
                    733:     if ($includeempty) {
                    734:         %langchoices = ('' => 'No language preference');
                    735:     }
                    736:     foreach my $id (&languageids()) {
                    737:         my $code = &supportedlanguagecode($id);
                    738:         if ($code) {
                    739:             $langchoices{$code} = &plainlanguagedescription($id);
                    740:         }
                    741:     }
                    742:     return &select_form($selected,$name,%langchoices);
                    743: }
                    744: 
1.42      matthew   745: =pod
1.36      matthew   746: 
1.648     raeburn   747: =item * &linked_select_forms(...)
1.36      matthew   748: 
                    749: linked_select_forms returns a string containing a <script></script> block
                    750: and html for two <select> menus.  The select menus will be linked in that
                    751: changing the value of the first menu will result in new values being placed
                    752: in the second menu.  The values in the select menu will appear in alphabetical
1.609     raeburn   753: order unless a defined order is provided.
1.36      matthew   754: 
                    755: linked_select_forms takes the following ordered inputs:
                    756: 
                    757: =over 4
                    758: 
1.112     bowersj2  759: =item * $formname, the name of the <form> tag
1.36      matthew   760: 
1.112     bowersj2  761: =item * $middletext, the text which appears between the <select> tags
1.36      matthew   762: 
1.112     bowersj2  763: =item * $firstdefault, the default value for the first menu
1.36      matthew   764: 
1.112     bowersj2  765: =item * $firstselectname, the name of the first <select> tag
1.36      matthew   766: 
1.112     bowersj2  767: =item * $secondselectname, the name of the second <select> tag
1.36      matthew   768: 
1.112     bowersj2  769: =item * $hashref, a reference to a hash containing the data for the menus.
1.36      matthew   770: 
1.609     raeburn   771: =item * $menuorder, the order of values in the first menu
                    772: 
1.41      ng        773: =back 
                    774: 
1.36      matthew   775: Below is an example of such a hash.  Only the 'text', 'default', and 
                    776: 'select2' keys must appear as stated.  keys(%menu) are the possible 
                    777: values for the first select menu.  The text that coincides with the 
1.41      ng        778: first menu value is given in $menu{$choice1}->{'text'}.  The values 
1.36      matthew   779: and text for the second menu are given in the hash pointed to by 
                    780: $menu{$choice1}->{'select2'}.  
                    781: 
1.112     bowersj2  782:  my %menu = ( A1 => { text =>"Choice A1" ,
                    783:                        default => "B3",
                    784:                        select2 => { 
                    785:                            B1 => "Choice B1",
                    786:                            B2 => "Choice B2",
                    787:                            B3 => "Choice B3",
                    788:                            B4 => "Choice B4"
1.609     raeburn   789:                            },
                    790:                        order => ['B4','B3','B1','B2'],
1.112     bowersj2  791:                    },
                    792:                A2 => { text =>"Choice A2" ,
                    793:                        default => "C2",
                    794:                        select2 => { 
                    795:                            C1 => "Choice C1",
                    796:                            C2 => "Choice C2",
                    797:                            C3 => "Choice C3"
1.609     raeburn   798:                            },
                    799:                        order => ['C2','C1','C3'],
1.112     bowersj2  800:                    },
                    801:                A3 => { text =>"Choice A3" ,
                    802:                        default => "D6",
                    803:                        select2 => { 
                    804:                            D1 => "Choice D1",
                    805:                            D2 => "Choice D2",
                    806:                            D3 => "Choice D3",
                    807:                            D4 => "Choice D4",
                    808:                            D5 => "Choice D5",
                    809:                            D6 => "Choice D6",
                    810:                            D7 => "Choice D7"
1.609     raeburn   811:                            },
                    812:                        order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112     bowersj2  813:                    }
                    814:                );
1.36      matthew   815: 
                    816: =cut
                    817: 
                    818: sub linked_select_forms {
                    819:     my ($formname,
                    820:         $middletext,
                    821:         $firstdefault,
                    822:         $firstselectname,
                    823:         $secondselectname, 
1.609     raeburn   824:         $hashref,
                    825:         $menuorder,
1.36      matthew   826:         ) = @_;
                    827:     my $second = "document.$formname.$secondselectname";
                    828:     my $first = "document.$formname.$firstselectname";
                    829:     # output the javascript to do the changing
                    830:     my $result = '';
1.776     bisitz    831:     $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.36      matthew   832:     $result.="var select2data = new Object();\n";
                    833:     $" = '","';
                    834:     my $debug = '';
                    835:     foreach my $s1 (sort(keys(%$hashref))) {
                    836:         $result.="select2data.d_$s1 = new Object();\n";        
                    837:         $result.="select2data.d_$s1.def = new String('".
                    838:             $hashref->{$s1}->{'default'}."');\n";
1.609     raeburn   839:         $result.="select2data.d_$s1.values = new Array(";
1.36      matthew   840:         my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609     raeburn   841:         if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
                    842:             @s2values = @{$hashref->{$s1}->{'order'}};
                    843:         }
1.36      matthew   844:         $result.="\"@s2values\");\n";
                    845:         $result.="select2data.d_$s1.texts = new Array(";        
                    846:         my @s2texts;
                    847:         foreach my $value (@s2values) {
                    848:             push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
                    849:         }
                    850:         $result.="\"@s2texts\");\n";
                    851:     }
                    852:     $"=' ';
                    853:     $result.= <<"END";
                    854: 
                    855: function select1_changed() {
                    856:     // Determine new choice
                    857:     var newvalue = "d_" + $first.value;
                    858:     // update select2
                    859:     var values     = select2data[newvalue].values;
                    860:     var texts      = select2data[newvalue].texts;
                    861:     var select2def = select2data[newvalue].def;
                    862:     var i;
                    863:     // out with the old
                    864:     for (i = 0; i < $second.options.length; i++) {
                    865:         $second.options[i] = null;
                    866:     }
                    867:     // in with the nuclear
                    868:     for (i=0;i<values.length; i++) {
                    869:         $second.options[i] = new Option(values[i]);
1.143     matthew   870:         $second.options[i].value = values[i];
1.36      matthew   871:         $second.options[i].text = texts[i];
                    872:         if (values[i] == select2def) {
                    873:             $second.options[i].selected = true;
                    874:         }
                    875:     }
                    876: }
                    877: </script>
                    878: END
                    879:     # output the initial values for the selection lists
                    880:     $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609     raeburn   881:     my @order = sort(keys(%{$hashref}));
                    882:     if (ref($menuorder) eq 'ARRAY') {
                    883:         @order = @{$menuorder};
                    884:     }
                    885:     foreach my $value (@order) {
1.36      matthew   886:         $result.="    <option value=\"$value\" ";
1.253     albertel  887:         $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119     www       888:         $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36      matthew   889:     }
                    890:     $result .= "</select>\n";
                    891:     my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
                    892:     $result .= $middletext;
                    893:     $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
                    894:     my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609     raeburn   895:     
                    896:     my @secondorder = sort(keys(%select2));
                    897:     if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
                    898:         @secondorder = @{$hashref->{$firstdefault}->{'order'}};
                    899:     }
                    900:     foreach my $value (@secondorder) {
1.36      matthew   901:         $result.="    <option value=\"$value\" ";        
1.253     albertel  902:         $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119     www       903:         $result.=">".&mt($select2{$value})."</option>\n";
1.36      matthew   904:     }
                    905:     $result .= "</select>\n";
                    906:     #    return $debug;
                    907:     return $result;
                    908: }   #  end of sub linked_select_forms {
                    909: 
1.45      matthew   910: =pod
1.44      bowersj2  911: 
1.648     raeburn   912: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44      bowersj2  913: 
1.112     bowersj2  914: Returns a string corresponding to an HTML link to the given help
                    915: $topic, where $topic corresponds to the name of a .tex file in
                    916: /home/httpd/html/adm/help/tex, with underscores replaced by
                    917: spaces. 
                    918: 
                    919: $text will optionally be linked to the same topic, allowing you to
                    920: link text in addition to the graphic. If you do not want to link
                    921: text, but wish to specify one of the later parameters, pass an
                    922: empty string. 
                    923: 
                    924: $stayOnPage is a value that will be interpreted as a boolean. If true,
                    925: the link will not open a new window. If false, the link will open
                    926: a new window using Javascript. (Default is false.) 
                    927: 
                    928: $width and $height are optional numerical parameters that will
                    929: override the width and height of the popped up window, which may
                    930: be useful for certain help topics with big pictures included. 
1.44      bowersj2  931: 
                    932: =cut
                    933: 
                    934: sub help_open_topic {
1.48      bowersj2  935:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
                    936:     $text = "" if (not defined $text);
1.44      bowersj2  937:     $stayOnPage = 0 if (not defined $stayOnPage);
                    938:     $width = 350 if (not defined $width);
                    939:     $height = 400 if (not defined $height);
                    940:     my $filename = $topic;
                    941:     $filename =~ s/ /_/g;
                    942: 
1.48      bowersj2  943:     my $template = "";
                    944:     my $link;
1.572     banghart  945:     
1.159     www       946:     $topic=~s/\W/\_/g;
1.44      bowersj2  947: 
1.572     banghart  948:     if (!$stayOnPage) {
1.72      bowersj2  949: 	$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  950:     } else {
1.48      bowersj2  951: 	$link = "/adm/help/${filename}.hlp";
                    952:     }
                    953: 
                    954:     # Add the text
1.755     neumanie  955:     if ($text ne "") {	
1.763     bisitz    956: 	$template.='<span class="LC_help_open_topic">'
                    957:                   .'<a target="_top" href="'.$link.'">'
                    958:                   .$text.'</a>';
1.48      bowersj2  959:     }
                    960: 
1.763     bisitz    961:     # (Always) Add the graphic
1.179     matthew   962:     my $title = &mt('Online Help');
1.667     raeburn   963:     my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.763     bisitz    964:     $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
                    965:               .'<img src="'.$helpicon.'" border="0"'
                    966:               .' alt="'.&mt('Help: [_1]',$topic).'"'
1.783     amueller  967:               .' title="'.$title.'"' 
1.763     bisitz    968:               .' /></a>';
                    969:     if ($text ne "") {	
                    970:         $template.='</span>';
                    971:     }
1.44      bowersj2  972:     return $template;
                    973: 
1.106     bowersj2  974: }
                    975: 
                    976: # This is a quicky function for Latex cheatsheet editing, since it 
                    977: # appears in at least four places
                    978: sub helpLatexCheatsheet {
1.732     raeburn   979:     my ($topic,$text,$not_author) = @_;
                    980:     my $out;
1.106     bowersj2  981:     my $addOther = '';
1.732     raeburn   982:     if ($topic) {
1.763     bisitz    983: 	$addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
                    984: 							       undef, undef, 600).
                    985: 								   '</span> ';
                    986:     }
                    987:     $out = '<span>' # Start cheatsheet
                    988: 	  .$addOther
                    989:           .'<span>'
                    990: 	  .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
                    991: 					       undef,undef,600)
                    992: 	  .'</span> <span>'
                    993: 	  .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
                    994: 					       undef,undef,600)
                    995: 	  .'</span>';
1.732     raeburn   996:     unless ($not_author) {
1.763     bisitz    997:         $out .= ' <span>'
                    998: 	       .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
                    999: 	                                            undef,undef,600)
                   1000: 	       .'</span>';
1.732     raeburn  1001:     }
1.763     bisitz   1002:     $out .= '</span>'; # End cheatsheet
1.732     raeburn  1003:     return $out;
1.172     www      1004: }
                   1005: 
1.430     albertel 1006: sub general_help {
                   1007:     my $helptopic='Student_Intro';
                   1008:     if ($env{'request.role'}=~/^(ca|au)/) {
                   1009: 	$helptopic='Authoring_Intro';
                   1010:     } elsif ($env{'request.role'}=~/^cc/) {
                   1011: 	$helptopic='Course_Coordination_Intro';
1.672     raeburn  1012:     } elsif ($env{'request.role'}=~/^dc/) {
                   1013:         $helptopic='Domain_Coordination_Intro';
1.430     albertel 1014:     }
                   1015:     return $helptopic;
                   1016: }
                   1017: 
                   1018: sub update_help_link {
                   1019:     my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
                   1020:     my $origurl = $ENV{'REQUEST_URI'};
                   1021:     $origurl=~s|^/~|/priv/|;
                   1022:     my $timestamp = time;
                   1023:     foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
                   1024:         $$datum = &escape($$datum);
                   1025:     }
                   1026: 
                   1027:     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";
                   1028:     my $output .= <<"ENDOUTPUT";
                   1029: <script type="text/javascript">
                   1030: banner_link = '$banner_link';
                   1031: </script>
                   1032: ENDOUTPUT
                   1033:     return $output;
                   1034: }
                   1035: 
                   1036: # now just updates the help link and generates a blue icon
1.193     raeburn  1037: sub help_open_menu {
1.430     albertel 1038:     my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text) 
1.552     banghart 1039: 	= @_;    
1.430     albertel 1040:     $stayOnPage = 0 if (not defined $stayOnPage);
1.572     banghart 1041:     # only use pop-up help (stayOnPage == 0)
1.552     banghart 1042:     # if environment.remote is on (using remote control UI)
1.798     tempelho 1043:     if ($env{'environment.remote'} eq 'off' ) {
1.552     banghart 1044:         $stayOnPage=1;
1.430     albertel 1045:     }
                   1046:     my $output;
                   1047:     if ($component_help) {
                   1048: 	if (!$text) {
                   1049: 	    $output=&help_open_topic($component_help,undef,$stayOnPage,
                   1050: 				       $width,$height);
                   1051: 	} else {
                   1052: 	    my $help_text;
                   1053: 	    $help_text=&unescape($topic);
                   1054: 	    $output='<table><tr><td>'.
                   1055: 		&help_open_topic($component_help,$help_text,$stayOnPage,
                   1056: 				 $width,$height).'</td></tr></table>';
                   1057: 	}
                   1058:     }
                   1059:     my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
                   1060:     return $output.$banner_link;
                   1061: }
                   1062: 
                   1063: sub top_nav_help {
                   1064:     my ($text) = @_;
1.436     albertel 1065:     $text = &mt($text);
1.572     banghart 1066:     my $stay_on_page = 
1.798     tempelho 1067: 	($env{'environment.remote'} eq 'off' );
1.572     banghart 1068:     my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436     albertel 1069: 	                     : "javascript:helpMenu('open')";
1.572     banghart 1070:     my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436     albertel 1071: 
1.201     raeburn  1072:     my $title = &mt('Get help');
1.436     albertel 1073: 
                   1074:     return <<"END";
                   1075: $banner_link
                   1076:  <a href="$link" title="$title">$text</a>
                   1077: END
                   1078: }
                   1079: 
                   1080: sub help_menu_js {
                   1081:     my ($text) = @_;
                   1082: 
                   1083:     my $stayOnPage = 
1.798     tempelho 1084: 	($env{'environment.remote'} eq 'off' );
1.436     albertel 1085: 
                   1086:     my $width = 620;
                   1087:     my $height = 600;
1.430     albertel 1088:     my $helptopic=&general_help();
                   1089:     my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261     albertel 1090:     my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331     albertel 1091:     my $start_page =
                   1092:         &Apache::loncommon::start_page('Help Menu', undef,
                   1093: 				       {'frameset'    => 1,
                   1094: 					'js_ready'    => 1,
                   1095: 					'add_entries' => {
                   1096: 					    'border' => '0',
1.579     raeburn  1097: 					    'rows'   => "110,*",},});
1.331     albertel 1098:     my $end_page =
                   1099:         &Apache::loncommon::end_page({'frameset' => 1,
                   1100: 				      'js_ready' => 1,});
                   1101: 
1.436     albertel 1102:     my $template .= <<"ENDTEMPLATE";
                   1103: <script type="text/javascript">
1.253     albertel 1104: // <!-- BEGIN LON-CAPA Internal
                   1105: // <![CDATA[
1.430     albertel 1106: var banner_link = '';
1.243     raeburn  1107: function helpMenu(target) {
                   1108:     var caller = this;
                   1109:     if (target == 'open') {
                   1110:         var newWindow = null;
                   1111:         try {
1.262     albertel 1112:             newWindow =  window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243     raeburn  1113:         }
                   1114:         catch(error) {
                   1115:             writeHelp(caller);
                   1116:             return;
                   1117:         }
                   1118:         if (newWindow) {
                   1119:             caller = newWindow;
                   1120:         }
1.193     raeburn  1121:     }
1.243     raeburn  1122:     writeHelp(caller);
                   1123:     return;
                   1124: }
                   1125: function writeHelp(caller) {
1.430     albertel 1126:     caller.document.writeln('$start_page<frame name="bannerframe"  src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243     raeburn  1127:     caller.document.close()
                   1128:     caller.focus()
1.193     raeburn  1129: }
1.253     albertel 1130: // ]]>
1.219     albertel 1131: // END LON-CAPA Internal -->
1.436     albertel 1132: </script>
1.193     raeburn  1133: ENDTEMPLATE
                   1134:     return $template;
                   1135: }
                   1136: 
1.172     www      1137: sub help_open_bug {
                   1138:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1139:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1140:     unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
                   1141:     $text = "" if (not defined $text);
                   1142:     $stayOnPage = 0 if (not defined $stayOnPage);
1.798     tempelho 1143:     if ($env{'environment.remote'} eq 'off' ) {
1.172     www      1144: 	$stayOnPage=1;
                   1145:     }
1.184     albertel 1146:     $width = 600 if (not defined $width);
                   1147:     $height = 600 if (not defined $height);
1.172     www      1148: 
                   1149:     $topic=~s/\W+/\+/g;
                   1150:     my $link='';
                   1151:     my $template='';
1.379     albertel 1152:     my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&amp;bug_file_loc='.
                   1153: 	&escape($ENV{'REQUEST_URI'}).'&amp;component='.$topic;
1.172     www      1154:     if (!$stayOnPage)
                   1155:     {
                   1156: 	$link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1157:     }
                   1158:     else
                   1159:     {
                   1160: 	$link = $url;
                   1161:     }
                   1162:     # Add the text
                   1163:     if ($text ne "")
                   1164:     {
                   1165: 	$template .= 
                   1166:   "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1167:   "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172     www      1168:     }
                   1169: 
                   1170:     # Add the graphic
1.179     matthew  1171:     my $title = &mt('Report a Bug');
1.215     albertel 1172:     my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172     www      1173:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1174:  <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172     www      1175: ENDTEMPLATE
                   1176:     if ($text ne '') { $template.='</td></tr></table>' };
                   1177:     return $template;
                   1178: 
                   1179: }
                   1180: 
                   1181: sub help_open_faq {
                   1182:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1183:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1184:     unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
                   1185:     $text = "" if (not defined $text);
                   1186:     $stayOnPage = 0 if (not defined $stayOnPage);
1.798     tempelho 1187:     if ($env{'environment.remote'} eq 'off' ) {
1.172     www      1188: 	$stayOnPage=1;
                   1189:     }
                   1190:     $width = 350 if (not defined $width);
                   1191:     $height = 400 if (not defined $height);
                   1192: 
                   1193:     $topic=~s/\W+/\+/g;
                   1194:     my $link='';
                   1195:     my $template='';
                   1196:     my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
                   1197:     if (!$stayOnPage)
                   1198:     {
                   1199: 	$link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1200:     }
                   1201:     else
                   1202:     {
                   1203: 	$link = $url;
                   1204:     }
                   1205: 
                   1206:     # Add the text
                   1207:     if ($text ne "")
                   1208:     {
                   1209: 	$template .= 
1.173     www      1210:   "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1211:   "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172     www      1212:     }
                   1213: 
                   1214:     # Add the graphic
1.179     matthew  1215:     my $title = &mt('View the FAQ');
1.215     albertel 1216:     my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172     www      1217:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1218:  <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172     www      1219: ENDTEMPLATE
                   1220:     if ($text ne '') { $template.='</td></tr></table>' };
                   1221:     return $template;
                   1222: 
1.44      bowersj2 1223: }
1.37      matthew  1224: 
1.180     matthew  1225: ###############################################################
                   1226: ###############################################################
                   1227: 
1.45      matthew  1228: =pod
                   1229: 
1.648     raeburn  1230: =item * &change_content_javascript():
1.256     matthew  1231: 
                   1232: This and the next function allow you to create small sections of an
                   1233: otherwise static HTML page that you can update on the fly with
                   1234: Javascript, even in Netscape 4.
                   1235: 
                   1236: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
                   1237: must be written to the HTML page once. It will prove the Javascript
                   1238: function "change(name, content)". Calling the change function with the
                   1239: name of the section 
                   1240: you want to update, matching the name passed to C<changable_area>, and
                   1241: the new content you want to put in there, will put the content into
                   1242: that area.
                   1243: 
                   1244: B<Note>: Netscape 4 only reserves enough space for the changable area
                   1245: to contain room for the original contents. You need to "make space"
                   1246: for whatever changes you wish to make, and be B<sure> to check your
                   1247: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
                   1248: it's adequate for updating a one-line status display, but little more.
                   1249: This script will set the space to 100% width, so you only need to
                   1250: worry about height in Netscape 4.
                   1251: 
                   1252: Modern browsers are much less limiting, and if you can commit to the
                   1253: user not using Netscape 4, this feature may be used freely with
                   1254: pretty much any HTML.
                   1255: 
                   1256: =cut
                   1257: 
                   1258: sub change_content_javascript {
                   1259:     # If we're on Netscape 4, we need to use Layer-based code
1.258     albertel 1260:     if ($env{'browser.type'} eq 'netscape' &&
                   1261: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1262: 	return (<<NETSCAPE4);
                   1263: 	function change(name, content) {
                   1264: 	    doc = document.layers[name+"___escape"].layers[0].document;
                   1265: 	    doc.open();
                   1266: 	    doc.write(content);
                   1267: 	    doc.close();
                   1268: 	}
                   1269: NETSCAPE4
                   1270:     } else {
                   1271: 	# Otherwise, we need to use semi-standards-compliant code
                   1272: 	# (technically, "innerHTML" isn't standard but the equivalent
                   1273: 	# is really scary, and every useful browser supports it
                   1274: 	return (<<DOMBASED);
                   1275: 	function change(name, content) {
                   1276: 	    element = document.getElementById(name);
                   1277: 	    element.innerHTML = content;
                   1278: 	}
                   1279: DOMBASED
                   1280:     }
                   1281: }
                   1282: 
                   1283: =pod
                   1284: 
1.648     raeburn  1285: =item * &changable_area($name,$origContent):
1.256     matthew  1286: 
                   1287: This provides a "changable area" that can be modified on the fly via
                   1288: the Javascript code provided in C<change_content_javascript>. $name is
                   1289: the name you will use to reference the area later; do not repeat the
                   1290: same name on a given HTML page more then once. $origContent is what
                   1291: the area will originally contain, which can be left blank.
                   1292: 
                   1293: =cut
                   1294: 
                   1295: sub changable_area {
                   1296:     my ($name, $origContent) = @_;
                   1297: 
1.258     albertel 1298:     if ($env{'browser.type'} eq 'netscape' &&
                   1299: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1300: 	# If this is netscape 4, we need to use the Layer tag
                   1301: 	return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
                   1302:     } else {
                   1303: 	return "<span id='$name'>$origContent</span>";
                   1304:     }
                   1305: }
                   1306: 
                   1307: =pod
                   1308: 
1.648     raeburn  1309: =item * &viewport_geometry_js 
1.590     raeburn  1310: 
                   1311: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
                   1312: 
                   1313: =cut
                   1314: 
                   1315: 
                   1316: sub viewport_geometry_js { 
                   1317:     return <<"GEOMETRY";
                   1318: var Geometry = {};
                   1319: function init_geometry() {
                   1320:     if (Geometry.init) { return };
                   1321:     Geometry.init=1;
                   1322:     if (window.innerHeight) {
                   1323:         Geometry.getViewportHeight   = function() { return window.innerHeight; };
                   1324:         Geometry.getViewportWidth   = function() { return window.innerWidth; };
                   1325:         Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
                   1326:         Geometry.getVerticalScroll   = function() { return window.pageYOffset; };
                   1327:     }
                   1328:     else if (document.documentElement && document.documentElement.clientHeight) {
                   1329:         Geometry.getViewportHeight =
                   1330:             function() { return document.documentElement.clientHeight; };
                   1331:         Geometry.getViewportWidth =
                   1332:             function() { return document.documentElement.clientWidth; };
                   1333: 
                   1334:         Geometry.getHorizontalScroll =
                   1335:             function() { return document.documentElement.scrollLeft; };
                   1336:         Geometry.getVerticalScroll =
                   1337:             function() { return document.documentElement.scrollTop; };
                   1338:     }
                   1339:     else if (document.body.clientHeight) {
                   1340:         Geometry.getViewportHeight =
                   1341:             function() { return document.body.clientHeight; };
                   1342:         Geometry.getViewportWidth =
                   1343:             function() { return document.body.clientWidth; };
                   1344:         Geometry.getHorizontalScroll =
                   1345:             function() { return document.body.scrollLeft; };
                   1346:         Geometry.getVerticalScroll =
                   1347:             function() { return document.body.scrollTop; };
                   1348:     }
                   1349: }
                   1350: 
                   1351: GEOMETRY
                   1352: }
                   1353: 
                   1354: =pod
                   1355: 
1.648     raeburn  1356: =item * &viewport_size_js()
1.590     raeburn  1357: 
                   1358: 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. 
                   1359: 
                   1360: =cut
                   1361: 
                   1362: sub viewport_size_js {
                   1363:     my $geometry = &viewport_geometry_js();
                   1364:     return <<"DIMS";
                   1365: 
                   1366: $geometry
                   1367: 
                   1368: function getViewportDims(width,height) {
                   1369:     init_geometry();
                   1370:     width.value = Geometry.getViewportWidth();
                   1371:     height.value = Geometry.getViewportHeight();
                   1372:     return;
                   1373: }
                   1374: 
                   1375: DIMS
                   1376: }
                   1377: 
                   1378: =pod
                   1379: 
1.648     raeburn  1380: =item * &resize_textarea_js()
1.565     albertel 1381: 
                   1382: emits the needed javascript to resize a textarea to be as big as possible
                   1383: 
                   1384: creates a function resize_textrea that takes two IDs first should be
                   1385: the id of the element to resize, second should be the id of a div that
                   1386: surrounds everything that comes after the textarea, this routine needs
                   1387: to be attached to the <body> for the onload and onresize events.
                   1388: 
1.648     raeburn  1389: =back
1.565     albertel 1390: 
                   1391: =cut
                   1392: 
                   1393: sub resize_textarea_js {
1.590     raeburn  1394:     my $geometry = &viewport_geometry_js();
1.565     albertel 1395:     return <<"RESIZE";
                   1396:     <script type="text/javascript">
1.590     raeburn  1397: $geometry
1.565     albertel 1398: 
1.588     albertel 1399: function getX(element) {
                   1400:     var x = 0;
                   1401:     while (element) {
                   1402: 	x += element.offsetLeft;
                   1403: 	element = element.offsetParent;
                   1404:     }
                   1405:     return x;
                   1406: }
                   1407: function getY(element) {
                   1408:     var y = 0;
                   1409:     while (element) {
                   1410: 	y += element.offsetTop;
                   1411: 	element = element.offsetParent;
                   1412:     }
                   1413:     return y;
                   1414: }
                   1415: 
                   1416: 
1.565     albertel 1417: function resize_textarea(textarea_id,bottom_id) {
                   1418:     init_geometry();
                   1419:     var textarea        = document.getElementById(textarea_id);
                   1420:     //alert(textarea);
                   1421: 
1.588     albertel 1422:     var textarea_top    = getY(textarea);
1.565     albertel 1423:     var textarea_height = textarea.offsetHeight;
                   1424:     var bottom          = document.getElementById(bottom_id);
1.588     albertel 1425:     var bottom_top      = getY(bottom);
1.565     albertel 1426:     var bottom_height   = bottom.offsetHeight;
                   1427:     var window_height   = Geometry.getViewportHeight();
1.588     albertel 1428:     var fudge           = 23;
1.565     albertel 1429:     var new_height      = window_height-fudge-textarea_top-bottom_height;
                   1430:     if (new_height < 300) {
                   1431: 	new_height = 300;
                   1432:     }
                   1433:     textarea.style.height=new_height+'px';
                   1434: }
                   1435: </script>
                   1436: RESIZE
                   1437: 
                   1438: }
                   1439: 
                   1440: =pod
                   1441: 
1.256     matthew  1442: =head1 Excel and CSV file utility routines
                   1443: 
                   1444: =over 4
                   1445: 
                   1446: =cut
                   1447: 
                   1448: ###############################################################
                   1449: ###############################################################
                   1450: 
                   1451: =pod
                   1452: 
1.648     raeburn  1453: =item * &csv_translate($text) 
1.37      matthew  1454: 
1.185     www      1455: Translate $text to allow it to be output as a 'comma separated values' 
1.37      matthew  1456: format.
                   1457: 
                   1458: =cut
                   1459: 
1.180     matthew  1460: ###############################################################
                   1461: ###############################################################
1.37      matthew  1462: sub csv_translate {
                   1463:     my $text = shift;
                   1464:     $text =~ s/\"/\"\"/g;
1.209     albertel 1465:     $text =~ s/\n/ /g;
1.37      matthew  1466:     return $text;
                   1467: }
1.180     matthew  1468: 
                   1469: ###############################################################
                   1470: ###############################################################
                   1471: 
                   1472: =pod
                   1473: 
1.648     raeburn  1474: =item * &define_excel_formats()
1.180     matthew  1475: 
                   1476: Define some commonly used Excel cell formats.
                   1477: 
                   1478: Currently supported formats:
                   1479: 
                   1480: =over 4
                   1481: 
                   1482: =item header
                   1483: 
                   1484: =item bold
                   1485: 
                   1486: =item h1
                   1487: 
                   1488: =item h2
                   1489: 
                   1490: =item h3
                   1491: 
1.256     matthew  1492: =item h4
                   1493: 
                   1494: =item i
                   1495: 
1.180     matthew  1496: =item date
                   1497: 
                   1498: =back
                   1499: 
                   1500: Inputs: $workbook
                   1501: 
                   1502: Returns: $format, a hash reference.
                   1503: 
                   1504: =cut
                   1505: 
                   1506: ###############################################################
                   1507: ###############################################################
                   1508: sub define_excel_formats {
                   1509:     my ($workbook) = @_;
                   1510:     my $format;
                   1511:     $format->{'header'} = $workbook->add_format(bold      => 1, 
                   1512:                                                 bottom    => 1,
                   1513:                                                 align     => 'center');
                   1514:     $format->{'bold'} = $workbook->add_format(bold=>1);
                   1515:     $format->{'h1'}   = $workbook->add_format(bold=>1, size=>18);
                   1516:     $format->{'h2'}   = $workbook->add_format(bold=>1, size=>16);
                   1517:     $format->{'h3'}   = $workbook->add_format(bold=>1, size=>14);
1.255     matthew  1518:     $format->{'h4'}   = $workbook->add_format(bold=>1, size=>12);
1.246     matthew  1519:     $format->{'i'}    = $workbook->add_format(italic=>1);
1.180     matthew  1520:     $format->{'date'} = $workbook->add_format(num_format=>
1.207     matthew  1521:                                             'mm/dd/yyyy hh:mm:ss');
1.180     matthew  1522:     return $format;
                   1523: }
                   1524: 
                   1525: ###############################################################
                   1526: ###############################################################
1.113     bowersj2 1527: 
                   1528: =pod
                   1529: 
1.648     raeburn  1530: =item * &create_workbook()
1.255     matthew  1531: 
                   1532: Create an Excel worksheet.  If it fails, output message on the
                   1533: request object and return undefs.
                   1534: 
                   1535: Inputs: Apache request object
                   1536: 
                   1537: Returns (undef) on failure, 
                   1538:     Excel worksheet object, scalar with filename, and formats 
                   1539:     from &Apache::loncommon::define_excel_formats on success
                   1540: 
                   1541: =cut
                   1542: 
                   1543: ###############################################################
                   1544: ###############################################################
                   1545: sub create_workbook {
                   1546:     my ($r) = @_;
                   1547:         #
                   1548:     # Create the excel spreadsheet
                   1549:     my $filename = '/prtspool/'.
1.258     albertel 1550:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255     matthew  1551:         time.'_'.rand(1000000000).'.xls';
                   1552:     my $workbook  = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
                   1553:     if (! defined($workbook)) {
                   1554:         $r->log_error("Error creating excel spreadsheet $filename: $!");
                   1555:         $r->print('<p>'.&mt("Unable to create new Excel file.  ".
                   1556:                             "This error has been logged.  ".
                   1557:                             "Please alert your LON-CAPA administrator").
                   1558:                   '</p>');
                   1559:         return (undef);
                   1560:     }
                   1561:     #
                   1562:     $workbook->set_tempdir('/home/httpd/perl/tmp');
                   1563:     #
                   1564:     my $format = &Apache::loncommon::define_excel_formats($workbook);
                   1565:     return ($workbook,$filename,$format);
                   1566: }
                   1567: 
                   1568: ###############################################################
                   1569: ###############################################################
                   1570: 
                   1571: =pod
                   1572: 
1.648     raeburn  1573: =item * &create_text_file()
1.113     bowersj2 1574: 
1.542     raeburn  1575: Create a file to write to and eventually make available to the user.
1.256     matthew  1576: If file creation fails, outputs an error message on the request object and 
                   1577: return undefs.
1.113     bowersj2 1578: 
1.256     matthew  1579: Inputs: Apache request object, and file suffix
1.113     bowersj2 1580: 
1.256     matthew  1581: Returns (undef) on failure, 
                   1582:     Filehandle and filename on success.
1.113     bowersj2 1583: 
                   1584: =cut
                   1585: 
1.256     matthew  1586: ###############################################################
                   1587: ###############################################################
                   1588: sub create_text_file {
                   1589:     my ($r,$suffix) = @_;
                   1590:     if (! defined($suffix)) { $suffix = 'txt'; };
                   1591:     my $fh;
                   1592:     my $filename = '/prtspool/'.
1.258     albertel 1593:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256     matthew  1594:         time.'_'.rand(1000000000).'.'.$suffix;
                   1595:     $fh = Apache::File->new('>/home/httpd'.$filename);
                   1596:     if (! defined($fh)) {
                   1597:         $r->log_error("Couldn't open $filename for output $!");
1.683     bisitz   1598:         $r->print(&mt('Problems occurred in creating the output file. '
                   1599:                      .'This error has been logged. '
                   1600:                      .'Please alert your LON-CAPA administrator.'));
1.113     bowersj2 1601:     }
1.256     matthew  1602:     return ($fh,$filename)
1.113     bowersj2 1603: }
                   1604: 
                   1605: 
1.256     matthew  1606: =pod 
1.113     bowersj2 1607: 
                   1608: =back
                   1609: 
                   1610: =cut
1.37      matthew  1611: 
                   1612: ###############################################################
1.33      matthew  1613: ##        Home server <option> list generating code          ##
                   1614: ###############################################################
1.35      matthew  1615: 
1.169     www      1616: # ------------------------------------------
                   1617: 
                   1618: sub domain_select {
                   1619:     my ($name,$value,$multiple)=@_;
                   1620:     my %domains=map { 
1.514     albertel 1621: 	$_ => $_.' '. &Apache::lonnet::domain($_,'description') 
1.512     albertel 1622:     } &Apache::lonnet::all_domains();
1.169     www      1623:     if ($multiple) {
                   1624: 	$domains{''}=&mt('Any domain');
1.550     albertel 1625: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287     albertel 1626: 	return &multiple_select_form($name,$value,4,\%domains);
1.169     www      1627:     } else {
1.550     albertel 1628: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169     www      1629: 	return &select_form($name,$value,%domains);
                   1630:     }
                   1631: }
                   1632: 
1.282     albertel 1633: #-------------------------------------------
                   1634: 
                   1635: =pod
                   1636: 
1.519     raeburn  1637: =head1 Routines for form select boxes
                   1638: 
                   1639: =over 4
                   1640: 
1.648     raeburn  1641: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282     albertel 1642: 
                   1643: Returns a string containing a <select> element int multiple mode
                   1644: 
                   1645: 
                   1646: Args:
                   1647:   $name - name of the <select> element
1.506     raeburn  1648:   $value - scalar or array ref of values that should already be selected
1.282     albertel 1649:   $size - number of rows long the select element is
1.283     albertel 1650:   $hash - the elements should be 'option' => 'shown text'
1.282     albertel 1651:           (shown text should already have been &mt())
1.506     raeburn  1652:   $order - (optional) array ref of the order to show the elements in
1.283     albertel 1653: 
1.282     albertel 1654: =cut
                   1655: 
                   1656: #-------------------------------------------
1.169     www      1657: sub multiple_select_form {
1.284     albertel 1658:     my ($name,$value,$size,$hash,$order)=@_;
1.169     www      1659:     my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
                   1660:     my $output='';
1.191     matthew  1661:     if (! defined($size)) {
                   1662:         $size = 4;
1.283     albertel 1663:         if (scalar(keys(%$hash))<4) {
                   1664:             $size = scalar(keys(%$hash));
1.191     matthew  1665:         }
                   1666:     }
1.734     bisitz   1667:     $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501     banghart 1668:     my @order;
1.506     raeburn  1669:     if (ref($order) eq 'ARRAY')  {
                   1670:         @order = @{$order};
                   1671:     } else {
                   1672:         @order = sort(keys(%$hash));
1.501     banghart 1673:     }
                   1674:     if (exists($$hash{'select_form_order'})) {
                   1675:         @order = @{$$hash{'select_form_order'}};
                   1676:     }
                   1677:         
1.284     albertel 1678:     foreach my $key (@order) {
1.356     albertel 1679:         $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284     albertel 1680:         $output.='selected="selected" ' if ($selected{$key});
                   1681:         $output.='>'.$hash->{$key}."</option>\n";
1.169     www      1682:     }
                   1683:     $output.="</select>\n";
                   1684:     return $output;
                   1685: }
                   1686: 
1.88      www      1687: #-------------------------------------------
                   1688: 
                   1689: =pod
                   1690: 
1.648     raeburn  1691: =item * &select_form($defdom,$name,%hash)
1.88      www      1692: 
                   1693: Returns a string containing a <select name='$name' size='1'> form to 
                   1694: allow a user to select options from a hash option_name => displayed text.  
                   1695: See lonrights.pm for an example invocation and use.
                   1696: 
                   1697: =cut
                   1698: 
                   1699: #-------------------------------------------
                   1700: sub select_form {
                   1701:     my ($def,$name,%hash) = @_;
                   1702:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128     albertel 1703:     my @keys;
                   1704:     if (exists($hash{'select_form_order'})) {
                   1705: 	@keys=@{$hash{'select_form_order'}};
                   1706:     } else {
                   1707: 	@keys=sort(keys(%hash));
                   1708:     }
1.356     albertel 1709:     foreach my $key (@keys) {
                   1710:         $selectform.=
                   1711: 	    '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
                   1712:             ($key eq $def ? 'selected="selected" ' : '').
                   1713:                 ">".&mt($hash{$key})."</option>\n";
1.88      www      1714:     }
                   1715:     $selectform.="</select>";
                   1716:     return $selectform;
                   1717: }
                   1718: 
1.475     www      1719: # For display filters
                   1720: 
                   1721: sub display_filter {
                   1722:     if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477     www      1723:     if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714     bisitz   1724:     return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475     www      1725: 			       &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
                   1726: 							   (&mt('all'),10,20,50,100,1000,10000))).
1.714     bisitz   1727: 	   '</label></span> <span class="LC_nobreak">'.
1.475     www      1728:            &mt('Filter [_1]',
1.477     www      1729: 	   &select_form($env{'form.displayfilter'},
                   1730: 			'displayfilter',
                   1731: 			('currentfolder' => 'Current folder/page',
                   1732: 			 'containing' => 'Containing phrase',
                   1733: 			 'none' => 'None'))).
1.714     bisitz   1734: 			 '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475     www      1735: }
                   1736: 
1.167     www      1737: sub gradeleveldescription {
                   1738:     my $gradelevel=shift;
                   1739:     my %gradelevels=(0 => 'Not specified',
                   1740: 		     1 => 'Grade 1',
                   1741: 		     2 => 'Grade 2',
                   1742: 		     3 => 'Grade 3',
                   1743: 		     4 => 'Grade 4',
                   1744: 		     5 => 'Grade 5',
                   1745: 		     6 => 'Grade 6',
                   1746: 		     7 => 'Grade 7',
                   1747: 		     8 => 'Grade 8',
                   1748: 		     9 => 'Grade 9',
                   1749: 		     10 => 'Grade 10',
                   1750: 		     11 => 'Grade 11',
                   1751: 		     12 => 'Grade 12',
                   1752: 		     13 => 'Grade 13',
                   1753: 		     14 => '100 Level',
                   1754: 		     15 => '200 Level',
                   1755: 		     16 => '300 Level',
                   1756: 		     17 => '400 Level',
                   1757: 		     18 => 'Graduate Level');
                   1758:     return &mt($gradelevels{$gradelevel});
                   1759: }
                   1760: 
1.163     www      1761: sub select_level_form {
                   1762:     my ($deflevel,$name)=@_;
                   1763:     unless ($deflevel) { $deflevel=0; }
1.167     www      1764:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
                   1765:     for (my $i=0; $i<=18; $i++) {
                   1766:         $selectform.="<option value=\"$i\" ".
1.253     albertel 1767:             ($i==$deflevel ? 'selected="selected" ' : '').
1.167     www      1768:                 ">".&gradeleveldescription($i)."</option>\n";
                   1769:     }
                   1770:     $selectform.="</select>";
                   1771:     return $selectform;
1.163     www      1772: }
1.167     www      1773: 
1.35      matthew  1774: #-------------------------------------------
                   1775: 
1.45      matthew  1776: =pod
                   1777: 
1.743     raeburn  1778: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$autosubmit)
1.35      matthew  1779: 
                   1780: Returns a string containing a <select name='$name' size='1'> form to 
                   1781: allow a user to select the domain to preform an operation in.  
                   1782: See loncreateuser.pm for an example invocation and use.
                   1783: 
1.90      www      1784: If the $includeempty flag is set, it also includes an empty choice ("no domain
                   1785: selected");
                   1786: 
1.743     raeburn  1787: If the $showdomdesc flag is set, the domain name is followed by the domain description.
                   1788: 
                   1789: If the $autosubmit flag is set, the form containing the domain selector will be auto-submitted by an onchange action.  
1.563     raeburn  1790: 
1.35      matthew  1791: =cut
                   1792: 
                   1793: #-------------------------------------------
1.34      matthew  1794: sub select_dom_form {
1.743     raeburn  1795:     my ($defdom,$name,$includeempty,$showdomdesc,$autosubmit) = @_;
                   1796:     my $onchange;
                   1797:     if ($autosubmit) {
                   1798:         $onchange = ' onchange="this.form.submit()"';
                   1799:     }
1.550     albertel 1800:     my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90      www      1801:     if ($includeempty) { @domains=('',@domains); }
1.743     raeburn  1802:     my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356     albertel 1803:     foreach my $dom (@domains) {
                   1804:         $selectdomain.="<option value=\"$dom\" ".
1.563     raeburn  1805:             ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
                   1806:         if ($showdomdesc) {
                   1807:             if ($dom ne '') {
                   1808:                 my $domdesc = &Apache::lonnet::domain($dom,'description');
                   1809:                 if ($domdesc ne '') {
                   1810:                     $selectdomain .= ' ('.$domdesc.')';
                   1811:                 }
                   1812:             } 
                   1813:         }
                   1814:         $selectdomain .= "</option>\n";
1.34      matthew  1815:     }
                   1816:     $selectdomain.="</select>";
                   1817:     return $selectdomain;
                   1818: }
                   1819: 
1.35      matthew  1820: #-------------------------------------------
                   1821: 
1.45      matthew  1822: =pod
                   1823: 
1.648     raeburn  1824: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35      matthew  1825: 
1.586     raeburn  1826: input: 4 arguments (two required, two optional) - 
                   1827:     $domain - domain of new user
                   1828:     $name - name of form element
                   1829:     $default - Value of 'default' causes a default item to be first 
                   1830:                             option, and selected by default. 
                   1831:     $hide - Value of 'hide' causes hiding of the name of the server, 
                   1832:                             if 1 server found, or default, if 0 found.
1.594     raeburn  1833: output: returns 2 items: 
1.586     raeburn  1834: (a) form element which contains either:
                   1835:    (i) <select name="$name">
                   1836:         <option value="$hostid1">$hostid $servers{$hostid}</option>
                   1837:         <option value="$hostid2">$hostid $servers{$hostid}</option>       
                   1838:        </select>
                   1839:        form item if there are multiple library servers in $domain, or
                   1840:    (ii) an <input type="hidden" name="$name" value="$hostid" /> form item 
                   1841:        if there is only one library server in $domain.
                   1842: 
                   1843: (b) number of library servers found.
                   1844: 
                   1845: See loncreateuser.pm for example of use.
1.35      matthew  1846: 
                   1847: =cut
                   1848: 
                   1849: #-------------------------------------------
1.586     raeburn  1850: sub home_server_form_item {
                   1851:     my ($domain,$name,$default,$hide) = @_;
1.513     albertel 1852:     my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586     raeburn  1853:     my $result;
                   1854:     my $numlib = keys(%servers);
                   1855:     if ($numlib > 1) {
                   1856:         $result .= '<select name="'.$name.'" />'."\n";
                   1857:         if ($default) {
                   1858:             $result .= '<option value="default" selected>'.&mt('default').
                   1859:                        '</option>'."\n";
                   1860:         }
                   1861:         foreach my $hostid (sort(keys(%servers))) {
                   1862:             $result.= '<option value="'.$hostid.'">'.
                   1863: 	              $hostid.' '.$servers{$hostid}."</option>\n";
                   1864:         }
                   1865:         $result .= '</select>'."\n";
                   1866:     } elsif ($numlib == 1) {
                   1867:         my $hostid;
                   1868:         foreach my $item (keys(%servers)) {
                   1869:             $hostid = $item;
                   1870:         }
                   1871:         $result .= '<input type="hidden" name="'.$name.'" value="'.
                   1872:                    $hostid.'" />';
                   1873:                    if (!$hide) {
                   1874:                        $result .= $hostid.' '.$servers{$hostid};
                   1875:                    }
                   1876:                    $result .= "\n";
                   1877:     } elsif ($default) {
                   1878:         $result .= '<input type="hidden" name="'.$name.
                   1879:                    '" value="default" />';
                   1880:                    if (!$hide) {
                   1881:                        $result .= &mt('default');
                   1882:                    }
                   1883:                    $result .= "\n";
1.33      matthew  1884:     }
1.586     raeburn  1885:     return ($result,$numlib);
1.33      matthew  1886: }
1.112     bowersj2 1887: 
                   1888: =pod
                   1889: 
1.534     albertel 1890: =back 
                   1891: 
1.112     bowersj2 1892: =cut
1.87      matthew  1893: 
                   1894: ###############################################################
1.112     bowersj2 1895: ##                  Decoding User Agent                      ##
1.87      matthew  1896: ###############################################################
                   1897: 
                   1898: =pod
                   1899: 
1.112     bowersj2 1900: =head1 Decoding the User Agent
                   1901: 
                   1902: =over 4
                   1903: 
                   1904: =item * &decode_user_agent()
1.87      matthew  1905: 
                   1906: Inputs: $r
                   1907: 
                   1908: Outputs:
                   1909: 
                   1910: =over 4
                   1911: 
1.112     bowersj2 1912: =item * $httpbrowser
1.87      matthew  1913: 
1.112     bowersj2 1914: =item * $clientbrowser
1.87      matthew  1915: 
1.112     bowersj2 1916: =item * $clientversion
1.87      matthew  1917: 
1.112     bowersj2 1918: =item * $clientmathml
1.87      matthew  1919: 
1.112     bowersj2 1920: =item * $clientunicode
1.87      matthew  1921: 
1.112     bowersj2 1922: =item * $clientos
1.87      matthew  1923: 
                   1924: =back
                   1925: 
1.157     matthew  1926: =back 
                   1927: 
1.87      matthew  1928: =cut
                   1929: 
                   1930: ###############################################################
                   1931: ###############################################################
                   1932: sub decode_user_agent {
1.247     albertel 1933:     my ($r)=@_;
1.87      matthew  1934:     my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
                   1935:     my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
                   1936:     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247     albertel 1937:     if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87      matthew  1938:     my $clientbrowser='unknown';
                   1939:     my $clientversion='0';
                   1940:     my $clientmathml='';
                   1941:     my $clientunicode='0';
                   1942:     for (my $i=0;$i<=$#browsertype;$i++) {
                   1943:         my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
                   1944: 	if (($httpbrowser=~/$match/i)  && ($httpbrowser!~/$notmatch/i)) {
                   1945: 	    $clientbrowser=$bname;
                   1946:             $httpbrowser=~/$vreg/i;
                   1947: 	    $clientversion=$1;
                   1948:             $clientmathml=($clientversion>=$minv);
                   1949:             $clientunicode=($clientversion>=$univ);
                   1950: 	}
                   1951:     }
                   1952:     my $clientos='unknown';
                   1953:     if (($httpbrowser=~/linux/i) ||
                   1954:         ($httpbrowser=~/unix/i) ||
                   1955:         ($httpbrowser=~/ux/i) ||
                   1956:         ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
                   1957:     if (($httpbrowser=~/vax/i) ||
                   1958:         ($httpbrowser=~/vms/i)) { $clientos='vms'; }
                   1959:     if ($httpbrowser=~/next/i) { $clientos='next'; }
                   1960:     if (($httpbrowser=~/mac/i) ||
                   1961:         ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
                   1962:     if ($httpbrowser=~/win/i) { $clientos='win'; }
                   1963:     if ($httpbrowser=~/embed/i) { $clientos='pda'; }
                   1964:     return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   1965:             $clientunicode,$clientos,);
                   1966: }
                   1967: 
1.32      matthew  1968: ###############################################################
                   1969: ##    Authentication changing form generation subroutines    ##
                   1970: ###############################################################
                   1971: ##
                   1972: ## All of the authform_xxxxxxx subroutines take their inputs in a
                   1973: ## hash, and have reasonable default values.
                   1974: ##
                   1975: ##    formname = the name given in the <form> tag.
1.35      matthew  1976: #-------------------------------------------
                   1977: 
1.45      matthew  1978: =pod
                   1979: 
1.112     bowersj2 1980: =head1 Authentication Routines
                   1981: 
                   1982: =over 4
                   1983: 
1.648     raeburn  1984: =item * &authform_xxxxxx()
1.35      matthew  1985: 
                   1986: The authform_xxxxxx subroutines provide javascript and html forms which 
                   1987: handle some of the conveniences required for authentication forms.  
                   1988: This is not an optimal method, but it works.  
                   1989: 
                   1990: =over 4
                   1991: 
1.112     bowersj2 1992: =item * authform_header
1.35      matthew  1993: 
1.112     bowersj2 1994: =item * authform_authorwarning
1.35      matthew  1995: 
1.112     bowersj2 1996: =item * authform_nochange
1.35      matthew  1997: 
1.112     bowersj2 1998: =item * authform_kerberos
1.35      matthew  1999: 
1.112     bowersj2 2000: =item * authform_internal
1.35      matthew  2001: 
1.112     bowersj2 2002: =item * authform_filesystem
1.35      matthew  2003: 
                   2004: =back
                   2005: 
1.648     raeburn  2006: See loncreateuser.pm for invocation and use examples.
1.157     matthew  2007: 
1.35      matthew  2008: =cut
                   2009: 
                   2010: #-------------------------------------------
1.32      matthew  2011: sub authform_header{  
                   2012:     my %in = (
                   2013:         formname => 'cu',
1.80      albertel 2014:         kerb_def_dom => '',
1.32      matthew  2015:         @_,
                   2016:     );
                   2017:     $in{'formname'} = 'document.' . $in{'formname'};
                   2018:     my $result='';
1.80      albertel 2019: 
                   2020: #---------------------------------------------- Code for upper case translation
                   2021:     my $Javascript_toUpperCase;
                   2022:     unless ($in{kerb_def_dom}) {
                   2023:         $Javascript_toUpperCase =<<"END";
                   2024:         switch (choice) {
                   2025:            case 'krb': currentform.elements[choicearg].value =
                   2026:                currentform.elements[choicearg].value.toUpperCase();
                   2027:                break;
                   2028:            default:
                   2029:         }
                   2030: END
                   2031:     } else {
                   2032:         $Javascript_toUpperCase = "";
                   2033:     }
                   2034: 
1.165     raeburn  2035:     my $radioval = "'nochange'";
1.591     raeburn  2036:     if (defined($in{'curr_authtype'})) {
                   2037:         if ($in{'curr_authtype'} ne '') {
                   2038:             $radioval = "'".$in{'curr_authtype'}."arg'";
                   2039:         }
1.174     matthew  2040:     }
1.165     raeburn  2041:     my $argfield = 'null';
1.591     raeburn  2042:     if (defined($in{'mode'})) {
1.165     raeburn  2043:         if ($in{'mode'} eq 'modifycourse')  {
1.591     raeburn  2044:             if (defined($in{'curr_autharg'})) {
                   2045:                 if ($in{'curr_autharg'} ne '') {
1.165     raeburn  2046:                     $argfield = "'$in{'curr_autharg'}'";
                   2047:                 }
                   2048:             }
                   2049:         }
                   2050:     }
                   2051: 
1.32      matthew  2052:     $result.=<<"END";
                   2053: var current = new Object();
1.165     raeburn  2054: current.radiovalue = $radioval;
                   2055: current.argfield = $argfield;
1.32      matthew  2056: 
                   2057: function changed_radio(choice,currentform) {
                   2058:     var choicearg = choice + 'arg';
                   2059:     // If a radio button in changed, we need to change the argfield
                   2060:     if (current.radiovalue != choice) {
                   2061:         current.radiovalue = choice;
                   2062:         if (current.argfield != null) {
                   2063:             currentform.elements[current.argfield].value = '';
                   2064:         }
                   2065:         if (choice == 'nochange') {
                   2066:             current.argfield = null;
                   2067:         } else {
                   2068:             current.argfield = choicearg;
                   2069:             switch(choice) {
                   2070:                 case 'krb': 
                   2071:                     currentform.elements[current.argfield].value = 
                   2072:                         "$in{'kerb_def_dom'}";
                   2073:                 break;
                   2074:               default:
                   2075:                 break;
                   2076:             }
                   2077:         }
                   2078:     }
                   2079:     return;
                   2080: }
1.22      www      2081: 
1.32      matthew  2082: function changed_text(choice,currentform) {
                   2083:     var choicearg = choice + 'arg';
                   2084:     if (currentform.elements[choicearg].value !='') {
1.80      albertel 2085:         $Javascript_toUpperCase
1.32      matthew  2086:         // clear old field
                   2087:         if ((current.argfield != choicearg) && (current.argfield != null)) {
                   2088:             currentform.elements[current.argfield].value = '';
                   2089:         }
                   2090:         current.argfield = choicearg;
                   2091:     }
                   2092:     set_auth_radio_buttons(choice,currentform);
                   2093:     return;
1.20      www      2094: }
1.32      matthew  2095: 
                   2096: function set_auth_radio_buttons(newvalue,currentform) {
                   2097:     var i=0;
                   2098:     while (i < currentform.login.length) {
                   2099:         if (currentform.login[i].value == newvalue) { break; }
                   2100:         i++;
                   2101:     }
                   2102:     if (i == currentform.login.length) {
                   2103:         return;
                   2104:     }
                   2105:     current.radiovalue = newvalue;
                   2106:     currentform.login[i].checked = true;
                   2107:     return;
                   2108: }
                   2109: END
                   2110:     return $result;
                   2111: }
                   2112: 
                   2113: sub authform_authorwarning{
                   2114:     my $result='';
1.144     matthew  2115:     $result='<i>'.
                   2116:         &mt('As a general rule, only authors or co-authors should be '.
                   2117:             'filesystem authenticated '.
                   2118:             '(which allows access to the server filesystem).')."</i>\n";
1.32      matthew  2119:     return $result;
                   2120: }
                   2121: 
                   2122: sub authform_nochange{  
                   2123:     my %in = (
                   2124:               formname => 'document.cu',
                   2125:               kerb_def_dom => 'MSU.EDU',
                   2126:               @_,
                   2127:           );
1.586     raeburn  2128:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'}); 
                   2129:     my $result;
                   2130:     if (keys(%can_assign) == 0) {
                   2131:         $result = &mt('Under you current role you are not permitted to change login settings for this user');  
                   2132:     } else {
                   2133:         $result = '<label>'.&mt('[_1] Do not change login data',
                   2134:                   '<input type="radio" name="login" value="nochange" '.
                   2135:                   'checked="checked" onclick="'.
1.281     albertel 2136:             "javascript:changed_radio('nochange',$in{'formname'});".'" />').
                   2137: 	    '</label>';
1.586     raeburn  2138:     }
1.32      matthew  2139:     return $result;
                   2140: }
                   2141: 
1.591     raeburn  2142: sub authform_kerberos {
1.32      matthew  2143:     my %in = (
                   2144:               formname => 'document.cu',
                   2145:               kerb_def_dom => 'MSU.EDU',
1.80      albertel 2146:               kerb_def_auth => 'krb4',
1.32      matthew  2147:               @_,
                   2148:               );
1.586     raeburn  2149:     my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
                   2150:         $autharg,$jscall);
                   2151:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.80      albertel 2152:     if ($in{'kerb_def_auth'} eq 'krb5') {
1.772     bisitz   2153:        $check5 = ' checked="checked"';
1.80      albertel 2154:     } else {
1.772     bisitz   2155:        $check4 = ' checked="checked"';
1.80      albertel 2156:     }
1.165     raeburn  2157:     $krbarg = $in{'kerb_def_dom'};
1.591     raeburn  2158:     if (defined($in{'curr_authtype'})) {
                   2159:         if ($in{'curr_authtype'} eq 'krb') {
1.772     bisitz   2160:             $krbcheck = ' checked="checked"';
1.623     raeburn  2161:             if (defined($in{'mode'})) {
                   2162:                 if ($in{'mode'} eq 'modifyuser') {
                   2163:                     $krbcheck = '';
                   2164:                 }
                   2165:             }
1.591     raeburn  2166:             if (defined($in{'curr_kerb_ver'})) {
                   2167:                 if ($in{'curr_krb_ver'} eq '5') {
1.772     bisitz   2168:                     $check5 = ' checked="checked"';
1.591     raeburn  2169:                     $check4 = '';
                   2170:                 } else {
1.772     bisitz   2171:                     $check4 = ' checked="checked"';
1.591     raeburn  2172:                     $check5 = '';
                   2173:                 }
1.586     raeburn  2174:             }
1.591     raeburn  2175:             if (defined($in{'curr_autharg'})) {
1.165     raeburn  2176:                 $krbarg = $in{'curr_autharg'};
                   2177:             }
1.586     raeburn  2178:             if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591     raeburn  2179:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2180:                     $result = 
                   2181:     &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
                   2182:         $in{'curr_autharg'},$krbver);
                   2183:                 } else {
                   2184:                     $result =
                   2185:     &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
                   2186:                 }
                   2187:                 return $result; 
                   2188:             }
                   2189:         }
                   2190:     } else {
                   2191:         if ($authnum == 1) {
1.784     bisitz   2192:             $authtype = '<input type="hidden" name="login" value="krb" />';
1.165     raeburn  2193:         }
                   2194:     }
1.586     raeburn  2195:     if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
                   2196:         return;
1.587     raeburn  2197:     } elsif ($authtype eq '') {
1.591     raeburn  2198:         if (defined($in{'mode'})) {
1.587     raeburn  2199:             if ($in{'mode'} eq 'modifycourse') {
                   2200:                 if ($authnum == 1) {
1.784     bisitz   2201:                     $authtype = '<input type="hidden" name="login" value="krb" />';
1.587     raeburn  2202:                 }
                   2203:             }
                   2204:         }
1.586     raeburn  2205:     }
                   2206:     $jscall = "javascript:changed_radio('krb',$in{'formname'});";
                   2207:     if ($authtype eq '') {
                   2208:         $authtype = '<input type="radio" name="login" value="krb" '.
                   2209:                     'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
                   2210:                     $krbcheck.' />';
                   2211:     }
                   2212:     if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
                   2213:         ($can_assign{'krb4'} && !$can_assign{'krb5'} && 
                   2214:          $in{'curr_authtype'} eq 'krb5') ||
                   2215:         (!$can_assign{'krb4'} && $can_assign{'krb5'} && 
                   2216:          $in{'curr_authtype'} eq 'krb4')) {
                   2217:         $result .= &mt
1.144     matthew  2218:         ('[_1] Kerberos authenticated with domain [_2] '.
1.281     albertel 2219:          '[_3] Version 4 [_4] Version 5 [_5]',
1.586     raeburn  2220:          '<label>'.$authtype,
1.281     albertel 2221:          '</label><input type="text" size="10" name="krbarg" '.
1.165     raeburn  2222:              'value="'.$krbarg.'" '.
1.144     matthew  2223:              'onchange="'.$jscall.'" />',
1.281     albertel 2224:          '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
                   2225:          '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
                   2226: 	 '</label>');
1.586     raeburn  2227:     } elsif ($can_assign{'krb4'}) {
                   2228:         $result .= &mt
                   2229:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2230:          '[_3] Version 4 [_4]',
                   2231:          '<label>'.$authtype,
                   2232:          '</label><input type="text" size="10" name="krbarg" '.
                   2233:              'value="'.$krbarg.'" '.
                   2234:              'onchange="'.$jscall.'" />',
                   2235:          '<label><input type="hidden" name="krbver" value="4" />',
                   2236:          '</label>');
                   2237:     } elsif ($can_assign{'krb5'}) {
                   2238:         $result .= &mt
                   2239:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2240:          '[_3] Version 5 [_4]',
                   2241:          '<label>'.$authtype,
                   2242:          '</label><input type="text" size="10" name="krbarg" '.
                   2243:              'value="'.$krbarg.'" '.
                   2244:              'onchange="'.$jscall.'" />',
                   2245:          '<label><input type="hidden" name="krbver" value="5" />',
                   2246:          '</label>');
                   2247:     }
1.32      matthew  2248:     return $result;
                   2249: }
                   2250: 
                   2251: sub authform_internal{  
1.586     raeburn  2252:     my %in = (
1.32      matthew  2253:                 formname => 'document.cu',
                   2254:                 kerb_def_dom => 'MSU.EDU',
                   2255:                 @_,
                   2256:                 );
1.586     raeburn  2257:     my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
                   2258:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2259:     if (defined($in{'curr_authtype'})) {
                   2260:         if ($in{'curr_authtype'} eq 'int') {
1.586     raeburn  2261:             if ($can_assign{'int'}) {
1.772     bisitz   2262:                 $intcheck = 'checked="checked" ';
1.623     raeburn  2263:                 if (defined($in{'mode'})) {
                   2264:                     if ($in{'mode'} eq 'modifyuser') {
                   2265:                         $intcheck = '';
                   2266:                     }
                   2267:                 }
1.591     raeburn  2268:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2269:                     $intarg = $in{'curr_autharg'};
                   2270:                 }
                   2271:             } else {
                   2272:                 $result = &mt('Currently internally authenticated.');
                   2273:                 return $result;
1.165     raeburn  2274:             }
                   2275:         }
1.586     raeburn  2276:     } else {
                   2277:         if ($authnum == 1) {
1.784     bisitz   2278:             $authtype = '<input type="hidden" name="login" value="int" />';
1.586     raeburn  2279:         }
                   2280:     }
                   2281:     if (!$can_assign{'int'}) {
                   2282:         return;
1.587     raeburn  2283:     } elsif ($authtype eq '') {
1.591     raeburn  2284:         if (defined($in{'mode'})) {
1.587     raeburn  2285:             if ($in{'mode'} eq 'modifycourse') {
                   2286:                 if ($authnum == 1) {
1.784     bisitz   2287:                     $authtype = '<input type="hidden" name="login" value="int" />';
1.587     raeburn  2288:                 }
                   2289:             }
                   2290:         }
1.165     raeburn  2291:     }
1.586     raeburn  2292:     $jscall = "javascript:changed_radio('int',$in{'formname'});";
                   2293:     if ($authtype eq '') {
                   2294:         $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
                   2295:                     ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
                   2296:     }
1.605     bisitz   2297:     $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586     raeburn  2298:                $intarg.'" onchange="'.$jscall.'" />';
                   2299:     $result = &mt
1.144     matthew  2300:         ('[_1] Internally authenticated (with initial password [_2])',
1.586     raeburn  2301:          '<label>'.$authtype,'</label>'.$autharg);
1.620     www      2302:     $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  2303:     return $result;
                   2304: }
                   2305: 
                   2306: sub authform_local{  
                   2307:     my %in = (
                   2308:               formname => 'document.cu',
                   2309:               kerb_def_dom => 'MSU.EDU',
                   2310:               @_,
                   2311:               );
1.586     raeburn  2312:     my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
                   2313:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2314:     if (defined($in{'curr_authtype'})) {
                   2315:         if ($in{'curr_authtype'} eq 'loc') {
1.586     raeburn  2316:             if ($can_assign{'loc'}) {
1.772     bisitz   2317:                 $loccheck = 'checked="checked" ';
1.623     raeburn  2318:                 if (defined($in{'mode'})) {
                   2319:                     if ($in{'mode'} eq 'modifyuser') {
                   2320:                         $loccheck = '';
                   2321:                     }
                   2322:                 }
1.591     raeburn  2323:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2324:                     $locarg = $in{'curr_autharg'};
                   2325:                 }
                   2326:             } else {
                   2327:                 $result = &mt('Currently using local (institutional) authentication.');
                   2328:                 return $result;
1.165     raeburn  2329:             }
                   2330:         }
1.586     raeburn  2331:     } else {
                   2332:         if ($authnum == 1) {
1.784     bisitz   2333:             $authtype = '<input type="hidden" name="login" value="loc" />';
1.586     raeburn  2334:         }
                   2335:     }
                   2336:     if (!$can_assign{'loc'}) {
                   2337:         return;
1.587     raeburn  2338:     } elsif ($authtype eq '') {
1.591     raeburn  2339:         if (defined($in{'mode'})) {
1.587     raeburn  2340:             if ($in{'mode'} eq 'modifycourse') {
                   2341:                 if ($authnum == 1) {
1.784     bisitz   2342:                     $authtype = '<input type="hidden" name="login" value="loc" />';
1.587     raeburn  2343:                 }
                   2344:             }
                   2345:         }
1.165     raeburn  2346:     }
1.586     raeburn  2347:     $jscall = "javascript:changed_radio('loc',$in{'formname'});";
                   2348:     if ($authtype eq '') {
                   2349:         $authtype = '<input type="radio" name="login" value="loc" '.
                   2350:                     $loccheck.' onchange="'.$jscall.'" onclick="'.
                   2351:                     $jscall.'" />';
                   2352:     }
                   2353:     $autharg = '<input type="text" size="10" name="locarg" value="'.
                   2354:                $locarg.'" onchange="'.$jscall.'" />';
                   2355:     $result = &mt('[_1] Local Authentication with argument [_2]',
                   2356:                   '<label>'.$authtype,'</label>'.$autharg);
1.32      matthew  2357:     return $result;
                   2358: }
                   2359: 
                   2360: sub authform_filesystem{  
                   2361:     my %in = (
                   2362:               formname => 'document.cu',
                   2363:               kerb_def_dom => 'MSU.EDU',
                   2364:               @_,
                   2365:               );
1.586     raeburn  2366:     my ($fsyscheck,$result,$authtype,$autharg,$jscall);
                   2367:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2368:     if (defined($in{'curr_authtype'})) {
                   2369:         if ($in{'curr_authtype'} eq 'fsys') {
1.586     raeburn  2370:             if ($can_assign{'fsys'}) {
1.772     bisitz   2371:                 $fsyscheck = 'checked="checked" ';
1.623     raeburn  2372:                 if (defined($in{'mode'})) {
                   2373:                     if ($in{'mode'} eq 'modifyuser') {
                   2374:                         $fsyscheck = '';
                   2375:                     }
                   2376:                 }
1.586     raeburn  2377:             } else {
                   2378:                 $result = &mt('Currently Filesystem Authenticated.');
                   2379:                 return $result;
                   2380:             }           
                   2381:         }
                   2382:     } else {
                   2383:         if ($authnum == 1) {
1.784     bisitz   2384:             $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586     raeburn  2385:         }
                   2386:     }
                   2387:     if (!$can_assign{'fsys'}) {
                   2388:         return;
1.587     raeburn  2389:     } elsif ($authtype eq '') {
1.591     raeburn  2390:         if (defined($in{'mode'})) {
1.587     raeburn  2391:             if ($in{'mode'} eq 'modifycourse') {
                   2392:                 if ($authnum == 1) {
1.784     bisitz   2393:                     $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587     raeburn  2394:                 }
                   2395:             }
                   2396:         }
1.586     raeburn  2397:     }
                   2398:     $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
                   2399:     if ($authtype eq '') {
                   2400:         $authtype = '<input type="radio" name="login" value="fsys" '.
                   2401:                     $fsyscheck.' onchange="'.$jscall.'" onclick="'.
                   2402:                     $jscall.'" />';
                   2403:     }
                   2404:     $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
                   2405:                ' onchange="'.$jscall.'" />';
                   2406:     $result = &mt
1.144     matthew  2407:         ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281     albertel 2408:          '<label><input type="radio" name="login" value="fsys" '.
1.586     raeburn  2409:          $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605     bisitz   2410:          '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144     matthew  2411:                   'onchange="'.$jscall.'" />');
1.32      matthew  2412:     return $result;
                   2413: }
                   2414: 
1.586     raeburn  2415: sub get_assignable_auth {
                   2416:     my ($dom) = @_;
                   2417:     if ($dom eq '') {
                   2418:         $dom = $env{'request.role.domain'};
                   2419:     }
                   2420:     my %can_assign = (
                   2421:                           krb4 => 1,
                   2422:                           krb5 => 1,
                   2423:                           int  => 1,
                   2424:                           loc  => 1,
                   2425:                      );
                   2426:     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
                   2427:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   2428:         if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
                   2429:             my $authhash = $domconfig{'usercreation'}{'authtypes'};
                   2430:             my $context;
                   2431:             if ($env{'request.role'} =~ /^au/) {
                   2432:                 $context = 'author';
                   2433:             } elsif ($env{'request.role'} =~ /^dc/) {
                   2434:                 $context = 'domain';
                   2435:             } elsif ($env{'request.course.id'}) {
                   2436:                 $context = 'course';
                   2437:             }
                   2438:             if ($context) {
                   2439:                 if (ref($authhash->{$context}) eq 'HASH') {
                   2440:                    %can_assign = %{$authhash->{$context}}; 
                   2441:                 }
                   2442:             }
                   2443:         }
                   2444:     }
                   2445:     my $authnum = 0;
                   2446:     foreach my $key (keys(%can_assign)) {
                   2447:         if ($can_assign{$key}) {
                   2448:             $authnum ++;
                   2449:         }
                   2450:     }
                   2451:     if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
                   2452:         $authnum --;
                   2453:     }
                   2454:     return ($authnum,%can_assign);
                   2455: }
                   2456: 
1.80      albertel 2457: ###############################################################
                   2458: ##    Get Kerberos Defaults for Domain                 ##
                   2459: ###############################################################
                   2460: ##
                   2461: ## Returns default kerberos version and an associated argument
                   2462: ## as listed in file domain.tab. If not listed, provides
                   2463: ## appropriate default domain and kerberos version.
                   2464: ##
                   2465: #-------------------------------------------
                   2466: 
                   2467: =pod
                   2468: 
1.648     raeburn  2469: =item * &get_kerberos_defaults()
1.80      albertel 2470: 
                   2471: get_kerberos_defaults($target_domain) returns the default kerberos
1.641     raeburn  2472: version and domain. If not found, it defaults to version 4 and the 
                   2473: domain of the server.
1.80      albertel 2474: 
1.648     raeburn  2475: =over 4
                   2476: 
1.80      albertel 2477: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
                   2478: 
1.648     raeburn  2479: =back
                   2480: 
                   2481: =back
                   2482: 
1.80      albertel 2483: =cut
                   2484: 
                   2485: #-------------------------------------------
                   2486: sub get_kerberos_defaults {
                   2487:     my $domain=shift;
1.641     raeburn  2488:     my ($krbdef,$krbdefdom);
                   2489:     my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
                   2490:     if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
                   2491:         $krbdef = $domdefaults{'auth_def'};
                   2492:         $krbdefdom = $domdefaults{'auth_arg_def'};
                   2493:     } else {
1.80      albertel 2494:         $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
                   2495:         my $krbdefdom=$1;
                   2496:         $krbdefdom=~tr/a-z/A-Z/;
                   2497:         $krbdef = "krb4";
                   2498:     }
                   2499:     return ($krbdef,$krbdefdom);
                   2500: }
1.112     bowersj2 2501: 
1.32      matthew  2502: 
1.46      matthew  2503: ###############################################################
                   2504: ##                Thesaurus Functions                        ##
                   2505: ###############################################################
1.20      www      2506: 
1.46      matthew  2507: =pod
1.20      www      2508: 
1.112     bowersj2 2509: =head1 Thesaurus Functions
                   2510: 
                   2511: =over 4
                   2512: 
1.648     raeburn  2513: =item * &initialize_keywords()
1.46      matthew  2514: 
                   2515: Initializes the package variable %Keywords if it is empty.  Uses the
                   2516: package variable $thesaurus_db_file.
                   2517: 
                   2518: =cut
                   2519: 
                   2520: ###################################################
                   2521: 
                   2522: sub initialize_keywords {
                   2523:     return 1 if (scalar keys(%Keywords));
                   2524:     # If we are here, %Keywords is empty, so fill it up
                   2525:     #   Make sure the file we need exists...
                   2526:     if (! -e $thesaurus_db_file) {
                   2527:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
                   2528:                                  " failed because it does not exist");
                   2529:         return 0;
                   2530:     }
                   2531:     #   Set up the hash as a database
                   2532:     my %thesaurus_db;
                   2533:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2534:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2535:         &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
                   2536:                                  $thesaurus_db_file);
                   2537:         return 0;
                   2538:     } 
                   2539:     #  Get the average number of appearances of a word.
                   2540:     my $avecount = $thesaurus_db{'average.count'};
                   2541:     #  Put keywords (those that appear > average) into %Keywords
                   2542:     while (my ($word,$data)=each (%thesaurus_db)) {
                   2543:         my ($count,undef) = split /:/,$data;
                   2544:         $Keywords{$word}++ if ($count > $avecount);
                   2545:     }
                   2546:     untie %thesaurus_db;
                   2547:     # Remove special values from %Keywords.
1.356     albertel 2548:     foreach my $value ('total.count','average.count') {
                   2549:         delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586     raeburn  2550:   }
1.46      matthew  2551:     return 1;
                   2552: }
                   2553: 
                   2554: ###################################################
                   2555: 
                   2556: =pod
                   2557: 
1.648     raeburn  2558: =item * &keyword($word)
1.46      matthew  2559: 
                   2560: Returns true if $word is a keyword.  A keyword is a word that appears more 
                   2561: than the average number of times in the thesaurus database.  Calls 
                   2562: &initialize_keywords
                   2563: 
                   2564: =cut
                   2565: 
                   2566: ###################################################
1.20      www      2567: 
                   2568: sub keyword {
1.46      matthew  2569:     return if (!&initialize_keywords());
                   2570:     my $word=lc(shift());
                   2571:     $word=~s/\W//g;
                   2572:     return exists($Keywords{$word});
1.20      www      2573: }
1.46      matthew  2574: 
                   2575: ###############################################################
                   2576: 
                   2577: =pod 
1.20      www      2578: 
1.648     raeburn  2579: =item * &get_related_words()
1.46      matthew  2580: 
1.160     matthew  2581: Look up a word in the thesaurus.  Takes a scalar argument and returns
1.46      matthew  2582: an array of words.  If the keyword is not in the thesaurus, an empty array
                   2583: will be returned.  The order of the words returned is determined by the
                   2584: database which holds them.
                   2585: 
                   2586: Uses global $thesaurus_db_file.
                   2587: 
                   2588: =cut
                   2589: 
                   2590: ###############################################################
                   2591: sub get_related_words {
                   2592:     my $keyword = shift;
                   2593:     my %thesaurus_db;
                   2594:     if (! -e $thesaurus_db_file) {
                   2595:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
                   2596:                                  "failed because the file does not exist");
                   2597:         return ();
                   2598:     }
                   2599:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2600:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2601:         return ();
                   2602:     } 
                   2603:     my @Words=();
1.429     www      2604:     my $count=0;
1.46      matthew  2605:     if (exists($thesaurus_db{$keyword})) {
1.356     albertel 2606: 	# The first element is the number of times
                   2607: 	# the word appears.  We do not need it now.
1.429     www      2608: 	my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
                   2609: 	my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
                   2610: 	my $threshold=$mostfrequentcount/10;
                   2611:         foreach my $possibleword (@RelatedWords) {
                   2612:             my ($word,$wordcount)=split(/\,/,$possibleword);
                   2613:             if ($wordcount>$threshold) {
                   2614: 		push(@Words,$word);
                   2615:                 $count++;
                   2616:                 if ($count>10) { last; }
                   2617: 	    }
1.20      www      2618:         }
                   2619:     }
1.46      matthew  2620:     untie %thesaurus_db;
                   2621:     return @Words;
1.14      harris41 2622: }
1.46      matthew  2623: 
1.112     bowersj2 2624: =pod
                   2625: 
                   2626: =back
                   2627: 
                   2628: =cut
1.61      www      2629: 
                   2630: # -------------------------------------------------------------- Plaintext name
1.81      albertel 2631: =pod
                   2632: 
1.112     bowersj2 2633: =head1 User Name Functions
                   2634: 
                   2635: =over 4
                   2636: 
1.648     raeburn  2637: =item * &plainname($uname,$udom,$first)
1.81      albertel 2638: 
1.112     bowersj2 2639: Takes a users logon name and returns it as a string in
1.226     albertel 2640: "first middle last generation" form 
                   2641: if $first is set to 'lastname' then it returns it as
                   2642: 'lastname generation, firstname middlename' if their is a lastname
1.81      albertel 2643: 
                   2644: =cut
1.61      www      2645: 
1.295     www      2646: 
1.81      albertel 2647: ###############################################################
1.61      www      2648: sub plainname {
1.226     albertel 2649:     my ($uname,$udom,$first)=@_;
1.537     albertel 2650:     return if (!defined($uname) || !defined($udom));
1.295     www      2651:     my %names=&getnames($uname,$udom);
1.226     albertel 2652:     my $name=&Apache::lonnet::format_name($names{'firstname'},
                   2653: 					  $names{'middlename'},
                   2654: 					  $names{'lastname'},
                   2655: 					  $names{'generation'},$first);
                   2656:     $name=~s/^\s+//;
1.62      www      2657:     $name=~s/\s+$//;
                   2658:     $name=~s/\s+/ /g;
1.353     albertel 2659:     if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62      www      2660:     return $name;
1.61      www      2661: }
1.66      www      2662: 
                   2663: # -------------------------------------------------------------------- Nickname
1.81      albertel 2664: =pod
                   2665: 
1.648     raeburn  2666: =item * &nickname($uname,$udom)
1.81      albertel 2667: 
                   2668: Gets a users name and returns it as a string as
                   2669: 
                   2670: "&quot;nickname&quot;"
1.66      www      2671: 
1.81      albertel 2672: if the user has a nickname or
                   2673: 
                   2674: "first middle last generation"
                   2675: 
                   2676: if the user does not
                   2677: 
                   2678: =cut
1.66      www      2679: 
                   2680: sub nickname {
                   2681:     my ($uname,$udom)=@_;
1.537     albertel 2682:     return if (!defined($uname) || !defined($udom));
1.295     www      2683:     my %names=&getnames($uname,$udom);
1.68      albertel 2684:     my $name=$names{'nickname'};
1.66      www      2685:     if ($name) {
                   2686:        $name='&quot;'.$name.'&quot;'; 
                   2687:     } else {
                   2688:        $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
                   2689: 	     $names{'lastname'}.' '.$names{'generation'};
                   2690:        $name=~s/\s+$//;
                   2691:        $name=~s/\s+/ /g;
                   2692:     }
                   2693:     return $name;
                   2694: }
                   2695: 
1.295     www      2696: sub getnames {
                   2697:     my ($uname,$udom)=@_;
1.537     albertel 2698:     return if (!defined($uname) || !defined($udom));
1.433     albertel 2699:     if ($udom eq 'public' && $uname eq 'public') {
                   2700: 	return ('lastname' => &mt('Public'));
                   2701:     }
1.295     www      2702:     my $id=$uname.':'.$udom;
                   2703:     my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
                   2704:     if ($cached) {
                   2705: 	return %{$names};
                   2706:     } else {
                   2707: 	my %loadnames=&Apache::lonnet::get('environment',
                   2708:                     ['firstname','middlename','lastname','generation','nickname'],
                   2709: 					 $udom,$uname);
                   2710: 	&Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
                   2711: 	return %loadnames;
                   2712:     }
                   2713: }
1.61      www      2714: 
1.542     raeburn  2715: # -------------------------------------------------------------------- getemails
1.648     raeburn  2716: 
1.542     raeburn  2717: =pod
                   2718: 
1.648     raeburn  2719: =item * &getemails($uname,$udom)
1.542     raeburn  2720: 
                   2721: Gets a user's email information and returns it as a hash with keys:
                   2722: notification, critnotification, permanentemail
                   2723: 
                   2724: For notification and critnotification, values are comma-separated lists 
1.648     raeburn  2725: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542     raeburn  2726:  
1.648     raeburn  2727: 
1.542     raeburn  2728: =cut
                   2729: 
1.648     raeburn  2730: 
1.466     albertel 2731: sub getemails {
                   2732:     my ($uname,$udom)=@_;
                   2733:     if ($udom eq 'public' && $uname eq 'public') {
                   2734: 	return;
                   2735:     }
1.467     www      2736:     if (!$udom) { $udom=$env{'user.domain'}; }
                   2737:     if (!$uname) { $uname=$env{'user.name'}; }
1.466     albertel 2738:     my $id=$uname.':'.$udom;
                   2739:     my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
                   2740:     if ($cached) {
                   2741: 	return %{$names};
                   2742:     } else {
                   2743: 	my %loadnames=&Apache::lonnet::get('environment',
                   2744:                     			   ['notification','critnotification',
                   2745: 					    'permanentemail'],
                   2746: 					   $udom,$uname);
                   2747: 	&Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
                   2748: 	return %loadnames;
                   2749:     }
                   2750: }
                   2751: 
1.551     albertel 2752: sub flush_email_cache {
                   2753:     my ($uname,$udom)=@_;
                   2754:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2755:     if (!$uname) { $uname=$env{'user.name'};   }
                   2756:     return if ($udom eq 'public' && $uname eq 'public');
                   2757:     my $id=$uname.':'.$udom;
                   2758:     &Apache::lonnet::devalidate_cache_new('emailscache',$id);
                   2759: }
                   2760: 
1.728     raeburn  2761: # -------------------------------------------------------------------- getlangs
                   2762: 
                   2763: =pod
                   2764: 
                   2765: =item * &getlangs($uname,$udom)
                   2766: 
                   2767: Gets a user's language preference and returns it as a hash with key:
                   2768: language.
                   2769: 
                   2770: =cut
                   2771: 
                   2772: 
                   2773: sub getlangs {
                   2774:     my ($uname,$udom) = @_;
                   2775:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2776:     if (!$uname) { $uname=$env{'user.name'};   }
                   2777:     my $id=$uname.':'.$udom;
                   2778:     my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
                   2779:     if ($cached) {
                   2780:         return %{$langs};
                   2781:     } else {
                   2782:         my %loadlangs=&Apache::lonnet::get('environment',['languages'],
                   2783:                                            $udom,$uname);
                   2784:         &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
                   2785:         return %loadlangs;
                   2786:     }
                   2787: }
                   2788: 
                   2789: sub flush_langs_cache {
                   2790:     my ($uname,$udom)=@_;
                   2791:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2792:     if (!$uname) { $uname=$env{'user.name'};   }
                   2793:     return if ($udom eq 'public' && $uname eq 'public');
                   2794:     my $id=$uname.':'.$udom;
                   2795:     &Apache::lonnet::devalidate_cache_new('userlangs',$id);
                   2796: }
                   2797: 
1.61      www      2798: # ------------------------------------------------------------------ Screenname
1.81      albertel 2799: 
                   2800: =pod
                   2801: 
1.648     raeburn  2802: =item * &screenname($uname,$udom)
1.81      albertel 2803: 
                   2804: Gets a users screenname and returns it as a string
                   2805: 
                   2806: =cut
1.61      www      2807: 
                   2808: sub screenname {
                   2809:     my ($uname,$udom)=@_;
1.258     albertel 2810:     if ($uname eq $env{'user.name'} &&
                   2811: 	$udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212     albertel 2812:     my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68      albertel 2813:     return $names{'screenname'};
1.62      www      2814: }
                   2815: 
1.212     albertel 2816: 
1.62      www      2817: # ------------------------------------------------------------- Message Wrapper
                   2818: 
                   2819: sub messagewrapper {
1.369     www      2820:     my ($link,$username,$domain,$subject,$text)=@_;
1.62      www      2821:     return 
1.441     albertel 2822:         '<a href="/adm/email?compose=individual&amp;'.
                   2823:         'recname='.$username.'&amp;recdom='.$domain.
                   2824: 	'&amp;subject='.&escape($subject).'&amp;text='.&escape($text).'" '.
1.200     matthew  2825:         'title="'.&mt('Send message').'">'.$link.'</a>';
1.74      www      2826: }
                   2827: # --------------------------------------------------------------- Notes Wrapper
                   2828: 
                   2829: sub noteswrapper {
                   2830:     my ($link,$un,$do)=@_;
                   2831:     return 
                   2832: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62      www      2833: }
                   2834: # ------------------------------------------------------------- Aboutme Wrapper
                   2835: 
                   2836: sub aboutmewrapper {
1.166     www      2837:     my ($link,$username,$domain,$target)=@_;
1.447     raeburn  2838:     if (!defined($username)  && !defined($domain)) {
                   2839:         return;
                   2840:     }
1.205     www      2841:     return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.756     weissno  2842: 	($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62      www      2843: }
                   2844: 
                   2845: # ------------------------------------------------------------ Syllabus Wrapper
                   2846: 
                   2847: 
                   2848: sub syllabuswrapper {
1.707     bisitz   2849:     my ($linktext,$coursedir,$domain)=@_;
1.208     matthew  2850:     return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61      www      2851: }
1.14      harris41 2852: 
1.208     matthew  2853: sub track_student_link {
1.268     albertel 2854:     my ($linktext,$sname,$sdom,$target,$start) = @_;
                   2855:     my $link ="/adm/trackstudent?";
1.208     matthew  2856:     my $title = 'View recent activity';
                   2857:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   2858:         defined($sdom)  && $sdom  !~ /^\s*$/) {
1.268     albertel 2859:         $link .= "selected_student=$sname:$sdom";
1.208     matthew  2860:         $title .= ' of this student';
1.268     albertel 2861:     } 
1.208     matthew  2862:     if (defined($target) && $target !~ /^\s*$/) {
                   2863:         $target = qq{target="$target"};
                   2864:     } else {
                   2865:         $target = '';
                   2866:     }
1.268     albertel 2867:     if ($start) { $link.='&amp;start='.$start; }
1.554     albertel 2868:     $title = &mt($title);
                   2869:     $linktext = &mt($linktext);
1.448     albertel 2870:     return qq{<a href="$link" title="$title" $target>$linktext</a>}.
                   2871: 	&help_open_topic('View_recent_activity');
1.208     matthew  2872: }
                   2873: 
1.781     raeburn  2874: sub slot_reservations_link {
                   2875:     my ($linktext,$sname,$sdom,$target) = @_;
                   2876:     my $link ="/adm/slotrequest?command=showresv&amp;origin=aboutme";
                   2877:     my $title = 'View slot reservation history';
                   2878:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   2879:         defined($sdom)  && $sdom  !~ /^\s*$/) {
                   2880:         $link .= "&amp;uname=$sname&amp;udom=$sdom";
                   2881:         $title .= ' of this student';
                   2882:     }
                   2883:     if (defined($target) && $target !~ /^\s*$/) {
                   2884:         $target = qq{target="$target"};
                   2885:     } else {
                   2886:         $target = '';
                   2887:     }
                   2888:     $title = &mt($title);
                   2889:     $linktext = &mt($linktext);
                   2890:     return qq{<a href="$link" title="$title" $target>$linktext</a>};
                   2891: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
                   2892: 
                   2893: }
                   2894: 
1.508     www      2895: # ===================================================== Display a student photo
                   2896: 
                   2897: 
1.509     albertel 2898: sub student_image_tag {
1.508     www      2899:     my ($domain,$user)=@_;
                   2900:     my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
                   2901:     if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
                   2902: 	return '<img src="'.$imgsrc.'" align="right" />';
                   2903:     } else {
                   2904: 	return '';
                   2905:     }
                   2906: }
                   2907: 
1.112     bowersj2 2908: =pod
                   2909: 
                   2910: =back
                   2911: 
                   2912: =head1 Access .tab File Data
                   2913: 
                   2914: =over 4
                   2915: 
1.648     raeburn  2916: =item * &languageids() 
1.112     bowersj2 2917: 
                   2918: returns list of all language ids
                   2919: 
                   2920: =cut
                   2921: 
1.14      harris41 2922: sub languageids {
1.16      harris41 2923:     return sort(keys(%language));
1.14      harris41 2924: }
                   2925: 
1.112     bowersj2 2926: =pod
                   2927: 
1.648     raeburn  2928: =item * &languagedescription() 
1.112     bowersj2 2929: 
                   2930: returns description of a specified language id
                   2931: 
                   2932: =cut
                   2933: 
1.14      harris41 2934: sub languagedescription {
1.125     www      2935:     my $code=shift;
                   2936:     return  ($supported_language{$code}?'* ':'').
                   2937:             $language{$code}.
1.126     www      2938: 	    ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145     www      2939: }
                   2940: 
                   2941: sub plainlanguagedescription {
                   2942:     my $code=shift;
                   2943:     return $language{$code};
                   2944: }
                   2945: 
                   2946: sub supportedlanguagecode {
                   2947:     my $code=shift;
                   2948:     return $supported_language{$code};
1.97      www      2949: }
                   2950: 
1.112     bowersj2 2951: =pod
                   2952: 
1.648     raeburn  2953: =item * &copyrightids() 
1.112     bowersj2 2954: 
                   2955: returns list of all copyrights
                   2956: 
                   2957: =cut
                   2958: 
                   2959: sub copyrightids {
                   2960:     return sort(keys(%cprtag));
                   2961: }
                   2962: 
                   2963: =pod
                   2964: 
1.648     raeburn  2965: =item * &copyrightdescription() 
1.112     bowersj2 2966: 
                   2967: returns description of a specified copyright id
                   2968: 
                   2969: =cut
                   2970: 
                   2971: sub copyrightdescription {
1.166     www      2972:     return &mt($cprtag{shift(@_)});
1.112     bowersj2 2973: }
1.197     matthew  2974: 
                   2975: =pod
                   2976: 
1.648     raeburn  2977: =item * &source_copyrightids() 
1.192     taceyjo1 2978: 
                   2979: returns list of all source copyrights
                   2980: 
                   2981: =cut
                   2982: 
                   2983: sub source_copyrightids {
                   2984:     return sort(keys(%scprtag));
                   2985: }
                   2986: 
                   2987: =pod
                   2988: 
1.648     raeburn  2989: =item * &source_copyrightdescription() 
1.192     taceyjo1 2990: 
                   2991: returns description of a specified source copyright id
                   2992: 
                   2993: =cut
                   2994: 
                   2995: sub source_copyrightdescription {
                   2996:     return &mt($scprtag{shift(@_)});
                   2997: }
1.112     bowersj2 2998: 
                   2999: =pod
                   3000: 
1.648     raeburn  3001: =item * &filecategories() 
1.112     bowersj2 3002: 
                   3003: returns list of all file categories
                   3004: 
                   3005: =cut
                   3006: 
                   3007: sub filecategories {
                   3008:     return sort(keys(%category_extensions));
                   3009: }
                   3010: 
                   3011: =pod
                   3012: 
1.648     raeburn  3013: =item * &filecategorytypes() 
1.112     bowersj2 3014: 
                   3015: returns list of file types belonging to a given file
                   3016: category
                   3017: 
                   3018: =cut
                   3019: 
                   3020: sub filecategorytypes {
1.356     albertel 3021:     my ($cat) = @_;
                   3022:     return @{$category_extensions{lc($cat)}};
1.112     bowersj2 3023: }
                   3024: 
                   3025: =pod
                   3026: 
1.648     raeburn  3027: =item * &fileembstyle() 
1.112     bowersj2 3028: 
                   3029: returns embedding style for a specified file type
                   3030: 
                   3031: =cut
                   3032: 
                   3033: sub fileembstyle {
                   3034:     return $fe{lc(shift(@_))};
1.169     www      3035: }
                   3036: 
1.351     www      3037: sub filemimetype {
                   3038:     return $fm{lc(shift(@_))};
                   3039: }
                   3040: 
1.169     www      3041: 
                   3042: sub filecategoryselect {
                   3043:     my ($name,$value)=@_;
1.189     matthew  3044:     return &select_form($value,$name,
1.169     www      3045: 			'' => &mt('Any category'),
                   3046: 			map { $_,$_ } sort(keys(%category_extensions)));
1.112     bowersj2 3047: }
                   3048: 
                   3049: =pod
                   3050: 
1.648     raeburn  3051: =item * &filedescription() 
1.112     bowersj2 3052: 
                   3053: returns description for a specified file type
                   3054: 
                   3055: =cut
                   3056: 
                   3057: sub filedescription {
1.188     matthew  3058:     my $file_description = $fd{lc(shift())};
                   3059:     $file_description =~ s:([\[\]]):~$1:g;
                   3060:     return &mt($file_description);
1.112     bowersj2 3061: }
                   3062: 
                   3063: =pod
                   3064: 
1.648     raeburn  3065: =item * &filedescriptionex() 
1.112     bowersj2 3066: 
                   3067: returns description for a specified file type with
                   3068: extra formatting
                   3069: 
                   3070: =cut
                   3071: 
                   3072: sub filedescriptionex {
                   3073:     my $ex=shift;
1.188     matthew  3074:     my $file_description = $fd{lc($ex)};
                   3075:     $file_description =~ s:([\[\]]):~$1:g;
                   3076:     return '.'.$ex.' '.&mt($file_description);
1.112     bowersj2 3077: }
                   3078: 
                   3079: # End of .tab access
                   3080: =pod
                   3081: 
                   3082: =back
                   3083: 
                   3084: =cut
                   3085: 
                   3086: # ------------------------------------------------------------------ File Types
                   3087: sub fileextensions {
                   3088:     return sort(keys(%fe));
                   3089: }
                   3090: 
1.97      www      3091: # ----------------------------------------------------------- Display Languages
                   3092: # returns a hash with all desired display languages
                   3093: #
                   3094: 
                   3095: sub display_languages {
                   3096:     my %languages=();
1.695     raeburn  3097:     foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356     albertel 3098: 	$languages{$lang}=1;
1.97      www      3099:     }
                   3100:     &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258     albertel 3101:     if ($env{'form.displaylanguage'}) {
1.356     albertel 3102: 	foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
                   3103: 	    $languages{$lang}=1;
1.97      www      3104:         }
                   3105:     }
                   3106:     return %languages;
1.14      harris41 3107: }
                   3108: 
1.582     albertel 3109: sub languages {
                   3110:     my ($possible_langs) = @_;
1.695     raeburn  3111:     my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582     albertel 3112:     if (!ref($possible_langs)) {
                   3113: 	if( wantarray ) {
                   3114: 	    return @preferred_langs;
                   3115: 	} else {
                   3116: 	    return $preferred_langs[0];
                   3117: 	}
                   3118:     }
                   3119:     my %possibilities = map { $_ => 1 } (@$possible_langs);
                   3120:     my @preferred_possibilities;
                   3121:     foreach my $preferred_lang (@preferred_langs) {
                   3122: 	if (exists($possibilities{$preferred_lang})) {
                   3123: 	    push(@preferred_possibilities, $preferred_lang);
                   3124: 	}
                   3125:     }
                   3126:     if( wantarray ) {
                   3127: 	return @preferred_possibilities;
                   3128:     }
                   3129:     return $preferred_possibilities[0];
                   3130: }
                   3131: 
1.742     raeburn  3132: sub user_lang {
                   3133:     my ($touname,$toudom,$fromcid) = @_;
                   3134:     my @userlangs;
                   3135:     if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
                   3136:         @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
                   3137:                     $env{'course.'.$fromcid.'.languages'}));
                   3138:     } else {
                   3139:         my %langhash = &getlangs($touname,$toudom);
                   3140:         if ($langhash{'languages'} ne '') {
                   3141:             @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
                   3142:         } else {
                   3143:             my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
                   3144:             if ($domdefs{'lang_def'} ne '') {
                   3145:                 @userlangs = ($domdefs{'lang_def'});
                   3146:             }
                   3147:         }
                   3148:     }
                   3149:     my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
                   3150:     my $user_lh = Apache::localize->get_handle(@languages);
                   3151:     return $user_lh;
                   3152: }
                   3153: 
                   3154: 
1.112     bowersj2 3155: ###############################################################
                   3156: ##               Student Answer Attempts                     ##
                   3157: ###############################################################
                   3158: 
                   3159: =pod
                   3160: 
                   3161: =head1 Alternate Problem Views
                   3162: 
                   3163: =over 4
                   3164: 
1.648     raeburn  3165: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112     bowersj2 3166:     $getattempt, $regexp, $gradesub)
                   3167: 
                   3168: Return string with previous attempt on problem. Arguments:
                   3169: 
                   3170: =over 4
                   3171: 
                   3172: =item * $symb: Problem, including path
                   3173: 
                   3174: =item * $username: username of the desired student
                   3175: 
                   3176: =item * $domain: domain of the desired student
1.14      harris41 3177: 
1.112     bowersj2 3178: =item * $course: Course ID
1.14      harris41 3179: 
1.112     bowersj2 3180: =item * $getattempt: Leave blank for all attempts, otherwise put
                   3181:     something
1.14      harris41 3182: 
1.112     bowersj2 3183: =item * $regexp: if string matches this regexp, the string will be
                   3184:     sent to $gradesub
1.14      harris41 3185: 
1.112     bowersj2 3186: =item * $gradesub: routine that processes the string if it matches $regexp
1.14      harris41 3187: 
1.112     bowersj2 3188: =back
1.14      harris41 3189: 
1.112     bowersj2 3190: The output string is a table containing all desired attempts, if any.
1.16      harris41 3191: 
1.112     bowersj2 3192: =cut
1.1       albertel 3193: 
                   3194: sub get_previous_attempt {
1.43      ng       3195:   my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1       albertel 3196:   my $prevattempts='';
1.43      ng       3197:   no strict 'refs';
1.1       albertel 3198:   if ($symb) {
1.3       albertel 3199:     my (%returnhash)=
                   3200:       &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1       albertel 3201:     if ($returnhash{'version'}) {
                   3202:       my %lasthash=();
                   3203:       my $version;
                   3204:       for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356     albertel 3205:         foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
                   3206: 	  $lasthash{$key}=$returnhash{$version.':'.$key};
1.19      harris41 3207:         }
1.1       albertel 3208:       }
1.596     albertel 3209:       $prevattempts=&start_data_table().&start_data_table_header_row();
                   3210:       $prevattempts.='<th>'.&mt('History').'</th>';
1.356     albertel 3211:       foreach my $key (sort(keys(%lasthash))) {
                   3212: 	my ($ign,@parts) = split(/\./,$key);
1.41      ng       3213: 	if ($#parts > 0) {
1.31      albertel 3214: 	  my $data=$parts[-1];
                   3215: 	  pop(@parts);
1.596     albertel 3216: 	  $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.'&nbsp;</th>';
1.31      albertel 3217: 	} else {
1.41      ng       3218: 	  if ($#parts == 0) {
                   3219: 	    $prevattempts.='<th>'.$parts[0].'</th>';
                   3220: 	  } else {
                   3221: 	    $prevattempts.='<th>'.$ign.'</th>';
                   3222: 	  }
1.31      albertel 3223: 	}
1.16      harris41 3224:       }
1.596     albertel 3225:       $prevattempts.=&end_data_table_header_row();
1.40      ng       3226:       if ($getattempt eq '') {
                   3227: 	for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596     albertel 3228: 	  $prevattempts.=&start_data_table_row().
                   3229: 	      '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356     albertel 3230: 	    foreach my $key (sort(keys(%lasthash))) {
1.581     albertel 3231: 		my $value = &format_previous_attempt_value($key,
                   3232: 							   $returnhash{$version.':'.$key});
                   3233: 		$prevattempts.='<td>'.$value.'&nbsp;</td>';   
1.40      ng       3234: 	    }
1.596     albertel 3235: 	  $prevattempts.=&end_data_table_row();
1.40      ng       3236: 	 }
1.1       albertel 3237:       }
1.596     albertel 3238:       $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356     albertel 3239:       foreach my $key (sort(keys(%lasthash))) {
1.581     albertel 3240: 	my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356     albertel 3241: 	if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40      ng       3242: 	$prevattempts.='<td>'.$value.'&nbsp;</td>';
1.16      harris41 3243:       }
1.596     albertel 3244:       $prevattempts.= &end_data_table_row().&end_data_table();
1.1       albertel 3245:     } else {
1.596     albertel 3246:       $prevattempts=
                   3247: 	  &start_data_table().&start_data_table_row().
                   3248: 	  '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
                   3249: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3250:     }
                   3251:   } else {
1.596     albertel 3252:     $prevattempts=
                   3253: 	  &start_data_table().&start_data_table_row().
                   3254: 	  '<td>'.&mt('No data.').'</td>'.
                   3255: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3256:   }
1.10      albertel 3257: }
                   3258: 
1.581     albertel 3259: sub format_previous_attempt_value {
                   3260:     my ($key,$value) = @_;
                   3261:     if ($key =~ /timestamp/) {
                   3262: 	$value = &Apache::lonlocal::locallocaltime($value);
                   3263:     } elsif (ref($value) eq 'ARRAY') {
                   3264: 	$value = '('.join(', ', @{ $value }).')';
                   3265:     } else {
                   3266: 	$value = &unescape($value);
                   3267:     }
                   3268:     return $value;
                   3269: }
                   3270: 
                   3271: 
1.107     albertel 3272: sub relative_to_absolute {
                   3273:     my ($url,$output)=@_;
                   3274:     my $parser=HTML::TokeParser->new(\$output);
                   3275:     my $token;
                   3276:     my $thisdir=$url;
                   3277:     my @rlinks=();
                   3278:     while ($token=$parser->get_token) {
                   3279: 	if ($token->[0] eq 'S') {
                   3280: 	    if ($token->[1] eq 'a') {
                   3281: 		if ($token->[2]->{'href'}) {
                   3282: 		    $rlinks[$#rlinks+1]=$token->[2]->{'href'};
                   3283: 		}
                   3284: 	    } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
                   3285: 		$rlinks[$#rlinks+1]=$token->[2]->{'src'};
                   3286: 	    } elsif ($token->[1] eq 'base') {
                   3287: 		$thisdir=$token->[2]->{'href'};
                   3288: 	    }
                   3289: 	}
                   3290:     }
                   3291:     $thisdir=~s-/[^/]*$--;
1.356     albertel 3292:     foreach my $link (@rlinks) {
1.726     raeburn  3293: 	unless (($link=~/^https?\:\/\//i) ||
1.356     albertel 3294: 		($link=~/^\//) ||
                   3295: 		($link=~/^javascript:/i) ||
                   3296: 		($link=~/^mailto:/i) ||
                   3297: 		($link=~/^\#/)) {
                   3298: 	    my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
                   3299: 	    $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107     albertel 3300: 	}
                   3301:     }
                   3302: # -------------------------------------------------- Deal with Applet codebases
                   3303:     $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
                   3304:     return $output;
                   3305: }
                   3306: 
1.112     bowersj2 3307: =pod
                   3308: 
1.648     raeburn  3309: =item * &get_student_view()
1.112     bowersj2 3310: 
                   3311: show a snapshot of what student was looking at
                   3312: 
                   3313: =cut
                   3314: 
1.10      albertel 3315: sub get_student_view {
1.186     albertel 3316:   my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114     www      3317:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3318:   my (%form);
1.10      albertel 3319:   my @elements=('symb','courseid','domain','username');
                   3320:   foreach my $element (@elements) {
1.186     albertel 3321:       $form{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3322:   }
1.186     albertel 3323:   if (defined($moreenv)) {
                   3324:       %form=(%form,%{$moreenv});
                   3325:   }
1.236     albertel 3326:   if (defined($target)) { $form{'grade_target'} = $target; }
1.107     albertel 3327:   $feedurl=&Apache::lonnet::clutter($feedurl);
1.650     www      3328:   my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11      albertel 3329:   $userview=~s/\<body[^\>]*\>//gi;
                   3330:   $userview=~s/\<\/body\>//gi;
                   3331:   $userview=~s/\<html\>//gi;
                   3332:   $userview=~s/\<\/html\>//gi;
                   3333:   $userview=~s/\<head\>//gi;
                   3334:   $userview=~s/\<\/head\>//gi;
                   3335:   $userview=~s/action\s*\=/would_be_action\=/gi;
1.107     albertel 3336:   $userview=&relative_to_absolute($feedurl,$userview);
1.650     www      3337:   if (wantarray) {
                   3338:      return ($userview,$response);
                   3339:   } else {
                   3340:      return $userview;
                   3341:   }
                   3342: }
                   3343: 
                   3344: sub get_student_view_with_retries {
                   3345:   my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
                   3346: 
                   3347:     my $ok = 0;                 # True if we got a good response.
                   3348:     my $content;
                   3349:     my $response;
                   3350: 
                   3351:     # Try to get the student_view done. within the retries count:
                   3352:     
                   3353:     do {
                   3354:          ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
                   3355:          $ok      = $response->is_success;
                   3356:          if (!$ok) {
                   3357:             &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
                   3358:          }
                   3359:          $retries--;
                   3360:     } while (!$ok && ($retries > 0));
                   3361:     
                   3362:     if (!$ok) {
                   3363:        $content = '';          # On error return an empty content.
                   3364:     }
1.651     www      3365:     if (wantarray) {
                   3366:        return ($content, $response);
                   3367:     } else {
                   3368:        return $content;
                   3369:     }
1.11      albertel 3370: }
                   3371: 
1.112     bowersj2 3372: =pod
                   3373: 
1.648     raeburn  3374: =item * &get_student_answers() 
1.112     bowersj2 3375: 
                   3376: show a snapshot of how student was answering problem
                   3377: 
                   3378: =cut
                   3379: 
1.11      albertel 3380: sub get_student_answers {
1.100     sakharuk 3381:   my ($symb,$username,$domain,$courseid,%form) = @_;
1.114     www      3382:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3383:   my (%moreenv);
1.11      albertel 3384:   my @elements=('symb','courseid','domain','username');
                   3385:   foreach my $element (@elements) {
1.186     albertel 3386:     $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3387:   }
1.186     albertel 3388:   $moreenv{'grade_target'}='answer';
                   3389:   %moreenv=(%form,%moreenv);
1.497     raeburn  3390:   $feedurl = &Apache::lonnet::clutter($feedurl);
                   3391:   my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10      albertel 3392:   return $userview;
1.1       albertel 3393: }
1.116     albertel 3394: 
                   3395: =pod
                   3396: 
                   3397: =item * &submlink()
                   3398: 
1.242     albertel 3399: Inputs: $text $uname $udom $symb $target
1.116     albertel 3400: 
                   3401: Returns: A link to grades.pm such as to see the SUBM view of a student
                   3402: 
                   3403: =cut
                   3404: 
                   3405: ###############################################
                   3406: sub submlink {
1.242     albertel 3407:     my ($text,$uname,$udom,$symb,$target)=@_;
1.116     albertel 3408:     if (!($uname && $udom)) {
                   3409: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3410: 	    &Apache::lonnet::whichuser($symb);
1.116     albertel 3411: 	if (!$symb) { $symb=$cursymb; }
                   3412:     }
1.254     matthew  3413:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3414:     $symb=&escape($symb);
1.242     albertel 3415:     if ($target) { $target="target=\"$target\""; }
                   3416:     return '<a href="/adm/grades?&command=submission&'.
                   3417: 	'symb='.$symb.'&student='.$uname.
                   3418: 	'&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
                   3419: }
                   3420: ##############################################
                   3421: 
                   3422: =pod
                   3423: 
                   3424: =item * &pgrdlink()
                   3425: 
                   3426: Inputs: $text $uname $udom $symb $target
                   3427: 
                   3428: Returns: A link to grades.pm such as to see the PGRD view of a student
                   3429: 
                   3430: =cut
                   3431: 
                   3432: ###############################################
                   3433: sub pgrdlink {
                   3434:     my $link=&submlink(@_);
                   3435:     $link=~s/(&command=submission)/$1&showgrading=yes/;
                   3436:     return $link;
                   3437: }
                   3438: ##############################################
                   3439: 
                   3440: =pod
                   3441: 
                   3442: =item * &pprmlink()
                   3443: 
                   3444: Inputs: $text $uname $udom $symb $target
                   3445: 
                   3446: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283     albertel 3447: student and a specific resource
1.242     albertel 3448: 
                   3449: =cut
                   3450: 
                   3451: ###############################################
                   3452: sub pprmlink {
                   3453:     my ($text,$uname,$udom,$symb,$target)=@_;
                   3454:     if (!($uname && $udom)) {
                   3455: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3456: 	    &Apache::lonnet::whichuser($symb);
1.242     albertel 3457: 	if (!$symb) { $symb=$cursymb; }
                   3458:     }
1.254     matthew  3459:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3460:     $symb=&escape($symb);
1.242     albertel 3461:     if ($target) { $target="target=\"$target\""; }
1.595     albertel 3462:     return '<a href="/adm/parmset?command=set&amp;'.
                   3463: 	'symb='.$symb.'&amp;uname='.$uname.
                   3464: 	'&amp;udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116     albertel 3465: }
                   3466: ##############################################
1.37      matthew  3467: 
1.112     bowersj2 3468: =pod
                   3469: 
                   3470: =back
                   3471: 
                   3472: =cut
                   3473: 
1.37      matthew  3474: ###############################################
1.51      www      3475: 
                   3476: 
                   3477: sub timehash {
1.687     raeburn  3478:     my ($thistime) = @_;
                   3479:     my $timezone = &Apache::lonlocal::gettimezone();
                   3480:     my $dt = DateTime->from_epoch(epoch => $thistime)
                   3481:                      ->set_time_zone($timezone);
                   3482:     my $wday = $dt->day_of_week();
                   3483:     if ($wday == 7) { $wday = 0; }
                   3484:     return ( 'second' => $dt->second(),
                   3485:              'minute' => $dt->minute(),
                   3486:              'hour'   => $dt->hour(),
                   3487:              'day'     => $dt->day_of_month(),
                   3488:              'month'   => $dt->month(),
                   3489:              'year'    => $dt->year(),
                   3490:              'weekday' => $wday,
                   3491:              'dayyear' => $dt->day_of_year(),
                   3492:              'dlsav'   => $dt->is_dst() );
1.51      www      3493: }
                   3494: 
1.370     www      3495: sub utc_string {
                   3496:     my ($date)=@_;
1.371     www      3497:     return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370     www      3498: }
                   3499: 
1.51      www      3500: sub maketime {
                   3501:     my %th=@_;
1.687     raeburn  3502:     my ($epoch_time,$timezone,$dt);
                   3503:     $timezone = &Apache::lonlocal::gettimezone();
                   3504:     eval {
                   3505:         $dt = DateTime->new( year   => $th{'year'},
                   3506:                              month  => $th{'month'},
                   3507:                              day    => $th{'day'},
                   3508:                              hour   => $th{'hour'},
                   3509:                              minute => $th{'minute'},
                   3510:                              second => $th{'second'},
                   3511:                              time_zone => $timezone,
                   3512:                          );
                   3513:     };
                   3514:     if (!$@) {
                   3515:         $epoch_time = $dt->epoch;
                   3516:         if ($epoch_time) {
                   3517:             return $epoch_time;
                   3518:         }
                   3519:     }
1.51      www      3520:     return POSIX::mktime(
                   3521:         ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210     www      3522:          $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70      www      3523: }
                   3524: 
                   3525: #########################################
1.51      www      3526: 
                   3527: sub findallcourses {
1.482     raeburn  3528:     my ($roles,$uname,$udom) = @_;
1.355     albertel 3529:     my %roles;
                   3530:     if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348     albertel 3531:     my %courses;
1.51      www      3532:     my $now=time;
1.482     raeburn  3533:     if (!defined($uname)) {
                   3534:         $uname = $env{'user.name'};
                   3535:     }
                   3536:     if (!defined($udom)) {
                   3537:         $udom = $env{'user.domain'};
                   3538:     }
                   3539:     if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
                   3540:         my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
                   3541:         if (!%roles) {
                   3542:             %roles = (
                   3543:                        cc => 1,
                   3544:                        in => 1,
                   3545:                        ep => 1,
                   3546:                        ta => 1,
                   3547:                        cr => 1,
                   3548:                        st => 1,
                   3549:              );
                   3550:         }
                   3551:         foreach my $entry (keys(%roleshash)) {
                   3552:             my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
                   3553:             if ($trole =~ /^cr/) { 
                   3554:                 next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
                   3555:             } else {
                   3556:                 next if (!exists($roles{$trole}));
                   3557:             }
                   3558:             if ($tend) {
                   3559:                 next if ($tend < $now);
                   3560:             }
                   3561:             if ($tstart) {
                   3562:                 next if ($tstart > $now);
                   3563:             }
                   3564:             my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
                   3565:             (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
                   3566:             if ($secpart eq '') {
                   3567:                 ($cnum,$role) = split(/_/,$cnumpart); 
                   3568:                 $sec = 'none';
                   3569:                 $realsec = '';
                   3570:             } else {
                   3571:                 $cnum = $cnumpart;
                   3572:                 ($sec,$role) = split(/_/,$secpart);
                   3573:                 $realsec = $sec;
1.490     raeburn  3574:             }
1.482     raeburn  3575:             $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
                   3576:         }
                   3577:     } else {
                   3578:         foreach my $key (keys(%env)) {
1.483     albertel 3579: 	    if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
                   3580:                  $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482     raeburn  3581: 	        my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
                   3582: 	        next if ($role eq 'ca' || $role eq 'aa');
                   3583: 	        next if (%roles && !exists($roles{$role}));
                   3584: 	        my ($starttime,$endtime)=split(/\./,$env{$key});
                   3585:                 my $active=1;
                   3586:                 if ($starttime) {
                   3587: 		    if ($now<$starttime) { $active=0; }
                   3588:                 }
                   3589:                 if ($endtime) {
                   3590:                     if ($now>$endtime) { $active=0; }
                   3591:                 }
                   3592:                 if ($active) {
                   3593:                     if ($sec eq '') {
                   3594:                         $sec = 'none';
                   3595:                     }
                   3596:                     $courses{$cdom.'_'.$cnum}{$sec} = 
                   3597:                                      $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474     raeburn  3598:                 }
                   3599:             }
1.51      www      3600:         }
                   3601:     }
1.474     raeburn  3602:     return %courses;
1.51      www      3603: }
1.37      matthew  3604: 
1.54      www      3605: ###############################################
1.474     raeburn  3606: 
                   3607: sub blockcheck {
1.482     raeburn  3608:     my ($setters,$activity,$uname,$udom) = @_;
1.490     raeburn  3609: 
                   3610:     if (!defined($udom)) {
                   3611:         $udom = $env{'user.domain'};
                   3612:     }
                   3613:     if (!defined($uname)) {
                   3614:         $uname = $env{'user.name'};
                   3615:     }
                   3616: 
                   3617:     # If uname and udom are for a course, check for blocks in the course.
                   3618: 
                   3619:     if (&Apache::lonnet::is_course($udom,$uname)) {
                   3620:         my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502     raeburn  3621:         my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490     raeburn  3622:         return ($startblock,$endblock);
                   3623:     }
1.474     raeburn  3624: 
1.502     raeburn  3625:     my $startblock = 0;
                   3626:     my $endblock = 0;
1.482     raeburn  3627:     my %live_courses = &findallcourses(undef,$uname,$udom);
1.474     raeburn  3628: 
1.490     raeburn  3629:     # If uname is for a user, and activity is course-specific, i.e.,
                   3630:     # boards, chat or groups, check for blocking in current course only.
1.474     raeburn  3631: 
1.490     raeburn  3632:     if (($activity eq 'boards' || $activity eq 'chat' ||
                   3633:          $activity eq 'groups') && ($env{'request.course.id'})) {
                   3634:         foreach my $key (keys(%live_courses)) {
                   3635:             if ($key ne $env{'request.course.id'}) {
                   3636:                 delete($live_courses{$key});
                   3637:             }
                   3638:         }
                   3639:     }
                   3640: 
                   3641:     my $otheruser = 0;
                   3642:     my %own_courses;
                   3643:     if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
                   3644:         # Resource belongs to user other than current user.
                   3645:         $otheruser = 1;
                   3646:         # Gather courses for current user
                   3647:         %own_courses = 
                   3648:             &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
                   3649:     }
                   3650: 
                   3651:     # Gather active course roles - course coordinator, instructor, 
                   3652:     # exam proctor, ta, student, or custom role.
1.474     raeburn  3653: 
                   3654:     foreach my $course (keys(%live_courses)) {
1.482     raeburn  3655:         my ($cdom,$cnum);
                   3656:         if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
                   3657:             $cdom = $env{'course.'.$course.'.domain'};
                   3658:             $cnum = $env{'course.'.$course.'.num'};
                   3659:         } else {
1.490     raeburn  3660:             ($cdom,$cnum) = split(/_/,$course); 
1.482     raeburn  3661:         }
                   3662:         my $no_ownblock = 0;
                   3663:         my $no_userblock = 0;
1.533     raeburn  3664:         if ($otheruser && $activity ne 'com') {
1.490     raeburn  3665:             # Check if current user has 'evb' priv for this
                   3666:             if (defined($own_courses{$course})) {
                   3667:                 foreach my $sec (keys(%{$own_courses{$course}})) {
                   3668:                     my $checkrole = 'cm./'.$cdom.'/'.$cnum;
                   3669:                     if ($sec ne 'none') {
                   3670:                         $checkrole .= '/'.$sec;
                   3671:                     }
                   3672:                     if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   3673:                         $no_ownblock = 1;
                   3674:                         last;
                   3675:                     }
                   3676:                 }
                   3677:             }
                   3678:             # if they have 'evb' priv and are currently not playing student
                   3679:             next if (($no_ownblock) &&
                   3680:                  ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
                   3681:         }
1.474     raeburn  3682:         foreach my $sec (keys(%{$live_courses{$course}})) {
1.482     raeburn  3683:             my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474     raeburn  3684:             if ($sec ne 'none') {
1.482     raeburn  3685:                 $checkrole .= '/'.$sec;
1.474     raeburn  3686:             }
1.490     raeburn  3687:             if ($otheruser) {
                   3688:                 # Resource belongs to user other than current user.
                   3689:                 # Assemble privs for that user, and check for 'evb' priv.
1.482     raeburn  3690:                 my ($trole,$tdom,$tnum,$tsec);
                   3691:                 my $entry = $live_courses{$course}{$sec};
                   3692:                 if ($entry =~ /^cr/) {
                   3693:                     ($trole,$tdom,$tnum,$tsec) = 
                   3694:                       ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
                   3695:                 } else {
                   3696:                     ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
                   3697:                 }
                   3698:                 my ($spec,$area,$trest,%allroles,%userroles);
                   3699:                 $area = '/'.$tdom.'/'.$tnum;
                   3700:                 $trest = $tnum;
                   3701:                 if ($tsec ne '') {
                   3702:                     $area .= '/'.$tsec;
                   3703:                     $trest .= '/'.$tsec;
                   3704:                 }
                   3705:                 $spec = $trole.'.'.$area;
                   3706:                 if ($trole =~ /^cr/) {
                   3707:                     &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
                   3708:                                                       $tdom,$spec,$trest,$area);
                   3709:                 } else {
                   3710:                     &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
                   3711:                                                        $tdom,$spec,$trest,$area);
                   3712:                 }
                   3713:                 my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486     raeburn  3714:                 if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
                   3715:                     if ($1) {
                   3716:                         $no_userblock = 1;
                   3717:                         last;
                   3718:                     }
                   3719:                 }
1.490     raeburn  3720:             } else {
                   3721:                 # Resource belongs to current user
                   3722:                 # Check for 'evb' priv via lonnet::allowed().
1.482     raeburn  3723:                 if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   3724:                     $no_ownblock = 1;
                   3725:                     last;
                   3726:                 }
1.474     raeburn  3727:             }
                   3728:         }
                   3729:         # if they have the evb priv and are currently not playing student
1.482     raeburn  3730:         next if (($no_ownblock) &&
1.491     albertel 3731:                  ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482     raeburn  3732:         next if ($no_userblock);
1.474     raeburn  3733: 
1.490     raeburn  3734:         # Retrieve blocking times and identity of blocker for course
                   3735:         # of specified user, unless user has 'evb' privilege.
1.502     raeburn  3736:         
                   3737:         my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
                   3738:         if (($start != 0) && 
                   3739:             (($startblock == 0) || ($startblock > $start))) {
                   3740:             $startblock = $start;
                   3741:         }
                   3742:         if (($end != 0)  &&
                   3743:             (($endblock == 0) || ($endblock < $end))) {
                   3744:             $endblock = $end;
                   3745:         }
1.490     raeburn  3746:     }
                   3747:     return ($startblock,$endblock);
                   3748: }
                   3749: 
                   3750: sub get_blocks {
                   3751:     my ($setters,$activity,$cdom,$cnum) = @_;
                   3752:     my $startblock = 0;
                   3753:     my $endblock = 0;
                   3754:     my $course = $cdom.'_'.$cnum;
                   3755:     $setters->{$course} = {};
                   3756:     $setters->{$course}{'staff'} = [];
                   3757:     $setters->{$course}{'times'} = [];
                   3758:     my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
                   3759:     foreach my $record (keys(%records)) {
                   3760:         my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
                   3761:         if ($start <= time && $end >= time) {
                   3762:             my ($staff_name,$staff_dom,$title,$blocks) =
                   3763:                 &parse_block_record($records{$record});
                   3764:             if ($blocks->{$activity} eq 'on') {
                   3765:                 push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
                   3766:                 push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491     albertel 3767:                 if ( ($startblock == 0) || ($startblock > $start) ) {
                   3768:                     $startblock = $start;
1.490     raeburn  3769:                 }
1.491     albertel 3770:                 if ( ($endblock == 0) || ($endblock < $end) ) {
                   3771:                     $endblock = $end;
1.474     raeburn  3772:                 }
                   3773:             }
                   3774:         }
                   3775:     }
                   3776:     return ($startblock,$endblock);
                   3777: }
                   3778: 
                   3779: sub parse_block_record {
                   3780:     my ($record) = @_;
                   3781:     my ($setuname,$setudom,$title,$blocks);
                   3782:     if (ref($record) eq 'HASH') {
                   3783:         ($setuname,$setudom) = split(/:/,$record->{'setter'});
                   3784:         $title = &unescape($record->{'event'});
                   3785:         $blocks = $record->{'blocks'};
                   3786:     } else {
                   3787:         my @data = split(/:/,$record,3);
                   3788:         if (scalar(@data) eq 2) {
                   3789:             $title = $data[1];
                   3790:             ($setuname,$setudom) = split(/@/,$data[0]);
                   3791:         } else {
                   3792:             ($setuname,$setudom,$title) = @data;
                   3793:         }
                   3794:         $blocks = { 'com' => 'on' };
                   3795:     }
                   3796:     return ($setuname,$setudom,$title,$blocks);
                   3797: }
                   3798: 
                   3799: sub build_block_table {
                   3800:     my ($startblock,$endblock,$setters) = @_;
                   3801:     my %lt = &Apache::lonlocal::texthash(
                   3802:         'cacb' => 'Currently active communication blocks',
                   3803:         'cour' => 'Course',
                   3804:         'dura' => 'Duration',
                   3805:         'blse' => 'Block set by'
                   3806:     );
                   3807:     my $output;
1.476     raeburn  3808:     $output = '<br />'.$lt{'cacb'}.':<br />';
1.474     raeburn  3809:     $output .= &start_data_table();
                   3810:     $output .= '
                   3811: <tr>
                   3812:  <th>'.$lt{'cour'}.'</th>
                   3813:  <th>'.$lt{'dura'}.'</th>
                   3814:  <th>'.$lt{'blse'}.'</th>
                   3815: </tr>
                   3816: ';
                   3817:     foreach my $course (keys(%{$setters})) {
                   3818:         my %courseinfo=&Apache::lonnet::coursedescription($course);
                   3819:         for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
                   3820:             my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490     raeburn  3821:             my $fullname = &plainname($uname,$udom);
                   3822:             if (defined($env{'user.name'}) && defined($env{'user.domain'})
                   3823:                 && $env{'user.name'} ne 'public' 
                   3824:                 && $env{'user.domain'} ne 'public') {
                   3825:                 $fullname = &aboutmewrapper($fullname,$uname,$udom);
                   3826:             }
1.474     raeburn  3827:             my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
                   3828:             $openblock = &Apache::lonlocal::locallocaltime($openblock);
                   3829:             $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
                   3830:             $output .= &Apache::loncommon::start_data_table_row().
                   3831:                        '<td>'.$courseinfo{'description'}.'</td>'.
                   3832:                        '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490     raeburn  3833:                        '<td>'.$fullname.'</td>'.
1.474     raeburn  3834:                         &Apache::loncommon::end_data_table_row();
                   3835:         }
                   3836:     }
                   3837:     $output .= &end_data_table();
                   3838: }
                   3839: 
1.490     raeburn  3840: sub blocking_status {
                   3841:     my ($activity,$uname,$udom) = @_;
                   3842:     my %setters;
                   3843:     my ($blocked,$output,$ownitem,$is_course);
                   3844:     my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
                   3845:     if ($startblock && $endblock) {
                   3846:         $blocked = 1;
                   3847:         if (wantarray) {
                   3848:             my $category;
                   3849:             if ($activity eq 'boards') {
                   3850:                 $category = 'Discussion posts in this course';
                   3851:             } elsif ($activity eq 'blogs') {
                   3852:                 $category = 'Blogs';
                   3853:             } elsif ($activity eq 'port') {
                   3854:                 if (defined($uname) && defined($udom)) {
                   3855:                     if ($uname eq $env{'user.name'} &&
                   3856:                         $udom eq $env{'user.domain'}) {
                   3857:                         $ownitem = 1;
                   3858:                     }
                   3859:                 }
                   3860:                 $is_course = &Apache::lonnet::is_course($udom,$uname);
                   3861:                 if ($ownitem) { 
                   3862:                     $category = 'Your portfolio files';  
                   3863:                 } elsif ($is_course) {
                   3864:                     my $coursedesc;
                   3865:                     foreach my $course (keys(%setters)) {
                   3866:                         my %courseinfo =
                   3867:                              &Apache::lonnet::coursedescription($course);
                   3868:                         $coursedesc = $courseinfo{'description'};
                   3869:                     }
1.764     weissno  3870:                     $category = "Group portfolio in the course '$coursedesc'";
1.490     raeburn  3871:                 } else {
                   3872:                     $category = 'Portfolio files belonging to ';
                   3873:                     if ($env{'user.name'} eq 'public' && 
                   3874:                         $env{'user.domain'} eq 'public') {
                   3875:                         $category .= &plainname($uname,$udom);
                   3876:                     } else {
                   3877:                         $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);  
                   3878:                     }
                   3879:                 }
                   3880:             } elsif ($activity eq 'groups') {
                   3881:                 $category = 'Groups in this course';
                   3882:             }
                   3883:             my $showstart = &Apache::lonlocal::locallocaltime($startblock);
                   3884:             my $showend = &Apache::lonlocal::locallocaltime($endblock);
                   3885:             $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
                   3886:             if (!($activity eq 'port' && !($ownitem) && !($is_course))) { 
                   3887:                 $output .= &build_block_table($startblock,$endblock,\%setters);
                   3888:             }
                   3889:         }
                   3890:     }
                   3891:     if (wantarray) {
                   3892:         return ($blocked,$output);
                   3893:     } else {
                   3894:         return $blocked;
                   3895:     }
                   3896: }
                   3897: 
1.60      matthew  3898: ###############################################
                   3899: 
1.682     raeburn  3900: sub check_ip_acc {
                   3901:     my ($acc)=@_;
                   3902:     &Apache::lonxml::debug("acc is $acc");
                   3903:     if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
                   3904:         return 1;
                   3905:     }
                   3906:     my $allowed=0;
                   3907:     my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
                   3908: 
                   3909:     my $name;
                   3910:     foreach my $pattern (split(',',$acc)) {
                   3911:         $pattern =~ s/^\s*//;
                   3912:         $pattern =~ s/\s*$//;
                   3913:         if ($pattern =~ /\*$/) {
                   3914:             #35.8.*
                   3915:             $pattern=~s/\*//;
                   3916:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   3917:         } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
                   3918:             #35.8.3.[34-56]
                   3919:             my $low=$2;
                   3920:             my $high=$3;
                   3921:             $pattern=$1;
                   3922:             if ($ip =~ /^\Q$pattern\E/) {
                   3923:                 my $last=(split(/\./,$ip))[3];
                   3924:                 if ($last <=$high && $last >=$low) { $allowed=1; }
                   3925:             }
                   3926:         } elsif ($pattern =~ /^\*/) {
                   3927:             #*.msu.edu
                   3928:             $pattern=~s/\*//;
                   3929:             if (!defined($name)) {
                   3930:                 use Socket;
                   3931:                 my $netaddr=inet_aton($ip);
                   3932:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   3933:             }
                   3934:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   3935:         } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
                   3936:             #127.0.0.1
                   3937:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   3938:         } else {
                   3939:             #some.name.com
                   3940:             if (!defined($name)) {
                   3941:                 use Socket;
                   3942:                 my $netaddr=inet_aton($ip);
                   3943:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   3944:             }
                   3945:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   3946:         }
                   3947:         if ($allowed) { last; }
                   3948:     }
                   3949:     return $allowed;
                   3950: }
                   3951: 
                   3952: ###############################################
                   3953: 
1.60      matthew  3954: =pod
                   3955: 
1.112     bowersj2 3956: =head1 Domain Template Functions
                   3957: 
                   3958: =over 4
                   3959: 
                   3960: =item * &determinedomain()
1.60      matthew  3961: 
                   3962: Inputs: $domain (usually will be undef)
                   3963: 
1.63      www      3964: Returns: Determines which domain should be used for designs
1.60      matthew  3965: 
                   3966: =cut
1.54      www      3967: 
1.60      matthew  3968: ###############################################
1.63      www      3969: sub determinedomain {
                   3970:     my $domain=shift;
1.531     albertel 3971:     if (! $domain) {
1.60      matthew  3972:         # Determine domain if we have not been given one
                   3973:         $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258     albertel 3974:         if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
                   3975:         if ($env{'request.role.domain'}) { 
                   3976:             $domain=$env{'request.role.domain'}; 
1.60      matthew  3977:         }
                   3978:     }
1.63      www      3979:     return $domain;
                   3980: }
                   3981: ###############################################
1.517     raeburn  3982: 
1.518     albertel 3983: sub devalidate_domconfig_cache {
                   3984:     my ($udom)=@_;
                   3985:     &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
                   3986: }
                   3987: 
                   3988: # ---------------------- Get domain configuration for a domain
                   3989: sub get_domainconf {
                   3990:     my ($udom) = @_;
                   3991:     my $cachetime=1800;
                   3992:     my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
                   3993:     if (defined($cached)) { return %{$result}; }
                   3994: 
                   3995:     my %domconfig = &Apache::lonnet::get_dom('configuration',
                   3996: 					     ['login','rolecolors'],$udom);
1.632     raeburn  3997:     my (%designhash,%legacy);
1.518     albertel 3998:     if (keys(%domconfig) > 0) {
                   3999:         if (ref($domconfig{'login'}) eq 'HASH') {
1.632     raeburn  4000:             if (keys(%{$domconfig{'login'}})) {
                   4001:                 foreach my $key (keys(%{$domconfig{'login'}})) {
1.699     raeburn  4002:                     if (ref($domconfig{'login'}{$key}) eq 'HASH') {
                   4003:                         foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
                   4004:                             $designhash{$udom.'.login.'.$key.'_'.$img} = 
                   4005:                                 $domconfig{'login'}{$key}{$img};
                   4006:                         }
                   4007:                     } else {
                   4008:                         $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
                   4009:                     }
1.632     raeburn  4010:                 }
                   4011:             } else {
                   4012:                 $legacy{'login'} = 1;
1.518     albertel 4013:             }
1.632     raeburn  4014:         } else {
                   4015:             $legacy{'login'} = 1;
1.518     albertel 4016:         }
                   4017:         if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632     raeburn  4018:             if (keys(%{$domconfig{'rolecolors'}})) {
                   4019:                 foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
                   4020:                     if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
                   4021:                         foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
                   4022:                             $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
                   4023:                         }
1.518     albertel 4024:                     }
                   4025:                 }
1.632     raeburn  4026:             } else {
                   4027:                 $legacy{'rolecolors'} = 1;
1.518     albertel 4028:             }
1.632     raeburn  4029:         } else {
                   4030:             $legacy{'rolecolors'} = 1;
1.518     albertel 4031:         }
1.632     raeburn  4032:         if (keys(%legacy) > 0) {
                   4033:             my %legacyhash = &get_legacy_domconf($udom);
                   4034:             foreach my $item (keys(%legacyhash)) {
                   4035:                 if ($item =~ /^\Q$udom\E\.login/) {
                   4036:                     if ($legacy{'login'}) { 
                   4037:                         $designhash{$item} = $legacyhash{$item};
                   4038:                     }
                   4039:                 } else {
                   4040:                     if ($legacy{'rolecolors'}) {
                   4041:                         $designhash{$item} = $legacyhash{$item};
                   4042:                     }
1.518     albertel 4043:                 }
                   4044:             }
                   4045:         }
1.632     raeburn  4046:     } else {
                   4047:         %designhash = &get_legacy_domconf($udom); 
1.518     albertel 4048:     }
                   4049:     &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
                   4050: 				  $cachetime);
                   4051:     return %designhash;
                   4052: }
                   4053: 
1.632     raeburn  4054: sub get_legacy_domconf {
                   4055:     my ($udom) = @_;
                   4056:     my %legacyhash;
                   4057:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
                   4058:     my $designfile =  $designdir.'/'.$udom.'.tab';
                   4059:     if (-e $designfile) {
                   4060:         if ( open (my $fh,"<$designfile") ) {
                   4061:             while (my $line = <$fh>) {
                   4062:                 next if ($line =~ /^\#/);
                   4063:                 chomp($line);
                   4064:                 my ($key,$val)=(split(/\=/,$line));
                   4065:                 if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
                   4066:             }
                   4067:             close($fh);
                   4068:         }
                   4069:     }
                   4070:     if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
                   4071:         $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
                   4072:     }
                   4073:     return %legacyhash;
                   4074: }
                   4075: 
1.63      www      4076: =pod
                   4077: 
1.112     bowersj2 4078: =item * &domainlogo()
1.63      www      4079: 
                   4080: Inputs: $domain (usually will be undef)
                   4081: 
                   4082: Returns: A link to a domain logo, if the domain logo exists.
                   4083: If the domain logo does not exist, a description of the domain.
                   4084: 
                   4085: =cut
1.112     bowersj2 4086: 
1.63      www      4087: ###############################################
                   4088: sub domainlogo {
1.517     raeburn  4089:     my $domain = &determinedomain(shift);
1.518     albertel 4090:     my %designhash = &get_domainconf($domain);    
1.517     raeburn  4091:     # See if there is a logo
                   4092:     if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519     raeburn  4093:         my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538     albertel 4094:         if ($imgsrc =~ m{^/(adm|res)/}) {
                   4095: 	    if ($imgsrc =~ m{^/res/}) {
                   4096: 		my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
                   4097: 		&Apache::lonnet::repcopy($local_name);
                   4098: 	    }
                   4099: 	   $imgsrc = &lonhttpdurl($imgsrc);
1.519     raeburn  4100:         } 
                   4101:         return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514     albertel 4102:     } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
                   4103:         return &Apache::lonnet::domain($domain,'description');
1.59      www      4104:     } else {
1.60      matthew  4105:         return '';
1.59      www      4106:     }
                   4107: }
1.63      www      4108: ##############################################
                   4109: 
                   4110: =pod
                   4111: 
1.112     bowersj2 4112: =item * &designparm()
1.63      www      4113: 
                   4114: Inputs: $which parameter; $domain (usually will be undef)
                   4115: 
                   4116: Returns: value of designparamter $which
                   4117: 
                   4118: =cut
1.112     bowersj2 4119: 
1.397     albertel 4120: 
1.400     albertel 4121: ##############################################
1.397     albertel 4122: sub designparm {
                   4123:     my ($which,$domain)=@_;
1.258     albertel 4124:     if ($env{'browser.blackwhite'} eq 'on') {
1.635     raeburn  4125: 	if ($which=~/\.(font|alink|vlink|link|textcol)$/) {
1.110     www      4126: 	    return '#000000';
                   4127: 	}
1.635     raeburn  4128: 	if ($which=~/\.(pgbg|sidebg|bgcol)$/) {
1.110     www      4129: 	    return '#FFFFFF';
                   4130: 	}
                   4131: 	if ($which=~/\.tabbg$/) {
                   4132: 	    return '#CCCCCC';
                   4133: 	}
                   4134:     }
1.397     albertel 4135:     if (exists($env{'environment.color.'.$which})) {
1.258     albertel 4136: 	return $env{'environment.color.'.$which};
1.96      www      4137:     }
1.63      www      4138:     $domain=&determinedomain($domain);
1.518     albertel 4139:     my %domdesign = &get_domainconf($domain);
1.520     raeburn  4140:     my $output;
1.517     raeburn  4141:     if ($domdesign{$domain.'.'.$which} ne '') {
1.520     raeburn  4142: 	$output = $domdesign{$domain.'.'.$which};
1.63      www      4143:     } else {
1.520     raeburn  4144:         $output = $defaultdesign{$which};
                   4145:     }
                   4146:     if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635     raeburn  4147:         ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538     albertel 4148:         if ($output =~ m{^/(adm|res)/}) {
                   4149: 	    if ($output =~ m{^/res/}) {
                   4150: 		my $local_name = &Apache::lonnet::filelocation('',$output);
                   4151: 		&Apache::lonnet::repcopy($local_name);
                   4152: 	    }
1.520     raeburn  4153:             $output = &lonhttpdurl($output);
                   4154:         }
1.63      www      4155:     }
1.520     raeburn  4156:     return $output;
1.63      www      4157: }
1.59      www      4158: 
1.60      matthew  4159: ###############################################
                   4160: ###############################################
                   4161: 
                   4162: =pod
                   4163: 
1.112     bowersj2 4164: =back
                   4165: 
1.549     albertel 4166: =head1 HTML Helpers
1.112     bowersj2 4167: 
                   4168: =over 4
                   4169: 
                   4170: =item * &bodytag()
1.60      matthew  4171: 
                   4172: Returns a uniform header for LON-CAPA web pages.
                   4173: 
                   4174: Inputs: 
                   4175: 
1.112     bowersj2 4176: =over 4
                   4177: 
                   4178: =item * $title, A title to be displayed on the page.
                   4179: 
                   4180: =item * $function, the current role (can be undef).
                   4181: 
                   4182: =item * $addentries, extra parameters for the <body> tag.
                   4183: 
                   4184: =item * $bodyonly, if defined, only return the <body> tag.
                   4185: 
                   4186: =item * $domain, if defined, force a given domain.
                   4187: 
                   4188: =item * $forcereg, if page should register as content page (relevant for 
1.86      www      4189:             text interface only)
1.60      matthew  4190: 
1.326     albertel 4191: =item * $customtitle, alternate text to use instead of $title
                   4192:                       in the title box that appears, this text
                   4193:                       is not auto translated like the $title is
1.309     albertel 4194: 
                   4195: =item * $notopbar, if true, keep the 'what is this' info but remove the
                   4196:                    navigational links
1.317     albertel 4197: 
1.338     albertel 4198: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
                   4199: 
                   4200: =item * $notitle, if true keep the nav controls, but remove the title bar
                   4201: 
1.361     albertel 4202: =item * $no_inline_link, if true and in remote mode, don't show the 
                   4203:          'Switch To Inline Menu' link
                   4204: 
1.460     albertel 4205: =item * $args, optional argument valid values are
                   4206:             no_auto_mt_title -> prevents &mt()ing the title arg
1.562     albertel 4207:             inherit_jsmath -> when creating popup window in a page,
                   4208:                               should it have jsmath forced on by the
                   4209:                               current page
1.460     albertel 4210: 
1.112     bowersj2 4211: =back
                   4212: 
1.60      matthew  4213: Returns: A uniform header for LON-CAPA web pages.  
                   4214: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
                   4215: If $bodyonly is undef or zero, an html string containing a <body> tag and 
                   4216: other decorations will be returned.
                   4217: 
                   4218: =cut
                   4219: 
1.54      www      4220: sub bodytag {
1.309     albertel 4221:     my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
1.460     albertel 4222: 	$notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
1.339     albertel 4223: 
1.460     albertel 4224:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339     albertel 4225: 
1.183     matthew  4226:     $function = &get_users_function() if (!$function);
1.339     albertel 4227:     my $img =    &designparm($function.'.img',$domain);
                   4228:     my $font =   &designparm($function.'.font',$domain);
                   4229:     my $pgbg   = $bgcolor || &designparm($function.'.pgbg',$domain);
                   4230: 
                   4231:     my %design = ( 'style'   => 'margin-top: 0px',
1.535     albertel 4232: 		   'bgcolor' => $pgbg,
1.339     albertel 4233: 		   'text'    => $font,
                   4234:                    'alink'   => &designparm($function.'.alink',$domain),
                   4235: 		   'vlink'   => &designparm($function.'.vlink',$domain),
                   4236: 		   'link'    => &designparm($function.'.link',$domain),);
1.438     albertel 4237:     @design{keys(%$addentries)} = @$addentries{keys(%$addentries)}; 
1.339     albertel 4238: 
1.63      www      4239:  # role and realm
1.378     raeburn  4240:     my ($role,$realm) = split(/\./,$env{'request.role'},2);
                   4241:     if ($role  eq 'ca') {
1.479     albertel 4242:         my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500     albertel 4243:         $realm = &plainname($rname,$rdom);
1.378     raeburn  4244:     } 
1.55      www      4245: # realm
1.258     albertel 4246:     if ($env{'request.course.id'}) {
1.378     raeburn  4247:         if ($env{'request.role'} !~ /^cr/) {
                   4248:             $role = &Apache::lonnet::plaintext($role,&course_type());
                   4249:         }
1.359     albertel 4250: 	$realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378     raeburn  4251:     } else {
                   4252:         $role = &Apache::lonnet::plaintext($role);
1.54      www      4253:     }
1.433     albertel 4254: 
1.359     albertel 4255:     if (!$realm) { $realm='&nbsp;'; }
1.55      www      4256: # Set messages
1.60      matthew  4257:     my $messages=&domainlogo($domain);
1.330     albertel 4258: 
1.438     albertel 4259:     my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329     albertel 4260: 
1.101     www      4261: # construct main body tag
1.359     albertel 4262:     my $bodytag = "<body $extra_body_attr>".
1.562     albertel 4263: 	&Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252     albertel 4264: 
1.530     albertel 4265:     if ($bodyonly) {
1.60      matthew  4266:         return $bodytag;
1.798     tempelho 4267:     } 
1.359     albertel 4268: 
1.410     albertel 4269:     my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433     albertel 4270:     if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
                   4271: 	undef($role);
1.434     albertel 4272:     } else {
                   4273: 	$name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433     albertel 4274:     }
1.359     albertel 4275:     
                   4276:     my $roleinfo=(<<ENDROLE);
                   4277: <td class="LC_title_bar_who">
                   4278: <div class="LC_title_bar_name">
1.410     albertel 4279:     $name
1.361     albertel 4280:     &nbsp;
1.359     albertel 4281: </div>
                   4282: <div class="LC_title_bar_role">
1.361     albertel 4283: $role&nbsp;
1.359     albertel 4284: </div>
                   4285: <div class="LC_title_bar_realm">
1.361     albertel 4286: $realm&nbsp;
1.359     albertel 4287: </div>
1.206     albertel 4288: </td>
                   4289: ENDROLE
1.235     raeburn  4290: 
1.762     bisitz   4291:     my $titleinfo = '<h1>'.$title.'</h1>';
1.359     albertel 4292:     if ($customtitle) {
                   4293:         $titleinfo = $customtitle;
                   4294:     }
                   4295:     #
                   4296:     # Extra info if you are the DC
                   4297:     my $dc_info = '';
                   4298:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   4299:                         $env{'course.'.$env{'request.course.id'}.
                   4300:                                  '.domain'}.'/'})) {
                   4301:         my $cid = $env{'request.course.id'};
                   4302:         $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380     www      4303:         $dc_info =~ s/\s+$//;
1.359     albertel 4304:         $dc_info = '('.$dc_info.')';
                   4305:     }
                   4306: 
1.644     www      4307:     if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) {
1.359     albertel 4308:         # No Remote
1.258     albertel 4309: 	if ($env{'request.state'} eq 'construct') {
1.359     albertel 4310: 	    $forcereg=1;
                   4311: 	}
                   4312: 
                   4313: 	if (!$customtitle && $env{'request.state'} eq 'construct') {
                   4314: 	    # this is for resources; directories have customtitle, and crumbs
                   4315:             # and select recent are created in lonpubdir.pm  
1.229     albertel 4316: 	    my ($uname,$thisdisfn)=
1.258     albertel 4317: 		($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
1.229     albertel 4318: 	    my $formaction='/priv/'.$uname.'/'.$thisdisfn;
                   4319: 	    $formaction=~s/\/+/\//g;
                   4320: 
1.359     albertel 4321: 	    my $parentpath = '';
                   4322: 	    my $lastitem = '';
                   4323: 	    if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
                   4324: 		$parentpath = $1;
                   4325: 		$lastitem = $2;
                   4326: 	    } else {
                   4327: 		$lastitem = $thisdisfn;
                   4328: 	    }
                   4329: 	    $titleinfo = 
1.640     bisitz   4330: 		&Apache::loncommon::help_open_menu('','',3,'Authoring')
                   4331: 		.'<b>'.&mt('Construction Space').'</b>:&nbsp;'
                   4332: 		.'<form name="dirs" method="post" action="'.$formaction
1.359     albertel 4333: 		.'" target="_top"><tt><b>'
1.705     tempelho 4334: 		.&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<span class=\"LC_fontsize_big\">$lastitem</span></b></tt><br />"
1.359     albertel 4335: 		.&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
                   4336: 		.'</form>'
                   4337: 		.&Apache::lonmenu::constspaceform();
1.235     raeburn  4338:         }
1.359     albertel 4339: 
1.337     albertel 4340:         my $titletable;
1.338     albertel 4341: 	if (!$notitle) {
1.337     albertel 4342: 	    $titletable =
1.359     albertel 4343: 		'<table id="LC_title_bar">'.
                   4344:                          "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
                   4345: 			 '</tr></table>';
1.337     albertel 4346: 	}
1.359     albertel 4347: 	if ($notopbar) {
                   4348: 	    $bodytag .= $titletable;
                   4349: 	} else {
                   4350: 	    if ($env{'request.state'} eq 'construct') {
1.337     albertel 4351:                 $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
                   4352: 							  $titletable);
1.272     raeburn  4353:             } else {
1.336     albertel 4354:                 $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
1.359     albertel 4355: 		    $titletable;
1.272     raeburn  4356:             }
1.235     raeburn  4357:         }
                   4358:         return $bodytag;
1.94      www      4359:     }
1.95      www      4360: 
1.93      www      4361: #
1.95      www      4362: # Top frame rendering, Remote is up
1.93      www      4363: #
1.359     albertel 4364: 
1.517     raeburn  4365:     my $imgsrc = $img;
                   4366:     if ($img =~ /^\/adm/) {
1.575     albertel 4367:         $imgsrc = &lonhttpdurl($img);
1.517     raeburn  4368:     }
                   4369:     my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359     albertel 4370: 
1.305     www      4371:     # Explicit link to get inline menu
1.361     albertel 4372:     my $menu= ($no_inline_link?''
                   4373: 	       :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
1.245     matthew  4374:     #
1.338     albertel 4375:     if ($notitle) {
1.337     albertel 4376: 	return $bodytag;
                   4377:     }
1.94      www      4378:     return(<<ENDBODY);
1.60      matthew  4379: $bodytag
1.359     albertel 4380: <table id="LC_title_bar" class="LC_with_remote">
1.791     tempelho 4381: <tr><td>$upperleft</td>
                   4382:     <td>$messages&nbsp;</td>
1.54      www      4383: </tr>
1.359     albertel 4384: <tr><td>$titleinfo $dc_info $menu</td>
                   4385: $roleinfo
1.368     albertel 4386: </tr>
1.356     albertel 4387: </table>
1.54      www      4388: ENDBODY
1.182     matthew  4389: }
                   4390: 
1.330     albertel 4391: sub make_attr_string {
                   4392:     my ($register,$attr_ref) = @_;
                   4393: 
                   4394:     if ($attr_ref && !ref($attr_ref)) {
                   4395: 	die("addentries Must be a hash ref ".
                   4396: 	    join(':',caller(1))." ".
                   4397: 	    join(':',caller(0))." ");
                   4398:     }
                   4399: 
                   4400:     if ($register) {
1.339     albertel 4401: 	my ($on_load,$on_unload);
                   4402: 	foreach my $key (keys(%{$attr_ref})) {
                   4403: 	    if      (lc($key) eq 'onload') {
                   4404: 		$on_load.=$attr_ref->{$key}.';';
                   4405: 		delete($attr_ref->{$key});
                   4406: 
                   4407: 	    } elsif (lc($key) eq 'onunload') {
                   4408: 		$on_unload.=$attr_ref->{$key}.';';
                   4409: 		delete($attr_ref->{$key});
                   4410: 	    }
                   4411: 	}
                   4412: 	$attr_ref->{'onload'}  =
                   4413: 	    &Apache::lonmenu::loadevents().  $on_load;
                   4414: 	$attr_ref->{'onunload'}=
                   4415: 	    &Apache::lonmenu::unloadevents().$on_unload;
                   4416:     }
                   4417: 
                   4418: # Accessibility font enhance
                   4419:     if ($env{'browser.fontenhance'} eq 'on') {
                   4420: 	my $style;
                   4421: 	foreach my $key (keys(%{$attr_ref})) {
                   4422: 	    if (lc($key) eq 'style') {
                   4423: 		$style.=$attr_ref->{$key}.';';
                   4424: 		delete($attr_ref->{$key});
                   4425: 	    }
                   4426: 	}
                   4427: 	$attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330     albertel 4428:     }
1.339     albertel 4429: 
                   4430:     if ($env{'browser.blackwhite'} eq 'on') {
                   4431: 	delete($attr_ref->{'font'});
                   4432: 	delete($attr_ref->{'link'});
                   4433: 	delete($attr_ref->{'alink'});
                   4434: 	delete($attr_ref->{'vlink'});
                   4435: 	delete($attr_ref->{'bgcolor'});
                   4436: 	delete($attr_ref->{'background'});
                   4437:     }
                   4438: 
1.330     albertel 4439:     my $attr_string;
                   4440:     foreach my $attr (keys(%$attr_ref)) {
                   4441: 	$attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
                   4442:     }
                   4443:     return $attr_string;
                   4444: }
                   4445: 
                   4446: 
1.182     matthew  4447: ###############################################
1.251     albertel 4448: ###############################################
                   4449: 
                   4450: =pod
                   4451: 
                   4452: =item * &endbodytag()
                   4453: 
                   4454: Returns a uniform footer for LON-CAPA web pages.
                   4455: 
1.635     raeburn  4456: Inputs: 1 - optional reference to an args hash
                   4457: If in the hash, key for noredirectlink has a value which evaluates to true,
                   4458: a 'Continue' link is not displayed if the page contains an
                   4459: internal redirect in the <head></head> section,
                   4460: i.e., $env{'internal.head.redirect'} exists   
1.251     albertel 4461: 
                   4462: =cut
                   4463: 
                   4464: sub endbodytag {
1.635     raeburn  4465:     my ($args) = @_;
1.251     albertel 4466:     my $endbodytag='</body>';
1.269     albertel 4467:     $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315     albertel 4468:     if ( exists( $env{'internal.head.redirect'} ) ) {
1.635     raeburn  4469:         if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
                   4470: 	    $endbodytag=
                   4471: 	        "<br /><a href=\"$env{'internal.head.redirect'}\">".
                   4472: 	        &mt('Continue').'</a>'.
                   4473: 	        $endbodytag;
                   4474:         }
1.315     albertel 4475:     }
1.251     albertel 4476:     return $endbodytag;
                   4477: }
                   4478: 
1.352     albertel 4479: =pod
                   4480: 
                   4481: =item * &standard_css()
                   4482: 
                   4483: Returns a style sheet
                   4484: 
                   4485: Inputs: (all optional)
                   4486:             domain         -> force to color decorate a page for a specific
                   4487:                                domain
                   4488:             function       -> force usage of a specific rolish color scheme
                   4489:             bgcolor        -> override the default page bgcolor
                   4490: 
                   4491: =cut
                   4492: 
1.343     albertel 4493: sub standard_css {
1.345     albertel 4494:     my ($function,$domain,$bgcolor) = @_;
1.352     albertel 4495:     $function  = &get_users_function() if (!$function);
                   4496:     my $img    = &designparm($function.'.img',   $domain);
                   4497:     my $tabbg  = &designparm($function.'.tabbg', $domain);
                   4498:     my $font   = &designparm($function.'.font',  $domain);
1.801   ! tempelho 4499:     my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791     tempelho 4500: #second colour for later usage
1.345     albertel 4501:     my $sidebg = &designparm($function.'.sidebg',$domain);
1.382     albertel 4502:     my $pgbg_or_bgcolor =
                   4503: 	         $bgcolor ||
1.352     albertel 4504: 	         &designparm($function.'.pgbg',  $domain);
1.382     albertel 4505:     my $pgbg   = &designparm($function.'.pgbg',  $domain);
1.352     albertel 4506:     my $alink  = &designparm($function.'.alink', $domain);
                   4507:     my $vlink  = &designparm($function.'.vlink', $domain);
                   4508:     my $link   = &designparm($function.'.link',  $domain);
                   4509: 
1.704     muellerd 4510:     my $loginbg = &designparm('login.sidebg',$domain);
1.712     muellerd 4511:     my $bgcol = &designparm('login.bgcol',$domain);
                   4512:     my $textcol = &designparm('login.textcol',$domain);
1.704     muellerd 4513: 
1.602     albertel 4514:     my $sans                 = 'Verdana,Arial,Helvetica,sans-serif';
1.395     albertel 4515:     my $mono                 = 'monospace';
1.352     albertel 4516:     my $data_table_head      = $tabbg;
                   4517:     my $data_table_light     = '#EEEEEE';
1.470     banghart 4518:     my $data_table_dark      = '#DDDDDD';
                   4519:     my $data_table_darker    = '#CCCCCC';
1.349     albertel 4520:     my $data_table_highlight = '#FFFF00';
1.352     albertel 4521:     my $mail_new             = '#FFBB77';
                   4522:     my $mail_new_hover       = '#DD9955';
                   4523:     my $mail_read            = '#BBBB77';
                   4524:     my $mail_read_hover      = '#999944';
                   4525:     my $mail_replied         = '#AAAA88';
                   4526:     my $mail_replied_hover   = '#888855';
                   4527:     my $mail_other           = '#99BBBB';
                   4528:     my $mail_other_hover     = '#669999';
1.391     albertel 4529:     my $table_header         = '#DDDDDD';
1.489     raeburn  4530:     my $feedback_link_bg     = '#BBBBBB';
1.701     harmsja  4531:     my $lg_border_color	     = '#C8C8C8';
1.392     albertel 4532: 
1.608     albertel 4533:     my $border = ($env{'browser.type'} eq 'explorer' ||
                   4534: 		  $env{'browser.type'} eq 'safari'     ) ? '0px 2px 0px 2px'
                   4535: 	                                                 : '0px 3px 0px 4px';
1.448     albertel 4536: 
1.523     albertel 4537: 
1.343     albertel 4538:     return <<END;
1.795     www      4539: body {
                   4540:    font-family: $sans;
                   4541:    line-height:130%;
                   4542:    font-size:0.83em;
                   4543:    color:$font;
                   4544: }
                   4545: 
                   4546: a:link, a:visited { 
                   4547:   font-size:100%; 
                   4548: }
                   4549: 
                   4550: a:focus { 
                   4551:   color: red;
                   4552:   background: yellow 
                   4553: }
1.698     harmsja  4554: 
1.510     albertel 4555: table.thinborder,
                   4556: table.thinborder tr th {
                   4557:   border-style: solid;
                   4558:   border-width: 1px;
1.698     harmsja  4559:   border-color: $lg_border_color;
1.510     albertel 4560:   background: $tabbg;
                   4561: }
1.795     www      4562: 
1.523     albertel 4563: table.thinborder tr td {
1.510     albertel 4564:   border-style: solid;
1.698     harmsja  4565:   border-width: 1px;
                   4566:   border-color: $lg_border_color;
1.510     albertel 4567: }
1.426     albertel 4568: 
1.795     www      4569: form, .inline { 
                   4570:    display: inline; 
                   4571: }
1.721     harmsja  4572: 
1.795     www      4573: .LC_right {
                   4574:    text-align:right;
                   4575: }
                   4576: 
                   4577: .LC_middle {
                   4578:    vertical-align:middle;
                   4579: }
1.721     harmsja  4580: 
                   4581: /* just for tests */
1.754     droeschl 4582: .LC_400Box {width:400px; }
1.721     harmsja  4583: /* end */
                   4584: 
1.778     bisitz   4585: .LC_filename {
                   4586:   font-family: $mono;
                   4587:   white-space:pre;
                   4588: }
                   4589: 
                   4590: .LC_fileicon {
                   4591:   border: none;
                   4592:   height: 1.3em;
                   4593:   vertical-align: text-bottom;
                   4594:   margin-right: 0.3em;
                   4595:   text-decoration:none;
                   4596: }
                   4597: 
1.350     albertel 4598: .LC_error {
                   4599:   color: red;
                   4600:   font-size: larger;
                   4601: }
1.795     www      4602: 
1.457     albertel 4603: .LC_warning,
                   4604: .LC_diff_removed {
1.733     bisitz   4605:   color: red;
1.394     albertel 4606: }
1.532     albertel 4607: 
                   4608: .LC_info,
1.457     albertel 4609: .LC_success,
                   4610: .LC_diff_added {
1.350     albertel 4611:   color: green;
                   4612: }
1.795     www      4613: 
1.543     albertel 4614: .LC_unknown {
                   4615:   color: yellow;
                   4616: }
                   4617: 
1.440     albertel 4618: .LC_icon {
1.771     droeschl 4619:   border: none;
1.790     droeschl 4620:   vertical-align: middle;
1.771     droeschl 4621: }
                   4622: 
1.539     albertel 4623: .LC_indexer_icon {
                   4624:   border: 0px;
                   4625:   height: 22px;
                   4626: }
1.795     www      4627: 
1.543     albertel 4628: .LC_docs_spacer {
                   4629:   width: 25px;
                   4630:   height: 1px;
1.771     droeschl 4631:   border: none;
1.543     albertel 4632: }
1.346     albertel 4633: 
1.532     albertel 4634: .LC_internal_info {
1.735     bisitz   4635:   color: #999999;
1.532     albertel 4636: }
                   4637: 
1.794     www      4638: .LC_discussion {
                   4639:    background: $tabbg;
                   4640:    border: 1px solid black;
                   4641:    margin: 2px;
                   4642: }
                   4643: 
                   4644: .LC_disc_action_links_bar {
                   4645:    background: $tabbg;
                   4646:    font-family: $sans;
                   4647:    border: 0px;
1.795     www      4648:    margin: 4px;
1.794     www      4649: }
                   4650: 
                   4651: .LC_disc_action_left {
                   4652:    text-align: left;
                   4653: }
                   4654: 
                   4655: .LC_disc_action_right {
                   4656:    text-align: right;
                   4657: }
                   4658: 
                   4659: .LC_disc_new_item {
                   4660:    background: white;
                   4661:    border: 2px solid red;
                   4662:    margin: 2px;
                   4663: }
                   4664: 
                   4665: .LC_disc_old_item {
                   4666:    background: white;
                   4667:    border: 1px solid black;
                   4668:    margin: 2px;
                   4669: }
                   4670: 
1.458     albertel 4671: table.LC_pastsubmission {
                   4672:   border: 1px solid black;
                   4673:   margin: 2px;
                   4674: }
                   4675: 
1.795     www      4676: table#LC_top_nav,
                   4677: table#LC_menubuttons,
                   4678: table#LC_nav_location {
1.345     albertel 4679:   width: 100%;
                   4680:   background: $pgbg;
1.392     albertel 4681:   border: 2px;
1.402     albertel 4682:   border-collapse: separate;
1.403     albertel 4683:   padding: 0px;
1.345     albertel 4684: }
1.392     albertel 4685: 
1.801   ! tempelho 4686: table#LC_title_bar a {
        !          4687:   color: $fontmenu;
        !          4688: }
        !          4689: 
1.795     www      4690: table#LC_title_bar,
                   4691: table.LC_breadcrumbs,
1.393     albertel 4692: table#LC_title_bar.LC_with_remote {
1.359     albertel 4693:   width: 100%;
1.392     albertel 4694:   border-color: $pgbg;
                   4695:   border-style: solid;
                   4696:   border-width: $border;
1.379     albertel 4697:   background: $pgbg;
1.801   ! tempelho 4698:   color: $fontmenu;
1.379     albertel 4699:   font-family: $sans;
1.392     albertel 4700:   border-collapse: collapse;
1.403     albertel 4701:   padding: 0px;
1.359     albertel 4702: }
1.795     www      4703: 
1.409     albertel 4704: table.LC_docs_path {
                   4705:   width: 100%;
                   4706:   border: 0;
                   4707:   background: $pgbg;
                   4708:   font-family: $sans;
                   4709:   border-collapse: collapse;
                   4710:   padding: 0px;
                   4711: }
                   4712: 
1.359     albertel 4713: table#LC_title_bar td {
                   4714:   background: $tabbg;
                   4715: }
1.795     www      4716: 
1.773     ehlerst  4717: table#LC_title_bar .LC_title_bar_who {
1.359     albertel 4718:   background: $tabbg;
1.801   ! tempelho 4719:   color: $fontmenu;
1.427     albertel 4720:   font: small $sans;
1.359     albertel 4721:   text-align: right;
1.773     ehlerst  4722:   margin: 0px;
                   4723: }
1.795     www      4724: 
1.773     ehlerst  4725: table#LC_title_bar .LC_title_bar_name {
                   4726:   margin: 0px;
                   4727: }
1.795     www      4728: 
1.773     ehlerst  4729: table#LC_title_bar .LC_title_bar_role {
                   4730:   margin: 0px;
                   4731: }
1.795     www      4732: 
1.775     bisitz   4733: table#LC_title_bar .LC_title_bar_realm {
1.773     ehlerst  4734:   margin: 0px;
1.359     albertel 4735: }
1.795     www      4736: 
1.469     banghart 4737: span.LC_metadata {
1.795     www      4738:   font-family: $sans;
1.469     banghart 4739: }
1.359     albertel 4740: 
1.706     harmsja  4741: table#LC_menubuttons img{
1.346     albertel 4742:   border: 0px;
                   4743: }
1.795     www      4744: 
1.345     albertel 4745: table#LC_top_nav td {
                   4746:   background: $tabbg;
1.392     albertel 4747:   border: 0px;
1.407     albertel 4748:   font-size: small;
1.706     harmsja  4749:   vertical-align:top;
                   4750:   padding:2px 5px 2px 5px;
1.345     albertel 4751: }
1.795     www      4752: 
                   4753: table#LC_top_nav td a,
                   4754: div#LC_top_nav a {
1.345     albertel 4755:   color: $font;
                   4756:   font-family: $sans;
                   4757: }
1.795     www      4758: 
1.364     albertel 4759: table#LC_top_nav td.LC_top_nav_logo {
                   4760:   background: $tabbg;
1.432     albertel 4761:   text-align: left;
1.408     albertel 4762:   white-space: nowrap;
1.432     albertel 4763:   width: 31px;
1.408     albertel 4764: }
1.795     www      4765: 
1.408     albertel 4766: table#LC_top_nav td.LC_top_nav_logo img {
1.432     albertel 4767:   border: 0px;
1.408     albertel 4768:   vertical-align: bottom;
1.364     albertel 4769: }
1.795     www      4770: 
1.777     tempelho 4771: table#LC_top_nav td.LC_top_nav_exit,
1.779     bisitz   4772: table#LC_top_nav td.LC_top_nav_help {
1.777     tempelho 4773:   width: 2.0em;
                   4774: }
1.795     www      4775: 
1.442     albertel 4776: table#LC_top_nav td.LC_top_nav_login {
                   4777:   width: 4.0em;
                   4778:   text-align: center;
                   4779: }
1.795     www      4780: 
                   4781: table.LC_breadcrumbs td,
                   4782: table.LC_docs_path td  {
1.357     albertel 4783:   background: $tabbg;
1.801   ! tempelho 4784:   color: $fontmenu;
1.357     albertel 4785:   font-family: $sans;
1.358     albertel 4786:   font-size: smaller;
1.357     albertel 4787: }
1.795     www      4788: 
1.777     tempelho 4789: table.LC_breadcrumbs td.LC_breadcrumbs_component,
                   4790: table.LC_docs_path td.LC_docs_path_component {
1.779     bisitz   4791:   background: $tabbg;
1.801   ! tempelho 4792:   color: $fontmenu;
1.777     tempelho 4793:   font-family: $sans;
1.779     bisitz   4794:   font-size: larger;
                   4795:   text-align: right;
1.777     tempelho 4796: }
1.795     www      4797: 
1.383     albertel 4798: td.LC_table_cell_checkbox {
                   4799:   text-align: center;
                   4800: }
1.795     www      4801: 
1.779     bisitz   4802: table#LC_mainmenu td.LC_mainmenu_column {
                   4803:     vertical-align: top;
1.777     tempelho 4804: }
1.522     albertel 4805: 
1.795     www      4806: .LC_fontsize_small {
1.705     tempelho 4807:  font-size: 70%;
                   4808: }
                   4809: 
1.795     www      4810: .LC_fontsize_medium {
1.705     tempelho 4811:  font-size: 85%;
                   4812: }
                   4813: 
1.795     www      4814: .LC_fontsize_large {
1.705     tempelho 4815:  font-size: 120%;
                   4816: }
                   4817: 
1.346     albertel 4818: .LC_menubuttons_inline_text {
                   4819:   color: $font;
                   4820:   font-family: $sans;
1.698     harmsja  4821:   font-size: 90%;
1.701     harmsja  4822:   padding-left:3px;
1.346     albertel 4823: }
                   4824: 
1.526     www      4825: .LC_menubuttons_link {
                   4826:   text-decoration: none;
                   4827: }
1.795     www      4828: 
1.522     albertel 4829: .LC_menubuttons_category {
1.521     www      4830:   color: $font;
1.526     www      4831:   background: $pgbg;
1.521     www      4832:   font-family: $sans;
                   4833:   font-size: larger;
                   4834:   font-weight: bold;
                   4835: }
                   4836: 
1.346     albertel 4837: td.LC_menubuttons_text {
1.779     bisitz   4838:  	color: $font;
1.346     albertel 4839: }
1.706     harmsja  4840: 
1.346     albertel 4841: .LC_current_location {
                   4842:   font-family: $sans;
                   4843:   background: $tabbg;
                   4844: }
1.795     www      4845: 
1.346     albertel 4846: .LC_new_mail {
                   4847:   font-family: $sans;
1.634     www      4848:   background: $tabbg;
1.346     albertel 4849:   font-weight: bold;
                   4850: }
1.347     albertel 4851: 
1.527     www      4852: .LC_dropadd_labeltext {
                   4853:   font-family: $sans;
                   4854:   text-align: right;
                   4855: }
                   4856: 
                   4857: .LC_preferences_labeltext {
                   4858:   font-family: $sans;
                   4859:   text-align: right;
                   4860: }
                   4861: 
1.666     raeburn  4862: .LC_roleslog_note {
1.701     harmsja  4863:   font-size: small;
1.666     raeburn  4864: }
                   4865: 
1.715     raeburn  4866: .LC_mail_functions {
                   4867:     font-weight: bold;
                   4868: }
                   4869: 
1.440     albertel 4870: table.LC_aboutme_port {
                   4871:   border: 0px;
                   4872:   border-collapse: collapse;
                   4873:   border-spacing: 0px;
                   4874: }
1.795     www      4875: 
                   4876: table.LC_data_table,
                   4877: table.LC_mail_list {
1.347     albertel 4878:   border: 1px solid #000000;
1.402     albertel 4879:   border-collapse: separate;
1.426     albertel 4880:   border-spacing: 1px;
1.610     albertel 4881:   background: $pgbg;
1.347     albertel 4882: }
1.795     www      4883: 
1.422     albertel 4884: .LC_data_table_dense {
                   4885:   font-size: small;
                   4886: }
1.795     www      4887: 
1.507     raeburn  4888: table.LC_nested_outer {
                   4889:   border: 1px solid #000000;
1.589     raeburn  4890:   border-collapse: collapse;
1.507     raeburn  4891:   border-spacing: 0px;
                   4892:   width: 100%;
                   4893: }
1.795     www      4894: 
1.507     raeburn  4895: table.LC_nested {
                   4896:   border: 0px;
1.589     raeburn  4897:   border-collapse: collapse;
1.507     raeburn  4898:   border-spacing: 0px;
                   4899:   width: 100%;
                   4900: }
1.795     www      4901: 
                   4902: table.LC_data_table tr th, 
                   4903: table.LC_calendar tr th, 
                   4904: table.LC_mail_list tr th,
1.523     albertel 4905: table.LC_prior_tries tr th {
1.349     albertel 4906:   font-weight: bold;
                   4907:   background-color: $data_table_head;
1.801   ! tempelho 4908:   color:$fontmenu;
1.701     harmsja  4909:   font-size:90%;
1.347     albertel 4910: }
1.795     www      4911: 
1.711     raeburn  4912: table.LC_data_table tr.LC_info_row > td {
1.735     bisitz   4913:   background-color: #CCCCCC;
1.711     raeburn  4914:   font-weight: bold;
                   4915:   text-align: left;
                   4916: }
1.795     www      4917: 
1.779     bisitz   4918: table.LC_data_table tr.LC_odd_row > td,
1.709     bisitz   4919: table.LC_pick_box tr > td.LC_odd_row,
1.440     albertel 4920: table.LC_aboutme_port tr td {
1.349     albertel 4921:   background-color: $data_table_light;
1.425     albertel 4922:   padding: 2px;
1.347     albertel 4923: }
1.795     www      4924: 
1.610     albertel 4925: table.LC_data_table tr.LC_even_row > td,
1.709     bisitz   4926: table.LC_pick_box tr > td.LC_even_row,
1.440     albertel 4927: table.LC_aboutme_port tr.LC_even_row td {
1.349     albertel 4928:   background-color: $data_table_dark;
1.709     bisitz   4929:   padding: 2px;
1.347     albertel 4930: }
1.795     www      4931: 
1.425     albertel 4932: table.LC_data_table tr.LC_data_table_highlight td {
                   4933:   background-color: $data_table_darker;
                   4934: }
1.795     www      4935: 
1.639     raeburn  4936: table.LC_data_table tr td.LC_leftcol_header {
                   4937:   background-color: $data_table_head;
                   4938:   font-weight: bold;
                   4939: }
1.795     www      4940: 
1.451     albertel 4941: table.LC_data_table tr.LC_empty_row td,
1.507     raeburn  4942: table.LC_nested tr.LC_empty_row td {
1.347     albertel 4943:   background-color: #FFFFFF;
1.421     albertel 4944:   font-weight: bold;
                   4945:   font-style: italic;
                   4946:   text-align: center;
                   4947:   padding: 8px;
1.347     albertel 4948: }
1.795     www      4949: 
1.507     raeburn  4950: table.LC_nested tr.LC_empty_row td {
1.465     albertel 4951:   padding: 4ex
                   4952: }
1.795     www      4953: 
1.507     raeburn  4954: table.LC_nested_outer tr th {
                   4955:   font-weight: bold;
1.801   ! tempelho 4956:   color:$fontmenu;
1.507     raeburn  4957:   background-color: $data_table_head;
1.701     harmsja  4958:   font-size: small;
1.507     raeburn  4959:   border-bottom: 1px solid #000000;
                   4960: }
1.795     www      4961: 
1.507     raeburn  4962: table.LC_nested_outer tr td.LC_subheader {
                   4963:   background-color: $data_table_head;
                   4964:   font-weight: bold;
                   4965:   font-size: small;
                   4966:   border-bottom: 1px solid #000000;
                   4967:   text-align: right;
1.451     albertel 4968: }
1.795     www      4969: 
1.507     raeburn  4970: table.LC_nested tr.LC_info_row td {
1.735     bisitz   4971:   background-color: #CCCCCC;
1.451     albertel 4972:   font-weight: bold;
                   4973:   font-size: small;
1.507     raeburn  4974:   text-align: center;
                   4975: }
1.795     www      4976: 
1.589     raeburn  4977: table.LC_nested tr.LC_info_row td.LC_left_item,
                   4978: table.LC_nested_outer tr th.LC_left_item {
1.507     raeburn  4979:   text-align: left;
1.451     albertel 4980: }
1.795     www      4981: 
1.507     raeburn  4982: table.LC_nested td {
1.735     bisitz   4983:   background-color: #FFFFFF;
1.451     albertel 4984:   font-size: small;
1.507     raeburn  4985: }
1.795     www      4986: 
1.507     raeburn  4987: table.LC_nested_outer tr th.LC_right_item,
                   4988: table.LC_nested tr.LC_info_row td.LC_right_item,
                   4989: table.LC_nested tr.LC_odd_row td.LC_right_item,
                   4990: table.LC_nested tr td.LC_right_item {
1.451     albertel 4991:   text-align: right;
                   4992: }
                   4993: 
1.507     raeburn  4994: table.LC_nested tr.LC_odd_row td {
1.735     bisitz   4995:   background-color: #EEEEEE;
1.451     albertel 4996: }
                   4997: 
1.473     raeburn  4998: table.LC_createuser {
                   4999: }
                   5000: 
                   5001: table.LC_createuser tr.LC_section_row td {
1.701     harmsja  5002:   font-size: small;
1.473     raeburn  5003: }
                   5004: 
                   5005: table.LC_createuser tr.LC_info_row td  {
1.735     bisitz   5006:   background-color: #CCCCCC;
1.473     raeburn  5007:   font-weight: bold;
                   5008:   text-align: center;
                   5009: }
                   5010: 
1.349     albertel 5011: table.LC_calendar {
                   5012:   border: 1px solid #000000;
                   5013:   border-collapse: collapse;
                   5014: }
1.795     www      5015: 
1.349     albertel 5016: table.LC_calendar_pickdate {
                   5017:   font-size: xx-small;
                   5018: }
1.795     www      5019: 
1.349     albertel 5020: table.LC_calendar tr td {
                   5021:   border: 1px solid #000000;
                   5022:   vertical-align: top;
                   5023: }
1.795     www      5024: 
1.349     albertel 5025: table.LC_calendar tr td.LC_calendar_day_empty {
                   5026:   background-color: $data_table_dark;
                   5027: }
1.795     www      5028: 
1.779     bisitz   5029: table.LC_calendar tr td.LC_calendar_day_current {
                   5030:   background-color: $data_table_highlight;
1.777     tempelho 5031: }
1.795     www      5032: 
1.349     albertel 5033: table.LC_mail_list tr.LC_mail_new {
                   5034:   background-color: $mail_new;
                   5035: }
1.795     www      5036: 
1.349     albertel 5037: table.LC_mail_list tr.LC_mail_new:hover {
                   5038:   background-color: $mail_new_hover;
                   5039: }
1.795     www      5040: 
                   5041: table.LC_mail_list tr.LC_mail_even {
1.777     tempelho 5042: }
1.795     www      5043: 
                   5044: table.LC_mail_list tr.LC_mail_odd {
1.777     tempelho 5045: }
1.795     www      5046: 
1.349     albertel 5047: table.LC_mail_list tr.LC_mail_read {
                   5048:   background-color: $mail_read;
                   5049: }
1.795     www      5050: 
1.349     albertel 5051: table.LC_mail_list tr.LC_mail_read:hover {
                   5052:   background-color: $mail_read_hover;
                   5053: }
1.795     www      5054: 
1.349     albertel 5055: table.LC_mail_list tr.LC_mail_replied {
                   5056:   background-color: $mail_replied;
                   5057: }
1.795     www      5058: 
1.349     albertel 5059: table.LC_mail_list tr.LC_mail_replied:hover {
                   5060:   background-color: $mail_replied_hover;
                   5061: }
1.795     www      5062: 
1.349     albertel 5063: table.LC_mail_list tr.LC_mail_other {
                   5064:   background-color: $mail_other;
                   5065: }
1.795     www      5066: 
1.349     albertel 5067: table.LC_mail_list tr.LC_mail_other:hover {
                   5068:   background-color: $mail_other_hover;
                   5069: }
1.494     raeburn  5070: 
1.777     tempelho 5071: table.LC_data_table tr > td.LC_browser_file,
                   5072: table.LC_data_table tr > td.LC_browser_file_published {
1.389     albertel 5073:   background: #CCFF88;
                   5074: }
1.795     www      5075: 
1.777     tempelho 5076: table.LC_data_table tr > td.LC_browser_file_locked,
                   5077: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389     albertel 5078:   background: #FFAA99;
1.387     albertel 5079: }
1.795     www      5080: 
1.777     tempelho 5081: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.779     bisitz   5082:   background: #AAAAAA;
                   5083: }
1.795     www      5084: 
1.777     tempelho 5085: table.LC_data_table tr > td.LC_browser_file_modified,
1.779     bisitz   5086: table.LC_data_table tr > td.LC_browser_file_metamodified {
                   5087:   background: #FFFF77;
1.777     tempelho 5088: }
1.795     www      5089: 
1.696     bisitz   5090: table.LC_data_table tr.LC_browser_folder > td {
1.389     albertel 5091:   background: #CCCCFF;
1.387     albertel 5092: }
1.696     bisitz   5093: 
1.707     bisitz   5094: table.LC_data_table tr > td.LC_roles_is {
                   5095: /*  background: #77FF77; */
                   5096: }
1.795     www      5097: 
1.707     bisitz   5098: table.LC_data_table tr > td.LC_roles_future {
                   5099:   background: #FFFF77;
                   5100: }
1.795     www      5101: 
1.707     bisitz   5102: table.LC_data_table tr > td.LC_roles_will {
                   5103:   background: #FFAA77;
                   5104: }
1.795     www      5105: 
1.707     bisitz   5106: table.LC_data_table tr > td.LC_roles_expired {
                   5107:   background: #FF7777;
                   5108: }
1.795     www      5109: 
1.707     bisitz   5110: table.LC_data_table tr > td.LC_roles_will_not {
                   5111:   background: #AAFF77;
                   5112: }
1.795     www      5113: 
1.707     bisitz   5114: table.LC_data_table tr > td.LC_roles_selected {
                   5115:   background: #11CC55;
                   5116: }
                   5117: 
1.388     albertel 5118: span.LC_current_location {
1.701     harmsja  5119:   font-size:larger;
1.388     albertel 5120:   background: $pgbg;
                   5121: }
1.387     albertel 5122: 
1.395     albertel 5123: span.LC_parm_menu_item {
                   5124:   font-size: larger;
                   5125:   font-family: $sans;
                   5126: }
1.795     www      5127: 
1.395     albertel 5128: span.LC_parm_scope_all {
                   5129:   color: red;
                   5130: }
1.795     www      5131: 
1.395     albertel 5132: span.LC_parm_scope_folder {
                   5133:   color: green;
                   5134: }
1.795     www      5135: 
1.395     albertel 5136: span.LC_parm_scope_resource {
                   5137:   color: orange;
                   5138: }
1.795     www      5139: 
1.395     albertel 5140: span.LC_parm_part {
                   5141:   color: blue;
                   5142: }
1.795     www      5143: 
1.395     albertel 5144: span.LC_parm_folder, span.LC_parm_symb {
                   5145:   font-size: x-small;
                   5146:   font-family: $mono;
                   5147:   color: #AAAAAA;
                   5148: }
                   5149: 
1.795     www      5150: td.LC_parm_overview_level_menu,
                   5151: td.LC_parm_overview_map_menu,
                   5152: td.LC_parm_overview_parm_selectors,
                   5153: td.LC_parm_overview_restrictions  {
1.396     albertel 5154:   border: 1px solid black;
                   5155:   border-collapse: collapse;
                   5156: }
1.795     www      5157: 
1.396     albertel 5158: table.LC_parm_overview_restrictions td {
                   5159:   border-width: 1px 4px 1px 4px;
                   5160:   border-style: solid;
                   5161:   border-color: $pgbg;
                   5162:   text-align: center;
                   5163: }
1.795     www      5164: 
1.396     albertel 5165: table.LC_parm_overview_restrictions th {
                   5166:   background: $tabbg;
                   5167:   border-width: 1px 4px 1px 4px;
                   5168:   border-style: solid;
                   5169:   border-color: $pgbg;
                   5170: }
1.795     www      5171: 
1.398     albertel 5172: table#LC_helpmenu {
                   5173:   border: 0px;
                   5174:   height: 55px;
                   5175:   border-spacing: 0px;
                   5176: }
                   5177: 
                   5178: table#LC_helpmenu fieldset legend {
                   5179:   font-size: larger;
                   5180:   font-weight: bold;
                   5181: }
1.795     www      5182: 
1.397     albertel 5183: table#LC_helpmenu_links {
                   5184:   width: 100%;
                   5185:   border: 1px solid black;
                   5186:   background: $pgbg;
                   5187:   padding: 0px;
                   5188:   border-spacing: 1px;
                   5189: }
1.795     www      5190: 
1.397     albertel 5191: table#LC_helpmenu_links tr td {
                   5192:   padding: 1px;
                   5193:   background: $tabbg;
1.399     albertel 5194:   text-align: center;
                   5195:   font-weight: bold;
1.397     albertel 5196: }
1.396     albertel 5197: 
1.795     www      5198: table#LC_helpmenu_links a:link,
                   5199: table#LC_helpmenu_links a:visited,
1.397     albertel 5200: table#LC_helpmenu_links a:active {
                   5201:   text-decoration: none;
                   5202:   color: $font;
                   5203: }
1.795     www      5204: 
1.397     albertel 5205: table#LC_helpmenu_links a:hover {
                   5206:   text-decoration: underline;
                   5207:   color: $vlink;
                   5208: }
1.396     albertel 5209: 
1.417     albertel 5210: .LC_chrt_popup_exists {
                   5211:   border: 1px solid #339933;
                   5212:   margin: -1px;
                   5213: }
1.795     www      5214: 
1.417     albertel 5215: .LC_chrt_popup_up {
                   5216:   border: 1px solid yellow;
                   5217:   margin: -1px;
                   5218: }
1.795     www      5219: 
1.417     albertel 5220: .LC_chrt_popup {
                   5221:   border: 1px solid #8888FF;
                   5222:   background: #CCCCFF;
                   5223: }
1.795     www      5224: 
1.421     albertel 5225: table.LC_pick_box {
                   5226:   border-collapse: separate;
                   5227:   background: white;
                   5228:   border: 1px solid black;
                   5229:   border-spacing: 1px;
                   5230: }
1.795     www      5231: 
1.421     albertel 5232: table.LC_pick_box td.LC_pick_box_title {
                   5233:   background: $tabbg;
                   5234:   font-weight: bold;
                   5235:   text-align: right;
1.740     bisitz   5236:   vertical-align: top;
1.421     albertel 5237:   width: 184px;
                   5238:   padding: 8px;
                   5239: }
1.795     www      5240: 
1.645     raeburn  5241: table.LC_pick_box td.LC_selfenroll_pick_box_title {
                   5242:   background: $tabbg;
                   5243:   font-weight: bold;
                   5244:   text-align: right;
                   5245:   width: 350px;
                   5246:   padding: 8px;
                   5247: }
                   5248: 
1.579     raeburn  5249: table.LC_pick_box td.LC_pick_box_value {
                   5250:   text-align: left;
                   5251:   padding: 8px;
                   5252: }
1.795     www      5253: 
1.579     raeburn  5254: table.LC_pick_box td.LC_pick_box_select {
                   5255:   text-align: left;
                   5256:   padding: 8px;
                   5257: }
1.795     www      5258: 
1.424     albertel 5259: table.LC_pick_box td.LC_pick_box_separator {
1.421     albertel 5260:   padding: 0px;
                   5261:   height: 1px;
                   5262:   background: black;
                   5263: }
1.795     www      5264: 
1.421     albertel 5265: table.LC_pick_box td.LC_pick_box_submit {
                   5266:   text-align: right;
                   5267: }
1.795     www      5268: 
1.579     raeburn  5269: table.LC_pick_box td.LC_evenrow_value {
                   5270:   text-align: left;
                   5271:   padding: 8px;
                   5272:   background-color: $data_table_light;
                   5273: }
1.795     www      5274: 
1.579     raeburn  5275: table.LC_pick_box td.LC_oddrow_value {
                   5276:   text-align: left;
                   5277:   padding: 8px;
                   5278:   background-color: $data_table_light;
                   5279: }
1.795     www      5280: 
1.579     raeburn  5281: table.LC_helpform_receipt {
                   5282:   width: 620px;
                   5283:   border-collapse: separate;
                   5284:   background: white;
                   5285:   border: 1px solid black;
                   5286:   border-spacing: 1px;
                   5287: }
1.795     www      5288: 
1.579     raeburn  5289: table.LC_helpform_receipt td.LC_pick_box_title {
                   5290:   background: $tabbg;
                   5291:   font-weight: bold;
                   5292:   text-align: right;
                   5293:   width: 184px;
                   5294:   padding: 8px;
                   5295: }
1.795     www      5296: 
1.579     raeburn  5297: table.LC_helpform_receipt td.LC_evenrow_value {
                   5298:   text-align: left;
                   5299:   padding: 8px;
                   5300:   background-color: $data_table_light;
                   5301: }
1.795     www      5302: 
1.579     raeburn  5303: table.LC_helpform_receipt td.LC_oddrow_value {
                   5304:   text-align: left;
                   5305:   padding: 8px;
                   5306:   background-color: $data_table_light;
                   5307: }
1.795     www      5308: 
1.579     raeburn  5309: table.LC_helpform_receipt td.LC_pick_box_separator {
                   5310:   padding: 0px;
                   5311:   height: 1px;
                   5312:   background: black;
                   5313: }
1.795     www      5314: 
1.579     raeburn  5315: span.LC_helpform_receipt_cat {
                   5316:   font-weight: bold;
                   5317: }
1.795     www      5318: 
1.424     albertel 5319: table.LC_group_priv_box {
                   5320:   background: white;
                   5321:   border: 1px solid black;
                   5322:   border-spacing: 1px;
                   5323: }
1.795     www      5324: 
1.424     albertel 5325: table.LC_group_priv_box td.LC_pick_box_title {
                   5326:   background: $tabbg;
                   5327:   font-weight: bold;
                   5328:   text-align: right;
                   5329:   width: 184px;
                   5330: }
1.795     www      5331: 
1.424     albertel 5332: table.LC_group_priv_box td.LC_groups_fixed {
                   5333:   background: $data_table_light;
                   5334:   text-align: center;
                   5335: }
1.795     www      5336: 
1.424     albertel 5337: table.LC_group_priv_box td.LC_groups_optional {
                   5338:   background: $data_table_dark;
                   5339:   text-align: center;
                   5340: }
1.795     www      5341: 
1.424     albertel 5342: table.LC_group_priv_box td.LC_groups_functionality {
                   5343:   background: $data_table_darker;
                   5344:   text-align: center;
                   5345:   font-weight: bold;
                   5346: }
1.795     www      5347: 
1.424     albertel 5348: table.LC_group_priv td {
                   5349:   text-align: left;
                   5350:   padding: 0px;
                   5351: }
                   5352: 
1.421     albertel 5353: table.LC_notify_front_page {
                   5354:   background: white;
                   5355:   border: 1px solid black;
                   5356:   padding: 8px;
                   5357: }
1.795     www      5358: 
1.421     albertel 5359: table.LC_notify_front_page td {
                   5360:   padding: 8px;
                   5361: }
1.795     www      5362: 
1.424     albertel 5363: .LC_navbuttons {
                   5364:   margin: 2ex 0ex 2ex 0ex;
                   5365: }
1.795     www      5366: 
1.423     albertel 5367: .LC_topic_bar {
                   5368:   font-family: $sans;
                   5369:   font-weight: bold;
                   5370:   width: 100%;
                   5371:   background: $tabbg;
                   5372:   vertical-align: middle;
                   5373:   margin: 2ex 0ex 2ex 0ex;
                   5374: }
1.795     www      5375: 
1.423     albertel 5376: .LC_topic_bar span {
                   5377:   vertical-align: middle;
                   5378: }
1.795     www      5379: 
1.423     albertel 5380: .LC_topic_bar img {
                   5381:   vertical-align: bottom;
                   5382: }
1.795     www      5383: 
1.423     albertel 5384: table.LC_course_group_status {
                   5385:   margin: 20px;
                   5386: }
1.795     www      5387: 
1.423     albertel 5388: table.LC_status_selector td {
                   5389:   vertical-align: top;
                   5390:   text-align: center;
1.424     albertel 5391:   padding: 4px;
                   5392: }
1.795     www      5393: 
1.424     albertel 5394: table.LC_descriptive_input td.LC_description {
                   5395:   vertical-align: top;
                   5396:   text-align: right;
                   5397:   font-weight: bold;
1.423     albertel 5398: }
1.795     www      5399: 
1.599     albertel 5400: div.LC_feedback_link {
1.616     albertel 5401:   clear: both;
1.599     albertel 5402:   background: white;
1.779     bisitz   5403:   width: 100%;
1.489     raeburn  5404: }
1.795     www      5405: 
1.489     raeburn  5406: span.LC_feedback_link {
1.599     albertel 5407:   background: $feedback_link_bg;
                   5408:   font-size: larger;
                   5409: }
1.795     www      5410: 
1.599     albertel 5411: span.LC_message_link {
                   5412:   background: $feedback_link_bg;
                   5413:   font-size: larger;
                   5414:   position: absolute;
                   5415:   right: 1em;
1.489     raeburn  5416: }
1.421     albertel 5417: 
1.515     albertel 5418: table.LC_prior_tries {
1.524     albertel 5419:   border: 1px solid #000000;
                   5420:   border-collapse: separate;
                   5421:   border-spacing: 1px;
1.515     albertel 5422: }
1.523     albertel 5423: 
1.515     albertel 5424: table.LC_prior_tries td {
1.524     albertel 5425:   padding: 2px;
1.515     albertel 5426: }
1.523     albertel 5427: 
                   5428: .LC_answer_correct {
1.795     www      5429:   background: lightgreen;
                   5430:   font-family: $sans;
                   5431:   color: darkgreen;
                   5432:   padding: 6px;
1.523     albertel 5433: }
1.795     www      5434: 
1.523     albertel 5435: .LC_answer_charged_try {
1.797     www      5436:   background: #FFAAAA;
1.795     www      5437:   font-family: $sans;
                   5438:   color: darkred;
                   5439:   padding: 6px;
1.523     albertel 5440: }
1.795     www      5441: 
1.779     bisitz   5442: .LC_answer_not_charged_try,
1.523     albertel 5443: .LC_answer_no_grade,
                   5444: .LC_answer_late {
1.795     www      5445:   background: lightyellow;
                   5446:   font-family: $sans;
1.523     albertel 5447:   color: black;
1.795     www      5448:   padding: 6px;
1.523     albertel 5449: }
1.795     www      5450: 
1.523     albertel 5451: .LC_answer_previous {
1.795     www      5452:   background: lightblue;
                   5453:   font-family: $sans;
                   5454:   color: darkblue;
                   5455:   padding: 6px;
1.523     albertel 5456: }
1.795     www      5457: 
1.779     bisitz   5458: .LC_answer_no_message {
1.777     tempelho 5459:   background: #FFFFFF;
1.795     www      5460:   font-family: $sans;
1.777     tempelho 5461:   color: black;
1.795     www      5462:   padding: 6px;
1.779     bisitz   5463: }
1.795     www      5464: 
1.779     bisitz   5465: .LC_answer_unknown {
                   5466:   background: orange;
1.795     www      5467:   font-family: $sans;
1.779     bisitz   5468:   color: black;
1.795     www      5469:   padding: 6px;
1.777     tempelho 5470: }
1.795     www      5471: 
1.529     albertel 5472: span.LC_prior_numerical,
                   5473: span.LC_prior_string,
                   5474: span.LC_prior_custom,
                   5475: span.LC_prior_reaction,
                   5476: span.LC_prior_math {
1.523     albertel 5477:   font-family: monospace;
                   5478:   white-space: pre;
                   5479: }
                   5480: 
1.525     albertel 5481: span.LC_prior_string {
                   5482:   font-family: monospace;
                   5483:   white-space: pre;
                   5484: }
                   5485: 
1.523     albertel 5486: table.LC_prior_option {
                   5487:   width: 100%;
                   5488:   border-collapse: collapse;
                   5489: }
1.795     www      5490: 
                   5491: table.LC_prior_rank, 
                   5492: table.LC_prior_match {
1.528     albertel 5493:   border-collapse: collapse;
                   5494: }
1.795     www      5495: 
1.528     albertel 5496: table.LC_prior_option tr td,
                   5497: table.LC_prior_rank tr td,
                   5498: table.LC_prior_match tr td {
1.524     albertel 5499:   border: 1px solid #000000;
1.515     albertel 5500: }
                   5501: 
1.770     droeschl 5502: td.LC_nobreak,
1.519     raeburn  5503: span.LC_nobreak {
1.544     albertel 5504:   white-space: nowrap;
1.519     raeburn  5505: }
                   5506: 
1.576     raeburn  5507: span.LC_cusr_emph {
                   5508:   font-style: italic;
                   5509: }
                   5510: 
1.633     raeburn  5511: span.LC_cusr_subheading {
                   5512:   font-weight: normal;
                   5513:   font-size: 85%;
                   5514: }
                   5515: 
1.545     albertel 5516: table.LC_docs_documents {
                   5517:   background: #BBBBBB;
1.547     albertel 5518:   border-width: 0px;
1.545     albertel 5519:   border-collapse: collapse;
                   5520: }
1.795     www      5521: 
1.777     tempelho 5522: table.LC_docs_documents td.LC_docs_document {
1.779     bisitz   5523:   border: 2px solid black;
                   5524:   padding: 4px;
1.777     tempelho 5525: }
1.795     www      5526: 
1.545     albertel 5527: .LC_docs_entry_move {
                   5528:   border: 0px;
                   5529:   border-collapse: collapse;
1.544     albertel 5530: }
                   5531: 
1.545     albertel 5532: .LC_docs_entry_move td {
                   5533:   border: 2px solid #BBBBBB;
                   5534:   background: #DDDDDD;
                   5535: }
                   5536: 
                   5537: .LC_docs_editor td.LC_docs_entry_commands {
                   5538:   background: #DDDDDD;
                   5539:   font-size: x-small;
                   5540: }
1.795     www      5541: 
1.544     albertel 5542: .LC_docs_copy {
1.545     albertel 5543:   color: #000099;
1.544     albertel 5544: }
1.795     www      5545: 
1.544     albertel 5546: .LC_docs_cut {
1.545     albertel 5547:   color: #550044;
1.544     albertel 5548: }
1.795     www      5549: 
1.544     albertel 5550: .LC_docs_rename {
1.545     albertel 5551:   color: #009900;
1.544     albertel 5552: }
1.795     www      5553: 
1.544     albertel 5554: .LC_docs_remove {
1.545     albertel 5555:   color: #990000;
                   5556: }
                   5557: 
1.547     albertel 5558: .LC_docs_reinit_warn,
                   5559: .LC_docs_ext_edit {
                   5560:   font-size: x-small;
                   5561: }
                   5562: 
1.545     albertel 5563: .LC_docs_editor td.LC_docs_entry_title,
                   5564: .LC_docs_editor td.LC_docs_entry_icon {
                   5565:   background: #FFFFBB;
                   5566: }
1.795     www      5567: 
1.545     albertel 5568: .LC_docs_editor td.LC_docs_entry_parameter {
                   5569:   background: #BBBBFF;
                   5570:   font-size: x-small;
                   5571:   white-space: nowrap;
                   5572: }
                   5573: 
                   5574: table.LC_docs_adddocs td,
                   5575: table.LC_docs_adddocs th {
                   5576:   border: 1px solid #BBBBBB;
                   5577:   padding: 4px;
                   5578:   background: #DDDDDD;
1.543     albertel 5579: }
                   5580: 
1.584     albertel 5581: table.LC_sty_begin {
                   5582:   background: #BBFFBB;
                   5583: }
1.795     www      5584: 
1.584     albertel 5585: table.LC_sty_end {
                   5586:   background: #FFBBBB;
                   5587: }
                   5588: 
1.589     raeburn  5589: table.LC_double_column {
                   5590:   border-width: 0px;
                   5591:   border-collapse: collapse;
                   5592:   width: 100%;
                   5593:   padding: 2px;
                   5594: }
                   5595: 
                   5596: table.LC_double_column tr td.LC_left_col {
1.590     raeburn  5597:   top: 2px;
1.589     raeburn  5598:   left: 2px;
                   5599:   width: 47%;
                   5600:   vertical-align: top;
                   5601: }
                   5602: 
                   5603: table.LC_double_column tr td.LC_right_col {
                   5604:   top: 2px;
1.779     bisitz   5605:   right: 2px;
1.589     raeburn  5606:   width: 47%;
                   5607:   vertical-align: top;
                   5608: }
                   5609: 
1.594     raeburn  5610: span.LC_role_level {
                   5611:   font-weight: bold;
                   5612: }
                   5613: 
1.591     raeburn  5614: div.LC_left_float {
                   5615:   float: left;
                   5616:   padding-right: 5%;
1.597     albertel 5617:   padding-bottom: 4px;
1.591     raeburn  5618: }
                   5619: 
                   5620: div.LC_clear_float_header {
1.597     albertel 5621:   padding-bottom: 2px;
1.591     raeburn  5622: }
                   5623: 
                   5624: div.LC_clear_float_footer {
1.597     albertel 5625:   padding-top: 10px;
1.591     raeburn  5626:   clear: both;
                   5627: }
                   5628: 
1.597     albertel 5629: div.LC_grade_show_user {
                   5630:   margin-top: 20px;
                   5631:   border: 1px solid black;
                   5632: }
1.795     www      5633: 
1.597     albertel 5634: div.LC_grade_user_name {
                   5635:   background: #DDDDEE;
                   5636:   border-bottom: 1px solid black;
1.705     tempelho 5637:   font-weight: bold;
                   5638:   font-size: large;
1.597     albertel 5639: }
1.795     www      5640: 
1.597     albertel 5641: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
                   5642:   background: #DDEEDD;
                   5643: }
                   5644: 
                   5645: div.LC_grade_show_problem,
                   5646: div.LC_grade_submissions,
                   5647: div.LC_grade_message_center,
                   5648: div.LC_grade_info_links,
                   5649: div.LC_grade_assign {
                   5650:   margin: 5px;
                   5651:   width: 99%;
                   5652:   background: #FFFFFF;
                   5653: }
1.795     www      5654: 
1.597     albertel 5655: div.LC_grade_show_problem_header,
                   5656: div.LC_grade_submissions_header,
                   5657: div.LC_grade_message_center_header,
                   5658: div.LC_grade_assign_header {
1.705     tempelho 5659:   font-weight: bold;
                   5660:   font-size: large;
1.597     albertel 5661: }
1.795     www      5662: 
1.597     albertel 5663: div.LC_grade_show_problem_problem,
                   5664: div.LC_grade_submissions_body,
                   5665: div.LC_grade_message_center_body,
                   5666: div.LC_grade_assign_body {
                   5667:   border: 1px solid black;
                   5668:   width: 99%;
                   5669:   background: #FFFFFF;
                   5670: }
1.795     www      5671: 
1.598     albertel 5672: span.LC_grade_check_note {
1.705     tempelho 5673:   font-weight: normal;
                   5674:   font-size: medium;
1.598     albertel 5675:   display: inline;
                   5676:   position: absolute;
                   5677:   right: 1em;
                   5678: }
1.597     albertel 5679: 
1.613     albertel 5680: table.LC_scantron_action {
                   5681:   width: 100%;
                   5682: }
1.795     www      5683: 
1.613     albertel 5684: table.LC_scantron_action tr th {
1.698     harmsja  5685:   font-weight:bold;
                   5686:   font-style:normal;
1.613     albertel 5687: }
1.795     www      5688: 
1.779     bisitz   5689: .LC_edit_problem_header,
1.614     albertel 5690: div.LC_edit_problem_footer {
1.705     tempelho 5691:   font-weight: normal;
                   5692:   font-size:  medium;
1.602     albertel 5693:   margin: 2px;
1.600     albertel 5694: }
1.795     www      5695: 
1.600     albertel 5696: div.LC_edit_problem_header,
1.602     albertel 5697: div.LC_edit_problem_header div,
1.614     albertel 5698: div.LC_edit_problem_footer,
                   5699: div.LC_edit_problem_footer div,
1.602     albertel 5700: div.LC_edit_problem_editxml_header,
                   5701: div.LC_edit_problem_editxml_header div {
1.600     albertel 5702:   margin-top: 5px;
                   5703: }
1.795     www      5704: 
1.602     albertel 5705: div.LC_edit_problem_header_edit_row {
                   5706:   background: $tabbg;
                   5707:   padding: 3px;
                   5708:   margin-bottom: 5px;
                   5709: }
1.795     www      5710: 
1.600     albertel 5711: div.LC_edit_problem_header_title {
1.705     tempelho 5712:   font-weight: bold;
                   5713:   font-size: larger;
1.602     albertel 5714:   background: $tabbg;
                   5715:   padding: 3px;
                   5716: }
1.795     www      5717: 
1.602     albertel 5718: table.LC_edit_problem_header_title {
1.705     tempelho 5719:   font-size: larger;
                   5720:   font-weight:  bold;
1.602     albertel 5721:   width: 100%;
                   5722:   border-color: $pgbg;
                   5723:   border-style: solid;
                   5724:   border-width: $border;
1.600     albertel 5725:   background: $tabbg;
1.602     albertel 5726:   border-collapse: collapse;
                   5727:   padding: 0px
                   5728: }
                   5729: 
                   5730: div.LC_edit_problem_discards {
                   5731:   float: left;
                   5732:   padding-bottom: 5px;
                   5733: }
1.795     www      5734: 
1.602     albertel 5735: div.LC_edit_problem_saves {
                   5736:   float: right;
                   5737:   padding-bottom: 5px;
1.600     albertel 5738: }
1.795     www      5739: 
1.600     albertel 5740: hr.LC_edit_problem_divide {
1.602     albertel 5741:   clear: both;
1.600     albertel 5742:   color: $tabbg;
                   5743:   background-color: $tabbg;
                   5744:   height: 3px;
                   5745:   border: 0px;
                   5746: }
1.795     www      5747: 
1.679     riegler  5748: img.stift{
1.678     riegler  5749:   border-width:0;
1.679     riegler  5750:   vertical-align:middle;
1.677     riegler  5751: }
1.680     riegler  5752: 
1.681     riegler  5753: table#LC_mainmenu{
                   5754:  margin-top:10px;
                   5755:  width:80%;
                   5756: }
                   5757: 
1.680     riegler  5758: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
                   5759:   vertical-align: top;
                   5760:   width: 45%;
                   5761: }
1.795     www      5762: 
1.779     bisitz   5763: .LC_mainmenu_fieldset_category {
                   5764:   color: $font;
                   5765:   background: $pgbg;
                   5766:   font-family: $sans;
                   5767:   font-size: small;
                   5768:   font-weight: bold;
1.777     tempelho 5769: }
1.795     www      5770: 
1.716     raeburn  5771: div.LC_createcourse {
                   5772:     margin: 10px 10px 10px 10px;
                   5773: }
                   5774: 
1.693     droeschl 5775: /* ---- Remove when done ----
                   5776: # The following styles is part of the redesign of LON-CAPA and are
                   5777: # subject to change during this project.
                   5778: # Don't rely on their current functionality as they might be 
                   5779: # changed or removed.
                   5780: # --------------------------*/
                   5781: 
1.698     harmsja  5782: a:hover,
1.721     harmsja  5783: ol.LC_smallMenu a:hover,
                   5784: ol#LC_MenuBreadcrumbs a:hover,
                   5785: ol#LC_PathBreadcrumbs a:hover,
                   5786: ul#LC_TabMainMenuContent a:hover,
                   5787: .LC_FormSectionClearButton input:hover
1.795     www      5788: ul.LC_TabContent   li:hover a {
1.698     harmsja  5789: 	color:#BF2317;
                   5790:         text-decoration:none;
1.693     droeschl 5791: }
                   5792: 
1.779     bisitz   5793: h1 {
1.721     harmsja  5794: 	padding:5px 10px 5px 20px;
1.693     droeschl 5795: 	line-height:130%;
                   5796: }
1.698     harmsja  5797: 
1.795     www      5798: h2,h3,h4,h5,h6 {
1.721     harmsja  5799: 	margin:5px 0px 5px 0px;
                   5800: 	padding:0px;
                   5801: 	line-height:130%;
1.693     droeschl 5802: }
1.795     www      5803: 
                   5804: .LC_hcell {
1.698     harmsja  5805:         padding:3px 15px 3px 15px;
                   5806:         margin:0px;
1.703     harmsja  5807: 	background-color:$tabbg;
1.801   ! tempelho 5808: 	color:$fontmenu;
1.779     bisitz   5809: 	border-bottom:solid 1px $lg_border_color;
1.693     droeschl 5810: }
1.795     www      5811: 
1.721     harmsja  5812: .LC_noBorder {
1.698     harmsja  5813:         border:0px;
                   5814: }
1.693     droeschl 5815: 
                   5816: 
1.698     harmsja  5817: /* Main Header with discription of Person, Course, etc. */
1.693     droeschl 5818: 
1.761     tempelho 5819: .LC_Right {
                   5820:         float: right;
                   5821:         margin: 0px;
                   5822:         padding: 0px;
                   5823: }
                   5824: 
1.721     harmsja  5825: .LC_FormSectionClearButton input {
1.779     bisitz   5826:         background-color:transparent;
1.698     harmsja  5827:         border:0px;
                   5828:         cursor:pointer;
                   5829:         text-decoration:underline;
1.693     droeschl 5830: }
1.763     bisitz   5831: 
                   5832: .LC_help_open_topic {
                   5833:         color: #FFFFFF;
                   5834:         background-color: #EEEEFF;
                   5835:         margin: 1px;
                   5836:         padding: 4px;
                   5837:         border: 1px solid #000033;
                   5838:         white-space: nowrap;
1.783     amueller 5839: /*		vertical-align: middle; */
1.759     neumanie 5840: }
1.693     droeschl 5841: 
1.698     harmsja  5842: dl,ul,div,fieldset {
                   5843: 	margin: 10px 10px 10px 0px;
1.693     droeschl 5844: 	overflow:hidden;
                   5845: }
1.795     www      5846: 
1.721     harmsja  5847: ol.LC_smallMenu, ol#LC_PathBreadcrumbs {
1.698     harmsja  5848: 	margin: 0px;
1.693     droeschl 5849: }
                   5850: 
1.721     harmsja  5851: ol.LC_smallMenu li {
1.693     droeschl 5852: 	display: inline;
                   5853: 	padding: 5px 5px 0px 10px;
                   5854: 	vertical-align: top;
                   5855: }
                   5856: 
1.721     harmsja  5857: ol.LC_smallMenu li img {
1.693     droeschl 5858: 	vertical-align: bottom;
                   5859: }
                   5860: 
1.721     harmsja  5861: ol.LC_smallMenu a {
1.693     droeschl 5862: 	font-size: 90%;
                   5863: 	color: RGB(80, 80, 80);
                   5864: 	text-decoration: none;
                   5865: }
1.795     www      5866: 
                   5867: ol#LC_TabMainMenuContent, 
                   5868: ul.LC_TabContent ,
1.741     harmsja  5869: ul.LC_TabContentBigger {
1.721     harmsja  5870: 	display:block;
                   5871: 	list-style:none;
1.741     harmsja  5872: 	margin: 0px;
1.693     droeschl 5873: 	padding: 0px;
                   5874: }
                   5875: 
1.795     www      5876: ol#LC_TabMainMenuContent li,
                   5877: ul.LC_TabContent li,
                   5878: ul.LC_TabContentBigger li {
1.693     droeschl 5879: 	display: inline;
1.741     harmsja  5880: 	border-right: solid 1px $lg_border_color;
                   5881: 	float:left;
                   5882: 	line-height:140%;
                   5883: 	white-space:nowrap;
                   5884: }
1.795     www      5885: 
                   5886: ol#LC_TabMainMenuContent li {
1.693     droeschl 5887: 	vertical-align: bottom;
                   5888: 	border-bottom: solid 1px RGB(175, 175, 175);
1.721     harmsja  5889: 	padding: 5px 10px 5px 10px;
1.741     harmsja  5890: 	margin-right:5px;
                   5891: 	margin-bottom:3px;
1.693     droeschl 5892: 	font-weight: bold;
1.723     riegler  5893: 	background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693     droeschl 5894: }
                   5895: 
1.795     www      5896: ol#LC_TabMainMenuContent li a {
1.693     droeschl 5897: 	color: RGB(47, 47, 47);
                   5898: 	text-decoration: none;
                   5899: }
1.795     www      5900: 
1.721     harmsja  5901: ul.LC_TabContent {
1.741     harmsja  5902: 	min-height:1.6em;
1.721     harmsja  5903: }
1.795     www      5904: 
                   5905: ul.LC_TabContent li {
1.741     harmsja  5906: 	vertical-align:middle;
                   5907: 	padding:0px 10px 0px 10px;
1.745     ehlerst  5908: 	background-color:$tabbg;
                   5909: 	border-bottom:solid 1px $lg_border_color;
1.721     harmsja  5910: }
1.795     www      5911: 
                   5912: ul.LC_TabContent li a, ul.LC_TabContent li {
1.721     harmsja  5913: 	color:rgb(47,47,47);
                   5914: 	text-decoration:none;
                   5915: 	font-size:95%;
                   5916: 	font-weight:bold;
1.761     tempelho 5917: 	padding-right: 16px;
1.721     harmsja  5918: }
1.795     www      5919: 
                   5920: ul.LC_TabContent li:hover, ul.LC_TabContent li.active {
1.761     tempelho 5921:         background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.745     ehlerst  5922: 	border-bottom:solid 1px #FFFFFF;
1.761     tempelho 5923: 	padding-right: 16px;
1.744     ehlerst  5924: }
1.795     www      5925: 
                   5926: ul.LC_TabContentBigger li {
1.741     harmsja  5927: 	vertical-align:bottom;
                   5928: 	border-top:solid 1px $lg_border_color;
                   5929: 	border-left:solid 1px $lg_border_color;
                   5930: 	padding:5px 10px 5px 10px;
                   5931: 	margin-left:2px;
                   5932: 	background:url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
                   5933: }
1.795     www      5934: 
                   5935: ul.LC_TabContentBigger li:hover, 
                   5936: ul.LC_TabContentBigger li.active {
1.744     ehlerst  5937: 	background:url(/adm/lonIcons/lightGreyBG.png) repeat-x right bottom;
                   5938: }
1.795     www      5939: 
                   5940: ul.LC_TabContentBigger li, 
                   5941: ul.LC_TabContentBigger li a {
1.741     harmsja  5942: 	font-size:110%;
                   5943: 	font-weight:bold;
                   5944: }
1.693     droeschl 5945: 
1.795     www      5946: ol#LC_MenuBreadcrumbs, 
                   5947: ol#LC_PathBreadcrumbs, 
                   5948: ul.LC_CourseBreadcrumbs {
1.693     droeschl 5949: 	border-top: solid 1px RGB(255, 255, 255);
                   5950: 	height: 20px;
                   5951: 	line-height: 20px;
                   5952: 	vertical-align: bottom;
                   5953: 	margin: 0px 0px 30px 0px;
                   5954: 	padding-left: 10px;
                   5955: 	list-style-position: inside;
1.723     riegler  5956: 	background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693     droeschl 5957: }
                   5958: 
1.795     www      5959: ol#LC_MenuBreadcrumbs li, 
                   5960: ol#LC_PathBreadcrumbs li, 
                   5961: ul.LC_CourseBreadcrumbs li {
1.741     harmsja  5962: /*
1.723     riegler  5963: 	background: url(/adm/lonIcons/arrow_white.png) no-repeat left center;
1.779     bisitz   5964: */
1.693     droeschl 5965: 	display: inline;
                   5966: 	padding: 0px 0px 0px 10px;
1.783     amueller 5967: /*	vertical-align: bottom; */
1.693     droeschl 5968: 	overflow:hidden;
                   5969: }
                   5970: 
1.783     amueller 5971: ol#LC_MenuBreadcrumbs li a, ul.LC_CourseBreadcrumbs li a {
1.693     droeschl 5972: 	text-decoration: none;
                   5973: 	font-size:90%;
                   5974: }
1.795     www      5975: 
                   5976: ol#LC_PathBreadcrumbs li a {
1.698     harmsja  5977: 	text-decoration:none;
                   5978: 	font-size:100%;
                   5979: 	font-weight:bold;
1.693     droeschl 5980: }
1.795     www      5981: 
                   5982: .LC_BoxPadding {
1.786     neumanie 5983: 	padding: 10px;
                   5984: }
1.795     www      5985: 
                   5986: .LC_ContentBoxSpecial {
1.701     harmsja  5987: 	border: solid 1px $lg_border_color;
1.746     neumanie 5988: }
1.795     www      5989: 
                   5990: .LC_ContentBoxSpecialContactInfo {
1.746     neumanie 5991: 	border: solid 1px $lg_border_color;
                   5992: 	max-width:25%;
                   5993: 	min-width:25%;
1.698     harmsja  5994: }
1.795     www      5995: 
                   5996: .LC_AboutMe_Image {
1.747     neumanie 5997: 	float:left;
                   5998: 	margin-right:10px;
                   5999: }
1.795     www      6000: 
                   6001: .LC_Clear_AboutMe_Image {
1.747     neumanie 6002: 	clear:left;
                   6003: }
1.795     www      6004: 
1.721     harmsja  6005: dl.LC_ListStyleClean dt {
1.693     droeschl 6006: 	padding-right: 5px;
                   6007: 	display: table-header-group;
                   6008: }
                   6009: 
1.721     harmsja  6010: dl.LC_ListStyleClean dd {
1.693     droeschl 6011: 	display: table-row;
                   6012: }
                   6013: 
1.721     harmsja  6014: .LC_ListStyleClean,
                   6015: .LC_ListStyleSimple,
                   6016: .LC_ListStyleNormal,
1.777     tempelho 6017: .LC_ListStyle_Border,
1.795     www      6018: .LC_ListStyleSpecial {
1.693     droeschl 6019: 	/*display:block;	*/
                   6020: 	list-style-position: inside;
                   6021: 	list-style-type: none;
                   6022: 	overflow: hidden;
                   6023: 	padding: 0px;
                   6024: }
                   6025: 
1.721     harmsja  6026: .LC_ListStyleSimple li,
                   6027: .LC_ListStyleSimple dd,
                   6028: .LC_ListStyleNormal li,
                   6029: .LC_ListStyleNormal dd,
                   6030: .LC_ListStyleSpecial li,
1.795     www      6031: .LC_ListStyleSpecial dd {
1.693     droeschl 6032: 	margin: 0px;
                   6033: 	padding: 5px 5px 5px 10px;
                   6034: 	clear: both;
                   6035: }
                   6036: 
1.721     harmsja  6037: .LC_ListStyleClean li,
                   6038: .LC_ListStyleClean dd {
1.693     droeschl 6039: 	padding-top: 0px;
                   6040: 	padding-bottom: 0px;
                   6041: }
                   6042: 
1.721     harmsja  6043: .LC_ListStyleSimple dd,
1.795     www      6044: .LC_ListStyleSimple li {
1.698     harmsja  6045: 	border-bottom: solid 1px $lg_border_color;
1.693     droeschl 6046: }
                   6047: 
1.721     harmsja  6048: .LC_ListStyleSpecial li,
                   6049: .LC_ListStyleSpecial dd {
1.693     droeschl 6050: 	list-style-type: none;
                   6051: 	background-color: RGB(220, 220, 220);
                   6052: 	margin-bottom: 4px;
                   6053: }
                   6054: 
1.721     harmsja  6055: table.LC_SimpleTable {
1.698     harmsja  6056: 	margin:5px;
                   6057: 	border:solid 1px $lg_border_color;
1.795     www      6058: }
1.693     droeschl 6059: 
1.721     harmsja  6060: table.LC_SimpleTable tr {
1.698     harmsja  6061: 	padding:0px;
                   6062: 	border:solid 1px $lg_border_color;
1.693     droeschl 6063: }
1.795     www      6064: 
                   6065: table.LC_SimpleTable thead {
1.698     harmsja  6066: 	 background:rgb(220,220,220);
1.693     droeschl 6067: }
                   6068: 
1.721     harmsja  6069: div.LC_columnSection {
1.693     droeschl 6070: 	display: block;
                   6071: 	clear: both;
                   6072: 	overflow: hidden;
                   6073: 	margin:0px;
                   6074: }
                   6075: 
1.721     harmsja  6076: div.LC_columnSection>* {
1.693     droeschl 6077: 	float: left;
                   6078: 	margin: 10px 20px 10px 0px;
1.747     neumanie 6079: 	overflow:hidden;
1.693     droeschl 6080: }
1.721     harmsja  6081: 
1.795     www      6082: .ContentBoxSpecialTemplate {
1.747     neumanie 6083:         border: solid 1px $lg_border_color;
1.719     ehlerst  6084: }
1.795     www      6085: 
1.719     ehlerst  6086: .ContentBoxTemplate {
                   6087:         padding:10px;
                   6088: }
                   6089: 
1.721     harmsja  6090: div.LC_columnSection > .ContentBoxTemplate,
1.795     www      6091: div.LC_columnSection > .ContentBoxSpecialTemplate {
1.719     ehlerst  6092:         width: 600px;
                   6093: }
1.753     droeschl 6094: 
1.795     www      6095: .clear {
1.720     ehlerst  6096: 	clear: both;
                   6097: 	line-height: 0px;
                   6098: 	font-size: 0px;
                   6099: 	height: 0px;
                   6100: }
1.693     droeschl 6101: 
1.694     tempelho 6102: .LC_loginpage_container {
                   6103: 	text-align:left;
                   6104: 	margin : 0 auto;
1.785     tempelho 6105: 	width:90%;
1.694     tempelho 6106: 	padding: 10px;
                   6107: 	height: auto;
1.712     muellerd 6108: 	background-color:#FFFFFF;
1.694     tempelho 6109: 	border:1px solid #CCCCCC;
                   6110: }
                   6111: 
                   6112: 
                   6113: .LC_loginpage_loginContainer {
                   6114: 	float:left;
1.712     muellerd 6115: 	width: 182px;
1.785     tempelho 6116: 	padding: 2px;
1.712     muellerd 6117: 	border:1px solid #CCCCCC;
                   6118: 	background-color:$loginbg;
1.694     tempelho 6119: }
                   6120: 
1.795     www      6121: .LC_loginpage_loginContainer h2 {
1.712     muellerd 6122: 	margin-top:0;
                   6123: 	display:block;
                   6124: 	background:$bgcol;
                   6125: 	color:$textcol;
                   6126: 	padding-left:5px;
                   6127: }
1.785     tempelho 6128: 
1.694     tempelho 6129: .LC_loginpage_loginInfo {
                   6130: 	float:left;
1.785     tempelho 6131: 	width:182px;
1.694     tempelho 6132: 	border:1px solid #CCCCCC;
1.785     tempelho 6133: 	padding:2px;
1.712     muellerd 6134: }
                   6135: 
1.694     tempelho 6136: .LC_loginpage_space {
1.754     droeschl 6137: 	clear: both;
                   6138: 	margin-bottom: 20px;
1.694     tempelho 6139: 	border-bottom: 1px solid #CCCCCC;
                   6140: }
                   6141: 
1.785     tempelho 6142: .LC_loginpage_floatLeft {
                   6143: 	float: left;
                   6144: 	width: 200px;
                   6145: 	margin: 0;
                   6146: }
                   6147: 
1.795     www      6148: table em {
1.754     droeschl 6149: 	font-weight: bold;
                   6150: 	font-style: normal;
1.748     schulted 6151: }
1.795     www      6152: 
1.779     bisitz   6153: table.LC_tableBrowseRes,
1.795     www      6154: table.LC_tableOfContent {
1.769     schulted 6155:         border:none;
                   6156: 	border-spacing: 1;
1.754     droeschl 6157: 	padding: 3px;
                   6158: 	background-color: #FFFFFF;
                   6159: 	font-size: 90%;
1.753     droeschl 6160: }
1.789     droeschl 6161: 
                   6162: table.LC_tableOfContent{
                   6163:     border-collapse: collapse;
                   6164: }
                   6165: 
1.771     droeschl 6166: table.LC_tableBrowseRes a,
1.768     schulted 6167: table.LC_tableOfContent a {
1.771     droeschl 6168:         background-color: transparent;
1.753     droeschl 6169: 	text-decoration: none;
                   6170: }
                   6171: 
1.771     droeschl 6172: table.LC_tableBrowseRes tr.LC_trOdd,
1.768     schulted 6173: table.LC_tableOfContent tr.LC_trOdd{
1.754     droeschl 6174: 	background-color: #EEEEEE;
1.753     droeschl 6175: }
                   6176: 
1.795     www      6177: table.LC_tableOfContent img {
1.753     droeschl 6178: 	border: none;
                   6179: 	height: 1.3em;
                   6180: 	vertical-align: text-bottom;
                   6181: 	margin-right: 0.3em;
                   6182: }
1.757     schulted 6183: 
1.795     www      6184: a#LC_content_toolbar_firsthomework {
1.774     ehlerst  6185: 	background-image:url(/res/adm/pages/open-first-problem.gif);
                   6186: }
                   6187: 
1.795     www      6188: a#LC_content_toolbar_launchnav {
1.774     ehlerst  6189: 	background-image:url(/res/adm/pages/start-navigation.gif);
                   6190: }
                   6191: 
1.795     www      6192: a#LC_content_toolbar_closenav {
1.774     ehlerst  6193: 	background-image:url(/res/adm/pages/close-navigation.gif);
                   6194: }
                   6195: 
1.795     www      6196: a#LC_content_toolbar_everything {
1.774     ehlerst  6197: 	background-image:url(/res/adm/pages/show-all.gif);
                   6198: }
                   6199: 
1.795     www      6200: a#LC_content_toolbar_uncompleted {
1.774     ehlerst  6201: 	background-image:url(/res/adm/pages/show-incomplete-problems.gif);
                   6202: }
                   6203: 
1.795     www      6204: #LC_content_toolbar_clearbubbles {
1.774     ehlerst  6205: 	background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
                   6206: }
                   6207: 
1.795     www      6208: a#LC_content_toolbar_changefolder {
1.757     schulted 6209: 	background : url(/res/adm/pages/close-all-folders.gif) top center ;
                   6210: }
                   6211: 
1.795     www      6212: a#LC_content_toolbar_changefolder_toggled {
1.757     schulted 6213: 	background-image:url(/res/adm/pages/open-all-folders.gif);
                   6214: }
                   6215: 
1.795     www      6216: ul#LC_toolbar li a:hover {
1.757     schulted 6217: 	background-position: bottom center;
                   6218: }
                   6219: 
1.795     www      6220: ul#LC_toolbar {
1.779     bisitz   6221: 	padding:0;
1.757     schulted 6222: 	margin: 2px;
                   6223: 	list-style:none;
                   6224: 	position:relative;
                   6225: 	background-color:white;
                   6226: }
                   6227: 
1.795     www      6228: ul#LC_toolbar li {
1.757     schulted 6229: 	border:1px solid white;
                   6230: 	padding:0;
                   6231: 	margin: 0;
1.795     www      6232:         float: left;
1.767     droeschl 6233: 	display:inline;
1.757     schulted 6234: 	vertical-align:middle;
1.795     www      6235: } 
1.757     schulted 6236: 
1.783     amueller 6237: 
1.795     www      6238: a.LC_toolbarItem {
1.767     droeschl 6239: 	display:block;
1.757     schulted 6240: 	padding:0;
                   6241: 	margin:0;
                   6242: 	height: 32px;
                   6243: 	width: 32px;
1.779     bisitz   6244: 	color:white;
                   6245: 	border:0 none;
1.757     schulted 6246: 	background-repeat:no-repeat;
                   6247: 	background-color:transparent;
                   6248: }
                   6249: 
1.782     bisitz   6250: ul.LC_functionslist li {
                   6251:   float: left;
                   6252:   white-space: nowrap;
                   6253:   height: 35px; /* at least as high as heighest list item */
                   6254:   margin: 0px 15px 15px 10px;
                   6255: }
                   6256: 
1.757     schulted 6257: 
1.343     albertel 6258: END
                   6259: }
                   6260: 
1.306     albertel 6261: =pod
                   6262: 
                   6263: =item * &headtag()
                   6264: 
                   6265: Returns a uniform footer for LON-CAPA web pages.
                   6266: 
1.307     albertel 6267: Inputs: $title - optional title for the head
                   6268:         $head_extra - optional extra HTML to put inside the <head>
1.315     albertel 6269:         $args - optional arguments
1.319     albertel 6270:             force_register - if is true call registerurl so the remote is 
                   6271:                              informed
1.415     albertel 6272:             redirect       -> array ref of
                   6273:                                    1- seconds before redirect occurs
                   6274:                                    2- url to redirect to
                   6275:                                    3- whether the side effect should occur
1.315     albertel 6276:                            (side effect of setting 
                   6277:                                $env{'internal.head.redirect'} to the url 
                   6278:                                redirected too)
1.352     albertel 6279:             domain         -> force to color decorate a page for a specific
                   6280:                                domain
                   6281:             function       -> force usage of a specific rolish color scheme
                   6282:             bgcolor        -> override the default page bgcolor
1.460     albertel 6283:             no_auto_mt_title
                   6284:                            -> prevent &mt()ing the title arg
1.464     albertel 6285: 
1.306     albertel 6286: =cut
                   6287: 
                   6288: sub headtag {
1.313     albertel 6289:     my ($title,$head_extra,$args) = @_;
1.306     albertel 6290:     
1.363     albertel 6291:     my $function = $args->{'function'} || &get_users_function();
                   6292:     my $domain   = $args->{'domain'}   || &determinedomain();
                   6293:     my $bgcolor  = $args->{'bgcolor'}  || &designparm($function.'.pgbg',$domain);
1.418     albertel 6294:     my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458     albertel 6295: 		   $Apache::lonnet::perlvar{'lonVersion'},
1.531     albertel 6296: 		   #time(),
1.418     albertel 6297: 		   $env{'environment.color.timestamp'},
1.363     albertel 6298: 		   $function,$domain,$bgcolor);
                   6299: 
1.369     www      6300:     $url = '/adm/css/'.&escape($url).'.css';
1.363     albertel 6301: 
1.308     albertel 6302:     my $result =
                   6303: 	'<head>'.
1.461     albertel 6304: 	&font_settings();
1.319     albertel 6305: 
1.461     albertel 6306:     if (!$args->{'frameset'}) {
                   6307: 	$result .= &Apache::lonhtmlcommon::htmlareaheaders();
                   6308:     }
1.319     albertel 6309:     if ($args->{'force_register'}) {
                   6310: 	$result .= &Apache::lonmenu::registerurl(1);
                   6311:     }
1.436     albertel 6312:     if (!$args->{'no_nav_bar'} 
                   6313: 	&& !$args->{'only_body'}
                   6314: 	&& !$args->{'frameset'}) {
                   6315: 	$result .= &help_menu_js();
                   6316:     }
1.319     albertel 6317: 
1.314     albertel 6318:     if (ref($args->{'redirect'})) {
1.414     albertel 6319: 	my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315     albertel 6320: 	$url = &Apache::lonenc::check_encrypt($url);
1.414     albertel 6321: 	if (!$inhibit_continue) {
                   6322: 	    $env{'internal.head.redirect'} = $url;
                   6323: 	}
1.313     albertel 6324: 	$result.=<<ADDMETA
                   6325: <meta http-equiv="pragma" content="no-cache" />
1.344     albertel 6326: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313     albertel 6327: ADDMETA
                   6328:     }
1.306     albertel 6329:     if (!defined($title)) {
                   6330: 	$title = 'The LearningOnline Network with CAPA';
                   6331:     }
1.460     albertel 6332:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
                   6333:     $result .= '<title> LON-CAPA '.$title.'</title>'
1.414     albertel 6334: 	.'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
                   6335: 	.$head_extra;
1.306     albertel 6336:     return $result;
                   6337: }
                   6338: 
                   6339: =pod
                   6340: 
1.340     albertel 6341: =item * &font_settings()
                   6342: 
                   6343: Returns neccessary <meta> to set the proper encoding
                   6344: 
                   6345: Inputs: none
                   6346: 
                   6347: =cut
                   6348: 
                   6349: sub font_settings {
                   6350:     my $headerstring='';
1.647     www      6351:     if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340     albertel 6352: 	$headerstring.=
                   6353: 	    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
                   6354:     }
                   6355:     return $headerstring;
                   6356: }
                   6357: 
1.341     albertel 6358: =pod
                   6359: 
                   6360: =item * &xml_begin()
                   6361: 
                   6362: Returns the needed doctype and <html>
                   6363: 
                   6364: Inputs: none
                   6365: 
                   6366: =cut
                   6367: 
                   6368: sub xml_begin {
                   6369:     my $output='';
                   6370: 
1.592     albertel 6371:     if ($env{'internal.start_page'}==1) {
                   6372: 	&Apache::lonhtmlcommon::init_htmlareafields();
                   6373:     }
1.342     albertel 6374: 
1.341     albertel 6375:     if ($env{'browser.mathml'}) {
                   6376: 	$output='<?xml version="1.0"?>'
                   6377:             #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
                   6378: #            .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
                   6379:             
                   6380: #	    .'<!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">] >'
                   6381: 	    .'<!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">'
                   6382:             .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" ' 
                   6383: 	    .'xmlns="http://www.w3.org/1999/xhtml">';
                   6384:     } else {
                   6385: 	$output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
                   6386:     }
                   6387:     return $output;
                   6388: }
1.340     albertel 6389: 
                   6390: =pod
                   6391: 
1.306     albertel 6392: =item * &endheadtag()
                   6393: 
                   6394: Returns a uniform </head> for LON-CAPA web pages.
                   6395: 
                   6396: Inputs: none
                   6397: 
                   6398: =cut
                   6399: 
                   6400: sub endheadtag {
                   6401:     return '</head>';
                   6402: }
                   6403: 
                   6404: =pod
                   6405: 
                   6406: =item * &head()
                   6407: 
                   6408: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
                   6409: 
1.648     raeburn  6410: Inputs:
                   6411: 
                   6412: =over 4
                   6413: 
                   6414: $title - optional title for the page
                   6415: 
                   6416: $head_extra - optional extra HTML to put inside the <head>
                   6417: 
                   6418: =back
1.405     albertel 6419: 
1.306     albertel 6420: =cut
                   6421: 
                   6422: sub head {
1.325     albertel 6423:     my ($title,$head_extra,$args) = @_;
                   6424:     return &headtag($title,$head_extra,$args).&endheadtag();
1.306     albertel 6425: }
                   6426: 
                   6427: =pod
                   6428: 
                   6429: =item * &start_page()
                   6430: 
                   6431: Returns a complete <html> .. <body> section for LON-CAPA web pages.
                   6432: 
1.648     raeburn  6433: Inputs:
                   6434: 
                   6435: =over 4
                   6436: 
                   6437: $title - optional title for the page
                   6438: 
                   6439: $head_extra - optional extra HTML to incude inside the <head>
                   6440: 
                   6441: $args - additional optional args supported are:
                   6442: 
                   6443: =over 8
                   6444: 
                   6445:              only_body      -> is true will set &bodytag() onlybodytag
1.317     albertel 6446:                                     arg on
1.648     raeburn  6447:              no_nav_bar     -> is true will set &bodytag() notopbar arg on
                   6448:              add_entries    -> additional attributes to add to the  <body>
                   6449:              domain         -> force to color decorate a page for a 
1.317     albertel 6450:                                     specific domain
1.648     raeburn  6451:              function       -> force usage of a specific rolish color
1.317     albertel 6452:                                     scheme
1.648     raeburn  6453:              redirect       -> see &headtag()
                   6454:              bgcolor        -> override the default page bg color
                   6455:              js_ready       -> return a string ready for being used in 
1.317     albertel 6456:                                     a javascript writeln
1.648     raeburn  6457:              html_encode    -> return a string ready for being used in 
1.320     albertel 6458:                                     a html attribute
1.648     raeburn  6459:              force_register -> if is true will turn on the &bodytag()
1.317     albertel 6460:                                     $forcereg arg
1.648     raeburn  6461:              body_title     -> alternate text to use instead of $title
1.326     albertel 6462:                                     in the title box that appears, this text
                   6463:                                     is not auto translated like the $title is
1.648     raeburn  6464:              frameset       -> if true will start with a <frameset>
1.330     albertel 6465:                                     rather than <body>
1.648     raeburn  6466:              no_title       -> if true the title bar won't be shown
                   6467:              skip_phases    -> hash ref of 
1.338     albertel 6468:                                     head -> skip the <html><head> generation
                   6469:                                     body -> skip all <body> generation
1.648     raeburn  6470:              no_inline_link -> if true and in remote mode, don't show the 
1.361     albertel 6471:                                     'Switch To Inline Menu' link
1.648     raeburn  6472:              no_auto_mt_title -> prevent &mt()ing the title arg
                   6473:              inherit_jsmath -> when creating popup window in a page,
                   6474:                                     should it have jsmath forced on by the
                   6475:                                     current page
1.361     albertel 6476: 
1.648     raeburn  6477: =back
1.460     albertel 6478: 
1.648     raeburn  6479: =back
1.562     albertel 6480: 
1.306     albertel 6481: =cut
                   6482: 
                   6483: sub start_page {
1.309     albertel 6484:     my ($title,$head_extra,$args) = @_;
1.318     albertel 6485:     #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313     albertel 6486:     my %head_args;
1.352     albertel 6487:     foreach my $arg ('redirect','force_register','domain','function',
1.460     albertel 6488: 		     'bgcolor','frameset','no_nav_bar','only_body',
                   6489: 		     'no_auto_mt_title') {
1.319     albertel 6490: 	if (defined($args->{$arg})) {
1.324     raeburn  6491: 	    $head_args{$arg} = $args->{$arg};
1.319     albertel 6492: 	}
1.313     albertel 6493:     }
1.319     albertel 6494: 
1.315     albertel 6495:     $env{'internal.start_page'}++;
1.338     albertel 6496:     my $result;
                   6497:     if (! exists($args->{'skip_phases'}{'head'}) ) {
                   6498: 	$result.=
1.341     albertel 6499: 	    &xml_begin().
1.338     albertel 6500: 	    &headtag($title,$head_extra,\%head_args).&endheadtag();
                   6501:     }
                   6502:     
                   6503:     if (! exists($args->{'skip_phases'}{'body'}) ) {
                   6504: 	if ($args->{'frameset'}) {
                   6505: 	    my $attr_string = &make_attr_string($args->{'force_register'},
                   6506: 						$args->{'add_entries'});
                   6507: 	    $result .= "\n<frameset $attr_string>\n";
                   6508: 	} else {
                   6509: 	    $result .=
                   6510: 		&bodytag($title, 
                   6511: 			 $args->{'function'},       $args->{'add_entries'},
                   6512: 			 $args->{'only_body'},      $args->{'domain'},
                   6513: 			 $args->{'force_register'}, $args->{'body_title'},
                   6514: 			 $args->{'no_nav_bar'},     $args->{'bgcolor'},
1.460     albertel 6515: 			 $args->{'no_title'},       $args->{'no_inline_link'},
                   6516: 			 $args);
1.338     albertel 6517: 	}
1.330     albertel 6518:     }
1.338     albertel 6519: 
1.315     albertel 6520:     if ($args->{'js_ready'}) {
1.713     kaisler  6521: 		$result = &js_ready($result);
1.315     albertel 6522:     }
1.320     albertel 6523:     if ($args->{'html_encode'}) {
1.713     kaisler  6524: 		$result = &html_encode($result);
                   6525:     }
                   6526: 
1.758     kaisler  6527: 	#Breadcrumbs
                   6528:     if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
                   6529: 		&Apache::lonhtmlcommon::clear_breadcrumbs();
                   6530: 		#if any br links exists, add them to the breadcrumbs
                   6531: 		if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {         
                   6532: 			foreach my $crumb (@{$args->{'bread_crumbs'}}){
                   6533: 				&Apache::lonhtmlcommon::add_breadcrumb($crumb);
                   6534: 			}
                   6535: 		}
                   6536: 
                   6537: 		#if bread_crumbs_component exists show it as headline else show only the breadcrumbs
                   6538: 		if(exists($args->{'bread_crumbs_component'})){
                   6539: 			$result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
                   6540: 		}else{
                   6541: 			$result .= &Apache::lonhtmlcommon::breadcrumbs();
                   6542: 		}
1.320     albertel 6543:     }
1.315     albertel 6544:     return $result;
1.306     albertel 6545: }
                   6546: 
1.330     albertel 6547: 
1.306     albertel 6548: =pod
                   6549: 
                   6550: =item * &head()
                   6551: 
                   6552: Returns a complete </body></html> section for LON-CAPA web pages.
                   6553: 
1.315     albertel 6554: Inputs:         $args - additional optional args supported are:
                   6555:                  js_ready     -> return a string ready for being used in 
                   6556:                                  a javascript writeln
1.320     albertel 6557:                  html_encode  -> return a string ready for being used in 
                   6558:                                  a html attribute
1.330     albertel 6559:                  frameset     -> if true will start with a <frameset>
                   6560:                                  rather than <body>
1.493     albertel 6561:                  dicsussion   -> if true will get discussion from
                   6562:                                   lonxml::xmlend
                   6563:                                  (you can pass the target and parser arguments
                   6564:                                   through optional 'target' and 'parser' args
                   6565:                                   to this routine)
1.306     albertel 6566: 
                   6567: =cut
                   6568: 
                   6569: sub end_page {
1.315     albertel 6570:     my ($args) = @_;
                   6571:     $env{'internal.end_page'}++;
1.330     albertel 6572:     my $result;
1.335     albertel 6573:     if ($args->{'discussion'}) {
                   6574: 	my ($target,$parser);
                   6575: 	if (ref($args->{'discussion'})) {
                   6576: 	    ($target,$parser) =($args->{'discussion'}{'target'},
                   6577: 				$args->{'discussion'}{'parser'});
                   6578: 	}
                   6579: 	$result .= &Apache::lonxml::xmlend($target,$parser);
                   6580:     }
                   6581: 
1.330     albertel 6582:     if ($args->{'frameset'}) {
                   6583: 	$result .= '</frameset>';
                   6584:     } else {
1.635     raeburn  6585: 	$result .= &endbodytag($args);
1.330     albertel 6586:     }
                   6587:     $result .= "\n</html>";
                   6588: 
1.315     albertel 6589:     if ($args->{'js_ready'}) {
1.317     albertel 6590: 	$result = &js_ready($result);
1.315     albertel 6591:     }
1.335     albertel 6592: 
1.320     albertel 6593:     if ($args->{'html_encode'}) {
                   6594: 	$result = &html_encode($result);
                   6595:     }
1.335     albertel 6596: 
1.315     albertel 6597:     return $result;
                   6598: }
                   6599: 
1.320     albertel 6600: sub html_encode {
                   6601:     my ($result) = @_;
                   6602: 
1.322     albertel 6603:     $result = &HTML::Entities::encode($result,'<>&"');
1.320     albertel 6604:     
                   6605:     return $result;
                   6606: }
1.317     albertel 6607: sub js_ready {
                   6608:     my ($result) = @_;
                   6609: 
1.323     albertel 6610:     $result =~ s/[\n\r]/ /xmsg;
                   6611:     $result =~ s/\\/\\\\/xmsg;
                   6612:     $result =~ s/'/\\'/xmsg;
1.372     albertel 6613:     $result =~ s{</}{<\\/}xmsg;
1.317     albertel 6614:     
                   6615:     return $result;
                   6616: }
                   6617: 
1.315     albertel 6618: sub validate_page {
                   6619:     if (  exists($env{'internal.start_page'})
1.316     albertel 6620: 	  &&     $env{'internal.start_page'} > 1) {
                   6621: 	&Apache::lonnet::logthis('start_page called multiple times '.
1.318     albertel 6622: 				 $env{'internal.start_page'}.' '.
1.316     albertel 6623: 				 $ENV{'request.filename'});
1.315     albertel 6624:     }
                   6625:     if (  exists($env{'internal.end_page'})
1.316     albertel 6626: 	  &&     $env{'internal.end_page'} > 1) {
                   6627: 	&Apache::lonnet::logthis('end_page called multiple times '.
1.318     albertel 6628: 				 $env{'internal.end_page'}.' '.
1.316     albertel 6629: 				 $env{'request.filename'});
1.315     albertel 6630:     }
                   6631:     if (     exists($env{'internal.start_page'})
                   6632: 	&& ! exists($env{'internal.end_page'})) {
1.316     albertel 6633: 	&Apache::lonnet::logthis('start_page called without end_page '.
                   6634: 				 $env{'request.filename'});
1.315     albertel 6635:     }
                   6636:     if (   ! exists($env{'internal.start_page'})
                   6637: 	&&   exists($env{'internal.end_page'})) {
1.316     albertel 6638: 	&Apache::lonnet::logthis('end_page called without start_page'.
                   6639: 				 $env{'request.filename'});
1.315     albertel 6640:     }
1.306     albertel 6641: }
1.315     albertel 6642: 
1.318     albertel 6643: sub simple_error_page {
                   6644:     my ($r,$title,$msg) = @_;
                   6645:     my $page =
                   6646: 	&Apache::loncommon::start_page($title).
                   6647: 	&mt($msg).
                   6648: 	&Apache::loncommon::end_page();
                   6649:     if (ref($r)) {
                   6650: 	$r->print($page);
1.327     albertel 6651: 	return;
1.318     albertel 6652:     }
                   6653:     return $page;
                   6654: }
1.347     albertel 6655: 
                   6656: {
1.610     albertel 6657:     my @row_count;
1.347     albertel 6658:     sub start_data_table {
1.422     albertel 6659: 	my ($add_class) = @_;
                   6660: 	my $css_class = (join(' ','LC_data_table',$add_class));
1.610     albertel 6661: 	unshift(@row_count,0);
1.422     albertel 6662: 	return '<table class="'.$css_class.'">'."\n";
1.347     albertel 6663:     }
                   6664: 
                   6665:     sub end_data_table {
1.610     albertel 6666: 	shift(@row_count);
1.389     albertel 6667: 	return '</table>'."\n";;
1.347     albertel 6668:     }
                   6669: 
                   6670:     sub start_data_table_row {
1.422     albertel 6671: 	my ($add_class) = @_;
1.610     albertel 6672: 	$row_count[0]++;
                   6673: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428     albertel 6674: 	$css_class = (join(' ',$css_class,$add_class));
1.422     albertel 6675: 	return  '<tr class="'.$css_class.'">'."\n";;
1.347     albertel 6676:     }
1.471     banghart 6677:     
                   6678:     sub continue_data_table_row {
                   6679: 	my ($add_class) = @_;
1.610     albertel 6680: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471     banghart 6681: 	$css_class = (join(' ',$css_class,$add_class));
                   6682: 	return  '<tr class="'.$css_class.'">'."\n";;
                   6683:     }
1.347     albertel 6684: 
                   6685:     sub end_data_table_row {
1.389     albertel 6686: 	return '</tr>'."\n";;
1.347     albertel 6687:     }
1.367     www      6688: 
1.421     albertel 6689:     sub start_data_table_empty_row {
1.707     bisitz   6690: #	$row_count[0]++;
1.421     albertel 6691: 	return  '<tr class="LC_empty_row" >'."\n";;
                   6692:     }
                   6693: 
                   6694:     sub end_data_table_empty_row {
                   6695: 	return '</tr>'."\n";;
                   6696:     }
                   6697: 
1.367     www      6698:     sub start_data_table_header_row {
1.389     albertel 6699: 	return  '<tr class="LC_header_row">'."\n";;
1.367     www      6700:     }
                   6701: 
                   6702:     sub end_data_table_header_row {
1.389     albertel 6703: 	return '</tr>'."\n";;
1.367     www      6704:     }
1.347     albertel 6705: }
                   6706: 
1.548     albertel 6707: =pod
                   6708: 
                   6709: =item * &inhibit_menu_check($arg)
                   6710: 
                   6711: Checks for a inhibitmenu state and generates output to preserve it
                   6712: 
                   6713: Inputs:         $arg - can be any of
                   6714:                      - undef - in which case the return value is a string 
                   6715:                                to add  into arguments list of a uri
                   6716:                      - 'input' - in which case the return value is a HTML
                   6717:                                  <form> <input> field of type hidden to
                   6718:                                  preserve the value
                   6719:                      - a url - in which case the return value is the url with
                   6720:                                the neccesary cgi args added to preserve the
                   6721:                                inhibitmenu state
                   6722:                      - a ref to a url - no return value, but the string is
                   6723:                                         updated to include the neccessary cgi
                   6724:                                         args to preserve the inhibitmenu state
                   6725: 
                   6726: =cut
                   6727: 
                   6728: sub inhibit_menu_check {
                   6729:     my ($arg) = @_;
                   6730:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   6731:     if ($arg eq 'input') {
                   6732: 	if ($env{'form.inhibitmenu'}) {
                   6733: 	    return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
                   6734: 	} else {
                   6735: 	    return
                   6736: 	}
                   6737:     }
                   6738:     if ($env{'form.inhibitmenu'}) {
                   6739: 	if (ref($arg)) {
                   6740: 	    $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   6741: 	} elsif ($arg eq '') {
                   6742: 	    $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
                   6743: 	} else {
                   6744: 	    $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   6745: 	}
                   6746:     }
                   6747:     if (!ref($arg)) {
                   6748: 	return $arg;
                   6749:     }
                   6750: }
                   6751: 
1.251     albertel 6752: ###############################################
1.182     matthew  6753: 
                   6754: =pod
                   6755: 
1.549     albertel 6756: =back
                   6757: 
                   6758: =head1 User Information Routines
                   6759: 
                   6760: =over 4
                   6761: 
1.405     albertel 6762: =item * &get_users_function()
1.182     matthew  6763: 
                   6764: Used by &bodytag to determine the current users primary role.
                   6765: Returns either 'student','coordinator','admin', or 'author'.
                   6766: 
                   6767: =cut
                   6768: 
                   6769: ###############################################
                   6770: sub get_users_function {
                   6771:     my $function = 'student';
1.258     albertel 6772:     if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182     matthew  6773:         $function='coordinator';
                   6774:     }
1.258     albertel 6775:     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182     matthew  6776:         $function='admin';
                   6777:     }
1.258     albertel 6778:     if (($env{'request.role'}=~/^(au|ca)/) ||
1.182     matthew  6779:         ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
                   6780:         $function='author';
                   6781:     }
                   6782:     return $function;
1.54      www      6783: }
1.99      www      6784: 
                   6785: ###############################################
                   6786: 
1.233     raeburn  6787: =pod
                   6788: 
1.542     raeburn  6789: =item * &check_user_status()
1.274     raeburn  6790: 
                   6791: Determines current status of supplied role for a
                   6792: specific user. Roles can be active, previous or future.
                   6793: 
                   6794: Inputs: 
                   6795: user's domain, user's username, course's domain,
1.375     raeburn  6796: course's number, optional section ID.
1.274     raeburn  6797: 
                   6798: Outputs:
                   6799: role status: active, previous or future. 
                   6800: 
                   6801: =cut
                   6802: 
                   6803: sub check_user_status {
1.412     raeburn  6804:     my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274     raeburn  6805:     my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
                   6806:     my @uroles = keys %userinfo;
                   6807:     my $srchstr;
                   6808:     my $active_chk = 'none';
1.412     raeburn  6809:     my $now = time;
1.274     raeburn  6810:     if (@uroles > 0) {
1.412     raeburn  6811:         if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274     raeburn  6812:             $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
                   6813:         } else {
1.412     raeburn  6814:             $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
                   6815:         }
                   6816:         if (grep/^\Q$srchstr\E$/,@uroles) {
1.274     raeburn  6817:             my $role_end = 0;
                   6818:             my $role_start = 0;
                   6819:             $active_chk = 'active';
1.412     raeburn  6820:             if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
                   6821:                 $role_end = $1;
                   6822:                 if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
                   6823:                     $role_start = $1;
1.274     raeburn  6824:                 }
                   6825:             }
                   6826:             if ($role_start > 0) {
1.412     raeburn  6827:                 if ($now < $role_start) {
1.274     raeburn  6828:                     $active_chk = 'future';
                   6829:                 }
                   6830:             }
                   6831:             if ($role_end > 0) {
1.412     raeburn  6832:                 if ($now > $role_end) {
1.274     raeburn  6833:                     $active_chk = 'previous';
                   6834:                 }
                   6835:             }
                   6836:         }
                   6837:     }
                   6838:     return $active_chk;
                   6839: }
                   6840: 
                   6841: ###############################################
                   6842: 
                   6843: =pod
                   6844: 
1.405     albertel 6845: =item * &get_sections()
1.233     raeburn  6846: 
                   6847: Determines all the sections for a course including
                   6848: sections with students and sections containing other roles.
1.419     raeburn  6849: Incoming parameters: 
                   6850: 
                   6851: 1. domain
                   6852: 2. course number 
                   6853: 3. reference to array containing roles for which sections should 
                   6854: be gathered (optional).
                   6855: 4. reference to array containing status types for which sections 
                   6856: should be gathered (optional).
                   6857: 
                   6858: If the third argument is undefined, sections are gathered for any role. 
                   6859: If the fourth argument is undefined, sections are gathered for any status.
                   6860: Permissible values are 'active' or 'future' or 'previous'.
1.233     raeburn  6861:  
1.374     raeburn  6862: Returns section hash (keys are section IDs, values are
                   6863: number of users in each section), subject to the
1.419     raeburn  6864: optional roles filter, optional status filter 
1.233     raeburn  6865: 
                   6866: =cut
                   6867: 
                   6868: ###############################################
                   6869: sub get_sections {
1.419     raeburn  6870:     my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366     albertel 6871:     if (!defined($cdom) || !defined($cnum)) {
                   6872:         my $cid =  $env{'request.course.id'};
                   6873: 
                   6874: 	return if (!defined($cid));
                   6875: 
                   6876:         $cdom = $env{'course.'.$cid.'.domain'};
                   6877:         $cnum = $env{'course.'.$cid.'.num'};
                   6878:     }
                   6879: 
                   6880:     my %sectioncount;
1.419     raeburn  6881:     my $now = time;
1.240     albertel 6882: 
1.366     albertel 6883:     if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276     albertel 6884: 	my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240     albertel 6885: 	my $sec_index = &Apache::loncoursedata::CL_SECTION();
                   6886: 	my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419     raeburn  6887:         my $start_index = &Apache::loncoursedata::CL_START();
                   6888:         my $end_index = &Apache::loncoursedata::CL_END();
                   6889:         my $status;
1.366     albertel 6890: 	while (my ($student,$data) = each(%$classlist)) {
1.419     raeburn  6891: 	    my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
                   6892: 				                     $data->[$status_index],
                   6893:                                                      $data->[$start_index],
                   6894:                                                      $data->[$end_index]);
                   6895:             if ($stu_status eq 'Active') {
                   6896:                 $status = 'active';
                   6897:             } elsif ($end < $now) {
                   6898:                 $status = 'previous';
                   6899:             } elsif ($start > $now) {
                   6900:                 $status = 'future';
                   6901:             } 
                   6902: 	    if ($section ne '-1' && $section !~ /^\s*$/) {
                   6903:                 if ((!defined($possible_status)) || (($status ne '') && 
                   6904:                     (grep/^\Q$status\E$/,@{$possible_status}))) { 
                   6905: 		    $sectioncount{$section}++;
                   6906:                 }
1.240     albertel 6907: 	    }
                   6908: 	}
                   6909:     }
                   6910:     my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   6911:     foreach my $user (sort(keys(%courseroles))) {
                   6912: 	if ($user !~ /^(\w{2})/) { next; }
                   6913: 	my ($role) = ($user =~ /^(\w{2})/);
                   6914: 	if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419     raeburn  6915: 	my ($section,$status);
1.240     albertel 6916: 	if ($role eq 'cr' &&
                   6917: 	    $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
                   6918: 	    $section=$1;
                   6919: 	}
                   6920: 	if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
                   6921: 	if (!defined($section) || $section eq '-1') { next; }
1.419     raeburn  6922:         my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
                   6923:         if ($end == -1 && $start == -1) {
                   6924:             next; #deleted role
                   6925:         }
                   6926:         if (!defined($possible_status)) { 
                   6927:             $sectioncount{$section}++;
                   6928:         } else {
                   6929:             if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
                   6930:                 $status = 'active';
                   6931:             } elsif ($end < $now) {
                   6932:                 $status = 'future';
                   6933:             } elsif ($start > $now) {
                   6934:                 $status = 'previous';
                   6935:             }
                   6936:             if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
                   6937:                 $sectioncount{$section}++;
                   6938:             }
                   6939:         }
1.233     raeburn  6940:     }
1.366     albertel 6941:     return %sectioncount;
1.233     raeburn  6942: }
                   6943: 
1.274     raeburn  6944: ###############################################
1.294     raeburn  6945: 
                   6946: =pod
1.405     albertel 6947: 
                   6948: =item * &get_course_users()
                   6949: 
1.275     raeburn  6950: Retrieves usernames:domains for users in the specified course
                   6951: with specific role(s), and access status. 
                   6952: 
                   6953: Incoming parameters:
1.277     albertel 6954: 1. course domain
                   6955: 2. course number
                   6956: 3. access status: users must have - either active, 
1.275     raeburn  6957: previous, future, or all.
1.277     albertel 6958: 4. reference to array of permissible roles
1.288     raeburn  6959: 5. reference to array of section restrictions (optional)
                   6960: 6. reference to results object (hash of hashes).
                   6961: 7. reference to optional userdata hash
1.609     raeburn  6962: 8. reference to optional statushash
1.630     raeburn  6963: 9. flag if privileged users (except those set to unhide in
                   6964:    course settings) should be excluded    
1.609     raeburn  6965: Keys of top level results hash are roles.
1.275     raeburn  6966: Keys of inner hashes are username:domain, with 
                   6967: values set to access type.
1.288     raeburn  6968: Optional userdata hash returns an array with arguments in the 
                   6969: same order as loncoursedata::get_classlist() for student data.
                   6970: 
1.609     raeburn  6971: Optional statushash returns
                   6972: 
1.288     raeburn  6973: Entries for end, start, section and status are blank because
                   6974: of the possibility of multiple values for non-student roles.
                   6975: 
1.275     raeburn  6976: =cut
1.405     albertel 6977: 
1.275     raeburn  6978: ###############################################
1.405     albertel 6979: 
1.275     raeburn  6980: sub get_course_users {
1.630     raeburn  6981:     my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288     raeburn  6982:     my %idx = ();
1.419     raeburn  6983:     my %seclists;
1.288     raeburn  6984: 
                   6985:     $idx{udom} = &Apache::loncoursedata::CL_SDOM();
                   6986:     $idx{uname} =  &Apache::loncoursedata::CL_SNAME();
                   6987:     $idx{end} = &Apache::loncoursedata::CL_END();
                   6988:     $idx{start} = &Apache::loncoursedata::CL_START();
                   6989:     $idx{id} = &Apache::loncoursedata::CL_ID();
                   6990:     $idx{section} = &Apache::loncoursedata::CL_SECTION();
                   6991:     $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
                   6992:     $idx{status} = &Apache::loncoursedata::CL_STATUS();
                   6993: 
1.290     albertel 6994:     if (grep(/^st$/,@{$roles})) {
1.276     albertel 6995:         my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278     raeburn  6996:         my $now = time;
1.277     albertel 6997:         foreach my $student (keys(%{$classlist})) {
1.288     raeburn  6998:             my $match = 0;
1.412     raeburn  6999:             my $secmatch = 0;
1.419     raeburn  7000:             my $section = $$classlist{$student}[$idx{section}];
1.609     raeburn  7001:             my $status = $$classlist{$student}[$idx{status}];
1.419     raeburn  7002:             if ($section eq '') {
                   7003:                 $section = 'none';
                   7004:             }
1.291     albertel 7005:             if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 7006:                 if (grep(/^all$/,@{$sections})) {
1.412     raeburn  7007:                     $secmatch = 1;
                   7008:                 } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420     albertel 7009:                     if (grep(/^none$/,@{$sections})) {
1.412     raeburn  7010:                         $secmatch = 1;
                   7011:                     }
                   7012:                 } else {  
1.419     raeburn  7013: 		    if (grep(/^\Q$section\E$/,@{$sections})) {
1.412     raeburn  7014: 		        $secmatch = 1;
                   7015:                     }
1.290     albertel 7016: 		}
1.412     raeburn  7017:                 if (!$secmatch) {
                   7018:                     next;
                   7019:                 }
1.419     raeburn  7020:             }
1.275     raeburn  7021:             if (defined($$types{'active'})) {
1.288     raeburn  7022:                 if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275     raeburn  7023:                     push(@{$$users{st}{$student}},'active');
1.288     raeburn  7024:                     $match = 1;
1.275     raeburn  7025:                 }
                   7026:             }
                   7027:             if (defined($$types{'previous'})) {
1.609     raeburn  7028:                 if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275     raeburn  7029:                     push(@{$$users{st}{$student}},'previous');
1.288     raeburn  7030:                     $match = 1;
1.275     raeburn  7031:                 }
                   7032:             }
                   7033:             if (defined($$types{'future'})) {
1.609     raeburn  7034:                 if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275     raeburn  7035:                     push(@{$$users{st}{$student}},'future');
1.288     raeburn  7036:                     $match = 1;
1.275     raeburn  7037:                 }
                   7038:             }
1.609     raeburn  7039:             if ($match) {
                   7040:                 push(@{$seclists{$student}},$section);
                   7041:                 if (ref($userdata) eq 'HASH') {
                   7042:                     $$userdata{$student} = $$classlist{$student};
                   7043:                 }
                   7044:                 if (ref($statushash) eq 'HASH') {
                   7045:                     $statushash->{$student}{'st'}{$section} = $status;
                   7046:                 }
1.288     raeburn  7047:             }
1.275     raeburn  7048:         }
                   7049:     }
1.412     raeburn  7050:     if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439     raeburn  7051:         my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7052:         my $now = time;
1.609     raeburn  7053:         my %displaystatus = ( previous => 'Expired',
                   7054:                               active   => 'Active',
                   7055:                               future   => 'Future',
                   7056:                             );
1.630     raeburn  7057:         my %nothide;
                   7058:         if ($hidepriv) {
                   7059:             my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
                   7060:             foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
                   7061:                 if ($user !~ /:/) {
                   7062:                     $nothide{join(':',split(/[\@]/,$user))}=1;
                   7063:                 } else {
                   7064:                     $nothide{$user} = 1;
                   7065:                 }
                   7066:             }
                   7067:         }
1.439     raeburn  7068:         foreach my $person (sort(keys(%coursepersonnel))) {
1.288     raeburn  7069:             my $match = 0;
1.412     raeburn  7070:             my $secmatch = 0;
1.439     raeburn  7071:             my $status;
1.412     raeburn  7072:             my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275     raeburn  7073:             $user =~ s/:$//;
1.439     raeburn  7074:             my ($end,$start) = split(/:/,$coursepersonnel{$person});
                   7075:             if ($end == -1 || $start == -1) {
                   7076:                 next;
                   7077:             }
                   7078:             if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
                   7079:                 (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412     raeburn  7080:                 my ($uname,$udom) = split(/:/,$user);
                   7081:                 if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 7082:                     if (grep(/^all$/,@{$sections})) {
1.412     raeburn  7083:                         $secmatch = 1;
                   7084:                     } elsif ($usec eq '') {
1.420     albertel 7085:                         if (grep(/^none$/,@{$sections})) {
1.412     raeburn  7086:                             $secmatch = 1;
                   7087:                         }
                   7088:                     } else {
                   7089:                         if (grep(/^\Q$usec\E$/,@{$sections})) {
                   7090:                             $secmatch = 1;
                   7091:                         }
                   7092:                     }
                   7093:                     if (!$secmatch) {
                   7094:                         next;
                   7095:                     }
1.288     raeburn  7096:                 }
1.419     raeburn  7097:                 if ($usec eq '') {
                   7098:                     $usec = 'none';
                   7099:                 }
1.275     raeburn  7100:                 if ($uname ne '' && $udom ne '') {
1.630     raeburn  7101:                     if ($hidepriv) {
                   7102:                         if ((&Apache::lonnet::privileged($uname,$udom)) &&
                   7103:                             (!$nothide{$uname.':'.$udom})) {
                   7104:                             next;
                   7105:                         }
                   7106:                     }
1.503     raeburn  7107:                     if ($end > 0 && $end < $now) {
1.439     raeburn  7108:                         $status = 'previous';
                   7109:                     } elsif ($start > $now) {
                   7110:                         $status = 'future';
                   7111:                     } else {
                   7112:                         $status = 'active';
                   7113:                     }
1.277     albertel 7114:                     foreach my $type (keys(%{$types})) { 
1.275     raeburn  7115:                         if ($status eq $type) {
1.420     albertel 7116:                             if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419     raeburn  7117:                                 push(@{$$users{$role}{$user}},$type);
                   7118:                             }
1.288     raeburn  7119:                             $match = 1;
                   7120:                         }
                   7121:                     }
1.419     raeburn  7122:                     if (($match) && (ref($userdata) eq 'HASH')) {
                   7123:                         if (!exists($$userdata{$uname.':'.$udom})) {
                   7124: 			    &get_user_info($udom,$uname,\%idx,$userdata);
                   7125:                         }
1.420     albertel 7126:                         if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419     raeburn  7127:                             push(@{$seclists{$uname.':'.$udom}},$usec);
                   7128:                         }
1.609     raeburn  7129:                         if (ref($statushash) eq 'HASH') {
                   7130:                             $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
                   7131:                         }
1.275     raeburn  7132:                     }
                   7133:                 }
                   7134:             }
                   7135:         }
1.290     albertel 7136:         if (grep(/^ow$/,@{$roles})) {
1.279     raeburn  7137:             if ((defined($cdom)) && (defined($cnum))) {
                   7138:                 my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
                   7139:                 if ( defined($csettings{'internal.courseowner'}) ) {
                   7140:                     my $owner = $csettings{'internal.courseowner'};
1.609     raeburn  7141:                     next if ($owner eq '');
                   7142:                     my ($ownername,$ownerdom);
                   7143:                     if ($owner =~ /^([^:]+):([^:]+)$/) {
                   7144:                         $ownername = $1;
                   7145:                         $ownerdom = $2;
                   7146:                     } else {
                   7147:                         $ownername = $owner;
                   7148:                         $ownerdom = $cdom;
                   7149:                         $owner = $ownername.':'.$ownerdom;
1.439     raeburn  7150:                     }
                   7151:                     @{$$users{'ow'}{$owner}} = 'any';
1.290     albertel 7152:                     if (defined($userdata) && 
1.609     raeburn  7153: 			!exists($$userdata{$owner})) {
                   7154: 			&get_user_info($ownerdom,$ownername,\%idx,$userdata);
                   7155:                         if (!grep(/^none$/,@{$seclists{$owner}})) {
                   7156:                             push(@{$seclists{$owner}},'none');
                   7157:                         }
                   7158:                         if (ref($statushash) eq 'HASH') {
                   7159:                             $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419     raeburn  7160:                         }
1.290     albertel 7161: 		    }
1.279     raeburn  7162:                 }
                   7163:             }
                   7164:         }
1.419     raeburn  7165:         foreach my $user (keys(%seclists)) {
                   7166:             @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
                   7167:             $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
                   7168:         }
1.275     raeburn  7169:     }
                   7170:     return;
                   7171: }
                   7172: 
1.288     raeburn  7173: sub get_user_info {
                   7174:     my ($udom,$uname,$idx,$userdata) = @_;
1.289     albertel 7175:     $$userdata{$uname.':'.$udom}[$$idx{fullname}] = 
                   7176: 	&plainname($uname,$udom,'lastname');
1.291     albertel 7177:     $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297     raeburn  7178:     $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609     raeburn  7179:     my %idhash =  &Apache::lonnet::idrget($udom,($uname));
                   7180:     $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname}; 
1.288     raeburn  7181:     return;
                   7182: }
1.275     raeburn  7183: 
1.472     raeburn  7184: ###############################################
                   7185: 
                   7186: =pod
                   7187: 
                   7188: =item * &get_user_quota()
                   7189: 
                   7190: Retrieves quota assigned for storage of portfolio files for a user  
                   7191: 
                   7192: Incoming parameters:
                   7193: 1. user's username
                   7194: 2. user's domain
                   7195: 
                   7196: Returns:
1.536     raeburn  7197: 1. Disk quota (in Mb) assigned to student.
                   7198: 2. (Optional) Type of setting: custom or default
                   7199:    (individually assigned or default for user's 
                   7200:    institutional status).
                   7201: 3. (Optional) - User's institutional status (e.g., faculty, staff
                   7202:    or student - types as defined in localenroll::inst_usertypes 
                   7203:    for user's domain, which determines default quota for user.
                   7204: 4. (Optional) - Default quota which would apply to the user.
1.472     raeburn  7205: 
                   7206: If a value has been stored in the user's environment, 
1.536     raeburn  7207: it will return that, otherwise it returns the maximal default
                   7208: defined for the user's instituional status(es) in the domain.
1.472     raeburn  7209: 
                   7210: =cut
                   7211: 
                   7212: ###############################################
                   7213: 
                   7214: 
                   7215: sub get_user_quota {
                   7216:     my ($uname,$udom) = @_;
1.536     raeburn  7217:     my ($quota,$quotatype,$settingstatus,$defquota);
1.472     raeburn  7218:     if (!defined($udom)) {
                   7219:         $udom = $env{'user.domain'};
                   7220:     }
                   7221:     if (!defined($uname)) {
                   7222:         $uname = $env{'user.name'};
                   7223:     }
                   7224:     if (($udom eq '' || $uname eq '') ||
                   7225:         ($udom eq 'public') && ($uname eq 'public')) {
                   7226:         $quota = 0;
1.536     raeburn  7227:         $quotatype = 'default';
                   7228:         $defquota = 0; 
1.472     raeburn  7229:     } else {
1.536     raeburn  7230:         my $inststatus;
1.472     raeburn  7231:         if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
                   7232:             $quota = $env{'environment.portfolioquota'};
1.536     raeburn  7233:             $inststatus = $env{'environment.inststatus'};
1.472     raeburn  7234:         } else {
1.536     raeburn  7235:             my %userenv = 
                   7236:                 &Apache::lonnet::get('environment',['portfolioquota',
                   7237:                                      'inststatus'],$udom,$uname);
1.472     raeburn  7238:             my ($tmp) = keys(%userenv);
                   7239:             if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   7240:                 $quota = $userenv{'portfolioquota'};
1.536     raeburn  7241:                 $inststatus = $userenv{'inststatus'};
1.472     raeburn  7242:             } else {
                   7243:                 undef(%userenv);
                   7244:             }
                   7245:         }
1.536     raeburn  7246:         ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472     raeburn  7247:         if ($quota eq '') {
1.536     raeburn  7248:             $quota = $defquota;
                   7249:             $quotatype = 'default';
                   7250:         } else {
                   7251:             $quotatype = 'custom';
1.472     raeburn  7252:         }
                   7253:     }
1.536     raeburn  7254:     if (wantarray) {
                   7255:         return ($quota,$quotatype,$settingstatus,$defquota);
                   7256:     } else {
                   7257:         return $quota;
                   7258:     }
1.472     raeburn  7259: }
                   7260: 
                   7261: ###############################################
                   7262: 
                   7263: =pod
                   7264: 
                   7265: =item * &default_quota()
                   7266: 
1.536     raeburn  7267: Retrieves default quota assigned for storage of user portfolio files,
                   7268: given an (optional) user's institutional status.
1.472     raeburn  7269: 
                   7270: Incoming parameters:
                   7271: 1. domain
1.536     raeburn  7272: 2. (Optional) institutional status(es).  This is a : separated list of 
                   7273:    status types (e.g., faculty, staff, student etc.)
                   7274:    which apply to the user for whom the default is being retrieved.
                   7275:    If the institutional status string in undefined, the domain
                   7276:    default quota will be returned. 
1.472     raeburn  7277: 
                   7278: Returns:
                   7279: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536     raeburn  7280: 2. (Optional) institutional type which determined the value of the
                   7281:    default quota.
1.472     raeburn  7282: 
                   7283: If a value has been stored in the domain's configuration db,
                   7284: it will return that, otherwise it returns 20 (for backwards 
                   7285: compatibility with domains which have not set up a configuration
                   7286: db file; the original statically defined portfolio quota was 20 Mb). 
                   7287: 
1.536     raeburn  7288: If the user's status includes multiple types (e.g., staff and student),
                   7289: the largest default quota which applies to the user determines the
                   7290: default quota returned.
                   7291: 
1.780     raeburn  7292: =back
                   7293: 
1.472     raeburn  7294: =cut
                   7295: 
                   7296: ###############################################
                   7297: 
                   7298: 
                   7299: sub default_quota {
1.536     raeburn  7300:     my ($udom,$inststatus) = @_;
                   7301:     my ($defquota,$settingstatus);
                   7302:     my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622     raeburn  7303:                                             ['quotas'],$udom);
                   7304:     if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536     raeburn  7305:         if ($inststatus ne '') {
1.765     raeburn  7306:             my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536     raeburn  7307:             foreach my $item (@statuses) {
1.711     raeburn  7308:                 if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7309:                     if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
                   7310:                         if ($defquota eq '') {
                   7311:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7312:                             $settingstatus = $item;
                   7313:                         } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
                   7314:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7315:                             $settingstatus = $item;
                   7316:                         }
                   7317:                     }
                   7318:                 } else {
                   7319:                     if ($quotahash{'quotas'}{$item} ne '') {
                   7320:                         if ($defquota eq '') {
                   7321:                             $defquota = $quotahash{'quotas'}{$item};
                   7322:                             $settingstatus = $item;
                   7323:                         } elsif ($quotahash{'quotas'}{$item} > $defquota) {
                   7324:                             $defquota = $quotahash{'quotas'}{$item};
                   7325:                             $settingstatus = $item;
                   7326:                         }
1.536     raeburn  7327:                     }
                   7328:                 }
                   7329:             }
                   7330:         }
                   7331:         if ($defquota eq '') {
1.711     raeburn  7332:             if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7333:                 $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
                   7334:             } else {
                   7335:                 $defquota = $quotahash{'quotas'}{'default'};
                   7336:             }
1.536     raeburn  7337:             $settingstatus = 'default';
                   7338:         }
                   7339:     } else {
                   7340:         $settingstatus = 'default';
                   7341:         $defquota = 20;
                   7342:     }
                   7343:     if (wantarray) {
                   7344:         return ($defquota,$settingstatus);
1.472     raeburn  7345:     } else {
1.536     raeburn  7346:         return $defquota;
1.472     raeburn  7347:     }
                   7348: }
                   7349: 
1.384     raeburn  7350: sub get_secgrprole_info {
                   7351:     my ($cdom,$cnum,$needroles,$type)  = @_;
                   7352:     my %sections_count = &get_sections($cdom,$cnum);
                   7353:     my @sections =  (sort {$a <=> $b} keys(%sections_count));
                   7354:     my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
                   7355:     my @groups = sort(keys(%curr_groups));
                   7356:     my $allroles = [];
                   7357:     my $rolehash;
                   7358:     my $accesshash = {
                   7359:                      active => 'Currently has access',
                   7360:                      future => 'Will have future access',
                   7361:                      previous => 'Previously had access',
                   7362:                   };
                   7363:     if ($needroles) {
                   7364:         $rolehash = {'all' => 'all'};
1.385     albertel 7365:         my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7366: 	if (&Apache::lonnet::error(%user_roles)) {
                   7367: 	    undef(%user_roles);
                   7368: 	}
                   7369:         foreach my $item (keys(%user_roles)) {
1.384     raeburn  7370:             my ($role)=split(/\:/,$item,2);
                   7371:             if ($role eq 'cr') { next; }
                   7372:             if ($role =~ /^cr/) {
                   7373:                 $$rolehash{$role} = (split('/',$role))[3];
                   7374:             } else {
                   7375:                 $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
                   7376:             }
                   7377:         }
                   7378:         foreach my $key (sort(keys(%{$rolehash}))) {
                   7379:             push(@{$allroles},$key);
                   7380:         }
                   7381:         push (@{$allroles},'st');
                   7382:         $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
                   7383:     }
                   7384:     return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
                   7385: }
                   7386: 
1.555     raeburn  7387: sub user_picker {
1.627     raeburn  7388:     my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555     raeburn  7389:     my $currdom = $dom;
                   7390:     my %curr_selected = (
                   7391:                         srchin => 'dom',
1.580     raeburn  7392:                         srchby => 'lastname',
1.555     raeburn  7393:                       );
                   7394:     my $srchterm;
1.625     raeburn  7395:     if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555     raeburn  7396:         if ($srch->{'srchby'} ne '') {
                   7397:             $curr_selected{'srchby'} = $srch->{'srchby'};
                   7398:         }
                   7399:         if ($srch->{'srchin'} ne '') {
                   7400:             $curr_selected{'srchin'} = $srch->{'srchin'};
                   7401:         }
                   7402:         if ($srch->{'srchtype'} ne '') {
                   7403:             $curr_selected{'srchtype'} = $srch->{'srchtype'};
                   7404:         }
                   7405:         if ($srch->{'srchdomain'} ne '') {
                   7406:             $currdom = $srch->{'srchdomain'};
                   7407:         }
                   7408:         $srchterm = $srch->{'srchterm'};
                   7409:     }
                   7410:     my %lt=&Apache::lonlocal::texthash(
1.573     raeburn  7411:                     'usr'       => 'Search criteria',
1.563     raeburn  7412:                     'doma'      => 'Domain/institution to search',
1.558     albertel 7413:                     'uname'     => 'username',
                   7414:                     'lastname'  => 'last name',
1.555     raeburn  7415:                     'lastfirst' => 'last name, first name',
1.558     albertel 7416:                     'crs'       => 'in this course',
1.576     raeburn  7417:                     'dom'       => 'in selected LON-CAPA domain', 
1.558     albertel 7418:                     'alc'       => 'all LON-CAPA',
1.573     raeburn  7419:                     'instd'     => 'in institutional directory for selected domain',
1.558     albertel 7420:                     'exact'     => 'is',
                   7421:                     'contains'  => 'contains',
1.569     raeburn  7422:                     'begins'    => 'begins with',
1.571     raeburn  7423:                     'youm'      => "You must include some text to search for.",
                   7424:                     'thte'      => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
                   7425:                     'thet'      => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
                   7426:                     'yomc'      => "You must choose a domain when using an institutional directory search.",
                   7427:                     'ymcd'      => "You must choose a domain when using a domain search.",
                   7428:                     'whus'      => "When using searching by last,first you must include a comma as separator between last name and first name.",
                   7429:                     'whse'      => "When searching by last,first you must include at least one character in the first name.",
                   7430:                      'thfo'     => "The following need to be corrected before the search can be run:",
1.555     raeburn  7431:                                        );
1.563     raeburn  7432:     my $domform = &select_dom_form($currdom,'srchdomain',1,1);
                   7433:     my $srchinsel = ' <select name="srchin">';
1.555     raeburn  7434: 
                   7435:     my @srchins = ('crs','dom','alc','instd');
                   7436: 
                   7437:     foreach my $option (@srchins) {
                   7438:         # FIXME 'alc' option unavailable until 
                   7439:         #       loncreateuser::print_user_query_page()
                   7440:         #       has been completed.
                   7441:         next if ($option eq 'alc');
                   7442:         next if ($option eq 'crs' && !$env{'request.course.id'});
1.563     raeburn  7443:         if ($curr_selected{'srchin'} eq $option) {
                   7444:             $srchinsel .= ' 
                   7445:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7446:         } else {
                   7447:             $srchinsel .= '
                   7448:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7449:         }
1.555     raeburn  7450:     }
1.563     raeburn  7451:     $srchinsel .= "\n  </select>\n";
1.555     raeburn  7452: 
                   7453:     my $srchbysel =  ' <select name="srchby">';
1.580     raeburn  7454:     foreach my $option ('lastname','lastfirst','uname') {
1.555     raeburn  7455:         if ($curr_selected{'srchby'} eq $option) {
                   7456:             $srchbysel .= '
                   7457:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7458:         } else {
                   7459:             $srchbysel .= '
                   7460:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7461:          }
                   7462:     }
                   7463:     $srchbysel .= "\n  </select>\n";
                   7464: 
                   7465:     my $srchtypesel = ' <select name="srchtype">';
1.580     raeburn  7466:     foreach my $option ('begins','contains','exact') {
1.555     raeburn  7467:         if ($curr_selected{'srchtype'} eq $option) {
                   7468:             $srchtypesel .= '
                   7469:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7470:         } else {
                   7471:             $srchtypesel .= '
                   7472:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7473:         }
                   7474:     }
                   7475:     $srchtypesel .= "\n  </select>\n";
                   7476: 
1.558     albertel 7477:     my ($newuserscript,$new_user_create);
1.556     raeburn  7478: 
                   7479:     if ($forcenewuser) {
1.576     raeburn  7480:         if (ref($srch) eq 'HASH') {
                   7481:             if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627     raeburn  7482:                 if ($cancreate) {
                   7483:                     $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>';
                   7484:                 } else {
1.799     bisitz   7485:                     my $helplink = 'javascript:helpMenu('."'display'".')';
1.627     raeburn  7486:                     my %usertypetext = (
                   7487:                         official   => 'institutional',
                   7488:                         unofficial => 'non-institutional',
                   7489:                     );
1.799     bisitz   7490:                     $new_user_create = '<p class="LC_warning">'
                   7491:                                       .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
                   7492:                                       .' '
                   7493:                                       .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
                   7494:                                           ,'<a href="'.$helplink.'">','</a>')
                   7495:                                       .'</p><br />';
1.627     raeburn  7496:                 }
1.576     raeburn  7497:             }
                   7498:         }
                   7499: 
1.556     raeburn  7500:         $newuserscript = <<"ENDSCRIPT";
                   7501: 
1.570     raeburn  7502: function setSearch(createnew,callingForm) {
1.556     raeburn  7503:     if (createnew == 1) {
1.570     raeburn  7504:         for (var i=0; i<callingForm.srchby.length; i++) {
                   7505:             if (callingForm.srchby.options[i].value == 'uname') {
                   7506:                 callingForm.srchby.selectedIndex = i;
1.556     raeburn  7507:             }
                   7508:         }
1.570     raeburn  7509:         for (var i=0; i<callingForm.srchin.length; i++) {
                   7510:             if ( callingForm.srchin.options[i].value == 'dom') {
                   7511: 		callingForm.srchin.selectedIndex = i;
1.556     raeburn  7512:             }
                   7513:         }
1.570     raeburn  7514:         for (var i=0; i<callingForm.srchtype.length; i++) {
                   7515:             if (callingForm.srchtype.options[i].value == 'exact') {
                   7516:                 callingForm.srchtype.selectedIndex = i;
1.556     raeburn  7517:             }
                   7518:         }
1.570     raeburn  7519:         for (var i=0; i<callingForm.srchdomain.length; i++) {
                   7520:             if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
                   7521:                 callingForm.srchdomain.selectedIndex = i;
1.556     raeburn  7522:             }
                   7523:         }
                   7524:     }
                   7525: }
                   7526: ENDSCRIPT
1.558     albertel 7527: 
1.556     raeburn  7528:     }
                   7529: 
1.555     raeburn  7530:     my $output = <<"END_BLOCK";
1.556     raeburn  7531: <script type="text/javascript">
1.570     raeburn  7532: function validateEntry(callingForm) {
1.558     albertel 7533: 
1.556     raeburn  7534:     var checkok = 1;
1.558     albertel 7535:     var srchin;
1.570     raeburn  7536:     for (var i=0; i<callingForm.srchin.length; i++) {
                   7537: 	if ( callingForm.srchin[i].checked ) {
                   7538: 	    srchin = callingForm.srchin[i].value;
1.558     albertel 7539: 	}
                   7540:     }
                   7541: 
1.570     raeburn  7542:     var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
                   7543:     var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
                   7544:     var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
                   7545:     var srchterm =  callingForm.srchterm.value;
                   7546:     var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556     raeburn  7547:     var msg = "";
                   7548: 
                   7549:     if (srchterm == "") {
                   7550:         checkok = 0;
1.571     raeburn  7551:         msg += "$lt{'youm'}\\n";
1.556     raeburn  7552:     }
                   7553: 
1.569     raeburn  7554:     if (srchtype== 'begins') {
                   7555:         if (srchterm.length < 2) {
                   7556:             checkok = 0;
1.571     raeburn  7557:             msg += "$lt{'thte'}\\n";
1.569     raeburn  7558:         }
                   7559:     }
                   7560: 
1.556     raeburn  7561:     if (srchtype== 'contains') {
                   7562:         if (srchterm.length < 3) {
                   7563:             checkok = 0;
1.571     raeburn  7564:             msg += "$lt{'thet'}\\n";
1.556     raeburn  7565:         }
                   7566:     }
                   7567:     if (srchin == 'instd') {
                   7568:         if (srchdomain == '') {
                   7569:             checkok = 0;
1.571     raeburn  7570:             msg += "$lt{'yomc'}\\n";
1.556     raeburn  7571:         }
                   7572:     }
                   7573:     if (srchin == 'dom') {
                   7574:         if (srchdomain == '') {
                   7575:             checkok = 0;
1.571     raeburn  7576:             msg += "$lt{'ymcd'}\\n";
1.556     raeburn  7577:         }
                   7578:     }
                   7579:     if (srchby == 'lastfirst') {
                   7580:         if (srchterm.indexOf(",") == -1) {
                   7581:             checkok = 0;
1.571     raeburn  7582:             msg += "$lt{'whus'}\\n";
1.556     raeburn  7583:         }
                   7584:         if (srchterm.indexOf(",") == srchterm.length -1) {
                   7585:             checkok = 0;
1.571     raeburn  7586:             msg += "$lt{'whse'}\\n";
1.556     raeburn  7587:         }
                   7588:     }
                   7589:     if (checkok == 0) {
1.571     raeburn  7590:         alert("$lt{'thfo'}\\n"+msg);
1.556     raeburn  7591:         return;
                   7592:     }
                   7593:     if (checkok == 1) {
1.570     raeburn  7594:         callingForm.submit();
1.556     raeburn  7595:     }
                   7596: }
                   7597: 
                   7598: $newuserscript
                   7599: 
                   7600: </script>
1.558     albertel 7601: 
                   7602: $new_user_create
                   7603: 
1.555     raeburn  7604: <table>
1.558     albertel 7605:  <tr>
1.573     raeburn  7606:   <td>$lt{'doma'}:</td>
                   7607:   <td>$domform</td>
                   7608:   </td>
                   7609:  </tr>
                   7610:  <tr>
                   7611:   <td>$lt{'usr'}:</td>
1.563     raeburn  7612:   <td>$srchbysel
                   7613:       $srchtypesel 
                   7614:       <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564     albertel 7615:       $srchinsel 
1.563     raeburn  7616:   </td>
                   7617:  </tr>
1.555     raeburn  7618: </table>
                   7619: <br />
                   7620: END_BLOCK
1.558     albertel 7621: 
1.555     raeburn  7622:     return $output;
                   7623: }
                   7624: 
1.612     raeburn  7625: sub user_rule_check {
1.615     raeburn  7626:     my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612     raeburn  7627:     my $response;
                   7628:     if (ref($usershash) eq 'HASH') {
                   7629:         foreach my $user (keys(%{$usershash})) {
                   7630:             my ($uname,$udom) = split(/:/,$user);
                   7631:             next if ($udom eq '' || $uname eq '');
1.615     raeburn  7632:             my ($id,$newuser);
1.612     raeburn  7633:             if (ref($usershash->{$user}) eq 'HASH') {
1.615     raeburn  7634:                 $newuser = $usershash->{$user}->{'newuser'};
1.612     raeburn  7635:                 $id = $usershash->{$user}->{'id'};
                   7636:             }
                   7637:             my $inst_response;
                   7638:             if (ref($checks) eq 'HASH') {
                   7639:                 if (defined($checks->{'username'})) {
1.615     raeburn  7640:                     ($inst_response,%{$inst_results->{$user}}) = 
1.612     raeburn  7641:                         &Apache::lonnet::get_instuser($udom,$uname);
                   7642:                 } elsif (defined($checks->{'id'})) {
1.615     raeburn  7643:                     ($inst_response,%{$inst_results->{$user}}) =
1.612     raeburn  7644:                         &Apache::lonnet::get_instuser($udom,undef,$id);
                   7645:                 }
1.615     raeburn  7646:             } else {
                   7647:                 ($inst_response,%{$inst_results->{$user}}) =
                   7648:                     &Apache::lonnet::get_instuser($udom,$uname);
                   7649:                 return;
1.612     raeburn  7650:             }
1.615     raeburn  7651:             if (!$got_rules->{$udom}) {
1.612     raeburn  7652:                 my %domconfig = &Apache::lonnet::get_dom('configuration',
                   7653:                                                   ['usercreation'],$udom);
                   7654:                 if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615     raeburn  7655:                     foreach my $item ('username','id') {
1.612     raeburn  7656:                         if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
                   7657:                             $$curr_rules{$udom}{$item} = 
                   7658:                                 $domconfig{'usercreation'}{$item.'_rule'};
1.585     raeburn  7659:                         }
                   7660:                     }
                   7661:                 }
1.615     raeburn  7662:                 $got_rules->{$udom} = 1;  
1.585     raeburn  7663:             }
1.612     raeburn  7664:             foreach my $item (keys(%{$checks})) {
                   7665:                 if (ref($$curr_rules{$udom}) eq 'HASH') {
                   7666:                     if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
                   7667:                         if (@{$$curr_rules{$udom}{$item}} > 0) {
                   7668:                             my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
                   7669:                             foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
                   7670:                                 if ($rule_check{$rule}) {
                   7671:                                     $$rulematch{$user}{$item} = $rule;
                   7672:                                     if ($inst_response eq 'ok') {
1.615     raeburn  7673:                                         if (ref($inst_results) eq 'HASH') {
                   7674:                                             if (ref($inst_results->{$user}) eq 'HASH') {
                   7675:                                                 if (keys(%{$inst_results->{$user}}) == 0) {
                   7676:                                                     $$alerts{$item}{$udom}{$uname} = 1;
                   7677:                                                 }
1.612     raeburn  7678:                                             }
                   7679:                                         }
1.615     raeburn  7680:                                     }
                   7681:                                     last;
1.585     raeburn  7682:                                 }
                   7683:                             }
                   7684:                         }
                   7685:                     }
                   7686:                 }
                   7687:             }
                   7688:         }
                   7689:     }
1.612     raeburn  7690:     return;
                   7691: }
                   7692: 
                   7693: sub user_rule_formats {
                   7694:     my ($domain,$domdesc,$curr_rules,$check) = @_;
                   7695:     my %text = ( 
                   7696:                  'username' => 'Usernames',
                   7697:                  'id'       => 'IDs',
                   7698:                );
                   7699:     my $output;
                   7700:     my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
                   7701:     if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
                   7702:         if (@{$ruleorder} > 0) {
                   7703:             $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>';
                   7704:             foreach my $rule (@{$ruleorder}) {
                   7705:                 if (ref($curr_rules) eq 'ARRAY') {
                   7706:                     if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
                   7707:                         if (ref($rules->{$rule}) eq 'HASH') {
                   7708:                             $output .= '<li>'.$rules->{$rule}{'name'}.': '.
                   7709:                                         $rules->{$rule}{'desc'}.'</li>';
                   7710:                         }
                   7711:                     }
                   7712:                 }
                   7713:             }
                   7714:             $output .= '</ul>';
                   7715:         }
                   7716:     }
                   7717:     return $output;
                   7718: }
                   7719: 
                   7720: sub instrule_disallow_msg {
1.615     raeburn  7721:     my ($checkitem,$domdesc,$count,$mode) = @_;
1.612     raeburn  7722:     my $response;
                   7723:     my %text = (
                   7724:                   item   => 'username',
                   7725:                   items  => 'usernames',
                   7726:                   match  => 'matches',
                   7727:                   do     => 'does',
                   7728:                   action => 'a username',
                   7729:                   one    => 'one',
                   7730:                );
                   7731:     if ($count > 1) {
                   7732:         $text{'item'} = 'usernames';
                   7733:         $text{'match'} ='match';
                   7734:         $text{'do'} = 'do';
                   7735:         $text{'action'} = 'usernames',
                   7736:         $text{'one'} = 'ones';
                   7737:     }
                   7738:     if ($checkitem eq 'id') {
                   7739:         $text{'items'} = 'IDs';
                   7740:         $text{'item'} = 'ID';
                   7741:         $text{'action'} = 'an ID';
1.615     raeburn  7742:         if ($count > 1) {
                   7743:             $text{'item'} = 'IDs';
                   7744:             $text{'action'} = 'IDs';
                   7745:         }
1.612     raeburn  7746:     }
1.674     bisitz   7747:     $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  7748:     if ($mode eq 'upload') {
                   7749:         if ($checkitem eq 'username') {
                   7750:             $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'}.");
                   7751:         } elsif ($checkitem eq 'id') {
1.674     bisitz   7752:             $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  7753:         }
1.669     raeburn  7754:     } elsif ($mode eq 'selfcreate') {
                   7755:         if ($checkitem eq 'id') {
                   7756:             $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.");
                   7757:         }
1.615     raeburn  7758:     } else {
                   7759:         if ($checkitem eq 'username') {
                   7760:             $response .= &mt("You must choose $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
                   7761:         } elsif ($checkitem eq 'id') {
                   7762:             $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.");
                   7763:         }
1.612     raeburn  7764:     }
                   7765:     return $response;
1.585     raeburn  7766: }
                   7767: 
1.624     raeburn  7768: sub personal_data_fieldtitles {
                   7769:     my %fieldtitles = &Apache::lonlocal::texthash (
                   7770:                         id => 'Student/Employee ID',
                   7771:                         permanentemail => 'E-mail address',
                   7772:                         lastname => 'Last Name',
                   7773:                         firstname => 'First Name',
                   7774:                         middlename => 'Middle Name',
                   7775:                         generation => 'Generation',
                   7776:                         gen => 'Generation',
1.765     raeburn  7777:                         inststatus => 'Affiliation',
1.624     raeburn  7778:                    );
                   7779:     return %fieldtitles;
                   7780: }
                   7781: 
1.642     raeburn  7782: sub sorted_inst_types {
                   7783:     my ($dom) = @_;
                   7784:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
                   7785:     my $othertitle = &mt('All users');
                   7786:     if ($env{'request.course.id'}) {
1.668     raeburn  7787:         $othertitle  = &mt('Any users');
1.642     raeburn  7788:     }
                   7789:     my @types;
                   7790:     if (ref($order) eq 'ARRAY') {
                   7791:         @types = @{$order};
                   7792:     }
                   7793:     if (@types == 0) {
                   7794:         if (ref($usertypes) eq 'HASH') {
                   7795:             @types = sort(keys(%{$usertypes}));
                   7796:         }
                   7797:     }
                   7798:     if (keys(%{$usertypes}) > 0) {
                   7799:         $othertitle = &mt('Other users');
                   7800:     }
                   7801:     return ($othertitle,$usertypes,\@types);
                   7802: }
                   7803: 
1.645     raeburn  7804: sub get_institutional_codes {
                   7805:     my ($settings,$allcourses,$LC_code) = @_;
                   7806: # Get complete list of course sections to update
                   7807:     my @currsections = ();
                   7808:     my @currxlists = ();
                   7809:     my $coursecode = $$settings{'internal.coursecode'};
                   7810: 
                   7811:     if ($$settings{'internal.sectionnums'} ne '') {
                   7812:         @currsections = split(/,/,$$settings{'internal.sectionnums'});
                   7813:     }
                   7814: 
                   7815:     if ($$settings{'internal.crosslistings'} ne '') {
                   7816:         @currxlists = split(/,/,$$settings{'internal.crosslistings'});
                   7817:     }
                   7818: 
                   7819:     if (@currxlists > 0) {
                   7820:         foreach (@currxlists) {
                   7821:             if (m/^([^:]+):(\w*)$/) {
                   7822:                 unless (grep/^$1$/,@{$allcourses}) {
                   7823:                     push @{$allcourses},$1;
                   7824:                     $$LC_code{$1} = $2;
                   7825:                 }
                   7826:             }
                   7827:         }
                   7828:     }
                   7829:  
                   7830:     if (@currsections > 0) {
                   7831:         foreach (@currsections) {
                   7832:             if (m/^(\w+):(\w*)$/) {
                   7833:                 my $sec = $coursecode.$1;
                   7834:                 my $lc_sec = $2;
                   7835:                 unless (grep/^$sec$/,@{$allcourses}) {
                   7836:                     push @{$allcourses},$sec;
                   7837:                     $$LC_code{$sec} = $lc_sec;
                   7838:                 }
                   7839:             }
                   7840:         }
                   7841:     }
                   7842:     return;
                   7843: }
                   7844: 
1.112     bowersj2 7845: =pod
                   7846: 
1.780     raeburn  7847: =head1 Slot Helpers
                   7848: 
                   7849: =over 4
                   7850: 
                   7851: =item * sorted_slots()
                   7852: 
                   7853: Sorts an array of slot names in order of slot start time (earliest first). 
                   7854: 
                   7855: Inputs:
                   7856: 
                   7857: =over 4
                   7858: 
                   7859: slotsarr  - Reference to array of unsorted slot names.
                   7860: 
                   7861: slots     - Reference to hash of hash, where outer hash keys are slot names.
                   7862: 
1.549     albertel 7863: =back
                   7864: 
1.780     raeburn  7865: Returns:
                   7866: 
                   7867: =over 4
                   7868: 
                   7869: sorted   - An array of slot names sorted by the start time of the slot.
                   7870: 
                   7871: =back
                   7872: 
                   7873: =back
                   7874: 
                   7875: =cut
                   7876: 
                   7877: 
                   7878: sub sorted_slots {
                   7879:     my ($slotsarr,$slots) = @_;
                   7880:     my @sorted;
                   7881:     if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
                   7882:         @sorted =
                   7883:             sort {
                   7884:                      if (ref($slots->{$a}) && ref($slots->{$b})) {
                   7885:                          return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
                   7886:                      }
                   7887:                      if (ref($slots->{$a})) { return -1;}
                   7888:                      if (ref($slots->{$b})) { return 1;}
                   7889:                      return 0;
                   7890:                  } @{$slotsarr};
                   7891:     }
                   7892:     return @sorted;
                   7893: }
                   7894: 
                   7895: 
                   7896: =pod
                   7897: 
1.549     albertel 7898: =head1 HTTP Helpers
                   7899: 
                   7900: =over 4
                   7901: 
1.648     raeburn  7902: =item * &get_unprocessed_cgi($query,$possible_names)
1.112     bowersj2 7903: 
1.258     albertel 7904: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112     bowersj2 7905: $query.  The parameters listed in $possible_names (an array reference),
1.258     albertel 7906: will be set in $env{'form.name'} if they do not already exist.
1.112     bowersj2 7907: 
                   7908: Typically called with $ENV{'QUERY_STRING'} as the first parameter.  
                   7909: $possible_names is an ref to an array of form element names.  As an example:
                   7910: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258     albertel 7911: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112     bowersj2 7912: 
                   7913: =cut
1.1       albertel 7914: 
1.6       albertel 7915: sub get_unprocessed_cgi {
1.25      albertel 7916:   my ($query,$possible_names)= @_;
1.26      matthew  7917:   # $Apache::lonxml::debug=1;
1.356     albertel 7918:   foreach my $pair (split(/&/,$query)) {
                   7919:     my ($name, $value) = split(/=/,$pair);
1.369     www      7920:     $name = &unescape($name);
1.25      albertel 7921:     if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
                   7922:       $value =~ tr/+/ /;
                   7923:       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258     albertel 7924:       unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25      albertel 7925:     }
1.16      harris41 7926:   }
1.6       albertel 7927: }
                   7928: 
1.112     bowersj2 7929: =pod
                   7930: 
1.648     raeburn  7931: =item * &cacheheader() 
1.112     bowersj2 7932: 
                   7933: returns cache-controlling header code
                   7934: 
                   7935: =cut
                   7936: 
1.7       albertel 7937: sub cacheheader {
1.258     albertel 7938:     unless ($env{'request.method'} eq 'GET') { return ''; }
1.216     albertel 7939:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
                   7940:     my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7       albertel 7941:                 <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
                   7942:                 <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216     albertel 7943:     return $output;
1.7       albertel 7944: }
                   7945: 
1.112     bowersj2 7946: =pod
                   7947: 
1.648     raeburn  7948: =item * &no_cache($r) 
1.112     bowersj2 7949: 
                   7950: specifies header code to not have cache
                   7951: 
                   7952: =cut
                   7953: 
1.9       albertel 7954: sub no_cache {
1.216     albertel 7955:     my ($r) = @_;
                   7956:     if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258     albertel 7957: 	$env{'request.method'} ne 'GET') { return ''; }
1.216     albertel 7958:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
                   7959:     $r->no_cache(1);
                   7960:     $r->header_out("Expires" => $date);
                   7961:     $r->header_out("Pragma" => "no-cache");
1.123     www      7962: }
                   7963: 
                   7964: sub content_type {
1.181     albertel 7965:     my ($r,$type,$charset) = @_;
1.299     foxr     7966:     if ($r) {
                   7967: 	#  Note that printout.pl calls this with undef for $r.
                   7968: 	&no_cache($r);
                   7969:     }
1.258     albertel 7970:     if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181     albertel 7971:     unless ($charset) {
                   7972: 	$charset=&Apache::lonlocal::current_encoding;
                   7973:     }
                   7974:     if ($charset) { $type.='; charset='.$charset; }
                   7975:     if ($r) {
                   7976: 	$r->content_type($type);
                   7977:     } else {
                   7978: 	print("Content-type: $type\n\n");
                   7979:     }
1.9       albertel 7980: }
1.25      albertel 7981: 
1.112     bowersj2 7982: =pod
                   7983: 
1.648     raeburn  7984: =item * &add_to_env($name,$value) 
1.112     bowersj2 7985: 
1.258     albertel 7986: adds $name to the %env hash with value
1.112     bowersj2 7987: $value, if $name already exists, the entry is converted to an array
                   7988: reference and $value is added to the array.
                   7989: 
                   7990: =cut
                   7991: 
1.25      albertel 7992: sub add_to_env {
                   7993:   my ($name,$value)=@_;
1.258     albertel 7994:   if (defined($env{$name})) {
                   7995:     if (ref($env{$name})) {
1.25      albertel 7996:       #already have multiple values
1.258     albertel 7997:       push(@{ $env{$name} },$value);
1.25      albertel 7998:     } else {
                   7999:       #first time seeing multiple values, convert hash entry to an arrayref
1.258     albertel 8000:       my $first=$env{$name};
                   8001:       undef($env{$name});
                   8002:       push(@{ $env{$name} },$first,$value);
1.25      albertel 8003:     }
                   8004:   } else {
1.258     albertel 8005:     $env{$name}=$value;
1.25      albertel 8006:   }
1.31      albertel 8007: }
1.149     albertel 8008: 
                   8009: =pod
                   8010: 
1.648     raeburn  8011: =item * &get_env_multiple($name) 
1.149     albertel 8012: 
1.258     albertel 8013: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149     albertel 8014: values may be defined and end up as an array ref.
                   8015: 
                   8016: returns an array of values
                   8017: 
                   8018: =cut
                   8019: 
                   8020: sub get_env_multiple {
                   8021:     my ($name) = @_;
                   8022:     my @values;
1.258     albertel 8023:     if (defined($env{$name})) {
1.149     albertel 8024:         # exists is it an array
1.258     albertel 8025:         if (ref($env{$name})) {
                   8026:             @values=@{ $env{$name} };
1.149     albertel 8027:         } else {
1.258     albertel 8028:             $values[0]=$env{$name};
1.149     albertel 8029:         }
                   8030:     }
                   8031:     return(@values);
                   8032: }
                   8033: 
1.660     raeburn  8034: sub ask_for_embedded_content {
                   8035:     my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
                   8036:     my $upload_output = '
                   8037:    <form name="upload_embedded" action="'.$actionurl.'"
                   8038:                   method="post" enctype="multipart/form-data">';
                   8039:     $upload_output .= $state;
1.661     raeburn  8040:     $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660     raeburn  8041: 
                   8042:     my $num = 0;
                   8043:     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
                   8044:         $upload_output .= &start_data_table_row().
                   8045:             '<td>'.$embed_file.'</td><td>';
                   8046:         if ($args->{'ignore_remote_references'}
                   8047:             && $embed_file =~ m{^\w+://}) {
                   8048:             $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
                   8049:         } elsif ($args->{'error_on_invalid_names'}
                   8050:             && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
                   8051: 
                   8052:             $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
                   8053: 
                   8054:         } else {
                   8055:             $upload_output .='
1.661     raeburn  8056:            <input name="embedded_item_'.$num.'" type="file" value="" />
1.660     raeburn  8057:            <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
                   8058:             my $attrib = join(':',@{$$allfiles{$embed_file}});
                   8059:             $upload_output .=
                   8060:                 "\n\t\t".
                   8061:                 '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
                   8062:                 $attrib.'" />';
                   8063:             if (exists($$codebase{$embed_file})) {
                   8064:                 $upload_output .=
                   8065:                     "\n\t\t".
                   8066:                     '<input name="codebase_'.$num.'" type="hidden" value="'.
                   8067:                     &escape($$codebase{$embed_file}).'" />';
                   8068:             }
                   8069:         }
                   8070:         $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
                   8071:         $num++;
                   8072:     }
                   8073:     $upload_output .= &Apache::loncommon::end_data_table().'<br />
                   8074:    <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
                   8075:    <input type ="submit" value="'.&mt('Upload Listed Files').'" />
                   8076:    '.&mt('(only files for which a location has been provided will be uploaded)').'
                   8077:    </form>';
                   8078:     return $upload_output;
                   8079: }
                   8080: 
1.661     raeburn  8081: sub upload_embedded {
                   8082:     my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
                   8083:         $current_disk_usage) = @_;
                   8084:     my $output;
                   8085:     for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
                   8086:         next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
                   8087:         my $orig_uploaded_filename =
                   8088:             $env{'form.embedded_item_'.$i.'.filename'};
                   8089: 
                   8090:         $env{'form.embedded_orig_'.$i} =
                   8091:             &unescape($env{'form.embedded_orig_'.$i});
                   8092:         my ($path,$fname) =
                   8093:             ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
                   8094:         # no path, whole string is fname
                   8095:         if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
                   8096: 
                   8097:         $path = $env{'form.currentpath'}.$path;
                   8098:         $fname = &Apache::lonnet::clean_filename($fname);
                   8099:         # See if there is anything left
                   8100:         next if ($fname eq '');
                   8101: 
                   8102:         # Check if file already exists as a file or directory.
                   8103:         my ($state,$msg);
                   8104:         if ($context eq 'portfolio') {
                   8105:             my $port_path = $dirpath;
                   8106:             if ($group ne '') {
                   8107:                 $port_path = "groups/$group/$port_path";
                   8108:             }
                   8109:             ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
                   8110:                                               $dir_root,$port_path,$disk_quota,
                   8111:                                               $current_disk_usage,$uname,$udom);
                   8112:             if ($state eq 'will_exceed_quota'
                   8113:                 || $state eq 'file_locked'
                   8114:                 || $state eq 'file_exists' ) {
                   8115:                 $output .= $msg;
                   8116:                 next;
                   8117:             }
                   8118:         } elsif (($context eq 'author') || ($context eq 'testbank')) {
                   8119:             ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
                   8120:             if ($state eq 'exists') {
                   8121:                 $output .= $msg;
                   8122:                 next;
                   8123:             }
                   8124:         }
                   8125:         # Check if extension is valid
                   8126:         if (($fname =~ /\.(\w+)$/) &&
                   8127:             (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   8128:             $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
                   8129:             next;
                   8130:         } elsif (($fname =~ /\.(\w+)$/) &&
                   8131:                  (!defined(&Apache::loncommon::fileembstyle($1)))) {
                   8132:             $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   8133:             next;
                   8134:         } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
                   8135:             $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
                   8136:             next;
                   8137:         }
                   8138: 
                   8139:         $env{'form.embedded_item_'.$i.'.filename'}=$fname;
                   8140:         if ($context eq 'portfolio') {
                   8141:             my $result=
                   8142:                 &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
                   8143:                                                 $dirpath.$path);
                   8144:             if ($result !~ m|^/uploaded/|) {
                   8145:                 $output .= '<span class="LC_error">'
                   8146:                       .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
                   8147:                            ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
                   8148:                       .'</span><br />';
                   8149:                 next;
                   8150:             } else {
                   8151:                 $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
                   8152:                            $path.$fname.'</span>').'</p>';     
                   8153:             }
                   8154:         } else {
                   8155: # Save the file
                   8156:             my $target = $env{'form.embedded_item_'.$i};
                   8157:             my $fullpath = $dir_root.$dirpath.'/'.$path;
                   8158:             my $dest = $fullpath.$fname;
                   8159:             my $url = $url_root.$dirpath.'/'.$path.$fname;
                   8160:             my @parts=split(/\//,$fullpath);
                   8161:             my $count;
                   8162:             my $filepath = $dir_root;
                   8163:             for ($count=4;$count<=$#parts;$count++) {
                   8164:                 $filepath .= "/$parts[$count]";
                   8165:                 if ((-e $filepath)!=1) {
                   8166:                     mkdir($filepath,0770);
                   8167:                 }
                   8168:             }
                   8169:             my $fh;
                   8170:             if (!open($fh,'>'.$dest)) {
                   8171:                 &Apache::lonnet::logthis('Failed to create '.$dest);
                   8172:                 $output .= '<span class="LC_error">'.
                   8173:                            &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   8174:                            '</span><br />';
                   8175:             } else {
                   8176:                 if (!print $fh $env{'form.embedded_item_'.$i}) {
                   8177:                     &Apache::lonnet::logthis('Failed to write to '.$dest);
                   8178:                     $output .= '<span class="LC_error">'.
                   8179:                               &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   8180:                               '</span><br />';
                   8181:                 } else {
                   8182:                     if ($context eq 'testbank') {
                   8183:                         $output .= &mt('Embedded file uploaded successfully:').
                   8184:                                    '&nbsp;<a href="'.$url.'">'.
                   8185:                                    $orig_uploaded_filename.'</a><br />';
                   8186:                     } else {
1.705     tempelho 8187:                         $output .= '<span class=\"LC_fontsize_large\">'.
1.661     raeburn  8188:                                    &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705     tempelho 8189:                                    $orig_uploaded_filename.'</a>').'</span><br />';
1.661     raeburn  8190:                     }
                   8191:                 }
                   8192:                 close($fh);
                   8193:             }
                   8194:         }
                   8195:     }
                   8196:     return $output;
                   8197: }
                   8198: 
                   8199: sub check_for_existing {
                   8200:     my ($path,$fname,$element) = @_;
                   8201:     my ($state,$msg);
                   8202:     if (-d $path.'/'.$fname) {
                   8203:         $state = 'exists';
                   8204:         $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   8205:     } elsif (-e $path.'/'.$fname) {
                   8206:         $state = 'exists';
                   8207:         $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   8208:     }
                   8209:     if ($state eq 'exists') {
                   8210:         $msg = '<span class="LC_error">'.$msg.'</span><br />';
                   8211:     }
                   8212:     return ($state,$msg);
                   8213: }
                   8214: 
                   8215: sub check_for_upload {
                   8216:     my ($path,$fname,$group,$element,$portfolio_root,$port_path,
                   8217:         $disk_quota,$current_disk_usage,$uname,$udom) = @_;
                   8218:     my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
                   8219:     my $getpropath = 1;
                   8220:     my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
                   8221:                                             $getpropath);
                   8222:     my $found_file = 0;
                   8223:     my $locked_file = 0;
                   8224:     foreach my $line (@dir_list) {
                   8225:         my ($file_name)=split(/\&/,$line,2);
                   8226:         if ($file_name eq $fname){
                   8227:             $file_name = $path.$file_name;
                   8228:             if ($group ne '') {
                   8229:                 $file_name = $group.$file_name;
                   8230:             }
                   8231:             $found_file = 1;
                   8232:             if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
                   8233:                 $locked_file = 1;
                   8234:             }
                   8235:         }
                   8236:     }
                   8237:     if (($current_disk_usage + $filesize) > $disk_quota){
                   8238:         my $msg = '<span class="LC_error">'.
                   8239:                 &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
                   8240:                   '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
                   8241:         return ('will_exceed_quota',$msg);
                   8242:     } elsif ($found_file) {
                   8243:         if ($locked_file) {
                   8244:             my $msg = '<span class="LC_error">';
                   8245:             $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>');
                   8246:             $msg .= '</span><br />';
                   8247:             $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
                   8248:             return ('file_locked',$msg);
                   8249:         } else {
                   8250:             my $msg = '<span class="LC_error">';
                   8251:             $msg .= &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
                   8252:             $msg .= '</span>';
                   8253:             $msg .= '<br />';
                   8254:             $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
                   8255:             return ('file_exists',$msg);
                   8256:         }
                   8257:     }
                   8258: }
                   8259: 
1.31      albertel 8260: 
1.41      ng       8261: =pod
1.45      matthew  8262: 
1.464     albertel 8263: =back
1.41      ng       8264: 
1.112     bowersj2 8265: =head1 CSV Upload/Handling functions
1.38      albertel 8266: 
1.41      ng       8267: =over 4
                   8268: 
1.648     raeburn  8269: =item * &upfile_store($r)
1.41      ng       8270: 
                   8271: Store uploaded file, $r should be the HTTP Request object,
1.258     albertel 8272: needs $env{'form.upfile'}
1.41      ng       8273: returns $datatoken to be put into hidden field
                   8274: 
                   8275: =cut
1.31      albertel 8276: 
                   8277: sub upfile_store {
                   8278:     my $r=shift;
1.258     albertel 8279:     $env{'form.upfile'}=~s/\r/\n/gs;
                   8280:     $env{'form.upfile'}=~s/\f/\n/gs;
                   8281:     $env{'form.upfile'}=~s/\n+/\n/gs;
                   8282:     $env{'form.upfile'}=~s/\n+$//gs;
1.31      albertel 8283: 
1.258     albertel 8284:     my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
                   8285: 	'_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31      albertel 8286:     {
1.158     raeburn  8287:         my $datafile = $r->dir_config('lonDaemons').
                   8288:                            '/tmp/'.$datatoken.'.tmp';
                   8289:         if ( open(my $fh,">$datafile") ) {
1.258     albertel 8290:             print $fh $env{'form.upfile'};
1.158     raeburn  8291:             close($fh);
                   8292:         }
1.31      albertel 8293:     }
                   8294:     return $datatoken;
                   8295: }
                   8296: 
1.56      matthew  8297: =pod
                   8298: 
1.648     raeburn  8299: =item * &load_tmp_file($r)
1.41      ng       8300: 
                   8301: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258     albertel 8302: needs $env{'form.datatoken'},
                   8303: sets $env{'form.upfile'} to the contents of the file
1.41      ng       8304: 
                   8305: =cut
1.31      albertel 8306: 
                   8307: sub load_tmp_file {
                   8308:     my $r=shift;
                   8309:     my @studentdata=();
                   8310:     {
1.158     raeburn  8311:         my $studentfile = $r->dir_config('lonDaemons').
1.258     albertel 8312:                               '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158     raeburn  8313:         if ( open(my $fh,"<$studentfile") ) {
                   8314:             @studentdata=<$fh>;
                   8315:             close($fh);
                   8316:         }
1.31      albertel 8317:     }
1.258     albertel 8318:     $env{'form.upfile'}=join('',@studentdata);
1.31      albertel 8319: }
                   8320: 
1.56      matthew  8321: =pod
                   8322: 
1.648     raeburn  8323: =item * &upfile_record_sep()
1.41      ng       8324: 
                   8325: Separate uploaded file into records
                   8326: returns array of records,
1.258     albertel 8327: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41      ng       8328: 
                   8329: =cut
1.31      albertel 8330: 
                   8331: sub upfile_record_sep {
1.258     albertel 8332:     if ($env{'form.upfiletype'} eq 'xml') {
1.31      albertel 8333:     } else {
1.248     albertel 8334: 	my @records;
1.258     albertel 8335: 	foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248     albertel 8336: 	    if ($line=~/^\s*$/) { next; }
                   8337: 	    push(@records,$line);
                   8338: 	}
                   8339: 	return @records;
1.31      albertel 8340:     }
                   8341: }
                   8342: 
1.56      matthew  8343: =pod
                   8344: 
1.648     raeburn  8345: =item * &record_sep($record)
1.41      ng       8346: 
1.258     albertel 8347: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41      ng       8348: 
                   8349: =cut
                   8350: 
1.263     www      8351: sub takeleft {
                   8352:     my $index=shift;
                   8353:     return substr('0000'.$index,-4,4);
                   8354: }
                   8355: 
1.31      albertel 8356: sub record_sep {
                   8357:     my $record=shift;
                   8358:     my %components=();
1.258     albertel 8359:     if ($env{'form.upfiletype'} eq 'xml') {
                   8360:     } elsif ($env{'form.upfiletype'} eq 'space') {
1.31      albertel 8361:         my $i=0;
1.356     albertel 8362:         foreach my $field (split(/\s+/,$record)) {
1.31      albertel 8363:             $field=~s/^(\"|\')//;
                   8364:             $field=~s/(\"|\')$//;
1.263     www      8365:             $components{&takeleft($i)}=$field;
1.31      albertel 8366:             $i++;
                   8367:         }
1.258     albertel 8368:     } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31      albertel 8369:         my $i=0;
1.356     albertel 8370:         foreach my $field (split(/\t/,$record)) {
1.31      albertel 8371:             $field=~s/^(\"|\')//;
                   8372:             $field=~s/(\"|\')$//;
1.263     www      8373:             $components{&takeleft($i)}=$field;
1.31      albertel 8374:             $i++;
                   8375:         }
                   8376:     } else {
1.561     www      8377:         my $separator=',';
1.480     banghart 8378:         if ($env{'form.upfiletype'} eq 'semisv') {
1.561     www      8379:             $separator=';';
1.480     banghart 8380:         }
1.31      albertel 8381:         my $i=0;
1.561     www      8382: # the character we are looking for to indicate the end of a quote or a record 
                   8383:         my $looking_for=$separator;
                   8384: # do not add the characters to the fields
                   8385:         my $ignore=0;
                   8386: # we just encountered a separator (or the beginning of the record)
                   8387:         my $just_found_separator=1;
                   8388: # store the field we are working on here
                   8389:         my $field='';
                   8390: # work our way through all characters in record
                   8391:         foreach my $character ($record=~/(.)/g) {
                   8392:             if ($character eq $looking_for) {
                   8393:                if ($character ne $separator) {
                   8394: # Found the end of a quote, again looking for separator
                   8395:                   $looking_for=$separator;
                   8396:                   $ignore=1;
                   8397:                } else {
                   8398: # Found a separator, store away what we got
                   8399:                   $components{&takeleft($i)}=$field;
                   8400: 	          $i++;
                   8401:                   $just_found_separator=1;
                   8402:                   $ignore=0;
                   8403:                   $field='';
                   8404:                }
                   8405:                next;
                   8406:             }
                   8407: # single or double quotation marks after a separator indicate beginning of a quote
                   8408: # we are now looking for the end of the quote and need to ignore separators
                   8409:             if ((($character eq '"') || ($character eq "'")) && ($just_found_separator))  {
                   8410:                $looking_for=$character;
                   8411:                next;
                   8412:             }
                   8413: # ignore would be true after we reached the end of a quote
                   8414:             if ($ignore) { next; }
                   8415:             if (($just_found_separator) && ($character=~/\s/)) { next; }
                   8416:             $field.=$character;
                   8417:             $just_found_separator=0; 
1.31      albertel 8418:         }
1.561     www      8419: # catch the very last entry, since we never encountered the separator
                   8420:         $components{&takeleft($i)}=$field;
1.31      albertel 8421:     }
                   8422:     return %components;
                   8423: }
                   8424: 
1.144     matthew  8425: ######################################################
                   8426: ######################################################
                   8427: 
1.56      matthew  8428: =pod
                   8429: 
1.648     raeburn  8430: =item * &upfile_select_html()
1.41      ng       8431: 
1.144     matthew  8432: Return HTML code to select a file from the users machine and specify 
                   8433: the file type.
1.41      ng       8434: 
                   8435: =cut
                   8436: 
1.144     matthew  8437: ######################################################
                   8438: ######################################################
1.31      albertel 8439: sub upfile_select_html {
1.144     matthew  8440:     my %Types = (
                   8441:                  csv   => &mt('CSV (comma separated values, spreadsheet)'),
1.480     banghart 8442:                  semisv => &mt('Semicolon separated values'),
1.144     matthew  8443:                  space => &mt('Space separated'),
                   8444:                  tab   => &mt('Tabulator separated'),
                   8445: #                 xml   => &mt('HTML/XML'),
                   8446:                  );
                   8447:     my $Str = '<input type="file" name="upfile" size="50" />'.
1.727     riegler  8448:         '<br />'.&mt('Type').': <select name="upfiletype">';
1.144     matthew  8449:     foreach my $type (sort(keys(%Types))) {
                   8450:         $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
                   8451:     }
                   8452:     $Str .= "</select>\n";
                   8453:     return $Str;
1.31      albertel 8454: }
                   8455: 
1.301     albertel 8456: sub get_samples {
                   8457:     my ($records,$toget) = @_;
                   8458:     my @samples=({});
                   8459:     my $got=0;
                   8460:     foreach my $rec (@$records) {
                   8461: 	my %temp = &record_sep($rec);
                   8462: 	if (! grep(/\S/, values(%temp))) { next; }
                   8463: 	if (%temp) {
                   8464: 	    $samples[$got]=\%temp;
                   8465: 	    $got++;
                   8466: 	    if ($got == $toget) { last; }
                   8467: 	}
                   8468:     }
                   8469:     return \@samples;
                   8470: }
                   8471: 
1.144     matthew  8472: ######################################################
                   8473: ######################################################
                   8474: 
1.56      matthew  8475: =pod
                   8476: 
1.648     raeburn  8477: =item * &csv_print_samples($r,$records)
1.41      ng       8478: 
                   8479: Prints a table of sample values from each column uploaded $r is an
                   8480: Apache Request ref, $records is an arrayref from
                   8481: &Apache::loncommon::upfile_record_sep
                   8482: 
                   8483: =cut
                   8484: 
1.144     matthew  8485: ######################################################
                   8486: ######################################################
1.31      albertel 8487: sub csv_print_samples {
                   8488:     my ($r,$records) = @_;
1.662     bisitz   8489:     my $samples = &get_samples($records,5);
1.301     albertel 8490: 
1.594     raeburn  8491:     $r->print(&mt('Samples').'<br />'.&start_data_table().
                   8492:               &start_data_table_header_row());
1.356     albertel 8493:     foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) { 
                   8494:         $r->print('<th>'.&mt('Column&nbsp;[_1]',($sample+1)).'</th>'); }
1.594     raeburn  8495:     $r->print(&end_data_table_header_row());
1.301     albertel 8496:     foreach my $hash (@$samples) {
1.594     raeburn  8497: 	$r->print(&start_data_table_row());
1.356     albertel 8498: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31      albertel 8499: 	    $r->print('<td>');
1.356     albertel 8500: 	    if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31      albertel 8501: 	    $r->print('</td>');
                   8502: 	}
1.594     raeburn  8503: 	$r->print(&end_data_table_row());
1.31      albertel 8504:     }
1.594     raeburn  8505:     $r->print(&end_data_table().'<br />'."\n");
1.31      albertel 8506: }
                   8507: 
1.144     matthew  8508: ######################################################
                   8509: ######################################################
                   8510: 
1.56      matthew  8511: =pod
                   8512: 
1.648     raeburn  8513: =item * &csv_print_select_table($r,$records,$d)
1.41      ng       8514: 
                   8515: Prints a table to create associations between values and table columns.
1.144     matthew  8516: 
1.41      ng       8517: $r is an Apache Request ref,
                   8518: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174     matthew  8519: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41      ng       8520: 
                   8521: =cut
                   8522: 
1.144     matthew  8523: ######################################################
                   8524: ######################################################
1.31      albertel 8525: sub csv_print_select_table {
                   8526:     my ($r,$records,$d) = @_;
1.301     albertel 8527:     my $i=0;
                   8528:     my $samples = &get_samples($records,1);
1.144     matthew  8529:     $r->print(&mt('Associate columns with student attributes.')."\n".
1.594     raeburn  8530: 	      &start_data_table().&start_data_table_header_row().
1.144     matthew  8531:               '<th>'.&mt('Attribute').'</th>'.
1.594     raeburn  8532:               '<th>'.&mt('Column').'</th>'.
                   8533:               &end_data_table_header_row()."\n");
1.356     albertel 8534:     foreach my $array_ref (@$d) {
                   8535: 	my ($value,$display,$defaultcol)=@{ $array_ref };
1.729     raeburn  8536: 	$r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31      albertel 8537: 
                   8538: 	$r->print('<td><select name=f'.$i.
1.32      matthew  8539: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.31      albertel 8540: 	$r->print('<option value="none"></option>');
1.356     albertel 8541: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
                   8542: 	    $r->print('<option value="'.$sample.'"'.
                   8543:                       ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662     bisitz   8544:                       '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31      albertel 8545: 	}
1.594     raeburn  8546: 	$r->print('</select></td>'.&end_data_table_row()."\n");
1.31      albertel 8547: 	$i++;
                   8548:     }
1.594     raeburn  8549:     $r->print(&end_data_table());
1.31      albertel 8550:     $i--;
                   8551:     return $i;
                   8552: }
1.56      matthew  8553: 
1.144     matthew  8554: ######################################################
                   8555: ######################################################
                   8556: 
1.56      matthew  8557: =pod
1.31      albertel 8558: 
1.648     raeburn  8559: =item * &csv_samples_select_table($r,$records,$d)
1.41      ng       8560: 
                   8561: Prints a table of sample values from the upload and can make associate samples to internal names.
                   8562: 
                   8563: $r is an Apache Request ref,
                   8564: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
                   8565: $d is an array of 2 element arrays (internal name, displayed name)
                   8566: 
                   8567: =cut
                   8568: 
1.144     matthew  8569: ######################################################
                   8570: ######################################################
1.31      albertel 8571: sub csv_samples_select_table {
                   8572:     my ($r,$records,$d) = @_;
                   8573:     my $i=0;
1.144     matthew  8574:     #
1.662     bisitz   8575:     my $max_samples = 5;
                   8576:     my $samples = &get_samples($records,$max_samples);
1.594     raeburn  8577:     $r->print(&start_data_table().
                   8578:               &start_data_table_header_row().'<th>'.
                   8579:               &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
                   8580:               &end_data_table_header_row());
1.301     albertel 8581: 
                   8582:     foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594     raeburn  8583: 	$r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32      matthew  8584: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.301     albertel 8585: 	foreach my $option (@$d) {
                   8586: 	    my ($value,$display,$defaultcol)=@{ $option };
1.174     matthew  8587: 	    $r->print('<option value="'.$value.'"'.
1.253     albertel 8588:                       ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174     matthew  8589:                       $display.'</option>');
1.31      albertel 8590: 	}
                   8591: 	$r->print('</select></td><td>');
1.662     bisitz   8592: 	foreach my $line (0..($max_samples-1)) {
1.301     albertel 8593: 	    if (defined($samples->[$line]{$key})) { 
                   8594: 		$r->print($samples->[$line]{$key}."<br />\n"); 
                   8595: 	    }
                   8596: 	}
1.594     raeburn  8597: 	$r->print('</td>'.&end_data_table_row());
1.31      albertel 8598: 	$i++;
                   8599:     }
1.594     raeburn  8600:     $r->print(&end_data_table());
1.31      albertel 8601:     $i--;
                   8602:     return($i);
1.115     matthew  8603: }
                   8604: 
1.144     matthew  8605: ######################################################
                   8606: ######################################################
                   8607: 
1.115     matthew  8608: =pod
                   8609: 
1.648     raeburn  8610: =item * &clean_excel_name($name)
1.115     matthew  8611: 
                   8612: Returns a replacement for $name which does not contain any illegal characters.
                   8613: 
                   8614: =cut
                   8615: 
1.144     matthew  8616: ######################################################
                   8617: ######################################################
1.115     matthew  8618: sub clean_excel_name {
                   8619:     my ($name) = @_;
                   8620:     $name =~ s/[:\*\?\/\\]//g;
                   8621:     if (length($name) > 31) {
                   8622:         $name = substr($name,0,31);
                   8623:     }
                   8624:     return $name;
1.25      albertel 8625: }
1.84      albertel 8626: 
1.85      albertel 8627: =pod
                   8628: 
1.648     raeburn  8629: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85      albertel 8630: 
                   8631: Returns either 1 or undef
                   8632: 
                   8633: 1 if the part is to be hidden, undef if it is to be shown
                   8634: 
                   8635: Arguments are:
                   8636: 
                   8637: $id the id of the part to be checked
                   8638: $symb, optional the symb of the resource to check
                   8639: $udom, optional the domain of the user to check for
                   8640: $uname, optional the username of the user to check for
                   8641: 
                   8642: =cut
1.84      albertel 8643: 
                   8644: sub check_if_partid_hidden {
                   8645:     my ($id,$symb,$udom,$uname) = @_;
1.133     albertel 8646:     my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84      albertel 8647: 					 $symb,$udom,$uname);
1.141     albertel 8648:     my $truth=1;
                   8649:     #if the string starts with !, then the list is the list to show not hide
                   8650:     if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84      albertel 8651:     my @hiddenlist=split(/,/,$hiddenparts);
                   8652:     foreach my $checkid (@hiddenlist) {
1.141     albertel 8653: 	if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84      albertel 8654:     }
1.141     albertel 8655:     return !$truth;
1.84      albertel 8656: }
1.127     matthew  8657: 
1.138     matthew  8658: 
                   8659: ############################################################
                   8660: ############################################################
                   8661: 
                   8662: =pod
                   8663: 
1.157     matthew  8664: =back 
                   8665: 
1.138     matthew  8666: =head1 cgi-bin script and graphing routines
                   8667: 
1.157     matthew  8668: =over 4
                   8669: 
1.648     raeburn  8670: =item * &get_cgi_id()
1.138     matthew  8671: 
                   8672: Inputs: none
                   8673: 
                   8674: Returns an id which can be used to pass environment variables
                   8675: to various cgi-bin scripts.  These environment variables will
                   8676: be removed from the users environment after a given time by
                   8677: the routine &Apache::lonnet::transfer_profile_to_env.
                   8678: 
                   8679: =cut
                   8680: 
                   8681: ############################################################
                   8682: ############################################################
1.152     albertel 8683: my $uniq=0;
1.136     matthew  8684: sub get_cgi_id {
1.154     albertel 8685:     $uniq=($uniq+1)%100000;
1.280     albertel 8686:     return (time.'_'.$$.'_'.$uniq);
1.136     matthew  8687: }
                   8688: 
1.127     matthew  8689: ############################################################
                   8690: ############################################################
                   8691: 
                   8692: =pod
                   8693: 
1.648     raeburn  8694: =item * &DrawBarGraph()
1.127     matthew  8695: 
1.138     matthew  8696: Facilitates the plotting of data in a (stacked) bar graph.
                   8697: Puts plot definition data into the users environment in order for 
                   8698: graph.png to plot it.  Returns an <img> tag for the plot.
                   8699: The bars on the plot are labeled '1','2',...,'n'.
                   8700: 
                   8701: Inputs:
                   8702: 
                   8703: =over 4
                   8704: 
                   8705: =item $Title: string, the title of the plot
                   8706: 
                   8707: =item $xlabel: string, text describing the X-axis of the plot
                   8708: 
                   8709: =item $ylabel: string, text describing the Y-axis of the plot
                   8710: 
                   8711: =item $Max: scalar, the maximum Y value to use in the plot
                   8712: If $Max is < any data point, the graph will not be rendered.
                   8713: 
1.140     matthew  8714: =item $colors: array ref holding the colors to be used for the data sets when
1.138     matthew  8715: they are plotted.  If undefined, default values will be used.
                   8716: 
1.178     matthew  8717: =item $labels: array ref holding the labels to use on the x-axis for the bars.
                   8718: 
1.138     matthew  8719: =item @Values: An array of array references.  Each array reference holds data
                   8720: to be plotted in a stacked bar chart.
                   8721: 
1.239     matthew  8722: =item If the final element of @Values is a hash reference the key/value
                   8723: pairs will be added to the graph definition.
                   8724: 
1.138     matthew  8725: =back
                   8726: 
                   8727: Returns:
                   8728: 
                   8729: An <img> tag which references graph.png and the appropriate identifying
                   8730: information for the plot.
                   8731: 
1.127     matthew  8732: =cut
                   8733: 
                   8734: ############################################################
                   8735: ############################################################
1.134     matthew  8736: sub DrawBarGraph {
1.178     matthew  8737:     my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134     matthew  8738:     #
                   8739:     if (! defined($colors)) {
                   8740:         $colors = ['#33ff00', 
                   8741:                   '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
                   8742:                   '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
                   8743:                   ]; 
                   8744:     }
1.228     matthew  8745:     my $extra_settings = {};
                   8746:     if (ref($Values[-1]) eq 'HASH') {
                   8747:         $extra_settings = pop(@Values);
                   8748:     }
1.127     matthew  8749:     #
1.136     matthew  8750:     my $identifier = &get_cgi_id();
                   8751:     my $id = 'cgi.'.$identifier;        
1.129     matthew  8752:     if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127     matthew  8753:         return '';
                   8754:     }
1.225     matthew  8755:     #
                   8756:     my @Labels;
                   8757:     if (defined($labels)) {
                   8758:         @Labels = @$labels;
                   8759:     } else {
                   8760:         for (my $i=0;$i<@{$Values[0]};$i++) {
                   8761:             push (@Labels,$i+1);
                   8762:         }
                   8763:     }
                   8764:     #
1.129     matthew  8765:     my $NumBars = scalar(@{$Values[0]});
1.225     matthew  8766:     if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129     matthew  8767:     my %ValuesHash;
                   8768:     my $NumSets=1;
                   8769:     foreach my $array (@Values) {
                   8770:         next if (! ref($array));
1.136     matthew  8771:         $ValuesHash{$id.'.data.'.$NumSets++} = 
1.132     matthew  8772:             join(',',@$array);
1.129     matthew  8773:     }
1.127     matthew  8774:     #
1.136     matthew  8775:     my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225     matthew  8776:     if ($NumBars < 3) {
                   8777:         $width = 120+$NumBars*32;
1.220     matthew  8778:         $xskip = 1;
1.225     matthew  8779:         $bar_width = 30;
                   8780:     } elsif ($NumBars < 5) {
                   8781:         $width = 120+$NumBars*20;
                   8782:         $xskip = 1;
                   8783:         $bar_width = 20;
1.220     matthew  8784:     } elsif ($NumBars < 10) {
1.136     matthew  8785:         $width = 120+$NumBars*15;
                   8786:         $xskip = 1;
                   8787:         $bar_width = 15;
                   8788:     } elsif ($NumBars <= 25) {
                   8789:         $width = 120+$NumBars*11;
                   8790:         $xskip = 5;
                   8791:         $bar_width = 8;
                   8792:     } elsif ($NumBars <= 50) {
                   8793:         $width = 120+$NumBars*8;
                   8794:         $xskip = 5;
                   8795:         $bar_width = 4;
                   8796:     } else {
                   8797:         $width = 120+$NumBars*8;
                   8798:         $xskip = 5;
                   8799:         $bar_width = 4;
                   8800:     }
                   8801:     #
1.137     matthew  8802:     $Max = 1 if ($Max < 1);
                   8803:     if ( int($Max) < $Max ) {
                   8804:         $Max++;
                   8805:         $Max = int($Max);
                   8806:     }
1.127     matthew  8807:     $Title  = '' if (! defined($Title));
                   8808:     $xlabel = '' if (! defined($xlabel));
                   8809:     $ylabel = '' if (! defined($ylabel));
1.369     www      8810:     $ValuesHash{$id.'.title'}    = &escape($Title);
                   8811:     $ValuesHash{$id.'.xlabel'}   = &escape($xlabel);
                   8812:     $ValuesHash{$id.'.ylabel'}   = &escape($ylabel);
1.137     matthew  8813:     $ValuesHash{$id.'.y_max_value'} = $Max;
1.136     matthew  8814:     $ValuesHash{$id.'.NumBars'}  = $NumBars;
                   8815:     $ValuesHash{$id.'.NumSets'}  = $NumSets;
                   8816:     $ValuesHash{$id.'.PlotType'} = 'bar';
                   8817:     $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8818:     $ValuesHash{$id.'.height'}   = $height;
                   8819:     $ValuesHash{$id.'.width'}    = $width;
                   8820:     $ValuesHash{$id.'.xskip'}    = $xskip;
                   8821:     $ValuesHash{$id.'.bar_width'} = $bar_width;
                   8822:     $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127     matthew  8823:     #
1.228     matthew  8824:     # Deal with other parameters
                   8825:     while (my ($key,$value) = each(%$extra_settings)) {
                   8826:         $ValuesHash{$id.'.'.$key} = $value;
                   8827:     }
                   8828:     #
1.646     raeburn  8829:     &Apache::lonnet::appenv(\%ValuesHash);
1.137     matthew  8830:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   8831: }
                   8832: 
                   8833: ############################################################
                   8834: ############################################################
                   8835: 
                   8836: =pod
                   8837: 
1.648     raeburn  8838: =item * &DrawXYGraph()
1.137     matthew  8839: 
1.138     matthew  8840: Facilitates the plotting of data in an XY graph.
                   8841: Puts plot definition data into the users environment in order for 
                   8842: graph.png to plot it.  Returns an <img> tag for the plot.
                   8843: 
                   8844: Inputs:
                   8845: 
                   8846: =over 4
                   8847: 
                   8848: =item $Title: string, the title of the plot
                   8849: 
                   8850: =item $xlabel: string, text describing the X-axis of the plot
                   8851: 
                   8852: =item $ylabel: string, text describing the Y-axis of the plot
                   8853: 
                   8854: =item $Max: scalar, the maximum Y value to use in the plot
                   8855: If $Max is < any data point, the graph will not be rendered.
                   8856: 
                   8857: =item $colors: Array ref containing the hex color codes for the data to be 
                   8858: plotted in.  If undefined, default values will be used.
                   8859: 
                   8860: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   8861: 
                   8862: =item $Ydata: Array ref containing Array refs.  
1.185     www      8863: Each of the contained arrays will be plotted as a separate curve.
1.138     matthew  8864: 
                   8865: =item %Values: hash indicating or overriding any default values which are 
                   8866: passed to graph.png.  
                   8867: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   8868: 
                   8869: =back
                   8870: 
                   8871: Returns:
                   8872: 
                   8873: An <img> tag which references graph.png and the appropriate identifying
                   8874: information for the plot.
                   8875: 
1.137     matthew  8876: =cut
                   8877: 
                   8878: ############################################################
                   8879: ############################################################
                   8880: sub DrawXYGraph {
                   8881:     my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
                   8882:     #
                   8883:     # Create the identifier for the graph
                   8884:     my $identifier = &get_cgi_id();
                   8885:     my $id = 'cgi.'.$identifier;
                   8886:     #
                   8887:     $Title  = '' if (! defined($Title));
                   8888:     $xlabel = '' if (! defined($xlabel));
                   8889:     $ylabel = '' if (! defined($ylabel));
                   8890:     my %ValuesHash = 
                   8891:         (
1.369     www      8892:          $id.'.title'  => &escape($Title),
                   8893:          $id.'.xlabel' => &escape($xlabel),
                   8894:          $id.'.ylabel' => &escape($ylabel),
1.137     matthew  8895:          $id.'.y_max_value'=> $Max,
                   8896:          $id.'.labels'     => join(',',@$Xlabels),
                   8897:          $id.'.PlotType'   => 'XY',
                   8898:          );
                   8899:     #
                   8900:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   8901:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8902:     }
                   8903:     #
                   8904:     if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
                   8905:         return '';
                   8906:     }
                   8907:     my $NumSets=1;
1.138     matthew  8908:     foreach my $array (@{$Ydata}){
1.137     matthew  8909:         next if (! ref($array));
                   8910:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
                   8911:     }
1.138     matthew  8912:     $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137     matthew  8913:     #
                   8914:     # Deal with other parameters
                   8915:     while (my ($key,$value) = each(%Values)) {
                   8916:         $ValuesHash{$id.'.'.$key} = $value;
1.127     matthew  8917:     }
                   8918:     #
1.646     raeburn  8919:     &Apache::lonnet::appenv(\%ValuesHash);
1.136     matthew  8920:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   8921: }
                   8922: 
                   8923: ############################################################
                   8924: ############################################################
                   8925: 
                   8926: =pod
                   8927: 
1.648     raeburn  8928: =item * &DrawXYYGraph()
1.138     matthew  8929: 
                   8930: Facilitates the plotting of data in an XY graph with two Y axes.
                   8931: Puts plot definition data into the users environment in order for 
                   8932: graph.png to plot it.  Returns an <img> tag for the plot.
                   8933: 
                   8934: Inputs:
                   8935: 
                   8936: =over 4
                   8937: 
                   8938: =item $Title: string, the title of the plot
                   8939: 
                   8940: =item $xlabel: string, text describing the X-axis of the plot
                   8941: 
                   8942: =item $ylabel: string, text describing the Y-axis of the plot
                   8943: 
                   8944: =item $colors: Array ref containing the hex color codes for the data to be 
                   8945: plotted in.  If undefined, default values will be used.
                   8946: 
                   8947: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   8948: 
                   8949: =item $Ydata1: The first data set
                   8950: 
                   8951: =item $Min1: The minimum value of the left Y-axis
                   8952: 
                   8953: =item $Max1: The maximum value of the left Y-axis
                   8954: 
                   8955: =item $Ydata2: The second data set
                   8956: 
                   8957: =item $Min2: The minimum value of the right Y-axis
                   8958: 
                   8959: =item $Max2: The maximum value of the left Y-axis
                   8960: 
                   8961: =item %Values: hash indicating or overriding any default values which are 
                   8962: passed to graph.png.  
                   8963: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   8964: 
                   8965: =back
                   8966: 
                   8967: Returns:
                   8968: 
                   8969: An <img> tag which references graph.png and the appropriate identifying
                   8970: information for the plot.
1.136     matthew  8971: 
                   8972: =cut
                   8973: 
                   8974: ############################################################
                   8975: ############################################################
1.137     matthew  8976: sub DrawXYYGraph {
                   8977:     my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
                   8978:                                         $Ydata2,$Min2,$Max2,%Values)=@_;
1.136     matthew  8979:     #
                   8980:     # Create the identifier for the graph
                   8981:     my $identifier = &get_cgi_id();
                   8982:     my $id = 'cgi.'.$identifier;
                   8983:     #
                   8984:     $Title  = '' if (! defined($Title));
                   8985:     $xlabel = '' if (! defined($xlabel));
                   8986:     $ylabel = '' if (! defined($ylabel));
                   8987:     my %ValuesHash = 
                   8988:         (
1.369     www      8989:          $id.'.title'  => &escape($Title),
                   8990:          $id.'.xlabel' => &escape($xlabel),
                   8991:          $id.'.ylabel' => &escape($ylabel),
1.136     matthew  8992:          $id.'.labels' => join(',',@$Xlabels),
                   8993:          $id.'.PlotType' => 'XY',
                   8994:          $id.'.NumSets' => 2,
1.137     matthew  8995:          $id.'.two_axes' => 1,
                   8996:          $id.'.y1_max_value' => $Max1,
                   8997:          $id.'.y1_min_value' => $Min1,
                   8998:          $id.'.y2_max_value' => $Max2,
                   8999:          $id.'.y2_min_value' => $Min2,
1.136     matthew  9000:          );
                   9001:     #
1.137     matthew  9002:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   9003:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   9004:     }
                   9005:     #
                   9006:     if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
                   9007:         ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136     matthew  9008:         return '';
                   9009:     }
                   9010:     my $NumSets=1;
1.137     matthew  9011:     foreach my $array ($Ydata1,$Ydata2){
1.136     matthew  9012:         next if (! ref($array));
                   9013:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137     matthew  9014:     }
                   9015:     #
                   9016:     # Deal with other parameters
                   9017:     while (my ($key,$value) = each(%Values)) {
                   9018:         $ValuesHash{$id.'.'.$key} = $value;
1.136     matthew  9019:     }
                   9020:     #
1.646     raeburn  9021:     &Apache::lonnet::appenv(\%ValuesHash);
1.130     albertel 9022:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139     matthew  9023: }
                   9024: 
                   9025: ############################################################
                   9026: ############################################################
                   9027: 
                   9028: =pod
                   9029: 
1.157     matthew  9030: =back 
                   9031: 
1.139     matthew  9032: =head1 Statistics helper routines?  
                   9033: 
                   9034: Bad place for them but what the hell.
                   9035: 
1.157     matthew  9036: =over 4
                   9037: 
1.648     raeburn  9038: =item * &chartlink()
1.139     matthew  9039: 
                   9040: Returns a link to the chart for a specific student.  
                   9041: 
                   9042: Inputs:
                   9043: 
                   9044: =over 4
                   9045: 
                   9046: =item $linktext: The text of the link
                   9047: 
                   9048: =item $sname: The students username
                   9049: 
                   9050: =item $sdomain: The students domain
                   9051: 
                   9052: =back
                   9053: 
1.157     matthew  9054: =back
                   9055: 
1.139     matthew  9056: =cut
                   9057: 
                   9058: ############################################################
                   9059: ############################################################
                   9060: sub chartlink {
                   9061:     my ($linktext, $sname, $sdomain) = @_;
                   9062:     my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369     www      9063:         '&amp;SelectedStudent='.&escape($sname.':'.$sdomain).
1.219     albertel 9064:         '&amp;chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139     matthew  9065:        '">'.$linktext.'</a>';
1.153     matthew  9066: }
                   9067: 
                   9068: #######################################################
                   9069: #######################################################
                   9070: 
                   9071: =pod
                   9072: 
                   9073: =head1 Course Environment Routines
1.157     matthew  9074: 
                   9075: =over 4
1.153     matthew  9076: 
1.648     raeburn  9077: =item * &restore_course_settings()
1.153     matthew  9078: 
1.648     raeburn  9079: =item * &store_course_settings()
1.153     matthew  9080: 
                   9081: Restores/Store indicated form parameters from the course environment.
                   9082: Will not overwrite existing values of the form parameters.
                   9083: 
                   9084: Inputs: 
                   9085: a scalar describing the data (e.g. 'chart', 'problem_analysis')
                   9086: 
                   9087: a hash ref describing the data to be stored.  For example:
                   9088:    
                   9089: %Save_Parameters = ('Status' => 'scalar',
                   9090:     'chartoutputmode' => 'scalar',
                   9091:     'chartoutputdata' => 'scalar',
                   9092:     'Section' => 'array',
1.373     raeburn  9093:     'Group' => 'array',
1.153     matthew  9094:     'StudentData' => 'array',
                   9095:     'Maps' => 'array');
                   9096: 
                   9097: Returns: both routines return nothing
                   9098: 
1.631     raeburn  9099: =back
                   9100: 
1.153     matthew  9101: =cut
                   9102: 
                   9103: #######################################################
                   9104: #######################################################
                   9105: sub store_course_settings {
1.496     albertel 9106:     return &store_settings($env{'request.course.id'},@_);
                   9107: }
                   9108: 
                   9109: sub store_settings {
1.153     matthew  9110:     # save to the environment
                   9111:     # appenv the same items, just to be safe
1.300     albertel 9112:     my $udom  = $env{'user.domain'};
                   9113:     my $uname = $env{'user.name'};
1.496     albertel 9114:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  9115:     my %SaveHash;
                   9116:     my %AppHash;
                   9117:     while (my ($setting,$type) = each(%$Settings)) {
1.496     albertel 9118:         my $basename = join('.','internal',$context,$prefix,$setting);
1.300     albertel 9119:         my $envname = 'environment.'.$basename;
1.258     albertel 9120:         if (exists($env{'form.'.$setting})) {
1.153     matthew  9121:             # Save this value away
                   9122:             if ($type eq 'scalar' &&
1.258     albertel 9123:                 (! exists($env{$envname}) || 
                   9124:                  $env{$envname} ne $env{'form.'.$setting})) {
                   9125:                 $SaveHash{$basename} = $env{'form.'.$setting};
                   9126:                 $AppHash{$envname}   = $env{'form.'.$setting};
1.153     matthew  9127:             } elsif ($type eq 'array') {
                   9128:                 my $stored_form;
1.258     albertel 9129:                 if (ref($env{'form.'.$setting})) {
1.153     matthew  9130:                     $stored_form = join(',',
                   9131:                                         map {
1.369     www      9132:                                             &escape($_);
1.258     albertel 9133:                                         } sort(@{$env{'form.'.$setting}}));
1.153     matthew  9134:                 } else {
                   9135:                     $stored_form = 
1.369     www      9136:                         &escape($env{'form.'.$setting});
1.153     matthew  9137:                 }
                   9138:                 # Determine if the array contents are the same.
1.258     albertel 9139:                 if ($stored_form ne $env{$envname}) {
1.153     matthew  9140:                     $SaveHash{$basename} = $stored_form;
                   9141:                     $AppHash{$envname}   = $stored_form;
                   9142:                 }
                   9143:             }
                   9144:         }
                   9145:     }
                   9146:     my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300     albertel 9147:                                           $udom,$uname);
1.153     matthew  9148:     if ($put_result !~ /^(ok|delayed)/) {
                   9149:         &Apache::lonnet::logthis('unable to save form parameters, '.
                   9150:                                  'got error:'.$put_result);
                   9151:     }
                   9152:     # Make sure these settings stick around in this session, too
1.646     raeburn  9153:     &Apache::lonnet::appenv(\%AppHash);
1.153     matthew  9154:     return;
                   9155: }
                   9156: 
                   9157: sub restore_course_settings {
1.499     albertel 9158:     return &restore_settings($env{'request.course.id'},@_);
1.496     albertel 9159: }
                   9160: 
                   9161: sub restore_settings {
                   9162:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  9163:     while (my ($setting,$type) = each(%$Settings)) {
1.258     albertel 9164:         next if (exists($env{'form.'.$setting}));
1.496     albertel 9165:         my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153     matthew  9166:             '.'.$setting;
1.258     albertel 9167:         if (exists($env{$envname})) {
1.153     matthew  9168:             if ($type eq 'scalar') {
1.258     albertel 9169:                 $env{'form.'.$setting} = $env{$envname};
1.153     matthew  9170:             } elsif ($type eq 'array') {
1.258     albertel 9171:                 $env{'form.'.$setting} = [ 
1.153     matthew  9172:                                            map { 
1.369     www      9173:                                                &unescape($_); 
1.258     albertel 9174:                                            } split(',',$env{$envname})
1.153     matthew  9175:                                            ];
                   9176:             }
                   9177:         }
                   9178:     }
1.127     matthew  9179: }
                   9180: 
1.618     raeburn  9181: #######################################################
                   9182: #######################################################
                   9183: 
                   9184: =pod
                   9185: 
                   9186: =head1 Domain E-mail Routines  
                   9187: 
                   9188: =over 4
                   9189: 
1.648     raeburn  9190: =item * &build_recipient_list()
1.618     raeburn  9191: 
1.766     raeburn  9192: Build recipient lists for four types of e-mail:
                   9193: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
                   9194: (d) Help requests, generated by
                   9195: lonerrorhandler.pm, CHECKRPMS, loncron, and lonsupportreq.pm respectively.
1.618     raeburn  9196: 
                   9197: Inputs:
1.619     raeburn  9198: defmail (scalar - email address of default recipient), 
1.618     raeburn  9199: mailing type (scalar - errormail, packagesmail, or helpdeskmail), 
1.619     raeburn  9200: defdom (domain for which to retrieve configuration settings),
                   9201: origmail (scalar - email address of recipient from loncapa.conf, 
                   9202: i.e., predates configuration by DC via domainprefs.pm 
1.618     raeburn  9203: 
1.655     raeburn  9204: Returns: comma separated list of addresses to which to send e-mail.
                   9205: 
                   9206: =back
1.618     raeburn  9207: 
                   9208: =cut
                   9209: 
                   9210: ############################################################
                   9211: ############################################################
                   9212: sub build_recipient_list {
1.619     raeburn  9213:     my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618     raeburn  9214:     my @recipients;
                   9215:     my $otheremails;
                   9216:     my %domconfig =
                   9217:          &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
                   9218:     if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766     raeburn  9219:         if (exists($domconfig{'contacts'}{$mailing})) {
                   9220:             if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
                   9221:                 my @contacts = ('adminemail','supportemail');
                   9222:                 foreach my $item (@contacts) {
                   9223:                     if ($domconfig{'contacts'}{$mailing}{$item}) {
                   9224:                         my $addr = $domconfig{'contacts'}{$item}; 
                   9225:                         if (!grep(/^\Q$addr\E$/,@recipients)) {
                   9226:                             push(@recipients,$addr);
                   9227:                         }
1.619     raeburn  9228:                     }
1.766     raeburn  9229:                     $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618     raeburn  9230:                 }
                   9231:             }
1.766     raeburn  9232:         } elsif ($origmail ne '') {
                   9233:             push(@recipients,$origmail);
1.618     raeburn  9234:         }
1.619     raeburn  9235:     } elsif ($origmail ne '') {
                   9236:         push(@recipients,$origmail);
1.618     raeburn  9237:     }
1.688     raeburn  9238:     if (defined($defmail)) {
                   9239:         if ($defmail ne '') {
                   9240:             push(@recipients,$defmail);
                   9241:         }
1.618     raeburn  9242:     }
                   9243:     if ($otheremails) {
1.619     raeburn  9244:         my @others;
                   9245:         if ($otheremails =~ /,/) {
                   9246:             @others = split(/,/,$otheremails);
1.618     raeburn  9247:         } else {
1.619     raeburn  9248:             push(@others,$otheremails);
                   9249:         }
                   9250:         foreach my $addr (@others) {
                   9251:             if (!grep(/^\Q$addr\E$/,@recipients)) {
                   9252:                 push(@recipients,$addr);
                   9253:             }
1.618     raeburn  9254:         }
                   9255:     }
1.619     raeburn  9256:     my $recipientlist = join(',',@recipients); 
1.618     raeburn  9257:     return $recipientlist;
                   9258: }
                   9259: 
1.127     matthew  9260: ############################################################
                   9261: ############################################################
1.154     albertel 9262: 
1.655     raeburn  9263: =pod
                   9264: 
                   9265: =head1 Course Catalog Routines
                   9266: 
                   9267: =over 4
                   9268: 
                   9269: =item * &gather_categories()
                   9270: 
                   9271: Converts category definitions - keys of categories hash stored in  
                   9272: coursecategories in configuration.db on the primary library server in a 
                   9273: domain - to an array.  Also generates javascript and idx hash used to 
                   9274: generate Domain Coordinator interface for editing Course Categories.
                   9275: 
                   9276: Inputs:
1.663     raeburn  9277: 
1.655     raeburn  9278: categories (reference to hash of category definitions).
1.663     raeburn  9279: 
1.655     raeburn  9280: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9281:       categories and subcategories).
1.663     raeburn  9282: 
1.655     raeburn  9283: idx (reference to hash of counters used in Domain Coordinator interface for 
                   9284:       editing Course Categories).
1.663     raeburn  9285: 
1.655     raeburn  9286: jsarray (reference to array of categories used to create Javascript arrays for
                   9287:          Domain Coordinator interface for editing Course Categories).
                   9288: 
                   9289: Returns: nothing
                   9290: 
                   9291: Side effects: populates cats, idx and jsarray. 
                   9292: 
                   9293: =cut
                   9294: 
                   9295: sub gather_categories {
                   9296:     my ($categories,$cats,$idx,$jsarray) = @_;
                   9297:     my %counters;
                   9298:     my $num = 0;
                   9299:     foreach my $item (keys(%{$categories})) {
                   9300:         my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   9301:         if ($container eq '' && $depth == 0) {
                   9302:             $cats->[$depth][$categories->{$item}] = $cat;
                   9303:         } else {
                   9304:             $cats->[$depth]{$container}[$categories->{$item}] = $cat;
                   9305:         }
                   9306:         my ($escitem,$tail) = split(/:/,$item,2);
                   9307:         if ($counters{$tail} eq '') {
                   9308:             $counters{$tail} = $num;
                   9309:             $num ++;
                   9310:         }
                   9311:         if (ref($idx) eq 'HASH') {
                   9312:             $idx->{$item} = $counters{$tail};
                   9313:         }
                   9314:         if (ref($jsarray) eq 'ARRAY') {
                   9315:             push(@{$jsarray->[$counters{$tail}]},$item);
                   9316:         }
                   9317:     }
                   9318:     return;
                   9319: }
                   9320: 
                   9321: =pod
                   9322: 
                   9323: =item * &extract_categories()
                   9324: 
                   9325: Used to generate breadcrumb trails for course categories.
                   9326: 
                   9327: Inputs:
1.663     raeburn  9328: 
1.655     raeburn  9329: categories (reference to hash of category definitions).
1.663     raeburn  9330: 
1.655     raeburn  9331: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9332:       categories and subcategories).
1.663     raeburn  9333: 
1.655     raeburn  9334: trails (reference to array of breacrumb trails for each category).
1.663     raeburn  9335: 
1.655     raeburn  9336: allitems (reference to hash - key is category key 
                   9337:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  9338: 
1.655     raeburn  9339: idx (reference to hash of counters used in Domain Coordinator interface for
                   9340:       editing Course Categories).
1.663     raeburn  9341: 
1.655     raeburn  9342: jsarray (reference to array of categories used to create Javascript arrays for
                   9343:          Domain Coordinator interface for editing Course Categories).
                   9344: 
1.665     raeburn  9345: subcats (reference to hash of arrays containing all subcategories within each 
                   9346:          category, -recursive)
                   9347: 
1.655     raeburn  9348: Returns: nothing
                   9349: 
                   9350: Side effects: populates trails and allitems hash references.
                   9351: 
                   9352: =cut
                   9353: 
                   9354: sub extract_categories {
1.665     raeburn  9355:     my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655     raeburn  9356:     if (ref($categories) eq 'HASH') {
                   9357:         &gather_categories($categories,$cats,$idx,$jsarray);
                   9358:         if (ref($cats->[0]) eq 'ARRAY') {
                   9359:             for (my $i=0; $i<@{$cats->[0]}; $i++) {
                   9360:                 my $name = $cats->[0][$i];
                   9361:                 my $item = &escape($name).'::0';
                   9362:                 my $trailstr;
                   9363:                 if ($name eq 'instcode') {
                   9364:                     $trailstr = &mt('Official courses (with institutional codes)');
                   9365:                 } else {
                   9366:                     $trailstr = $name;
                   9367:                 }
                   9368:                 if ($allitems->{$item} eq '') {
                   9369:                     push(@{$trails},$trailstr);
                   9370:                     $allitems->{$item} = scalar(@{$trails})-1;
                   9371:                 }
                   9372:                 my @parents = ($name);
                   9373:                 if (ref($cats->[1]{$name}) eq 'ARRAY') {
                   9374:                     for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
                   9375:                         my $category = $cats->[1]{$name}[$j];
1.665     raeburn  9376:                         if (ref($subcats) eq 'HASH') {
                   9377:                             push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
                   9378:                         }
                   9379:                         &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
                   9380:                     }
                   9381:                 } else {
                   9382:                     if (ref($subcats) eq 'HASH') {
                   9383:                         $subcats->{$item} = [];
1.655     raeburn  9384:                     }
                   9385:                 }
                   9386:             }
                   9387:         }
                   9388:     }
                   9389:     return;
                   9390: }
                   9391: 
                   9392: =pod
                   9393: 
                   9394: =item *&recurse_categories()
                   9395: 
                   9396: Recursively used to generate breadcrumb trails for course categories.
                   9397: 
                   9398: Inputs:
1.663     raeburn  9399: 
1.655     raeburn  9400: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9401:       categories and subcategories).
1.663     raeburn  9402: 
1.655     raeburn  9403: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663     raeburn  9404: 
                   9405: category (current course category, for which breadcrumb trail is being generated).
                   9406: 
                   9407: trails (reference to array of breadcrumb trails for each category).
                   9408: 
1.655     raeburn  9409: allitems (reference to hash - key is category key
                   9410:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  9411: 
1.655     raeburn  9412: parents (array containing containers directories for current category, 
                   9413:          back to top level). 
                   9414: 
                   9415: Returns: nothing
                   9416: 
                   9417: Side effects: populates trails and allitems hash references
                   9418: 
                   9419: =cut
                   9420: 
                   9421: sub recurse_categories {
1.665     raeburn  9422:     my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655     raeburn  9423:     my $shallower = $depth - 1;
                   9424:     if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
                   9425:         for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
                   9426:             my $name = $cats->[$depth]{$category}[$k];
                   9427:             my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   9428:             my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   9429:             if ($allitems->{$item} eq '') {
                   9430:                 push(@{$trails},$trailstr);
                   9431:                 $allitems->{$item} = scalar(@{$trails})-1;
                   9432:             }
                   9433:             my $deeper = $depth+1;
                   9434:             push(@{$parents},$category);
1.665     raeburn  9435:             if (ref($subcats) eq 'HASH') {
                   9436:                 my $subcat = &escape($name).':'.$category.':'.$depth;
                   9437:                 for (my $j=@{$parents}; $j>=0; $j--) {
                   9438:                     my $higher;
                   9439:                     if ($j > 0) {
                   9440:                         $higher = &escape($parents->[$j]).':'.
                   9441:                                   &escape($parents->[$j-1]).':'.$j;
                   9442:                     } else {
                   9443:                         $higher = &escape($parents->[$j]).'::'.$j;
                   9444:                     }
                   9445:                     push(@{$subcats->{$higher}},$subcat);
                   9446:                 }
                   9447:             }
                   9448:             &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
                   9449:                                 $subcats);
1.655     raeburn  9450:             pop(@{$parents});
                   9451:         }
                   9452:     } else {
                   9453:         my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   9454:         my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   9455:         if ($allitems->{$item} eq '') {
                   9456:             push(@{$trails},$trailstr);
                   9457:             $allitems->{$item} = scalar(@{$trails})-1;
                   9458:         }
                   9459:     }
                   9460:     return;
                   9461: }
                   9462: 
1.663     raeburn  9463: =pod
                   9464: 
                   9465: =item *&assign_categories_table()
                   9466: 
                   9467: Create a datatable for display of hierarchical categories in a domain,
                   9468: with checkboxes to allow a course to be categorized. 
                   9469: 
                   9470: Inputs:
                   9471: 
                   9472: cathash - reference to hash of categories defined for the domain (from
                   9473:           configuration.db)
                   9474: 
                   9475: currcat - scalar with an & separated list of categories assigned to a course. 
                   9476: 
                   9477: Returns: $output (markup to be displayed) 
                   9478: 
                   9479: =cut
                   9480: 
                   9481: sub assign_categories_table {
                   9482:     my ($cathash,$currcat) = @_;
                   9483:     my $output;
                   9484:     if (ref($cathash) eq 'HASH') {
                   9485:         my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
                   9486:         &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
                   9487:         $maxdepth = scalar(@cats);
                   9488:         if (@cats > 0) {
                   9489:             my $itemcount = 0;
                   9490:             if (ref($cats[0]) eq 'ARRAY') {
                   9491:                 $output = &Apache::loncommon::start_data_table();
                   9492:                 my @currcategories;
                   9493:                 if ($currcat ne '') {
                   9494:                     @currcategories = split('&',$currcat);
                   9495:                 }
                   9496:                 for (my $i=0; $i<@{$cats[0]}; $i++) {
                   9497:                     my $parent = $cats[0][$i];
                   9498:                     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9499:                     next if ($parent eq 'instcode');
                   9500:                     my $item = &escape($parent).'::0';
                   9501:                     my $checked = '';
                   9502:                     if (@currcategories > 0) {
                   9503:                         if (grep(/^\Q$item\E$/,@currcategories)) {
1.772     bisitz   9504:                             $checked = ' checked="checked"';
1.663     raeburn  9505:                         }
                   9506:                     }
1.675     raeburn  9507:                     $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
                   9508:                                '<input type="checkbox" name="usecategory" value="'.
                   9509:                                $item.'"'.$checked.' />'.$parent.'</span>'.
                   9510:                                '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663     raeburn  9511:                     my $depth = 1;
                   9512:                     push(@path,$parent);
                   9513:                     $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
                   9514:                     pop(@path);
                   9515:                     $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   9516:                     $itemcount ++;
                   9517:                 }
                   9518:                 $output .= &Apache::loncommon::end_data_table();
                   9519:             }
                   9520:         }
                   9521:     }
                   9522:     return $output;
                   9523: }
                   9524: 
                   9525: =pod
                   9526: 
                   9527: =item *&assign_category_rows()
                   9528: 
                   9529: Create a datatable row for display of nested categories in a domain,
                   9530: with checkboxes to allow a course to be categorized,called recursively.
                   9531: 
                   9532: Inputs:
                   9533: 
                   9534: itemcount - track row number for alternating colors
                   9535: 
                   9536: cats - reference to array of arrays/hashes which encapsulates hierarchy of
                   9537:       categories and subcategories.
                   9538: 
                   9539: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
                   9540: 
                   9541: parent - parent of current category item
                   9542: 
                   9543: path - Array containing all categories back up through the hierarchy from the
                   9544:        current category to the top level.
                   9545: 
                   9546: currcategories - reference to array of current categories assigned to the course
                   9547: 
                   9548: Returns: $output (markup to be displayed).
                   9549: 
                   9550: =cut
                   9551: 
                   9552: sub assign_category_rows {
                   9553:     my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
                   9554:     my ($text,$name,$item,$chgstr);
                   9555:     if (ref($cats) eq 'ARRAY') {
                   9556:         my $maxdepth = scalar(@{$cats});
                   9557:         if (ref($cats->[$depth]) eq 'HASH') {
                   9558:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   9559:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   9560:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9561:                 $text .= '<td><table class="LC_datatable">';
                   9562:                 for (my $j=0; $j<$numchildren; $j++) {
                   9563:                     $name = $cats->[$depth]{$parent}[$j];
                   9564:                     $item = &escape($name).':'.&escape($parent).':'.$depth;
                   9565:                     my $deeper = $depth+1;
                   9566:                     my $checked = '';
                   9567:                     if (ref($currcategories) eq 'ARRAY') {
                   9568:                         if (@{$currcategories} > 0) {
                   9569:                             if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772     bisitz   9570:                                 $checked = ' checked="checked"';
1.663     raeburn  9571:                             }
                   9572:                         }
                   9573:                     }
1.664     raeburn  9574:                     $text .= '<tr><td><span class="LC_nobreak"><label>'.
                   9575:                              '<input type="checkbox" name="usecategory" value="'.
1.675     raeburn  9576:                              $item.'"'.$checked.' />'.$name.'</label></span>'.
                   9577:                              '<input type="hidden" name="catname" value="'.$name.'" />'.
                   9578:                              '</td><td>';
1.663     raeburn  9579:                     if (ref($path) eq 'ARRAY') {
                   9580:                         push(@{$path},$name);
                   9581:                         $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
                   9582:                         pop(@{$path});
                   9583:                     }
                   9584:                     $text .= '</td></tr>';
                   9585:                 }
                   9586:                 $text .= '</table></td>';
                   9587:             }
                   9588:         }
                   9589:     }
                   9590:     return $text;
                   9591: }
                   9592: 
1.655     raeburn  9593: ############################################################
                   9594: ############################################################
                   9595: 
                   9596: 
1.443     albertel 9597: sub commit_customrole {
1.664     raeburn  9598:     my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630     raeburn  9599:     my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443     albertel 9600:                          ($start?', '.&mt('starting').' '.localtime($start):'').
                   9601:                          ($end?', ending '.localtime($end):'').': <b>'.
                   9602:               &Apache::lonnet::assigncustomrole(
1.664     raeburn  9603:                  $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443     albertel 9604:                  '</b><br />';
                   9605:     return $output;
                   9606: }
                   9607: 
                   9608: sub commit_standardrole {
1.541     raeburn  9609:     my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
                   9610:     my ($output,$logmsg,$linefeed);
                   9611:     if ($context eq 'auto') {
                   9612:         $linefeed = "\n";
                   9613:     } else {
                   9614:         $linefeed = "<br />\n";
                   9615:     }  
1.443     albertel 9616:     if ($three eq 'st') {
1.541     raeburn  9617:         my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
                   9618:                                          $one,$two,$sec,$context);
                   9619:         if (($result =~ /^error/) || ($result eq 'not_in_class') || 
1.626     raeburn  9620:             ($result eq 'unknown_course') || ($result eq 'refused')) {
                   9621:             $output = $logmsg.' '.&mt('Error: ').$result."\n"; 
1.443     albertel 9622:         } else {
1.541     raeburn  9623:             $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443     albertel 9624:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  9625:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
                   9626:             if ($context eq 'auto') {
                   9627:                 $output .= $result.$linefeed.&mt('Add to classlist').': ok';
                   9628:             } else {
                   9629:                $output .= '<b>'.$result.'</b>'.$linefeed.
                   9630:                &mt('Add to classlist').': <b>ok</b>';
                   9631:             }
                   9632:             $output .= $linefeed;
1.443     albertel 9633:         }
                   9634:     } else {
                   9635:         $output = &mt('Assigning').' '.$three.' in '.$url.
                   9636:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  9637:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652     raeburn  9638:         my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541     raeburn  9639:         if ($context eq 'auto') {
                   9640:             $output .= $result.$linefeed;
                   9641:         } else {
                   9642:             $output .= '<b>'.$result.'</b>'.$linefeed;
                   9643:         }
1.443     albertel 9644:     }
                   9645:     return $output;
                   9646: }
                   9647: 
                   9648: sub commit_studentrole {
1.541     raeburn  9649:     my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626     raeburn  9650:     my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541     raeburn  9651:     if ($context eq 'auto') {
                   9652:         $linefeed = "\n";
                   9653:     } else {
                   9654:         $linefeed = '<br />'."\n";
                   9655:     }
1.443     albertel 9656:     if (defined($one) && defined($two)) {
                   9657:         my $cid=$one.'_'.$two;
                   9658:         my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
                   9659:         my $secchange = 0;
                   9660:         my $expire_role_result;
                   9661:         my $modify_section_result;
1.628     raeburn  9662:         if ($oldsec ne '-1') { 
                   9663:             if ($oldsec ne $sec) {
1.443     albertel 9664:                 $secchange = 1;
1.628     raeburn  9665:                 my $now = time;
1.443     albertel 9666:                 my $uurl='/'.$cid;
                   9667:                 $uurl=~s/\_/\//g;
                   9668:                 if ($oldsec) {
                   9669:                     $uurl.='/'.$oldsec;
                   9670:                 }
1.626     raeburn  9671:                 $oldsecurl = $uurl;
1.628     raeburn  9672:                 $expire_role_result = 
1.652     raeburn  9673:                     &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628     raeburn  9674:                 if ($env{'request.course.sec'} ne '') { 
                   9675:                     if ($expire_role_result eq 'refused') {
                   9676:                         my @roles = ('st');
                   9677:                         my @statuses = ('previous');
                   9678:                         my @roledoms = ($one);
                   9679:                         my $withsec = 1;
                   9680:                         my %roleshash = 
                   9681:                             &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
                   9682:                                               \@statuses,\@roles,\@roledoms,$withsec);
                   9683:                         if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
                   9684:                             my ($oldstart,$oldend) = 
                   9685:                                 split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
                   9686:                             if ($oldend > 0 && $oldend <= $now) {
                   9687:                                 $expire_role_result = 'ok';
                   9688:                             }
                   9689:                         }
                   9690:                     }
                   9691:                 }
1.443     albertel 9692:                 $result = $expire_role_result;
                   9693:             }
                   9694:         }
                   9695:         if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652     raeburn  9696:             $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443     albertel 9697:             if ($modify_section_result =~ /^ok/) {
                   9698:                 if ($secchange == 1) {
1.628     raeburn  9699:                     if ($sec eq '') {
                   9700:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
                   9701:                     } else {
                   9702:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
                   9703:                     }
1.443     albertel 9704:                 } elsif ($oldsec eq '-1') {
1.628     raeburn  9705:                     if ($sec eq '') {
                   9706:                         $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
                   9707:                     } else {
                   9708:                         $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   9709:                     }
1.443     albertel 9710:                 } else {
1.628     raeburn  9711:                     if ($sec eq '') {
                   9712:                         $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
                   9713:                     } else {
                   9714:                         $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   9715:                     }
1.443     albertel 9716:                 }
                   9717:             } else {
1.628     raeburn  9718:                 if ($secchange) {       
                   9719:                     $$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;
                   9720:                 } else {
                   9721:                     $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
                   9722:                 }
1.443     albertel 9723:             }
                   9724:             $result = $modify_section_result;
                   9725:         } elsif ($secchange == 1) {
1.628     raeburn  9726:             if ($oldsec eq '') {
                   9727:                 $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
                   9728:             } else {
                   9729:                 $$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;
                   9730:             }
1.626     raeburn  9731:             if ($expire_role_result eq 'refused') {
                   9732:                 my $newsecurl = '/'.$cid;
                   9733:                 $newsecurl =~ s/\_/\//g;
                   9734:                 if ($sec ne '') {
                   9735:                     $newsecurl.='/'.$sec;
                   9736:                 }
                   9737:                 if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
                   9738:                     if ($sec eq '') {
                   9739:                         $$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;
                   9740:                     } else {
                   9741:                         $$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;
                   9742:                     }
                   9743:                 }
                   9744:             }
1.443     albertel 9745:         }
                   9746:     } else {
1.626     raeburn  9747:         $$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 9748:         $result = "error: incomplete course id\n";
                   9749:     }
                   9750:     return $result;
                   9751: }
                   9752: 
                   9753: ############################################################
                   9754: ############################################################
                   9755: 
1.566     albertel 9756: sub check_clone {
1.578     raeburn  9757:     my ($args,$linefeed) = @_;
1.566     albertel 9758:     my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
                   9759:     my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
                   9760:     my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
                   9761:     my $clonemsg;
                   9762:     my $can_clone = 0;
                   9763: 
                   9764:     if ($clonehome eq 'no_host') {
1.578     raeburn  9765:         $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'});     
1.566     albertel 9766:     } else {
                   9767: 	my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568     albertel 9768: 	if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566     albertel 9769: 	    $can_clone = 1;
                   9770: 	} else {
                   9771: 	    my %clonehash = &Apache::lonnet::get('environment',['cloners'],
                   9772: 						 $args->{'clonedomain'},$args->{'clonecourse'});
                   9773: 	    my @cloners = split(/,/,$clonehash{'cloners'});
1.578     raeburn  9774:             if (grep(/^\*$/,@cloners)) {
                   9775:                 $can_clone = 1;
                   9776:             } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
                   9777:                 $can_clone = 1;
                   9778:             } else {
                   9779: 	        my %roleshash =
                   9780: 		    &Apache::lonnet::get_my_roles($args->{'ccuname'},
                   9781: 					 $args->{'ccdomain'},
                   9782:                                          'userroles',['active'],['cc'],
                   9783: 					 [$args->{'clonedomain'}]);
                   9784: 	        if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
                   9785: 		    $can_clone = 1;
                   9786: 	        } else {
                   9787:                     $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'});
                   9788: 	        }
1.566     albertel 9789: 	    }
1.578     raeburn  9790:         }
1.566     albertel 9791:     }
                   9792:     return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   9793: }
                   9794: 
1.444     albertel 9795: sub construct_course {
1.541     raeburn  9796:     my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444     albertel 9797:     my $outcome;
1.541     raeburn  9798:     my $linefeed =  '<br />'."\n";
                   9799:     if ($context eq 'auto') {
                   9800:         $linefeed = "\n";
                   9801:     }
1.566     albertel 9802: 
                   9803: #
                   9804: # Are we cloning?
                   9805: #
                   9806:     my ($can_clone, $clonemsg, $cloneid, $clonehome);
                   9807:     if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578     raeburn  9808: 	($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566     albertel 9809: 	if ($context ne 'auto') {
1.578     raeburn  9810:             if ($clonemsg ne '') {
                   9811: 	        $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
                   9812:             }
1.566     albertel 9813: 	}
                   9814: 	$outcome .= $clonemsg.$linefeed;
                   9815: 
                   9816:         if (!$can_clone) {
                   9817: 	    return (0,$outcome);
                   9818: 	}
                   9819:     }
                   9820: 
1.444     albertel 9821: #
                   9822: # Open course
                   9823: #
                   9824:     my $crstype = lc($args->{'crstype'});
                   9825:     my %cenv=();
                   9826:     $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
                   9827:                                              $args->{'cdescr'},
                   9828:                                              $args->{'curl'},
                   9829:                                              $args->{'course_home'},
                   9830:                                              $args->{'nonstandard'},
                   9831:                                              $args->{'crscode'},
                   9832:                                              $args->{'ccuname'}.':'.
                   9833:                                              $args->{'ccdomain'},
                   9834:                                              $args->{'crstype'});
                   9835: 
                   9836:     # Note: The testing routines depend on this being output; see 
                   9837:     # Utils::Course. This needs to at least be output as a comment
                   9838:     # if anyone ever decides to not show this, and Utils::Course::new
                   9839:     # will need to be suitably modified.
1.541     raeburn  9840:     $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444     albertel 9841: #
                   9842: # Check if created correctly
                   9843: #
1.479     albertel 9844:     ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444     albertel 9845:     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541     raeburn  9846:     $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566     albertel 9847: 
1.444     albertel 9848: #
1.566     albertel 9849: # Do the cloning
                   9850: #   
                   9851:     if ($can_clone && $cloneid) {
                   9852: 	$clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
                   9853: 	if ($context ne 'auto') {
                   9854: 	    $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
                   9855: 	}
                   9856: 	$outcome .= $clonemsg.$linefeed;
                   9857: 	my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444     albertel 9858: # Copy all files
1.637     www      9859: 	&Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444     albertel 9860: # Restore URL
1.566     albertel 9861: 	$cenv{'url'}=$oldcenv{'url'};
1.444     albertel 9862: # Restore title
1.566     albertel 9863: 	$cenv{'description'}=$oldcenv{'description'};
1.444     albertel 9864: # Mark as cloned
1.566     albertel 9865: 	$cenv{'clonedfrom'}=$cloneid;
1.638     www      9866: # Need to clone grading mode
                   9867:         my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
                   9868:         $cenv{'grading'}=$newenv{'grading'};
                   9869: # Do not clone these environment entries
                   9870:         &Apache::lonnet::del('environment',
                   9871:                   ['default_enrollment_start_date',
                   9872:                    'default_enrollment_end_date',
                   9873:                    'question.email',
                   9874:                    'policy.email',
                   9875:                    'comment.email',
                   9876:                    'pch.users.denied',
1.725     raeburn  9877:                    'plc.users.denied',
                   9878:                    'hidefromcat',
                   9879:                    'categories'],
1.638     www      9880:                    $$crsudom,$$crsunum);
1.444     albertel 9881:     }
1.566     albertel 9882: 
1.444     albertel 9883: #
                   9884: # Set environment (will override cloned, if existing)
                   9885: #
                   9886:     my @sections = ();
                   9887:     my @xlists = ();
                   9888:     if ($args->{'crstype'}) {
                   9889:         $cenv{'type'}=$args->{'crstype'};
                   9890:     }
                   9891:     if ($args->{'crsid'}) {
                   9892:         $cenv{'courseid'}=$args->{'crsid'};
                   9893:     }
                   9894:     if ($args->{'crscode'}) {
                   9895:         $cenv{'internal.coursecode'}=$args->{'crscode'};
                   9896:     }
                   9897:     if ($args->{'crsquota'} ne '') {
                   9898:         $cenv{'internal.coursequota'}=$args->{'crsquota'};
                   9899:     } else {
                   9900:         $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
                   9901:     }
                   9902:     if ($args->{'ccuname'}) {
                   9903:         $cenv{'internal.courseowner'} = $args->{'ccuname'}.
                   9904:                                         ':'.$args->{'ccdomain'};
                   9905:     } else {
                   9906:         $cenv{'internal.courseowner'} = $args->{'curruser'};
                   9907:     }
                   9908:     my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
                   9909:     if ($args->{'crssections'}) {
                   9910:         $cenv{'internal.sectionnums'} = '';
                   9911:         if ($args->{'crssections'} =~ m/,/) {
                   9912:             @sections = split/,/,$args->{'crssections'};
                   9913:         } else {
                   9914:             $sections[0] = $args->{'crssections'};
                   9915:         }
                   9916:         if (@sections > 0) {
                   9917:             foreach my $item (@sections) {
                   9918:                 my ($sec,$gp) = split/:/,$item;
                   9919:                 my $class = $args->{'crscode'}.$sec;
                   9920:                 my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
                   9921:                 $cenv{'internal.sectionnums'} .= $item.',';
                   9922:                 unless ($addcheck eq 'ok') {
                   9923:                     push @badclasses, $class;
                   9924:                 }
                   9925:             }
                   9926:             $cenv{'internal.sectionnums'} =~ s/,$//;
                   9927:         }
                   9928:     }
                   9929: # do not hide course coordinator from staff listing, 
                   9930: # even if privileged
                   9931:     $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   9932: # add crosslistings
                   9933:     if ($args->{'crsxlist'}) {
                   9934:         $cenv{'internal.crosslistings'}='';
                   9935:         if ($args->{'crsxlist'} =~ m/,/) {
                   9936:             @xlists = split/,/,$args->{'crsxlist'};
                   9937:         } else {
                   9938:             $xlists[0] = $args->{'crsxlist'};
                   9939:         }
                   9940:         if (@xlists > 0) {
                   9941:             foreach my $item (@xlists) {
                   9942:                 my ($xl,$gp) = split/:/,$item;
                   9943:                 my $addcheck =  &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
                   9944:                 $cenv{'internal.crosslistings'} .= $item.',';
                   9945:                 unless ($addcheck eq 'ok') {
                   9946:                     push @badclasses, $xl;
                   9947:                 }
                   9948:             }
                   9949:             $cenv{'internal.crosslistings'} =~ s/,$//;
                   9950:         }
                   9951:     }
                   9952:     if ($args->{'autoadds'}) {
                   9953:         $cenv{'internal.autoadds'}=$args->{'autoadds'};
                   9954:     }
                   9955:     if ($args->{'autodrops'}) {
                   9956:         $cenv{'internal.autodrops'}=$args->{'autodrops'};
                   9957:     }
                   9958: # check for notification of enrollment changes
                   9959:     my @notified = ();
                   9960:     if ($args->{'notify_owner'}) {
                   9961:         if ($args->{'ccuname'} ne '') {
                   9962:             push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
                   9963:         }
                   9964:     }
                   9965:     if ($args->{'notify_dc'}) {
                   9966:         if ($uname ne '') { 
1.630     raeburn  9967:             push(@notified,$uname.':'.$udom);
1.444     albertel 9968:         }
                   9969:     }
                   9970:     if (@notified > 0) {
                   9971:         my $notifylist;
                   9972:         if (@notified > 1) {
                   9973:             $notifylist = join(',',@notified);
                   9974:         } else {
                   9975:             $notifylist = $notified[0];
                   9976:         }
                   9977:         $cenv{'internal.notifylist'} = $notifylist;
                   9978:     }
                   9979:     if (@badclasses > 0) {
                   9980:         my %lt=&Apache::lonlocal::texthash(
                   9981:                 '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',
                   9982:                 'dnhr' => 'does not have rights to access enrollment in these classes',
                   9983:                 'adby' => 'as determined by the policies of your institution on access to official classlists'
                   9984:         );
1.541     raeburn  9985:         my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
                   9986:                            ' ('.$lt{'adby'}.')';
                   9987:         if ($context eq 'auto') {
                   9988:             $outcome .= $badclass_msg.$linefeed;
1.566     albertel 9989:             $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541     raeburn  9990:             foreach my $item (@badclasses) {
                   9991:                 if ($context eq 'auto') {
                   9992:                     $outcome .= " - $item\n";
                   9993:                 } else {
                   9994:                     $outcome .= "<li>$item</li>\n";
                   9995:                 }
                   9996:             }
                   9997:             if ($context eq 'auto') {
                   9998:                 $outcome .= $linefeed;
                   9999:             } else {
1.566     albertel 10000:                 $outcome .= "</ul><br /><br /></div>\n";
1.541     raeburn  10001:             }
                   10002:         } 
1.444     albertel 10003:     }
                   10004:     if ($args->{'no_end_date'}) {
                   10005:         $args->{'endaccess'} = 0;
                   10006:     }
                   10007:     $cenv{'internal.autostart'}=$args->{'enrollstart'};
                   10008:     $cenv{'internal.autoend'}=$args->{'enrollend'};
                   10009:     $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
                   10010:     $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
                   10011:     if ($args->{'showphotos'}) {
                   10012:       $cenv{'internal.showphotos'}=$args->{'showphotos'};
                   10013:     }
                   10014:     $cenv{'internal.authtype'} = $args->{'authtype'};
                   10015:     $cenv{'internal.autharg'} = $args->{'autharg'}; 
                   10016:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
                   10017:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
1.541     raeburn  10018:             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'); 
                   10019:             if ($context eq 'auto') {
                   10020:                 $outcome .= $krb_msg;
                   10021:             } else {
1.566     albertel 10022:                 $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541     raeburn  10023:             }
                   10024:             $outcome .= $linefeed;
1.444     albertel 10025:         }
                   10026:     }
                   10027:     if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
                   10028:        if ($args->{'setpolicy'}) {
                   10029:            $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   10030:        }
                   10031:        if ($args->{'setcontent'}) {
                   10032:            $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   10033:        }
                   10034:     }
                   10035:     if ($args->{'reshome'}) {
                   10036: 	$cenv{'reshome'}=$args->{'reshome'}.'/';
                   10037: 	$cenv{'reshome'}=~s/\/+$/\//;
                   10038:     }
                   10039: #
                   10040: # course has keyed access
                   10041: #
                   10042:     if ($args->{'setkeys'}) {
                   10043:        $cenv{'keyaccess'}='yes';
                   10044:     }
                   10045: # if specified, key authority is not course, but user
                   10046: # only active if keyaccess is yes
                   10047:     if ($args->{'keyauth'}) {
1.487     albertel 10048: 	my ($user,$domain) = split(':',$args->{'keyauth'});
                   10049: 	$user = &LONCAPA::clean_username($user);
                   10050: 	$domain = &LONCAPA::clean_username($domain);
1.488     foxr     10051: 	if ($user ne '' && $domain ne '') {
1.487     albertel 10052: 	    $cenv{'keyauth'}=$user.':'.$domain;
1.444     albertel 10053: 	}
                   10054:     }
                   10055: 
                   10056:     if ($args->{'disresdis'}) {
                   10057:         $cenv{'pch.roles.denied'}='st';
                   10058:     }
                   10059:     if ($args->{'disablechat'}) {
                   10060:         $cenv{'plc.roles.denied'}='st';
                   10061:     }
                   10062: 
                   10063:     # Record we've not yet viewed the Course Initialization Helper for this 
                   10064:     # course
                   10065:     $cenv{'course.helper.not.run'} = 1;
                   10066:     #
                   10067:     # Use new Randomseed
                   10068:     #
                   10069:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
                   10070:     $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
                   10071:     #
                   10072:     # The encryption code and receipt prefix for this course
                   10073:     #
                   10074:     $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
                   10075:     $cenv{'internal.encpref'}=100+int(9*rand(99));
                   10076:     #
                   10077:     # By default, use standard grading
                   10078:     if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
                   10079: 
1.541     raeburn  10080:     $outcome .= $linefeed.&mt('Setting environment').': '.                 
                   10081:           &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 10082: #
                   10083: # Open all assignments
                   10084: #
                   10085:     if ($args->{'openall'}) {
                   10086:        my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
                   10087:        my %storecontent = ($storeunder         => time,
                   10088:                            $storeunder.'.type' => 'date_start');
                   10089:        
                   10090:        $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541     raeburn  10091:                  ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 10092:    }
                   10093: #
                   10094: # Set first page
                   10095: #
                   10096:     unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
                   10097: 	    || ($cloneid)) {
1.445     albertel 10098: 	use LONCAPA::map;
1.444     albertel 10099: 	$outcome .= &mt('Setting first resource').': ';
1.445     albertel 10100: 
                   10101: 	my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
                   10102:         my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
                   10103: 
1.444     albertel 10104:         $outcome .= ($fatal?$errtext:'read ok').' - ';
                   10105:         my $title; my $url;
                   10106:         if ($args->{'firstres'} eq 'syl') {
1.690     bisitz   10107: 	    $title=&mt('Syllabus');
1.444     albertel 10108:             $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
                   10109:         } else {
1.690     bisitz   10110:             $title=&mt('Navigate Contents');
1.444     albertel 10111:             $url='/adm/navmaps';
                   10112:         }
1.445     albertel 10113: 
                   10114:         $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
                   10115: 	(my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
                   10116: 
                   10117: 	if ($errtext) { $fatal=2; }
1.541     raeburn  10118:         $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444     albertel 10119:     }
1.566     albertel 10120: 
                   10121:     return (1,$outcome);
1.444     albertel 10122: }
                   10123: 
                   10124: ############################################################
                   10125: ############################################################
                   10126: 
1.378     raeburn  10127: sub course_type {
                   10128:     my ($cid) = @_;
                   10129:     if (!defined($cid)) {
                   10130:         $cid = $env{'request.course.id'};
                   10131:     }
1.404     albertel 10132:     if (defined($env{'course.'.$cid.'.type'})) {
                   10133:         return $env{'course.'.$cid.'.type'};
1.378     raeburn  10134:     } else {
                   10135:         return 'Course';
1.377     raeburn  10136:     }
                   10137: }
1.156     albertel 10138: 
1.406     raeburn  10139: sub group_term {
                   10140:     my $crstype = &course_type();
                   10141:     my %names = (
                   10142:                   'Course' => 'group',
                   10143:                   'Group' => 'team',
                   10144:                 );
                   10145:     return $names{$crstype};
                   10146: }
                   10147: 
1.156     albertel 10148: sub icon {
                   10149:     my ($file)=@_;
1.505     albertel 10150:     my $curfext = lc((split(/\./,$file))[-1]);
1.168     albertel 10151:     my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156     albertel 10152:     my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168     albertel 10153:     if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
                   10154: 	if (-e  $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
                   10155: 	          $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   10156: 	            $curfext.".gif") {
                   10157: 	    $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   10158: 		$curfext.".gif";
                   10159: 	}
                   10160:     }
1.249     albertel 10161:     return &lonhttpdurl($iconname);
1.154     albertel 10162: } 
1.84      albertel 10163: 
1.575     albertel 10164: sub lonhttpdurl {
1.692     www      10165: #
                   10166: # Had been used for "small fry" static images on separate port 8080.
                   10167: # Modify here if lightweight http functionality desired again.
                   10168: # Currently eliminated due to increasing firewall issues.
                   10169: #
1.575     albertel 10170:     my ($url)=@_;
1.692     www      10171:     return $url;
1.215     albertel 10172: }
                   10173: 
1.213     albertel 10174: sub connection_aborted {
                   10175:     my ($r)=@_;
                   10176:     $r->print(" ");$r->rflush();
                   10177:     my $c = $r->connection;
                   10178:     return $c->aborted();
                   10179: }
                   10180: 
1.221     foxr     10181: #    Escapes strings that may have embedded 's that will be put into
1.222     foxr     10182: #    strings as 'strings'.
                   10183: sub escape_single {
1.221     foxr     10184:     my ($input) = @_;
1.223     albertel 10185:     $input =~ s/\\/\\\\/g;	# Escape the \'s..(must be first)>
1.221     foxr     10186:     $input =~ s/\'/\\\'/g;	# Esacpe the 's....
                   10187:     return $input;
                   10188: }
1.223     albertel 10189: 
1.222     foxr     10190: #  Same as escape_single, but escape's "'s  This 
                   10191: #  can be used for  "strings"
                   10192: sub escape_double {
                   10193:     my ($input) = @_;
                   10194:     $input =~ s/\\/\\\\/g;	# Escape the /'s..(must be first)>
                   10195:     $input =~ s/\"/\\\"/g;	# Esacpe the "s....
                   10196:     return $input;
                   10197: }
1.223     albertel 10198:  
1.222     foxr     10199: #   Escapes the last element of a full URL.
                   10200: sub escape_url {
                   10201:     my ($url)   = @_;
1.238     raeburn  10202:     my @urlslices = split(/\//, $url,-1);
1.369     www      10203:     my $lastitem = &escape(pop(@urlslices));
1.223     albertel 10204:     return join('/',@urlslices).'/'.$lastitem;
1.222     foxr     10205: }
1.462     albertel 10206: 
                   10207: # -------------------------------------------------------- Initliaze user login
                   10208: sub init_user_environment {
1.463     albertel 10209:     my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462     albertel 10210:     my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
                   10211: 
                   10212:     my $public=($username eq 'public' && $domain eq 'public');
                   10213: 
                   10214: # See if old ID present, if so, remove
                   10215: 
                   10216:     my ($filename,$cookie,$userroles);
                   10217:     my $now=time;
                   10218: 
                   10219:     if ($public) {
                   10220: 	my $max_public=100;
                   10221: 	my $oldest;
                   10222: 	my $oldest_time=0;
                   10223: 	for(my $next=1;$next<=$max_public;$next++) {
                   10224: 	    if (-e $lonids."/publicuser_$next.id") {
                   10225: 		my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
                   10226: 		if ($mtime<$oldest_time || !$oldest_time) {
                   10227: 		    $oldest_time=$mtime;
                   10228: 		    $oldest=$next;
                   10229: 		}
                   10230: 	    } else {
                   10231: 		$cookie="publicuser_$next";
                   10232: 		last;
                   10233: 	    }
                   10234: 	}
                   10235: 	if (!$cookie) { $cookie="publicuser_$oldest"; }
                   10236:     } else {
1.463     albertel 10237: 	# if this isn't a robot, kill any existing non-robot sessions
                   10238: 	if (!$args->{'robot'}) {
                   10239: 	    opendir(DIR,$lonids);
                   10240: 	    while ($filename=readdir(DIR)) {
                   10241: 		if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
                   10242: 		    unlink($lonids.'/'.$filename);
                   10243: 		}
1.462     albertel 10244: 	    }
1.463     albertel 10245: 	    closedir(DIR);
1.462     albertel 10246: 	}
                   10247: # Give them a new cookie
1.463     albertel 10248: 	my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684     www      10249: 		                   : $now.$$.int(rand(10000)));
1.463     albertel 10250: 	$cookie="$username\_$id\_$domain\_$authhost";
1.462     albertel 10251:     
                   10252: # Initialize roles
                   10253: 
                   10254: 	$userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
                   10255:     }
                   10256: # ------------------------------------ Check browser type and MathML capability
                   10257: 
                   10258:     my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   10259:         $clientunicode,$clientos) = &decode_user_agent($r);
                   10260: 
                   10261: # -------------------------------------- Any accessibility options to remember?
                   10262:     if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
                   10263: 	foreach my $option ('imagesuppress','appletsuppress',
                   10264: 			    'embedsuppress','fontenhance','blackwhite') {
                   10265: 	    if ($form->{$option} eq 'true') {
                   10266: 		&Apache::lonnet::put('environment',{$option => 'on'},
                   10267: 				     $domain,$username);
                   10268: 	    } else {
                   10269: 		&Apache::lonnet::del('environment',[$option],
                   10270: 				     $domain,$username);
                   10271: 	    }
                   10272: 	}
                   10273:     }
                   10274: # ------------------------------------------------------------- Get environment
                   10275: 
                   10276:     my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
                   10277:     my ($tmp) = keys(%userenv);
                   10278:     if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   10279: 	# default remote control to off
                   10280: 	if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
                   10281:     } else {
                   10282: 	undef(%userenv);
                   10283:     }
                   10284:     if (($userenv{'interface'}) && (!$form->{'interface'})) {
                   10285: 	$form->{'interface'}=$userenv{'interface'};
                   10286:     }
                   10287:     $env{'environment.remote'}=$userenv{'remote'};
                   10288:     if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
                   10289: 
                   10290: # --------------- Do not trust query string to be put directly into environment
                   10291:     foreach my $option ('imagesuppress','appletsuppress',
                   10292: 			'embedsuppress','fontenhance','blackwhite',
                   10293: 			'interface','localpath','localres') {
                   10294: 	$form->{$option}=~s/[\n\r\=]//gs;
                   10295:     }
                   10296: # --------------------------------------------------------- Write first profile
                   10297: 
                   10298:     {
                   10299: 	my %initial_env = 
                   10300: 	    ("user.name"          => $username,
                   10301: 	     "user.domain"        => $domain,
                   10302: 	     "user.home"          => $authhost,
                   10303: 	     "browser.type"       => $clientbrowser,
                   10304: 	     "browser.version"    => $clientversion,
                   10305: 	     "browser.mathml"     => $clientmathml,
                   10306: 	     "browser.unicode"    => $clientunicode,
                   10307: 	     "browser.os"         => $clientos,
                   10308: 	     "server.domain"      => $Apache::lonnet::perlvar{'lonDefDomain'},
                   10309: 	     "request.course.fn"  => '',
                   10310: 	     "request.course.uri" => '',
                   10311: 	     "request.course.sec" => '',
                   10312: 	     "request.role"       => 'cm',
                   10313: 	     "request.role.adv"   => $env{'user.adv'},
                   10314: 	     "request.host"       => $ENV{'REMOTE_ADDR'},);
                   10315: 
                   10316:         if ($form->{'localpath'}) {
                   10317: 	    $initial_env{"browser.localpath"}  = $form->{'localpath'};
                   10318: 	    $initial_env{"browser.localres"}   = $form->{'localres'};
                   10319:         }
                   10320: 	
                   10321: 	if ($public) {
                   10322: 	    $initial_env{"environment.remote"} = "off";
                   10323: 	}
                   10324: 	if ($form->{'interface'}) {
                   10325: 	    $form->{'interface'}=~s/\W//gs;
                   10326: 	    $initial_env{"browser.interface"} = $form->{'interface'};
                   10327: 	    $env{'browser.interface'}=$form->{'interface'};
                   10328: 	    foreach my $option ('imagesuppress','appletsuppress',
                   10329: 				'embedsuppress','fontenhance','blackwhite') {
                   10330: 		if (($form->{$option} eq 'true') ||
                   10331: 		    ($userenv{$option} eq 'on')) {
                   10332: 		    $initial_env{"browser.$option"} = "on";
                   10333: 		}
                   10334: 	    }
                   10335: 	}
                   10336: 
1.724     raeburn  10337:         foreach my $tool ('aboutme','blog','portfolio') {
                   10338:             $userenv{'availabletools.'.$tool} = 
                   10339:                 &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
                   10340:         }
                   10341: 
1.765     raeburn  10342:         foreach my $crstype ('official','unofficial') {
                   10343:             $userenv{'canrequest.'.$crstype} =
                   10344:                 &Apache::lonnet::usertools_access($username,$domain,$crstype,
                   10345:                                                   'reload','requestcourses');
                   10346:         }
                   10347: 
1.462     albertel 10348: 	$env{'user.environment'} = "$lonids/$cookie.id";
                   10349: 	
                   10350: 	if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
                   10351: 		 &GDBM_WRCREAT(),0640)) {
                   10352: 	    &_add_to_env(\%disk_env,\%initial_env);
                   10353: 	    &_add_to_env(\%disk_env,\%userenv,'environment.');
                   10354: 	    &_add_to_env(\%disk_env,$userroles);
1.463     albertel 10355: 	    if (ref($args->{'extra_env'})) {
                   10356: 		&_add_to_env(\%disk_env,$args->{'extra_env'});
                   10357: 	    }
1.462     albertel 10358: 	    untie(%disk_env);
                   10359: 	} else {
1.705     tempelho 10360: 	    &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
                   10361: 			   'Could not create environment storage in lonauth: '.$!.'</span>');
1.462     albertel 10362: 	    return 'error: '.$!;
                   10363: 	}
                   10364:     }
                   10365:     $env{'request.role'}='cm';
                   10366:     $env{'request.role.adv'}=$env{'user.adv'};
                   10367:     $env{'browser.type'}=$clientbrowser;
                   10368: 
                   10369:     return $cookie;
                   10370: 
                   10371: }
                   10372: 
                   10373: sub _add_to_env {
                   10374:     my ($idf,$env_data,$prefix) = @_;
1.676     raeburn  10375:     if (ref($env_data) eq 'HASH') {
                   10376:         while (my ($key,$value) = each(%$env_data)) {
                   10377: 	    $idf->{$prefix.$key} = $value;
                   10378: 	    $env{$prefix.$key}   = $value;
                   10379:         }
1.462     albertel 10380:     }
                   10381: }
                   10382: 
1.685     tempelho 10383: # --- Get the symbolic name of a problem and the url
                   10384: sub get_symb {
                   10385:     my ($request,$silent) = @_;
1.726     raeburn  10386:     (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685     tempelho 10387:     my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
                   10388:     if ($symb eq '') {
                   10389:         if (!$silent) {
                   10390:             $request->print("Unable to handle ambiguous references:$url:.");
                   10391:             return ();
                   10392:         }
                   10393:     }
                   10394:     &Apache::lonenc::check_decrypt(\$symb);
                   10395:     return ($symb);
                   10396: }
                   10397: 
                   10398: # --------------------------------------------------------------Get annotation
                   10399: 
                   10400: sub get_annotation {
                   10401:     my ($symb,$enc) = @_;
                   10402: 
                   10403:     my $key = $symb;
                   10404:     if (!$enc) {
                   10405:         $key =
                   10406:             &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
                   10407:     }
                   10408:     my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
                   10409:     return $annotation{$key};
                   10410: }
                   10411: 
                   10412: sub clean_symb {
1.731     raeburn  10413:     my ($symb,$delete_enc) = @_;
1.685     tempelho 10414: 
                   10415:     &Apache::lonenc::check_decrypt(\$symb);
                   10416:     my $enc = $env{'request.enc'};
1.731     raeburn  10417:     if ($delete_enc) {
1.730     raeburn  10418:         delete($env{'request.enc'});
                   10419:     }
1.685     tempelho 10420: 
                   10421:     return ($symb,$enc);
                   10422: }
1.462     albertel 10423: 
1.41      ng       10424: =pod
                   10425: 
                   10426: =back
                   10427: 
1.112     bowersj2 10428: =cut
1.41      ng       10429: 
1.112     bowersj2 10430: 1;
                   10431: __END__;
1.41      ng       10432: 

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