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

1.10      albertel    1: # The LearningOnline Network with CAPA
1.1       albertel    2: # a pile of common routines
1.10      albertel    3: #
1.799   ! bisitz      4: # $Id: loncommon.pm,v 1.798 2009/04/28 21:54:57 tempelho 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;
                    520:                 }
                    521:             }     
1.230     raeburn   522:         }
1.293     raeburn   523:         if (multflag !=null && multflag != '') {
                    524:             url += '&multiple='+multflag;
                    525:         }
1.377     raeburn   526:         if (crstype == 'Course/Group') {
                    527:             if (formname == 'cu') {
                    528:                 crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value; 
                    529:                 if (crstype == "") {
                    530:                     alert("$crs_or_grp_alert");
                    531:                     return;
                    532:                 }
                    533:             }
                    534:         }
                    535:         if (crstype !=null && crstype != '') {
                    536:             url += '&type='+crstype;
                    537:         }
1.102     www       538:         var title = 'Course_Browser';
1.91      www       539:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    540:         options += ',width=700,height=600';
                    541:         stdeditbrowser = open(url,title,options,'1');
                    542:         stdeditbrowser.focus();
                    543:     }
1.468     raeburn   544: 
                    545:     function getFormIdByName(formname) {
                    546:         for (var i=0;i<document.forms.length;i++) {
                    547:             if (document.forms[i].name == formname) {
                    548:                 return i;
                    549:             }
                    550:         }
                    551:         return -1; 
                    552:     }
                    553: 
                    554:     function getIndexByName(formid,item) {
                    555:         for (var i=0;i<document.forms[formid].elements.length;i++) {
                    556:             if (document.forms[formid].elements[i].name == item) {
                    557:                 return i;
                    558:             }
                    559:         }
                    560:         return -1;
                    561:     }
1.91      www       562: ENDSTDBRW
1.468     raeburn   563:     if ($sec_element ne '') {
                    564:         $output .= &setsec_javascript($sec_element,$formname);
                    565:     }
                    566:     $output .= '
                    567: </script>';
                    568:     return $output;
                    569: }
                    570: 
                    571: sub setsec_javascript {
                    572:     my ($sec_element,$formname) = @_;
                    573:     my $setsections = qq|
                    574: function setSect(sectionlist) {
1.629     raeburn   575:     var sectionsArray = new Array();
                    576:     if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
                    577:         sectionsArray = sectionlist.split(",");
                    578:     }
1.468     raeburn   579:     var numSections = sectionsArray.length;
                    580:     document.$formname.$sec_element.length = 0;
                    581:     if (numSections == 0) {
                    582:         document.$formname.$sec_element.multiple=false;
                    583:         document.$formname.$sec_element.size=1;
                    584:         document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
                    585:     } else {
                    586:         if (numSections == 1) {
                    587:             document.$formname.$sec_element.multiple=false;
                    588:             document.$formname.$sec_element.size=1;
                    589:             document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
                    590:             document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
                    591:             document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
                    592:         } else {
                    593:             for (var i=0; i<numSections; i++) {
                    594:                 document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
                    595:             }
                    596:             document.$formname.$sec_element.multiple=true
                    597:             if (numSections < 3) {
                    598:                 document.$formname.$sec_element.size=numSections;
                    599:             } else {
                    600:                 document.$formname.$sec_element.size=3;
                    601:             }
                    602:             document.$formname.$sec_element.options[0].selected = false
                    603:         }
                    604:     }
1.91      www       605: }
1.468     raeburn   606: |;
                    607:     return $setsections;
                    608: }
                    609: 
1.91      www       610: 
                    611: sub selectcourse_link {
1.377     raeburn   612:    my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.787     bisitz    613:    return '<span class="LC_nobreak">'
                    614:          ."<a href='"
                    615:          .'javascript:opencrsbrowser("'.$form.'","'.$unameele
                    616:          .'","'.$udomele.'","'.$desc.'","'.$extra_element
                    617:          .'","'.$multflag.'","'.$selecttype.'");'
                    618:          ."'>".&mt('Select Course').'</a>'
                    619:          .'</span>';
1.74      www       620: }
1.42      matthew   621: 
1.653     raeburn   622: sub selectauthor_link {
                    623:    my ($form,$udom)=@_;
                    624:    return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
                    625:           &mt('Select Author').'</a>';
                    626: }
                    627: 
1.273     raeburn   628: sub check_uncheck_jscript {
                    629:     my $jscript = <<"ENDSCRT";
                    630: function checkAll(field) {
                    631:     if (field.length > 0) {
                    632:         for (i = 0; i < field.length; i++) {
                    633:             field[i].checked = true ;
                    634:         }
                    635:     } else {
                    636:         field.checked = true
                    637:     }
                    638: }
                    639:  
                    640: function uncheckAll(field) {
                    641:     if (field.length > 0) {
                    642:         for (i = 0; i < field.length; i++) {
                    643:             field[i].checked = false ;
1.543     albertel  644:         }
                    645:     } else {
1.273     raeburn   646:         field.checked = false ;
                    647:     }
                    648: }
                    649: ENDSCRT
                    650:     return $jscript;
                    651: }
                    652: 
1.656     www       653: sub select_timezone {
1.659     raeburn   654:    my ($name,$selected,$onchange,$includeempty)=@_;
                    655:    my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    656:    if ($includeempty) {
                    657:        $output .= '<option value=""';
                    658:        if (($selected eq '') || ($selected eq 'local')) {
                    659:            $output .= ' selected="selected" ';
                    660:        }
                    661:        $output .= '> </option>';
                    662:    }
1.657     raeburn   663:    my @timezones = DateTime::TimeZone->all_names;
                    664:    foreach my $tzone (@timezones) {
                    665:        $output.= '<option value="'.$tzone.'"';
                    666:        if ($tzone eq $selected) {
                    667:            $output.=' selected="selected"';
                    668:        }
                    669:        $output.=">$tzone</option>\n";
1.656     www       670:    }
                    671:    $output.="</select>";
                    672:    return $output;
                    673: }
1.273     raeburn   674: 
1.687     raeburn   675: sub select_datelocale {
                    676:     my ($name,$selected,$onchange,$includeempty)=@_;
                    677:     my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    678:     if ($includeempty) {
                    679:         $output .= '<option value=""';
                    680:         if ($selected eq '') {
                    681:             $output .= ' selected="selected" ';
                    682:         }
                    683:         $output .= '> </option>';
                    684:     }
                    685:     my (@possibles,%locale_names);
                    686:     my @locales = DateTime::Locale::Catalog::Locales;
                    687:     foreach my $locale (@locales) {
                    688:         if (ref($locale) eq 'HASH') {
                    689:             my $id = $locale->{'id'};
                    690:             if ($id ne '') {
                    691:                 my $en_terr = $locale->{'en_territory'};
                    692:                 my $native_terr = $locale->{'native_territory'};
1.695     raeburn   693:                 my @languages = &Apache::lonlocal::preferred_languages();
1.687     raeburn   694:                 if (grep(/^en$/,@languages) || !@languages) {
                    695:                     if ($en_terr ne '') {
                    696:                         $locale_names{$id} = '('.$en_terr.')';
                    697:                     } elsif ($native_terr ne '') {
                    698:                         $locale_names{$id} = $native_terr;
                    699:                     }
                    700:                 } else {
                    701:                     if ($native_terr ne '') {
                    702:                         $locale_names{$id} = $native_terr.' ';
                    703:                     } elsif ($en_terr ne '') {
                    704:                         $locale_names{$id} = '('.$en_terr.')';
                    705:                     }
                    706:                 }
                    707:                 push (@possibles,$id);
                    708:             }
                    709:         }
                    710:     }
                    711:     foreach my $item (sort(@possibles)) {
                    712:         $output.= '<option value="'.$item.'"';
                    713:         if ($item eq $selected) {
                    714:             $output.=' selected="selected"';
                    715:         }
                    716:         $output.=">$item";
                    717:         if ($locale_names{$item} ne '') {
                    718:             $output.="  $locale_names{$item}</option>\n";
                    719:         }
                    720:         $output.="</option>\n";
                    721:     }
                    722:     $output.="</select>";
                    723:     return $output;
                    724: }
                    725: 
1.792     raeburn   726: sub select_language {
                    727:     my ($name,$selected,$includeempty) = @_;
                    728:     my %langchoices;
                    729:     if ($includeempty) {
                    730:         %langchoices = ('' => 'No language preference');
                    731:     }
                    732:     foreach my $id (&languageids()) {
                    733:         my $code = &supportedlanguagecode($id);
                    734:         if ($code) {
                    735:             $langchoices{$code} = &plainlanguagedescription($id);
                    736:         }
                    737:     }
                    738:     return &select_form($selected,$name,%langchoices);
                    739: }
                    740: 
1.42      matthew   741: =pod
1.36      matthew   742: 
1.648     raeburn   743: =item * &linked_select_forms(...)
1.36      matthew   744: 
                    745: linked_select_forms returns a string containing a <script></script> block
                    746: and html for two <select> menus.  The select menus will be linked in that
                    747: changing the value of the first menu will result in new values being placed
                    748: in the second menu.  The values in the select menu will appear in alphabetical
1.609     raeburn   749: order unless a defined order is provided.
1.36      matthew   750: 
                    751: linked_select_forms takes the following ordered inputs:
                    752: 
                    753: =over 4
                    754: 
1.112     bowersj2  755: =item * $formname, the name of the <form> tag
1.36      matthew   756: 
1.112     bowersj2  757: =item * $middletext, the text which appears between the <select> tags
1.36      matthew   758: 
1.112     bowersj2  759: =item * $firstdefault, the default value for the first menu
1.36      matthew   760: 
1.112     bowersj2  761: =item * $firstselectname, the name of the first <select> tag
1.36      matthew   762: 
1.112     bowersj2  763: =item * $secondselectname, the name of the second <select> tag
1.36      matthew   764: 
1.112     bowersj2  765: =item * $hashref, a reference to a hash containing the data for the menus.
1.36      matthew   766: 
1.609     raeburn   767: =item * $menuorder, the order of values in the first menu
                    768: 
1.41      ng        769: =back 
                    770: 
1.36      matthew   771: Below is an example of such a hash.  Only the 'text', 'default', and 
                    772: 'select2' keys must appear as stated.  keys(%menu) are the possible 
                    773: values for the first select menu.  The text that coincides with the 
1.41      ng        774: first menu value is given in $menu{$choice1}->{'text'}.  The values 
1.36      matthew   775: and text for the second menu are given in the hash pointed to by 
                    776: $menu{$choice1}->{'select2'}.  
                    777: 
1.112     bowersj2  778:  my %menu = ( A1 => { text =>"Choice A1" ,
                    779:                        default => "B3",
                    780:                        select2 => { 
                    781:                            B1 => "Choice B1",
                    782:                            B2 => "Choice B2",
                    783:                            B3 => "Choice B3",
                    784:                            B4 => "Choice B4"
1.609     raeburn   785:                            },
                    786:                        order => ['B4','B3','B1','B2'],
1.112     bowersj2  787:                    },
                    788:                A2 => { text =>"Choice A2" ,
                    789:                        default => "C2",
                    790:                        select2 => { 
                    791:                            C1 => "Choice C1",
                    792:                            C2 => "Choice C2",
                    793:                            C3 => "Choice C3"
1.609     raeburn   794:                            },
                    795:                        order => ['C2','C1','C3'],
1.112     bowersj2  796:                    },
                    797:                A3 => { text =>"Choice A3" ,
                    798:                        default => "D6",
                    799:                        select2 => { 
                    800:                            D1 => "Choice D1",
                    801:                            D2 => "Choice D2",
                    802:                            D3 => "Choice D3",
                    803:                            D4 => "Choice D4",
                    804:                            D5 => "Choice D5",
                    805:                            D6 => "Choice D6",
                    806:                            D7 => "Choice D7"
1.609     raeburn   807:                            },
                    808:                        order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112     bowersj2  809:                    }
                    810:                );
1.36      matthew   811: 
                    812: =cut
                    813: 
                    814: sub linked_select_forms {
                    815:     my ($formname,
                    816:         $middletext,
                    817:         $firstdefault,
                    818:         $firstselectname,
                    819:         $secondselectname, 
1.609     raeburn   820:         $hashref,
                    821:         $menuorder,
1.36      matthew   822:         ) = @_;
                    823:     my $second = "document.$formname.$secondselectname";
                    824:     my $first = "document.$formname.$firstselectname";
                    825:     # output the javascript to do the changing
                    826:     my $result = '';
1.776     bisitz    827:     $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.36      matthew   828:     $result.="var select2data = new Object();\n";
                    829:     $" = '","';
                    830:     my $debug = '';
                    831:     foreach my $s1 (sort(keys(%$hashref))) {
                    832:         $result.="select2data.d_$s1 = new Object();\n";        
                    833:         $result.="select2data.d_$s1.def = new String('".
                    834:             $hashref->{$s1}->{'default'}."');\n";
1.609     raeburn   835:         $result.="select2data.d_$s1.values = new Array(";
1.36      matthew   836:         my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609     raeburn   837:         if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
                    838:             @s2values = @{$hashref->{$s1}->{'order'}};
                    839:         }
1.36      matthew   840:         $result.="\"@s2values\");\n";
                    841:         $result.="select2data.d_$s1.texts = new Array(";        
                    842:         my @s2texts;
                    843:         foreach my $value (@s2values) {
                    844:             push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
                    845:         }
                    846:         $result.="\"@s2texts\");\n";
                    847:     }
                    848:     $"=' ';
                    849:     $result.= <<"END";
                    850: 
                    851: function select1_changed() {
                    852:     // Determine new choice
                    853:     var newvalue = "d_" + $first.value;
                    854:     // update select2
                    855:     var values     = select2data[newvalue].values;
                    856:     var texts      = select2data[newvalue].texts;
                    857:     var select2def = select2data[newvalue].def;
                    858:     var i;
                    859:     // out with the old
                    860:     for (i = 0; i < $second.options.length; i++) {
                    861:         $second.options[i] = null;
                    862:     }
                    863:     // in with the nuclear
                    864:     for (i=0;i<values.length; i++) {
                    865:         $second.options[i] = new Option(values[i]);
1.143     matthew   866:         $second.options[i].value = values[i];
1.36      matthew   867:         $second.options[i].text = texts[i];
                    868:         if (values[i] == select2def) {
                    869:             $second.options[i].selected = true;
                    870:         }
                    871:     }
                    872: }
                    873: </script>
                    874: END
                    875:     # output the initial values for the selection lists
                    876:     $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609     raeburn   877:     my @order = sort(keys(%{$hashref}));
                    878:     if (ref($menuorder) eq 'ARRAY') {
                    879:         @order = @{$menuorder};
                    880:     }
                    881:     foreach my $value (@order) {
1.36      matthew   882:         $result.="    <option value=\"$value\" ";
1.253     albertel  883:         $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119     www       884:         $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36      matthew   885:     }
                    886:     $result .= "</select>\n";
                    887:     my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
                    888:     $result .= $middletext;
                    889:     $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
                    890:     my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609     raeburn   891:     
                    892:     my @secondorder = sort(keys(%select2));
                    893:     if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
                    894:         @secondorder = @{$hashref->{$firstdefault}->{'order'}};
                    895:     }
                    896:     foreach my $value (@secondorder) {
1.36      matthew   897:         $result.="    <option value=\"$value\" ";        
1.253     albertel  898:         $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119     www       899:         $result.=">".&mt($select2{$value})."</option>\n";
1.36      matthew   900:     }
                    901:     $result .= "</select>\n";
                    902:     #    return $debug;
                    903:     return $result;
                    904: }   #  end of sub linked_select_forms {
                    905: 
1.45      matthew   906: =pod
1.44      bowersj2  907: 
1.648     raeburn   908: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44      bowersj2  909: 
1.112     bowersj2  910: Returns a string corresponding to an HTML link to the given help
                    911: $topic, where $topic corresponds to the name of a .tex file in
                    912: /home/httpd/html/adm/help/tex, with underscores replaced by
                    913: spaces. 
                    914: 
                    915: $text will optionally be linked to the same topic, allowing you to
                    916: link text in addition to the graphic. If you do not want to link
                    917: text, but wish to specify one of the later parameters, pass an
                    918: empty string. 
                    919: 
                    920: $stayOnPage is a value that will be interpreted as a boolean. If true,
                    921: the link will not open a new window. If false, the link will open
                    922: a new window using Javascript. (Default is false.) 
                    923: 
                    924: $width and $height are optional numerical parameters that will
                    925: override the width and height of the popped up window, which may
                    926: be useful for certain help topics with big pictures included. 
1.44      bowersj2  927: 
                    928: =cut
                    929: 
                    930: sub help_open_topic {
1.48      bowersj2  931:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
                    932:     $text = "" if (not defined $text);
1.44      bowersj2  933:     $stayOnPage = 0 if (not defined $stayOnPage);
                    934:     $width = 350 if (not defined $width);
                    935:     $height = 400 if (not defined $height);
                    936:     my $filename = $topic;
                    937:     $filename =~ s/ /_/g;
                    938: 
1.48      bowersj2  939:     my $template = "";
                    940:     my $link;
1.572     banghart  941:     
1.159     www       942:     $topic=~s/\W/\_/g;
1.44      bowersj2  943: 
1.572     banghart  944:     if (!$stayOnPage) {
1.72      bowersj2  945: 	$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  946:     } else {
1.48      bowersj2  947: 	$link = "/adm/help/${filename}.hlp";
                    948:     }
                    949: 
                    950:     # Add the text
1.755     neumanie  951:     if ($text ne "") {	
1.763     bisitz    952: 	$template.='<span class="LC_help_open_topic">'
                    953:                   .'<a target="_top" href="'.$link.'">'
                    954:                   .$text.'</a>';
1.48      bowersj2  955:     }
                    956: 
1.763     bisitz    957:     # (Always) Add the graphic
1.179     matthew   958:     my $title = &mt('Online Help');
1.667     raeburn   959:     my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.763     bisitz    960:     $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
                    961:               .'<img src="'.$helpicon.'" border="0"'
                    962:               .' alt="'.&mt('Help: [_1]',$topic).'"'
1.783     amueller  963:               .' title="'.$title.'"' 
1.763     bisitz    964:               .' /></a>';
                    965:     if ($text ne "") {	
                    966:         $template.='</span>';
                    967:     }
1.44      bowersj2  968:     return $template;
                    969: 
1.106     bowersj2  970: }
                    971: 
                    972: # This is a quicky function for Latex cheatsheet editing, since it 
                    973: # appears in at least four places
                    974: sub helpLatexCheatsheet {
1.732     raeburn   975:     my ($topic,$text,$not_author) = @_;
                    976:     my $out;
1.106     bowersj2  977:     my $addOther = '';
1.732     raeburn   978:     if ($topic) {
1.763     bisitz    979: 	$addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
                    980: 							       undef, undef, 600).
                    981: 								   '</span> ';
                    982:     }
                    983:     $out = '<span>' # Start cheatsheet
                    984: 	  .$addOther
                    985:           .'<span>'
                    986: 	  .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
                    987: 					       undef,undef,600)
                    988: 	  .'</span> <span>'
                    989: 	  .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
                    990: 					       undef,undef,600)
                    991: 	  .'</span>';
1.732     raeburn   992:     unless ($not_author) {
1.763     bisitz    993:         $out .= ' <span>'
                    994: 	       .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
                    995: 	                                            undef,undef,600)
                    996: 	       .'</span>';
1.732     raeburn   997:     }
1.763     bisitz    998:     $out .= '</span>'; # End cheatsheet
1.732     raeburn   999:     return $out;
1.172     www      1000: }
                   1001: 
1.430     albertel 1002: sub general_help {
                   1003:     my $helptopic='Student_Intro';
                   1004:     if ($env{'request.role'}=~/^(ca|au)/) {
                   1005: 	$helptopic='Authoring_Intro';
                   1006:     } elsif ($env{'request.role'}=~/^cc/) {
                   1007: 	$helptopic='Course_Coordination_Intro';
1.672     raeburn  1008:     } elsif ($env{'request.role'}=~/^dc/) {
                   1009:         $helptopic='Domain_Coordination_Intro';
1.430     albertel 1010:     }
                   1011:     return $helptopic;
                   1012: }
                   1013: 
                   1014: sub update_help_link {
                   1015:     my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
                   1016:     my $origurl = $ENV{'REQUEST_URI'};
                   1017:     $origurl=~s|^/~|/priv/|;
                   1018:     my $timestamp = time;
                   1019:     foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
                   1020:         $$datum = &escape($$datum);
                   1021:     }
                   1022: 
                   1023:     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";
                   1024:     my $output .= <<"ENDOUTPUT";
                   1025: <script type="text/javascript">
                   1026: banner_link = '$banner_link';
                   1027: </script>
                   1028: ENDOUTPUT
                   1029:     return $output;
                   1030: }
                   1031: 
                   1032: # now just updates the help link and generates a blue icon
1.193     raeburn  1033: sub help_open_menu {
1.430     albertel 1034:     my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text) 
1.552     banghart 1035: 	= @_;    
1.430     albertel 1036:     $stayOnPage = 0 if (not defined $stayOnPage);
1.572     banghart 1037:     # only use pop-up help (stayOnPage == 0)
1.552     banghart 1038:     # if environment.remote is on (using remote control UI)
1.798     tempelho 1039:     if ($env{'environment.remote'} eq 'off' ) {
1.552     banghart 1040:         $stayOnPage=1;
1.430     albertel 1041:     }
                   1042:     my $output;
                   1043:     if ($component_help) {
                   1044: 	if (!$text) {
                   1045: 	    $output=&help_open_topic($component_help,undef,$stayOnPage,
                   1046: 				       $width,$height);
                   1047: 	} else {
                   1048: 	    my $help_text;
                   1049: 	    $help_text=&unescape($topic);
                   1050: 	    $output='<table><tr><td>'.
                   1051: 		&help_open_topic($component_help,$help_text,$stayOnPage,
                   1052: 				 $width,$height).'</td></tr></table>';
                   1053: 	}
                   1054:     }
                   1055:     my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
                   1056:     return $output.$banner_link;
                   1057: }
                   1058: 
                   1059: sub top_nav_help {
                   1060:     my ($text) = @_;
1.436     albertel 1061:     $text = &mt($text);
1.572     banghart 1062:     my $stay_on_page = 
1.798     tempelho 1063: 	($env{'environment.remote'} eq 'off' );
1.572     banghart 1064:     my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436     albertel 1065: 	                     : "javascript:helpMenu('open')";
1.572     banghart 1066:     my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436     albertel 1067: 
1.201     raeburn  1068:     my $title = &mt('Get help');
1.436     albertel 1069: 
                   1070:     return <<"END";
                   1071: $banner_link
                   1072:  <a href="$link" title="$title">$text</a>
                   1073: END
                   1074: }
                   1075: 
                   1076: sub help_menu_js {
                   1077:     my ($text) = @_;
                   1078: 
                   1079:     my $stayOnPage = 
1.798     tempelho 1080: 	($env{'environment.remote'} eq 'off' );
1.436     albertel 1081: 
                   1082:     my $width = 620;
                   1083:     my $height = 600;
1.430     albertel 1084:     my $helptopic=&general_help();
                   1085:     my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261     albertel 1086:     my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331     albertel 1087:     my $start_page =
                   1088:         &Apache::loncommon::start_page('Help Menu', undef,
                   1089: 				       {'frameset'    => 1,
                   1090: 					'js_ready'    => 1,
                   1091: 					'add_entries' => {
                   1092: 					    'border' => '0',
1.579     raeburn  1093: 					    'rows'   => "110,*",},});
1.331     albertel 1094:     my $end_page =
                   1095:         &Apache::loncommon::end_page({'frameset' => 1,
                   1096: 				      'js_ready' => 1,});
                   1097: 
1.436     albertel 1098:     my $template .= <<"ENDTEMPLATE";
                   1099: <script type="text/javascript">
1.253     albertel 1100: // <!-- BEGIN LON-CAPA Internal
                   1101: // <![CDATA[
1.430     albertel 1102: var banner_link = '';
1.243     raeburn  1103: function helpMenu(target) {
                   1104:     var caller = this;
                   1105:     if (target == 'open') {
                   1106:         var newWindow = null;
                   1107:         try {
1.262     albertel 1108:             newWindow =  window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243     raeburn  1109:         }
                   1110:         catch(error) {
                   1111:             writeHelp(caller);
                   1112:             return;
                   1113:         }
                   1114:         if (newWindow) {
                   1115:             caller = newWindow;
                   1116:         }
1.193     raeburn  1117:     }
1.243     raeburn  1118:     writeHelp(caller);
                   1119:     return;
                   1120: }
                   1121: function writeHelp(caller) {
1.430     albertel 1122:     caller.document.writeln('$start_page<frame name="bannerframe"  src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243     raeburn  1123:     caller.document.close()
                   1124:     caller.focus()
1.193     raeburn  1125: }
1.253     albertel 1126: // ]]>
1.219     albertel 1127: // END LON-CAPA Internal -->
1.436     albertel 1128: </script>
1.193     raeburn  1129: ENDTEMPLATE
                   1130:     return $template;
                   1131: }
                   1132: 
1.172     www      1133: sub help_open_bug {
                   1134:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1135:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1136:     unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
                   1137:     $text = "" if (not defined $text);
                   1138:     $stayOnPage = 0 if (not defined $stayOnPage);
1.798     tempelho 1139:     if ($env{'environment.remote'} eq 'off' ) {
1.172     www      1140: 	$stayOnPage=1;
                   1141:     }
1.184     albertel 1142:     $width = 600 if (not defined $width);
                   1143:     $height = 600 if (not defined $height);
1.172     www      1144: 
                   1145:     $topic=~s/\W+/\+/g;
                   1146:     my $link='';
                   1147:     my $template='';
1.379     albertel 1148:     my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&amp;bug_file_loc='.
                   1149: 	&escape($ENV{'REQUEST_URI'}).'&amp;component='.$topic;
1.172     www      1150:     if (!$stayOnPage)
                   1151:     {
                   1152: 	$link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1153:     }
                   1154:     else
                   1155:     {
                   1156: 	$link = $url;
                   1157:     }
                   1158:     # Add the text
                   1159:     if ($text ne "")
                   1160:     {
                   1161: 	$template .= 
                   1162:   "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1163:   "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172     www      1164:     }
                   1165: 
                   1166:     # Add the graphic
1.179     matthew  1167:     my $title = &mt('Report a Bug');
1.215     albertel 1168:     my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172     www      1169:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1170:  <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172     www      1171: ENDTEMPLATE
                   1172:     if ($text ne '') { $template.='</td></tr></table>' };
                   1173:     return $template;
                   1174: 
                   1175: }
                   1176: 
                   1177: sub help_open_faq {
                   1178:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1179:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1180:     unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
                   1181:     $text = "" if (not defined $text);
                   1182:     $stayOnPage = 0 if (not defined $stayOnPage);
1.798     tempelho 1183:     if ($env{'environment.remote'} eq 'off' ) {
1.172     www      1184: 	$stayOnPage=1;
                   1185:     }
                   1186:     $width = 350 if (not defined $width);
                   1187:     $height = 400 if (not defined $height);
                   1188: 
                   1189:     $topic=~s/\W+/\+/g;
                   1190:     my $link='';
                   1191:     my $template='';
                   1192:     my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
                   1193:     if (!$stayOnPage)
                   1194:     {
                   1195: 	$link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1196:     }
                   1197:     else
                   1198:     {
                   1199: 	$link = $url;
                   1200:     }
                   1201: 
                   1202:     # Add the text
                   1203:     if ($text ne "")
                   1204:     {
                   1205: 	$template .= 
1.173     www      1206:   "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1207:   "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172     www      1208:     }
                   1209: 
                   1210:     # Add the graphic
1.179     matthew  1211:     my $title = &mt('View the FAQ');
1.215     albertel 1212:     my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172     www      1213:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1214:  <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172     www      1215: ENDTEMPLATE
                   1216:     if ($text ne '') { $template.='</td></tr></table>' };
                   1217:     return $template;
                   1218: 
1.44      bowersj2 1219: }
1.37      matthew  1220: 
1.180     matthew  1221: ###############################################################
                   1222: ###############################################################
                   1223: 
1.45      matthew  1224: =pod
                   1225: 
1.648     raeburn  1226: =item * &change_content_javascript():
1.256     matthew  1227: 
                   1228: This and the next function allow you to create small sections of an
                   1229: otherwise static HTML page that you can update on the fly with
                   1230: Javascript, even in Netscape 4.
                   1231: 
                   1232: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
                   1233: must be written to the HTML page once. It will prove the Javascript
                   1234: function "change(name, content)". Calling the change function with the
                   1235: name of the section 
                   1236: you want to update, matching the name passed to C<changable_area>, and
                   1237: the new content you want to put in there, will put the content into
                   1238: that area.
                   1239: 
                   1240: B<Note>: Netscape 4 only reserves enough space for the changable area
                   1241: to contain room for the original contents. You need to "make space"
                   1242: for whatever changes you wish to make, and be B<sure> to check your
                   1243: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
                   1244: it's adequate for updating a one-line status display, but little more.
                   1245: This script will set the space to 100% width, so you only need to
                   1246: worry about height in Netscape 4.
                   1247: 
                   1248: Modern browsers are much less limiting, and if you can commit to the
                   1249: user not using Netscape 4, this feature may be used freely with
                   1250: pretty much any HTML.
                   1251: 
                   1252: =cut
                   1253: 
                   1254: sub change_content_javascript {
                   1255:     # If we're on Netscape 4, we need to use Layer-based code
1.258     albertel 1256:     if ($env{'browser.type'} eq 'netscape' &&
                   1257: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1258: 	return (<<NETSCAPE4);
                   1259: 	function change(name, content) {
                   1260: 	    doc = document.layers[name+"___escape"].layers[0].document;
                   1261: 	    doc.open();
                   1262: 	    doc.write(content);
                   1263: 	    doc.close();
                   1264: 	}
                   1265: NETSCAPE4
                   1266:     } else {
                   1267: 	# Otherwise, we need to use semi-standards-compliant code
                   1268: 	# (technically, "innerHTML" isn't standard but the equivalent
                   1269: 	# is really scary, and every useful browser supports it
                   1270: 	return (<<DOMBASED);
                   1271: 	function change(name, content) {
                   1272: 	    element = document.getElementById(name);
                   1273: 	    element.innerHTML = content;
                   1274: 	}
                   1275: DOMBASED
                   1276:     }
                   1277: }
                   1278: 
                   1279: =pod
                   1280: 
1.648     raeburn  1281: =item * &changable_area($name,$origContent):
1.256     matthew  1282: 
                   1283: This provides a "changable area" that can be modified on the fly via
                   1284: the Javascript code provided in C<change_content_javascript>. $name is
                   1285: the name you will use to reference the area later; do not repeat the
                   1286: same name on a given HTML page more then once. $origContent is what
                   1287: the area will originally contain, which can be left blank.
                   1288: 
                   1289: =cut
                   1290: 
                   1291: sub changable_area {
                   1292:     my ($name, $origContent) = @_;
                   1293: 
1.258     albertel 1294:     if ($env{'browser.type'} eq 'netscape' &&
                   1295: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1296: 	# If this is netscape 4, we need to use the Layer tag
                   1297: 	return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
                   1298:     } else {
                   1299: 	return "<span id='$name'>$origContent</span>";
                   1300:     }
                   1301: }
                   1302: 
                   1303: =pod
                   1304: 
1.648     raeburn  1305: =item * &viewport_geometry_js 
1.590     raeburn  1306: 
                   1307: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
                   1308: 
                   1309: =cut
                   1310: 
                   1311: 
                   1312: sub viewport_geometry_js { 
                   1313:     return <<"GEOMETRY";
                   1314: var Geometry = {};
                   1315: function init_geometry() {
                   1316:     if (Geometry.init) { return };
                   1317:     Geometry.init=1;
                   1318:     if (window.innerHeight) {
                   1319:         Geometry.getViewportHeight   = function() { return window.innerHeight; };
                   1320:         Geometry.getViewportWidth   = function() { return window.innerWidth; };
                   1321:         Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
                   1322:         Geometry.getVerticalScroll   = function() { return window.pageYOffset; };
                   1323:     }
                   1324:     else if (document.documentElement && document.documentElement.clientHeight) {
                   1325:         Geometry.getViewportHeight =
                   1326:             function() { return document.documentElement.clientHeight; };
                   1327:         Geometry.getViewportWidth =
                   1328:             function() { return document.documentElement.clientWidth; };
                   1329: 
                   1330:         Geometry.getHorizontalScroll =
                   1331:             function() { return document.documentElement.scrollLeft; };
                   1332:         Geometry.getVerticalScroll =
                   1333:             function() { return document.documentElement.scrollTop; };
                   1334:     }
                   1335:     else if (document.body.clientHeight) {
                   1336:         Geometry.getViewportHeight =
                   1337:             function() { return document.body.clientHeight; };
                   1338:         Geometry.getViewportWidth =
                   1339:             function() { return document.body.clientWidth; };
                   1340:         Geometry.getHorizontalScroll =
                   1341:             function() { return document.body.scrollLeft; };
                   1342:         Geometry.getVerticalScroll =
                   1343:             function() { return document.body.scrollTop; };
                   1344:     }
                   1345: }
                   1346: 
                   1347: GEOMETRY
                   1348: }
                   1349: 
                   1350: =pod
                   1351: 
1.648     raeburn  1352: =item * &viewport_size_js()
1.590     raeburn  1353: 
                   1354: 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. 
                   1355: 
                   1356: =cut
                   1357: 
                   1358: sub viewport_size_js {
                   1359:     my $geometry = &viewport_geometry_js();
                   1360:     return <<"DIMS";
                   1361: 
                   1362: $geometry
                   1363: 
                   1364: function getViewportDims(width,height) {
                   1365:     init_geometry();
                   1366:     width.value = Geometry.getViewportWidth();
                   1367:     height.value = Geometry.getViewportHeight();
                   1368:     return;
                   1369: }
                   1370: 
                   1371: DIMS
                   1372: }
                   1373: 
                   1374: =pod
                   1375: 
1.648     raeburn  1376: =item * &resize_textarea_js()
1.565     albertel 1377: 
                   1378: emits the needed javascript to resize a textarea to be as big as possible
                   1379: 
                   1380: creates a function resize_textrea that takes two IDs first should be
                   1381: the id of the element to resize, second should be the id of a div that
                   1382: surrounds everything that comes after the textarea, this routine needs
                   1383: to be attached to the <body> for the onload and onresize events.
                   1384: 
1.648     raeburn  1385: =back
1.565     albertel 1386: 
                   1387: =cut
                   1388: 
                   1389: sub resize_textarea_js {
1.590     raeburn  1390:     my $geometry = &viewport_geometry_js();
1.565     albertel 1391:     return <<"RESIZE";
                   1392:     <script type="text/javascript">
1.590     raeburn  1393: $geometry
1.565     albertel 1394: 
1.588     albertel 1395: function getX(element) {
                   1396:     var x = 0;
                   1397:     while (element) {
                   1398: 	x += element.offsetLeft;
                   1399: 	element = element.offsetParent;
                   1400:     }
                   1401:     return x;
                   1402: }
                   1403: function getY(element) {
                   1404:     var y = 0;
                   1405:     while (element) {
                   1406: 	y += element.offsetTop;
                   1407: 	element = element.offsetParent;
                   1408:     }
                   1409:     return y;
                   1410: }
                   1411: 
                   1412: 
1.565     albertel 1413: function resize_textarea(textarea_id,bottom_id) {
                   1414:     init_geometry();
                   1415:     var textarea        = document.getElementById(textarea_id);
                   1416:     //alert(textarea);
                   1417: 
1.588     albertel 1418:     var textarea_top    = getY(textarea);
1.565     albertel 1419:     var textarea_height = textarea.offsetHeight;
                   1420:     var bottom          = document.getElementById(bottom_id);
1.588     albertel 1421:     var bottom_top      = getY(bottom);
1.565     albertel 1422:     var bottom_height   = bottom.offsetHeight;
                   1423:     var window_height   = Geometry.getViewportHeight();
1.588     albertel 1424:     var fudge           = 23;
1.565     albertel 1425:     var new_height      = window_height-fudge-textarea_top-bottom_height;
                   1426:     if (new_height < 300) {
                   1427: 	new_height = 300;
                   1428:     }
                   1429:     textarea.style.height=new_height+'px';
                   1430: }
                   1431: </script>
                   1432: RESIZE
                   1433: 
                   1434: }
                   1435: 
                   1436: =pod
                   1437: 
1.256     matthew  1438: =head1 Excel and CSV file utility routines
                   1439: 
                   1440: =over 4
                   1441: 
                   1442: =cut
                   1443: 
                   1444: ###############################################################
                   1445: ###############################################################
                   1446: 
                   1447: =pod
                   1448: 
1.648     raeburn  1449: =item * &csv_translate($text) 
1.37      matthew  1450: 
1.185     www      1451: Translate $text to allow it to be output as a 'comma separated values' 
1.37      matthew  1452: format.
                   1453: 
                   1454: =cut
                   1455: 
1.180     matthew  1456: ###############################################################
                   1457: ###############################################################
1.37      matthew  1458: sub csv_translate {
                   1459:     my $text = shift;
                   1460:     $text =~ s/\"/\"\"/g;
1.209     albertel 1461:     $text =~ s/\n/ /g;
1.37      matthew  1462:     return $text;
                   1463: }
1.180     matthew  1464: 
                   1465: ###############################################################
                   1466: ###############################################################
                   1467: 
                   1468: =pod
                   1469: 
1.648     raeburn  1470: =item * &define_excel_formats()
1.180     matthew  1471: 
                   1472: Define some commonly used Excel cell formats.
                   1473: 
                   1474: Currently supported formats:
                   1475: 
                   1476: =over 4
                   1477: 
                   1478: =item header
                   1479: 
                   1480: =item bold
                   1481: 
                   1482: =item h1
                   1483: 
                   1484: =item h2
                   1485: 
                   1486: =item h3
                   1487: 
1.256     matthew  1488: =item h4
                   1489: 
                   1490: =item i
                   1491: 
1.180     matthew  1492: =item date
                   1493: 
                   1494: =back
                   1495: 
                   1496: Inputs: $workbook
                   1497: 
                   1498: Returns: $format, a hash reference.
                   1499: 
                   1500: =cut
                   1501: 
                   1502: ###############################################################
                   1503: ###############################################################
                   1504: sub define_excel_formats {
                   1505:     my ($workbook) = @_;
                   1506:     my $format;
                   1507:     $format->{'header'} = $workbook->add_format(bold      => 1, 
                   1508:                                                 bottom    => 1,
                   1509:                                                 align     => 'center');
                   1510:     $format->{'bold'} = $workbook->add_format(bold=>1);
                   1511:     $format->{'h1'}   = $workbook->add_format(bold=>1, size=>18);
                   1512:     $format->{'h2'}   = $workbook->add_format(bold=>1, size=>16);
                   1513:     $format->{'h3'}   = $workbook->add_format(bold=>1, size=>14);
1.255     matthew  1514:     $format->{'h4'}   = $workbook->add_format(bold=>1, size=>12);
1.246     matthew  1515:     $format->{'i'}    = $workbook->add_format(italic=>1);
1.180     matthew  1516:     $format->{'date'} = $workbook->add_format(num_format=>
1.207     matthew  1517:                                             'mm/dd/yyyy hh:mm:ss');
1.180     matthew  1518:     return $format;
                   1519: }
                   1520: 
                   1521: ###############################################################
                   1522: ###############################################################
1.113     bowersj2 1523: 
                   1524: =pod
                   1525: 
1.648     raeburn  1526: =item * &create_workbook()
1.255     matthew  1527: 
                   1528: Create an Excel worksheet.  If it fails, output message on the
                   1529: request object and return undefs.
                   1530: 
                   1531: Inputs: Apache request object
                   1532: 
                   1533: Returns (undef) on failure, 
                   1534:     Excel worksheet object, scalar with filename, and formats 
                   1535:     from &Apache::loncommon::define_excel_formats on success
                   1536: 
                   1537: =cut
                   1538: 
                   1539: ###############################################################
                   1540: ###############################################################
                   1541: sub create_workbook {
                   1542:     my ($r) = @_;
                   1543:         #
                   1544:     # Create the excel spreadsheet
                   1545:     my $filename = '/prtspool/'.
1.258     albertel 1546:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255     matthew  1547:         time.'_'.rand(1000000000).'.xls';
                   1548:     my $workbook  = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
                   1549:     if (! defined($workbook)) {
                   1550:         $r->log_error("Error creating excel spreadsheet $filename: $!");
                   1551:         $r->print('<p>'.&mt("Unable to create new Excel file.  ".
                   1552:                             "This error has been logged.  ".
                   1553:                             "Please alert your LON-CAPA administrator").
                   1554:                   '</p>');
                   1555:         return (undef);
                   1556:     }
                   1557:     #
                   1558:     $workbook->set_tempdir('/home/httpd/perl/tmp');
                   1559:     #
                   1560:     my $format = &Apache::loncommon::define_excel_formats($workbook);
                   1561:     return ($workbook,$filename,$format);
                   1562: }
                   1563: 
                   1564: ###############################################################
                   1565: ###############################################################
                   1566: 
                   1567: =pod
                   1568: 
1.648     raeburn  1569: =item * &create_text_file()
1.113     bowersj2 1570: 
1.542     raeburn  1571: Create a file to write to and eventually make available to the user.
1.256     matthew  1572: If file creation fails, outputs an error message on the request object and 
                   1573: return undefs.
1.113     bowersj2 1574: 
1.256     matthew  1575: Inputs: Apache request object, and file suffix
1.113     bowersj2 1576: 
1.256     matthew  1577: Returns (undef) on failure, 
                   1578:     Filehandle and filename on success.
1.113     bowersj2 1579: 
                   1580: =cut
                   1581: 
1.256     matthew  1582: ###############################################################
                   1583: ###############################################################
                   1584: sub create_text_file {
                   1585:     my ($r,$suffix) = @_;
                   1586:     if (! defined($suffix)) { $suffix = 'txt'; };
                   1587:     my $fh;
                   1588:     my $filename = '/prtspool/'.
1.258     albertel 1589:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256     matthew  1590:         time.'_'.rand(1000000000).'.'.$suffix;
                   1591:     $fh = Apache::File->new('>/home/httpd'.$filename);
                   1592:     if (! defined($fh)) {
                   1593:         $r->log_error("Couldn't open $filename for output $!");
1.683     bisitz   1594:         $r->print(&mt('Problems occurred in creating the output file. '
                   1595:                      .'This error has been logged. '
                   1596:                      .'Please alert your LON-CAPA administrator.'));
1.113     bowersj2 1597:     }
1.256     matthew  1598:     return ($fh,$filename)
1.113     bowersj2 1599: }
                   1600: 
                   1601: 
1.256     matthew  1602: =pod 
1.113     bowersj2 1603: 
                   1604: =back
                   1605: 
                   1606: =cut
1.37      matthew  1607: 
                   1608: ###############################################################
1.33      matthew  1609: ##        Home server <option> list generating code          ##
                   1610: ###############################################################
1.35      matthew  1611: 
1.169     www      1612: # ------------------------------------------
                   1613: 
                   1614: sub domain_select {
                   1615:     my ($name,$value,$multiple)=@_;
                   1616:     my %domains=map { 
1.514     albertel 1617: 	$_ => $_.' '. &Apache::lonnet::domain($_,'description') 
1.512     albertel 1618:     } &Apache::lonnet::all_domains();
1.169     www      1619:     if ($multiple) {
                   1620: 	$domains{''}=&mt('Any domain');
1.550     albertel 1621: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287     albertel 1622: 	return &multiple_select_form($name,$value,4,\%domains);
1.169     www      1623:     } else {
1.550     albertel 1624: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169     www      1625: 	return &select_form($name,$value,%domains);
                   1626:     }
                   1627: }
                   1628: 
1.282     albertel 1629: #-------------------------------------------
                   1630: 
                   1631: =pod
                   1632: 
1.519     raeburn  1633: =head1 Routines for form select boxes
                   1634: 
                   1635: =over 4
                   1636: 
1.648     raeburn  1637: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282     albertel 1638: 
                   1639: Returns a string containing a <select> element int multiple mode
                   1640: 
                   1641: 
                   1642: Args:
                   1643:   $name - name of the <select> element
1.506     raeburn  1644:   $value - scalar or array ref of values that should already be selected
1.282     albertel 1645:   $size - number of rows long the select element is
1.283     albertel 1646:   $hash - the elements should be 'option' => 'shown text'
1.282     albertel 1647:           (shown text should already have been &mt())
1.506     raeburn  1648:   $order - (optional) array ref of the order to show the elements in
1.283     albertel 1649: 
1.282     albertel 1650: =cut
                   1651: 
                   1652: #-------------------------------------------
1.169     www      1653: sub multiple_select_form {
1.284     albertel 1654:     my ($name,$value,$size,$hash,$order)=@_;
1.169     www      1655:     my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
                   1656:     my $output='';
1.191     matthew  1657:     if (! defined($size)) {
                   1658:         $size = 4;
1.283     albertel 1659:         if (scalar(keys(%$hash))<4) {
                   1660:             $size = scalar(keys(%$hash));
1.191     matthew  1661:         }
                   1662:     }
1.734     bisitz   1663:     $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501     banghart 1664:     my @order;
1.506     raeburn  1665:     if (ref($order) eq 'ARRAY')  {
                   1666:         @order = @{$order};
                   1667:     } else {
                   1668:         @order = sort(keys(%$hash));
1.501     banghart 1669:     }
                   1670:     if (exists($$hash{'select_form_order'})) {
                   1671:         @order = @{$$hash{'select_form_order'}};
                   1672:     }
                   1673:         
1.284     albertel 1674:     foreach my $key (@order) {
1.356     albertel 1675:         $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284     albertel 1676:         $output.='selected="selected" ' if ($selected{$key});
                   1677:         $output.='>'.$hash->{$key}."</option>\n";
1.169     www      1678:     }
                   1679:     $output.="</select>\n";
                   1680:     return $output;
                   1681: }
                   1682: 
1.88      www      1683: #-------------------------------------------
                   1684: 
                   1685: =pod
                   1686: 
1.648     raeburn  1687: =item * &select_form($defdom,$name,%hash)
1.88      www      1688: 
                   1689: Returns a string containing a <select name='$name' size='1'> form to 
                   1690: allow a user to select options from a hash option_name => displayed text.  
                   1691: See lonrights.pm for an example invocation and use.
                   1692: 
                   1693: =cut
                   1694: 
                   1695: #-------------------------------------------
                   1696: sub select_form {
                   1697:     my ($def,$name,%hash) = @_;
                   1698:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128     albertel 1699:     my @keys;
                   1700:     if (exists($hash{'select_form_order'})) {
                   1701: 	@keys=@{$hash{'select_form_order'}};
                   1702:     } else {
                   1703: 	@keys=sort(keys(%hash));
                   1704:     }
1.356     albertel 1705:     foreach my $key (@keys) {
                   1706:         $selectform.=
                   1707: 	    '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
                   1708:             ($key eq $def ? 'selected="selected" ' : '').
                   1709:                 ">".&mt($hash{$key})."</option>\n";
1.88      www      1710:     }
                   1711:     $selectform.="</select>";
                   1712:     return $selectform;
                   1713: }
                   1714: 
1.475     www      1715: # For display filters
                   1716: 
                   1717: sub display_filter {
                   1718:     if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477     www      1719:     if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714     bisitz   1720:     return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475     www      1721: 			       &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
                   1722: 							   (&mt('all'),10,20,50,100,1000,10000))).
1.714     bisitz   1723: 	   '</label></span> <span class="LC_nobreak">'.
1.475     www      1724:            &mt('Filter [_1]',
1.477     www      1725: 	   &select_form($env{'form.displayfilter'},
                   1726: 			'displayfilter',
                   1727: 			('currentfolder' => 'Current folder/page',
                   1728: 			 'containing' => 'Containing phrase',
                   1729: 			 'none' => 'None'))).
1.714     bisitz   1730: 			 '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475     www      1731: }
                   1732: 
1.167     www      1733: sub gradeleveldescription {
                   1734:     my $gradelevel=shift;
                   1735:     my %gradelevels=(0 => 'Not specified',
                   1736: 		     1 => 'Grade 1',
                   1737: 		     2 => 'Grade 2',
                   1738: 		     3 => 'Grade 3',
                   1739: 		     4 => 'Grade 4',
                   1740: 		     5 => 'Grade 5',
                   1741: 		     6 => 'Grade 6',
                   1742: 		     7 => 'Grade 7',
                   1743: 		     8 => 'Grade 8',
                   1744: 		     9 => 'Grade 9',
                   1745: 		     10 => 'Grade 10',
                   1746: 		     11 => 'Grade 11',
                   1747: 		     12 => 'Grade 12',
                   1748: 		     13 => 'Grade 13',
                   1749: 		     14 => '100 Level',
                   1750: 		     15 => '200 Level',
                   1751: 		     16 => '300 Level',
                   1752: 		     17 => '400 Level',
                   1753: 		     18 => 'Graduate Level');
                   1754:     return &mt($gradelevels{$gradelevel});
                   1755: }
                   1756: 
1.163     www      1757: sub select_level_form {
                   1758:     my ($deflevel,$name)=@_;
                   1759:     unless ($deflevel) { $deflevel=0; }
1.167     www      1760:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
                   1761:     for (my $i=0; $i<=18; $i++) {
                   1762:         $selectform.="<option value=\"$i\" ".
1.253     albertel 1763:             ($i==$deflevel ? 'selected="selected" ' : '').
1.167     www      1764:                 ">".&gradeleveldescription($i)."</option>\n";
                   1765:     }
                   1766:     $selectform.="</select>";
                   1767:     return $selectform;
1.163     www      1768: }
1.167     www      1769: 
1.35      matthew  1770: #-------------------------------------------
                   1771: 
1.45      matthew  1772: =pod
                   1773: 
1.743     raeburn  1774: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$autosubmit)
1.35      matthew  1775: 
                   1776: Returns a string containing a <select name='$name' size='1'> form to 
                   1777: allow a user to select the domain to preform an operation in.  
                   1778: See loncreateuser.pm for an example invocation and use.
                   1779: 
1.90      www      1780: If the $includeempty flag is set, it also includes an empty choice ("no domain
                   1781: selected");
                   1782: 
1.743     raeburn  1783: If the $showdomdesc flag is set, the domain name is followed by the domain description.
                   1784: 
                   1785: If the $autosubmit flag is set, the form containing the domain selector will be auto-submitted by an onchange action.  
1.563     raeburn  1786: 
1.35      matthew  1787: =cut
                   1788: 
                   1789: #-------------------------------------------
1.34      matthew  1790: sub select_dom_form {
1.743     raeburn  1791:     my ($defdom,$name,$includeempty,$showdomdesc,$autosubmit) = @_;
                   1792:     my $onchange;
                   1793:     if ($autosubmit) {
                   1794:         $onchange = ' onchange="this.form.submit()"';
                   1795:     }
1.550     albertel 1796:     my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90      www      1797:     if ($includeempty) { @domains=('',@domains); }
1.743     raeburn  1798:     my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356     albertel 1799:     foreach my $dom (@domains) {
                   1800:         $selectdomain.="<option value=\"$dom\" ".
1.563     raeburn  1801:             ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
                   1802:         if ($showdomdesc) {
                   1803:             if ($dom ne '') {
                   1804:                 my $domdesc = &Apache::lonnet::domain($dom,'description');
                   1805:                 if ($domdesc ne '') {
                   1806:                     $selectdomain .= ' ('.$domdesc.')';
                   1807:                 }
                   1808:             } 
                   1809:         }
                   1810:         $selectdomain .= "</option>\n";
1.34      matthew  1811:     }
                   1812:     $selectdomain.="</select>";
                   1813:     return $selectdomain;
                   1814: }
                   1815: 
1.35      matthew  1816: #-------------------------------------------
                   1817: 
1.45      matthew  1818: =pod
                   1819: 
1.648     raeburn  1820: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35      matthew  1821: 
1.586     raeburn  1822: input: 4 arguments (two required, two optional) - 
                   1823:     $domain - domain of new user
                   1824:     $name - name of form element
                   1825:     $default - Value of 'default' causes a default item to be first 
                   1826:                             option, and selected by default. 
                   1827:     $hide - Value of 'hide' causes hiding of the name of the server, 
                   1828:                             if 1 server found, or default, if 0 found.
1.594     raeburn  1829: output: returns 2 items: 
1.586     raeburn  1830: (a) form element which contains either:
                   1831:    (i) <select name="$name">
                   1832:         <option value="$hostid1">$hostid $servers{$hostid}</option>
                   1833:         <option value="$hostid2">$hostid $servers{$hostid}</option>       
                   1834:        </select>
                   1835:        form item if there are multiple library servers in $domain, or
                   1836:    (ii) an <input type="hidden" name="$name" value="$hostid" /> form item 
                   1837:        if there is only one library server in $domain.
                   1838: 
                   1839: (b) number of library servers found.
                   1840: 
                   1841: See loncreateuser.pm for example of use.
1.35      matthew  1842: 
                   1843: =cut
                   1844: 
                   1845: #-------------------------------------------
1.586     raeburn  1846: sub home_server_form_item {
                   1847:     my ($domain,$name,$default,$hide) = @_;
1.513     albertel 1848:     my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586     raeburn  1849:     my $result;
                   1850:     my $numlib = keys(%servers);
                   1851:     if ($numlib > 1) {
                   1852:         $result .= '<select name="'.$name.'" />'."\n";
                   1853:         if ($default) {
                   1854:             $result .= '<option value="default" selected>'.&mt('default').
                   1855:                        '</option>'."\n";
                   1856:         }
                   1857:         foreach my $hostid (sort(keys(%servers))) {
                   1858:             $result.= '<option value="'.$hostid.'">'.
                   1859: 	              $hostid.' '.$servers{$hostid}."</option>\n";
                   1860:         }
                   1861:         $result .= '</select>'."\n";
                   1862:     } elsif ($numlib == 1) {
                   1863:         my $hostid;
                   1864:         foreach my $item (keys(%servers)) {
                   1865:             $hostid = $item;
                   1866:         }
                   1867:         $result .= '<input type="hidden" name="'.$name.'" value="'.
                   1868:                    $hostid.'" />';
                   1869:                    if (!$hide) {
                   1870:                        $result .= $hostid.' '.$servers{$hostid};
                   1871:                    }
                   1872:                    $result .= "\n";
                   1873:     } elsif ($default) {
                   1874:         $result .= '<input type="hidden" name="'.$name.
                   1875:                    '" value="default" />';
                   1876:                    if (!$hide) {
                   1877:                        $result .= &mt('default');
                   1878:                    }
                   1879:                    $result .= "\n";
1.33      matthew  1880:     }
1.586     raeburn  1881:     return ($result,$numlib);
1.33      matthew  1882: }
1.112     bowersj2 1883: 
                   1884: =pod
                   1885: 
1.534     albertel 1886: =back 
                   1887: 
1.112     bowersj2 1888: =cut
1.87      matthew  1889: 
                   1890: ###############################################################
1.112     bowersj2 1891: ##                  Decoding User Agent                      ##
1.87      matthew  1892: ###############################################################
                   1893: 
                   1894: =pod
                   1895: 
1.112     bowersj2 1896: =head1 Decoding the User Agent
                   1897: 
                   1898: =over 4
                   1899: 
                   1900: =item * &decode_user_agent()
1.87      matthew  1901: 
                   1902: Inputs: $r
                   1903: 
                   1904: Outputs:
                   1905: 
                   1906: =over 4
                   1907: 
1.112     bowersj2 1908: =item * $httpbrowser
1.87      matthew  1909: 
1.112     bowersj2 1910: =item * $clientbrowser
1.87      matthew  1911: 
1.112     bowersj2 1912: =item * $clientversion
1.87      matthew  1913: 
1.112     bowersj2 1914: =item * $clientmathml
1.87      matthew  1915: 
1.112     bowersj2 1916: =item * $clientunicode
1.87      matthew  1917: 
1.112     bowersj2 1918: =item * $clientos
1.87      matthew  1919: 
                   1920: =back
                   1921: 
1.157     matthew  1922: =back 
                   1923: 
1.87      matthew  1924: =cut
                   1925: 
                   1926: ###############################################################
                   1927: ###############################################################
                   1928: sub decode_user_agent {
1.247     albertel 1929:     my ($r)=@_;
1.87      matthew  1930:     my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
                   1931:     my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
                   1932:     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247     albertel 1933:     if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87      matthew  1934:     my $clientbrowser='unknown';
                   1935:     my $clientversion='0';
                   1936:     my $clientmathml='';
                   1937:     my $clientunicode='0';
                   1938:     for (my $i=0;$i<=$#browsertype;$i++) {
                   1939:         my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
                   1940: 	if (($httpbrowser=~/$match/i)  && ($httpbrowser!~/$notmatch/i)) {
                   1941: 	    $clientbrowser=$bname;
                   1942:             $httpbrowser=~/$vreg/i;
                   1943: 	    $clientversion=$1;
                   1944:             $clientmathml=($clientversion>=$minv);
                   1945:             $clientunicode=($clientversion>=$univ);
                   1946: 	}
                   1947:     }
                   1948:     my $clientos='unknown';
                   1949:     if (($httpbrowser=~/linux/i) ||
                   1950:         ($httpbrowser=~/unix/i) ||
                   1951:         ($httpbrowser=~/ux/i) ||
                   1952:         ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
                   1953:     if (($httpbrowser=~/vax/i) ||
                   1954:         ($httpbrowser=~/vms/i)) { $clientos='vms'; }
                   1955:     if ($httpbrowser=~/next/i) { $clientos='next'; }
                   1956:     if (($httpbrowser=~/mac/i) ||
                   1957:         ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
                   1958:     if ($httpbrowser=~/win/i) { $clientos='win'; }
                   1959:     if ($httpbrowser=~/embed/i) { $clientos='pda'; }
                   1960:     return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   1961:             $clientunicode,$clientos,);
                   1962: }
                   1963: 
1.32      matthew  1964: ###############################################################
                   1965: ##    Authentication changing form generation subroutines    ##
                   1966: ###############################################################
                   1967: ##
                   1968: ## All of the authform_xxxxxxx subroutines take their inputs in a
                   1969: ## hash, and have reasonable default values.
                   1970: ##
                   1971: ##    formname = the name given in the <form> tag.
1.35      matthew  1972: #-------------------------------------------
                   1973: 
1.45      matthew  1974: =pod
                   1975: 
1.112     bowersj2 1976: =head1 Authentication Routines
                   1977: 
                   1978: =over 4
                   1979: 
1.648     raeburn  1980: =item * &authform_xxxxxx()
1.35      matthew  1981: 
                   1982: The authform_xxxxxx subroutines provide javascript and html forms which 
                   1983: handle some of the conveniences required for authentication forms.  
                   1984: This is not an optimal method, but it works.  
                   1985: 
                   1986: =over 4
                   1987: 
1.112     bowersj2 1988: =item * authform_header
1.35      matthew  1989: 
1.112     bowersj2 1990: =item * authform_authorwarning
1.35      matthew  1991: 
1.112     bowersj2 1992: =item * authform_nochange
1.35      matthew  1993: 
1.112     bowersj2 1994: =item * authform_kerberos
1.35      matthew  1995: 
1.112     bowersj2 1996: =item * authform_internal
1.35      matthew  1997: 
1.112     bowersj2 1998: =item * authform_filesystem
1.35      matthew  1999: 
                   2000: =back
                   2001: 
1.648     raeburn  2002: See loncreateuser.pm for invocation and use examples.
1.157     matthew  2003: 
1.35      matthew  2004: =cut
                   2005: 
                   2006: #-------------------------------------------
1.32      matthew  2007: sub authform_header{  
                   2008:     my %in = (
                   2009:         formname => 'cu',
1.80      albertel 2010:         kerb_def_dom => '',
1.32      matthew  2011:         @_,
                   2012:     );
                   2013:     $in{'formname'} = 'document.' . $in{'formname'};
                   2014:     my $result='';
1.80      albertel 2015: 
                   2016: #---------------------------------------------- Code for upper case translation
                   2017:     my $Javascript_toUpperCase;
                   2018:     unless ($in{kerb_def_dom}) {
                   2019:         $Javascript_toUpperCase =<<"END";
                   2020:         switch (choice) {
                   2021:            case 'krb': currentform.elements[choicearg].value =
                   2022:                currentform.elements[choicearg].value.toUpperCase();
                   2023:                break;
                   2024:            default:
                   2025:         }
                   2026: END
                   2027:     } else {
                   2028:         $Javascript_toUpperCase = "";
                   2029:     }
                   2030: 
1.165     raeburn  2031:     my $radioval = "'nochange'";
1.591     raeburn  2032:     if (defined($in{'curr_authtype'})) {
                   2033:         if ($in{'curr_authtype'} ne '') {
                   2034:             $radioval = "'".$in{'curr_authtype'}."arg'";
                   2035:         }
1.174     matthew  2036:     }
1.165     raeburn  2037:     my $argfield = 'null';
1.591     raeburn  2038:     if (defined($in{'mode'})) {
1.165     raeburn  2039:         if ($in{'mode'} eq 'modifycourse')  {
1.591     raeburn  2040:             if (defined($in{'curr_autharg'})) {
                   2041:                 if ($in{'curr_autharg'} ne '') {
1.165     raeburn  2042:                     $argfield = "'$in{'curr_autharg'}'";
                   2043:                 }
                   2044:             }
                   2045:         }
                   2046:     }
                   2047: 
1.32      matthew  2048:     $result.=<<"END";
                   2049: var current = new Object();
1.165     raeburn  2050: current.radiovalue = $radioval;
                   2051: current.argfield = $argfield;
1.32      matthew  2052: 
                   2053: function changed_radio(choice,currentform) {
                   2054:     var choicearg = choice + 'arg';
                   2055:     // If a radio button in changed, we need to change the argfield
                   2056:     if (current.radiovalue != choice) {
                   2057:         current.radiovalue = choice;
                   2058:         if (current.argfield != null) {
                   2059:             currentform.elements[current.argfield].value = '';
                   2060:         }
                   2061:         if (choice == 'nochange') {
                   2062:             current.argfield = null;
                   2063:         } else {
                   2064:             current.argfield = choicearg;
                   2065:             switch(choice) {
                   2066:                 case 'krb': 
                   2067:                     currentform.elements[current.argfield].value = 
                   2068:                         "$in{'kerb_def_dom'}";
                   2069:                 break;
                   2070:               default:
                   2071:                 break;
                   2072:             }
                   2073:         }
                   2074:     }
                   2075:     return;
                   2076: }
1.22      www      2077: 
1.32      matthew  2078: function changed_text(choice,currentform) {
                   2079:     var choicearg = choice + 'arg';
                   2080:     if (currentform.elements[choicearg].value !='') {
1.80      albertel 2081:         $Javascript_toUpperCase
1.32      matthew  2082:         // clear old field
                   2083:         if ((current.argfield != choicearg) && (current.argfield != null)) {
                   2084:             currentform.elements[current.argfield].value = '';
                   2085:         }
                   2086:         current.argfield = choicearg;
                   2087:     }
                   2088:     set_auth_radio_buttons(choice,currentform);
                   2089:     return;
1.20      www      2090: }
1.32      matthew  2091: 
                   2092: function set_auth_radio_buttons(newvalue,currentform) {
                   2093:     var i=0;
                   2094:     while (i < currentform.login.length) {
                   2095:         if (currentform.login[i].value == newvalue) { break; }
                   2096:         i++;
                   2097:     }
                   2098:     if (i == currentform.login.length) {
                   2099:         return;
                   2100:     }
                   2101:     current.radiovalue = newvalue;
                   2102:     currentform.login[i].checked = true;
                   2103:     return;
                   2104: }
                   2105: END
                   2106:     return $result;
                   2107: }
                   2108: 
                   2109: sub authform_authorwarning{
                   2110:     my $result='';
1.144     matthew  2111:     $result='<i>'.
                   2112:         &mt('As a general rule, only authors or co-authors should be '.
                   2113:             'filesystem authenticated '.
                   2114:             '(which allows access to the server filesystem).')."</i>\n";
1.32      matthew  2115:     return $result;
                   2116: }
                   2117: 
                   2118: sub authform_nochange{  
                   2119:     my %in = (
                   2120:               formname => 'document.cu',
                   2121:               kerb_def_dom => 'MSU.EDU',
                   2122:               @_,
                   2123:           );
1.586     raeburn  2124:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'}); 
                   2125:     my $result;
                   2126:     if (keys(%can_assign) == 0) {
                   2127:         $result = &mt('Under you current role you are not permitted to change login settings for this user');  
                   2128:     } else {
                   2129:         $result = '<label>'.&mt('[_1] Do not change login data',
                   2130:                   '<input type="radio" name="login" value="nochange" '.
                   2131:                   'checked="checked" onclick="'.
1.281     albertel 2132:             "javascript:changed_radio('nochange',$in{'formname'});".'" />').
                   2133: 	    '</label>';
1.586     raeburn  2134:     }
1.32      matthew  2135:     return $result;
                   2136: }
                   2137: 
1.591     raeburn  2138: sub authform_kerberos {
1.32      matthew  2139:     my %in = (
                   2140:               formname => 'document.cu',
                   2141:               kerb_def_dom => 'MSU.EDU',
1.80      albertel 2142:               kerb_def_auth => 'krb4',
1.32      matthew  2143:               @_,
                   2144:               );
1.586     raeburn  2145:     my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
                   2146:         $autharg,$jscall);
                   2147:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.80      albertel 2148:     if ($in{'kerb_def_auth'} eq 'krb5') {
1.772     bisitz   2149:        $check5 = ' checked="checked"';
1.80      albertel 2150:     } else {
1.772     bisitz   2151:        $check4 = ' checked="checked"';
1.80      albertel 2152:     }
1.165     raeburn  2153:     $krbarg = $in{'kerb_def_dom'};
1.591     raeburn  2154:     if (defined($in{'curr_authtype'})) {
                   2155:         if ($in{'curr_authtype'} eq 'krb') {
1.772     bisitz   2156:             $krbcheck = ' checked="checked"';
1.623     raeburn  2157:             if (defined($in{'mode'})) {
                   2158:                 if ($in{'mode'} eq 'modifyuser') {
                   2159:                     $krbcheck = '';
                   2160:                 }
                   2161:             }
1.591     raeburn  2162:             if (defined($in{'curr_kerb_ver'})) {
                   2163:                 if ($in{'curr_krb_ver'} eq '5') {
1.772     bisitz   2164:                     $check5 = ' checked="checked"';
1.591     raeburn  2165:                     $check4 = '';
                   2166:                 } else {
1.772     bisitz   2167:                     $check4 = ' checked="checked"';
1.591     raeburn  2168:                     $check5 = '';
                   2169:                 }
1.586     raeburn  2170:             }
1.591     raeburn  2171:             if (defined($in{'curr_autharg'})) {
1.165     raeburn  2172:                 $krbarg = $in{'curr_autharg'};
                   2173:             }
1.586     raeburn  2174:             if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591     raeburn  2175:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2176:                     $result = 
                   2177:     &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
                   2178:         $in{'curr_autharg'},$krbver);
                   2179:                 } else {
                   2180:                     $result =
                   2181:     &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
                   2182:                 }
                   2183:                 return $result; 
                   2184:             }
                   2185:         }
                   2186:     } else {
                   2187:         if ($authnum == 1) {
1.784     bisitz   2188:             $authtype = '<input type="hidden" name="login" value="krb" />';
1.165     raeburn  2189:         }
                   2190:     }
1.586     raeburn  2191:     if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
                   2192:         return;
1.587     raeburn  2193:     } elsif ($authtype eq '') {
1.591     raeburn  2194:         if (defined($in{'mode'})) {
1.587     raeburn  2195:             if ($in{'mode'} eq 'modifycourse') {
                   2196:                 if ($authnum == 1) {
1.784     bisitz   2197:                     $authtype = '<input type="hidden" name="login" value="krb" />';
1.587     raeburn  2198:                 }
                   2199:             }
                   2200:         }
1.586     raeburn  2201:     }
                   2202:     $jscall = "javascript:changed_radio('krb',$in{'formname'});";
                   2203:     if ($authtype eq '') {
                   2204:         $authtype = '<input type="radio" name="login" value="krb" '.
                   2205:                     'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
                   2206:                     $krbcheck.' />';
                   2207:     }
                   2208:     if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
                   2209:         ($can_assign{'krb4'} && !$can_assign{'krb5'} && 
                   2210:          $in{'curr_authtype'} eq 'krb5') ||
                   2211:         (!$can_assign{'krb4'} && $can_assign{'krb5'} && 
                   2212:          $in{'curr_authtype'} eq 'krb4')) {
                   2213:         $result .= &mt
1.144     matthew  2214:         ('[_1] Kerberos authenticated with domain [_2] '.
1.281     albertel 2215:          '[_3] Version 4 [_4] Version 5 [_5]',
1.586     raeburn  2216:          '<label>'.$authtype,
1.281     albertel 2217:          '</label><input type="text" size="10" name="krbarg" '.
1.165     raeburn  2218:              'value="'.$krbarg.'" '.
1.144     matthew  2219:              'onchange="'.$jscall.'" />',
1.281     albertel 2220:          '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
                   2221:          '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
                   2222: 	 '</label>');
1.586     raeburn  2223:     } elsif ($can_assign{'krb4'}) {
                   2224:         $result .= &mt
                   2225:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2226:          '[_3] Version 4 [_4]',
                   2227:          '<label>'.$authtype,
                   2228:          '</label><input type="text" size="10" name="krbarg" '.
                   2229:              'value="'.$krbarg.'" '.
                   2230:              'onchange="'.$jscall.'" />',
                   2231:          '<label><input type="hidden" name="krbver" value="4" />',
                   2232:          '</label>');
                   2233:     } elsif ($can_assign{'krb5'}) {
                   2234:         $result .= &mt
                   2235:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2236:          '[_3] Version 5 [_4]',
                   2237:          '<label>'.$authtype,
                   2238:          '</label><input type="text" size="10" name="krbarg" '.
                   2239:              'value="'.$krbarg.'" '.
                   2240:              'onchange="'.$jscall.'" />',
                   2241:          '<label><input type="hidden" name="krbver" value="5" />',
                   2242:          '</label>');
                   2243:     }
1.32      matthew  2244:     return $result;
                   2245: }
                   2246: 
                   2247: sub authform_internal{  
1.586     raeburn  2248:     my %in = (
1.32      matthew  2249:                 formname => 'document.cu',
                   2250:                 kerb_def_dom => 'MSU.EDU',
                   2251:                 @_,
                   2252:                 );
1.586     raeburn  2253:     my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
                   2254:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2255:     if (defined($in{'curr_authtype'})) {
                   2256:         if ($in{'curr_authtype'} eq 'int') {
1.586     raeburn  2257:             if ($can_assign{'int'}) {
1.772     bisitz   2258:                 $intcheck = 'checked="checked" ';
1.623     raeburn  2259:                 if (defined($in{'mode'})) {
                   2260:                     if ($in{'mode'} eq 'modifyuser') {
                   2261:                         $intcheck = '';
                   2262:                     }
                   2263:                 }
1.591     raeburn  2264:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2265:                     $intarg = $in{'curr_autharg'};
                   2266:                 }
                   2267:             } else {
                   2268:                 $result = &mt('Currently internally authenticated.');
                   2269:                 return $result;
1.165     raeburn  2270:             }
                   2271:         }
1.586     raeburn  2272:     } else {
                   2273:         if ($authnum == 1) {
1.784     bisitz   2274:             $authtype = '<input type="hidden" name="login" value="int" />';
1.586     raeburn  2275:         }
                   2276:     }
                   2277:     if (!$can_assign{'int'}) {
                   2278:         return;
1.587     raeburn  2279:     } elsif ($authtype eq '') {
1.591     raeburn  2280:         if (defined($in{'mode'})) {
1.587     raeburn  2281:             if ($in{'mode'} eq 'modifycourse') {
                   2282:                 if ($authnum == 1) {
1.784     bisitz   2283:                     $authtype = '<input type="hidden" name="login" value="int" />';
1.587     raeburn  2284:                 }
                   2285:             }
                   2286:         }
1.165     raeburn  2287:     }
1.586     raeburn  2288:     $jscall = "javascript:changed_radio('int',$in{'formname'});";
                   2289:     if ($authtype eq '') {
                   2290:         $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
                   2291:                     ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
                   2292:     }
1.605     bisitz   2293:     $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586     raeburn  2294:                $intarg.'" onchange="'.$jscall.'" />';
                   2295:     $result = &mt
1.144     matthew  2296:         ('[_1] Internally authenticated (with initial password [_2])',
1.586     raeburn  2297:          '<label>'.$authtype,'</label>'.$autharg);
1.620     www      2298:     $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  2299:     return $result;
                   2300: }
                   2301: 
                   2302: sub authform_local{  
                   2303:     my %in = (
                   2304:               formname => 'document.cu',
                   2305:               kerb_def_dom => 'MSU.EDU',
                   2306:               @_,
                   2307:               );
1.586     raeburn  2308:     my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
                   2309:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2310:     if (defined($in{'curr_authtype'})) {
                   2311:         if ($in{'curr_authtype'} eq 'loc') {
1.586     raeburn  2312:             if ($can_assign{'loc'}) {
1.772     bisitz   2313:                 $loccheck = 'checked="checked" ';
1.623     raeburn  2314:                 if (defined($in{'mode'})) {
                   2315:                     if ($in{'mode'} eq 'modifyuser') {
                   2316:                         $loccheck = '';
                   2317:                     }
                   2318:                 }
1.591     raeburn  2319:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2320:                     $locarg = $in{'curr_autharg'};
                   2321:                 }
                   2322:             } else {
                   2323:                 $result = &mt('Currently using local (institutional) authentication.');
                   2324:                 return $result;
1.165     raeburn  2325:             }
                   2326:         }
1.586     raeburn  2327:     } else {
                   2328:         if ($authnum == 1) {
1.784     bisitz   2329:             $authtype = '<input type="hidden" name="login" value="loc" />';
1.586     raeburn  2330:         }
                   2331:     }
                   2332:     if (!$can_assign{'loc'}) {
                   2333:         return;
1.587     raeburn  2334:     } elsif ($authtype eq '') {
1.591     raeburn  2335:         if (defined($in{'mode'})) {
1.587     raeburn  2336:             if ($in{'mode'} eq 'modifycourse') {
                   2337:                 if ($authnum == 1) {
1.784     bisitz   2338:                     $authtype = '<input type="hidden" name="login" value="loc" />';
1.587     raeburn  2339:                 }
                   2340:             }
                   2341:         }
1.165     raeburn  2342:     }
1.586     raeburn  2343:     $jscall = "javascript:changed_radio('loc',$in{'formname'});";
                   2344:     if ($authtype eq '') {
                   2345:         $authtype = '<input type="radio" name="login" value="loc" '.
                   2346:                     $loccheck.' onchange="'.$jscall.'" onclick="'.
                   2347:                     $jscall.'" />';
                   2348:     }
                   2349:     $autharg = '<input type="text" size="10" name="locarg" value="'.
                   2350:                $locarg.'" onchange="'.$jscall.'" />';
                   2351:     $result = &mt('[_1] Local Authentication with argument [_2]',
                   2352:                   '<label>'.$authtype,'</label>'.$autharg);
1.32      matthew  2353:     return $result;
                   2354: }
                   2355: 
                   2356: sub authform_filesystem{  
                   2357:     my %in = (
                   2358:               formname => 'document.cu',
                   2359:               kerb_def_dom => 'MSU.EDU',
                   2360:               @_,
                   2361:               );
1.586     raeburn  2362:     my ($fsyscheck,$result,$authtype,$autharg,$jscall);
                   2363:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2364:     if (defined($in{'curr_authtype'})) {
                   2365:         if ($in{'curr_authtype'} eq 'fsys') {
1.586     raeburn  2366:             if ($can_assign{'fsys'}) {
1.772     bisitz   2367:                 $fsyscheck = 'checked="checked" ';
1.623     raeburn  2368:                 if (defined($in{'mode'})) {
                   2369:                     if ($in{'mode'} eq 'modifyuser') {
                   2370:                         $fsyscheck = '';
                   2371:                     }
                   2372:                 }
1.586     raeburn  2373:             } else {
                   2374:                 $result = &mt('Currently Filesystem Authenticated.');
                   2375:                 return $result;
                   2376:             }           
                   2377:         }
                   2378:     } else {
                   2379:         if ($authnum == 1) {
1.784     bisitz   2380:             $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586     raeburn  2381:         }
                   2382:     }
                   2383:     if (!$can_assign{'fsys'}) {
                   2384:         return;
1.587     raeburn  2385:     } elsif ($authtype eq '') {
1.591     raeburn  2386:         if (defined($in{'mode'})) {
1.587     raeburn  2387:             if ($in{'mode'} eq 'modifycourse') {
                   2388:                 if ($authnum == 1) {
1.784     bisitz   2389:                     $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587     raeburn  2390:                 }
                   2391:             }
                   2392:         }
1.586     raeburn  2393:     }
                   2394:     $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
                   2395:     if ($authtype eq '') {
                   2396:         $authtype = '<input type="radio" name="login" value="fsys" '.
                   2397:                     $fsyscheck.' onchange="'.$jscall.'" onclick="'.
                   2398:                     $jscall.'" />';
                   2399:     }
                   2400:     $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
                   2401:                ' onchange="'.$jscall.'" />';
                   2402:     $result = &mt
1.144     matthew  2403:         ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281     albertel 2404:          '<label><input type="radio" name="login" value="fsys" '.
1.586     raeburn  2405:          $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605     bisitz   2406:          '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144     matthew  2407:                   'onchange="'.$jscall.'" />');
1.32      matthew  2408:     return $result;
                   2409: }
                   2410: 
1.586     raeburn  2411: sub get_assignable_auth {
                   2412:     my ($dom) = @_;
                   2413:     if ($dom eq '') {
                   2414:         $dom = $env{'request.role.domain'};
                   2415:     }
                   2416:     my %can_assign = (
                   2417:                           krb4 => 1,
                   2418:                           krb5 => 1,
                   2419:                           int  => 1,
                   2420:                           loc  => 1,
                   2421:                      );
                   2422:     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
                   2423:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   2424:         if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
                   2425:             my $authhash = $domconfig{'usercreation'}{'authtypes'};
                   2426:             my $context;
                   2427:             if ($env{'request.role'} =~ /^au/) {
                   2428:                 $context = 'author';
                   2429:             } elsif ($env{'request.role'} =~ /^dc/) {
                   2430:                 $context = 'domain';
                   2431:             } elsif ($env{'request.course.id'}) {
                   2432:                 $context = 'course';
                   2433:             }
                   2434:             if ($context) {
                   2435:                 if (ref($authhash->{$context}) eq 'HASH') {
                   2436:                    %can_assign = %{$authhash->{$context}}; 
                   2437:                 }
                   2438:             }
                   2439:         }
                   2440:     }
                   2441:     my $authnum = 0;
                   2442:     foreach my $key (keys(%can_assign)) {
                   2443:         if ($can_assign{$key}) {
                   2444:             $authnum ++;
                   2445:         }
                   2446:     }
                   2447:     if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
                   2448:         $authnum --;
                   2449:     }
                   2450:     return ($authnum,%can_assign);
                   2451: }
                   2452: 
1.80      albertel 2453: ###############################################################
                   2454: ##    Get Kerberos Defaults for Domain                 ##
                   2455: ###############################################################
                   2456: ##
                   2457: ## Returns default kerberos version and an associated argument
                   2458: ## as listed in file domain.tab. If not listed, provides
                   2459: ## appropriate default domain and kerberos version.
                   2460: ##
                   2461: #-------------------------------------------
                   2462: 
                   2463: =pod
                   2464: 
1.648     raeburn  2465: =item * &get_kerberos_defaults()
1.80      albertel 2466: 
                   2467: get_kerberos_defaults($target_domain) returns the default kerberos
1.641     raeburn  2468: version and domain. If not found, it defaults to version 4 and the 
                   2469: domain of the server.
1.80      albertel 2470: 
1.648     raeburn  2471: =over 4
                   2472: 
1.80      albertel 2473: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
                   2474: 
1.648     raeburn  2475: =back
                   2476: 
                   2477: =back
                   2478: 
1.80      albertel 2479: =cut
                   2480: 
                   2481: #-------------------------------------------
                   2482: sub get_kerberos_defaults {
                   2483:     my $domain=shift;
1.641     raeburn  2484:     my ($krbdef,$krbdefdom);
                   2485:     my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
                   2486:     if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
                   2487:         $krbdef = $domdefaults{'auth_def'};
                   2488:         $krbdefdom = $domdefaults{'auth_arg_def'};
                   2489:     } else {
1.80      albertel 2490:         $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
                   2491:         my $krbdefdom=$1;
                   2492:         $krbdefdom=~tr/a-z/A-Z/;
                   2493:         $krbdef = "krb4";
                   2494:     }
                   2495:     return ($krbdef,$krbdefdom);
                   2496: }
1.112     bowersj2 2497: 
1.32      matthew  2498: 
1.46      matthew  2499: ###############################################################
                   2500: ##                Thesaurus Functions                        ##
                   2501: ###############################################################
1.20      www      2502: 
1.46      matthew  2503: =pod
1.20      www      2504: 
1.112     bowersj2 2505: =head1 Thesaurus Functions
                   2506: 
                   2507: =over 4
                   2508: 
1.648     raeburn  2509: =item * &initialize_keywords()
1.46      matthew  2510: 
                   2511: Initializes the package variable %Keywords if it is empty.  Uses the
                   2512: package variable $thesaurus_db_file.
                   2513: 
                   2514: =cut
                   2515: 
                   2516: ###################################################
                   2517: 
                   2518: sub initialize_keywords {
                   2519:     return 1 if (scalar keys(%Keywords));
                   2520:     # If we are here, %Keywords is empty, so fill it up
                   2521:     #   Make sure the file we need exists...
                   2522:     if (! -e $thesaurus_db_file) {
                   2523:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
                   2524:                                  " failed because it does not exist");
                   2525:         return 0;
                   2526:     }
                   2527:     #   Set up the hash as a database
                   2528:     my %thesaurus_db;
                   2529:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2530:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2531:         &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
                   2532:                                  $thesaurus_db_file);
                   2533:         return 0;
                   2534:     } 
                   2535:     #  Get the average number of appearances of a word.
                   2536:     my $avecount = $thesaurus_db{'average.count'};
                   2537:     #  Put keywords (those that appear > average) into %Keywords
                   2538:     while (my ($word,$data)=each (%thesaurus_db)) {
                   2539:         my ($count,undef) = split /:/,$data;
                   2540:         $Keywords{$word}++ if ($count > $avecount);
                   2541:     }
                   2542:     untie %thesaurus_db;
                   2543:     # Remove special values from %Keywords.
1.356     albertel 2544:     foreach my $value ('total.count','average.count') {
                   2545:         delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586     raeburn  2546:   }
1.46      matthew  2547:     return 1;
                   2548: }
                   2549: 
                   2550: ###################################################
                   2551: 
                   2552: =pod
                   2553: 
1.648     raeburn  2554: =item * &keyword($word)
1.46      matthew  2555: 
                   2556: Returns true if $word is a keyword.  A keyword is a word that appears more 
                   2557: than the average number of times in the thesaurus database.  Calls 
                   2558: &initialize_keywords
                   2559: 
                   2560: =cut
                   2561: 
                   2562: ###################################################
1.20      www      2563: 
                   2564: sub keyword {
1.46      matthew  2565:     return if (!&initialize_keywords());
                   2566:     my $word=lc(shift());
                   2567:     $word=~s/\W//g;
                   2568:     return exists($Keywords{$word});
1.20      www      2569: }
1.46      matthew  2570: 
                   2571: ###############################################################
                   2572: 
                   2573: =pod 
1.20      www      2574: 
1.648     raeburn  2575: =item * &get_related_words()
1.46      matthew  2576: 
1.160     matthew  2577: Look up a word in the thesaurus.  Takes a scalar argument and returns
1.46      matthew  2578: an array of words.  If the keyword is not in the thesaurus, an empty array
                   2579: will be returned.  The order of the words returned is determined by the
                   2580: database which holds them.
                   2581: 
                   2582: Uses global $thesaurus_db_file.
                   2583: 
                   2584: =cut
                   2585: 
                   2586: ###############################################################
                   2587: sub get_related_words {
                   2588:     my $keyword = shift;
                   2589:     my %thesaurus_db;
                   2590:     if (! -e $thesaurus_db_file) {
                   2591:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
                   2592:                                  "failed because the file does not exist");
                   2593:         return ();
                   2594:     }
                   2595:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2596:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2597:         return ();
                   2598:     } 
                   2599:     my @Words=();
1.429     www      2600:     my $count=0;
1.46      matthew  2601:     if (exists($thesaurus_db{$keyword})) {
1.356     albertel 2602: 	# The first element is the number of times
                   2603: 	# the word appears.  We do not need it now.
1.429     www      2604: 	my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
                   2605: 	my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
                   2606: 	my $threshold=$mostfrequentcount/10;
                   2607:         foreach my $possibleword (@RelatedWords) {
                   2608:             my ($word,$wordcount)=split(/\,/,$possibleword);
                   2609:             if ($wordcount>$threshold) {
                   2610: 		push(@Words,$word);
                   2611:                 $count++;
                   2612:                 if ($count>10) { last; }
                   2613: 	    }
1.20      www      2614:         }
                   2615:     }
1.46      matthew  2616:     untie %thesaurus_db;
                   2617:     return @Words;
1.14      harris41 2618: }
1.46      matthew  2619: 
1.112     bowersj2 2620: =pod
                   2621: 
                   2622: =back
                   2623: 
                   2624: =cut
1.61      www      2625: 
                   2626: # -------------------------------------------------------------- Plaintext name
1.81      albertel 2627: =pod
                   2628: 
1.112     bowersj2 2629: =head1 User Name Functions
                   2630: 
                   2631: =over 4
                   2632: 
1.648     raeburn  2633: =item * &plainname($uname,$udom,$first)
1.81      albertel 2634: 
1.112     bowersj2 2635: Takes a users logon name and returns it as a string in
1.226     albertel 2636: "first middle last generation" form 
                   2637: if $first is set to 'lastname' then it returns it as
                   2638: 'lastname generation, firstname middlename' if their is a lastname
1.81      albertel 2639: 
                   2640: =cut
1.61      www      2641: 
1.295     www      2642: 
1.81      albertel 2643: ###############################################################
1.61      www      2644: sub plainname {
1.226     albertel 2645:     my ($uname,$udom,$first)=@_;
1.537     albertel 2646:     return if (!defined($uname) || !defined($udom));
1.295     www      2647:     my %names=&getnames($uname,$udom);
1.226     albertel 2648:     my $name=&Apache::lonnet::format_name($names{'firstname'},
                   2649: 					  $names{'middlename'},
                   2650: 					  $names{'lastname'},
                   2651: 					  $names{'generation'},$first);
                   2652:     $name=~s/^\s+//;
1.62      www      2653:     $name=~s/\s+$//;
                   2654:     $name=~s/\s+/ /g;
1.353     albertel 2655:     if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62      www      2656:     return $name;
1.61      www      2657: }
1.66      www      2658: 
                   2659: # -------------------------------------------------------------------- Nickname
1.81      albertel 2660: =pod
                   2661: 
1.648     raeburn  2662: =item * &nickname($uname,$udom)
1.81      albertel 2663: 
                   2664: Gets a users name and returns it as a string as
                   2665: 
                   2666: "&quot;nickname&quot;"
1.66      www      2667: 
1.81      albertel 2668: if the user has a nickname or
                   2669: 
                   2670: "first middle last generation"
                   2671: 
                   2672: if the user does not
                   2673: 
                   2674: =cut
1.66      www      2675: 
                   2676: sub nickname {
                   2677:     my ($uname,$udom)=@_;
1.537     albertel 2678:     return if (!defined($uname) || !defined($udom));
1.295     www      2679:     my %names=&getnames($uname,$udom);
1.68      albertel 2680:     my $name=$names{'nickname'};
1.66      www      2681:     if ($name) {
                   2682:        $name='&quot;'.$name.'&quot;'; 
                   2683:     } else {
                   2684:        $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
                   2685: 	     $names{'lastname'}.' '.$names{'generation'};
                   2686:        $name=~s/\s+$//;
                   2687:        $name=~s/\s+/ /g;
                   2688:     }
                   2689:     return $name;
                   2690: }
                   2691: 
1.295     www      2692: sub getnames {
                   2693:     my ($uname,$udom)=@_;
1.537     albertel 2694:     return if (!defined($uname) || !defined($udom));
1.433     albertel 2695:     if ($udom eq 'public' && $uname eq 'public') {
                   2696: 	return ('lastname' => &mt('Public'));
                   2697:     }
1.295     www      2698:     my $id=$uname.':'.$udom;
                   2699:     my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
                   2700:     if ($cached) {
                   2701: 	return %{$names};
                   2702:     } else {
                   2703: 	my %loadnames=&Apache::lonnet::get('environment',
                   2704:                     ['firstname','middlename','lastname','generation','nickname'],
                   2705: 					 $udom,$uname);
                   2706: 	&Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
                   2707: 	return %loadnames;
                   2708:     }
                   2709: }
1.61      www      2710: 
1.542     raeburn  2711: # -------------------------------------------------------------------- getemails
1.648     raeburn  2712: 
1.542     raeburn  2713: =pod
                   2714: 
1.648     raeburn  2715: =item * &getemails($uname,$udom)
1.542     raeburn  2716: 
                   2717: Gets a user's email information and returns it as a hash with keys:
                   2718: notification, critnotification, permanentemail
                   2719: 
                   2720: For notification and critnotification, values are comma-separated lists 
1.648     raeburn  2721: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542     raeburn  2722:  
1.648     raeburn  2723: 
1.542     raeburn  2724: =cut
                   2725: 
1.648     raeburn  2726: 
1.466     albertel 2727: sub getemails {
                   2728:     my ($uname,$udom)=@_;
                   2729:     if ($udom eq 'public' && $uname eq 'public') {
                   2730: 	return;
                   2731:     }
1.467     www      2732:     if (!$udom) { $udom=$env{'user.domain'}; }
                   2733:     if (!$uname) { $uname=$env{'user.name'}; }
1.466     albertel 2734:     my $id=$uname.':'.$udom;
                   2735:     my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
                   2736:     if ($cached) {
                   2737: 	return %{$names};
                   2738:     } else {
                   2739: 	my %loadnames=&Apache::lonnet::get('environment',
                   2740:                     			   ['notification','critnotification',
                   2741: 					    'permanentemail'],
                   2742: 					   $udom,$uname);
                   2743: 	&Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
                   2744: 	return %loadnames;
                   2745:     }
                   2746: }
                   2747: 
1.551     albertel 2748: sub flush_email_cache {
                   2749:     my ($uname,$udom)=@_;
                   2750:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2751:     if (!$uname) { $uname=$env{'user.name'};   }
                   2752:     return if ($udom eq 'public' && $uname eq 'public');
                   2753:     my $id=$uname.':'.$udom;
                   2754:     &Apache::lonnet::devalidate_cache_new('emailscache',$id);
                   2755: }
                   2756: 
1.728     raeburn  2757: # -------------------------------------------------------------------- getlangs
                   2758: 
                   2759: =pod
                   2760: 
                   2761: =item * &getlangs($uname,$udom)
                   2762: 
                   2763: Gets a user's language preference and returns it as a hash with key:
                   2764: language.
                   2765: 
                   2766: =cut
                   2767: 
                   2768: 
                   2769: sub getlangs {
                   2770:     my ($uname,$udom) = @_;
                   2771:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2772:     if (!$uname) { $uname=$env{'user.name'};   }
                   2773:     my $id=$uname.':'.$udom;
                   2774:     my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
                   2775:     if ($cached) {
                   2776:         return %{$langs};
                   2777:     } else {
                   2778:         my %loadlangs=&Apache::lonnet::get('environment',['languages'],
                   2779:                                            $udom,$uname);
                   2780:         &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
                   2781:         return %loadlangs;
                   2782:     }
                   2783: }
                   2784: 
                   2785: sub flush_langs_cache {
                   2786:     my ($uname,$udom)=@_;
                   2787:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2788:     if (!$uname) { $uname=$env{'user.name'};   }
                   2789:     return if ($udom eq 'public' && $uname eq 'public');
                   2790:     my $id=$uname.':'.$udom;
                   2791:     &Apache::lonnet::devalidate_cache_new('userlangs',$id);
                   2792: }
                   2793: 
1.61      www      2794: # ------------------------------------------------------------------ Screenname
1.81      albertel 2795: 
                   2796: =pod
                   2797: 
1.648     raeburn  2798: =item * &screenname($uname,$udom)
1.81      albertel 2799: 
                   2800: Gets a users screenname and returns it as a string
                   2801: 
                   2802: =cut
1.61      www      2803: 
                   2804: sub screenname {
                   2805:     my ($uname,$udom)=@_;
1.258     albertel 2806:     if ($uname eq $env{'user.name'} &&
                   2807: 	$udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212     albertel 2808:     my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68      albertel 2809:     return $names{'screenname'};
1.62      www      2810: }
                   2811: 
1.212     albertel 2812: 
1.62      www      2813: # ------------------------------------------------------------- Message Wrapper
                   2814: 
                   2815: sub messagewrapper {
1.369     www      2816:     my ($link,$username,$domain,$subject,$text)=@_;
1.62      www      2817:     return 
1.441     albertel 2818:         '<a href="/adm/email?compose=individual&amp;'.
                   2819:         'recname='.$username.'&amp;recdom='.$domain.
                   2820: 	'&amp;subject='.&escape($subject).'&amp;text='.&escape($text).'" '.
1.200     matthew  2821:         'title="'.&mt('Send message').'">'.$link.'</a>';
1.74      www      2822: }
                   2823: # --------------------------------------------------------------- Notes Wrapper
                   2824: 
                   2825: sub noteswrapper {
                   2826:     my ($link,$un,$do)=@_;
                   2827:     return 
                   2828: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62      www      2829: }
                   2830: # ------------------------------------------------------------- Aboutme Wrapper
                   2831: 
                   2832: sub aboutmewrapper {
1.166     www      2833:     my ($link,$username,$domain,$target)=@_;
1.447     raeburn  2834:     if (!defined($username)  && !defined($domain)) {
                   2835:         return;
                   2836:     }
1.205     www      2837:     return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.756     weissno  2838: 	($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62      www      2839: }
                   2840: 
                   2841: # ------------------------------------------------------------ Syllabus Wrapper
                   2842: 
                   2843: 
                   2844: sub syllabuswrapper {
1.707     bisitz   2845:     my ($linktext,$coursedir,$domain)=@_;
1.208     matthew  2846:     return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61      www      2847: }
1.14      harris41 2848: 
1.208     matthew  2849: sub track_student_link {
1.268     albertel 2850:     my ($linktext,$sname,$sdom,$target,$start) = @_;
                   2851:     my $link ="/adm/trackstudent?";
1.208     matthew  2852:     my $title = 'View recent activity';
                   2853:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   2854:         defined($sdom)  && $sdom  !~ /^\s*$/) {
1.268     albertel 2855:         $link .= "selected_student=$sname:$sdom";
1.208     matthew  2856:         $title .= ' of this student';
1.268     albertel 2857:     } 
1.208     matthew  2858:     if (defined($target) && $target !~ /^\s*$/) {
                   2859:         $target = qq{target="$target"};
                   2860:     } else {
                   2861:         $target = '';
                   2862:     }
1.268     albertel 2863:     if ($start) { $link.='&amp;start='.$start; }
1.554     albertel 2864:     $title = &mt($title);
                   2865:     $linktext = &mt($linktext);
1.448     albertel 2866:     return qq{<a href="$link" title="$title" $target>$linktext</a>}.
                   2867: 	&help_open_topic('View_recent_activity');
1.208     matthew  2868: }
                   2869: 
1.781     raeburn  2870: sub slot_reservations_link {
                   2871:     my ($linktext,$sname,$sdom,$target) = @_;
                   2872:     my $link ="/adm/slotrequest?command=showresv&amp;origin=aboutme";
                   2873:     my $title = 'View slot reservation history';
                   2874:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   2875:         defined($sdom)  && $sdom  !~ /^\s*$/) {
                   2876:         $link .= "&amp;uname=$sname&amp;udom=$sdom";
                   2877:         $title .= ' of this student';
                   2878:     }
                   2879:     if (defined($target) && $target !~ /^\s*$/) {
                   2880:         $target = qq{target="$target"};
                   2881:     } else {
                   2882:         $target = '';
                   2883:     }
                   2884:     $title = &mt($title);
                   2885:     $linktext = &mt($linktext);
                   2886:     return qq{<a href="$link" title="$title" $target>$linktext</a>};
                   2887: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
                   2888: 
                   2889: }
                   2890: 
1.508     www      2891: # ===================================================== Display a student photo
                   2892: 
                   2893: 
1.509     albertel 2894: sub student_image_tag {
1.508     www      2895:     my ($domain,$user)=@_;
                   2896:     my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
                   2897:     if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
                   2898: 	return '<img src="'.$imgsrc.'" align="right" />';
                   2899:     } else {
                   2900: 	return '';
                   2901:     }
                   2902: }
                   2903: 
1.112     bowersj2 2904: =pod
                   2905: 
                   2906: =back
                   2907: 
                   2908: =head1 Access .tab File Data
                   2909: 
                   2910: =over 4
                   2911: 
1.648     raeburn  2912: =item * &languageids() 
1.112     bowersj2 2913: 
                   2914: returns list of all language ids
                   2915: 
                   2916: =cut
                   2917: 
1.14      harris41 2918: sub languageids {
1.16      harris41 2919:     return sort(keys(%language));
1.14      harris41 2920: }
                   2921: 
1.112     bowersj2 2922: =pod
                   2923: 
1.648     raeburn  2924: =item * &languagedescription() 
1.112     bowersj2 2925: 
                   2926: returns description of a specified language id
                   2927: 
                   2928: =cut
                   2929: 
1.14      harris41 2930: sub languagedescription {
1.125     www      2931:     my $code=shift;
                   2932:     return  ($supported_language{$code}?'* ':'').
                   2933:             $language{$code}.
1.126     www      2934: 	    ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145     www      2935: }
                   2936: 
                   2937: sub plainlanguagedescription {
                   2938:     my $code=shift;
                   2939:     return $language{$code};
                   2940: }
                   2941: 
                   2942: sub supportedlanguagecode {
                   2943:     my $code=shift;
                   2944:     return $supported_language{$code};
1.97      www      2945: }
                   2946: 
1.112     bowersj2 2947: =pod
                   2948: 
1.648     raeburn  2949: =item * &copyrightids() 
1.112     bowersj2 2950: 
                   2951: returns list of all copyrights
                   2952: 
                   2953: =cut
                   2954: 
                   2955: sub copyrightids {
                   2956:     return sort(keys(%cprtag));
                   2957: }
                   2958: 
                   2959: =pod
                   2960: 
1.648     raeburn  2961: =item * &copyrightdescription() 
1.112     bowersj2 2962: 
                   2963: returns description of a specified copyright id
                   2964: 
                   2965: =cut
                   2966: 
                   2967: sub copyrightdescription {
1.166     www      2968:     return &mt($cprtag{shift(@_)});
1.112     bowersj2 2969: }
1.197     matthew  2970: 
                   2971: =pod
                   2972: 
1.648     raeburn  2973: =item * &source_copyrightids() 
1.192     taceyjo1 2974: 
                   2975: returns list of all source copyrights
                   2976: 
                   2977: =cut
                   2978: 
                   2979: sub source_copyrightids {
                   2980:     return sort(keys(%scprtag));
                   2981: }
                   2982: 
                   2983: =pod
                   2984: 
1.648     raeburn  2985: =item * &source_copyrightdescription() 
1.192     taceyjo1 2986: 
                   2987: returns description of a specified source copyright id
                   2988: 
                   2989: =cut
                   2990: 
                   2991: sub source_copyrightdescription {
                   2992:     return &mt($scprtag{shift(@_)});
                   2993: }
1.112     bowersj2 2994: 
                   2995: =pod
                   2996: 
1.648     raeburn  2997: =item * &filecategories() 
1.112     bowersj2 2998: 
                   2999: returns list of all file categories
                   3000: 
                   3001: =cut
                   3002: 
                   3003: sub filecategories {
                   3004:     return sort(keys(%category_extensions));
                   3005: }
                   3006: 
                   3007: =pod
                   3008: 
1.648     raeburn  3009: =item * &filecategorytypes() 
1.112     bowersj2 3010: 
                   3011: returns list of file types belonging to a given file
                   3012: category
                   3013: 
                   3014: =cut
                   3015: 
                   3016: sub filecategorytypes {
1.356     albertel 3017:     my ($cat) = @_;
                   3018:     return @{$category_extensions{lc($cat)}};
1.112     bowersj2 3019: }
                   3020: 
                   3021: =pod
                   3022: 
1.648     raeburn  3023: =item * &fileembstyle() 
1.112     bowersj2 3024: 
                   3025: returns embedding style for a specified file type
                   3026: 
                   3027: =cut
                   3028: 
                   3029: sub fileembstyle {
                   3030:     return $fe{lc(shift(@_))};
1.169     www      3031: }
                   3032: 
1.351     www      3033: sub filemimetype {
                   3034:     return $fm{lc(shift(@_))};
                   3035: }
                   3036: 
1.169     www      3037: 
                   3038: sub filecategoryselect {
                   3039:     my ($name,$value)=@_;
1.189     matthew  3040:     return &select_form($value,$name,
1.169     www      3041: 			'' => &mt('Any category'),
                   3042: 			map { $_,$_ } sort(keys(%category_extensions)));
1.112     bowersj2 3043: }
                   3044: 
                   3045: =pod
                   3046: 
1.648     raeburn  3047: =item * &filedescription() 
1.112     bowersj2 3048: 
                   3049: returns description for a specified file type
                   3050: 
                   3051: =cut
                   3052: 
                   3053: sub filedescription {
1.188     matthew  3054:     my $file_description = $fd{lc(shift())};
                   3055:     $file_description =~ s:([\[\]]):~$1:g;
                   3056:     return &mt($file_description);
1.112     bowersj2 3057: }
                   3058: 
                   3059: =pod
                   3060: 
1.648     raeburn  3061: =item * &filedescriptionex() 
1.112     bowersj2 3062: 
                   3063: returns description for a specified file type with
                   3064: extra formatting
                   3065: 
                   3066: =cut
                   3067: 
                   3068: sub filedescriptionex {
                   3069:     my $ex=shift;
1.188     matthew  3070:     my $file_description = $fd{lc($ex)};
                   3071:     $file_description =~ s:([\[\]]):~$1:g;
                   3072:     return '.'.$ex.' '.&mt($file_description);
1.112     bowersj2 3073: }
                   3074: 
                   3075: # End of .tab access
                   3076: =pod
                   3077: 
                   3078: =back
                   3079: 
                   3080: =cut
                   3081: 
                   3082: # ------------------------------------------------------------------ File Types
                   3083: sub fileextensions {
                   3084:     return sort(keys(%fe));
                   3085: }
                   3086: 
1.97      www      3087: # ----------------------------------------------------------- Display Languages
                   3088: # returns a hash with all desired display languages
                   3089: #
                   3090: 
                   3091: sub display_languages {
                   3092:     my %languages=();
1.695     raeburn  3093:     foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356     albertel 3094: 	$languages{$lang}=1;
1.97      www      3095:     }
                   3096:     &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258     albertel 3097:     if ($env{'form.displaylanguage'}) {
1.356     albertel 3098: 	foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
                   3099: 	    $languages{$lang}=1;
1.97      www      3100:         }
                   3101:     }
                   3102:     return %languages;
1.14      harris41 3103: }
                   3104: 
1.582     albertel 3105: sub languages {
                   3106:     my ($possible_langs) = @_;
1.695     raeburn  3107:     my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582     albertel 3108:     if (!ref($possible_langs)) {
                   3109: 	if( wantarray ) {
                   3110: 	    return @preferred_langs;
                   3111: 	} else {
                   3112: 	    return $preferred_langs[0];
                   3113: 	}
                   3114:     }
                   3115:     my %possibilities = map { $_ => 1 } (@$possible_langs);
                   3116:     my @preferred_possibilities;
                   3117:     foreach my $preferred_lang (@preferred_langs) {
                   3118: 	if (exists($possibilities{$preferred_lang})) {
                   3119: 	    push(@preferred_possibilities, $preferred_lang);
                   3120: 	}
                   3121:     }
                   3122:     if( wantarray ) {
                   3123: 	return @preferred_possibilities;
                   3124:     }
                   3125:     return $preferred_possibilities[0];
                   3126: }
                   3127: 
1.742     raeburn  3128: sub user_lang {
                   3129:     my ($touname,$toudom,$fromcid) = @_;
                   3130:     my @userlangs;
                   3131:     if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
                   3132:         @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
                   3133:                     $env{'course.'.$fromcid.'.languages'}));
                   3134:     } else {
                   3135:         my %langhash = &getlangs($touname,$toudom);
                   3136:         if ($langhash{'languages'} ne '') {
                   3137:             @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
                   3138:         } else {
                   3139:             my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
                   3140:             if ($domdefs{'lang_def'} ne '') {
                   3141:                 @userlangs = ($domdefs{'lang_def'});
                   3142:             }
                   3143:         }
                   3144:     }
                   3145:     my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
                   3146:     my $user_lh = Apache::localize->get_handle(@languages);
                   3147:     return $user_lh;
                   3148: }
                   3149: 
                   3150: 
1.112     bowersj2 3151: ###############################################################
                   3152: ##               Student Answer Attempts                     ##
                   3153: ###############################################################
                   3154: 
                   3155: =pod
                   3156: 
                   3157: =head1 Alternate Problem Views
                   3158: 
                   3159: =over 4
                   3160: 
1.648     raeburn  3161: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112     bowersj2 3162:     $getattempt, $regexp, $gradesub)
                   3163: 
                   3164: Return string with previous attempt on problem. Arguments:
                   3165: 
                   3166: =over 4
                   3167: 
                   3168: =item * $symb: Problem, including path
                   3169: 
                   3170: =item * $username: username of the desired student
                   3171: 
                   3172: =item * $domain: domain of the desired student
1.14      harris41 3173: 
1.112     bowersj2 3174: =item * $course: Course ID
1.14      harris41 3175: 
1.112     bowersj2 3176: =item * $getattempt: Leave blank for all attempts, otherwise put
                   3177:     something
1.14      harris41 3178: 
1.112     bowersj2 3179: =item * $regexp: if string matches this regexp, the string will be
                   3180:     sent to $gradesub
1.14      harris41 3181: 
1.112     bowersj2 3182: =item * $gradesub: routine that processes the string if it matches $regexp
1.14      harris41 3183: 
1.112     bowersj2 3184: =back
1.14      harris41 3185: 
1.112     bowersj2 3186: The output string is a table containing all desired attempts, if any.
1.16      harris41 3187: 
1.112     bowersj2 3188: =cut
1.1       albertel 3189: 
                   3190: sub get_previous_attempt {
1.43      ng       3191:   my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1       albertel 3192:   my $prevattempts='';
1.43      ng       3193:   no strict 'refs';
1.1       albertel 3194:   if ($symb) {
1.3       albertel 3195:     my (%returnhash)=
                   3196:       &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1       albertel 3197:     if ($returnhash{'version'}) {
                   3198:       my %lasthash=();
                   3199:       my $version;
                   3200:       for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356     albertel 3201:         foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
                   3202: 	  $lasthash{$key}=$returnhash{$version.':'.$key};
1.19      harris41 3203:         }
1.1       albertel 3204:       }
1.596     albertel 3205:       $prevattempts=&start_data_table().&start_data_table_header_row();
                   3206:       $prevattempts.='<th>'.&mt('History').'</th>';
1.356     albertel 3207:       foreach my $key (sort(keys(%lasthash))) {
                   3208: 	my ($ign,@parts) = split(/\./,$key);
1.41      ng       3209: 	if ($#parts > 0) {
1.31      albertel 3210: 	  my $data=$parts[-1];
                   3211: 	  pop(@parts);
1.596     albertel 3212: 	  $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.'&nbsp;</th>';
1.31      albertel 3213: 	} else {
1.41      ng       3214: 	  if ($#parts == 0) {
                   3215: 	    $prevattempts.='<th>'.$parts[0].'</th>';
                   3216: 	  } else {
                   3217: 	    $prevattempts.='<th>'.$ign.'</th>';
                   3218: 	  }
1.31      albertel 3219: 	}
1.16      harris41 3220:       }
1.596     albertel 3221:       $prevattempts.=&end_data_table_header_row();
1.40      ng       3222:       if ($getattempt eq '') {
                   3223: 	for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596     albertel 3224: 	  $prevattempts.=&start_data_table_row().
                   3225: 	      '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356     albertel 3226: 	    foreach my $key (sort(keys(%lasthash))) {
1.581     albertel 3227: 		my $value = &format_previous_attempt_value($key,
                   3228: 							   $returnhash{$version.':'.$key});
                   3229: 		$prevattempts.='<td>'.$value.'&nbsp;</td>';   
1.40      ng       3230: 	    }
1.596     albertel 3231: 	  $prevattempts.=&end_data_table_row();
1.40      ng       3232: 	 }
1.1       albertel 3233:       }
1.596     albertel 3234:       $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356     albertel 3235:       foreach my $key (sort(keys(%lasthash))) {
1.581     albertel 3236: 	my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356     albertel 3237: 	if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40      ng       3238: 	$prevattempts.='<td>'.$value.'&nbsp;</td>';
1.16      harris41 3239:       }
1.596     albertel 3240:       $prevattempts.= &end_data_table_row().&end_data_table();
1.1       albertel 3241:     } else {
1.596     albertel 3242:       $prevattempts=
                   3243: 	  &start_data_table().&start_data_table_row().
                   3244: 	  '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
                   3245: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3246:     }
                   3247:   } else {
1.596     albertel 3248:     $prevattempts=
                   3249: 	  &start_data_table().&start_data_table_row().
                   3250: 	  '<td>'.&mt('No data.').'</td>'.
                   3251: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3252:   }
1.10      albertel 3253: }
                   3254: 
1.581     albertel 3255: sub format_previous_attempt_value {
                   3256:     my ($key,$value) = @_;
                   3257:     if ($key =~ /timestamp/) {
                   3258: 	$value = &Apache::lonlocal::locallocaltime($value);
                   3259:     } elsif (ref($value) eq 'ARRAY') {
                   3260: 	$value = '('.join(', ', @{ $value }).')';
                   3261:     } else {
                   3262: 	$value = &unescape($value);
                   3263:     }
                   3264:     return $value;
                   3265: }
                   3266: 
                   3267: 
1.107     albertel 3268: sub relative_to_absolute {
                   3269:     my ($url,$output)=@_;
                   3270:     my $parser=HTML::TokeParser->new(\$output);
                   3271:     my $token;
                   3272:     my $thisdir=$url;
                   3273:     my @rlinks=();
                   3274:     while ($token=$parser->get_token) {
                   3275: 	if ($token->[0] eq 'S') {
                   3276: 	    if ($token->[1] eq 'a') {
                   3277: 		if ($token->[2]->{'href'}) {
                   3278: 		    $rlinks[$#rlinks+1]=$token->[2]->{'href'};
                   3279: 		}
                   3280: 	    } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
                   3281: 		$rlinks[$#rlinks+1]=$token->[2]->{'src'};
                   3282: 	    } elsif ($token->[1] eq 'base') {
                   3283: 		$thisdir=$token->[2]->{'href'};
                   3284: 	    }
                   3285: 	}
                   3286:     }
                   3287:     $thisdir=~s-/[^/]*$--;
1.356     albertel 3288:     foreach my $link (@rlinks) {
1.726     raeburn  3289: 	unless (($link=~/^https?\:\/\//i) ||
1.356     albertel 3290: 		($link=~/^\//) ||
                   3291: 		($link=~/^javascript:/i) ||
                   3292: 		($link=~/^mailto:/i) ||
                   3293: 		($link=~/^\#/)) {
                   3294: 	    my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
                   3295: 	    $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107     albertel 3296: 	}
                   3297:     }
                   3298: # -------------------------------------------------- Deal with Applet codebases
                   3299:     $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
                   3300:     return $output;
                   3301: }
                   3302: 
1.112     bowersj2 3303: =pod
                   3304: 
1.648     raeburn  3305: =item * &get_student_view()
1.112     bowersj2 3306: 
                   3307: show a snapshot of what student was looking at
                   3308: 
                   3309: =cut
                   3310: 
1.10      albertel 3311: sub get_student_view {
1.186     albertel 3312:   my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114     www      3313:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3314:   my (%form);
1.10      albertel 3315:   my @elements=('symb','courseid','domain','username');
                   3316:   foreach my $element (@elements) {
1.186     albertel 3317:       $form{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3318:   }
1.186     albertel 3319:   if (defined($moreenv)) {
                   3320:       %form=(%form,%{$moreenv});
                   3321:   }
1.236     albertel 3322:   if (defined($target)) { $form{'grade_target'} = $target; }
1.107     albertel 3323:   $feedurl=&Apache::lonnet::clutter($feedurl);
1.650     www      3324:   my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11      albertel 3325:   $userview=~s/\<body[^\>]*\>//gi;
                   3326:   $userview=~s/\<\/body\>//gi;
                   3327:   $userview=~s/\<html\>//gi;
                   3328:   $userview=~s/\<\/html\>//gi;
                   3329:   $userview=~s/\<head\>//gi;
                   3330:   $userview=~s/\<\/head\>//gi;
                   3331:   $userview=~s/action\s*\=/would_be_action\=/gi;
1.107     albertel 3332:   $userview=&relative_to_absolute($feedurl,$userview);
1.650     www      3333:   if (wantarray) {
                   3334:      return ($userview,$response);
                   3335:   } else {
                   3336:      return $userview;
                   3337:   }
                   3338: }
                   3339: 
                   3340: sub get_student_view_with_retries {
                   3341:   my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
                   3342: 
                   3343:     my $ok = 0;                 # True if we got a good response.
                   3344:     my $content;
                   3345:     my $response;
                   3346: 
                   3347:     # Try to get the student_view done. within the retries count:
                   3348:     
                   3349:     do {
                   3350:          ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
                   3351:          $ok      = $response->is_success;
                   3352:          if (!$ok) {
                   3353:             &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
                   3354:          }
                   3355:          $retries--;
                   3356:     } while (!$ok && ($retries > 0));
                   3357:     
                   3358:     if (!$ok) {
                   3359:        $content = '';          # On error return an empty content.
                   3360:     }
1.651     www      3361:     if (wantarray) {
                   3362:        return ($content, $response);
                   3363:     } else {
                   3364:        return $content;
                   3365:     }
1.11      albertel 3366: }
                   3367: 
1.112     bowersj2 3368: =pod
                   3369: 
1.648     raeburn  3370: =item * &get_student_answers() 
1.112     bowersj2 3371: 
                   3372: show a snapshot of how student was answering problem
                   3373: 
                   3374: =cut
                   3375: 
1.11      albertel 3376: sub get_student_answers {
1.100     sakharuk 3377:   my ($symb,$username,$domain,$courseid,%form) = @_;
1.114     www      3378:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3379:   my (%moreenv);
1.11      albertel 3380:   my @elements=('symb','courseid','domain','username');
                   3381:   foreach my $element (@elements) {
1.186     albertel 3382:     $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3383:   }
1.186     albertel 3384:   $moreenv{'grade_target'}='answer';
                   3385:   %moreenv=(%form,%moreenv);
1.497     raeburn  3386:   $feedurl = &Apache::lonnet::clutter($feedurl);
                   3387:   my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10      albertel 3388:   return $userview;
1.1       albertel 3389: }
1.116     albertel 3390: 
                   3391: =pod
                   3392: 
                   3393: =item * &submlink()
                   3394: 
1.242     albertel 3395: Inputs: $text $uname $udom $symb $target
1.116     albertel 3396: 
                   3397: Returns: A link to grades.pm such as to see the SUBM view of a student
                   3398: 
                   3399: =cut
                   3400: 
                   3401: ###############################################
                   3402: sub submlink {
1.242     albertel 3403:     my ($text,$uname,$udom,$symb,$target)=@_;
1.116     albertel 3404:     if (!($uname && $udom)) {
                   3405: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3406: 	    &Apache::lonnet::whichuser($symb);
1.116     albertel 3407: 	if (!$symb) { $symb=$cursymb; }
                   3408:     }
1.254     matthew  3409:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3410:     $symb=&escape($symb);
1.242     albertel 3411:     if ($target) { $target="target=\"$target\""; }
                   3412:     return '<a href="/adm/grades?&command=submission&'.
                   3413: 	'symb='.$symb.'&student='.$uname.
                   3414: 	'&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
                   3415: }
                   3416: ##############################################
                   3417: 
                   3418: =pod
                   3419: 
                   3420: =item * &pgrdlink()
                   3421: 
                   3422: Inputs: $text $uname $udom $symb $target
                   3423: 
                   3424: Returns: A link to grades.pm such as to see the PGRD view of a student
                   3425: 
                   3426: =cut
                   3427: 
                   3428: ###############################################
                   3429: sub pgrdlink {
                   3430:     my $link=&submlink(@_);
                   3431:     $link=~s/(&command=submission)/$1&showgrading=yes/;
                   3432:     return $link;
                   3433: }
                   3434: ##############################################
                   3435: 
                   3436: =pod
                   3437: 
                   3438: =item * &pprmlink()
                   3439: 
                   3440: Inputs: $text $uname $udom $symb $target
                   3441: 
                   3442: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283     albertel 3443: student and a specific resource
1.242     albertel 3444: 
                   3445: =cut
                   3446: 
                   3447: ###############################################
                   3448: sub pprmlink {
                   3449:     my ($text,$uname,$udom,$symb,$target)=@_;
                   3450:     if (!($uname && $udom)) {
                   3451: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3452: 	    &Apache::lonnet::whichuser($symb);
1.242     albertel 3453: 	if (!$symb) { $symb=$cursymb; }
                   3454:     }
1.254     matthew  3455:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3456:     $symb=&escape($symb);
1.242     albertel 3457:     if ($target) { $target="target=\"$target\""; }
1.595     albertel 3458:     return '<a href="/adm/parmset?command=set&amp;'.
                   3459: 	'symb='.$symb.'&amp;uname='.$uname.
                   3460: 	'&amp;udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116     albertel 3461: }
                   3462: ##############################################
1.37      matthew  3463: 
1.112     bowersj2 3464: =pod
                   3465: 
                   3466: =back
                   3467: 
                   3468: =cut
                   3469: 
1.37      matthew  3470: ###############################################
1.51      www      3471: 
                   3472: 
                   3473: sub timehash {
1.687     raeburn  3474:     my ($thistime) = @_;
                   3475:     my $timezone = &Apache::lonlocal::gettimezone();
                   3476:     my $dt = DateTime->from_epoch(epoch => $thistime)
                   3477:                      ->set_time_zone($timezone);
                   3478:     my $wday = $dt->day_of_week();
                   3479:     if ($wday == 7) { $wday = 0; }
                   3480:     return ( 'second' => $dt->second(),
                   3481:              'minute' => $dt->minute(),
                   3482:              'hour'   => $dt->hour(),
                   3483:              'day'     => $dt->day_of_month(),
                   3484:              'month'   => $dt->month(),
                   3485:              'year'    => $dt->year(),
                   3486:              'weekday' => $wday,
                   3487:              'dayyear' => $dt->day_of_year(),
                   3488:              'dlsav'   => $dt->is_dst() );
1.51      www      3489: }
                   3490: 
1.370     www      3491: sub utc_string {
                   3492:     my ($date)=@_;
1.371     www      3493:     return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370     www      3494: }
                   3495: 
1.51      www      3496: sub maketime {
                   3497:     my %th=@_;
1.687     raeburn  3498:     my ($epoch_time,$timezone,$dt);
                   3499:     $timezone = &Apache::lonlocal::gettimezone();
                   3500:     eval {
                   3501:         $dt = DateTime->new( year   => $th{'year'},
                   3502:                              month  => $th{'month'},
                   3503:                              day    => $th{'day'},
                   3504:                              hour   => $th{'hour'},
                   3505:                              minute => $th{'minute'},
                   3506:                              second => $th{'second'},
                   3507:                              time_zone => $timezone,
                   3508:                          );
                   3509:     };
                   3510:     if (!$@) {
                   3511:         $epoch_time = $dt->epoch;
                   3512:         if ($epoch_time) {
                   3513:             return $epoch_time;
                   3514:         }
                   3515:     }
1.51      www      3516:     return POSIX::mktime(
                   3517:         ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210     www      3518:          $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70      www      3519: }
                   3520: 
                   3521: #########################################
1.51      www      3522: 
                   3523: sub findallcourses {
1.482     raeburn  3524:     my ($roles,$uname,$udom) = @_;
1.355     albertel 3525:     my %roles;
                   3526:     if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348     albertel 3527:     my %courses;
1.51      www      3528:     my $now=time;
1.482     raeburn  3529:     if (!defined($uname)) {
                   3530:         $uname = $env{'user.name'};
                   3531:     }
                   3532:     if (!defined($udom)) {
                   3533:         $udom = $env{'user.domain'};
                   3534:     }
                   3535:     if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
                   3536:         my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
                   3537:         if (!%roles) {
                   3538:             %roles = (
                   3539:                        cc => 1,
                   3540:                        in => 1,
                   3541:                        ep => 1,
                   3542:                        ta => 1,
                   3543:                        cr => 1,
                   3544:                        st => 1,
                   3545:              );
                   3546:         }
                   3547:         foreach my $entry (keys(%roleshash)) {
                   3548:             my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
                   3549:             if ($trole =~ /^cr/) { 
                   3550:                 next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
                   3551:             } else {
                   3552:                 next if (!exists($roles{$trole}));
                   3553:             }
                   3554:             if ($tend) {
                   3555:                 next if ($tend < $now);
                   3556:             }
                   3557:             if ($tstart) {
                   3558:                 next if ($tstart > $now);
                   3559:             }
                   3560:             my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
                   3561:             (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
                   3562:             if ($secpart eq '') {
                   3563:                 ($cnum,$role) = split(/_/,$cnumpart); 
                   3564:                 $sec = 'none';
                   3565:                 $realsec = '';
                   3566:             } else {
                   3567:                 $cnum = $cnumpart;
                   3568:                 ($sec,$role) = split(/_/,$secpart);
                   3569:                 $realsec = $sec;
1.490     raeburn  3570:             }
1.482     raeburn  3571:             $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
                   3572:         }
                   3573:     } else {
                   3574:         foreach my $key (keys(%env)) {
1.483     albertel 3575: 	    if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
                   3576:                  $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482     raeburn  3577: 	        my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
                   3578: 	        next if ($role eq 'ca' || $role eq 'aa');
                   3579: 	        next if (%roles && !exists($roles{$role}));
                   3580: 	        my ($starttime,$endtime)=split(/\./,$env{$key});
                   3581:                 my $active=1;
                   3582:                 if ($starttime) {
                   3583: 		    if ($now<$starttime) { $active=0; }
                   3584:                 }
                   3585:                 if ($endtime) {
                   3586:                     if ($now>$endtime) { $active=0; }
                   3587:                 }
                   3588:                 if ($active) {
                   3589:                     if ($sec eq '') {
                   3590:                         $sec = 'none';
                   3591:                     }
                   3592:                     $courses{$cdom.'_'.$cnum}{$sec} = 
                   3593:                                      $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474     raeburn  3594:                 }
                   3595:             }
1.51      www      3596:         }
                   3597:     }
1.474     raeburn  3598:     return %courses;
1.51      www      3599: }
1.37      matthew  3600: 
1.54      www      3601: ###############################################
1.474     raeburn  3602: 
                   3603: sub blockcheck {
1.482     raeburn  3604:     my ($setters,$activity,$uname,$udom) = @_;
1.490     raeburn  3605: 
                   3606:     if (!defined($udom)) {
                   3607:         $udom = $env{'user.domain'};
                   3608:     }
                   3609:     if (!defined($uname)) {
                   3610:         $uname = $env{'user.name'};
                   3611:     }
                   3612: 
                   3613:     # If uname and udom are for a course, check for blocks in the course.
                   3614: 
                   3615:     if (&Apache::lonnet::is_course($udom,$uname)) {
                   3616:         my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502     raeburn  3617:         my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490     raeburn  3618:         return ($startblock,$endblock);
                   3619:     }
1.474     raeburn  3620: 
1.502     raeburn  3621:     my $startblock = 0;
                   3622:     my $endblock = 0;
1.482     raeburn  3623:     my %live_courses = &findallcourses(undef,$uname,$udom);
1.474     raeburn  3624: 
1.490     raeburn  3625:     # If uname is for a user, and activity is course-specific, i.e.,
                   3626:     # boards, chat or groups, check for blocking in current course only.
1.474     raeburn  3627: 
1.490     raeburn  3628:     if (($activity eq 'boards' || $activity eq 'chat' ||
                   3629:          $activity eq 'groups') && ($env{'request.course.id'})) {
                   3630:         foreach my $key (keys(%live_courses)) {
                   3631:             if ($key ne $env{'request.course.id'}) {
                   3632:                 delete($live_courses{$key});
                   3633:             }
                   3634:         }
                   3635:     }
                   3636: 
                   3637:     my $otheruser = 0;
                   3638:     my %own_courses;
                   3639:     if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
                   3640:         # Resource belongs to user other than current user.
                   3641:         $otheruser = 1;
                   3642:         # Gather courses for current user
                   3643:         %own_courses = 
                   3644:             &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
                   3645:     }
                   3646: 
                   3647:     # Gather active course roles - course coordinator, instructor, 
                   3648:     # exam proctor, ta, student, or custom role.
1.474     raeburn  3649: 
                   3650:     foreach my $course (keys(%live_courses)) {
1.482     raeburn  3651:         my ($cdom,$cnum);
                   3652:         if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
                   3653:             $cdom = $env{'course.'.$course.'.domain'};
                   3654:             $cnum = $env{'course.'.$course.'.num'};
                   3655:         } else {
1.490     raeburn  3656:             ($cdom,$cnum) = split(/_/,$course); 
1.482     raeburn  3657:         }
                   3658:         my $no_ownblock = 0;
                   3659:         my $no_userblock = 0;
1.533     raeburn  3660:         if ($otheruser && $activity ne 'com') {
1.490     raeburn  3661:             # Check if current user has 'evb' priv for this
                   3662:             if (defined($own_courses{$course})) {
                   3663:                 foreach my $sec (keys(%{$own_courses{$course}})) {
                   3664:                     my $checkrole = 'cm./'.$cdom.'/'.$cnum;
                   3665:                     if ($sec ne 'none') {
                   3666:                         $checkrole .= '/'.$sec;
                   3667:                     }
                   3668:                     if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   3669:                         $no_ownblock = 1;
                   3670:                         last;
                   3671:                     }
                   3672:                 }
                   3673:             }
                   3674:             # if they have 'evb' priv and are currently not playing student
                   3675:             next if (($no_ownblock) &&
                   3676:                  ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
                   3677:         }
1.474     raeburn  3678:         foreach my $sec (keys(%{$live_courses{$course}})) {
1.482     raeburn  3679:             my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474     raeburn  3680:             if ($sec ne 'none') {
1.482     raeburn  3681:                 $checkrole .= '/'.$sec;
1.474     raeburn  3682:             }
1.490     raeburn  3683:             if ($otheruser) {
                   3684:                 # Resource belongs to user other than current user.
                   3685:                 # Assemble privs for that user, and check for 'evb' priv.
1.482     raeburn  3686:                 my ($trole,$tdom,$tnum,$tsec);
                   3687:                 my $entry = $live_courses{$course}{$sec};
                   3688:                 if ($entry =~ /^cr/) {
                   3689:                     ($trole,$tdom,$tnum,$tsec) = 
                   3690:                       ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
                   3691:                 } else {
                   3692:                     ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
                   3693:                 }
                   3694:                 my ($spec,$area,$trest,%allroles,%userroles);
                   3695:                 $area = '/'.$tdom.'/'.$tnum;
                   3696:                 $trest = $tnum;
                   3697:                 if ($tsec ne '') {
                   3698:                     $area .= '/'.$tsec;
                   3699:                     $trest .= '/'.$tsec;
                   3700:                 }
                   3701:                 $spec = $trole.'.'.$area;
                   3702:                 if ($trole =~ /^cr/) {
                   3703:                     &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
                   3704:                                                       $tdom,$spec,$trest,$area);
                   3705:                 } else {
                   3706:                     &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
                   3707:                                                        $tdom,$spec,$trest,$area);
                   3708:                 }
                   3709:                 my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486     raeburn  3710:                 if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
                   3711:                     if ($1) {
                   3712:                         $no_userblock = 1;
                   3713:                         last;
                   3714:                     }
                   3715:                 }
1.490     raeburn  3716:             } else {
                   3717:                 # Resource belongs to current user
                   3718:                 # Check for 'evb' priv via lonnet::allowed().
1.482     raeburn  3719:                 if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   3720:                     $no_ownblock = 1;
                   3721:                     last;
                   3722:                 }
1.474     raeburn  3723:             }
                   3724:         }
                   3725:         # if they have the evb priv and are currently not playing student
1.482     raeburn  3726:         next if (($no_ownblock) &&
1.491     albertel 3727:                  ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482     raeburn  3728:         next if ($no_userblock);
1.474     raeburn  3729: 
1.490     raeburn  3730:         # Retrieve blocking times and identity of blocker for course
                   3731:         # of specified user, unless user has 'evb' privilege.
1.502     raeburn  3732:         
                   3733:         my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
                   3734:         if (($start != 0) && 
                   3735:             (($startblock == 0) || ($startblock > $start))) {
                   3736:             $startblock = $start;
                   3737:         }
                   3738:         if (($end != 0)  &&
                   3739:             (($endblock == 0) || ($endblock < $end))) {
                   3740:             $endblock = $end;
                   3741:         }
1.490     raeburn  3742:     }
                   3743:     return ($startblock,$endblock);
                   3744: }
                   3745: 
                   3746: sub get_blocks {
                   3747:     my ($setters,$activity,$cdom,$cnum) = @_;
                   3748:     my $startblock = 0;
                   3749:     my $endblock = 0;
                   3750:     my $course = $cdom.'_'.$cnum;
                   3751:     $setters->{$course} = {};
                   3752:     $setters->{$course}{'staff'} = [];
                   3753:     $setters->{$course}{'times'} = [];
                   3754:     my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
                   3755:     foreach my $record (keys(%records)) {
                   3756:         my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
                   3757:         if ($start <= time && $end >= time) {
                   3758:             my ($staff_name,$staff_dom,$title,$blocks) =
                   3759:                 &parse_block_record($records{$record});
                   3760:             if ($blocks->{$activity} eq 'on') {
                   3761:                 push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
                   3762:                 push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491     albertel 3763:                 if ( ($startblock == 0) || ($startblock > $start) ) {
                   3764:                     $startblock = $start;
1.490     raeburn  3765:                 }
1.491     albertel 3766:                 if ( ($endblock == 0) || ($endblock < $end) ) {
                   3767:                     $endblock = $end;
1.474     raeburn  3768:                 }
                   3769:             }
                   3770:         }
                   3771:     }
                   3772:     return ($startblock,$endblock);
                   3773: }
                   3774: 
                   3775: sub parse_block_record {
                   3776:     my ($record) = @_;
                   3777:     my ($setuname,$setudom,$title,$blocks);
                   3778:     if (ref($record) eq 'HASH') {
                   3779:         ($setuname,$setudom) = split(/:/,$record->{'setter'});
                   3780:         $title = &unescape($record->{'event'});
                   3781:         $blocks = $record->{'blocks'};
                   3782:     } else {
                   3783:         my @data = split(/:/,$record,3);
                   3784:         if (scalar(@data) eq 2) {
                   3785:             $title = $data[1];
                   3786:             ($setuname,$setudom) = split(/@/,$data[0]);
                   3787:         } else {
                   3788:             ($setuname,$setudom,$title) = @data;
                   3789:         }
                   3790:         $blocks = { 'com' => 'on' };
                   3791:     }
                   3792:     return ($setuname,$setudom,$title,$blocks);
                   3793: }
                   3794: 
                   3795: sub build_block_table {
                   3796:     my ($startblock,$endblock,$setters) = @_;
                   3797:     my %lt = &Apache::lonlocal::texthash(
                   3798:         'cacb' => 'Currently active communication blocks',
                   3799:         'cour' => 'Course',
                   3800:         'dura' => 'Duration',
                   3801:         'blse' => 'Block set by'
                   3802:     );
                   3803:     my $output;
1.476     raeburn  3804:     $output = '<br />'.$lt{'cacb'}.':<br />';
1.474     raeburn  3805:     $output .= &start_data_table();
                   3806:     $output .= '
                   3807: <tr>
                   3808:  <th>'.$lt{'cour'}.'</th>
                   3809:  <th>'.$lt{'dura'}.'</th>
                   3810:  <th>'.$lt{'blse'}.'</th>
                   3811: </tr>
                   3812: ';
                   3813:     foreach my $course (keys(%{$setters})) {
                   3814:         my %courseinfo=&Apache::lonnet::coursedescription($course);
                   3815:         for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
                   3816:             my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490     raeburn  3817:             my $fullname = &plainname($uname,$udom);
                   3818:             if (defined($env{'user.name'}) && defined($env{'user.domain'})
                   3819:                 && $env{'user.name'} ne 'public' 
                   3820:                 && $env{'user.domain'} ne 'public') {
                   3821:                 $fullname = &aboutmewrapper($fullname,$uname,$udom);
                   3822:             }
1.474     raeburn  3823:             my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
                   3824:             $openblock = &Apache::lonlocal::locallocaltime($openblock);
                   3825:             $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
                   3826:             $output .= &Apache::loncommon::start_data_table_row().
                   3827:                        '<td>'.$courseinfo{'description'}.'</td>'.
                   3828:                        '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490     raeburn  3829:                        '<td>'.$fullname.'</td>'.
1.474     raeburn  3830:                         &Apache::loncommon::end_data_table_row();
                   3831:         }
                   3832:     }
                   3833:     $output .= &end_data_table();
                   3834: }
                   3835: 
1.490     raeburn  3836: sub blocking_status {
                   3837:     my ($activity,$uname,$udom) = @_;
                   3838:     my %setters;
                   3839:     my ($blocked,$output,$ownitem,$is_course);
                   3840:     my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
                   3841:     if ($startblock && $endblock) {
                   3842:         $blocked = 1;
                   3843:         if (wantarray) {
                   3844:             my $category;
                   3845:             if ($activity eq 'boards') {
                   3846:                 $category = 'Discussion posts in this course';
                   3847:             } elsif ($activity eq 'blogs') {
                   3848:                 $category = 'Blogs';
                   3849:             } elsif ($activity eq 'port') {
                   3850:                 if (defined($uname) && defined($udom)) {
                   3851:                     if ($uname eq $env{'user.name'} &&
                   3852:                         $udom eq $env{'user.domain'}) {
                   3853:                         $ownitem = 1;
                   3854:                     }
                   3855:                 }
                   3856:                 $is_course = &Apache::lonnet::is_course($udom,$uname);
                   3857:                 if ($ownitem) { 
                   3858:                     $category = 'Your portfolio files';  
                   3859:                 } elsif ($is_course) {
                   3860:                     my $coursedesc;
                   3861:                     foreach my $course (keys(%setters)) {
                   3862:                         my %courseinfo =
                   3863:                              &Apache::lonnet::coursedescription($course);
                   3864:                         $coursedesc = $courseinfo{'description'};
                   3865:                     }
1.764     weissno  3866:                     $category = "Group portfolio in the course '$coursedesc'";
1.490     raeburn  3867:                 } else {
                   3868:                     $category = 'Portfolio files belonging to ';
                   3869:                     if ($env{'user.name'} eq 'public' && 
                   3870:                         $env{'user.domain'} eq 'public') {
                   3871:                         $category .= &plainname($uname,$udom);
                   3872:                     } else {
                   3873:                         $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);  
                   3874:                     }
                   3875:                 }
                   3876:             } elsif ($activity eq 'groups') {
                   3877:                 $category = 'Groups in this course';
                   3878:             }
                   3879:             my $showstart = &Apache::lonlocal::locallocaltime($startblock);
                   3880:             my $showend = &Apache::lonlocal::locallocaltime($endblock);
                   3881:             $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
                   3882:             if (!($activity eq 'port' && !($ownitem) && !($is_course))) { 
                   3883:                 $output .= &build_block_table($startblock,$endblock,\%setters);
                   3884:             }
                   3885:         }
                   3886:     }
                   3887:     if (wantarray) {
                   3888:         return ($blocked,$output);
                   3889:     } else {
                   3890:         return $blocked;
                   3891:     }
                   3892: }
                   3893: 
1.60      matthew  3894: ###############################################
                   3895: 
1.682     raeburn  3896: sub check_ip_acc {
                   3897:     my ($acc)=@_;
                   3898:     &Apache::lonxml::debug("acc is $acc");
                   3899:     if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
                   3900:         return 1;
                   3901:     }
                   3902:     my $allowed=0;
                   3903:     my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
                   3904: 
                   3905:     my $name;
                   3906:     foreach my $pattern (split(',',$acc)) {
                   3907:         $pattern =~ s/^\s*//;
                   3908:         $pattern =~ s/\s*$//;
                   3909:         if ($pattern =~ /\*$/) {
                   3910:             #35.8.*
                   3911:             $pattern=~s/\*//;
                   3912:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   3913:         } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
                   3914:             #35.8.3.[34-56]
                   3915:             my $low=$2;
                   3916:             my $high=$3;
                   3917:             $pattern=$1;
                   3918:             if ($ip =~ /^\Q$pattern\E/) {
                   3919:                 my $last=(split(/\./,$ip))[3];
                   3920:                 if ($last <=$high && $last >=$low) { $allowed=1; }
                   3921:             }
                   3922:         } elsif ($pattern =~ /^\*/) {
                   3923:             #*.msu.edu
                   3924:             $pattern=~s/\*//;
                   3925:             if (!defined($name)) {
                   3926:                 use Socket;
                   3927:                 my $netaddr=inet_aton($ip);
                   3928:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   3929:             }
                   3930:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   3931:         } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
                   3932:             #127.0.0.1
                   3933:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   3934:         } else {
                   3935:             #some.name.com
                   3936:             if (!defined($name)) {
                   3937:                 use Socket;
                   3938:                 my $netaddr=inet_aton($ip);
                   3939:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   3940:             }
                   3941:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   3942:         }
                   3943:         if ($allowed) { last; }
                   3944:     }
                   3945:     return $allowed;
                   3946: }
                   3947: 
                   3948: ###############################################
                   3949: 
1.60      matthew  3950: =pod
                   3951: 
1.112     bowersj2 3952: =head1 Domain Template Functions
                   3953: 
                   3954: =over 4
                   3955: 
                   3956: =item * &determinedomain()
1.60      matthew  3957: 
                   3958: Inputs: $domain (usually will be undef)
                   3959: 
1.63      www      3960: Returns: Determines which domain should be used for designs
1.60      matthew  3961: 
                   3962: =cut
1.54      www      3963: 
1.60      matthew  3964: ###############################################
1.63      www      3965: sub determinedomain {
                   3966:     my $domain=shift;
1.531     albertel 3967:     if (! $domain) {
1.60      matthew  3968:         # Determine domain if we have not been given one
                   3969:         $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258     albertel 3970:         if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
                   3971:         if ($env{'request.role.domain'}) { 
                   3972:             $domain=$env{'request.role.domain'}; 
1.60      matthew  3973:         }
                   3974:     }
1.63      www      3975:     return $domain;
                   3976: }
                   3977: ###############################################
1.517     raeburn  3978: 
1.518     albertel 3979: sub devalidate_domconfig_cache {
                   3980:     my ($udom)=@_;
                   3981:     &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
                   3982: }
                   3983: 
                   3984: # ---------------------- Get domain configuration for a domain
                   3985: sub get_domainconf {
                   3986:     my ($udom) = @_;
                   3987:     my $cachetime=1800;
                   3988:     my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
                   3989:     if (defined($cached)) { return %{$result}; }
                   3990: 
                   3991:     my %domconfig = &Apache::lonnet::get_dom('configuration',
                   3992: 					     ['login','rolecolors'],$udom);
1.632     raeburn  3993:     my (%designhash,%legacy);
1.518     albertel 3994:     if (keys(%domconfig) > 0) {
                   3995:         if (ref($domconfig{'login'}) eq 'HASH') {
1.632     raeburn  3996:             if (keys(%{$domconfig{'login'}})) {
                   3997:                 foreach my $key (keys(%{$domconfig{'login'}})) {
1.699     raeburn  3998:                     if (ref($domconfig{'login'}{$key}) eq 'HASH') {
                   3999:                         foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
                   4000:                             $designhash{$udom.'.login.'.$key.'_'.$img} = 
                   4001:                                 $domconfig{'login'}{$key}{$img};
                   4002:                         }
                   4003:                     } else {
                   4004:                         $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
                   4005:                     }
1.632     raeburn  4006:                 }
                   4007:             } else {
                   4008:                 $legacy{'login'} = 1;
1.518     albertel 4009:             }
1.632     raeburn  4010:         } else {
                   4011:             $legacy{'login'} = 1;
1.518     albertel 4012:         }
                   4013:         if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632     raeburn  4014:             if (keys(%{$domconfig{'rolecolors'}})) {
                   4015:                 foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
                   4016:                     if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
                   4017:                         foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
                   4018:                             $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
                   4019:                         }
1.518     albertel 4020:                     }
                   4021:                 }
1.632     raeburn  4022:             } else {
                   4023:                 $legacy{'rolecolors'} = 1;
1.518     albertel 4024:             }
1.632     raeburn  4025:         } else {
                   4026:             $legacy{'rolecolors'} = 1;
1.518     albertel 4027:         }
1.632     raeburn  4028:         if (keys(%legacy) > 0) {
                   4029:             my %legacyhash = &get_legacy_domconf($udom);
                   4030:             foreach my $item (keys(%legacyhash)) {
                   4031:                 if ($item =~ /^\Q$udom\E\.login/) {
                   4032:                     if ($legacy{'login'}) { 
                   4033:                         $designhash{$item} = $legacyhash{$item};
                   4034:                     }
                   4035:                 } else {
                   4036:                     if ($legacy{'rolecolors'}) {
                   4037:                         $designhash{$item} = $legacyhash{$item};
                   4038:                     }
1.518     albertel 4039:                 }
                   4040:             }
                   4041:         }
1.632     raeburn  4042:     } else {
                   4043:         %designhash = &get_legacy_domconf($udom); 
1.518     albertel 4044:     }
                   4045:     &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
                   4046: 				  $cachetime);
                   4047:     return %designhash;
                   4048: }
                   4049: 
1.632     raeburn  4050: sub get_legacy_domconf {
                   4051:     my ($udom) = @_;
                   4052:     my %legacyhash;
                   4053:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
                   4054:     my $designfile =  $designdir.'/'.$udom.'.tab';
                   4055:     if (-e $designfile) {
                   4056:         if ( open (my $fh,"<$designfile") ) {
                   4057:             while (my $line = <$fh>) {
                   4058:                 next if ($line =~ /^\#/);
                   4059:                 chomp($line);
                   4060:                 my ($key,$val)=(split(/\=/,$line));
                   4061:                 if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
                   4062:             }
                   4063:             close($fh);
                   4064:         }
                   4065:     }
                   4066:     if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
                   4067:         $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
                   4068:     }
                   4069:     return %legacyhash;
                   4070: }
                   4071: 
1.63      www      4072: =pod
                   4073: 
1.112     bowersj2 4074: =item * &domainlogo()
1.63      www      4075: 
                   4076: Inputs: $domain (usually will be undef)
                   4077: 
                   4078: Returns: A link to a domain logo, if the domain logo exists.
                   4079: If the domain logo does not exist, a description of the domain.
                   4080: 
                   4081: =cut
1.112     bowersj2 4082: 
1.63      www      4083: ###############################################
                   4084: sub domainlogo {
1.517     raeburn  4085:     my $domain = &determinedomain(shift);
1.518     albertel 4086:     my %designhash = &get_domainconf($domain);    
1.517     raeburn  4087:     # See if there is a logo
                   4088:     if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519     raeburn  4089:         my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538     albertel 4090:         if ($imgsrc =~ m{^/(adm|res)/}) {
                   4091: 	    if ($imgsrc =~ m{^/res/}) {
                   4092: 		my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
                   4093: 		&Apache::lonnet::repcopy($local_name);
                   4094: 	    }
                   4095: 	   $imgsrc = &lonhttpdurl($imgsrc);
1.519     raeburn  4096:         } 
                   4097:         return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514     albertel 4098:     } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
                   4099:         return &Apache::lonnet::domain($domain,'description');
1.59      www      4100:     } else {
1.60      matthew  4101:         return '';
1.59      www      4102:     }
                   4103: }
1.63      www      4104: ##############################################
                   4105: 
                   4106: =pod
                   4107: 
1.112     bowersj2 4108: =item * &designparm()
1.63      www      4109: 
                   4110: Inputs: $which parameter; $domain (usually will be undef)
                   4111: 
                   4112: Returns: value of designparamter $which
                   4113: 
                   4114: =cut
1.112     bowersj2 4115: 
1.397     albertel 4116: 
1.400     albertel 4117: ##############################################
1.397     albertel 4118: sub designparm {
                   4119:     my ($which,$domain)=@_;
1.258     albertel 4120:     if ($env{'browser.blackwhite'} eq 'on') {
1.635     raeburn  4121: 	if ($which=~/\.(font|alink|vlink|link|textcol)$/) {
1.110     www      4122: 	    return '#000000';
                   4123: 	}
1.635     raeburn  4124: 	if ($which=~/\.(pgbg|sidebg|bgcol)$/) {
1.110     www      4125: 	    return '#FFFFFF';
                   4126: 	}
                   4127: 	if ($which=~/\.tabbg$/) {
                   4128: 	    return '#CCCCCC';
                   4129: 	}
                   4130:     }
1.397     albertel 4131:     if (exists($env{'environment.color.'.$which})) {
1.258     albertel 4132: 	return $env{'environment.color.'.$which};
1.96      www      4133:     }
1.63      www      4134:     $domain=&determinedomain($domain);
1.518     albertel 4135:     my %domdesign = &get_domainconf($domain);
1.520     raeburn  4136:     my $output;
1.517     raeburn  4137:     if ($domdesign{$domain.'.'.$which} ne '') {
1.520     raeburn  4138: 	$output = $domdesign{$domain.'.'.$which};
1.63      www      4139:     } else {
1.520     raeburn  4140:         $output = $defaultdesign{$which};
                   4141:     }
                   4142:     if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635     raeburn  4143:         ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538     albertel 4144:         if ($output =~ m{^/(adm|res)/}) {
                   4145: 	    if ($output =~ m{^/res/}) {
                   4146: 		my $local_name = &Apache::lonnet::filelocation('',$output);
                   4147: 		&Apache::lonnet::repcopy($local_name);
                   4148: 	    }
1.520     raeburn  4149:             $output = &lonhttpdurl($output);
                   4150:         }
1.63      www      4151:     }
1.520     raeburn  4152:     return $output;
1.63      www      4153: }
1.59      www      4154: 
1.60      matthew  4155: ###############################################
                   4156: ###############################################
                   4157: 
                   4158: =pod
                   4159: 
1.112     bowersj2 4160: =back
                   4161: 
1.549     albertel 4162: =head1 HTML Helpers
1.112     bowersj2 4163: 
                   4164: =over 4
                   4165: 
                   4166: =item * &bodytag()
1.60      matthew  4167: 
                   4168: Returns a uniform header for LON-CAPA web pages.
                   4169: 
                   4170: Inputs: 
                   4171: 
1.112     bowersj2 4172: =over 4
                   4173: 
                   4174: =item * $title, A title to be displayed on the page.
                   4175: 
                   4176: =item * $function, the current role (can be undef).
                   4177: 
                   4178: =item * $addentries, extra parameters for the <body> tag.
                   4179: 
                   4180: =item * $bodyonly, if defined, only return the <body> tag.
                   4181: 
                   4182: =item * $domain, if defined, force a given domain.
                   4183: 
                   4184: =item * $forcereg, if page should register as content page (relevant for 
1.86      www      4185:             text interface only)
1.60      matthew  4186: 
1.326     albertel 4187: =item * $customtitle, alternate text to use instead of $title
                   4188:                       in the title box that appears, this text
                   4189:                       is not auto translated like the $title is
1.309     albertel 4190: 
                   4191: =item * $notopbar, if true, keep the 'what is this' info but remove the
                   4192:                    navigational links
1.317     albertel 4193: 
1.338     albertel 4194: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
                   4195: 
                   4196: =item * $notitle, if true keep the nav controls, but remove the title bar
                   4197: 
1.361     albertel 4198: =item * $no_inline_link, if true and in remote mode, don't show the 
                   4199:          'Switch To Inline Menu' link
                   4200: 
1.460     albertel 4201: =item * $args, optional argument valid values are
                   4202:             no_auto_mt_title -> prevents &mt()ing the title arg
1.562     albertel 4203:             inherit_jsmath -> when creating popup window in a page,
                   4204:                               should it have jsmath forced on by the
                   4205:                               current page
1.460     albertel 4206: 
1.112     bowersj2 4207: =back
                   4208: 
1.60      matthew  4209: Returns: A uniform header for LON-CAPA web pages.  
                   4210: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
                   4211: If $bodyonly is undef or zero, an html string containing a <body> tag and 
                   4212: other decorations will be returned.
                   4213: 
                   4214: =cut
                   4215: 
1.54      www      4216: sub bodytag {
1.309     albertel 4217:     my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
1.460     albertel 4218: 	$notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
1.339     albertel 4219: 
1.460     albertel 4220:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339     albertel 4221: 
1.183     matthew  4222:     $function = &get_users_function() if (!$function);
1.339     albertel 4223:     my $img =    &designparm($function.'.img',$domain);
                   4224:     my $font =   &designparm($function.'.font',$domain);
                   4225:     my $pgbg   = $bgcolor || &designparm($function.'.pgbg',$domain);
                   4226: 
                   4227:     my %design = ( 'style'   => 'margin-top: 0px',
1.535     albertel 4228: 		   'bgcolor' => $pgbg,
1.339     albertel 4229: 		   'text'    => $font,
                   4230:                    'alink'   => &designparm($function.'.alink',$domain),
                   4231: 		   'vlink'   => &designparm($function.'.vlink',$domain),
                   4232: 		   'link'    => &designparm($function.'.link',$domain),);
1.438     albertel 4233:     @design{keys(%$addentries)} = @$addentries{keys(%$addentries)}; 
1.339     albertel 4234: 
1.63      www      4235:  # role and realm
1.378     raeburn  4236:     my ($role,$realm) = split(/\./,$env{'request.role'},2);
                   4237:     if ($role  eq 'ca') {
1.479     albertel 4238:         my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500     albertel 4239:         $realm = &plainname($rname,$rdom);
1.378     raeburn  4240:     } 
1.55      www      4241: # realm
1.258     albertel 4242:     if ($env{'request.course.id'}) {
1.378     raeburn  4243:         if ($env{'request.role'} !~ /^cr/) {
                   4244:             $role = &Apache::lonnet::plaintext($role,&course_type());
                   4245:         }
1.359     albertel 4246: 	$realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378     raeburn  4247:     } else {
                   4248:         $role = &Apache::lonnet::plaintext($role);
1.54      www      4249:     }
1.433     albertel 4250: 
1.359     albertel 4251:     if (!$realm) { $realm='&nbsp;'; }
1.55      www      4252: # Set messages
1.60      matthew  4253:     my $messages=&domainlogo($domain);
1.330     albertel 4254: 
1.438     albertel 4255:     my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329     albertel 4256: 
1.101     www      4257: # construct main body tag
1.359     albertel 4258:     my $bodytag = "<body $extra_body_attr>".
1.562     albertel 4259: 	&Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252     albertel 4260: 
1.530     albertel 4261:     if ($bodyonly) {
1.60      matthew  4262:         return $bodytag;
1.798     tempelho 4263:     } 
1.359     albertel 4264: 
1.410     albertel 4265:     my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433     albertel 4266:     if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
                   4267: 	undef($role);
1.434     albertel 4268:     } else {
                   4269: 	$name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433     albertel 4270:     }
1.359     albertel 4271:     
                   4272:     my $roleinfo=(<<ENDROLE);
                   4273: <td class="LC_title_bar_who">
                   4274: <div class="LC_title_bar_name">
1.410     albertel 4275:     $name
1.361     albertel 4276:     &nbsp;
1.359     albertel 4277: </div>
                   4278: <div class="LC_title_bar_role">
1.361     albertel 4279: $role&nbsp;
1.359     albertel 4280: </div>
                   4281: <div class="LC_title_bar_realm">
1.361     albertel 4282: $realm&nbsp;
1.359     albertel 4283: </div>
1.206     albertel 4284: </td>
                   4285: ENDROLE
1.235     raeburn  4286: 
1.762     bisitz   4287:     my $titleinfo = '<h1>'.$title.'</h1>';
1.359     albertel 4288:     if ($customtitle) {
                   4289:         $titleinfo = $customtitle;
                   4290:     }
                   4291:     #
                   4292:     # Extra info if you are the DC
                   4293:     my $dc_info = '';
                   4294:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   4295:                         $env{'course.'.$env{'request.course.id'}.
                   4296:                                  '.domain'}.'/'})) {
                   4297:         my $cid = $env{'request.course.id'};
                   4298:         $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380     www      4299:         $dc_info =~ s/\s+$//;
1.359     albertel 4300:         $dc_info = '('.$dc_info.')';
                   4301:     }
                   4302: 
1.644     www      4303:     if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) {
1.359     albertel 4304:         # No Remote
1.258     albertel 4305: 	if ($env{'request.state'} eq 'construct') {
1.359     albertel 4306: 	    $forcereg=1;
                   4307: 	}
                   4308: 
                   4309: 	if (!$customtitle && $env{'request.state'} eq 'construct') {
                   4310: 	    # this is for resources; directories have customtitle, and crumbs
                   4311:             # and select recent are created in lonpubdir.pm  
1.229     albertel 4312: 	    my ($uname,$thisdisfn)=
1.258     albertel 4313: 		($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
1.229     albertel 4314: 	    my $formaction='/priv/'.$uname.'/'.$thisdisfn;
                   4315: 	    $formaction=~s/\/+/\//g;
                   4316: 
1.359     albertel 4317: 	    my $parentpath = '';
                   4318: 	    my $lastitem = '';
                   4319: 	    if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
                   4320: 		$parentpath = $1;
                   4321: 		$lastitem = $2;
                   4322: 	    } else {
                   4323: 		$lastitem = $thisdisfn;
                   4324: 	    }
                   4325: 	    $titleinfo = 
1.640     bisitz   4326: 		&Apache::loncommon::help_open_menu('','',3,'Authoring')
                   4327: 		.'<b>'.&mt('Construction Space').'</b>:&nbsp;'
                   4328: 		.'<form name="dirs" method="post" action="'.$formaction
1.359     albertel 4329: 		.'" target="_top"><tt><b>'
1.705     tempelho 4330: 		.&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<span class=\"LC_fontsize_big\">$lastitem</span></b></tt><br />"
1.359     albertel 4331: 		.&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
                   4332: 		.'</form>'
                   4333: 		.&Apache::lonmenu::constspaceform();
1.235     raeburn  4334:         }
1.359     albertel 4335: 
1.337     albertel 4336:         my $titletable;
1.338     albertel 4337: 	if (!$notitle) {
1.337     albertel 4338: 	    $titletable =
1.359     albertel 4339: 		'<table id="LC_title_bar">'.
                   4340:                          "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
                   4341: 			 '</tr></table>';
1.337     albertel 4342: 	}
1.359     albertel 4343: 	if ($notopbar) {
                   4344: 	    $bodytag .= $titletable;
                   4345: 	} else {
                   4346: 	    if ($env{'request.state'} eq 'construct') {
1.337     albertel 4347:                 $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
                   4348: 							  $titletable);
1.272     raeburn  4349:             } else {
1.336     albertel 4350:                 $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
1.359     albertel 4351: 		    $titletable;
1.272     raeburn  4352:             }
1.235     raeburn  4353:         }
                   4354:         return $bodytag;
1.94      www      4355:     }
1.95      www      4356: 
1.93      www      4357: #
1.95      www      4358: # Top frame rendering, Remote is up
1.93      www      4359: #
1.359     albertel 4360: 
1.517     raeburn  4361:     my $imgsrc = $img;
                   4362:     if ($img =~ /^\/adm/) {
1.575     albertel 4363:         $imgsrc = &lonhttpdurl($img);
1.517     raeburn  4364:     }
                   4365:     my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359     albertel 4366: 
1.305     www      4367:     # Explicit link to get inline menu
1.361     albertel 4368:     my $menu= ($no_inline_link?''
                   4369: 	       :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
1.245     matthew  4370:     #
1.338     albertel 4371:     if ($notitle) {
1.337     albertel 4372: 	return $bodytag;
                   4373:     }
1.94      www      4374:     return(<<ENDBODY);
1.60      matthew  4375: $bodytag
1.359     albertel 4376: <table id="LC_title_bar" class="LC_with_remote">
1.791     tempelho 4377: <tr><td>$upperleft</td>
                   4378:     <td>$messages&nbsp;</td>
1.54      www      4379: </tr>
1.359     albertel 4380: <tr><td>$titleinfo $dc_info $menu</td>
                   4381: $roleinfo
1.368     albertel 4382: </tr>
1.356     albertel 4383: </table>
1.54      www      4384: ENDBODY
1.182     matthew  4385: }
                   4386: 
1.330     albertel 4387: sub make_attr_string {
                   4388:     my ($register,$attr_ref) = @_;
                   4389: 
                   4390:     if ($attr_ref && !ref($attr_ref)) {
                   4391: 	die("addentries Must be a hash ref ".
                   4392: 	    join(':',caller(1))." ".
                   4393: 	    join(':',caller(0))." ");
                   4394:     }
                   4395: 
                   4396:     if ($register) {
1.339     albertel 4397: 	my ($on_load,$on_unload);
                   4398: 	foreach my $key (keys(%{$attr_ref})) {
                   4399: 	    if      (lc($key) eq 'onload') {
                   4400: 		$on_load.=$attr_ref->{$key}.';';
                   4401: 		delete($attr_ref->{$key});
                   4402: 
                   4403: 	    } elsif (lc($key) eq 'onunload') {
                   4404: 		$on_unload.=$attr_ref->{$key}.';';
                   4405: 		delete($attr_ref->{$key});
                   4406: 	    }
                   4407: 	}
                   4408: 	$attr_ref->{'onload'}  =
                   4409: 	    &Apache::lonmenu::loadevents().  $on_load;
                   4410: 	$attr_ref->{'onunload'}=
                   4411: 	    &Apache::lonmenu::unloadevents().$on_unload;
                   4412:     }
                   4413: 
                   4414: # Accessibility font enhance
                   4415:     if ($env{'browser.fontenhance'} eq 'on') {
                   4416: 	my $style;
                   4417: 	foreach my $key (keys(%{$attr_ref})) {
                   4418: 	    if (lc($key) eq 'style') {
                   4419: 		$style.=$attr_ref->{$key}.';';
                   4420: 		delete($attr_ref->{$key});
                   4421: 	    }
                   4422: 	}
                   4423: 	$attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330     albertel 4424:     }
1.339     albertel 4425: 
                   4426:     if ($env{'browser.blackwhite'} eq 'on') {
                   4427: 	delete($attr_ref->{'font'});
                   4428: 	delete($attr_ref->{'link'});
                   4429: 	delete($attr_ref->{'alink'});
                   4430: 	delete($attr_ref->{'vlink'});
                   4431: 	delete($attr_ref->{'bgcolor'});
                   4432: 	delete($attr_ref->{'background'});
                   4433:     }
                   4434: 
1.330     albertel 4435:     my $attr_string;
                   4436:     foreach my $attr (keys(%$attr_ref)) {
                   4437: 	$attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
                   4438:     }
                   4439:     return $attr_string;
                   4440: }
                   4441: 
                   4442: 
1.182     matthew  4443: ###############################################
1.251     albertel 4444: ###############################################
                   4445: 
                   4446: =pod
                   4447: 
                   4448: =item * &endbodytag()
                   4449: 
                   4450: Returns a uniform footer for LON-CAPA web pages.
                   4451: 
1.635     raeburn  4452: Inputs: 1 - optional reference to an args hash
                   4453: If in the hash, key for noredirectlink has a value which evaluates to true,
                   4454: a 'Continue' link is not displayed if the page contains an
                   4455: internal redirect in the <head></head> section,
                   4456: i.e., $env{'internal.head.redirect'} exists   
1.251     albertel 4457: 
                   4458: =cut
                   4459: 
                   4460: sub endbodytag {
1.635     raeburn  4461:     my ($args) = @_;
1.251     albertel 4462:     my $endbodytag='</body>';
1.269     albertel 4463:     $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315     albertel 4464:     if ( exists( $env{'internal.head.redirect'} ) ) {
1.635     raeburn  4465:         if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
                   4466: 	    $endbodytag=
                   4467: 	        "<br /><a href=\"$env{'internal.head.redirect'}\">".
                   4468: 	        &mt('Continue').'</a>'.
                   4469: 	        $endbodytag;
                   4470:         }
1.315     albertel 4471:     }
1.251     albertel 4472:     return $endbodytag;
                   4473: }
                   4474: 
1.352     albertel 4475: =pod
                   4476: 
                   4477: =item * &standard_css()
                   4478: 
                   4479: Returns a style sheet
                   4480: 
                   4481: Inputs: (all optional)
                   4482:             domain         -> force to color decorate a page for a specific
                   4483:                                domain
                   4484:             function       -> force usage of a specific rolish color scheme
                   4485:             bgcolor        -> override the default page bgcolor
                   4486: 
                   4487: =cut
                   4488: 
1.343     albertel 4489: sub standard_css {
1.345     albertel 4490:     my ($function,$domain,$bgcolor) = @_;
1.352     albertel 4491:     $function  = &get_users_function() if (!$function);
                   4492:     my $img    = &designparm($function.'.img',   $domain);
                   4493:     my $tabbg  = &designparm($function.'.tabbg', $domain);
                   4494:     my $font   = &designparm($function.'.font',  $domain);
1.791     tempelho 4495: #second colour for later usage
1.345     albertel 4496:     my $sidebg = &designparm($function.'.sidebg',$domain);
1.382     albertel 4497:     my $pgbg_or_bgcolor =
                   4498: 	         $bgcolor ||
1.352     albertel 4499: 	         &designparm($function.'.pgbg',  $domain);
1.382     albertel 4500:     my $pgbg   = &designparm($function.'.pgbg',  $domain);
1.352     albertel 4501:     my $alink  = &designparm($function.'.alink', $domain);
                   4502:     my $vlink  = &designparm($function.'.vlink', $domain);
                   4503:     my $link   = &designparm($function.'.link',  $domain);
                   4504: 
1.704     muellerd 4505:     my $loginbg = &designparm('login.sidebg',$domain);
1.712     muellerd 4506:     my $bgcol = &designparm('login.bgcol',$domain);
                   4507:     my $textcol = &designparm('login.textcol',$domain);
1.704     muellerd 4508: 
1.602     albertel 4509:     my $sans                 = 'Verdana,Arial,Helvetica,sans-serif';
1.395     albertel 4510:     my $mono                 = 'monospace';
1.352     albertel 4511:     my $data_table_head      = $tabbg;
                   4512:     my $data_table_light     = '#EEEEEE';
1.470     banghart 4513:     my $data_table_dark      = '#DDDDDD';
                   4514:     my $data_table_darker    = '#CCCCCC';
1.349     albertel 4515:     my $data_table_highlight = '#FFFF00';
1.352     albertel 4516:     my $mail_new             = '#FFBB77';
                   4517:     my $mail_new_hover       = '#DD9955';
                   4518:     my $mail_read            = '#BBBB77';
                   4519:     my $mail_read_hover      = '#999944';
                   4520:     my $mail_replied         = '#AAAA88';
                   4521:     my $mail_replied_hover   = '#888855';
                   4522:     my $mail_other           = '#99BBBB';
                   4523:     my $mail_other_hover     = '#669999';
1.391     albertel 4524:     my $table_header         = '#DDDDDD';
1.489     raeburn  4525:     my $feedback_link_bg     = '#BBBBBB';
1.701     harmsja  4526:     my $lg_border_color	     = '#C8C8C8';
1.392     albertel 4527: 
1.608     albertel 4528:     my $border = ($env{'browser.type'} eq 'explorer' ||
                   4529: 		  $env{'browser.type'} eq 'safari'     ) ? '0px 2px 0px 2px'
                   4530: 	                                                 : '0px 3px 0px 4px';
1.448     albertel 4531: 
1.523     albertel 4532: 
1.343     albertel 4533:     return <<END;
1.795     www      4534: body {
                   4535:    font-family: $sans;
                   4536:    line-height:130%;
                   4537:    font-size:0.83em;
                   4538:    color:$font;
                   4539: }
                   4540: 
                   4541: a:link, a:visited { 
                   4542:   font-size:100%; 
                   4543: }
                   4544: 
                   4545: a:focus { 
                   4546:   color: red;
                   4547:   background: yellow 
                   4548: }
1.698     harmsja  4549: 
1.510     albertel 4550: table.thinborder,
                   4551: table.thinborder tr th {
                   4552:   border-style: solid;
                   4553:   border-width: 1px;
1.698     harmsja  4554:   border-color: $lg_border_color;
1.510     albertel 4555:   background: $tabbg;
                   4556: }
1.795     www      4557: 
1.523     albertel 4558: table.thinborder tr td {
1.510     albertel 4559:   border-style: solid;
1.698     harmsja  4560:   border-width: 1px;
                   4561:   border-color: $lg_border_color;
1.510     albertel 4562: }
1.426     albertel 4563: 
1.795     www      4564: form, .inline { 
                   4565:    display: inline; 
                   4566: }
1.721     harmsja  4567: 
1.795     www      4568: .LC_right {
                   4569:    text-align:right;
                   4570: }
                   4571: 
                   4572: .LC_middle {
                   4573:    vertical-align:middle;
                   4574: }
1.721     harmsja  4575: 
                   4576: /* just for tests */
1.754     droeschl 4577: .LC_400Box {width:400px; }
1.721     harmsja  4578: /* end */
                   4579: 
1.778     bisitz   4580: .LC_filename {
                   4581:   font-family: $mono;
                   4582:   white-space:pre;
                   4583: }
                   4584: 
                   4585: .LC_fileicon {
                   4586:   border: none;
                   4587:   height: 1.3em;
                   4588:   vertical-align: text-bottom;
                   4589:   margin-right: 0.3em;
                   4590:   text-decoration:none;
                   4591: }
                   4592: 
1.350     albertel 4593: .LC_error {
                   4594:   color: red;
                   4595:   font-size: larger;
                   4596: }
1.795     www      4597: 
1.457     albertel 4598: .LC_warning,
                   4599: .LC_diff_removed {
1.733     bisitz   4600:   color: red;
1.394     albertel 4601: }
1.532     albertel 4602: 
                   4603: .LC_info,
1.457     albertel 4604: .LC_success,
                   4605: .LC_diff_added {
1.350     albertel 4606:   color: green;
                   4607: }
1.795     www      4608: 
1.543     albertel 4609: .LC_unknown {
                   4610:   color: yellow;
                   4611: }
                   4612: 
1.440     albertel 4613: .LC_icon {
1.771     droeschl 4614:   border: none;
1.790     droeschl 4615:   vertical-align: middle;
1.771     droeschl 4616: }
                   4617: 
1.539     albertel 4618: .LC_indexer_icon {
                   4619:   border: 0px;
                   4620:   height: 22px;
                   4621: }
1.795     www      4622: 
1.543     albertel 4623: .LC_docs_spacer {
                   4624:   width: 25px;
                   4625:   height: 1px;
1.771     droeschl 4626:   border: none;
1.543     albertel 4627: }
1.346     albertel 4628: 
1.532     albertel 4629: .LC_internal_info {
1.735     bisitz   4630:   color: #999999;
1.532     albertel 4631: }
                   4632: 
1.794     www      4633: .LC_discussion {
                   4634:    background: $tabbg;
                   4635:    border: 1px solid black;
                   4636:    margin: 2px;
                   4637: }
                   4638: 
                   4639: .LC_disc_action_links_bar {
                   4640:    background: $tabbg;
                   4641:    font-family: $sans;
                   4642:    border: 0px;
1.795     www      4643:    margin: 4px;
1.794     www      4644: }
                   4645: 
                   4646: .LC_disc_action_left {
                   4647:    text-align: left;
                   4648: }
                   4649: 
                   4650: .LC_disc_action_right {
                   4651:    text-align: right;
                   4652: }
                   4653: 
                   4654: .LC_disc_new_item {
                   4655:    background: white;
                   4656:    border: 2px solid red;
                   4657:    margin: 2px;
                   4658: }
                   4659: 
                   4660: .LC_disc_old_item {
                   4661:    background: white;
                   4662:    border: 1px solid black;
                   4663:    margin: 2px;
                   4664: }
                   4665: 
1.458     albertel 4666: table.LC_pastsubmission {
                   4667:   border: 1px solid black;
                   4668:   margin: 2px;
                   4669: }
                   4670: 
1.795     www      4671: table#LC_top_nav,
                   4672: table#LC_menubuttons,
                   4673: table#LC_nav_location {
1.345     albertel 4674:   width: 100%;
                   4675:   background: $pgbg;
1.392     albertel 4676:   border: 2px;
1.402     albertel 4677:   border-collapse: separate;
1.403     albertel 4678:   padding: 0px;
1.345     albertel 4679: }
1.392     albertel 4680: 
1.795     www      4681: table#LC_title_bar,
                   4682: table.LC_breadcrumbs,
1.393     albertel 4683: table#LC_title_bar.LC_with_remote {
1.359     albertel 4684:   width: 100%;
1.392     albertel 4685:   border-color: $pgbg;
                   4686:   border-style: solid;
                   4687:   border-width: $border;
1.379     albertel 4688:   background: $pgbg;
                   4689:   font-family: $sans;
1.392     albertel 4690:   border-collapse: collapse;
1.403     albertel 4691:   padding: 0px;
1.359     albertel 4692: }
1.795     www      4693: 
1.409     albertel 4694: table.LC_docs_path {
                   4695:   width: 100%;
                   4696:   border: 0;
                   4697:   background: $pgbg;
                   4698:   font-family: $sans;
                   4699:   border-collapse: collapse;
                   4700:   padding: 0px;
                   4701: }
                   4702: 
1.359     albertel 4703: table#LC_title_bar td {
                   4704:   background: $tabbg;
                   4705: }
1.795     www      4706: 
1.773     ehlerst  4707: table#LC_title_bar .LC_title_bar_who {
1.359     albertel 4708:   background: $tabbg;
                   4709:   color: $font;
1.427     albertel 4710:   font: small $sans;
1.359     albertel 4711:   text-align: right;
1.773     ehlerst  4712:   margin: 0px;
                   4713: }
1.795     www      4714: 
1.773     ehlerst  4715: table#LC_title_bar .LC_title_bar_name {
                   4716:   margin: 0px;
                   4717: }
1.795     www      4718: 
1.773     ehlerst  4719: table#LC_title_bar .LC_title_bar_role {
                   4720:   margin: 0px;
                   4721: }
1.795     www      4722: 
1.775     bisitz   4723: table#LC_title_bar .LC_title_bar_realm {
1.773     ehlerst  4724:   margin: 0px;
1.359     albertel 4725: }
1.795     www      4726: 
1.469     banghart 4727: span.LC_metadata {
1.795     www      4728:   font-family: $sans;
1.469     banghart 4729: }
1.359     albertel 4730: 
1.706     harmsja  4731: table#LC_menubuttons img{
1.346     albertel 4732:   border: 0px;
                   4733: }
1.795     www      4734: 
1.345     albertel 4735: table#LC_top_nav td {
                   4736:   background: $tabbg;
1.392     albertel 4737:   border: 0px;
1.407     albertel 4738:   font-size: small;
1.706     harmsja  4739:   vertical-align:top;
                   4740:   padding:2px 5px 2px 5px;
1.345     albertel 4741: }
1.795     www      4742: 
                   4743: table#LC_top_nav td a,
                   4744: div#LC_top_nav a {
1.345     albertel 4745:   color: $font;
                   4746:   font-family: $sans;
                   4747: }
1.795     www      4748: 
1.364     albertel 4749: table#LC_top_nav td.LC_top_nav_logo {
                   4750:   background: $tabbg;
1.432     albertel 4751:   text-align: left;
1.408     albertel 4752:   white-space: nowrap;
1.432     albertel 4753:   width: 31px;
1.408     albertel 4754: }
1.795     www      4755: 
1.408     albertel 4756: table#LC_top_nav td.LC_top_nav_logo img {
1.432     albertel 4757:   border: 0px;
1.408     albertel 4758:   vertical-align: bottom;
1.364     albertel 4759: }
1.795     www      4760: 
1.777     tempelho 4761: table#LC_top_nav td.LC_top_nav_exit,
1.779     bisitz   4762: table#LC_top_nav td.LC_top_nav_help {
1.777     tempelho 4763:   width: 2.0em;
                   4764: }
1.795     www      4765: 
1.442     albertel 4766: table#LC_top_nav td.LC_top_nav_login {
                   4767:   width: 4.0em;
                   4768:   text-align: center;
                   4769: }
1.795     www      4770: 
                   4771: table.LC_breadcrumbs td,
                   4772: table.LC_docs_path td  {
1.357     albertel 4773:   background: $tabbg;
                   4774:   color: $font;
                   4775:   font-family: $sans;
1.358     albertel 4776:   font-size: smaller;
1.357     albertel 4777: }
1.795     www      4778: 
1.777     tempelho 4779: table.LC_breadcrumbs td.LC_breadcrumbs_component,
                   4780: table.LC_docs_path td.LC_docs_path_component {
1.779     bisitz   4781:   background: $tabbg;
1.777     tempelho 4782:   color: $font;
                   4783:   font-family: $sans;
1.779     bisitz   4784:   font-size: larger;
                   4785:   text-align: right;
1.777     tempelho 4786: }
1.795     www      4787: 
1.383     albertel 4788: td.LC_table_cell_checkbox {
                   4789:   text-align: center;
                   4790: }
1.795     www      4791: 
1.779     bisitz   4792: table#LC_mainmenu td.LC_mainmenu_column {
                   4793:     vertical-align: top;
1.777     tempelho 4794: }
1.522     albertel 4795: 
1.795     www      4796: .LC_fontsize_small {
1.705     tempelho 4797:  font-size: 70%;
                   4798: }
                   4799: 
1.795     www      4800: .LC_fontsize_medium {
1.705     tempelho 4801:  font-size: 85%;
                   4802: }
                   4803: 
1.795     www      4804: .LC_fontsize_large {
1.705     tempelho 4805:  font-size: 120%;
                   4806: }
                   4807: 
1.346     albertel 4808: .LC_menubuttons_inline_text {
                   4809:   color: $font;
                   4810:   font-family: $sans;
1.698     harmsja  4811:   font-size: 90%;
1.701     harmsja  4812:   padding-left:3px;
1.346     albertel 4813: }
                   4814: 
1.526     www      4815: .LC_menubuttons_link {
                   4816:   text-decoration: none;
                   4817: }
1.795     www      4818: 
1.522     albertel 4819: .LC_menubuttons_category {
1.521     www      4820:   color: $font;
1.526     www      4821:   background: $pgbg;
1.521     www      4822:   font-family: $sans;
                   4823:   font-size: larger;
                   4824:   font-weight: bold;
                   4825: }
                   4826: 
1.346     albertel 4827: td.LC_menubuttons_text {
1.779     bisitz   4828:  	color: $font;
1.346     albertel 4829: }
1.706     harmsja  4830: 
1.346     albertel 4831: .LC_current_location {
                   4832:   font-family: $sans;
                   4833:   background: $tabbg;
                   4834: }
1.795     www      4835: 
1.346     albertel 4836: .LC_new_mail {
                   4837:   font-family: $sans;
1.634     www      4838:   background: $tabbg;
1.346     albertel 4839:   font-weight: bold;
                   4840: }
1.347     albertel 4841: 
1.527     www      4842: .LC_dropadd_labeltext {
                   4843:   font-family: $sans;
                   4844:   text-align: right;
                   4845: }
                   4846: 
                   4847: .LC_preferences_labeltext {
                   4848:   font-family: $sans;
                   4849:   text-align: right;
                   4850: }
                   4851: 
1.666     raeburn  4852: .LC_roleslog_note {
1.701     harmsja  4853:   font-size: small;
1.666     raeburn  4854: }
                   4855: 
1.715     raeburn  4856: .LC_mail_functions {
                   4857:     font-weight: bold;
                   4858: }
                   4859: 
1.440     albertel 4860: table.LC_aboutme_port {
                   4861:   border: 0px;
                   4862:   border-collapse: collapse;
                   4863:   border-spacing: 0px;
                   4864: }
1.795     www      4865: 
                   4866: table.LC_data_table,
                   4867: table.LC_mail_list {
1.347     albertel 4868:   border: 1px solid #000000;
1.402     albertel 4869:   border-collapse: separate;
1.426     albertel 4870:   border-spacing: 1px;
1.610     albertel 4871:   background: $pgbg;
1.347     albertel 4872: }
1.795     www      4873: 
1.422     albertel 4874: .LC_data_table_dense {
                   4875:   font-size: small;
                   4876: }
1.795     www      4877: 
1.507     raeburn  4878: table.LC_nested_outer {
                   4879:   border: 1px solid #000000;
1.589     raeburn  4880:   border-collapse: collapse;
1.507     raeburn  4881:   border-spacing: 0px;
                   4882:   width: 100%;
                   4883: }
1.795     www      4884: 
1.507     raeburn  4885: table.LC_nested {
                   4886:   border: 0px;
1.589     raeburn  4887:   border-collapse: collapse;
1.507     raeburn  4888:   border-spacing: 0px;
                   4889:   width: 100%;
                   4890: }
1.795     www      4891: 
                   4892: table.LC_data_table tr th, 
                   4893: table.LC_calendar tr th, 
                   4894: table.LC_mail_list tr th,
1.523     albertel 4895: table.LC_prior_tries tr th {
1.349     albertel 4896:   font-weight: bold;
                   4897:   background-color: $data_table_head;
1.701     harmsja  4898:   font-size:90%;
1.347     albertel 4899: }
1.795     www      4900: 
1.711     raeburn  4901: table.LC_data_table tr.LC_info_row > td {
1.735     bisitz   4902:   background-color: #CCCCCC;
1.711     raeburn  4903:   font-weight: bold;
                   4904:   text-align: left;
                   4905: }
1.795     www      4906: 
1.779     bisitz   4907: table.LC_data_table tr.LC_odd_row > td,
1.709     bisitz   4908: table.LC_pick_box tr > td.LC_odd_row,
1.440     albertel 4909: table.LC_aboutme_port tr td {
1.349     albertel 4910:   background-color: $data_table_light;
1.425     albertel 4911:   padding: 2px;
1.347     albertel 4912: }
1.795     www      4913: 
1.610     albertel 4914: table.LC_data_table tr.LC_even_row > td,
1.709     bisitz   4915: table.LC_pick_box tr > td.LC_even_row,
1.440     albertel 4916: table.LC_aboutme_port tr.LC_even_row td {
1.349     albertel 4917:   background-color: $data_table_dark;
1.709     bisitz   4918:   padding: 2px;
1.347     albertel 4919: }
1.795     www      4920: 
1.425     albertel 4921: table.LC_data_table tr.LC_data_table_highlight td {
                   4922:   background-color: $data_table_darker;
                   4923: }
1.795     www      4924: 
1.639     raeburn  4925: table.LC_data_table tr td.LC_leftcol_header {
                   4926:   background-color: $data_table_head;
                   4927:   font-weight: bold;
                   4928: }
1.795     www      4929: 
1.451     albertel 4930: table.LC_data_table tr.LC_empty_row td,
1.507     raeburn  4931: table.LC_nested tr.LC_empty_row td {
1.347     albertel 4932:   background-color: #FFFFFF;
1.421     albertel 4933:   font-weight: bold;
                   4934:   font-style: italic;
                   4935:   text-align: center;
                   4936:   padding: 8px;
1.347     albertel 4937: }
1.795     www      4938: 
1.507     raeburn  4939: table.LC_nested tr.LC_empty_row td {
1.465     albertel 4940:   padding: 4ex
                   4941: }
1.795     www      4942: 
1.507     raeburn  4943: table.LC_nested_outer tr th {
                   4944:   font-weight: bold;
                   4945:   background-color: $data_table_head;
1.701     harmsja  4946:   font-size: small;
1.507     raeburn  4947:   border-bottom: 1px solid #000000;
                   4948: }
1.795     www      4949: 
1.507     raeburn  4950: table.LC_nested_outer tr td.LC_subheader {
                   4951:   background-color: $data_table_head;
                   4952:   font-weight: bold;
                   4953:   font-size: small;
                   4954:   border-bottom: 1px solid #000000;
                   4955:   text-align: right;
1.451     albertel 4956: }
1.795     www      4957: 
1.507     raeburn  4958: table.LC_nested tr.LC_info_row td {
1.735     bisitz   4959:   background-color: #CCCCCC;
1.451     albertel 4960:   font-weight: bold;
                   4961:   font-size: small;
1.507     raeburn  4962:   text-align: center;
                   4963: }
1.795     www      4964: 
1.589     raeburn  4965: table.LC_nested tr.LC_info_row td.LC_left_item,
                   4966: table.LC_nested_outer tr th.LC_left_item {
1.507     raeburn  4967:   text-align: left;
1.451     albertel 4968: }
1.795     www      4969: 
1.507     raeburn  4970: table.LC_nested td {
1.735     bisitz   4971:   background-color: #FFFFFF;
1.451     albertel 4972:   font-size: small;
1.507     raeburn  4973: }
1.795     www      4974: 
1.507     raeburn  4975: table.LC_nested_outer tr th.LC_right_item,
                   4976: table.LC_nested tr.LC_info_row td.LC_right_item,
                   4977: table.LC_nested tr.LC_odd_row td.LC_right_item,
                   4978: table.LC_nested tr td.LC_right_item {
1.451     albertel 4979:   text-align: right;
                   4980: }
                   4981: 
1.507     raeburn  4982: table.LC_nested tr.LC_odd_row td {
1.735     bisitz   4983:   background-color: #EEEEEE;
1.451     albertel 4984: }
                   4985: 
1.473     raeburn  4986: table.LC_createuser {
                   4987: }
                   4988: 
                   4989: table.LC_createuser tr.LC_section_row td {
1.701     harmsja  4990:   font-size: small;
1.473     raeburn  4991: }
                   4992: 
                   4993: table.LC_createuser tr.LC_info_row td  {
1.735     bisitz   4994:   background-color: #CCCCCC;
1.473     raeburn  4995:   font-weight: bold;
                   4996:   text-align: center;
                   4997: }
                   4998: 
1.349     albertel 4999: table.LC_calendar {
                   5000:   border: 1px solid #000000;
                   5001:   border-collapse: collapse;
                   5002: }
1.795     www      5003: 
1.349     albertel 5004: table.LC_calendar_pickdate {
                   5005:   font-size: xx-small;
                   5006: }
1.795     www      5007: 
1.349     albertel 5008: table.LC_calendar tr td {
                   5009:   border: 1px solid #000000;
                   5010:   vertical-align: top;
                   5011: }
1.795     www      5012: 
1.349     albertel 5013: table.LC_calendar tr td.LC_calendar_day_empty {
                   5014:   background-color: $data_table_dark;
                   5015: }
1.795     www      5016: 
1.779     bisitz   5017: table.LC_calendar tr td.LC_calendar_day_current {
                   5018:   background-color: $data_table_highlight;
1.777     tempelho 5019: }
1.795     www      5020: 
1.349     albertel 5021: table.LC_mail_list tr.LC_mail_new {
                   5022:   background-color: $mail_new;
                   5023: }
1.795     www      5024: 
1.349     albertel 5025: table.LC_mail_list tr.LC_mail_new:hover {
                   5026:   background-color: $mail_new_hover;
                   5027: }
1.795     www      5028: 
                   5029: table.LC_mail_list tr.LC_mail_even {
1.777     tempelho 5030: }
1.795     www      5031: 
                   5032: table.LC_mail_list tr.LC_mail_odd {
1.777     tempelho 5033: }
1.795     www      5034: 
1.349     albertel 5035: table.LC_mail_list tr.LC_mail_read {
                   5036:   background-color: $mail_read;
                   5037: }
1.795     www      5038: 
1.349     albertel 5039: table.LC_mail_list tr.LC_mail_read:hover {
                   5040:   background-color: $mail_read_hover;
                   5041: }
1.795     www      5042: 
1.349     albertel 5043: table.LC_mail_list tr.LC_mail_replied {
                   5044:   background-color: $mail_replied;
                   5045: }
1.795     www      5046: 
1.349     albertel 5047: table.LC_mail_list tr.LC_mail_replied:hover {
                   5048:   background-color: $mail_replied_hover;
                   5049: }
1.795     www      5050: 
1.349     albertel 5051: table.LC_mail_list tr.LC_mail_other {
                   5052:   background-color: $mail_other;
                   5053: }
1.795     www      5054: 
1.349     albertel 5055: table.LC_mail_list tr.LC_mail_other:hover {
                   5056:   background-color: $mail_other_hover;
                   5057: }
1.494     raeburn  5058: 
1.777     tempelho 5059: table.LC_data_table tr > td.LC_browser_file,
                   5060: table.LC_data_table tr > td.LC_browser_file_published {
1.389     albertel 5061:   background: #CCFF88;
                   5062: }
1.795     www      5063: 
1.777     tempelho 5064: table.LC_data_table tr > td.LC_browser_file_locked,
                   5065: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389     albertel 5066:   background: #FFAA99;
1.387     albertel 5067: }
1.795     www      5068: 
1.777     tempelho 5069: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.779     bisitz   5070:   background: #AAAAAA;
                   5071: }
1.795     www      5072: 
1.777     tempelho 5073: table.LC_data_table tr > td.LC_browser_file_modified,
1.779     bisitz   5074: table.LC_data_table tr > td.LC_browser_file_metamodified {
                   5075:   background: #FFFF77;
1.777     tempelho 5076: }
1.795     www      5077: 
1.696     bisitz   5078: table.LC_data_table tr.LC_browser_folder > td {
1.389     albertel 5079:   background: #CCCCFF;
1.387     albertel 5080: }
1.696     bisitz   5081: 
1.707     bisitz   5082: table.LC_data_table tr > td.LC_roles_is {
                   5083: /*  background: #77FF77; */
                   5084: }
1.795     www      5085: 
1.707     bisitz   5086: table.LC_data_table tr > td.LC_roles_future {
                   5087:   background: #FFFF77;
                   5088: }
1.795     www      5089: 
1.707     bisitz   5090: table.LC_data_table tr > td.LC_roles_will {
                   5091:   background: #FFAA77;
                   5092: }
1.795     www      5093: 
1.707     bisitz   5094: table.LC_data_table tr > td.LC_roles_expired {
                   5095:   background: #FF7777;
                   5096: }
1.795     www      5097: 
1.707     bisitz   5098: table.LC_data_table tr > td.LC_roles_will_not {
                   5099:   background: #AAFF77;
                   5100: }
1.795     www      5101: 
1.707     bisitz   5102: table.LC_data_table tr > td.LC_roles_selected {
                   5103:   background: #11CC55;
                   5104: }
                   5105: 
1.388     albertel 5106: span.LC_current_location {
1.701     harmsja  5107:   font-size:larger;
1.388     albertel 5108:   background: $pgbg;
                   5109: }
1.387     albertel 5110: 
1.395     albertel 5111: span.LC_parm_menu_item {
                   5112:   font-size: larger;
                   5113:   font-family: $sans;
                   5114: }
1.795     www      5115: 
1.395     albertel 5116: span.LC_parm_scope_all {
                   5117:   color: red;
                   5118: }
1.795     www      5119: 
1.395     albertel 5120: span.LC_parm_scope_folder {
                   5121:   color: green;
                   5122: }
1.795     www      5123: 
1.395     albertel 5124: span.LC_parm_scope_resource {
                   5125:   color: orange;
                   5126: }
1.795     www      5127: 
1.395     albertel 5128: span.LC_parm_part {
                   5129:   color: blue;
                   5130: }
1.795     www      5131: 
1.395     albertel 5132: span.LC_parm_folder, span.LC_parm_symb {
                   5133:   font-size: x-small;
                   5134:   font-family: $mono;
                   5135:   color: #AAAAAA;
                   5136: }
                   5137: 
1.795     www      5138: td.LC_parm_overview_level_menu,
                   5139: td.LC_parm_overview_map_menu,
                   5140: td.LC_parm_overview_parm_selectors,
                   5141: td.LC_parm_overview_restrictions  {
1.396     albertel 5142:   border: 1px solid black;
                   5143:   border-collapse: collapse;
                   5144: }
1.795     www      5145: 
1.396     albertel 5146: table.LC_parm_overview_restrictions td {
                   5147:   border-width: 1px 4px 1px 4px;
                   5148:   border-style: solid;
                   5149:   border-color: $pgbg;
                   5150:   text-align: center;
                   5151: }
1.795     www      5152: 
1.396     albertel 5153: table.LC_parm_overview_restrictions th {
                   5154:   background: $tabbg;
                   5155:   border-width: 1px 4px 1px 4px;
                   5156:   border-style: solid;
                   5157:   border-color: $pgbg;
                   5158: }
1.795     www      5159: 
1.398     albertel 5160: table#LC_helpmenu {
                   5161:   border: 0px;
                   5162:   height: 55px;
                   5163:   border-spacing: 0px;
                   5164: }
                   5165: 
                   5166: table#LC_helpmenu fieldset legend {
                   5167:   font-size: larger;
                   5168:   font-weight: bold;
                   5169: }
1.795     www      5170: 
1.397     albertel 5171: table#LC_helpmenu_links {
                   5172:   width: 100%;
                   5173:   border: 1px solid black;
                   5174:   background: $pgbg;
                   5175:   padding: 0px;
                   5176:   border-spacing: 1px;
                   5177: }
1.795     www      5178: 
1.397     albertel 5179: table#LC_helpmenu_links tr td {
                   5180:   padding: 1px;
                   5181:   background: $tabbg;
1.399     albertel 5182:   text-align: center;
                   5183:   font-weight: bold;
1.397     albertel 5184: }
1.396     albertel 5185: 
1.795     www      5186: table#LC_helpmenu_links a:link,
                   5187: table#LC_helpmenu_links a:visited,
1.397     albertel 5188: table#LC_helpmenu_links a:active {
                   5189:   text-decoration: none;
                   5190:   color: $font;
                   5191: }
1.795     www      5192: 
1.397     albertel 5193: table#LC_helpmenu_links a:hover {
                   5194:   text-decoration: underline;
                   5195:   color: $vlink;
                   5196: }
1.396     albertel 5197: 
1.417     albertel 5198: .LC_chrt_popup_exists {
                   5199:   border: 1px solid #339933;
                   5200:   margin: -1px;
                   5201: }
1.795     www      5202: 
1.417     albertel 5203: .LC_chrt_popup_up {
                   5204:   border: 1px solid yellow;
                   5205:   margin: -1px;
                   5206: }
1.795     www      5207: 
1.417     albertel 5208: .LC_chrt_popup {
                   5209:   border: 1px solid #8888FF;
                   5210:   background: #CCCCFF;
                   5211: }
1.795     www      5212: 
1.421     albertel 5213: table.LC_pick_box {
                   5214:   border-collapse: separate;
                   5215:   background: white;
                   5216:   border: 1px solid black;
                   5217:   border-spacing: 1px;
                   5218: }
1.795     www      5219: 
1.421     albertel 5220: table.LC_pick_box td.LC_pick_box_title {
                   5221:   background: $tabbg;
                   5222:   font-weight: bold;
                   5223:   text-align: right;
1.740     bisitz   5224:   vertical-align: top;
1.421     albertel 5225:   width: 184px;
                   5226:   padding: 8px;
                   5227: }
1.795     www      5228: 
1.645     raeburn  5229: table.LC_pick_box td.LC_selfenroll_pick_box_title {
                   5230:   background: $tabbg;
                   5231:   font-weight: bold;
                   5232:   text-align: right;
                   5233:   width: 350px;
                   5234:   padding: 8px;
                   5235: }
                   5236: 
1.579     raeburn  5237: table.LC_pick_box td.LC_pick_box_value {
                   5238:   text-align: left;
                   5239:   padding: 8px;
                   5240: }
1.795     www      5241: 
1.579     raeburn  5242: table.LC_pick_box td.LC_pick_box_select {
                   5243:   text-align: left;
                   5244:   padding: 8px;
                   5245: }
1.795     www      5246: 
1.424     albertel 5247: table.LC_pick_box td.LC_pick_box_separator {
1.421     albertel 5248:   padding: 0px;
                   5249:   height: 1px;
                   5250:   background: black;
                   5251: }
1.795     www      5252: 
1.421     albertel 5253: table.LC_pick_box td.LC_pick_box_submit {
                   5254:   text-align: right;
                   5255: }
1.795     www      5256: 
1.579     raeburn  5257: table.LC_pick_box td.LC_evenrow_value {
                   5258:   text-align: left;
                   5259:   padding: 8px;
                   5260:   background-color: $data_table_light;
                   5261: }
1.795     www      5262: 
1.579     raeburn  5263: table.LC_pick_box td.LC_oddrow_value {
                   5264:   text-align: left;
                   5265:   padding: 8px;
                   5266:   background-color: $data_table_light;
                   5267: }
1.795     www      5268: 
1.579     raeburn  5269: table.LC_helpform_receipt {
                   5270:   width: 620px;
                   5271:   border-collapse: separate;
                   5272:   background: white;
                   5273:   border: 1px solid black;
                   5274:   border-spacing: 1px;
                   5275: }
1.795     www      5276: 
1.579     raeburn  5277: table.LC_helpform_receipt td.LC_pick_box_title {
                   5278:   background: $tabbg;
                   5279:   font-weight: bold;
                   5280:   text-align: right;
                   5281:   width: 184px;
                   5282:   padding: 8px;
                   5283: }
1.795     www      5284: 
1.579     raeburn  5285: table.LC_helpform_receipt td.LC_evenrow_value {
                   5286:   text-align: left;
                   5287:   padding: 8px;
                   5288:   background-color: $data_table_light;
                   5289: }
1.795     www      5290: 
1.579     raeburn  5291: table.LC_helpform_receipt td.LC_oddrow_value {
                   5292:   text-align: left;
                   5293:   padding: 8px;
                   5294:   background-color: $data_table_light;
                   5295: }
1.795     www      5296: 
1.579     raeburn  5297: table.LC_helpform_receipt td.LC_pick_box_separator {
                   5298:   padding: 0px;
                   5299:   height: 1px;
                   5300:   background: black;
                   5301: }
1.795     www      5302: 
1.579     raeburn  5303: span.LC_helpform_receipt_cat {
                   5304:   font-weight: bold;
                   5305: }
1.795     www      5306: 
1.424     albertel 5307: table.LC_group_priv_box {
                   5308:   background: white;
                   5309:   border: 1px solid black;
                   5310:   border-spacing: 1px;
                   5311: }
1.795     www      5312: 
1.424     albertel 5313: table.LC_group_priv_box td.LC_pick_box_title {
                   5314:   background: $tabbg;
                   5315:   font-weight: bold;
                   5316:   text-align: right;
                   5317:   width: 184px;
                   5318: }
1.795     www      5319: 
1.424     albertel 5320: table.LC_group_priv_box td.LC_groups_fixed {
                   5321:   background: $data_table_light;
                   5322:   text-align: center;
                   5323: }
1.795     www      5324: 
1.424     albertel 5325: table.LC_group_priv_box td.LC_groups_optional {
                   5326:   background: $data_table_dark;
                   5327:   text-align: center;
                   5328: }
1.795     www      5329: 
1.424     albertel 5330: table.LC_group_priv_box td.LC_groups_functionality {
                   5331:   background: $data_table_darker;
                   5332:   text-align: center;
                   5333:   font-weight: bold;
                   5334: }
1.795     www      5335: 
1.424     albertel 5336: table.LC_group_priv td {
                   5337:   text-align: left;
                   5338:   padding: 0px;
                   5339: }
                   5340: 
1.421     albertel 5341: table.LC_notify_front_page {
                   5342:   background: white;
                   5343:   border: 1px solid black;
                   5344:   padding: 8px;
                   5345: }
1.795     www      5346: 
1.421     albertel 5347: table.LC_notify_front_page td {
                   5348:   padding: 8px;
                   5349: }
1.795     www      5350: 
1.424     albertel 5351: .LC_navbuttons {
                   5352:   margin: 2ex 0ex 2ex 0ex;
                   5353: }
1.795     www      5354: 
1.423     albertel 5355: .LC_topic_bar {
                   5356:   font-family: $sans;
                   5357:   font-weight: bold;
                   5358:   width: 100%;
                   5359:   background: $tabbg;
                   5360:   vertical-align: middle;
                   5361:   margin: 2ex 0ex 2ex 0ex;
                   5362: }
1.795     www      5363: 
1.423     albertel 5364: .LC_topic_bar span {
                   5365:   vertical-align: middle;
                   5366: }
1.795     www      5367: 
1.423     albertel 5368: .LC_topic_bar img {
                   5369:   vertical-align: bottom;
                   5370: }
1.795     www      5371: 
1.423     albertel 5372: table.LC_course_group_status {
                   5373:   margin: 20px;
                   5374: }
1.795     www      5375: 
1.423     albertel 5376: table.LC_status_selector td {
                   5377:   vertical-align: top;
                   5378:   text-align: center;
1.424     albertel 5379:   padding: 4px;
                   5380: }
1.795     www      5381: 
1.424     albertel 5382: table.LC_descriptive_input td.LC_description {
                   5383:   vertical-align: top;
                   5384:   text-align: right;
                   5385:   font-weight: bold;
1.423     albertel 5386: }
1.795     www      5387: 
1.599     albertel 5388: div.LC_feedback_link {
1.616     albertel 5389:   clear: both;
1.599     albertel 5390:   background: white;
1.779     bisitz   5391:   width: 100%;
1.489     raeburn  5392: }
1.795     www      5393: 
1.489     raeburn  5394: span.LC_feedback_link {
1.599     albertel 5395:   background: $feedback_link_bg;
                   5396:   font-size: larger;
                   5397: }
1.795     www      5398: 
1.599     albertel 5399: span.LC_message_link {
                   5400:   background: $feedback_link_bg;
                   5401:   font-size: larger;
                   5402:   position: absolute;
                   5403:   right: 1em;
1.489     raeburn  5404: }
1.421     albertel 5405: 
1.515     albertel 5406: table.LC_prior_tries {
1.524     albertel 5407:   border: 1px solid #000000;
                   5408:   border-collapse: separate;
                   5409:   border-spacing: 1px;
1.515     albertel 5410: }
1.523     albertel 5411: 
1.515     albertel 5412: table.LC_prior_tries td {
1.524     albertel 5413:   padding: 2px;
1.515     albertel 5414: }
1.523     albertel 5415: 
                   5416: .LC_answer_correct {
1.795     www      5417:   background: lightgreen;
                   5418:   font-family: $sans;
                   5419:   color: darkgreen;
                   5420:   padding: 6px;
1.523     albertel 5421: }
1.795     www      5422: 
1.523     albertel 5423: .LC_answer_charged_try {
1.797     www      5424:   background: #FFAAAA;
1.795     www      5425:   font-family: $sans;
                   5426:   color: darkred;
                   5427:   padding: 6px;
1.523     albertel 5428: }
1.795     www      5429: 
1.779     bisitz   5430: .LC_answer_not_charged_try,
1.523     albertel 5431: .LC_answer_no_grade,
                   5432: .LC_answer_late {
1.795     www      5433:   background: lightyellow;
                   5434:   font-family: $sans;
1.523     albertel 5435:   color: black;
1.795     www      5436:   padding: 6px;
1.523     albertel 5437: }
1.795     www      5438: 
1.523     albertel 5439: .LC_answer_previous {
1.795     www      5440:   background: lightblue;
                   5441:   font-family: $sans;
                   5442:   color: darkblue;
                   5443:   padding: 6px;
1.523     albertel 5444: }
1.795     www      5445: 
1.779     bisitz   5446: .LC_answer_no_message {
1.777     tempelho 5447:   background: #FFFFFF;
1.795     www      5448:   font-family: $sans;
1.777     tempelho 5449:   color: black;
1.795     www      5450:   padding: 6px;
1.779     bisitz   5451: }
1.795     www      5452: 
1.779     bisitz   5453: .LC_answer_unknown {
                   5454:   background: orange;
1.795     www      5455:   font-family: $sans;
1.779     bisitz   5456:   color: black;
1.795     www      5457:   padding: 6px;
1.777     tempelho 5458: }
1.795     www      5459: 
1.529     albertel 5460: span.LC_prior_numerical,
                   5461: span.LC_prior_string,
                   5462: span.LC_prior_custom,
                   5463: span.LC_prior_reaction,
                   5464: span.LC_prior_math {
1.523     albertel 5465:   font-family: monospace;
                   5466:   white-space: pre;
                   5467: }
                   5468: 
1.525     albertel 5469: span.LC_prior_string {
                   5470:   font-family: monospace;
                   5471:   white-space: pre;
                   5472: }
                   5473: 
1.523     albertel 5474: table.LC_prior_option {
                   5475:   width: 100%;
                   5476:   border-collapse: collapse;
                   5477: }
1.795     www      5478: 
                   5479: table.LC_prior_rank, 
                   5480: table.LC_prior_match {
1.528     albertel 5481:   border-collapse: collapse;
                   5482: }
1.795     www      5483: 
1.528     albertel 5484: table.LC_prior_option tr td,
                   5485: table.LC_prior_rank tr td,
                   5486: table.LC_prior_match tr td {
1.524     albertel 5487:   border: 1px solid #000000;
1.515     albertel 5488: }
                   5489: 
1.770     droeschl 5490: td.LC_nobreak,
1.519     raeburn  5491: span.LC_nobreak {
1.544     albertel 5492:   white-space: nowrap;
1.519     raeburn  5493: }
                   5494: 
1.576     raeburn  5495: span.LC_cusr_emph {
                   5496:   font-style: italic;
                   5497: }
                   5498: 
1.633     raeburn  5499: span.LC_cusr_subheading {
                   5500:   font-weight: normal;
                   5501:   font-size: 85%;
                   5502: }
                   5503: 
1.545     albertel 5504: table.LC_docs_documents {
                   5505:   background: #BBBBBB;
1.547     albertel 5506:   border-width: 0px;
1.545     albertel 5507:   border-collapse: collapse;
                   5508: }
1.795     www      5509: 
1.777     tempelho 5510: table.LC_docs_documents td.LC_docs_document {
1.779     bisitz   5511:   border: 2px solid black;
                   5512:   padding: 4px;
1.777     tempelho 5513: }
1.795     www      5514: 
1.545     albertel 5515: .LC_docs_entry_move {
                   5516:   border: 0px;
                   5517:   border-collapse: collapse;
1.544     albertel 5518: }
                   5519: 
1.545     albertel 5520: .LC_docs_entry_move td {
                   5521:   border: 2px solid #BBBBBB;
                   5522:   background: #DDDDDD;
                   5523: }
                   5524: 
                   5525: .LC_docs_editor td.LC_docs_entry_commands {
                   5526:   background: #DDDDDD;
                   5527:   font-size: x-small;
                   5528: }
1.795     www      5529: 
1.544     albertel 5530: .LC_docs_copy {
1.545     albertel 5531:   color: #000099;
1.544     albertel 5532: }
1.795     www      5533: 
1.544     albertel 5534: .LC_docs_cut {
1.545     albertel 5535:   color: #550044;
1.544     albertel 5536: }
1.795     www      5537: 
1.544     albertel 5538: .LC_docs_rename {
1.545     albertel 5539:   color: #009900;
1.544     albertel 5540: }
1.795     www      5541: 
1.544     albertel 5542: .LC_docs_remove {
1.545     albertel 5543:   color: #990000;
                   5544: }
                   5545: 
1.547     albertel 5546: .LC_docs_reinit_warn,
                   5547: .LC_docs_ext_edit {
                   5548:   font-size: x-small;
                   5549: }
                   5550: 
1.545     albertel 5551: .LC_docs_editor td.LC_docs_entry_title,
                   5552: .LC_docs_editor td.LC_docs_entry_icon {
                   5553:   background: #FFFFBB;
                   5554: }
1.795     www      5555: 
1.545     albertel 5556: .LC_docs_editor td.LC_docs_entry_parameter {
                   5557:   background: #BBBBFF;
                   5558:   font-size: x-small;
                   5559:   white-space: nowrap;
                   5560: }
                   5561: 
                   5562: table.LC_docs_adddocs td,
                   5563: table.LC_docs_adddocs th {
                   5564:   border: 1px solid #BBBBBB;
                   5565:   padding: 4px;
                   5566:   background: #DDDDDD;
1.543     albertel 5567: }
                   5568: 
1.584     albertel 5569: table.LC_sty_begin {
                   5570:   background: #BBFFBB;
                   5571: }
1.795     www      5572: 
1.584     albertel 5573: table.LC_sty_end {
                   5574:   background: #FFBBBB;
                   5575: }
                   5576: 
1.589     raeburn  5577: table.LC_double_column {
                   5578:   border-width: 0px;
                   5579:   border-collapse: collapse;
                   5580:   width: 100%;
                   5581:   padding: 2px;
                   5582: }
                   5583: 
                   5584: table.LC_double_column tr td.LC_left_col {
1.590     raeburn  5585:   top: 2px;
1.589     raeburn  5586:   left: 2px;
                   5587:   width: 47%;
                   5588:   vertical-align: top;
                   5589: }
                   5590: 
                   5591: table.LC_double_column tr td.LC_right_col {
                   5592:   top: 2px;
1.779     bisitz   5593:   right: 2px;
1.589     raeburn  5594:   width: 47%;
                   5595:   vertical-align: top;
                   5596: }
                   5597: 
1.594     raeburn  5598: span.LC_role_level {
                   5599:   font-weight: bold;
                   5600: }
                   5601: 
1.591     raeburn  5602: div.LC_left_float {
                   5603:   float: left;
                   5604:   padding-right: 5%;
1.597     albertel 5605:   padding-bottom: 4px;
1.591     raeburn  5606: }
                   5607: 
                   5608: div.LC_clear_float_header {
1.597     albertel 5609:   padding-bottom: 2px;
1.591     raeburn  5610: }
                   5611: 
                   5612: div.LC_clear_float_footer {
1.597     albertel 5613:   padding-top: 10px;
1.591     raeburn  5614:   clear: both;
                   5615: }
                   5616: 
1.597     albertel 5617: div.LC_grade_show_user {
                   5618:   margin-top: 20px;
                   5619:   border: 1px solid black;
                   5620: }
1.795     www      5621: 
1.597     albertel 5622: div.LC_grade_user_name {
                   5623:   background: #DDDDEE;
                   5624:   border-bottom: 1px solid black;
1.705     tempelho 5625:   font-weight: bold;
                   5626:   font-size: large;
1.597     albertel 5627: }
1.795     www      5628: 
1.597     albertel 5629: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
                   5630:   background: #DDEEDD;
                   5631: }
                   5632: 
                   5633: div.LC_grade_show_problem,
                   5634: div.LC_grade_submissions,
                   5635: div.LC_grade_message_center,
                   5636: div.LC_grade_info_links,
                   5637: div.LC_grade_assign {
                   5638:   margin: 5px;
                   5639:   width: 99%;
                   5640:   background: #FFFFFF;
                   5641: }
1.795     www      5642: 
1.597     albertel 5643: div.LC_grade_show_problem_header,
                   5644: div.LC_grade_submissions_header,
                   5645: div.LC_grade_message_center_header,
                   5646: div.LC_grade_assign_header {
1.705     tempelho 5647:   font-weight: bold;
                   5648:   font-size: large;
1.597     albertel 5649: }
1.795     www      5650: 
1.597     albertel 5651: div.LC_grade_show_problem_problem,
                   5652: div.LC_grade_submissions_body,
                   5653: div.LC_grade_message_center_body,
                   5654: div.LC_grade_assign_body {
                   5655:   border: 1px solid black;
                   5656:   width: 99%;
                   5657:   background: #FFFFFF;
                   5658: }
1.795     www      5659: 
1.598     albertel 5660: span.LC_grade_check_note {
1.705     tempelho 5661:   font-weight: normal;
                   5662:   font-size: medium;
1.598     albertel 5663:   display: inline;
                   5664:   position: absolute;
                   5665:   right: 1em;
                   5666: }
1.597     albertel 5667: 
1.613     albertel 5668: table.LC_scantron_action {
                   5669:   width: 100%;
                   5670: }
1.795     www      5671: 
1.613     albertel 5672: table.LC_scantron_action tr th {
1.698     harmsja  5673:   font-weight:bold;
                   5674:   font-style:normal;
1.613     albertel 5675: }
1.795     www      5676: 
1.779     bisitz   5677: .LC_edit_problem_header,
1.614     albertel 5678: div.LC_edit_problem_footer {
1.705     tempelho 5679:   font-weight: normal;
                   5680:   font-size:  medium;
1.602     albertel 5681:   margin: 2px;
1.600     albertel 5682: }
1.795     www      5683: 
1.600     albertel 5684: div.LC_edit_problem_header,
1.602     albertel 5685: div.LC_edit_problem_header div,
1.614     albertel 5686: div.LC_edit_problem_footer,
                   5687: div.LC_edit_problem_footer div,
1.602     albertel 5688: div.LC_edit_problem_editxml_header,
                   5689: div.LC_edit_problem_editxml_header div {
1.600     albertel 5690:   margin-top: 5px;
                   5691: }
1.795     www      5692: 
1.602     albertel 5693: div.LC_edit_problem_header_edit_row {
                   5694:   background: $tabbg;
                   5695:   padding: 3px;
                   5696:   margin-bottom: 5px;
                   5697: }
1.795     www      5698: 
1.600     albertel 5699: div.LC_edit_problem_header_title {
1.705     tempelho 5700:   font-weight: bold;
                   5701:   font-size: larger;
1.602     albertel 5702:   background: $tabbg;
                   5703:   padding: 3px;
                   5704: }
1.795     www      5705: 
1.602     albertel 5706: table.LC_edit_problem_header_title {
1.705     tempelho 5707:   font-size: larger;
                   5708:   font-weight:  bold;
1.602     albertel 5709:   width: 100%;
                   5710:   border-color: $pgbg;
                   5711:   border-style: solid;
                   5712:   border-width: $border;
1.600     albertel 5713:   background: $tabbg;
1.602     albertel 5714:   border-collapse: collapse;
                   5715:   padding: 0px
                   5716: }
                   5717: 
                   5718: div.LC_edit_problem_discards {
                   5719:   float: left;
                   5720:   padding-bottom: 5px;
                   5721: }
1.795     www      5722: 
1.602     albertel 5723: div.LC_edit_problem_saves {
                   5724:   float: right;
                   5725:   padding-bottom: 5px;
1.600     albertel 5726: }
1.795     www      5727: 
1.600     albertel 5728: hr.LC_edit_problem_divide {
1.602     albertel 5729:   clear: both;
1.600     albertel 5730:   color: $tabbg;
                   5731:   background-color: $tabbg;
                   5732:   height: 3px;
                   5733:   border: 0px;
                   5734: }
1.795     www      5735: 
1.679     riegler  5736: img.stift{
1.678     riegler  5737:   border-width:0;
1.679     riegler  5738:   vertical-align:middle;
1.677     riegler  5739: }
1.680     riegler  5740: 
1.681     riegler  5741: table#LC_mainmenu{
                   5742:  margin-top:10px;
                   5743:  width:80%;
                   5744: }
                   5745: 
1.680     riegler  5746: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
                   5747:   vertical-align: top;
                   5748:   width: 45%;
                   5749: }
1.795     www      5750: 
1.779     bisitz   5751: .LC_mainmenu_fieldset_category {
                   5752:   color: $font;
                   5753:   background: $pgbg;
                   5754:   font-family: $sans;
                   5755:   font-size: small;
                   5756:   font-weight: bold;
1.777     tempelho 5757: }
1.795     www      5758: 
1.716     raeburn  5759: div.LC_createcourse {
                   5760:     margin: 10px 10px 10px 10px;
                   5761: }
                   5762: 
1.693     droeschl 5763: /* ---- Remove when done ----
                   5764: # The following styles is part of the redesign of LON-CAPA and are
                   5765: # subject to change during this project.
                   5766: # Don't rely on their current functionality as they might be 
                   5767: # changed or removed.
                   5768: # --------------------------*/
                   5769: 
1.698     harmsja  5770: a:hover,
1.721     harmsja  5771: ol.LC_smallMenu a:hover,
                   5772: ol#LC_MenuBreadcrumbs a:hover,
                   5773: ol#LC_PathBreadcrumbs a:hover,
                   5774: ul#LC_TabMainMenuContent a:hover,
                   5775: .LC_FormSectionClearButton input:hover
1.795     www      5776: ul.LC_TabContent   li:hover a {
1.698     harmsja  5777: 	color:#BF2317;
                   5778:         text-decoration:none;
1.693     droeschl 5779: }
                   5780: 
1.779     bisitz   5781: h1 {
1.721     harmsja  5782: 	padding:5px 10px 5px 20px;
1.693     droeschl 5783: 	line-height:130%;
                   5784: }
1.698     harmsja  5785: 
1.795     www      5786: h2,h3,h4,h5,h6 {
1.721     harmsja  5787: 	margin:5px 0px 5px 0px;
                   5788: 	padding:0px;
                   5789: 	line-height:130%;
1.693     droeschl 5790: }
1.795     www      5791: 
                   5792: .LC_hcell {
1.698     harmsja  5793:         padding:3px 15px 3px 15px;
                   5794:         margin:0px;
1.703     harmsja  5795: 	background-color:$tabbg;
1.779     bisitz   5796: 	border-bottom:solid 1px $lg_border_color;
1.693     droeschl 5797: }
1.795     www      5798: 
1.721     harmsja  5799: .LC_noBorder {
1.698     harmsja  5800:         border:0px;
                   5801: }
1.693     droeschl 5802: 
                   5803: 
1.698     harmsja  5804: /* Main Header with discription of Person, Course, etc. */
1.693     droeschl 5805: 
1.761     tempelho 5806: .LC_Right {
                   5807:         float: right;
                   5808:         margin: 0px;
                   5809:         padding: 0px;
                   5810: }
                   5811: 
1.721     harmsja  5812: .LC_FormSectionClearButton input {
1.779     bisitz   5813:         background-color:transparent;
1.698     harmsja  5814:         border:0px;
                   5815:         cursor:pointer;
                   5816:         text-decoration:underline;
1.693     droeschl 5817: }
1.763     bisitz   5818: 
                   5819: .LC_help_open_topic {
                   5820:         color: #FFFFFF;
                   5821:         background-color: #EEEEFF;
                   5822:         margin: 1px;
                   5823:         padding: 4px;
                   5824:         border: 1px solid #000033;
                   5825:         white-space: nowrap;
1.783     amueller 5826: /*		vertical-align: middle; */
1.759     neumanie 5827: }
1.693     droeschl 5828: 
1.698     harmsja  5829: dl,ul,div,fieldset {
                   5830: 	margin: 10px 10px 10px 0px;
1.693     droeschl 5831: 	overflow:hidden;
                   5832: }
1.795     www      5833: 
1.721     harmsja  5834: ol.LC_smallMenu, ol#LC_PathBreadcrumbs {
1.698     harmsja  5835: 	margin: 0px;
1.693     droeschl 5836: }
                   5837: 
1.721     harmsja  5838: ol.LC_smallMenu li {
1.693     droeschl 5839: 	display: inline;
                   5840: 	padding: 5px 5px 0px 10px;
                   5841: 	vertical-align: top;
                   5842: }
                   5843: 
1.721     harmsja  5844: ol.LC_smallMenu li img {
1.693     droeschl 5845: 	vertical-align: bottom;
                   5846: }
                   5847: 
1.721     harmsja  5848: ol.LC_smallMenu a {
1.693     droeschl 5849: 	font-size: 90%;
                   5850: 	color: RGB(80, 80, 80);
                   5851: 	text-decoration: none;
                   5852: }
1.795     www      5853: 
                   5854: ol#LC_TabMainMenuContent, 
                   5855: ul.LC_TabContent ,
1.741     harmsja  5856: ul.LC_TabContentBigger {
1.721     harmsja  5857: 	display:block;
                   5858: 	list-style:none;
1.741     harmsja  5859: 	margin: 0px;
1.693     droeschl 5860: 	padding: 0px;
                   5861: }
                   5862: 
1.795     www      5863: ol#LC_TabMainMenuContent li,
                   5864: ul.LC_TabContent li,
                   5865: ul.LC_TabContentBigger li {
1.693     droeschl 5866: 	display: inline;
1.741     harmsja  5867: 	border-right: solid 1px $lg_border_color;
                   5868: 	float:left;
                   5869: 	line-height:140%;
                   5870: 	white-space:nowrap;
                   5871: }
1.795     www      5872: 
                   5873: ol#LC_TabMainMenuContent li {
1.693     droeschl 5874: 	vertical-align: bottom;
                   5875: 	border-bottom: solid 1px RGB(175, 175, 175);
1.721     harmsja  5876: 	padding: 5px 10px 5px 10px;
1.741     harmsja  5877: 	margin-right:5px;
                   5878: 	margin-bottom:3px;
1.693     droeschl 5879: 	font-weight: bold;
1.723     riegler  5880: 	background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693     droeschl 5881: }
                   5882: 
1.795     www      5883: ol#LC_TabMainMenuContent li a {
1.693     droeschl 5884: 	color: RGB(47, 47, 47);
                   5885: 	text-decoration: none;
                   5886: }
1.795     www      5887: 
1.721     harmsja  5888: ul.LC_TabContent {
1.741     harmsja  5889: 	min-height:1.6em;
1.721     harmsja  5890: }
1.795     www      5891: 
                   5892: ul.LC_TabContent li {
1.741     harmsja  5893: 	vertical-align:middle;
                   5894: 	padding:0px 10px 0px 10px;
1.745     ehlerst  5895: 	background-color:$tabbg;
                   5896: 	border-bottom:solid 1px $lg_border_color;
1.721     harmsja  5897: }
1.795     www      5898: 
                   5899: ul.LC_TabContent li a, ul.LC_TabContent li {
1.721     harmsja  5900: 	color:rgb(47,47,47);
                   5901: 	text-decoration:none;
                   5902: 	font-size:95%;
                   5903: 	font-weight:bold;
1.761     tempelho 5904: 	padding-right: 16px;
1.721     harmsja  5905: }
1.795     www      5906: 
                   5907: ul.LC_TabContent li:hover, ul.LC_TabContent li.active {
1.761     tempelho 5908:         background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.745     ehlerst  5909: 	border-bottom:solid 1px #FFFFFF;
1.761     tempelho 5910: 	padding-right: 16px;
1.744     ehlerst  5911: }
1.795     www      5912: 
                   5913: ul.LC_TabContentBigger li {
1.741     harmsja  5914: 	vertical-align:bottom;
                   5915: 	border-top:solid 1px $lg_border_color;
                   5916: 	border-left:solid 1px $lg_border_color;
                   5917: 	padding:5px 10px 5px 10px;
                   5918: 	margin-left:2px;
                   5919: 	background:url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
                   5920: }
1.795     www      5921: 
                   5922: ul.LC_TabContentBigger li:hover, 
                   5923: ul.LC_TabContentBigger li.active {
1.744     ehlerst  5924: 	background:url(/adm/lonIcons/lightGreyBG.png) repeat-x right bottom;
                   5925: }
1.795     www      5926: 
                   5927: ul.LC_TabContentBigger li, 
                   5928: ul.LC_TabContentBigger li a {
1.741     harmsja  5929: 	font-size:110%;
                   5930: 	font-weight:bold;
                   5931: }
1.693     droeschl 5932: 
1.795     www      5933: ol#LC_MenuBreadcrumbs, 
                   5934: ol#LC_PathBreadcrumbs, 
                   5935: ul.LC_CourseBreadcrumbs {
1.693     droeschl 5936: 	border-top: solid 1px RGB(255, 255, 255);
                   5937: 	height: 20px;
                   5938: 	line-height: 20px;
                   5939: 	vertical-align: bottom;
                   5940: 	margin: 0px 0px 30px 0px;
                   5941: 	padding-left: 10px;
                   5942: 	list-style-position: inside;
1.723     riegler  5943: 	background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693     droeschl 5944: }
                   5945: 
1.795     www      5946: ol#LC_MenuBreadcrumbs li, 
                   5947: ol#LC_PathBreadcrumbs li, 
                   5948: ul.LC_CourseBreadcrumbs li {
1.741     harmsja  5949: /*
1.723     riegler  5950: 	background: url(/adm/lonIcons/arrow_white.png) no-repeat left center;
1.779     bisitz   5951: */
1.693     droeschl 5952: 	display: inline;
                   5953: 	padding: 0px 0px 0px 10px;
1.783     amueller 5954: /*	vertical-align: bottom; */
1.693     droeschl 5955: 	overflow:hidden;
                   5956: }
                   5957: 
1.783     amueller 5958: ol#LC_MenuBreadcrumbs li a, ul.LC_CourseBreadcrumbs li a {
1.693     droeschl 5959: 	text-decoration: none;
                   5960: 	font-size:90%;
                   5961: }
1.795     www      5962: 
                   5963: ol#LC_PathBreadcrumbs li a {
1.698     harmsja  5964: 	text-decoration:none;
                   5965: 	font-size:100%;
                   5966: 	font-weight:bold;
1.693     droeschl 5967: }
1.795     www      5968: 
                   5969: .LC_BoxPadding {
1.786     neumanie 5970: 	padding: 10px;
                   5971: }
1.795     www      5972: 
                   5973: .LC_ContentBoxSpecial {
1.701     harmsja  5974: 	border: solid 1px $lg_border_color;
1.746     neumanie 5975: }
1.795     www      5976: 
                   5977: .LC_ContentBoxSpecialContactInfo {
1.746     neumanie 5978: 	border: solid 1px $lg_border_color;
                   5979: 	max-width:25%;
                   5980: 	min-width:25%;
1.698     harmsja  5981: }
1.795     www      5982: 
                   5983: .LC_AboutMe_Image {
1.747     neumanie 5984: 	float:left;
                   5985: 	margin-right:10px;
                   5986: }
1.795     www      5987: 
                   5988: .LC_Clear_AboutMe_Image {
1.747     neumanie 5989: 	clear:left;
                   5990: }
1.795     www      5991: 
1.721     harmsja  5992: dl.LC_ListStyleClean dt {
1.693     droeschl 5993: 	padding-right: 5px;
                   5994: 	display: table-header-group;
                   5995: }
                   5996: 
1.721     harmsja  5997: dl.LC_ListStyleClean dd {
1.693     droeschl 5998: 	display: table-row;
                   5999: }
                   6000: 
1.721     harmsja  6001: .LC_ListStyleClean,
                   6002: .LC_ListStyleSimple,
                   6003: .LC_ListStyleNormal,
1.777     tempelho 6004: .LC_ListStyle_Border,
1.795     www      6005: .LC_ListStyleSpecial {
1.693     droeschl 6006: 	/*display:block;	*/
                   6007: 	list-style-position: inside;
                   6008: 	list-style-type: none;
                   6009: 	overflow: hidden;
                   6010: 	padding: 0px;
                   6011: }
                   6012: 
1.721     harmsja  6013: .LC_ListStyleSimple li,
                   6014: .LC_ListStyleSimple dd,
                   6015: .LC_ListStyleNormal li,
                   6016: .LC_ListStyleNormal dd,
                   6017: .LC_ListStyleSpecial li,
1.795     www      6018: .LC_ListStyleSpecial dd {
1.693     droeschl 6019: 	margin: 0px;
                   6020: 	padding: 5px 5px 5px 10px;
                   6021: 	clear: both;
                   6022: }
                   6023: 
1.721     harmsja  6024: .LC_ListStyleClean li,
                   6025: .LC_ListStyleClean dd {
1.693     droeschl 6026: 	padding-top: 0px;
                   6027: 	padding-bottom: 0px;
                   6028: }
                   6029: 
1.721     harmsja  6030: .LC_ListStyleSimple dd,
1.795     www      6031: .LC_ListStyleSimple li {
1.698     harmsja  6032: 	border-bottom: solid 1px $lg_border_color;
1.693     droeschl 6033: }
                   6034: 
1.721     harmsja  6035: .LC_ListStyleSpecial li,
                   6036: .LC_ListStyleSpecial dd {
1.693     droeschl 6037: 	list-style-type: none;
                   6038: 	background-color: RGB(220, 220, 220);
                   6039: 	margin-bottom: 4px;
                   6040: }
                   6041: 
1.721     harmsja  6042: table.LC_SimpleTable {
1.698     harmsja  6043: 	margin:5px;
                   6044: 	border:solid 1px $lg_border_color;
1.795     www      6045: }
1.693     droeschl 6046: 
1.721     harmsja  6047: table.LC_SimpleTable tr {
1.698     harmsja  6048: 	padding:0px;
                   6049: 	border:solid 1px $lg_border_color;
1.693     droeschl 6050: }
1.795     www      6051: 
                   6052: table.LC_SimpleTable thead {
1.698     harmsja  6053: 	 background:rgb(220,220,220);
1.693     droeschl 6054: }
                   6055: 
1.721     harmsja  6056: div.LC_columnSection {
1.693     droeschl 6057: 	display: block;
                   6058: 	clear: both;
                   6059: 	overflow: hidden;
                   6060: 	margin:0px;
                   6061: }
                   6062: 
1.721     harmsja  6063: div.LC_columnSection>* {
1.693     droeschl 6064: 	float: left;
                   6065: 	margin: 10px 20px 10px 0px;
1.747     neumanie 6066: 	overflow:hidden;
1.693     droeschl 6067: }
1.721     harmsja  6068: 
1.795     www      6069: .ContentBoxSpecialTemplate {
1.747     neumanie 6070:         border: solid 1px $lg_border_color;
1.719     ehlerst  6071: }
1.795     www      6072: 
1.719     ehlerst  6073: .ContentBoxTemplate {
                   6074:         padding:10px;
                   6075: }
                   6076: 
1.721     harmsja  6077: div.LC_columnSection > .ContentBoxTemplate,
1.795     www      6078: div.LC_columnSection > .ContentBoxSpecialTemplate {
1.719     ehlerst  6079:         width: 600px;
                   6080: }
1.753     droeschl 6081: 
1.795     www      6082: .clear {
1.720     ehlerst  6083: 	clear: both;
                   6084: 	line-height: 0px;
                   6085: 	font-size: 0px;
                   6086: 	height: 0px;
                   6087: }
1.693     droeschl 6088: 
1.694     tempelho 6089: .LC_loginpage_container {
                   6090: 	text-align:left;
                   6091: 	margin : 0 auto;
1.785     tempelho 6092: 	width:90%;
1.694     tempelho 6093: 	padding: 10px;
                   6094: 	height: auto;
1.712     muellerd 6095: 	background-color:#FFFFFF;
1.694     tempelho 6096: 	border:1px solid #CCCCCC;
                   6097: }
                   6098: 
                   6099: 
                   6100: .LC_loginpage_loginContainer {
                   6101: 	float:left;
1.712     muellerd 6102: 	width: 182px;
1.785     tempelho 6103: 	padding: 2px;
1.712     muellerd 6104: 	border:1px solid #CCCCCC;
                   6105: 	background-color:$loginbg;
1.694     tempelho 6106: }
                   6107: 
1.795     www      6108: .LC_loginpage_loginContainer h2 {
1.712     muellerd 6109: 	margin-top:0;
                   6110: 	display:block;
                   6111: 	background:$bgcol;
                   6112: 	color:$textcol;
                   6113: 	padding-left:5px;
                   6114: }
1.785     tempelho 6115: 
1.694     tempelho 6116: .LC_loginpage_loginInfo {
                   6117: 	float:left;
1.785     tempelho 6118: 	width:182px;
1.694     tempelho 6119: 	border:1px solid #CCCCCC;
1.785     tempelho 6120: 	padding:2px;
1.712     muellerd 6121: }
                   6122: 
1.694     tempelho 6123: .LC_loginpage_space {
1.754     droeschl 6124: 	clear: both;
                   6125: 	margin-bottom: 20px;
1.694     tempelho 6126: 	border-bottom: 1px solid #CCCCCC;
                   6127: }
                   6128: 
1.785     tempelho 6129: .LC_loginpage_floatLeft {
                   6130: 	float: left;
                   6131: 	width: 200px;
                   6132: 	margin: 0;
                   6133: }
                   6134: 
1.795     www      6135: table em {
1.754     droeschl 6136: 	font-weight: bold;
                   6137: 	font-style: normal;
1.748     schulted 6138: }
1.795     www      6139: 
1.779     bisitz   6140: table.LC_tableBrowseRes,
1.795     www      6141: table.LC_tableOfContent {
1.769     schulted 6142:         border:none;
                   6143: 	border-spacing: 1;
1.754     droeschl 6144: 	padding: 3px;
                   6145: 	background-color: #FFFFFF;
                   6146: 	font-size: 90%;
1.753     droeschl 6147: }
1.789     droeschl 6148: 
                   6149: table.LC_tableOfContent{
                   6150:     border-collapse: collapse;
                   6151: }
                   6152: 
1.771     droeschl 6153: table.LC_tableBrowseRes a,
1.768     schulted 6154: table.LC_tableOfContent a {
1.771     droeschl 6155:         background-color: transparent;
1.753     droeschl 6156: 	text-decoration: none;
                   6157: }
                   6158: 
1.771     droeschl 6159: table.LC_tableBrowseRes tr.LC_trOdd,
1.768     schulted 6160: table.LC_tableOfContent tr.LC_trOdd{
1.754     droeschl 6161: 	background-color: #EEEEEE;
1.753     droeschl 6162: }
                   6163: 
1.795     www      6164: table.LC_tableOfContent img {
1.753     droeschl 6165: 	border: none;
                   6166: 	height: 1.3em;
                   6167: 	vertical-align: text-bottom;
                   6168: 	margin-right: 0.3em;
                   6169: }
1.757     schulted 6170: 
1.795     www      6171: a#LC_content_toolbar_firsthomework {
1.774     ehlerst  6172: 	background-image:url(/res/adm/pages/open-first-problem.gif);
                   6173: }
                   6174: 
1.795     www      6175: a#LC_content_toolbar_launchnav {
1.774     ehlerst  6176: 	background-image:url(/res/adm/pages/start-navigation.gif);
                   6177: }
                   6178: 
1.795     www      6179: a#LC_content_toolbar_closenav {
1.774     ehlerst  6180: 	background-image:url(/res/adm/pages/close-navigation.gif);
                   6181: }
                   6182: 
1.795     www      6183: a#LC_content_toolbar_everything {
1.774     ehlerst  6184: 	background-image:url(/res/adm/pages/show-all.gif);
                   6185: }
                   6186: 
1.795     www      6187: a#LC_content_toolbar_uncompleted {
1.774     ehlerst  6188: 	background-image:url(/res/adm/pages/show-incomplete-problems.gif);
                   6189: }
                   6190: 
1.795     www      6191: #LC_content_toolbar_clearbubbles {
1.774     ehlerst  6192: 	background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
                   6193: }
                   6194: 
1.795     www      6195: a#LC_content_toolbar_changefolder {
1.757     schulted 6196: 	background : url(/res/adm/pages/close-all-folders.gif) top center ;
                   6197: }
                   6198: 
1.795     www      6199: a#LC_content_toolbar_changefolder_toggled {
1.757     schulted 6200: 	background-image:url(/res/adm/pages/open-all-folders.gif);
                   6201: }
                   6202: 
1.795     www      6203: ul#LC_toolbar li a:hover {
1.757     schulted 6204: 	background-position: bottom center;
                   6205: }
                   6206: 
1.795     www      6207: ul#LC_toolbar {
1.779     bisitz   6208: 	padding:0;
1.757     schulted 6209: 	margin: 2px;
                   6210: 	list-style:none;
                   6211: 	position:relative;
                   6212: 	background-color:white;
                   6213: }
                   6214: 
1.795     www      6215: ul#LC_toolbar li {
1.757     schulted 6216: 	border:1px solid white;
                   6217: 	padding:0;
                   6218: 	margin: 0;
1.795     www      6219:         float: left;
1.767     droeschl 6220: 	display:inline;
1.757     schulted 6221: 	vertical-align:middle;
1.795     www      6222: } 
1.757     schulted 6223: 
1.783     amueller 6224: 
1.795     www      6225: a.LC_toolbarItem {
1.767     droeschl 6226: 	display:block;
1.757     schulted 6227: 	padding:0;
                   6228: 	margin:0;
                   6229: 	height: 32px;
                   6230: 	width: 32px;
1.779     bisitz   6231: 	color:white;
                   6232: 	border:0 none;
1.757     schulted 6233: 	background-repeat:no-repeat;
                   6234: 	background-color:transparent;
                   6235: }
                   6236: 
1.782     bisitz   6237: ul.LC_functionslist li {
                   6238:   float: left;
                   6239:   white-space: nowrap;
                   6240:   height: 35px; /* at least as high as heighest list item */
                   6241:   margin: 0px 15px 15px 10px;
                   6242: }
                   6243: 
1.757     schulted 6244: 
1.343     albertel 6245: END
                   6246: }
                   6247: 
1.306     albertel 6248: =pod
                   6249: 
                   6250: =item * &headtag()
                   6251: 
                   6252: Returns a uniform footer for LON-CAPA web pages.
                   6253: 
1.307     albertel 6254: Inputs: $title - optional title for the head
                   6255:         $head_extra - optional extra HTML to put inside the <head>
1.315     albertel 6256:         $args - optional arguments
1.319     albertel 6257:             force_register - if is true call registerurl so the remote is 
                   6258:                              informed
1.415     albertel 6259:             redirect       -> array ref of
                   6260:                                    1- seconds before redirect occurs
                   6261:                                    2- url to redirect to
                   6262:                                    3- whether the side effect should occur
1.315     albertel 6263:                            (side effect of setting 
                   6264:                                $env{'internal.head.redirect'} to the url 
                   6265:                                redirected too)
1.352     albertel 6266:             domain         -> force to color decorate a page for a specific
                   6267:                                domain
                   6268:             function       -> force usage of a specific rolish color scheme
                   6269:             bgcolor        -> override the default page bgcolor
1.460     albertel 6270:             no_auto_mt_title
                   6271:                            -> prevent &mt()ing the title arg
1.464     albertel 6272: 
1.306     albertel 6273: =cut
                   6274: 
                   6275: sub headtag {
1.313     albertel 6276:     my ($title,$head_extra,$args) = @_;
1.306     albertel 6277:     
1.363     albertel 6278:     my $function = $args->{'function'} || &get_users_function();
                   6279:     my $domain   = $args->{'domain'}   || &determinedomain();
                   6280:     my $bgcolor  = $args->{'bgcolor'}  || &designparm($function.'.pgbg',$domain);
1.418     albertel 6281:     my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458     albertel 6282: 		   $Apache::lonnet::perlvar{'lonVersion'},
1.531     albertel 6283: 		   #time(),
1.418     albertel 6284: 		   $env{'environment.color.timestamp'},
1.363     albertel 6285: 		   $function,$domain,$bgcolor);
                   6286: 
1.369     www      6287:     $url = '/adm/css/'.&escape($url).'.css';
1.363     albertel 6288: 
1.308     albertel 6289:     my $result =
                   6290: 	'<head>'.
1.461     albertel 6291: 	&font_settings();
1.319     albertel 6292: 
1.461     albertel 6293:     if (!$args->{'frameset'}) {
                   6294: 	$result .= &Apache::lonhtmlcommon::htmlareaheaders();
                   6295:     }
1.319     albertel 6296:     if ($args->{'force_register'}) {
                   6297: 	$result .= &Apache::lonmenu::registerurl(1);
                   6298:     }
1.436     albertel 6299:     if (!$args->{'no_nav_bar'} 
                   6300: 	&& !$args->{'only_body'}
                   6301: 	&& !$args->{'frameset'}) {
                   6302: 	$result .= &help_menu_js();
                   6303:     }
1.319     albertel 6304: 
1.314     albertel 6305:     if (ref($args->{'redirect'})) {
1.414     albertel 6306: 	my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315     albertel 6307: 	$url = &Apache::lonenc::check_encrypt($url);
1.414     albertel 6308: 	if (!$inhibit_continue) {
                   6309: 	    $env{'internal.head.redirect'} = $url;
                   6310: 	}
1.313     albertel 6311: 	$result.=<<ADDMETA
                   6312: <meta http-equiv="pragma" content="no-cache" />
1.344     albertel 6313: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313     albertel 6314: ADDMETA
                   6315:     }
1.306     albertel 6316:     if (!defined($title)) {
                   6317: 	$title = 'The LearningOnline Network with CAPA';
                   6318:     }
1.460     albertel 6319:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
                   6320:     $result .= '<title> LON-CAPA '.$title.'</title>'
1.414     albertel 6321: 	.'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
                   6322: 	.$head_extra;
1.306     albertel 6323:     return $result;
                   6324: }
                   6325: 
                   6326: =pod
                   6327: 
1.340     albertel 6328: =item * &font_settings()
                   6329: 
                   6330: Returns neccessary <meta> to set the proper encoding
                   6331: 
                   6332: Inputs: none
                   6333: 
                   6334: =cut
                   6335: 
                   6336: sub font_settings {
                   6337:     my $headerstring='';
1.647     www      6338:     if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340     albertel 6339: 	$headerstring.=
                   6340: 	    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
                   6341:     }
                   6342:     return $headerstring;
                   6343: }
                   6344: 
1.341     albertel 6345: =pod
                   6346: 
                   6347: =item * &xml_begin()
                   6348: 
                   6349: Returns the needed doctype and <html>
                   6350: 
                   6351: Inputs: none
                   6352: 
                   6353: =cut
                   6354: 
                   6355: sub xml_begin {
                   6356:     my $output='';
                   6357: 
1.592     albertel 6358:     if ($env{'internal.start_page'}==1) {
                   6359: 	&Apache::lonhtmlcommon::init_htmlareafields();
                   6360:     }
1.342     albertel 6361: 
1.341     albertel 6362:     if ($env{'browser.mathml'}) {
                   6363: 	$output='<?xml version="1.0"?>'
                   6364:             #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
                   6365: #            .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
                   6366:             
                   6367: #	    .'<!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">] >'
                   6368: 	    .'<!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">'
                   6369:             .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" ' 
                   6370: 	    .'xmlns="http://www.w3.org/1999/xhtml">';
                   6371:     } else {
                   6372: 	$output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
                   6373:     }
                   6374:     return $output;
                   6375: }
1.340     albertel 6376: 
                   6377: =pod
                   6378: 
1.306     albertel 6379: =item * &endheadtag()
                   6380: 
                   6381: Returns a uniform </head> for LON-CAPA web pages.
                   6382: 
                   6383: Inputs: none
                   6384: 
                   6385: =cut
                   6386: 
                   6387: sub endheadtag {
                   6388:     return '</head>';
                   6389: }
                   6390: 
                   6391: =pod
                   6392: 
                   6393: =item * &head()
                   6394: 
                   6395: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
                   6396: 
1.648     raeburn  6397: Inputs:
                   6398: 
                   6399: =over 4
                   6400: 
                   6401: $title - optional title for the page
                   6402: 
                   6403: $head_extra - optional extra HTML to put inside the <head>
                   6404: 
                   6405: =back
1.405     albertel 6406: 
1.306     albertel 6407: =cut
                   6408: 
                   6409: sub head {
1.325     albertel 6410:     my ($title,$head_extra,$args) = @_;
                   6411:     return &headtag($title,$head_extra,$args).&endheadtag();
1.306     albertel 6412: }
                   6413: 
                   6414: =pod
                   6415: 
                   6416: =item * &start_page()
                   6417: 
                   6418: Returns a complete <html> .. <body> section for LON-CAPA web pages.
                   6419: 
1.648     raeburn  6420: Inputs:
                   6421: 
                   6422: =over 4
                   6423: 
                   6424: $title - optional title for the page
                   6425: 
                   6426: $head_extra - optional extra HTML to incude inside the <head>
                   6427: 
                   6428: $args - additional optional args supported are:
                   6429: 
                   6430: =over 8
                   6431: 
                   6432:              only_body      -> is true will set &bodytag() onlybodytag
1.317     albertel 6433:                                     arg on
1.648     raeburn  6434:              no_nav_bar     -> is true will set &bodytag() notopbar arg on
                   6435:              add_entries    -> additional attributes to add to the  <body>
                   6436:              domain         -> force to color decorate a page for a 
1.317     albertel 6437:                                     specific domain
1.648     raeburn  6438:              function       -> force usage of a specific rolish color
1.317     albertel 6439:                                     scheme
1.648     raeburn  6440:              redirect       -> see &headtag()
                   6441:              bgcolor        -> override the default page bg color
                   6442:              js_ready       -> return a string ready for being used in 
1.317     albertel 6443:                                     a javascript writeln
1.648     raeburn  6444:              html_encode    -> return a string ready for being used in 
1.320     albertel 6445:                                     a html attribute
1.648     raeburn  6446:              force_register -> if is true will turn on the &bodytag()
1.317     albertel 6447:                                     $forcereg arg
1.648     raeburn  6448:              body_title     -> alternate text to use instead of $title
1.326     albertel 6449:                                     in the title box that appears, this text
                   6450:                                     is not auto translated like the $title is
1.648     raeburn  6451:              frameset       -> if true will start with a <frameset>
1.330     albertel 6452:                                     rather than <body>
1.648     raeburn  6453:              no_title       -> if true the title bar won't be shown
                   6454:              skip_phases    -> hash ref of 
1.338     albertel 6455:                                     head -> skip the <html><head> generation
                   6456:                                     body -> skip all <body> generation
1.648     raeburn  6457:              no_inline_link -> if true and in remote mode, don't show the 
1.361     albertel 6458:                                     'Switch To Inline Menu' link
1.648     raeburn  6459:              no_auto_mt_title -> prevent &mt()ing the title arg
                   6460:              inherit_jsmath -> when creating popup window in a page,
                   6461:                                     should it have jsmath forced on by the
                   6462:                                     current page
1.361     albertel 6463: 
1.648     raeburn  6464: =back
1.460     albertel 6465: 
1.648     raeburn  6466: =back
1.562     albertel 6467: 
1.306     albertel 6468: =cut
                   6469: 
                   6470: sub start_page {
1.309     albertel 6471:     my ($title,$head_extra,$args) = @_;
1.318     albertel 6472:     #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313     albertel 6473:     my %head_args;
1.352     albertel 6474:     foreach my $arg ('redirect','force_register','domain','function',
1.460     albertel 6475: 		     'bgcolor','frameset','no_nav_bar','only_body',
                   6476: 		     'no_auto_mt_title') {
1.319     albertel 6477: 	if (defined($args->{$arg})) {
1.324     raeburn  6478: 	    $head_args{$arg} = $args->{$arg};
1.319     albertel 6479: 	}
1.313     albertel 6480:     }
1.319     albertel 6481: 
1.315     albertel 6482:     $env{'internal.start_page'}++;
1.338     albertel 6483:     my $result;
                   6484:     if (! exists($args->{'skip_phases'}{'head'}) ) {
                   6485: 	$result.=
1.341     albertel 6486: 	    &xml_begin().
1.338     albertel 6487: 	    &headtag($title,$head_extra,\%head_args).&endheadtag();
                   6488:     }
                   6489:     
                   6490:     if (! exists($args->{'skip_phases'}{'body'}) ) {
                   6491: 	if ($args->{'frameset'}) {
                   6492: 	    my $attr_string = &make_attr_string($args->{'force_register'},
                   6493: 						$args->{'add_entries'});
                   6494: 	    $result .= "\n<frameset $attr_string>\n";
                   6495: 	} else {
                   6496: 	    $result .=
                   6497: 		&bodytag($title, 
                   6498: 			 $args->{'function'},       $args->{'add_entries'},
                   6499: 			 $args->{'only_body'},      $args->{'domain'},
                   6500: 			 $args->{'force_register'}, $args->{'body_title'},
                   6501: 			 $args->{'no_nav_bar'},     $args->{'bgcolor'},
1.460     albertel 6502: 			 $args->{'no_title'},       $args->{'no_inline_link'},
                   6503: 			 $args);
1.338     albertel 6504: 	}
1.330     albertel 6505:     }
1.338     albertel 6506: 
1.315     albertel 6507:     if ($args->{'js_ready'}) {
1.713     kaisler  6508: 		$result = &js_ready($result);
1.315     albertel 6509:     }
1.320     albertel 6510:     if ($args->{'html_encode'}) {
1.713     kaisler  6511: 		$result = &html_encode($result);
                   6512:     }
                   6513: 
1.758     kaisler  6514: 	#Breadcrumbs
                   6515:     if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
                   6516: 		&Apache::lonhtmlcommon::clear_breadcrumbs();
                   6517: 		#if any br links exists, add them to the breadcrumbs
                   6518: 		if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {         
                   6519: 			foreach my $crumb (@{$args->{'bread_crumbs'}}){
                   6520: 				&Apache::lonhtmlcommon::add_breadcrumb($crumb);
                   6521: 			}
                   6522: 		}
                   6523: 
                   6524: 		#if bread_crumbs_component exists show it as headline else show only the breadcrumbs
                   6525: 		if(exists($args->{'bread_crumbs_component'})){
                   6526: 			$result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
                   6527: 		}else{
                   6528: 			$result .= &Apache::lonhtmlcommon::breadcrumbs();
                   6529: 		}
1.320     albertel 6530:     }
1.315     albertel 6531:     return $result;
1.306     albertel 6532: }
                   6533: 
1.330     albertel 6534: 
1.306     albertel 6535: =pod
                   6536: 
                   6537: =item * &head()
                   6538: 
                   6539: Returns a complete </body></html> section for LON-CAPA web pages.
                   6540: 
1.315     albertel 6541: Inputs:         $args - additional optional args supported are:
                   6542:                  js_ready     -> return a string ready for being used in 
                   6543:                                  a javascript writeln
1.320     albertel 6544:                  html_encode  -> return a string ready for being used in 
                   6545:                                  a html attribute
1.330     albertel 6546:                  frameset     -> if true will start with a <frameset>
                   6547:                                  rather than <body>
1.493     albertel 6548:                  dicsussion   -> if true will get discussion from
                   6549:                                   lonxml::xmlend
                   6550:                                  (you can pass the target and parser arguments
                   6551:                                   through optional 'target' and 'parser' args
                   6552:                                   to this routine)
1.306     albertel 6553: 
                   6554: =cut
                   6555: 
                   6556: sub end_page {
1.315     albertel 6557:     my ($args) = @_;
                   6558:     $env{'internal.end_page'}++;
1.330     albertel 6559:     my $result;
1.335     albertel 6560:     if ($args->{'discussion'}) {
                   6561: 	my ($target,$parser);
                   6562: 	if (ref($args->{'discussion'})) {
                   6563: 	    ($target,$parser) =($args->{'discussion'}{'target'},
                   6564: 				$args->{'discussion'}{'parser'});
                   6565: 	}
                   6566: 	$result .= &Apache::lonxml::xmlend($target,$parser);
                   6567:     }
                   6568: 
1.330     albertel 6569:     if ($args->{'frameset'}) {
                   6570: 	$result .= '</frameset>';
                   6571:     } else {
1.635     raeburn  6572: 	$result .= &endbodytag($args);
1.330     albertel 6573:     }
                   6574:     $result .= "\n</html>";
                   6575: 
1.315     albertel 6576:     if ($args->{'js_ready'}) {
1.317     albertel 6577: 	$result = &js_ready($result);
1.315     albertel 6578:     }
1.335     albertel 6579: 
1.320     albertel 6580:     if ($args->{'html_encode'}) {
                   6581: 	$result = &html_encode($result);
                   6582:     }
1.335     albertel 6583: 
1.315     albertel 6584:     return $result;
                   6585: }
                   6586: 
1.320     albertel 6587: sub html_encode {
                   6588:     my ($result) = @_;
                   6589: 
1.322     albertel 6590:     $result = &HTML::Entities::encode($result,'<>&"');
1.320     albertel 6591:     
                   6592:     return $result;
                   6593: }
1.317     albertel 6594: sub js_ready {
                   6595:     my ($result) = @_;
                   6596: 
1.323     albertel 6597:     $result =~ s/[\n\r]/ /xmsg;
                   6598:     $result =~ s/\\/\\\\/xmsg;
                   6599:     $result =~ s/'/\\'/xmsg;
1.372     albertel 6600:     $result =~ s{</}{<\\/}xmsg;
1.317     albertel 6601:     
                   6602:     return $result;
                   6603: }
                   6604: 
1.315     albertel 6605: sub validate_page {
                   6606:     if (  exists($env{'internal.start_page'})
1.316     albertel 6607: 	  &&     $env{'internal.start_page'} > 1) {
                   6608: 	&Apache::lonnet::logthis('start_page called multiple times '.
1.318     albertel 6609: 				 $env{'internal.start_page'}.' '.
1.316     albertel 6610: 				 $ENV{'request.filename'});
1.315     albertel 6611:     }
                   6612:     if (  exists($env{'internal.end_page'})
1.316     albertel 6613: 	  &&     $env{'internal.end_page'} > 1) {
                   6614: 	&Apache::lonnet::logthis('end_page called multiple times '.
1.318     albertel 6615: 				 $env{'internal.end_page'}.' '.
1.316     albertel 6616: 				 $env{'request.filename'});
1.315     albertel 6617:     }
                   6618:     if (     exists($env{'internal.start_page'})
                   6619: 	&& ! exists($env{'internal.end_page'})) {
1.316     albertel 6620: 	&Apache::lonnet::logthis('start_page called without end_page '.
                   6621: 				 $env{'request.filename'});
1.315     albertel 6622:     }
                   6623:     if (   ! exists($env{'internal.start_page'})
                   6624: 	&&   exists($env{'internal.end_page'})) {
1.316     albertel 6625: 	&Apache::lonnet::logthis('end_page called without start_page'.
                   6626: 				 $env{'request.filename'});
1.315     albertel 6627:     }
1.306     albertel 6628: }
1.315     albertel 6629: 
1.318     albertel 6630: sub simple_error_page {
                   6631:     my ($r,$title,$msg) = @_;
                   6632:     my $page =
                   6633: 	&Apache::loncommon::start_page($title).
                   6634: 	&mt($msg).
                   6635: 	&Apache::loncommon::end_page();
                   6636:     if (ref($r)) {
                   6637: 	$r->print($page);
1.327     albertel 6638: 	return;
1.318     albertel 6639:     }
                   6640:     return $page;
                   6641: }
1.347     albertel 6642: 
                   6643: {
1.610     albertel 6644:     my @row_count;
1.347     albertel 6645:     sub start_data_table {
1.422     albertel 6646: 	my ($add_class) = @_;
                   6647: 	my $css_class = (join(' ','LC_data_table',$add_class));
1.610     albertel 6648: 	unshift(@row_count,0);
1.422     albertel 6649: 	return '<table class="'.$css_class.'">'."\n";
1.347     albertel 6650:     }
                   6651: 
                   6652:     sub end_data_table {
1.610     albertel 6653: 	shift(@row_count);
1.389     albertel 6654: 	return '</table>'."\n";;
1.347     albertel 6655:     }
                   6656: 
                   6657:     sub start_data_table_row {
1.422     albertel 6658: 	my ($add_class) = @_;
1.610     albertel 6659: 	$row_count[0]++;
                   6660: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428     albertel 6661: 	$css_class = (join(' ',$css_class,$add_class));
1.422     albertel 6662: 	return  '<tr class="'.$css_class.'">'."\n";;
1.347     albertel 6663:     }
1.471     banghart 6664:     
                   6665:     sub continue_data_table_row {
                   6666: 	my ($add_class) = @_;
1.610     albertel 6667: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471     banghart 6668: 	$css_class = (join(' ',$css_class,$add_class));
                   6669: 	return  '<tr class="'.$css_class.'">'."\n";;
                   6670:     }
1.347     albertel 6671: 
                   6672:     sub end_data_table_row {
1.389     albertel 6673: 	return '</tr>'."\n";;
1.347     albertel 6674:     }
1.367     www      6675: 
1.421     albertel 6676:     sub start_data_table_empty_row {
1.707     bisitz   6677: #	$row_count[0]++;
1.421     albertel 6678: 	return  '<tr class="LC_empty_row" >'."\n";;
                   6679:     }
                   6680: 
                   6681:     sub end_data_table_empty_row {
                   6682: 	return '</tr>'."\n";;
                   6683:     }
                   6684: 
1.367     www      6685:     sub start_data_table_header_row {
1.389     albertel 6686: 	return  '<tr class="LC_header_row">'."\n";;
1.367     www      6687:     }
                   6688: 
                   6689:     sub end_data_table_header_row {
1.389     albertel 6690: 	return '</tr>'."\n";;
1.367     www      6691:     }
1.347     albertel 6692: }
                   6693: 
1.548     albertel 6694: =pod
                   6695: 
                   6696: =item * &inhibit_menu_check($arg)
                   6697: 
                   6698: Checks for a inhibitmenu state and generates output to preserve it
                   6699: 
                   6700: Inputs:         $arg - can be any of
                   6701:                      - undef - in which case the return value is a string 
                   6702:                                to add  into arguments list of a uri
                   6703:                      - 'input' - in which case the return value is a HTML
                   6704:                                  <form> <input> field of type hidden to
                   6705:                                  preserve the value
                   6706:                      - a url - in which case the return value is the url with
                   6707:                                the neccesary cgi args added to preserve the
                   6708:                                inhibitmenu state
                   6709:                      - a ref to a url - no return value, but the string is
                   6710:                                         updated to include the neccessary cgi
                   6711:                                         args to preserve the inhibitmenu state
                   6712: 
                   6713: =cut
                   6714: 
                   6715: sub inhibit_menu_check {
                   6716:     my ($arg) = @_;
                   6717:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   6718:     if ($arg eq 'input') {
                   6719: 	if ($env{'form.inhibitmenu'}) {
                   6720: 	    return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
                   6721: 	} else {
                   6722: 	    return
                   6723: 	}
                   6724:     }
                   6725:     if ($env{'form.inhibitmenu'}) {
                   6726: 	if (ref($arg)) {
                   6727: 	    $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   6728: 	} elsif ($arg eq '') {
                   6729: 	    $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
                   6730: 	} else {
                   6731: 	    $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   6732: 	}
                   6733:     }
                   6734:     if (!ref($arg)) {
                   6735: 	return $arg;
                   6736:     }
                   6737: }
                   6738: 
1.251     albertel 6739: ###############################################
1.182     matthew  6740: 
                   6741: =pod
                   6742: 
1.549     albertel 6743: =back
                   6744: 
                   6745: =head1 User Information Routines
                   6746: 
                   6747: =over 4
                   6748: 
1.405     albertel 6749: =item * &get_users_function()
1.182     matthew  6750: 
                   6751: Used by &bodytag to determine the current users primary role.
                   6752: Returns either 'student','coordinator','admin', or 'author'.
                   6753: 
                   6754: =cut
                   6755: 
                   6756: ###############################################
                   6757: sub get_users_function {
                   6758:     my $function = 'student';
1.258     albertel 6759:     if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182     matthew  6760:         $function='coordinator';
                   6761:     }
1.258     albertel 6762:     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182     matthew  6763:         $function='admin';
                   6764:     }
1.258     albertel 6765:     if (($env{'request.role'}=~/^(au|ca)/) ||
1.182     matthew  6766:         ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
                   6767:         $function='author';
                   6768:     }
                   6769:     return $function;
1.54      www      6770: }
1.99      www      6771: 
                   6772: ###############################################
                   6773: 
1.233     raeburn  6774: =pod
                   6775: 
1.542     raeburn  6776: =item * &check_user_status()
1.274     raeburn  6777: 
                   6778: Determines current status of supplied role for a
                   6779: specific user. Roles can be active, previous or future.
                   6780: 
                   6781: Inputs: 
                   6782: user's domain, user's username, course's domain,
1.375     raeburn  6783: course's number, optional section ID.
1.274     raeburn  6784: 
                   6785: Outputs:
                   6786: role status: active, previous or future. 
                   6787: 
                   6788: =cut
                   6789: 
                   6790: sub check_user_status {
1.412     raeburn  6791:     my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274     raeburn  6792:     my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
                   6793:     my @uroles = keys %userinfo;
                   6794:     my $srchstr;
                   6795:     my $active_chk = 'none';
1.412     raeburn  6796:     my $now = time;
1.274     raeburn  6797:     if (@uroles > 0) {
1.412     raeburn  6798:         if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274     raeburn  6799:             $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
                   6800:         } else {
1.412     raeburn  6801:             $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
                   6802:         }
                   6803:         if (grep/^\Q$srchstr\E$/,@uroles) {
1.274     raeburn  6804:             my $role_end = 0;
                   6805:             my $role_start = 0;
                   6806:             $active_chk = 'active';
1.412     raeburn  6807:             if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
                   6808:                 $role_end = $1;
                   6809:                 if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
                   6810:                     $role_start = $1;
1.274     raeburn  6811:                 }
                   6812:             }
                   6813:             if ($role_start > 0) {
1.412     raeburn  6814:                 if ($now < $role_start) {
1.274     raeburn  6815:                     $active_chk = 'future';
                   6816:                 }
                   6817:             }
                   6818:             if ($role_end > 0) {
1.412     raeburn  6819:                 if ($now > $role_end) {
1.274     raeburn  6820:                     $active_chk = 'previous';
                   6821:                 }
                   6822:             }
                   6823:         }
                   6824:     }
                   6825:     return $active_chk;
                   6826: }
                   6827: 
                   6828: ###############################################
                   6829: 
                   6830: =pod
                   6831: 
1.405     albertel 6832: =item * &get_sections()
1.233     raeburn  6833: 
                   6834: Determines all the sections for a course including
                   6835: sections with students and sections containing other roles.
1.419     raeburn  6836: Incoming parameters: 
                   6837: 
                   6838: 1. domain
                   6839: 2. course number 
                   6840: 3. reference to array containing roles for which sections should 
                   6841: be gathered (optional).
                   6842: 4. reference to array containing status types for which sections 
                   6843: should be gathered (optional).
                   6844: 
                   6845: If the third argument is undefined, sections are gathered for any role. 
                   6846: If the fourth argument is undefined, sections are gathered for any status.
                   6847: Permissible values are 'active' or 'future' or 'previous'.
1.233     raeburn  6848:  
1.374     raeburn  6849: Returns section hash (keys are section IDs, values are
                   6850: number of users in each section), subject to the
1.419     raeburn  6851: optional roles filter, optional status filter 
1.233     raeburn  6852: 
                   6853: =cut
                   6854: 
                   6855: ###############################################
                   6856: sub get_sections {
1.419     raeburn  6857:     my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366     albertel 6858:     if (!defined($cdom) || !defined($cnum)) {
                   6859:         my $cid =  $env{'request.course.id'};
                   6860: 
                   6861: 	return if (!defined($cid));
                   6862: 
                   6863:         $cdom = $env{'course.'.$cid.'.domain'};
                   6864:         $cnum = $env{'course.'.$cid.'.num'};
                   6865:     }
                   6866: 
                   6867:     my %sectioncount;
1.419     raeburn  6868:     my $now = time;
1.240     albertel 6869: 
1.366     albertel 6870:     if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276     albertel 6871: 	my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240     albertel 6872: 	my $sec_index = &Apache::loncoursedata::CL_SECTION();
                   6873: 	my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419     raeburn  6874:         my $start_index = &Apache::loncoursedata::CL_START();
                   6875:         my $end_index = &Apache::loncoursedata::CL_END();
                   6876:         my $status;
1.366     albertel 6877: 	while (my ($student,$data) = each(%$classlist)) {
1.419     raeburn  6878: 	    my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
                   6879: 				                     $data->[$status_index],
                   6880:                                                      $data->[$start_index],
                   6881:                                                      $data->[$end_index]);
                   6882:             if ($stu_status eq 'Active') {
                   6883:                 $status = 'active';
                   6884:             } elsif ($end < $now) {
                   6885:                 $status = 'previous';
                   6886:             } elsif ($start > $now) {
                   6887:                 $status = 'future';
                   6888:             } 
                   6889: 	    if ($section ne '-1' && $section !~ /^\s*$/) {
                   6890:                 if ((!defined($possible_status)) || (($status ne '') && 
                   6891:                     (grep/^\Q$status\E$/,@{$possible_status}))) { 
                   6892: 		    $sectioncount{$section}++;
                   6893:                 }
1.240     albertel 6894: 	    }
                   6895: 	}
                   6896:     }
                   6897:     my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   6898:     foreach my $user (sort(keys(%courseroles))) {
                   6899: 	if ($user !~ /^(\w{2})/) { next; }
                   6900: 	my ($role) = ($user =~ /^(\w{2})/);
                   6901: 	if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419     raeburn  6902: 	my ($section,$status);
1.240     albertel 6903: 	if ($role eq 'cr' &&
                   6904: 	    $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
                   6905: 	    $section=$1;
                   6906: 	}
                   6907: 	if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
                   6908: 	if (!defined($section) || $section eq '-1') { next; }
1.419     raeburn  6909:         my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
                   6910:         if ($end == -1 && $start == -1) {
                   6911:             next; #deleted role
                   6912:         }
                   6913:         if (!defined($possible_status)) { 
                   6914:             $sectioncount{$section}++;
                   6915:         } else {
                   6916:             if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
                   6917:                 $status = 'active';
                   6918:             } elsif ($end < $now) {
                   6919:                 $status = 'future';
                   6920:             } elsif ($start > $now) {
                   6921:                 $status = 'previous';
                   6922:             }
                   6923:             if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
                   6924:                 $sectioncount{$section}++;
                   6925:             }
                   6926:         }
1.233     raeburn  6927:     }
1.366     albertel 6928:     return %sectioncount;
1.233     raeburn  6929: }
                   6930: 
1.274     raeburn  6931: ###############################################
1.294     raeburn  6932: 
                   6933: =pod
1.405     albertel 6934: 
                   6935: =item * &get_course_users()
                   6936: 
1.275     raeburn  6937: Retrieves usernames:domains for users in the specified course
                   6938: with specific role(s), and access status. 
                   6939: 
                   6940: Incoming parameters:
1.277     albertel 6941: 1. course domain
                   6942: 2. course number
                   6943: 3. access status: users must have - either active, 
1.275     raeburn  6944: previous, future, or all.
1.277     albertel 6945: 4. reference to array of permissible roles
1.288     raeburn  6946: 5. reference to array of section restrictions (optional)
                   6947: 6. reference to results object (hash of hashes).
                   6948: 7. reference to optional userdata hash
1.609     raeburn  6949: 8. reference to optional statushash
1.630     raeburn  6950: 9. flag if privileged users (except those set to unhide in
                   6951:    course settings) should be excluded    
1.609     raeburn  6952: Keys of top level results hash are roles.
1.275     raeburn  6953: Keys of inner hashes are username:domain, with 
                   6954: values set to access type.
1.288     raeburn  6955: Optional userdata hash returns an array with arguments in the 
                   6956: same order as loncoursedata::get_classlist() for student data.
                   6957: 
1.609     raeburn  6958: Optional statushash returns
                   6959: 
1.288     raeburn  6960: Entries for end, start, section and status are blank because
                   6961: of the possibility of multiple values for non-student roles.
                   6962: 
1.275     raeburn  6963: =cut
1.405     albertel 6964: 
1.275     raeburn  6965: ###############################################
1.405     albertel 6966: 
1.275     raeburn  6967: sub get_course_users {
1.630     raeburn  6968:     my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288     raeburn  6969:     my %idx = ();
1.419     raeburn  6970:     my %seclists;
1.288     raeburn  6971: 
                   6972:     $idx{udom} = &Apache::loncoursedata::CL_SDOM();
                   6973:     $idx{uname} =  &Apache::loncoursedata::CL_SNAME();
                   6974:     $idx{end} = &Apache::loncoursedata::CL_END();
                   6975:     $idx{start} = &Apache::loncoursedata::CL_START();
                   6976:     $idx{id} = &Apache::loncoursedata::CL_ID();
                   6977:     $idx{section} = &Apache::loncoursedata::CL_SECTION();
                   6978:     $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
                   6979:     $idx{status} = &Apache::loncoursedata::CL_STATUS();
                   6980: 
1.290     albertel 6981:     if (grep(/^st$/,@{$roles})) {
1.276     albertel 6982:         my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278     raeburn  6983:         my $now = time;
1.277     albertel 6984:         foreach my $student (keys(%{$classlist})) {
1.288     raeburn  6985:             my $match = 0;
1.412     raeburn  6986:             my $secmatch = 0;
1.419     raeburn  6987:             my $section = $$classlist{$student}[$idx{section}];
1.609     raeburn  6988:             my $status = $$classlist{$student}[$idx{status}];
1.419     raeburn  6989:             if ($section eq '') {
                   6990:                 $section = 'none';
                   6991:             }
1.291     albertel 6992:             if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 6993:                 if (grep(/^all$/,@{$sections})) {
1.412     raeburn  6994:                     $secmatch = 1;
                   6995:                 } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420     albertel 6996:                     if (grep(/^none$/,@{$sections})) {
1.412     raeburn  6997:                         $secmatch = 1;
                   6998:                     }
                   6999:                 } else {  
1.419     raeburn  7000: 		    if (grep(/^\Q$section\E$/,@{$sections})) {
1.412     raeburn  7001: 		        $secmatch = 1;
                   7002:                     }
1.290     albertel 7003: 		}
1.412     raeburn  7004:                 if (!$secmatch) {
                   7005:                     next;
                   7006:                 }
1.419     raeburn  7007:             }
1.275     raeburn  7008:             if (defined($$types{'active'})) {
1.288     raeburn  7009:                 if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275     raeburn  7010:                     push(@{$$users{st}{$student}},'active');
1.288     raeburn  7011:                     $match = 1;
1.275     raeburn  7012:                 }
                   7013:             }
                   7014:             if (defined($$types{'previous'})) {
1.609     raeburn  7015:                 if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275     raeburn  7016:                     push(@{$$users{st}{$student}},'previous');
1.288     raeburn  7017:                     $match = 1;
1.275     raeburn  7018:                 }
                   7019:             }
                   7020:             if (defined($$types{'future'})) {
1.609     raeburn  7021:                 if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275     raeburn  7022:                     push(@{$$users{st}{$student}},'future');
1.288     raeburn  7023:                     $match = 1;
1.275     raeburn  7024:                 }
                   7025:             }
1.609     raeburn  7026:             if ($match) {
                   7027:                 push(@{$seclists{$student}},$section);
                   7028:                 if (ref($userdata) eq 'HASH') {
                   7029:                     $$userdata{$student} = $$classlist{$student};
                   7030:                 }
                   7031:                 if (ref($statushash) eq 'HASH') {
                   7032:                     $statushash->{$student}{'st'}{$section} = $status;
                   7033:                 }
1.288     raeburn  7034:             }
1.275     raeburn  7035:         }
                   7036:     }
1.412     raeburn  7037:     if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439     raeburn  7038:         my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7039:         my $now = time;
1.609     raeburn  7040:         my %displaystatus = ( previous => 'Expired',
                   7041:                               active   => 'Active',
                   7042:                               future   => 'Future',
                   7043:                             );
1.630     raeburn  7044:         my %nothide;
                   7045:         if ($hidepriv) {
                   7046:             my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
                   7047:             foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
                   7048:                 if ($user !~ /:/) {
                   7049:                     $nothide{join(':',split(/[\@]/,$user))}=1;
                   7050:                 } else {
                   7051:                     $nothide{$user} = 1;
                   7052:                 }
                   7053:             }
                   7054:         }
1.439     raeburn  7055:         foreach my $person (sort(keys(%coursepersonnel))) {
1.288     raeburn  7056:             my $match = 0;
1.412     raeburn  7057:             my $secmatch = 0;
1.439     raeburn  7058:             my $status;
1.412     raeburn  7059:             my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275     raeburn  7060:             $user =~ s/:$//;
1.439     raeburn  7061:             my ($end,$start) = split(/:/,$coursepersonnel{$person});
                   7062:             if ($end == -1 || $start == -1) {
                   7063:                 next;
                   7064:             }
                   7065:             if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
                   7066:                 (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412     raeburn  7067:                 my ($uname,$udom) = split(/:/,$user);
                   7068:                 if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 7069:                     if (grep(/^all$/,@{$sections})) {
1.412     raeburn  7070:                         $secmatch = 1;
                   7071:                     } elsif ($usec eq '') {
1.420     albertel 7072:                         if (grep(/^none$/,@{$sections})) {
1.412     raeburn  7073:                             $secmatch = 1;
                   7074:                         }
                   7075:                     } else {
                   7076:                         if (grep(/^\Q$usec\E$/,@{$sections})) {
                   7077:                             $secmatch = 1;
                   7078:                         }
                   7079:                     }
                   7080:                     if (!$secmatch) {
                   7081:                         next;
                   7082:                     }
1.288     raeburn  7083:                 }
1.419     raeburn  7084:                 if ($usec eq '') {
                   7085:                     $usec = 'none';
                   7086:                 }
1.275     raeburn  7087:                 if ($uname ne '' && $udom ne '') {
1.630     raeburn  7088:                     if ($hidepriv) {
                   7089:                         if ((&Apache::lonnet::privileged($uname,$udom)) &&
                   7090:                             (!$nothide{$uname.':'.$udom})) {
                   7091:                             next;
                   7092:                         }
                   7093:                     }
1.503     raeburn  7094:                     if ($end > 0 && $end < $now) {
1.439     raeburn  7095:                         $status = 'previous';
                   7096:                     } elsif ($start > $now) {
                   7097:                         $status = 'future';
                   7098:                     } else {
                   7099:                         $status = 'active';
                   7100:                     }
1.277     albertel 7101:                     foreach my $type (keys(%{$types})) { 
1.275     raeburn  7102:                         if ($status eq $type) {
1.420     albertel 7103:                             if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419     raeburn  7104:                                 push(@{$$users{$role}{$user}},$type);
                   7105:                             }
1.288     raeburn  7106:                             $match = 1;
                   7107:                         }
                   7108:                     }
1.419     raeburn  7109:                     if (($match) && (ref($userdata) eq 'HASH')) {
                   7110:                         if (!exists($$userdata{$uname.':'.$udom})) {
                   7111: 			    &get_user_info($udom,$uname,\%idx,$userdata);
                   7112:                         }
1.420     albertel 7113:                         if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419     raeburn  7114:                             push(@{$seclists{$uname.':'.$udom}},$usec);
                   7115:                         }
1.609     raeburn  7116:                         if (ref($statushash) eq 'HASH') {
                   7117:                             $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
                   7118:                         }
1.275     raeburn  7119:                     }
                   7120:                 }
                   7121:             }
                   7122:         }
1.290     albertel 7123:         if (grep(/^ow$/,@{$roles})) {
1.279     raeburn  7124:             if ((defined($cdom)) && (defined($cnum))) {
                   7125:                 my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
                   7126:                 if ( defined($csettings{'internal.courseowner'}) ) {
                   7127:                     my $owner = $csettings{'internal.courseowner'};
1.609     raeburn  7128:                     next if ($owner eq '');
                   7129:                     my ($ownername,$ownerdom);
                   7130:                     if ($owner =~ /^([^:]+):([^:]+)$/) {
                   7131:                         $ownername = $1;
                   7132:                         $ownerdom = $2;
                   7133:                     } else {
                   7134:                         $ownername = $owner;
                   7135:                         $ownerdom = $cdom;
                   7136:                         $owner = $ownername.':'.$ownerdom;
1.439     raeburn  7137:                     }
                   7138:                     @{$$users{'ow'}{$owner}} = 'any';
1.290     albertel 7139:                     if (defined($userdata) && 
1.609     raeburn  7140: 			!exists($$userdata{$owner})) {
                   7141: 			&get_user_info($ownerdom,$ownername,\%idx,$userdata);
                   7142:                         if (!grep(/^none$/,@{$seclists{$owner}})) {
                   7143:                             push(@{$seclists{$owner}},'none');
                   7144:                         }
                   7145:                         if (ref($statushash) eq 'HASH') {
                   7146:                             $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419     raeburn  7147:                         }
1.290     albertel 7148: 		    }
1.279     raeburn  7149:                 }
                   7150:             }
                   7151:         }
1.419     raeburn  7152:         foreach my $user (keys(%seclists)) {
                   7153:             @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
                   7154:             $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
                   7155:         }
1.275     raeburn  7156:     }
                   7157:     return;
                   7158: }
                   7159: 
1.288     raeburn  7160: sub get_user_info {
                   7161:     my ($udom,$uname,$idx,$userdata) = @_;
1.289     albertel 7162:     $$userdata{$uname.':'.$udom}[$$idx{fullname}] = 
                   7163: 	&plainname($uname,$udom,'lastname');
1.291     albertel 7164:     $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297     raeburn  7165:     $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609     raeburn  7166:     my %idhash =  &Apache::lonnet::idrget($udom,($uname));
                   7167:     $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname}; 
1.288     raeburn  7168:     return;
                   7169: }
1.275     raeburn  7170: 
1.472     raeburn  7171: ###############################################
                   7172: 
                   7173: =pod
                   7174: 
                   7175: =item * &get_user_quota()
                   7176: 
                   7177: Retrieves quota assigned for storage of portfolio files for a user  
                   7178: 
                   7179: Incoming parameters:
                   7180: 1. user's username
                   7181: 2. user's domain
                   7182: 
                   7183: Returns:
1.536     raeburn  7184: 1. Disk quota (in Mb) assigned to student.
                   7185: 2. (Optional) Type of setting: custom or default
                   7186:    (individually assigned or default for user's 
                   7187:    institutional status).
                   7188: 3. (Optional) - User's institutional status (e.g., faculty, staff
                   7189:    or student - types as defined in localenroll::inst_usertypes 
                   7190:    for user's domain, which determines default quota for user.
                   7191: 4. (Optional) - Default quota which would apply to the user.
1.472     raeburn  7192: 
                   7193: If a value has been stored in the user's environment, 
1.536     raeburn  7194: it will return that, otherwise it returns the maximal default
                   7195: defined for the user's instituional status(es) in the domain.
1.472     raeburn  7196: 
                   7197: =cut
                   7198: 
                   7199: ###############################################
                   7200: 
                   7201: 
                   7202: sub get_user_quota {
                   7203:     my ($uname,$udom) = @_;
1.536     raeburn  7204:     my ($quota,$quotatype,$settingstatus,$defquota);
1.472     raeburn  7205:     if (!defined($udom)) {
                   7206:         $udom = $env{'user.domain'};
                   7207:     }
                   7208:     if (!defined($uname)) {
                   7209:         $uname = $env{'user.name'};
                   7210:     }
                   7211:     if (($udom eq '' || $uname eq '') ||
                   7212:         ($udom eq 'public') && ($uname eq 'public')) {
                   7213:         $quota = 0;
1.536     raeburn  7214:         $quotatype = 'default';
                   7215:         $defquota = 0; 
1.472     raeburn  7216:     } else {
1.536     raeburn  7217:         my $inststatus;
1.472     raeburn  7218:         if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
                   7219:             $quota = $env{'environment.portfolioquota'};
1.536     raeburn  7220:             $inststatus = $env{'environment.inststatus'};
1.472     raeburn  7221:         } else {
1.536     raeburn  7222:             my %userenv = 
                   7223:                 &Apache::lonnet::get('environment',['portfolioquota',
                   7224:                                      'inststatus'],$udom,$uname);
1.472     raeburn  7225:             my ($tmp) = keys(%userenv);
                   7226:             if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   7227:                 $quota = $userenv{'portfolioquota'};
1.536     raeburn  7228:                 $inststatus = $userenv{'inststatus'};
1.472     raeburn  7229:             } else {
                   7230:                 undef(%userenv);
                   7231:             }
                   7232:         }
1.536     raeburn  7233:         ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472     raeburn  7234:         if ($quota eq '') {
1.536     raeburn  7235:             $quota = $defquota;
                   7236:             $quotatype = 'default';
                   7237:         } else {
                   7238:             $quotatype = 'custom';
1.472     raeburn  7239:         }
                   7240:     }
1.536     raeburn  7241:     if (wantarray) {
                   7242:         return ($quota,$quotatype,$settingstatus,$defquota);
                   7243:     } else {
                   7244:         return $quota;
                   7245:     }
1.472     raeburn  7246: }
                   7247: 
                   7248: ###############################################
                   7249: 
                   7250: =pod
                   7251: 
                   7252: =item * &default_quota()
                   7253: 
1.536     raeburn  7254: Retrieves default quota assigned for storage of user portfolio files,
                   7255: given an (optional) user's institutional status.
1.472     raeburn  7256: 
                   7257: Incoming parameters:
                   7258: 1. domain
1.536     raeburn  7259: 2. (Optional) institutional status(es).  This is a : separated list of 
                   7260:    status types (e.g., faculty, staff, student etc.)
                   7261:    which apply to the user for whom the default is being retrieved.
                   7262:    If the institutional status string in undefined, the domain
                   7263:    default quota will be returned. 
1.472     raeburn  7264: 
                   7265: Returns:
                   7266: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536     raeburn  7267: 2. (Optional) institutional type which determined the value of the
                   7268:    default quota.
1.472     raeburn  7269: 
                   7270: If a value has been stored in the domain's configuration db,
                   7271: it will return that, otherwise it returns 20 (for backwards 
                   7272: compatibility with domains which have not set up a configuration
                   7273: db file; the original statically defined portfolio quota was 20 Mb). 
                   7274: 
1.536     raeburn  7275: If the user's status includes multiple types (e.g., staff and student),
                   7276: the largest default quota which applies to the user determines the
                   7277: default quota returned.
                   7278: 
1.780     raeburn  7279: =back
                   7280: 
1.472     raeburn  7281: =cut
                   7282: 
                   7283: ###############################################
                   7284: 
                   7285: 
                   7286: sub default_quota {
1.536     raeburn  7287:     my ($udom,$inststatus) = @_;
                   7288:     my ($defquota,$settingstatus);
                   7289:     my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622     raeburn  7290:                                             ['quotas'],$udom);
                   7291:     if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536     raeburn  7292:         if ($inststatus ne '') {
1.765     raeburn  7293:             my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536     raeburn  7294:             foreach my $item (@statuses) {
1.711     raeburn  7295:                 if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7296:                     if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
                   7297:                         if ($defquota eq '') {
                   7298:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7299:                             $settingstatus = $item;
                   7300:                         } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
                   7301:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7302:                             $settingstatus = $item;
                   7303:                         }
                   7304:                     }
                   7305:                 } else {
                   7306:                     if ($quotahash{'quotas'}{$item} ne '') {
                   7307:                         if ($defquota eq '') {
                   7308:                             $defquota = $quotahash{'quotas'}{$item};
                   7309:                             $settingstatus = $item;
                   7310:                         } elsif ($quotahash{'quotas'}{$item} > $defquota) {
                   7311:                             $defquota = $quotahash{'quotas'}{$item};
                   7312:                             $settingstatus = $item;
                   7313:                         }
1.536     raeburn  7314:                     }
                   7315:                 }
                   7316:             }
                   7317:         }
                   7318:         if ($defquota eq '') {
1.711     raeburn  7319:             if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7320:                 $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
                   7321:             } else {
                   7322:                 $defquota = $quotahash{'quotas'}{'default'};
                   7323:             }
1.536     raeburn  7324:             $settingstatus = 'default';
                   7325:         }
                   7326:     } else {
                   7327:         $settingstatus = 'default';
                   7328:         $defquota = 20;
                   7329:     }
                   7330:     if (wantarray) {
                   7331:         return ($defquota,$settingstatus);
1.472     raeburn  7332:     } else {
1.536     raeburn  7333:         return $defquota;
1.472     raeburn  7334:     }
                   7335: }
                   7336: 
1.384     raeburn  7337: sub get_secgrprole_info {
                   7338:     my ($cdom,$cnum,$needroles,$type)  = @_;
                   7339:     my %sections_count = &get_sections($cdom,$cnum);
                   7340:     my @sections =  (sort {$a <=> $b} keys(%sections_count));
                   7341:     my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
                   7342:     my @groups = sort(keys(%curr_groups));
                   7343:     my $allroles = [];
                   7344:     my $rolehash;
                   7345:     my $accesshash = {
                   7346:                      active => 'Currently has access',
                   7347:                      future => 'Will have future access',
                   7348:                      previous => 'Previously had access',
                   7349:                   };
                   7350:     if ($needroles) {
                   7351:         $rolehash = {'all' => 'all'};
1.385     albertel 7352:         my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7353: 	if (&Apache::lonnet::error(%user_roles)) {
                   7354: 	    undef(%user_roles);
                   7355: 	}
                   7356:         foreach my $item (keys(%user_roles)) {
1.384     raeburn  7357:             my ($role)=split(/\:/,$item,2);
                   7358:             if ($role eq 'cr') { next; }
                   7359:             if ($role =~ /^cr/) {
                   7360:                 $$rolehash{$role} = (split('/',$role))[3];
                   7361:             } else {
                   7362:                 $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
                   7363:             }
                   7364:         }
                   7365:         foreach my $key (sort(keys(%{$rolehash}))) {
                   7366:             push(@{$allroles},$key);
                   7367:         }
                   7368:         push (@{$allroles},'st');
                   7369:         $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
                   7370:     }
                   7371:     return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
                   7372: }
                   7373: 
1.555     raeburn  7374: sub user_picker {
1.627     raeburn  7375:     my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555     raeburn  7376:     my $currdom = $dom;
                   7377:     my %curr_selected = (
                   7378:                         srchin => 'dom',
1.580     raeburn  7379:                         srchby => 'lastname',
1.555     raeburn  7380:                       );
                   7381:     my $srchterm;
1.625     raeburn  7382:     if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555     raeburn  7383:         if ($srch->{'srchby'} ne '') {
                   7384:             $curr_selected{'srchby'} = $srch->{'srchby'};
                   7385:         }
                   7386:         if ($srch->{'srchin'} ne '') {
                   7387:             $curr_selected{'srchin'} = $srch->{'srchin'};
                   7388:         }
                   7389:         if ($srch->{'srchtype'} ne '') {
                   7390:             $curr_selected{'srchtype'} = $srch->{'srchtype'};
                   7391:         }
                   7392:         if ($srch->{'srchdomain'} ne '') {
                   7393:             $currdom = $srch->{'srchdomain'};
                   7394:         }
                   7395:         $srchterm = $srch->{'srchterm'};
                   7396:     }
                   7397:     my %lt=&Apache::lonlocal::texthash(
1.573     raeburn  7398:                     'usr'       => 'Search criteria',
1.563     raeburn  7399:                     'doma'      => 'Domain/institution to search',
1.558     albertel 7400:                     'uname'     => 'username',
                   7401:                     'lastname'  => 'last name',
1.555     raeburn  7402:                     'lastfirst' => 'last name, first name',
1.558     albertel 7403:                     'crs'       => 'in this course',
1.576     raeburn  7404:                     'dom'       => 'in selected LON-CAPA domain', 
1.558     albertel 7405:                     'alc'       => 'all LON-CAPA',
1.573     raeburn  7406:                     'instd'     => 'in institutional directory for selected domain',
1.558     albertel 7407:                     'exact'     => 'is',
                   7408:                     'contains'  => 'contains',
1.569     raeburn  7409:                     'begins'    => 'begins with',
1.571     raeburn  7410:                     'youm'      => "You must include some text to search for.",
                   7411:                     'thte'      => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
                   7412:                     'thet'      => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
                   7413:                     'yomc'      => "You must choose a domain when using an institutional directory search.",
                   7414:                     'ymcd'      => "You must choose a domain when using a domain search.",
                   7415:                     'whus'      => "When using searching by last,first you must include a comma as separator between last name and first name.",
                   7416:                     'whse'      => "When searching by last,first you must include at least one character in the first name.",
                   7417:                      'thfo'     => "The following need to be corrected before the search can be run:",
1.555     raeburn  7418:                                        );
1.563     raeburn  7419:     my $domform = &select_dom_form($currdom,'srchdomain',1,1);
                   7420:     my $srchinsel = ' <select name="srchin">';
1.555     raeburn  7421: 
                   7422:     my @srchins = ('crs','dom','alc','instd');
                   7423: 
                   7424:     foreach my $option (@srchins) {
                   7425:         # FIXME 'alc' option unavailable until 
                   7426:         #       loncreateuser::print_user_query_page()
                   7427:         #       has been completed.
                   7428:         next if ($option eq 'alc');
                   7429:         next if ($option eq 'crs' && !$env{'request.course.id'});
1.563     raeburn  7430:         if ($curr_selected{'srchin'} eq $option) {
                   7431:             $srchinsel .= ' 
                   7432:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7433:         } else {
                   7434:             $srchinsel .= '
                   7435:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7436:         }
1.555     raeburn  7437:     }
1.563     raeburn  7438:     $srchinsel .= "\n  </select>\n";
1.555     raeburn  7439: 
                   7440:     my $srchbysel =  ' <select name="srchby">';
1.580     raeburn  7441:     foreach my $option ('lastname','lastfirst','uname') {
1.555     raeburn  7442:         if ($curr_selected{'srchby'} eq $option) {
                   7443:             $srchbysel .= '
                   7444:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7445:         } else {
                   7446:             $srchbysel .= '
                   7447:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7448:          }
                   7449:     }
                   7450:     $srchbysel .= "\n  </select>\n";
                   7451: 
                   7452:     my $srchtypesel = ' <select name="srchtype">';
1.580     raeburn  7453:     foreach my $option ('begins','contains','exact') {
1.555     raeburn  7454:         if ($curr_selected{'srchtype'} eq $option) {
                   7455:             $srchtypesel .= '
                   7456:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7457:         } else {
                   7458:             $srchtypesel .= '
                   7459:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7460:         }
                   7461:     }
                   7462:     $srchtypesel .= "\n  </select>\n";
                   7463: 
1.558     albertel 7464:     my ($newuserscript,$new_user_create);
1.556     raeburn  7465: 
                   7466:     if ($forcenewuser) {
1.576     raeburn  7467:         if (ref($srch) eq 'HASH') {
                   7468:             if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627     raeburn  7469:                 if ($cancreate) {
                   7470:                     $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>';
                   7471:                 } else {
1.799   ! bisitz   7472:                     my $helplink = 'javascript:helpMenu('."'display'".')';
1.627     raeburn  7473:                     my %usertypetext = (
                   7474:                         official   => 'institutional',
                   7475:                         unofficial => 'non-institutional',
                   7476:                     );
1.799   ! bisitz   7477:                     $new_user_create = '<p class="LC_warning">'
        !          7478:                                       .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
        !          7479:                                       .' '
        !          7480:                                       .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
        !          7481:                                           ,'<a href="'.$helplink.'">','</a>')
        !          7482:                                       .'</p><br />';
1.627     raeburn  7483:                 }
1.576     raeburn  7484:             }
                   7485:         }
                   7486: 
1.556     raeburn  7487:         $newuserscript = <<"ENDSCRIPT";
                   7488: 
1.570     raeburn  7489: function setSearch(createnew,callingForm) {
1.556     raeburn  7490:     if (createnew == 1) {
1.570     raeburn  7491:         for (var i=0; i<callingForm.srchby.length; i++) {
                   7492:             if (callingForm.srchby.options[i].value == 'uname') {
                   7493:                 callingForm.srchby.selectedIndex = i;
1.556     raeburn  7494:             }
                   7495:         }
1.570     raeburn  7496:         for (var i=0; i<callingForm.srchin.length; i++) {
                   7497:             if ( callingForm.srchin.options[i].value == 'dom') {
                   7498: 		callingForm.srchin.selectedIndex = i;
1.556     raeburn  7499:             }
                   7500:         }
1.570     raeburn  7501:         for (var i=0; i<callingForm.srchtype.length; i++) {
                   7502:             if (callingForm.srchtype.options[i].value == 'exact') {
                   7503:                 callingForm.srchtype.selectedIndex = i;
1.556     raeburn  7504:             }
                   7505:         }
1.570     raeburn  7506:         for (var i=0; i<callingForm.srchdomain.length; i++) {
                   7507:             if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
                   7508:                 callingForm.srchdomain.selectedIndex = i;
1.556     raeburn  7509:             }
                   7510:         }
                   7511:     }
                   7512: }
                   7513: ENDSCRIPT
1.558     albertel 7514: 
1.556     raeburn  7515:     }
                   7516: 
1.555     raeburn  7517:     my $output = <<"END_BLOCK";
1.556     raeburn  7518: <script type="text/javascript">
1.570     raeburn  7519: function validateEntry(callingForm) {
1.558     albertel 7520: 
1.556     raeburn  7521:     var checkok = 1;
1.558     albertel 7522:     var srchin;
1.570     raeburn  7523:     for (var i=0; i<callingForm.srchin.length; i++) {
                   7524: 	if ( callingForm.srchin[i].checked ) {
                   7525: 	    srchin = callingForm.srchin[i].value;
1.558     albertel 7526: 	}
                   7527:     }
                   7528: 
1.570     raeburn  7529:     var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
                   7530:     var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
                   7531:     var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
                   7532:     var srchterm =  callingForm.srchterm.value;
                   7533:     var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556     raeburn  7534:     var msg = "";
                   7535: 
                   7536:     if (srchterm == "") {
                   7537:         checkok = 0;
1.571     raeburn  7538:         msg += "$lt{'youm'}\\n";
1.556     raeburn  7539:     }
                   7540: 
1.569     raeburn  7541:     if (srchtype== 'begins') {
                   7542:         if (srchterm.length < 2) {
                   7543:             checkok = 0;
1.571     raeburn  7544:             msg += "$lt{'thte'}\\n";
1.569     raeburn  7545:         }
                   7546:     }
                   7547: 
1.556     raeburn  7548:     if (srchtype== 'contains') {
                   7549:         if (srchterm.length < 3) {
                   7550:             checkok = 0;
1.571     raeburn  7551:             msg += "$lt{'thet'}\\n";
1.556     raeburn  7552:         }
                   7553:     }
                   7554:     if (srchin == 'instd') {
                   7555:         if (srchdomain == '') {
                   7556:             checkok = 0;
1.571     raeburn  7557:             msg += "$lt{'yomc'}\\n";
1.556     raeburn  7558:         }
                   7559:     }
                   7560:     if (srchin == 'dom') {
                   7561:         if (srchdomain == '') {
                   7562:             checkok = 0;
1.571     raeburn  7563:             msg += "$lt{'ymcd'}\\n";
1.556     raeburn  7564:         }
                   7565:     }
                   7566:     if (srchby == 'lastfirst') {
                   7567:         if (srchterm.indexOf(",") == -1) {
                   7568:             checkok = 0;
1.571     raeburn  7569:             msg += "$lt{'whus'}\\n";
1.556     raeburn  7570:         }
                   7571:         if (srchterm.indexOf(",") == srchterm.length -1) {
                   7572:             checkok = 0;
1.571     raeburn  7573:             msg += "$lt{'whse'}\\n";
1.556     raeburn  7574:         }
                   7575:     }
                   7576:     if (checkok == 0) {
1.571     raeburn  7577:         alert("$lt{'thfo'}\\n"+msg);
1.556     raeburn  7578:         return;
                   7579:     }
                   7580:     if (checkok == 1) {
1.570     raeburn  7581:         callingForm.submit();
1.556     raeburn  7582:     }
                   7583: }
                   7584: 
                   7585: $newuserscript
                   7586: 
                   7587: </script>
1.558     albertel 7588: 
                   7589: $new_user_create
                   7590: 
1.555     raeburn  7591: <table>
1.558     albertel 7592:  <tr>
1.573     raeburn  7593:   <td>$lt{'doma'}:</td>
                   7594:   <td>$domform</td>
                   7595:   </td>
                   7596:  </tr>
                   7597:  <tr>
                   7598:   <td>$lt{'usr'}:</td>
1.563     raeburn  7599:   <td>$srchbysel
                   7600:       $srchtypesel 
                   7601:       <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564     albertel 7602:       $srchinsel 
1.563     raeburn  7603:   </td>
                   7604:  </tr>
1.555     raeburn  7605: </table>
                   7606: <br />
                   7607: END_BLOCK
1.558     albertel 7608: 
1.555     raeburn  7609:     return $output;
                   7610: }
                   7611: 
1.612     raeburn  7612: sub user_rule_check {
1.615     raeburn  7613:     my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612     raeburn  7614:     my $response;
                   7615:     if (ref($usershash) eq 'HASH') {
                   7616:         foreach my $user (keys(%{$usershash})) {
                   7617:             my ($uname,$udom) = split(/:/,$user);
                   7618:             next if ($udom eq '' || $uname eq '');
1.615     raeburn  7619:             my ($id,$newuser);
1.612     raeburn  7620:             if (ref($usershash->{$user}) eq 'HASH') {
1.615     raeburn  7621:                 $newuser = $usershash->{$user}->{'newuser'};
1.612     raeburn  7622:                 $id = $usershash->{$user}->{'id'};
                   7623:             }
                   7624:             my $inst_response;
                   7625:             if (ref($checks) eq 'HASH') {
                   7626:                 if (defined($checks->{'username'})) {
1.615     raeburn  7627:                     ($inst_response,%{$inst_results->{$user}}) = 
1.612     raeburn  7628:                         &Apache::lonnet::get_instuser($udom,$uname);
                   7629:                 } elsif (defined($checks->{'id'})) {
1.615     raeburn  7630:                     ($inst_response,%{$inst_results->{$user}}) =
1.612     raeburn  7631:                         &Apache::lonnet::get_instuser($udom,undef,$id);
                   7632:                 }
1.615     raeburn  7633:             } else {
                   7634:                 ($inst_response,%{$inst_results->{$user}}) =
                   7635:                     &Apache::lonnet::get_instuser($udom,$uname);
                   7636:                 return;
1.612     raeburn  7637:             }
1.615     raeburn  7638:             if (!$got_rules->{$udom}) {
1.612     raeburn  7639:                 my %domconfig = &Apache::lonnet::get_dom('configuration',
                   7640:                                                   ['usercreation'],$udom);
                   7641:                 if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615     raeburn  7642:                     foreach my $item ('username','id') {
1.612     raeburn  7643:                         if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
                   7644:                             $$curr_rules{$udom}{$item} = 
                   7645:                                 $domconfig{'usercreation'}{$item.'_rule'};
1.585     raeburn  7646:                         }
                   7647:                     }
                   7648:                 }
1.615     raeburn  7649:                 $got_rules->{$udom} = 1;  
1.585     raeburn  7650:             }
1.612     raeburn  7651:             foreach my $item (keys(%{$checks})) {
                   7652:                 if (ref($$curr_rules{$udom}) eq 'HASH') {
                   7653:                     if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
                   7654:                         if (@{$$curr_rules{$udom}{$item}} > 0) {
                   7655:                             my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
                   7656:                             foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
                   7657:                                 if ($rule_check{$rule}) {
                   7658:                                     $$rulematch{$user}{$item} = $rule;
                   7659:                                     if ($inst_response eq 'ok') {
1.615     raeburn  7660:                                         if (ref($inst_results) eq 'HASH') {
                   7661:                                             if (ref($inst_results->{$user}) eq 'HASH') {
                   7662:                                                 if (keys(%{$inst_results->{$user}}) == 0) {
                   7663:                                                     $$alerts{$item}{$udom}{$uname} = 1;
                   7664:                                                 }
1.612     raeburn  7665:                                             }
                   7666:                                         }
1.615     raeburn  7667:                                     }
                   7668:                                     last;
1.585     raeburn  7669:                                 }
                   7670:                             }
                   7671:                         }
                   7672:                     }
                   7673:                 }
                   7674:             }
                   7675:         }
                   7676:     }
1.612     raeburn  7677:     return;
                   7678: }
                   7679: 
                   7680: sub user_rule_formats {
                   7681:     my ($domain,$domdesc,$curr_rules,$check) = @_;
                   7682:     my %text = ( 
                   7683:                  'username' => 'Usernames',
                   7684:                  'id'       => 'IDs',
                   7685:                );
                   7686:     my $output;
                   7687:     my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
                   7688:     if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
                   7689:         if (@{$ruleorder} > 0) {
                   7690:             $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>';
                   7691:             foreach my $rule (@{$ruleorder}) {
                   7692:                 if (ref($curr_rules) eq 'ARRAY') {
                   7693:                     if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
                   7694:                         if (ref($rules->{$rule}) eq 'HASH') {
                   7695:                             $output .= '<li>'.$rules->{$rule}{'name'}.': '.
                   7696:                                         $rules->{$rule}{'desc'}.'</li>';
                   7697:                         }
                   7698:                     }
                   7699:                 }
                   7700:             }
                   7701:             $output .= '</ul>';
                   7702:         }
                   7703:     }
                   7704:     return $output;
                   7705: }
                   7706: 
                   7707: sub instrule_disallow_msg {
1.615     raeburn  7708:     my ($checkitem,$domdesc,$count,$mode) = @_;
1.612     raeburn  7709:     my $response;
                   7710:     my %text = (
                   7711:                   item   => 'username',
                   7712:                   items  => 'usernames',
                   7713:                   match  => 'matches',
                   7714:                   do     => 'does',
                   7715:                   action => 'a username',
                   7716:                   one    => 'one',
                   7717:                );
                   7718:     if ($count > 1) {
                   7719:         $text{'item'} = 'usernames';
                   7720:         $text{'match'} ='match';
                   7721:         $text{'do'} = 'do';
                   7722:         $text{'action'} = 'usernames',
                   7723:         $text{'one'} = 'ones';
                   7724:     }
                   7725:     if ($checkitem eq 'id') {
                   7726:         $text{'items'} = 'IDs';
                   7727:         $text{'item'} = 'ID';
                   7728:         $text{'action'} = 'an ID';
1.615     raeburn  7729:         if ($count > 1) {
                   7730:             $text{'item'} = 'IDs';
                   7731:             $text{'action'} = 'IDs';
                   7732:         }
1.612     raeburn  7733:     }
1.674     bisitz   7734:     $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  7735:     if ($mode eq 'upload') {
                   7736:         if ($checkitem eq 'username') {
                   7737:             $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'}.");
                   7738:         } elsif ($checkitem eq 'id') {
1.674     bisitz   7739:             $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  7740:         }
1.669     raeburn  7741:     } elsif ($mode eq 'selfcreate') {
                   7742:         if ($checkitem eq 'id') {
                   7743:             $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.");
                   7744:         }
1.615     raeburn  7745:     } else {
                   7746:         if ($checkitem eq 'username') {
                   7747:             $response .= &mt("You must choose $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
                   7748:         } elsif ($checkitem eq 'id') {
                   7749:             $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.");
                   7750:         }
1.612     raeburn  7751:     }
                   7752:     return $response;
1.585     raeburn  7753: }
                   7754: 
1.624     raeburn  7755: sub personal_data_fieldtitles {
                   7756:     my %fieldtitles = &Apache::lonlocal::texthash (
                   7757:                         id => 'Student/Employee ID',
                   7758:                         permanentemail => 'E-mail address',
                   7759:                         lastname => 'Last Name',
                   7760:                         firstname => 'First Name',
                   7761:                         middlename => 'Middle Name',
                   7762:                         generation => 'Generation',
                   7763:                         gen => 'Generation',
1.765     raeburn  7764:                         inststatus => 'Affiliation',
1.624     raeburn  7765:                    );
                   7766:     return %fieldtitles;
                   7767: }
                   7768: 
1.642     raeburn  7769: sub sorted_inst_types {
                   7770:     my ($dom) = @_;
                   7771:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
                   7772:     my $othertitle = &mt('All users');
                   7773:     if ($env{'request.course.id'}) {
1.668     raeburn  7774:         $othertitle  = &mt('Any users');
1.642     raeburn  7775:     }
                   7776:     my @types;
                   7777:     if (ref($order) eq 'ARRAY') {
                   7778:         @types = @{$order};
                   7779:     }
                   7780:     if (@types == 0) {
                   7781:         if (ref($usertypes) eq 'HASH') {
                   7782:             @types = sort(keys(%{$usertypes}));
                   7783:         }
                   7784:     }
                   7785:     if (keys(%{$usertypes}) > 0) {
                   7786:         $othertitle = &mt('Other users');
                   7787:     }
                   7788:     return ($othertitle,$usertypes,\@types);
                   7789: }
                   7790: 
1.645     raeburn  7791: sub get_institutional_codes {
                   7792:     my ($settings,$allcourses,$LC_code) = @_;
                   7793: # Get complete list of course sections to update
                   7794:     my @currsections = ();
                   7795:     my @currxlists = ();
                   7796:     my $coursecode = $$settings{'internal.coursecode'};
                   7797: 
                   7798:     if ($$settings{'internal.sectionnums'} ne '') {
                   7799:         @currsections = split(/,/,$$settings{'internal.sectionnums'});
                   7800:     }
                   7801: 
                   7802:     if ($$settings{'internal.crosslistings'} ne '') {
                   7803:         @currxlists = split(/,/,$$settings{'internal.crosslistings'});
                   7804:     }
                   7805: 
                   7806:     if (@currxlists > 0) {
                   7807:         foreach (@currxlists) {
                   7808:             if (m/^([^:]+):(\w*)$/) {
                   7809:                 unless (grep/^$1$/,@{$allcourses}) {
                   7810:                     push @{$allcourses},$1;
                   7811:                     $$LC_code{$1} = $2;
                   7812:                 }
                   7813:             }
                   7814:         }
                   7815:     }
                   7816:  
                   7817:     if (@currsections > 0) {
                   7818:         foreach (@currsections) {
                   7819:             if (m/^(\w+):(\w*)$/) {
                   7820:                 my $sec = $coursecode.$1;
                   7821:                 my $lc_sec = $2;
                   7822:                 unless (grep/^$sec$/,@{$allcourses}) {
                   7823:                     push @{$allcourses},$sec;
                   7824:                     $$LC_code{$sec} = $lc_sec;
                   7825:                 }
                   7826:             }
                   7827:         }
                   7828:     }
                   7829:     return;
                   7830: }
                   7831: 
1.112     bowersj2 7832: =pod
                   7833: 
1.780     raeburn  7834: =head1 Slot Helpers
                   7835: 
                   7836: =over 4
                   7837: 
                   7838: =item * sorted_slots()
                   7839: 
                   7840: Sorts an array of slot names in order of slot start time (earliest first). 
                   7841: 
                   7842: Inputs:
                   7843: 
                   7844: =over 4
                   7845: 
                   7846: slotsarr  - Reference to array of unsorted slot names.
                   7847: 
                   7848: slots     - Reference to hash of hash, where outer hash keys are slot names.
                   7849: 
1.549     albertel 7850: =back
                   7851: 
1.780     raeburn  7852: Returns:
                   7853: 
                   7854: =over 4
                   7855: 
                   7856: sorted   - An array of slot names sorted by the start time of the slot.
                   7857: 
                   7858: =back
                   7859: 
                   7860: =back
                   7861: 
                   7862: =cut
                   7863: 
                   7864: 
                   7865: sub sorted_slots {
                   7866:     my ($slotsarr,$slots) = @_;
                   7867:     my @sorted;
                   7868:     if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
                   7869:         @sorted =
                   7870:             sort {
                   7871:                      if (ref($slots->{$a}) && ref($slots->{$b})) {
                   7872:                          return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
                   7873:                      }
                   7874:                      if (ref($slots->{$a})) { return -1;}
                   7875:                      if (ref($slots->{$b})) { return 1;}
                   7876:                      return 0;
                   7877:                  } @{$slotsarr};
                   7878:     }
                   7879:     return @sorted;
                   7880: }
                   7881: 
                   7882: 
                   7883: =pod
                   7884: 
1.549     albertel 7885: =head1 HTTP Helpers
                   7886: 
                   7887: =over 4
                   7888: 
1.648     raeburn  7889: =item * &get_unprocessed_cgi($query,$possible_names)
1.112     bowersj2 7890: 
1.258     albertel 7891: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112     bowersj2 7892: $query.  The parameters listed in $possible_names (an array reference),
1.258     albertel 7893: will be set in $env{'form.name'} if they do not already exist.
1.112     bowersj2 7894: 
                   7895: Typically called with $ENV{'QUERY_STRING'} as the first parameter.  
                   7896: $possible_names is an ref to an array of form element names.  As an example:
                   7897: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258     albertel 7898: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112     bowersj2 7899: 
                   7900: =cut
1.1       albertel 7901: 
1.6       albertel 7902: sub get_unprocessed_cgi {
1.25      albertel 7903:   my ($query,$possible_names)= @_;
1.26      matthew  7904:   # $Apache::lonxml::debug=1;
1.356     albertel 7905:   foreach my $pair (split(/&/,$query)) {
                   7906:     my ($name, $value) = split(/=/,$pair);
1.369     www      7907:     $name = &unescape($name);
1.25      albertel 7908:     if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
                   7909:       $value =~ tr/+/ /;
                   7910:       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258     albertel 7911:       unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25      albertel 7912:     }
1.16      harris41 7913:   }
1.6       albertel 7914: }
                   7915: 
1.112     bowersj2 7916: =pod
                   7917: 
1.648     raeburn  7918: =item * &cacheheader() 
1.112     bowersj2 7919: 
                   7920: returns cache-controlling header code
                   7921: 
                   7922: =cut
                   7923: 
1.7       albertel 7924: sub cacheheader {
1.258     albertel 7925:     unless ($env{'request.method'} eq 'GET') { return ''; }
1.216     albertel 7926:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
                   7927:     my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7       albertel 7928:                 <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
                   7929:                 <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216     albertel 7930:     return $output;
1.7       albertel 7931: }
                   7932: 
1.112     bowersj2 7933: =pod
                   7934: 
1.648     raeburn  7935: =item * &no_cache($r) 
1.112     bowersj2 7936: 
                   7937: specifies header code to not have cache
                   7938: 
                   7939: =cut
                   7940: 
1.9       albertel 7941: sub no_cache {
1.216     albertel 7942:     my ($r) = @_;
                   7943:     if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258     albertel 7944: 	$env{'request.method'} ne 'GET') { return ''; }
1.216     albertel 7945:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
                   7946:     $r->no_cache(1);
                   7947:     $r->header_out("Expires" => $date);
                   7948:     $r->header_out("Pragma" => "no-cache");
1.123     www      7949: }
                   7950: 
                   7951: sub content_type {
1.181     albertel 7952:     my ($r,$type,$charset) = @_;
1.299     foxr     7953:     if ($r) {
                   7954: 	#  Note that printout.pl calls this with undef for $r.
                   7955: 	&no_cache($r);
                   7956:     }
1.258     albertel 7957:     if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181     albertel 7958:     unless ($charset) {
                   7959: 	$charset=&Apache::lonlocal::current_encoding;
                   7960:     }
                   7961:     if ($charset) { $type.='; charset='.$charset; }
                   7962:     if ($r) {
                   7963: 	$r->content_type($type);
                   7964:     } else {
                   7965: 	print("Content-type: $type\n\n");
                   7966:     }
1.9       albertel 7967: }
1.25      albertel 7968: 
1.112     bowersj2 7969: =pod
                   7970: 
1.648     raeburn  7971: =item * &add_to_env($name,$value) 
1.112     bowersj2 7972: 
1.258     albertel 7973: adds $name to the %env hash with value
1.112     bowersj2 7974: $value, if $name already exists, the entry is converted to an array
                   7975: reference and $value is added to the array.
                   7976: 
                   7977: =cut
                   7978: 
1.25      albertel 7979: sub add_to_env {
                   7980:   my ($name,$value)=@_;
1.258     albertel 7981:   if (defined($env{$name})) {
                   7982:     if (ref($env{$name})) {
1.25      albertel 7983:       #already have multiple values
1.258     albertel 7984:       push(@{ $env{$name} },$value);
1.25      albertel 7985:     } else {
                   7986:       #first time seeing multiple values, convert hash entry to an arrayref
1.258     albertel 7987:       my $first=$env{$name};
                   7988:       undef($env{$name});
                   7989:       push(@{ $env{$name} },$first,$value);
1.25      albertel 7990:     }
                   7991:   } else {
1.258     albertel 7992:     $env{$name}=$value;
1.25      albertel 7993:   }
1.31      albertel 7994: }
1.149     albertel 7995: 
                   7996: =pod
                   7997: 
1.648     raeburn  7998: =item * &get_env_multiple($name) 
1.149     albertel 7999: 
1.258     albertel 8000: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149     albertel 8001: values may be defined and end up as an array ref.
                   8002: 
                   8003: returns an array of values
                   8004: 
                   8005: =cut
                   8006: 
                   8007: sub get_env_multiple {
                   8008:     my ($name) = @_;
                   8009:     my @values;
1.258     albertel 8010:     if (defined($env{$name})) {
1.149     albertel 8011:         # exists is it an array
1.258     albertel 8012:         if (ref($env{$name})) {
                   8013:             @values=@{ $env{$name} };
1.149     albertel 8014:         } else {
1.258     albertel 8015:             $values[0]=$env{$name};
1.149     albertel 8016:         }
                   8017:     }
                   8018:     return(@values);
                   8019: }
                   8020: 
1.660     raeburn  8021: sub ask_for_embedded_content {
                   8022:     my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
                   8023:     my $upload_output = '
                   8024:    <form name="upload_embedded" action="'.$actionurl.'"
                   8025:                   method="post" enctype="multipart/form-data">';
                   8026:     $upload_output .= $state;
1.661     raeburn  8027:     $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660     raeburn  8028: 
                   8029:     my $num = 0;
                   8030:     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
                   8031:         $upload_output .= &start_data_table_row().
                   8032:             '<td>'.$embed_file.'</td><td>';
                   8033:         if ($args->{'ignore_remote_references'}
                   8034:             && $embed_file =~ m{^\w+://}) {
                   8035:             $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
                   8036:         } elsif ($args->{'error_on_invalid_names'}
                   8037:             && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
                   8038: 
                   8039:             $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
                   8040: 
                   8041:         } else {
                   8042:             $upload_output .='
1.661     raeburn  8043:            <input name="embedded_item_'.$num.'" type="file" value="" />
1.660     raeburn  8044:            <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
                   8045:             my $attrib = join(':',@{$$allfiles{$embed_file}});
                   8046:             $upload_output .=
                   8047:                 "\n\t\t".
                   8048:                 '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
                   8049:                 $attrib.'" />';
                   8050:             if (exists($$codebase{$embed_file})) {
                   8051:                 $upload_output .=
                   8052:                     "\n\t\t".
                   8053:                     '<input name="codebase_'.$num.'" type="hidden" value="'.
                   8054:                     &escape($$codebase{$embed_file}).'" />';
                   8055:             }
                   8056:         }
                   8057:         $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
                   8058:         $num++;
                   8059:     }
                   8060:     $upload_output .= &Apache::loncommon::end_data_table().'<br />
                   8061:    <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
                   8062:    <input type ="submit" value="'.&mt('Upload Listed Files').'" />
                   8063:    '.&mt('(only files for which a location has been provided will be uploaded)').'
                   8064:    </form>';
                   8065:     return $upload_output;
                   8066: }
                   8067: 
1.661     raeburn  8068: sub upload_embedded {
                   8069:     my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
                   8070:         $current_disk_usage) = @_;
                   8071:     my $output;
                   8072:     for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
                   8073:         next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
                   8074:         my $orig_uploaded_filename =
                   8075:             $env{'form.embedded_item_'.$i.'.filename'};
                   8076: 
                   8077:         $env{'form.embedded_orig_'.$i} =
                   8078:             &unescape($env{'form.embedded_orig_'.$i});
                   8079:         my ($path,$fname) =
                   8080:             ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
                   8081:         # no path, whole string is fname
                   8082:         if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
                   8083: 
                   8084:         $path = $env{'form.currentpath'}.$path;
                   8085:         $fname = &Apache::lonnet::clean_filename($fname);
                   8086:         # See if there is anything left
                   8087:         next if ($fname eq '');
                   8088: 
                   8089:         # Check if file already exists as a file or directory.
                   8090:         my ($state,$msg);
                   8091:         if ($context eq 'portfolio') {
                   8092:             my $port_path = $dirpath;
                   8093:             if ($group ne '') {
                   8094:                 $port_path = "groups/$group/$port_path";
                   8095:             }
                   8096:             ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
                   8097:                                               $dir_root,$port_path,$disk_quota,
                   8098:                                               $current_disk_usage,$uname,$udom);
                   8099:             if ($state eq 'will_exceed_quota'
                   8100:                 || $state eq 'file_locked'
                   8101:                 || $state eq 'file_exists' ) {
                   8102:                 $output .= $msg;
                   8103:                 next;
                   8104:             }
                   8105:         } elsif (($context eq 'author') || ($context eq 'testbank')) {
                   8106:             ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
                   8107:             if ($state eq 'exists') {
                   8108:                 $output .= $msg;
                   8109:                 next;
                   8110:             }
                   8111:         }
                   8112:         # Check if extension is valid
                   8113:         if (($fname =~ /\.(\w+)$/) &&
                   8114:             (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   8115:             $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
                   8116:             next;
                   8117:         } elsif (($fname =~ /\.(\w+)$/) &&
                   8118:                  (!defined(&Apache::loncommon::fileembstyle($1)))) {
                   8119:             $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   8120:             next;
                   8121:         } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
                   8122:             $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
                   8123:             next;
                   8124:         }
                   8125: 
                   8126:         $env{'form.embedded_item_'.$i.'.filename'}=$fname;
                   8127:         if ($context eq 'portfolio') {
                   8128:             my $result=
                   8129:                 &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
                   8130:                                                 $dirpath.$path);
                   8131:             if ($result !~ m|^/uploaded/|) {
                   8132:                 $output .= '<span class="LC_error">'
                   8133:                       .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
                   8134:                            ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
                   8135:                       .'</span><br />';
                   8136:                 next;
                   8137:             } else {
                   8138:                 $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
                   8139:                            $path.$fname.'</span>').'</p>';     
                   8140:             }
                   8141:         } else {
                   8142: # Save the file
                   8143:             my $target = $env{'form.embedded_item_'.$i};
                   8144:             my $fullpath = $dir_root.$dirpath.'/'.$path;
                   8145:             my $dest = $fullpath.$fname;
                   8146:             my $url = $url_root.$dirpath.'/'.$path.$fname;
                   8147:             my @parts=split(/\//,$fullpath);
                   8148:             my $count;
                   8149:             my $filepath = $dir_root;
                   8150:             for ($count=4;$count<=$#parts;$count++) {
                   8151:                 $filepath .= "/$parts[$count]";
                   8152:                 if ((-e $filepath)!=1) {
                   8153:                     mkdir($filepath,0770);
                   8154:                 }
                   8155:             }
                   8156:             my $fh;
                   8157:             if (!open($fh,'>'.$dest)) {
                   8158:                 &Apache::lonnet::logthis('Failed to create '.$dest);
                   8159:                 $output .= '<span class="LC_error">'.
                   8160:                            &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   8161:                            '</span><br />';
                   8162:             } else {
                   8163:                 if (!print $fh $env{'form.embedded_item_'.$i}) {
                   8164:                     &Apache::lonnet::logthis('Failed to write to '.$dest);
                   8165:                     $output .= '<span class="LC_error">'.
                   8166:                               &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   8167:                               '</span><br />';
                   8168:                 } else {
                   8169:                     if ($context eq 'testbank') {
                   8170:                         $output .= &mt('Embedded file uploaded successfully:').
                   8171:                                    '&nbsp;<a href="'.$url.'">'.
                   8172:                                    $orig_uploaded_filename.'</a><br />';
                   8173:                     } else {
1.705     tempelho 8174:                         $output .= '<span class=\"LC_fontsize_large\">'.
1.661     raeburn  8175:                                    &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705     tempelho 8176:                                    $orig_uploaded_filename.'</a>').'</span><br />';
1.661     raeburn  8177:                     }
                   8178:                 }
                   8179:                 close($fh);
                   8180:             }
                   8181:         }
                   8182:     }
                   8183:     return $output;
                   8184: }
                   8185: 
                   8186: sub check_for_existing {
                   8187:     my ($path,$fname,$element) = @_;
                   8188:     my ($state,$msg);
                   8189:     if (-d $path.'/'.$fname) {
                   8190:         $state = 'exists';
                   8191:         $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   8192:     } elsif (-e $path.'/'.$fname) {
                   8193:         $state = 'exists';
                   8194:         $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   8195:     }
                   8196:     if ($state eq 'exists') {
                   8197:         $msg = '<span class="LC_error">'.$msg.'</span><br />';
                   8198:     }
                   8199:     return ($state,$msg);
                   8200: }
                   8201: 
                   8202: sub check_for_upload {
                   8203:     my ($path,$fname,$group,$element,$portfolio_root,$port_path,
                   8204:         $disk_quota,$current_disk_usage,$uname,$udom) = @_;
                   8205:     my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
                   8206:     my $getpropath = 1;
                   8207:     my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
                   8208:                                             $getpropath);
                   8209:     my $found_file = 0;
                   8210:     my $locked_file = 0;
                   8211:     foreach my $line (@dir_list) {
                   8212:         my ($file_name)=split(/\&/,$line,2);
                   8213:         if ($file_name eq $fname){
                   8214:             $file_name = $path.$file_name;
                   8215:             if ($group ne '') {
                   8216:                 $file_name = $group.$file_name;
                   8217:             }
                   8218:             $found_file = 1;
                   8219:             if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
                   8220:                 $locked_file = 1;
                   8221:             }
                   8222:         }
                   8223:     }
                   8224:     if (($current_disk_usage + $filesize) > $disk_quota){
                   8225:         my $msg = '<span class="LC_error">'.
                   8226:                 &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
                   8227:                   '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
                   8228:         return ('will_exceed_quota',$msg);
                   8229:     } elsif ($found_file) {
                   8230:         if ($locked_file) {
                   8231:             my $msg = '<span class="LC_error">';
                   8232:             $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>');
                   8233:             $msg .= '</span><br />';
                   8234:             $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
                   8235:             return ('file_locked',$msg);
                   8236:         } else {
                   8237:             my $msg = '<span class="LC_error">';
                   8238:             $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'});
                   8239:             $msg .= '</span>';
                   8240:             $msg .= '<br />';
                   8241:             $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
                   8242:             return ('file_exists',$msg);
                   8243:         }
                   8244:     }
                   8245: }
                   8246: 
1.31      albertel 8247: 
1.41      ng       8248: =pod
1.45      matthew  8249: 
1.464     albertel 8250: =back
1.41      ng       8251: 
1.112     bowersj2 8252: =head1 CSV Upload/Handling functions
1.38      albertel 8253: 
1.41      ng       8254: =over 4
                   8255: 
1.648     raeburn  8256: =item * &upfile_store($r)
1.41      ng       8257: 
                   8258: Store uploaded file, $r should be the HTTP Request object,
1.258     albertel 8259: needs $env{'form.upfile'}
1.41      ng       8260: returns $datatoken to be put into hidden field
                   8261: 
                   8262: =cut
1.31      albertel 8263: 
                   8264: sub upfile_store {
                   8265:     my $r=shift;
1.258     albertel 8266:     $env{'form.upfile'}=~s/\r/\n/gs;
                   8267:     $env{'form.upfile'}=~s/\f/\n/gs;
                   8268:     $env{'form.upfile'}=~s/\n+/\n/gs;
                   8269:     $env{'form.upfile'}=~s/\n+$//gs;
1.31      albertel 8270: 
1.258     albertel 8271:     my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
                   8272: 	'_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31      albertel 8273:     {
1.158     raeburn  8274:         my $datafile = $r->dir_config('lonDaemons').
                   8275:                            '/tmp/'.$datatoken.'.tmp';
                   8276:         if ( open(my $fh,">$datafile") ) {
1.258     albertel 8277:             print $fh $env{'form.upfile'};
1.158     raeburn  8278:             close($fh);
                   8279:         }
1.31      albertel 8280:     }
                   8281:     return $datatoken;
                   8282: }
                   8283: 
1.56      matthew  8284: =pod
                   8285: 
1.648     raeburn  8286: =item * &load_tmp_file($r)
1.41      ng       8287: 
                   8288: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258     albertel 8289: needs $env{'form.datatoken'},
                   8290: sets $env{'form.upfile'} to the contents of the file
1.41      ng       8291: 
                   8292: =cut
1.31      albertel 8293: 
                   8294: sub load_tmp_file {
                   8295:     my $r=shift;
                   8296:     my @studentdata=();
                   8297:     {
1.158     raeburn  8298:         my $studentfile = $r->dir_config('lonDaemons').
1.258     albertel 8299:                               '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158     raeburn  8300:         if ( open(my $fh,"<$studentfile") ) {
                   8301:             @studentdata=<$fh>;
                   8302:             close($fh);
                   8303:         }
1.31      albertel 8304:     }
1.258     albertel 8305:     $env{'form.upfile'}=join('',@studentdata);
1.31      albertel 8306: }
                   8307: 
1.56      matthew  8308: =pod
                   8309: 
1.648     raeburn  8310: =item * &upfile_record_sep()
1.41      ng       8311: 
                   8312: Separate uploaded file into records
                   8313: returns array of records,
1.258     albertel 8314: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41      ng       8315: 
                   8316: =cut
1.31      albertel 8317: 
                   8318: sub upfile_record_sep {
1.258     albertel 8319:     if ($env{'form.upfiletype'} eq 'xml') {
1.31      albertel 8320:     } else {
1.248     albertel 8321: 	my @records;
1.258     albertel 8322: 	foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248     albertel 8323: 	    if ($line=~/^\s*$/) { next; }
                   8324: 	    push(@records,$line);
                   8325: 	}
                   8326: 	return @records;
1.31      albertel 8327:     }
                   8328: }
                   8329: 
1.56      matthew  8330: =pod
                   8331: 
1.648     raeburn  8332: =item * &record_sep($record)
1.41      ng       8333: 
1.258     albertel 8334: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41      ng       8335: 
                   8336: =cut
                   8337: 
1.263     www      8338: sub takeleft {
                   8339:     my $index=shift;
                   8340:     return substr('0000'.$index,-4,4);
                   8341: }
                   8342: 
1.31      albertel 8343: sub record_sep {
                   8344:     my $record=shift;
                   8345:     my %components=();
1.258     albertel 8346:     if ($env{'form.upfiletype'} eq 'xml') {
                   8347:     } elsif ($env{'form.upfiletype'} eq 'space') {
1.31      albertel 8348:         my $i=0;
1.356     albertel 8349:         foreach my $field (split(/\s+/,$record)) {
1.31      albertel 8350:             $field=~s/^(\"|\')//;
                   8351:             $field=~s/(\"|\')$//;
1.263     www      8352:             $components{&takeleft($i)}=$field;
1.31      albertel 8353:             $i++;
                   8354:         }
1.258     albertel 8355:     } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31      albertel 8356:         my $i=0;
1.356     albertel 8357:         foreach my $field (split(/\t/,$record)) {
1.31      albertel 8358:             $field=~s/^(\"|\')//;
                   8359:             $field=~s/(\"|\')$//;
1.263     www      8360:             $components{&takeleft($i)}=$field;
1.31      albertel 8361:             $i++;
                   8362:         }
                   8363:     } else {
1.561     www      8364:         my $separator=',';
1.480     banghart 8365:         if ($env{'form.upfiletype'} eq 'semisv') {
1.561     www      8366:             $separator=';';
1.480     banghart 8367:         }
1.31      albertel 8368:         my $i=0;
1.561     www      8369: # the character we are looking for to indicate the end of a quote or a record 
                   8370:         my $looking_for=$separator;
                   8371: # do not add the characters to the fields
                   8372:         my $ignore=0;
                   8373: # we just encountered a separator (or the beginning of the record)
                   8374:         my $just_found_separator=1;
                   8375: # store the field we are working on here
                   8376:         my $field='';
                   8377: # work our way through all characters in record
                   8378:         foreach my $character ($record=~/(.)/g) {
                   8379:             if ($character eq $looking_for) {
                   8380:                if ($character ne $separator) {
                   8381: # Found the end of a quote, again looking for separator
                   8382:                   $looking_for=$separator;
                   8383:                   $ignore=1;
                   8384:                } else {
                   8385: # Found a separator, store away what we got
                   8386:                   $components{&takeleft($i)}=$field;
                   8387: 	          $i++;
                   8388:                   $just_found_separator=1;
                   8389:                   $ignore=0;
                   8390:                   $field='';
                   8391:                }
                   8392:                next;
                   8393:             }
                   8394: # single or double quotation marks after a separator indicate beginning of a quote
                   8395: # we are now looking for the end of the quote and need to ignore separators
                   8396:             if ((($character eq '"') || ($character eq "'")) && ($just_found_separator))  {
                   8397:                $looking_for=$character;
                   8398:                next;
                   8399:             }
                   8400: # ignore would be true after we reached the end of a quote
                   8401:             if ($ignore) { next; }
                   8402:             if (($just_found_separator) && ($character=~/\s/)) { next; }
                   8403:             $field.=$character;
                   8404:             $just_found_separator=0; 
1.31      albertel 8405:         }
1.561     www      8406: # catch the very last entry, since we never encountered the separator
                   8407:         $components{&takeleft($i)}=$field;
1.31      albertel 8408:     }
                   8409:     return %components;
                   8410: }
                   8411: 
1.144     matthew  8412: ######################################################
                   8413: ######################################################
                   8414: 
1.56      matthew  8415: =pod
                   8416: 
1.648     raeburn  8417: =item * &upfile_select_html()
1.41      ng       8418: 
1.144     matthew  8419: Return HTML code to select a file from the users machine and specify 
                   8420: the file type.
1.41      ng       8421: 
                   8422: =cut
                   8423: 
1.144     matthew  8424: ######################################################
                   8425: ######################################################
1.31      albertel 8426: sub upfile_select_html {
1.144     matthew  8427:     my %Types = (
                   8428:                  csv   => &mt('CSV (comma separated values, spreadsheet)'),
1.480     banghart 8429:                  semisv => &mt('Semicolon separated values'),
1.144     matthew  8430:                  space => &mt('Space separated'),
                   8431:                  tab   => &mt('Tabulator separated'),
                   8432: #                 xml   => &mt('HTML/XML'),
                   8433:                  );
                   8434:     my $Str = '<input type="file" name="upfile" size="50" />'.
1.727     riegler  8435:         '<br />'.&mt('Type').': <select name="upfiletype">';
1.144     matthew  8436:     foreach my $type (sort(keys(%Types))) {
                   8437:         $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
                   8438:     }
                   8439:     $Str .= "</select>\n";
                   8440:     return $Str;
1.31      albertel 8441: }
                   8442: 
1.301     albertel 8443: sub get_samples {
                   8444:     my ($records,$toget) = @_;
                   8445:     my @samples=({});
                   8446:     my $got=0;
                   8447:     foreach my $rec (@$records) {
                   8448: 	my %temp = &record_sep($rec);
                   8449: 	if (! grep(/\S/, values(%temp))) { next; }
                   8450: 	if (%temp) {
                   8451: 	    $samples[$got]=\%temp;
                   8452: 	    $got++;
                   8453: 	    if ($got == $toget) { last; }
                   8454: 	}
                   8455:     }
                   8456:     return \@samples;
                   8457: }
                   8458: 
1.144     matthew  8459: ######################################################
                   8460: ######################################################
                   8461: 
1.56      matthew  8462: =pod
                   8463: 
1.648     raeburn  8464: =item * &csv_print_samples($r,$records)
1.41      ng       8465: 
                   8466: Prints a table of sample values from each column uploaded $r is an
                   8467: Apache Request ref, $records is an arrayref from
                   8468: &Apache::loncommon::upfile_record_sep
                   8469: 
                   8470: =cut
                   8471: 
1.144     matthew  8472: ######################################################
                   8473: ######################################################
1.31      albertel 8474: sub csv_print_samples {
                   8475:     my ($r,$records) = @_;
1.662     bisitz   8476:     my $samples = &get_samples($records,5);
1.301     albertel 8477: 
1.594     raeburn  8478:     $r->print(&mt('Samples').'<br />'.&start_data_table().
                   8479:               &start_data_table_header_row());
1.356     albertel 8480:     foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) { 
                   8481:         $r->print('<th>'.&mt('Column&nbsp;[_1]',($sample+1)).'</th>'); }
1.594     raeburn  8482:     $r->print(&end_data_table_header_row());
1.301     albertel 8483:     foreach my $hash (@$samples) {
1.594     raeburn  8484: 	$r->print(&start_data_table_row());
1.356     albertel 8485: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31      albertel 8486: 	    $r->print('<td>');
1.356     albertel 8487: 	    if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31      albertel 8488: 	    $r->print('</td>');
                   8489: 	}
1.594     raeburn  8490: 	$r->print(&end_data_table_row());
1.31      albertel 8491:     }
1.594     raeburn  8492:     $r->print(&end_data_table().'<br />'."\n");
1.31      albertel 8493: }
                   8494: 
1.144     matthew  8495: ######################################################
                   8496: ######################################################
                   8497: 
1.56      matthew  8498: =pod
                   8499: 
1.648     raeburn  8500: =item * &csv_print_select_table($r,$records,$d)
1.41      ng       8501: 
                   8502: Prints a table to create associations between values and table columns.
1.144     matthew  8503: 
1.41      ng       8504: $r is an Apache Request ref,
                   8505: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174     matthew  8506: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41      ng       8507: 
                   8508: =cut
                   8509: 
1.144     matthew  8510: ######################################################
                   8511: ######################################################
1.31      albertel 8512: sub csv_print_select_table {
                   8513:     my ($r,$records,$d) = @_;
1.301     albertel 8514:     my $i=0;
                   8515:     my $samples = &get_samples($records,1);
1.144     matthew  8516:     $r->print(&mt('Associate columns with student attributes.')."\n".
1.594     raeburn  8517: 	      &start_data_table().&start_data_table_header_row().
1.144     matthew  8518:               '<th>'.&mt('Attribute').'</th>'.
1.594     raeburn  8519:               '<th>'.&mt('Column').'</th>'.
                   8520:               &end_data_table_header_row()."\n");
1.356     albertel 8521:     foreach my $array_ref (@$d) {
                   8522: 	my ($value,$display,$defaultcol)=@{ $array_ref };
1.729     raeburn  8523: 	$r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31      albertel 8524: 
                   8525: 	$r->print('<td><select name=f'.$i.
1.32      matthew  8526: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.31      albertel 8527: 	$r->print('<option value="none"></option>');
1.356     albertel 8528: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
                   8529: 	    $r->print('<option value="'.$sample.'"'.
                   8530:                       ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662     bisitz   8531:                       '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31      albertel 8532: 	}
1.594     raeburn  8533: 	$r->print('</select></td>'.&end_data_table_row()."\n");
1.31      albertel 8534: 	$i++;
                   8535:     }
1.594     raeburn  8536:     $r->print(&end_data_table());
1.31      albertel 8537:     $i--;
                   8538:     return $i;
                   8539: }
1.56      matthew  8540: 
1.144     matthew  8541: ######################################################
                   8542: ######################################################
                   8543: 
1.56      matthew  8544: =pod
1.31      albertel 8545: 
1.648     raeburn  8546: =item * &csv_samples_select_table($r,$records,$d)
1.41      ng       8547: 
                   8548: Prints a table of sample values from the upload and can make associate samples to internal names.
                   8549: 
                   8550: $r is an Apache Request ref,
                   8551: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
                   8552: $d is an array of 2 element arrays (internal name, displayed name)
                   8553: 
                   8554: =cut
                   8555: 
1.144     matthew  8556: ######################################################
                   8557: ######################################################
1.31      albertel 8558: sub csv_samples_select_table {
                   8559:     my ($r,$records,$d) = @_;
                   8560:     my $i=0;
1.144     matthew  8561:     #
1.662     bisitz   8562:     my $max_samples = 5;
                   8563:     my $samples = &get_samples($records,$max_samples);
1.594     raeburn  8564:     $r->print(&start_data_table().
                   8565:               &start_data_table_header_row().'<th>'.
                   8566:               &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
                   8567:               &end_data_table_header_row());
1.301     albertel 8568: 
                   8569:     foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594     raeburn  8570: 	$r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32      matthew  8571: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.301     albertel 8572: 	foreach my $option (@$d) {
                   8573: 	    my ($value,$display,$defaultcol)=@{ $option };
1.174     matthew  8574: 	    $r->print('<option value="'.$value.'"'.
1.253     albertel 8575:                       ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174     matthew  8576:                       $display.'</option>');
1.31      albertel 8577: 	}
                   8578: 	$r->print('</select></td><td>');
1.662     bisitz   8579: 	foreach my $line (0..($max_samples-1)) {
1.301     albertel 8580: 	    if (defined($samples->[$line]{$key})) { 
                   8581: 		$r->print($samples->[$line]{$key}."<br />\n"); 
                   8582: 	    }
                   8583: 	}
1.594     raeburn  8584: 	$r->print('</td>'.&end_data_table_row());
1.31      albertel 8585: 	$i++;
                   8586:     }
1.594     raeburn  8587:     $r->print(&end_data_table());
1.31      albertel 8588:     $i--;
                   8589:     return($i);
1.115     matthew  8590: }
                   8591: 
1.144     matthew  8592: ######################################################
                   8593: ######################################################
                   8594: 
1.115     matthew  8595: =pod
                   8596: 
1.648     raeburn  8597: =item * &clean_excel_name($name)
1.115     matthew  8598: 
                   8599: Returns a replacement for $name which does not contain any illegal characters.
                   8600: 
                   8601: =cut
                   8602: 
1.144     matthew  8603: ######################################################
                   8604: ######################################################
1.115     matthew  8605: sub clean_excel_name {
                   8606:     my ($name) = @_;
                   8607:     $name =~ s/[:\*\?\/\\]//g;
                   8608:     if (length($name) > 31) {
                   8609:         $name = substr($name,0,31);
                   8610:     }
                   8611:     return $name;
1.25      albertel 8612: }
1.84      albertel 8613: 
1.85      albertel 8614: =pod
                   8615: 
1.648     raeburn  8616: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85      albertel 8617: 
                   8618: Returns either 1 or undef
                   8619: 
                   8620: 1 if the part is to be hidden, undef if it is to be shown
                   8621: 
                   8622: Arguments are:
                   8623: 
                   8624: $id the id of the part to be checked
                   8625: $symb, optional the symb of the resource to check
                   8626: $udom, optional the domain of the user to check for
                   8627: $uname, optional the username of the user to check for
                   8628: 
                   8629: =cut
1.84      albertel 8630: 
                   8631: sub check_if_partid_hidden {
                   8632:     my ($id,$symb,$udom,$uname) = @_;
1.133     albertel 8633:     my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84      albertel 8634: 					 $symb,$udom,$uname);
1.141     albertel 8635:     my $truth=1;
                   8636:     #if the string starts with !, then the list is the list to show not hide
                   8637:     if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84      albertel 8638:     my @hiddenlist=split(/,/,$hiddenparts);
                   8639:     foreach my $checkid (@hiddenlist) {
1.141     albertel 8640: 	if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84      albertel 8641:     }
1.141     albertel 8642:     return !$truth;
1.84      albertel 8643: }
1.127     matthew  8644: 
1.138     matthew  8645: 
                   8646: ############################################################
                   8647: ############################################################
                   8648: 
                   8649: =pod
                   8650: 
1.157     matthew  8651: =back 
                   8652: 
1.138     matthew  8653: =head1 cgi-bin script and graphing routines
                   8654: 
1.157     matthew  8655: =over 4
                   8656: 
1.648     raeburn  8657: =item * &get_cgi_id()
1.138     matthew  8658: 
                   8659: Inputs: none
                   8660: 
                   8661: Returns an id which can be used to pass environment variables
                   8662: to various cgi-bin scripts.  These environment variables will
                   8663: be removed from the users environment after a given time by
                   8664: the routine &Apache::lonnet::transfer_profile_to_env.
                   8665: 
                   8666: =cut
                   8667: 
                   8668: ############################################################
                   8669: ############################################################
1.152     albertel 8670: my $uniq=0;
1.136     matthew  8671: sub get_cgi_id {
1.154     albertel 8672:     $uniq=($uniq+1)%100000;
1.280     albertel 8673:     return (time.'_'.$$.'_'.$uniq);
1.136     matthew  8674: }
                   8675: 
1.127     matthew  8676: ############################################################
                   8677: ############################################################
                   8678: 
                   8679: =pod
                   8680: 
1.648     raeburn  8681: =item * &DrawBarGraph()
1.127     matthew  8682: 
1.138     matthew  8683: Facilitates the plotting of data in a (stacked) bar graph.
                   8684: Puts plot definition data into the users environment in order for 
                   8685: graph.png to plot it.  Returns an <img> tag for the plot.
                   8686: The bars on the plot are labeled '1','2',...,'n'.
                   8687: 
                   8688: Inputs:
                   8689: 
                   8690: =over 4
                   8691: 
                   8692: =item $Title: string, the title of the plot
                   8693: 
                   8694: =item $xlabel: string, text describing the X-axis of the plot
                   8695: 
                   8696: =item $ylabel: string, text describing the Y-axis of the plot
                   8697: 
                   8698: =item $Max: scalar, the maximum Y value to use in the plot
                   8699: If $Max is < any data point, the graph will not be rendered.
                   8700: 
1.140     matthew  8701: =item $colors: array ref holding the colors to be used for the data sets when
1.138     matthew  8702: they are plotted.  If undefined, default values will be used.
                   8703: 
1.178     matthew  8704: =item $labels: array ref holding the labels to use on the x-axis for the bars.
                   8705: 
1.138     matthew  8706: =item @Values: An array of array references.  Each array reference holds data
                   8707: to be plotted in a stacked bar chart.
                   8708: 
1.239     matthew  8709: =item If the final element of @Values is a hash reference the key/value
                   8710: pairs will be added to the graph definition.
                   8711: 
1.138     matthew  8712: =back
                   8713: 
                   8714: Returns:
                   8715: 
                   8716: An <img> tag which references graph.png and the appropriate identifying
                   8717: information for the plot.
                   8718: 
1.127     matthew  8719: =cut
                   8720: 
                   8721: ############################################################
                   8722: ############################################################
1.134     matthew  8723: sub DrawBarGraph {
1.178     matthew  8724:     my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134     matthew  8725:     #
                   8726:     if (! defined($colors)) {
                   8727:         $colors = ['#33ff00', 
                   8728:                   '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
                   8729:                   '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
                   8730:                   ]; 
                   8731:     }
1.228     matthew  8732:     my $extra_settings = {};
                   8733:     if (ref($Values[-1]) eq 'HASH') {
                   8734:         $extra_settings = pop(@Values);
                   8735:     }
1.127     matthew  8736:     #
1.136     matthew  8737:     my $identifier = &get_cgi_id();
                   8738:     my $id = 'cgi.'.$identifier;        
1.129     matthew  8739:     if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127     matthew  8740:         return '';
                   8741:     }
1.225     matthew  8742:     #
                   8743:     my @Labels;
                   8744:     if (defined($labels)) {
                   8745:         @Labels = @$labels;
                   8746:     } else {
                   8747:         for (my $i=0;$i<@{$Values[0]};$i++) {
                   8748:             push (@Labels,$i+1);
                   8749:         }
                   8750:     }
                   8751:     #
1.129     matthew  8752:     my $NumBars = scalar(@{$Values[0]});
1.225     matthew  8753:     if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129     matthew  8754:     my %ValuesHash;
                   8755:     my $NumSets=1;
                   8756:     foreach my $array (@Values) {
                   8757:         next if (! ref($array));
1.136     matthew  8758:         $ValuesHash{$id.'.data.'.$NumSets++} = 
1.132     matthew  8759:             join(',',@$array);
1.129     matthew  8760:     }
1.127     matthew  8761:     #
1.136     matthew  8762:     my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225     matthew  8763:     if ($NumBars < 3) {
                   8764:         $width = 120+$NumBars*32;
1.220     matthew  8765:         $xskip = 1;
1.225     matthew  8766:         $bar_width = 30;
                   8767:     } elsif ($NumBars < 5) {
                   8768:         $width = 120+$NumBars*20;
                   8769:         $xskip = 1;
                   8770:         $bar_width = 20;
1.220     matthew  8771:     } elsif ($NumBars < 10) {
1.136     matthew  8772:         $width = 120+$NumBars*15;
                   8773:         $xskip = 1;
                   8774:         $bar_width = 15;
                   8775:     } elsif ($NumBars <= 25) {
                   8776:         $width = 120+$NumBars*11;
                   8777:         $xskip = 5;
                   8778:         $bar_width = 8;
                   8779:     } elsif ($NumBars <= 50) {
                   8780:         $width = 120+$NumBars*8;
                   8781:         $xskip = 5;
                   8782:         $bar_width = 4;
                   8783:     } else {
                   8784:         $width = 120+$NumBars*8;
                   8785:         $xskip = 5;
                   8786:         $bar_width = 4;
                   8787:     }
                   8788:     #
1.137     matthew  8789:     $Max = 1 if ($Max < 1);
                   8790:     if ( int($Max) < $Max ) {
                   8791:         $Max++;
                   8792:         $Max = int($Max);
                   8793:     }
1.127     matthew  8794:     $Title  = '' if (! defined($Title));
                   8795:     $xlabel = '' if (! defined($xlabel));
                   8796:     $ylabel = '' if (! defined($ylabel));
1.369     www      8797:     $ValuesHash{$id.'.title'}    = &escape($Title);
                   8798:     $ValuesHash{$id.'.xlabel'}   = &escape($xlabel);
                   8799:     $ValuesHash{$id.'.ylabel'}   = &escape($ylabel);
1.137     matthew  8800:     $ValuesHash{$id.'.y_max_value'} = $Max;
1.136     matthew  8801:     $ValuesHash{$id.'.NumBars'}  = $NumBars;
                   8802:     $ValuesHash{$id.'.NumSets'}  = $NumSets;
                   8803:     $ValuesHash{$id.'.PlotType'} = 'bar';
                   8804:     $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8805:     $ValuesHash{$id.'.height'}   = $height;
                   8806:     $ValuesHash{$id.'.width'}    = $width;
                   8807:     $ValuesHash{$id.'.xskip'}    = $xskip;
                   8808:     $ValuesHash{$id.'.bar_width'} = $bar_width;
                   8809:     $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127     matthew  8810:     #
1.228     matthew  8811:     # Deal with other parameters
                   8812:     while (my ($key,$value) = each(%$extra_settings)) {
                   8813:         $ValuesHash{$id.'.'.$key} = $value;
                   8814:     }
                   8815:     #
1.646     raeburn  8816:     &Apache::lonnet::appenv(\%ValuesHash);
1.137     matthew  8817:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   8818: }
                   8819: 
                   8820: ############################################################
                   8821: ############################################################
                   8822: 
                   8823: =pod
                   8824: 
1.648     raeburn  8825: =item * &DrawXYGraph()
1.137     matthew  8826: 
1.138     matthew  8827: Facilitates the plotting of data in an XY graph.
                   8828: Puts plot definition data into the users environment in order for 
                   8829: graph.png to plot it.  Returns an <img> tag for the plot.
                   8830: 
                   8831: Inputs:
                   8832: 
                   8833: =over 4
                   8834: 
                   8835: =item $Title: string, the title of the plot
                   8836: 
                   8837: =item $xlabel: string, text describing the X-axis of the plot
                   8838: 
                   8839: =item $ylabel: string, text describing the Y-axis of the plot
                   8840: 
                   8841: =item $Max: scalar, the maximum Y value to use in the plot
                   8842: If $Max is < any data point, the graph will not be rendered.
                   8843: 
                   8844: =item $colors: Array ref containing the hex color codes for the data to be 
                   8845: plotted in.  If undefined, default values will be used.
                   8846: 
                   8847: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   8848: 
                   8849: =item $Ydata: Array ref containing Array refs.  
1.185     www      8850: Each of the contained arrays will be plotted as a separate curve.
1.138     matthew  8851: 
                   8852: =item %Values: hash indicating or overriding any default values which are 
                   8853: passed to graph.png.  
                   8854: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   8855: 
                   8856: =back
                   8857: 
                   8858: Returns:
                   8859: 
                   8860: An <img> tag which references graph.png and the appropriate identifying
                   8861: information for the plot.
                   8862: 
1.137     matthew  8863: =cut
                   8864: 
                   8865: ############################################################
                   8866: ############################################################
                   8867: sub DrawXYGraph {
                   8868:     my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
                   8869:     #
                   8870:     # Create the identifier for the graph
                   8871:     my $identifier = &get_cgi_id();
                   8872:     my $id = 'cgi.'.$identifier;
                   8873:     #
                   8874:     $Title  = '' if (! defined($Title));
                   8875:     $xlabel = '' if (! defined($xlabel));
                   8876:     $ylabel = '' if (! defined($ylabel));
                   8877:     my %ValuesHash = 
                   8878:         (
1.369     www      8879:          $id.'.title'  => &escape($Title),
                   8880:          $id.'.xlabel' => &escape($xlabel),
                   8881:          $id.'.ylabel' => &escape($ylabel),
1.137     matthew  8882:          $id.'.y_max_value'=> $Max,
                   8883:          $id.'.labels'     => join(',',@$Xlabels),
                   8884:          $id.'.PlotType'   => 'XY',
                   8885:          );
                   8886:     #
                   8887:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   8888:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8889:     }
                   8890:     #
                   8891:     if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
                   8892:         return '';
                   8893:     }
                   8894:     my $NumSets=1;
1.138     matthew  8895:     foreach my $array (@{$Ydata}){
1.137     matthew  8896:         next if (! ref($array));
                   8897:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
                   8898:     }
1.138     matthew  8899:     $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137     matthew  8900:     #
                   8901:     # Deal with other parameters
                   8902:     while (my ($key,$value) = each(%Values)) {
                   8903:         $ValuesHash{$id.'.'.$key} = $value;
1.127     matthew  8904:     }
                   8905:     #
1.646     raeburn  8906:     &Apache::lonnet::appenv(\%ValuesHash);
1.136     matthew  8907:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   8908: }
                   8909: 
                   8910: ############################################################
                   8911: ############################################################
                   8912: 
                   8913: =pod
                   8914: 
1.648     raeburn  8915: =item * &DrawXYYGraph()
1.138     matthew  8916: 
                   8917: Facilitates the plotting of data in an XY graph with two Y axes.
                   8918: Puts plot definition data into the users environment in order for 
                   8919: graph.png to plot it.  Returns an <img> tag for the plot.
                   8920: 
                   8921: Inputs:
                   8922: 
                   8923: =over 4
                   8924: 
                   8925: =item $Title: string, the title of the plot
                   8926: 
                   8927: =item $xlabel: string, text describing the X-axis of the plot
                   8928: 
                   8929: =item $ylabel: string, text describing the Y-axis of the plot
                   8930: 
                   8931: =item $colors: Array ref containing the hex color codes for the data to be 
                   8932: plotted in.  If undefined, default values will be used.
                   8933: 
                   8934: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   8935: 
                   8936: =item $Ydata1: The first data set
                   8937: 
                   8938: =item $Min1: The minimum value of the left Y-axis
                   8939: 
                   8940: =item $Max1: The maximum value of the left Y-axis
                   8941: 
                   8942: =item $Ydata2: The second data set
                   8943: 
                   8944: =item $Min2: The minimum value of the right Y-axis
                   8945: 
                   8946: =item $Max2: The maximum value of the left Y-axis
                   8947: 
                   8948: =item %Values: hash indicating or overriding any default values which are 
                   8949: passed to graph.png.  
                   8950: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   8951: 
                   8952: =back
                   8953: 
                   8954: Returns:
                   8955: 
                   8956: An <img> tag which references graph.png and the appropriate identifying
                   8957: information for the plot.
1.136     matthew  8958: 
                   8959: =cut
                   8960: 
                   8961: ############################################################
                   8962: ############################################################
1.137     matthew  8963: sub DrawXYYGraph {
                   8964:     my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
                   8965:                                         $Ydata2,$Min2,$Max2,%Values)=@_;
1.136     matthew  8966:     #
                   8967:     # Create the identifier for the graph
                   8968:     my $identifier = &get_cgi_id();
                   8969:     my $id = 'cgi.'.$identifier;
                   8970:     #
                   8971:     $Title  = '' if (! defined($Title));
                   8972:     $xlabel = '' if (! defined($xlabel));
                   8973:     $ylabel = '' if (! defined($ylabel));
                   8974:     my %ValuesHash = 
                   8975:         (
1.369     www      8976:          $id.'.title'  => &escape($Title),
                   8977:          $id.'.xlabel' => &escape($xlabel),
                   8978:          $id.'.ylabel' => &escape($ylabel),
1.136     matthew  8979:          $id.'.labels' => join(',',@$Xlabels),
                   8980:          $id.'.PlotType' => 'XY',
                   8981:          $id.'.NumSets' => 2,
1.137     matthew  8982:          $id.'.two_axes' => 1,
                   8983:          $id.'.y1_max_value' => $Max1,
                   8984:          $id.'.y1_min_value' => $Min1,
                   8985:          $id.'.y2_max_value' => $Max2,
                   8986:          $id.'.y2_min_value' => $Min2,
1.136     matthew  8987:          );
                   8988:     #
1.137     matthew  8989:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   8990:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8991:     }
                   8992:     #
                   8993:     if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
                   8994:         ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136     matthew  8995:         return '';
                   8996:     }
                   8997:     my $NumSets=1;
1.137     matthew  8998:     foreach my $array ($Ydata1,$Ydata2){
1.136     matthew  8999:         next if (! ref($array));
                   9000:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137     matthew  9001:     }
                   9002:     #
                   9003:     # Deal with other parameters
                   9004:     while (my ($key,$value) = each(%Values)) {
                   9005:         $ValuesHash{$id.'.'.$key} = $value;
1.136     matthew  9006:     }
                   9007:     #
1.646     raeburn  9008:     &Apache::lonnet::appenv(\%ValuesHash);
1.130     albertel 9009:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139     matthew  9010: }
                   9011: 
                   9012: ############################################################
                   9013: ############################################################
                   9014: 
                   9015: =pod
                   9016: 
1.157     matthew  9017: =back 
                   9018: 
1.139     matthew  9019: =head1 Statistics helper routines?  
                   9020: 
                   9021: Bad place for them but what the hell.
                   9022: 
1.157     matthew  9023: =over 4
                   9024: 
1.648     raeburn  9025: =item * &chartlink()
1.139     matthew  9026: 
                   9027: Returns a link to the chart for a specific student.  
                   9028: 
                   9029: Inputs:
                   9030: 
                   9031: =over 4
                   9032: 
                   9033: =item $linktext: The text of the link
                   9034: 
                   9035: =item $sname: The students username
                   9036: 
                   9037: =item $sdomain: The students domain
                   9038: 
                   9039: =back
                   9040: 
1.157     matthew  9041: =back
                   9042: 
1.139     matthew  9043: =cut
                   9044: 
                   9045: ############################################################
                   9046: ############################################################
                   9047: sub chartlink {
                   9048:     my ($linktext, $sname, $sdomain) = @_;
                   9049:     my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369     www      9050:         '&amp;SelectedStudent='.&escape($sname.':'.$sdomain).
1.219     albertel 9051:         '&amp;chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139     matthew  9052:        '">'.$linktext.'</a>';
1.153     matthew  9053: }
                   9054: 
                   9055: #######################################################
                   9056: #######################################################
                   9057: 
                   9058: =pod
                   9059: 
                   9060: =head1 Course Environment Routines
1.157     matthew  9061: 
                   9062: =over 4
1.153     matthew  9063: 
1.648     raeburn  9064: =item * &restore_course_settings()
1.153     matthew  9065: 
1.648     raeburn  9066: =item * &store_course_settings()
1.153     matthew  9067: 
                   9068: Restores/Store indicated form parameters from the course environment.
                   9069: Will not overwrite existing values of the form parameters.
                   9070: 
                   9071: Inputs: 
                   9072: a scalar describing the data (e.g. 'chart', 'problem_analysis')
                   9073: 
                   9074: a hash ref describing the data to be stored.  For example:
                   9075:    
                   9076: %Save_Parameters = ('Status' => 'scalar',
                   9077:     'chartoutputmode' => 'scalar',
                   9078:     'chartoutputdata' => 'scalar',
                   9079:     'Section' => 'array',
1.373     raeburn  9080:     'Group' => 'array',
1.153     matthew  9081:     'StudentData' => 'array',
                   9082:     'Maps' => 'array');
                   9083: 
                   9084: Returns: both routines return nothing
                   9085: 
1.631     raeburn  9086: =back
                   9087: 
1.153     matthew  9088: =cut
                   9089: 
                   9090: #######################################################
                   9091: #######################################################
                   9092: sub store_course_settings {
1.496     albertel 9093:     return &store_settings($env{'request.course.id'},@_);
                   9094: }
                   9095: 
                   9096: sub store_settings {
1.153     matthew  9097:     # save to the environment
                   9098:     # appenv the same items, just to be safe
1.300     albertel 9099:     my $udom  = $env{'user.domain'};
                   9100:     my $uname = $env{'user.name'};
1.496     albertel 9101:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  9102:     my %SaveHash;
                   9103:     my %AppHash;
                   9104:     while (my ($setting,$type) = each(%$Settings)) {
1.496     albertel 9105:         my $basename = join('.','internal',$context,$prefix,$setting);
1.300     albertel 9106:         my $envname = 'environment.'.$basename;
1.258     albertel 9107:         if (exists($env{'form.'.$setting})) {
1.153     matthew  9108:             # Save this value away
                   9109:             if ($type eq 'scalar' &&
1.258     albertel 9110:                 (! exists($env{$envname}) || 
                   9111:                  $env{$envname} ne $env{'form.'.$setting})) {
                   9112:                 $SaveHash{$basename} = $env{'form.'.$setting};
                   9113:                 $AppHash{$envname}   = $env{'form.'.$setting};
1.153     matthew  9114:             } elsif ($type eq 'array') {
                   9115:                 my $stored_form;
1.258     albertel 9116:                 if (ref($env{'form.'.$setting})) {
1.153     matthew  9117:                     $stored_form = join(',',
                   9118:                                         map {
1.369     www      9119:                                             &escape($_);
1.258     albertel 9120:                                         } sort(@{$env{'form.'.$setting}}));
1.153     matthew  9121:                 } else {
                   9122:                     $stored_form = 
1.369     www      9123:                         &escape($env{'form.'.$setting});
1.153     matthew  9124:                 }
                   9125:                 # Determine if the array contents are the same.
1.258     albertel 9126:                 if ($stored_form ne $env{$envname}) {
1.153     matthew  9127:                     $SaveHash{$basename} = $stored_form;
                   9128:                     $AppHash{$envname}   = $stored_form;
                   9129:                 }
                   9130:             }
                   9131:         }
                   9132:     }
                   9133:     my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300     albertel 9134:                                           $udom,$uname);
1.153     matthew  9135:     if ($put_result !~ /^(ok|delayed)/) {
                   9136:         &Apache::lonnet::logthis('unable to save form parameters, '.
                   9137:                                  'got error:'.$put_result);
                   9138:     }
                   9139:     # Make sure these settings stick around in this session, too
1.646     raeburn  9140:     &Apache::lonnet::appenv(\%AppHash);
1.153     matthew  9141:     return;
                   9142: }
                   9143: 
                   9144: sub restore_course_settings {
1.499     albertel 9145:     return &restore_settings($env{'request.course.id'},@_);
1.496     albertel 9146: }
                   9147: 
                   9148: sub restore_settings {
                   9149:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  9150:     while (my ($setting,$type) = each(%$Settings)) {
1.258     albertel 9151:         next if (exists($env{'form.'.$setting}));
1.496     albertel 9152:         my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153     matthew  9153:             '.'.$setting;
1.258     albertel 9154:         if (exists($env{$envname})) {
1.153     matthew  9155:             if ($type eq 'scalar') {
1.258     albertel 9156:                 $env{'form.'.$setting} = $env{$envname};
1.153     matthew  9157:             } elsif ($type eq 'array') {
1.258     albertel 9158:                 $env{'form.'.$setting} = [ 
1.153     matthew  9159:                                            map { 
1.369     www      9160:                                                &unescape($_); 
1.258     albertel 9161:                                            } split(',',$env{$envname})
1.153     matthew  9162:                                            ];
                   9163:             }
                   9164:         }
                   9165:     }
1.127     matthew  9166: }
                   9167: 
1.618     raeburn  9168: #######################################################
                   9169: #######################################################
                   9170: 
                   9171: =pod
                   9172: 
                   9173: =head1 Domain E-mail Routines  
                   9174: 
                   9175: =over 4
                   9176: 
1.648     raeburn  9177: =item * &build_recipient_list()
1.618     raeburn  9178: 
1.766     raeburn  9179: Build recipient lists for four types of e-mail:
                   9180: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
                   9181: (d) Help requests, generated by
                   9182: lonerrorhandler.pm, CHECKRPMS, loncron, and lonsupportreq.pm respectively.
1.618     raeburn  9183: 
                   9184: Inputs:
1.619     raeburn  9185: defmail (scalar - email address of default recipient), 
1.618     raeburn  9186: mailing type (scalar - errormail, packagesmail, or helpdeskmail), 
1.619     raeburn  9187: defdom (domain for which to retrieve configuration settings),
                   9188: origmail (scalar - email address of recipient from loncapa.conf, 
                   9189: i.e., predates configuration by DC via domainprefs.pm 
1.618     raeburn  9190: 
1.655     raeburn  9191: Returns: comma separated list of addresses to which to send e-mail.
                   9192: 
                   9193: =back
1.618     raeburn  9194: 
                   9195: =cut
                   9196: 
                   9197: ############################################################
                   9198: ############################################################
                   9199: sub build_recipient_list {
1.619     raeburn  9200:     my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618     raeburn  9201:     my @recipients;
                   9202:     my $otheremails;
                   9203:     my %domconfig =
                   9204:          &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
                   9205:     if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766     raeburn  9206:         if (exists($domconfig{'contacts'}{$mailing})) {
                   9207:             if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
                   9208:                 my @contacts = ('adminemail','supportemail');
                   9209:                 foreach my $item (@contacts) {
                   9210:                     if ($domconfig{'contacts'}{$mailing}{$item}) {
                   9211:                         my $addr = $domconfig{'contacts'}{$item}; 
                   9212:                         if (!grep(/^\Q$addr\E$/,@recipients)) {
                   9213:                             push(@recipients,$addr);
                   9214:                         }
1.619     raeburn  9215:                     }
1.766     raeburn  9216:                     $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618     raeburn  9217:                 }
                   9218:             }
1.766     raeburn  9219:         } elsif ($origmail ne '') {
                   9220:             push(@recipients,$origmail);
1.618     raeburn  9221:         }
1.619     raeburn  9222:     } elsif ($origmail ne '') {
                   9223:         push(@recipients,$origmail);
1.618     raeburn  9224:     }
1.688     raeburn  9225:     if (defined($defmail)) {
                   9226:         if ($defmail ne '') {
                   9227:             push(@recipients,$defmail);
                   9228:         }
1.618     raeburn  9229:     }
                   9230:     if ($otheremails) {
1.619     raeburn  9231:         my @others;
                   9232:         if ($otheremails =~ /,/) {
                   9233:             @others = split(/,/,$otheremails);
1.618     raeburn  9234:         } else {
1.619     raeburn  9235:             push(@others,$otheremails);
                   9236:         }
                   9237:         foreach my $addr (@others) {
                   9238:             if (!grep(/^\Q$addr\E$/,@recipients)) {
                   9239:                 push(@recipients,$addr);
                   9240:             }
1.618     raeburn  9241:         }
                   9242:     }
1.619     raeburn  9243:     my $recipientlist = join(',',@recipients); 
1.618     raeburn  9244:     return $recipientlist;
                   9245: }
                   9246: 
1.127     matthew  9247: ############################################################
                   9248: ############################################################
1.154     albertel 9249: 
1.655     raeburn  9250: =pod
                   9251: 
                   9252: =head1 Course Catalog Routines
                   9253: 
                   9254: =over 4
                   9255: 
                   9256: =item * &gather_categories()
                   9257: 
                   9258: Converts category definitions - keys of categories hash stored in  
                   9259: coursecategories in configuration.db on the primary library server in a 
                   9260: domain - to an array.  Also generates javascript and idx hash used to 
                   9261: generate Domain Coordinator interface for editing Course Categories.
                   9262: 
                   9263: Inputs:
1.663     raeburn  9264: 
1.655     raeburn  9265: categories (reference to hash of category definitions).
1.663     raeburn  9266: 
1.655     raeburn  9267: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9268:       categories and subcategories).
1.663     raeburn  9269: 
1.655     raeburn  9270: idx (reference to hash of counters used in Domain Coordinator interface for 
                   9271:       editing Course Categories).
1.663     raeburn  9272: 
1.655     raeburn  9273: jsarray (reference to array of categories used to create Javascript arrays for
                   9274:          Domain Coordinator interface for editing Course Categories).
                   9275: 
                   9276: Returns: nothing
                   9277: 
                   9278: Side effects: populates cats, idx and jsarray. 
                   9279: 
                   9280: =cut
                   9281: 
                   9282: sub gather_categories {
                   9283:     my ($categories,$cats,$idx,$jsarray) = @_;
                   9284:     my %counters;
                   9285:     my $num = 0;
                   9286:     foreach my $item (keys(%{$categories})) {
                   9287:         my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   9288:         if ($container eq '' && $depth == 0) {
                   9289:             $cats->[$depth][$categories->{$item}] = $cat;
                   9290:         } else {
                   9291:             $cats->[$depth]{$container}[$categories->{$item}] = $cat;
                   9292:         }
                   9293:         my ($escitem,$tail) = split(/:/,$item,2);
                   9294:         if ($counters{$tail} eq '') {
                   9295:             $counters{$tail} = $num;
                   9296:             $num ++;
                   9297:         }
                   9298:         if (ref($idx) eq 'HASH') {
                   9299:             $idx->{$item} = $counters{$tail};
                   9300:         }
                   9301:         if (ref($jsarray) eq 'ARRAY') {
                   9302:             push(@{$jsarray->[$counters{$tail}]},$item);
                   9303:         }
                   9304:     }
                   9305:     return;
                   9306: }
                   9307: 
                   9308: =pod
                   9309: 
                   9310: =item * &extract_categories()
                   9311: 
                   9312: Used to generate breadcrumb trails for course categories.
                   9313: 
                   9314: Inputs:
1.663     raeburn  9315: 
1.655     raeburn  9316: categories (reference to hash of category definitions).
1.663     raeburn  9317: 
1.655     raeburn  9318: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9319:       categories and subcategories).
1.663     raeburn  9320: 
1.655     raeburn  9321: trails (reference to array of breacrumb trails for each category).
1.663     raeburn  9322: 
1.655     raeburn  9323: allitems (reference to hash - key is category key 
                   9324:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  9325: 
1.655     raeburn  9326: idx (reference to hash of counters used in Domain Coordinator interface for
                   9327:       editing Course Categories).
1.663     raeburn  9328: 
1.655     raeburn  9329: jsarray (reference to array of categories used to create Javascript arrays for
                   9330:          Domain Coordinator interface for editing Course Categories).
                   9331: 
1.665     raeburn  9332: subcats (reference to hash of arrays containing all subcategories within each 
                   9333:          category, -recursive)
                   9334: 
1.655     raeburn  9335: Returns: nothing
                   9336: 
                   9337: Side effects: populates trails and allitems hash references.
                   9338: 
                   9339: =cut
                   9340: 
                   9341: sub extract_categories {
1.665     raeburn  9342:     my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655     raeburn  9343:     if (ref($categories) eq 'HASH') {
                   9344:         &gather_categories($categories,$cats,$idx,$jsarray);
                   9345:         if (ref($cats->[0]) eq 'ARRAY') {
                   9346:             for (my $i=0; $i<@{$cats->[0]}; $i++) {
                   9347:                 my $name = $cats->[0][$i];
                   9348:                 my $item = &escape($name).'::0';
                   9349:                 my $trailstr;
                   9350:                 if ($name eq 'instcode') {
                   9351:                     $trailstr = &mt('Official courses (with institutional codes)');
                   9352:                 } else {
                   9353:                     $trailstr = $name;
                   9354:                 }
                   9355:                 if ($allitems->{$item} eq '') {
                   9356:                     push(@{$trails},$trailstr);
                   9357:                     $allitems->{$item} = scalar(@{$trails})-1;
                   9358:                 }
                   9359:                 my @parents = ($name);
                   9360:                 if (ref($cats->[1]{$name}) eq 'ARRAY') {
                   9361:                     for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
                   9362:                         my $category = $cats->[1]{$name}[$j];
1.665     raeburn  9363:                         if (ref($subcats) eq 'HASH') {
                   9364:                             push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
                   9365:                         }
                   9366:                         &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
                   9367:                     }
                   9368:                 } else {
                   9369:                     if (ref($subcats) eq 'HASH') {
                   9370:                         $subcats->{$item} = [];
1.655     raeburn  9371:                     }
                   9372:                 }
                   9373:             }
                   9374:         }
                   9375:     }
                   9376:     return;
                   9377: }
                   9378: 
                   9379: =pod
                   9380: 
                   9381: =item *&recurse_categories()
                   9382: 
                   9383: Recursively used to generate breadcrumb trails for course categories.
                   9384: 
                   9385: Inputs:
1.663     raeburn  9386: 
1.655     raeburn  9387: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9388:       categories and subcategories).
1.663     raeburn  9389: 
1.655     raeburn  9390: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663     raeburn  9391: 
                   9392: category (current course category, for which breadcrumb trail is being generated).
                   9393: 
                   9394: trails (reference to array of breadcrumb trails for each category).
                   9395: 
1.655     raeburn  9396: allitems (reference to hash - key is category key
                   9397:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  9398: 
1.655     raeburn  9399: parents (array containing containers directories for current category, 
                   9400:          back to top level). 
                   9401: 
                   9402: Returns: nothing
                   9403: 
                   9404: Side effects: populates trails and allitems hash references
                   9405: 
                   9406: =cut
                   9407: 
                   9408: sub recurse_categories {
1.665     raeburn  9409:     my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655     raeburn  9410:     my $shallower = $depth - 1;
                   9411:     if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
                   9412:         for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
                   9413:             my $name = $cats->[$depth]{$category}[$k];
                   9414:             my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   9415:             my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   9416:             if ($allitems->{$item} eq '') {
                   9417:                 push(@{$trails},$trailstr);
                   9418:                 $allitems->{$item} = scalar(@{$trails})-1;
                   9419:             }
                   9420:             my $deeper = $depth+1;
                   9421:             push(@{$parents},$category);
1.665     raeburn  9422:             if (ref($subcats) eq 'HASH') {
                   9423:                 my $subcat = &escape($name).':'.$category.':'.$depth;
                   9424:                 for (my $j=@{$parents}; $j>=0; $j--) {
                   9425:                     my $higher;
                   9426:                     if ($j > 0) {
                   9427:                         $higher = &escape($parents->[$j]).':'.
                   9428:                                   &escape($parents->[$j-1]).':'.$j;
                   9429:                     } else {
                   9430:                         $higher = &escape($parents->[$j]).'::'.$j;
                   9431:                     }
                   9432:                     push(@{$subcats->{$higher}},$subcat);
                   9433:                 }
                   9434:             }
                   9435:             &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
                   9436:                                 $subcats);
1.655     raeburn  9437:             pop(@{$parents});
                   9438:         }
                   9439:     } else {
                   9440:         my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   9441:         my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   9442:         if ($allitems->{$item} eq '') {
                   9443:             push(@{$trails},$trailstr);
                   9444:             $allitems->{$item} = scalar(@{$trails})-1;
                   9445:         }
                   9446:     }
                   9447:     return;
                   9448: }
                   9449: 
1.663     raeburn  9450: =pod
                   9451: 
                   9452: =item *&assign_categories_table()
                   9453: 
                   9454: Create a datatable for display of hierarchical categories in a domain,
                   9455: with checkboxes to allow a course to be categorized. 
                   9456: 
                   9457: Inputs:
                   9458: 
                   9459: cathash - reference to hash of categories defined for the domain (from
                   9460:           configuration.db)
                   9461: 
                   9462: currcat - scalar with an & separated list of categories assigned to a course. 
                   9463: 
                   9464: Returns: $output (markup to be displayed) 
                   9465: 
                   9466: =cut
                   9467: 
                   9468: sub assign_categories_table {
                   9469:     my ($cathash,$currcat) = @_;
                   9470:     my $output;
                   9471:     if (ref($cathash) eq 'HASH') {
                   9472:         my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
                   9473:         &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
                   9474:         $maxdepth = scalar(@cats);
                   9475:         if (@cats > 0) {
                   9476:             my $itemcount = 0;
                   9477:             if (ref($cats[0]) eq 'ARRAY') {
                   9478:                 $output = &Apache::loncommon::start_data_table();
                   9479:                 my @currcategories;
                   9480:                 if ($currcat ne '') {
                   9481:                     @currcategories = split('&',$currcat);
                   9482:                 }
                   9483:                 for (my $i=0; $i<@{$cats[0]}; $i++) {
                   9484:                     my $parent = $cats[0][$i];
                   9485:                     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9486:                     next if ($parent eq 'instcode');
                   9487:                     my $item = &escape($parent).'::0';
                   9488:                     my $checked = '';
                   9489:                     if (@currcategories > 0) {
                   9490:                         if (grep(/^\Q$item\E$/,@currcategories)) {
1.772     bisitz   9491:                             $checked = ' checked="checked"';
1.663     raeburn  9492:                         }
                   9493:                     }
1.675     raeburn  9494:                     $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
                   9495:                                '<input type="checkbox" name="usecategory" value="'.
                   9496:                                $item.'"'.$checked.' />'.$parent.'</span>'.
                   9497:                                '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663     raeburn  9498:                     my $depth = 1;
                   9499:                     push(@path,$parent);
                   9500:                     $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
                   9501:                     pop(@path);
                   9502:                     $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   9503:                     $itemcount ++;
                   9504:                 }
                   9505:                 $output .= &Apache::loncommon::end_data_table();
                   9506:             }
                   9507:         }
                   9508:     }
                   9509:     return $output;
                   9510: }
                   9511: 
                   9512: =pod
                   9513: 
                   9514: =item *&assign_category_rows()
                   9515: 
                   9516: Create a datatable row for display of nested categories in a domain,
                   9517: with checkboxes to allow a course to be categorized,called recursively.
                   9518: 
                   9519: Inputs:
                   9520: 
                   9521: itemcount - track row number for alternating colors
                   9522: 
                   9523: cats - reference to array of arrays/hashes which encapsulates hierarchy of
                   9524:       categories and subcategories.
                   9525: 
                   9526: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
                   9527: 
                   9528: parent - parent of current category item
                   9529: 
                   9530: path - Array containing all categories back up through the hierarchy from the
                   9531:        current category to the top level.
                   9532: 
                   9533: currcategories - reference to array of current categories assigned to the course
                   9534: 
                   9535: Returns: $output (markup to be displayed).
                   9536: 
                   9537: =cut
                   9538: 
                   9539: sub assign_category_rows {
                   9540:     my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
                   9541:     my ($text,$name,$item,$chgstr);
                   9542:     if (ref($cats) eq 'ARRAY') {
                   9543:         my $maxdepth = scalar(@{$cats});
                   9544:         if (ref($cats->[$depth]) eq 'HASH') {
                   9545:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   9546:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   9547:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9548:                 $text .= '<td><table class="LC_datatable">';
                   9549:                 for (my $j=0; $j<$numchildren; $j++) {
                   9550:                     $name = $cats->[$depth]{$parent}[$j];
                   9551:                     $item = &escape($name).':'.&escape($parent).':'.$depth;
                   9552:                     my $deeper = $depth+1;
                   9553:                     my $checked = '';
                   9554:                     if (ref($currcategories) eq 'ARRAY') {
                   9555:                         if (@{$currcategories} > 0) {
                   9556:                             if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772     bisitz   9557:                                 $checked = ' checked="checked"';
1.663     raeburn  9558:                             }
                   9559:                         }
                   9560:                     }
1.664     raeburn  9561:                     $text .= '<tr><td><span class="LC_nobreak"><label>'.
                   9562:                              '<input type="checkbox" name="usecategory" value="'.
1.675     raeburn  9563:                              $item.'"'.$checked.' />'.$name.'</label></span>'.
                   9564:                              '<input type="hidden" name="catname" value="'.$name.'" />'.
                   9565:                              '</td><td>';
1.663     raeburn  9566:                     if (ref($path) eq 'ARRAY') {
                   9567:                         push(@{$path},$name);
                   9568:                         $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
                   9569:                         pop(@{$path});
                   9570:                     }
                   9571:                     $text .= '</td></tr>';
                   9572:                 }
                   9573:                 $text .= '</table></td>';
                   9574:             }
                   9575:         }
                   9576:     }
                   9577:     return $text;
                   9578: }
                   9579: 
1.655     raeburn  9580: ############################################################
                   9581: ############################################################
                   9582: 
                   9583: 
1.443     albertel 9584: sub commit_customrole {
1.664     raeburn  9585:     my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630     raeburn  9586:     my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443     albertel 9587:                          ($start?', '.&mt('starting').' '.localtime($start):'').
                   9588:                          ($end?', ending '.localtime($end):'').': <b>'.
                   9589:               &Apache::lonnet::assigncustomrole(
1.664     raeburn  9590:                  $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443     albertel 9591:                  '</b><br />';
                   9592:     return $output;
                   9593: }
                   9594: 
                   9595: sub commit_standardrole {
1.541     raeburn  9596:     my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
                   9597:     my ($output,$logmsg,$linefeed);
                   9598:     if ($context eq 'auto') {
                   9599:         $linefeed = "\n";
                   9600:     } else {
                   9601:         $linefeed = "<br />\n";
                   9602:     }  
1.443     albertel 9603:     if ($three eq 'st') {
1.541     raeburn  9604:         my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
                   9605:                                          $one,$two,$sec,$context);
                   9606:         if (($result =~ /^error/) || ($result eq 'not_in_class') || 
1.626     raeburn  9607:             ($result eq 'unknown_course') || ($result eq 'refused')) {
                   9608:             $output = $logmsg.' '.&mt('Error: ').$result."\n"; 
1.443     albertel 9609:         } else {
1.541     raeburn  9610:             $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443     albertel 9611:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  9612:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
                   9613:             if ($context eq 'auto') {
                   9614:                 $output .= $result.$linefeed.&mt('Add to classlist').': ok';
                   9615:             } else {
                   9616:                $output .= '<b>'.$result.'</b>'.$linefeed.
                   9617:                &mt('Add to classlist').': <b>ok</b>';
                   9618:             }
                   9619:             $output .= $linefeed;
1.443     albertel 9620:         }
                   9621:     } else {
                   9622:         $output = &mt('Assigning').' '.$three.' in '.$url.
                   9623:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  9624:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652     raeburn  9625:         my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541     raeburn  9626:         if ($context eq 'auto') {
                   9627:             $output .= $result.$linefeed;
                   9628:         } else {
                   9629:             $output .= '<b>'.$result.'</b>'.$linefeed;
                   9630:         }
1.443     albertel 9631:     }
                   9632:     return $output;
                   9633: }
                   9634: 
                   9635: sub commit_studentrole {
1.541     raeburn  9636:     my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626     raeburn  9637:     my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541     raeburn  9638:     if ($context eq 'auto') {
                   9639:         $linefeed = "\n";
                   9640:     } else {
                   9641:         $linefeed = '<br />'."\n";
                   9642:     }
1.443     albertel 9643:     if (defined($one) && defined($two)) {
                   9644:         my $cid=$one.'_'.$two;
                   9645:         my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
                   9646:         my $secchange = 0;
                   9647:         my $expire_role_result;
                   9648:         my $modify_section_result;
1.628     raeburn  9649:         if ($oldsec ne '-1') { 
                   9650:             if ($oldsec ne $sec) {
1.443     albertel 9651:                 $secchange = 1;
1.628     raeburn  9652:                 my $now = time;
1.443     albertel 9653:                 my $uurl='/'.$cid;
                   9654:                 $uurl=~s/\_/\//g;
                   9655:                 if ($oldsec) {
                   9656:                     $uurl.='/'.$oldsec;
                   9657:                 }
1.626     raeburn  9658:                 $oldsecurl = $uurl;
1.628     raeburn  9659:                 $expire_role_result = 
1.652     raeburn  9660:                     &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628     raeburn  9661:                 if ($env{'request.course.sec'} ne '') { 
                   9662:                     if ($expire_role_result eq 'refused') {
                   9663:                         my @roles = ('st');
                   9664:                         my @statuses = ('previous');
                   9665:                         my @roledoms = ($one);
                   9666:                         my $withsec = 1;
                   9667:                         my %roleshash = 
                   9668:                             &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
                   9669:                                               \@statuses,\@roles,\@roledoms,$withsec);
                   9670:                         if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
                   9671:                             my ($oldstart,$oldend) = 
                   9672:                                 split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
                   9673:                             if ($oldend > 0 && $oldend <= $now) {
                   9674:                                 $expire_role_result = 'ok';
                   9675:                             }
                   9676:                         }
                   9677:                     }
                   9678:                 }
1.443     albertel 9679:                 $result = $expire_role_result;
                   9680:             }
                   9681:         }
                   9682:         if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652     raeburn  9683:             $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443     albertel 9684:             if ($modify_section_result =~ /^ok/) {
                   9685:                 if ($secchange == 1) {
1.628     raeburn  9686:                     if ($sec eq '') {
                   9687:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
                   9688:                     } else {
                   9689:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
                   9690:                     }
1.443     albertel 9691:                 } elsif ($oldsec eq '-1') {
1.628     raeburn  9692:                     if ($sec eq '') {
                   9693:                         $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
                   9694:                     } else {
                   9695:                         $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   9696:                     }
1.443     albertel 9697:                 } else {
1.628     raeburn  9698:                     if ($sec eq '') {
                   9699:                         $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
                   9700:                     } else {
                   9701:                         $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   9702:                     }
1.443     albertel 9703:                 }
                   9704:             } else {
1.628     raeburn  9705:                 if ($secchange) {       
                   9706:                     $$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;
                   9707:                 } else {
                   9708:                     $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
                   9709:                 }
1.443     albertel 9710:             }
                   9711:             $result = $modify_section_result;
                   9712:         } elsif ($secchange == 1) {
1.628     raeburn  9713:             if ($oldsec eq '') {
                   9714:                 $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
                   9715:             } else {
                   9716:                 $$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;
                   9717:             }
1.626     raeburn  9718:             if ($expire_role_result eq 'refused') {
                   9719:                 my $newsecurl = '/'.$cid;
                   9720:                 $newsecurl =~ s/\_/\//g;
                   9721:                 if ($sec ne '') {
                   9722:                     $newsecurl.='/'.$sec;
                   9723:                 }
                   9724:                 if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
                   9725:                     if ($sec eq '') {
                   9726:                         $$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;
                   9727:                     } else {
                   9728:                         $$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;
                   9729:                     }
                   9730:                 }
                   9731:             }
1.443     albertel 9732:         }
                   9733:     } else {
1.626     raeburn  9734:         $$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 9735:         $result = "error: incomplete course id\n";
                   9736:     }
                   9737:     return $result;
                   9738: }
                   9739: 
                   9740: ############################################################
                   9741: ############################################################
                   9742: 
1.566     albertel 9743: sub check_clone {
1.578     raeburn  9744:     my ($args,$linefeed) = @_;
1.566     albertel 9745:     my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
                   9746:     my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
                   9747:     my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
                   9748:     my $clonemsg;
                   9749:     my $can_clone = 0;
                   9750: 
                   9751:     if ($clonehome eq 'no_host') {
1.578     raeburn  9752:         $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 9753:     } else {
                   9754: 	my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568     albertel 9755: 	if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566     albertel 9756: 	    $can_clone = 1;
                   9757: 	} else {
                   9758: 	    my %clonehash = &Apache::lonnet::get('environment',['cloners'],
                   9759: 						 $args->{'clonedomain'},$args->{'clonecourse'});
                   9760: 	    my @cloners = split(/,/,$clonehash{'cloners'});
1.578     raeburn  9761:             if (grep(/^\*$/,@cloners)) {
                   9762:                 $can_clone = 1;
                   9763:             } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
                   9764:                 $can_clone = 1;
                   9765:             } else {
                   9766: 	        my %roleshash =
                   9767: 		    &Apache::lonnet::get_my_roles($args->{'ccuname'},
                   9768: 					 $args->{'ccdomain'},
                   9769:                                          'userroles',['active'],['cc'],
                   9770: 					 [$args->{'clonedomain'}]);
                   9771: 	        if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
                   9772: 		    $can_clone = 1;
                   9773: 	        } else {
                   9774:                     $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'});
                   9775: 	        }
1.566     albertel 9776: 	    }
1.578     raeburn  9777:         }
1.566     albertel 9778:     }
                   9779:     return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   9780: }
                   9781: 
1.444     albertel 9782: sub construct_course {
1.541     raeburn  9783:     my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444     albertel 9784:     my $outcome;
1.541     raeburn  9785:     my $linefeed =  '<br />'."\n";
                   9786:     if ($context eq 'auto') {
                   9787:         $linefeed = "\n";
                   9788:     }
1.566     albertel 9789: 
                   9790: #
                   9791: # Are we cloning?
                   9792: #
                   9793:     my ($can_clone, $clonemsg, $cloneid, $clonehome);
                   9794:     if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578     raeburn  9795: 	($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566     albertel 9796: 	if ($context ne 'auto') {
1.578     raeburn  9797:             if ($clonemsg ne '') {
                   9798: 	        $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
                   9799:             }
1.566     albertel 9800: 	}
                   9801: 	$outcome .= $clonemsg.$linefeed;
                   9802: 
                   9803:         if (!$can_clone) {
                   9804: 	    return (0,$outcome);
                   9805: 	}
                   9806:     }
                   9807: 
1.444     albertel 9808: #
                   9809: # Open course
                   9810: #
                   9811:     my $crstype = lc($args->{'crstype'});
                   9812:     my %cenv=();
                   9813:     $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
                   9814:                                              $args->{'cdescr'},
                   9815:                                              $args->{'curl'},
                   9816:                                              $args->{'course_home'},
                   9817:                                              $args->{'nonstandard'},
                   9818:                                              $args->{'crscode'},
                   9819:                                              $args->{'ccuname'}.':'.
                   9820:                                              $args->{'ccdomain'},
                   9821:                                              $args->{'crstype'});
                   9822: 
                   9823:     # Note: The testing routines depend on this being output; see 
                   9824:     # Utils::Course. This needs to at least be output as a comment
                   9825:     # if anyone ever decides to not show this, and Utils::Course::new
                   9826:     # will need to be suitably modified.
1.541     raeburn  9827:     $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444     albertel 9828: #
                   9829: # Check if created correctly
                   9830: #
1.479     albertel 9831:     ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444     albertel 9832:     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541     raeburn  9833:     $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566     albertel 9834: 
1.444     albertel 9835: #
1.566     albertel 9836: # Do the cloning
                   9837: #   
                   9838:     if ($can_clone && $cloneid) {
                   9839: 	$clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
                   9840: 	if ($context ne 'auto') {
                   9841: 	    $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
                   9842: 	}
                   9843: 	$outcome .= $clonemsg.$linefeed;
                   9844: 	my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444     albertel 9845: # Copy all files
1.637     www      9846: 	&Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444     albertel 9847: # Restore URL
1.566     albertel 9848: 	$cenv{'url'}=$oldcenv{'url'};
1.444     albertel 9849: # Restore title
1.566     albertel 9850: 	$cenv{'description'}=$oldcenv{'description'};
1.444     albertel 9851: # Mark as cloned
1.566     albertel 9852: 	$cenv{'clonedfrom'}=$cloneid;
1.638     www      9853: # Need to clone grading mode
                   9854:         my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
                   9855:         $cenv{'grading'}=$newenv{'grading'};
                   9856: # Do not clone these environment entries
                   9857:         &Apache::lonnet::del('environment',
                   9858:                   ['default_enrollment_start_date',
                   9859:                    'default_enrollment_end_date',
                   9860:                    'question.email',
                   9861:                    'policy.email',
                   9862:                    'comment.email',
                   9863:                    'pch.users.denied',
1.725     raeburn  9864:                    'plc.users.denied',
                   9865:                    'hidefromcat',
                   9866:                    'categories'],
1.638     www      9867:                    $$crsudom,$$crsunum);
1.444     albertel 9868:     }
1.566     albertel 9869: 
1.444     albertel 9870: #
                   9871: # Set environment (will override cloned, if existing)
                   9872: #
                   9873:     my @sections = ();
                   9874:     my @xlists = ();
                   9875:     if ($args->{'crstype'}) {
                   9876:         $cenv{'type'}=$args->{'crstype'};
                   9877:     }
                   9878:     if ($args->{'crsid'}) {
                   9879:         $cenv{'courseid'}=$args->{'crsid'};
                   9880:     }
                   9881:     if ($args->{'crscode'}) {
                   9882:         $cenv{'internal.coursecode'}=$args->{'crscode'};
                   9883:     }
                   9884:     if ($args->{'crsquota'} ne '') {
                   9885:         $cenv{'internal.coursequota'}=$args->{'crsquota'};
                   9886:     } else {
                   9887:         $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
                   9888:     }
                   9889:     if ($args->{'ccuname'}) {
                   9890:         $cenv{'internal.courseowner'} = $args->{'ccuname'}.
                   9891:                                         ':'.$args->{'ccdomain'};
                   9892:     } else {
                   9893:         $cenv{'internal.courseowner'} = $args->{'curruser'};
                   9894:     }
                   9895:     my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
                   9896:     if ($args->{'crssections'}) {
                   9897:         $cenv{'internal.sectionnums'} = '';
                   9898:         if ($args->{'crssections'} =~ m/,/) {
                   9899:             @sections = split/,/,$args->{'crssections'};
                   9900:         } else {
                   9901:             $sections[0] = $args->{'crssections'};
                   9902:         }
                   9903:         if (@sections > 0) {
                   9904:             foreach my $item (@sections) {
                   9905:                 my ($sec,$gp) = split/:/,$item;
                   9906:                 my $class = $args->{'crscode'}.$sec;
                   9907:                 my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
                   9908:                 $cenv{'internal.sectionnums'} .= $item.',';
                   9909:                 unless ($addcheck eq 'ok') {
                   9910:                     push @badclasses, $class;
                   9911:                 }
                   9912:             }
                   9913:             $cenv{'internal.sectionnums'} =~ s/,$//;
                   9914:         }
                   9915:     }
                   9916: # do not hide course coordinator from staff listing, 
                   9917: # even if privileged
                   9918:     $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   9919: # add crosslistings
                   9920:     if ($args->{'crsxlist'}) {
                   9921:         $cenv{'internal.crosslistings'}='';
                   9922:         if ($args->{'crsxlist'} =~ m/,/) {
                   9923:             @xlists = split/,/,$args->{'crsxlist'};
                   9924:         } else {
                   9925:             $xlists[0] = $args->{'crsxlist'};
                   9926:         }
                   9927:         if (@xlists > 0) {
                   9928:             foreach my $item (@xlists) {
                   9929:                 my ($xl,$gp) = split/:/,$item;
                   9930:                 my $addcheck =  &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
                   9931:                 $cenv{'internal.crosslistings'} .= $item.',';
                   9932:                 unless ($addcheck eq 'ok') {
                   9933:                     push @badclasses, $xl;
                   9934:                 }
                   9935:             }
                   9936:             $cenv{'internal.crosslistings'} =~ s/,$//;
                   9937:         }
                   9938:     }
                   9939:     if ($args->{'autoadds'}) {
                   9940:         $cenv{'internal.autoadds'}=$args->{'autoadds'};
                   9941:     }
                   9942:     if ($args->{'autodrops'}) {
                   9943:         $cenv{'internal.autodrops'}=$args->{'autodrops'};
                   9944:     }
                   9945: # check for notification of enrollment changes
                   9946:     my @notified = ();
                   9947:     if ($args->{'notify_owner'}) {
                   9948:         if ($args->{'ccuname'} ne '') {
                   9949:             push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
                   9950:         }
                   9951:     }
                   9952:     if ($args->{'notify_dc'}) {
                   9953:         if ($uname ne '') { 
1.630     raeburn  9954:             push(@notified,$uname.':'.$udom);
1.444     albertel 9955:         }
                   9956:     }
                   9957:     if (@notified > 0) {
                   9958:         my $notifylist;
                   9959:         if (@notified > 1) {
                   9960:             $notifylist = join(',',@notified);
                   9961:         } else {
                   9962:             $notifylist = $notified[0];
                   9963:         }
                   9964:         $cenv{'internal.notifylist'} = $notifylist;
                   9965:     }
                   9966:     if (@badclasses > 0) {
                   9967:         my %lt=&Apache::lonlocal::texthash(
                   9968:                 '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',
                   9969:                 'dnhr' => 'does not have rights to access enrollment in these classes',
                   9970:                 'adby' => 'as determined by the policies of your institution on access to official classlists'
                   9971:         );
1.541     raeburn  9972:         my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
                   9973:                            ' ('.$lt{'adby'}.')';
                   9974:         if ($context eq 'auto') {
                   9975:             $outcome .= $badclass_msg.$linefeed;
1.566     albertel 9976:             $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541     raeburn  9977:             foreach my $item (@badclasses) {
                   9978:                 if ($context eq 'auto') {
                   9979:                     $outcome .= " - $item\n";
                   9980:                 } else {
                   9981:                     $outcome .= "<li>$item</li>\n";
                   9982:                 }
                   9983:             }
                   9984:             if ($context eq 'auto') {
                   9985:                 $outcome .= $linefeed;
                   9986:             } else {
1.566     albertel 9987:                 $outcome .= "</ul><br /><br /></div>\n";
1.541     raeburn  9988:             }
                   9989:         } 
1.444     albertel 9990:     }
                   9991:     if ($args->{'no_end_date'}) {
                   9992:         $args->{'endaccess'} = 0;
                   9993:     }
                   9994:     $cenv{'internal.autostart'}=$args->{'enrollstart'};
                   9995:     $cenv{'internal.autoend'}=$args->{'enrollend'};
                   9996:     $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
                   9997:     $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
                   9998:     if ($args->{'showphotos'}) {
                   9999:       $cenv{'internal.showphotos'}=$args->{'showphotos'};
                   10000:     }
                   10001:     $cenv{'internal.authtype'} = $args->{'authtype'};
                   10002:     $cenv{'internal.autharg'} = $args->{'autharg'}; 
                   10003:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
                   10004:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
1.541     raeburn  10005:             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'); 
                   10006:             if ($context eq 'auto') {
                   10007:                 $outcome .= $krb_msg;
                   10008:             } else {
1.566     albertel 10009:                 $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541     raeburn  10010:             }
                   10011:             $outcome .= $linefeed;
1.444     albertel 10012:         }
                   10013:     }
                   10014:     if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
                   10015:        if ($args->{'setpolicy'}) {
                   10016:            $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   10017:        }
                   10018:        if ($args->{'setcontent'}) {
                   10019:            $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   10020:        }
                   10021:     }
                   10022:     if ($args->{'reshome'}) {
                   10023: 	$cenv{'reshome'}=$args->{'reshome'}.'/';
                   10024: 	$cenv{'reshome'}=~s/\/+$/\//;
                   10025:     }
                   10026: #
                   10027: # course has keyed access
                   10028: #
                   10029:     if ($args->{'setkeys'}) {
                   10030:        $cenv{'keyaccess'}='yes';
                   10031:     }
                   10032: # if specified, key authority is not course, but user
                   10033: # only active if keyaccess is yes
                   10034:     if ($args->{'keyauth'}) {
1.487     albertel 10035: 	my ($user,$domain) = split(':',$args->{'keyauth'});
                   10036: 	$user = &LONCAPA::clean_username($user);
                   10037: 	$domain = &LONCAPA::clean_username($domain);
1.488     foxr     10038: 	if ($user ne '' && $domain ne '') {
1.487     albertel 10039: 	    $cenv{'keyauth'}=$user.':'.$domain;
1.444     albertel 10040: 	}
                   10041:     }
                   10042: 
                   10043:     if ($args->{'disresdis'}) {
                   10044:         $cenv{'pch.roles.denied'}='st';
                   10045:     }
                   10046:     if ($args->{'disablechat'}) {
                   10047:         $cenv{'plc.roles.denied'}='st';
                   10048:     }
                   10049: 
                   10050:     # Record we've not yet viewed the Course Initialization Helper for this 
                   10051:     # course
                   10052:     $cenv{'course.helper.not.run'} = 1;
                   10053:     #
                   10054:     # Use new Randomseed
                   10055:     #
                   10056:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
                   10057:     $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
                   10058:     #
                   10059:     # The encryption code and receipt prefix for this course
                   10060:     #
                   10061:     $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
                   10062:     $cenv{'internal.encpref'}=100+int(9*rand(99));
                   10063:     #
                   10064:     # By default, use standard grading
                   10065:     if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
                   10066: 
1.541     raeburn  10067:     $outcome .= $linefeed.&mt('Setting environment').': '.                 
                   10068:           &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 10069: #
                   10070: # Open all assignments
                   10071: #
                   10072:     if ($args->{'openall'}) {
                   10073:        my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
                   10074:        my %storecontent = ($storeunder         => time,
                   10075:                            $storeunder.'.type' => 'date_start');
                   10076:        
                   10077:        $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541     raeburn  10078:                  ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 10079:    }
                   10080: #
                   10081: # Set first page
                   10082: #
                   10083:     unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
                   10084: 	    || ($cloneid)) {
1.445     albertel 10085: 	use LONCAPA::map;
1.444     albertel 10086: 	$outcome .= &mt('Setting first resource').': ';
1.445     albertel 10087: 
                   10088: 	my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
                   10089:         my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
                   10090: 
1.444     albertel 10091:         $outcome .= ($fatal?$errtext:'read ok').' - ';
                   10092:         my $title; my $url;
                   10093:         if ($args->{'firstres'} eq 'syl') {
1.690     bisitz   10094: 	    $title=&mt('Syllabus');
1.444     albertel 10095:             $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
                   10096:         } else {
1.690     bisitz   10097:             $title=&mt('Navigate Contents');
1.444     albertel 10098:             $url='/adm/navmaps';
                   10099:         }
1.445     albertel 10100: 
                   10101:         $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
                   10102: 	(my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
                   10103: 
                   10104: 	if ($errtext) { $fatal=2; }
1.541     raeburn  10105:         $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444     albertel 10106:     }
1.566     albertel 10107: 
                   10108:     return (1,$outcome);
1.444     albertel 10109: }
                   10110: 
                   10111: ############################################################
                   10112: ############################################################
                   10113: 
1.378     raeburn  10114: sub course_type {
                   10115:     my ($cid) = @_;
                   10116:     if (!defined($cid)) {
                   10117:         $cid = $env{'request.course.id'};
                   10118:     }
1.404     albertel 10119:     if (defined($env{'course.'.$cid.'.type'})) {
                   10120:         return $env{'course.'.$cid.'.type'};
1.378     raeburn  10121:     } else {
                   10122:         return 'Course';
1.377     raeburn  10123:     }
                   10124: }
1.156     albertel 10125: 
1.406     raeburn  10126: sub group_term {
                   10127:     my $crstype = &course_type();
                   10128:     my %names = (
                   10129:                   'Course' => 'group',
                   10130:                   'Group' => 'team',
                   10131:                 );
                   10132:     return $names{$crstype};
                   10133: }
                   10134: 
1.156     albertel 10135: sub icon {
                   10136:     my ($file)=@_;
1.505     albertel 10137:     my $curfext = lc((split(/\./,$file))[-1]);
1.168     albertel 10138:     my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156     albertel 10139:     my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168     albertel 10140:     if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
                   10141: 	if (-e  $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
                   10142: 	          $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   10143: 	            $curfext.".gif") {
                   10144: 	    $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   10145: 		$curfext.".gif";
                   10146: 	}
                   10147:     }
1.249     albertel 10148:     return &lonhttpdurl($iconname);
1.154     albertel 10149: } 
1.84      albertel 10150: 
1.575     albertel 10151: sub lonhttpdurl {
1.692     www      10152: #
                   10153: # Had been used for "small fry" static images on separate port 8080.
                   10154: # Modify here if lightweight http functionality desired again.
                   10155: # Currently eliminated due to increasing firewall issues.
                   10156: #
1.575     albertel 10157:     my ($url)=@_;
1.692     www      10158:     return $url;
1.215     albertel 10159: }
                   10160: 
1.213     albertel 10161: sub connection_aborted {
                   10162:     my ($r)=@_;
                   10163:     $r->print(" ");$r->rflush();
                   10164:     my $c = $r->connection;
                   10165:     return $c->aborted();
                   10166: }
                   10167: 
1.221     foxr     10168: #    Escapes strings that may have embedded 's that will be put into
1.222     foxr     10169: #    strings as 'strings'.
                   10170: sub escape_single {
1.221     foxr     10171:     my ($input) = @_;
1.223     albertel 10172:     $input =~ s/\\/\\\\/g;	# Escape the \'s..(must be first)>
1.221     foxr     10173:     $input =~ s/\'/\\\'/g;	# Esacpe the 's....
                   10174:     return $input;
                   10175: }
1.223     albertel 10176: 
1.222     foxr     10177: #  Same as escape_single, but escape's "'s  This 
                   10178: #  can be used for  "strings"
                   10179: sub escape_double {
                   10180:     my ($input) = @_;
                   10181:     $input =~ s/\\/\\\\/g;	# Escape the /'s..(must be first)>
                   10182:     $input =~ s/\"/\\\"/g;	# Esacpe the "s....
                   10183:     return $input;
                   10184: }
1.223     albertel 10185:  
1.222     foxr     10186: #   Escapes the last element of a full URL.
                   10187: sub escape_url {
                   10188:     my ($url)   = @_;
1.238     raeburn  10189:     my @urlslices = split(/\//, $url,-1);
1.369     www      10190:     my $lastitem = &escape(pop(@urlslices));
1.223     albertel 10191:     return join('/',@urlslices).'/'.$lastitem;
1.222     foxr     10192: }
1.462     albertel 10193: 
                   10194: # -------------------------------------------------------- Initliaze user login
                   10195: sub init_user_environment {
1.463     albertel 10196:     my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462     albertel 10197:     my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
                   10198: 
                   10199:     my $public=($username eq 'public' && $domain eq 'public');
                   10200: 
                   10201: # See if old ID present, if so, remove
                   10202: 
                   10203:     my ($filename,$cookie,$userroles);
                   10204:     my $now=time;
                   10205: 
                   10206:     if ($public) {
                   10207: 	my $max_public=100;
                   10208: 	my $oldest;
                   10209: 	my $oldest_time=0;
                   10210: 	for(my $next=1;$next<=$max_public;$next++) {
                   10211: 	    if (-e $lonids."/publicuser_$next.id") {
                   10212: 		my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
                   10213: 		if ($mtime<$oldest_time || !$oldest_time) {
                   10214: 		    $oldest_time=$mtime;
                   10215: 		    $oldest=$next;
                   10216: 		}
                   10217: 	    } else {
                   10218: 		$cookie="publicuser_$next";
                   10219: 		last;
                   10220: 	    }
                   10221: 	}
                   10222: 	if (!$cookie) { $cookie="publicuser_$oldest"; }
                   10223:     } else {
1.463     albertel 10224: 	# if this isn't a robot, kill any existing non-robot sessions
                   10225: 	if (!$args->{'robot'}) {
                   10226: 	    opendir(DIR,$lonids);
                   10227: 	    while ($filename=readdir(DIR)) {
                   10228: 		if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
                   10229: 		    unlink($lonids.'/'.$filename);
                   10230: 		}
1.462     albertel 10231: 	    }
1.463     albertel 10232: 	    closedir(DIR);
1.462     albertel 10233: 	}
                   10234: # Give them a new cookie
1.463     albertel 10235: 	my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684     www      10236: 		                   : $now.$$.int(rand(10000)));
1.463     albertel 10237: 	$cookie="$username\_$id\_$domain\_$authhost";
1.462     albertel 10238:     
                   10239: # Initialize roles
                   10240: 
                   10241: 	$userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
                   10242:     }
                   10243: # ------------------------------------ Check browser type and MathML capability
                   10244: 
                   10245:     my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   10246:         $clientunicode,$clientos) = &decode_user_agent($r);
                   10247: 
                   10248: # -------------------------------------- Any accessibility options to remember?
                   10249:     if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
                   10250: 	foreach my $option ('imagesuppress','appletsuppress',
                   10251: 			    'embedsuppress','fontenhance','blackwhite') {
                   10252: 	    if ($form->{$option} eq 'true') {
                   10253: 		&Apache::lonnet::put('environment',{$option => 'on'},
                   10254: 				     $domain,$username);
                   10255: 	    } else {
                   10256: 		&Apache::lonnet::del('environment',[$option],
                   10257: 				     $domain,$username);
                   10258: 	    }
                   10259: 	}
                   10260:     }
                   10261: # ------------------------------------------------------------- Get environment
                   10262: 
                   10263:     my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
                   10264:     my ($tmp) = keys(%userenv);
                   10265:     if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   10266: 	# default remote control to off
                   10267: 	if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
                   10268:     } else {
                   10269: 	undef(%userenv);
                   10270:     }
                   10271:     if (($userenv{'interface'}) && (!$form->{'interface'})) {
                   10272: 	$form->{'interface'}=$userenv{'interface'};
                   10273:     }
                   10274:     $env{'environment.remote'}=$userenv{'remote'};
                   10275:     if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
                   10276: 
                   10277: # --------------- Do not trust query string to be put directly into environment
                   10278:     foreach my $option ('imagesuppress','appletsuppress',
                   10279: 			'embedsuppress','fontenhance','blackwhite',
                   10280: 			'interface','localpath','localres') {
                   10281: 	$form->{$option}=~s/[\n\r\=]//gs;
                   10282:     }
                   10283: # --------------------------------------------------------- Write first profile
                   10284: 
                   10285:     {
                   10286: 	my %initial_env = 
                   10287: 	    ("user.name"          => $username,
                   10288: 	     "user.domain"        => $domain,
                   10289: 	     "user.home"          => $authhost,
                   10290: 	     "browser.type"       => $clientbrowser,
                   10291: 	     "browser.version"    => $clientversion,
                   10292: 	     "browser.mathml"     => $clientmathml,
                   10293: 	     "browser.unicode"    => $clientunicode,
                   10294: 	     "browser.os"         => $clientos,
                   10295: 	     "server.domain"      => $Apache::lonnet::perlvar{'lonDefDomain'},
                   10296: 	     "request.course.fn"  => '',
                   10297: 	     "request.course.uri" => '',
                   10298: 	     "request.course.sec" => '',
                   10299: 	     "request.role"       => 'cm',
                   10300: 	     "request.role.adv"   => $env{'user.adv'},
                   10301: 	     "request.host"       => $ENV{'REMOTE_ADDR'},);
                   10302: 
                   10303:         if ($form->{'localpath'}) {
                   10304: 	    $initial_env{"browser.localpath"}  = $form->{'localpath'};
                   10305: 	    $initial_env{"browser.localres"}   = $form->{'localres'};
                   10306:         }
                   10307: 	
                   10308: 	if ($public) {
                   10309: 	    $initial_env{"environment.remote"} = "off";
                   10310: 	}
                   10311: 	if ($form->{'interface'}) {
                   10312: 	    $form->{'interface'}=~s/\W//gs;
                   10313: 	    $initial_env{"browser.interface"} = $form->{'interface'};
                   10314: 	    $env{'browser.interface'}=$form->{'interface'};
                   10315: 	    foreach my $option ('imagesuppress','appletsuppress',
                   10316: 				'embedsuppress','fontenhance','blackwhite') {
                   10317: 		if (($form->{$option} eq 'true') ||
                   10318: 		    ($userenv{$option} eq 'on')) {
                   10319: 		    $initial_env{"browser.$option"} = "on";
                   10320: 		}
                   10321: 	    }
                   10322: 	}
                   10323: 
1.724     raeburn  10324:         foreach my $tool ('aboutme','blog','portfolio') {
                   10325:             $userenv{'availabletools.'.$tool} = 
                   10326:                 &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
                   10327:         }
                   10328: 
1.765     raeburn  10329:         foreach my $crstype ('official','unofficial') {
                   10330:             $userenv{'canrequest.'.$crstype} =
                   10331:                 &Apache::lonnet::usertools_access($username,$domain,$crstype,
                   10332:                                                   'reload','requestcourses');
                   10333:         }
                   10334: 
1.462     albertel 10335: 	$env{'user.environment'} = "$lonids/$cookie.id";
                   10336: 	
                   10337: 	if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
                   10338: 		 &GDBM_WRCREAT(),0640)) {
                   10339: 	    &_add_to_env(\%disk_env,\%initial_env);
                   10340: 	    &_add_to_env(\%disk_env,\%userenv,'environment.');
                   10341: 	    &_add_to_env(\%disk_env,$userroles);
1.463     albertel 10342: 	    if (ref($args->{'extra_env'})) {
                   10343: 		&_add_to_env(\%disk_env,$args->{'extra_env'});
                   10344: 	    }
1.462     albertel 10345: 	    untie(%disk_env);
                   10346: 	} else {
1.705     tempelho 10347: 	    &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
                   10348: 			   'Could not create environment storage in lonauth: '.$!.'</span>');
1.462     albertel 10349: 	    return 'error: '.$!;
                   10350: 	}
                   10351:     }
                   10352:     $env{'request.role'}='cm';
                   10353:     $env{'request.role.adv'}=$env{'user.adv'};
                   10354:     $env{'browser.type'}=$clientbrowser;
                   10355: 
                   10356:     return $cookie;
                   10357: 
                   10358: }
                   10359: 
                   10360: sub _add_to_env {
                   10361:     my ($idf,$env_data,$prefix) = @_;
1.676     raeburn  10362:     if (ref($env_data) eq 'HASH') {
                   10363:         while (my ($key,$value) = each(%$env_data)) {
                   10364: 	    $idf->{$prefix.$key} = $value;
                   10365: 	    $env{$prefix.$key}   = $value;
                   10366:         }
1.462     albertel 10367:     }
                   10368: }
                   10369: 
1.685     tempelho 10370: # --- Get the symbolic name of a problem and the url
                   10371: sub get_symb {
                   10372:     my ($request,$silent) = @_;
1.726     raeburn  10373:     (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685     tempelho 10374:     my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
                   10375:     if ($symb eq '') {
                   10376:         if (!$silent) {
                   10377:             $request->print("Unable to handle ambiguous references:$url:.");
                   10378:             return ();
                   10379:         }
                   10380:     }
                   10381:     &Apache::lonenc::check_decrypt(\$symb);
                   10382:     return ($symb);
                   10383: }
                   10384: 
                   10385: # --------------------------------------------------------------Get annotation
                   10386: 
                   10387: sub get_annotation {
                   10388:     my ($symb,$enc) = @_;
                   10389: 
                   10390:     my $key = $symb;
                   10391:     if (!$enc) {
                   10392:         $key =
                   10393:             &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
                   10394:     }
                   10395:     my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
                   10396:     return $annotation{$key};
                   10397: }
                   10398: 
                   10399: sub clean_symb {
1.731     raeburn  10400:     my ($symb,$delete_enc) = @_;
1.685     tempelho 10401: 
                   10402:     &Apache::lonenc::check_decrypt(\$symb);
                   10403:     my $enc = $env{'request.enc'};
1.731     raeburn  10404:     if ($delete_enc) {
1.730     raeburn  10405:         delete($env{'request.enc'});
                   10406:     }
1.685     tempelho 10407: 
                   10408:     return ($symb,$enc);
                   10409: }
1.462     albertel 10410: 
1.41      ng       10411: =pod
                   10412: 
                   10413: =back
                   10414: 
1.112     bowersj2 10415: =cut
1.41      ng       10416: 
1.112     bowersj2 10417: 1;
                   10418: __END__;
1.41      ng       10419: 

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