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

1.10      albertel    1: # The LearningOnline Network with CAPA
1.1       albertel    2: # a pile of common routines
1.10      albertel    3: #
1.810   ! bisitz      4: # $Id: loncommon.pm,v 1.809 2009/05/11 14:13:51 bisitz Exp $
1.10      albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
1.1       albertel   28: 
                     29: # Makes a table out of the previous attempts
1.2       albertel   30: # Inputs result_from_symbread, user, domain, course_id
1.16      harris41   31: # Reads in non-network-related .tab files
1.1       albertel   32: 
1.35      matthew    33: # POD header:
                     34: 
1.45      matthew    35: =pod
                     36: 
1.35      matthew    37: =head1 NAME
                     38: 
                     39: Apache::loncommon - pile of common routines
                     40: 
                     41: =head1 SYNOPSIS
                     42: 
1.112     bowersj2   43: Common routines for manipulating connections, student answers,
                     44:     domains, common Javascript fragments, etc.
1.35      matthew    45: 
1.112     bowersj2   46: =head1 OVERVIEW
1.35      matthew    47: 
1.112     bowersj2   48: A collection of commonly used subroutines that don't have a natural
                     49: home anywhere else. This collection helps remove
1.35      matthew    50: redundancy from other modules and increase efficiency of memory usage.
                     51: 
                     52: =cut 
                     53: 
                     54: # End of POD header
1.1       albertel   55: package Apache::loncommon;
                     56: 
                     57: use strict;
1.258     albertel   58: use Apache::lonnet;
1.46      matthew    59: use GDBM_File;
1.51      www        60: use POSIX qw(strftime mktime);
1.82      www        61: use Apache::lonmenu();
1.498     albertel   62: use Apache::lonenc();
1.117     www        63: use Apache::lonlocal;
1.685     tempelho   64: use Apache::lonnet();
1.139     matthew    65: use HTML::Entities;
1.334     albertel   66: use Apache::lonhtmlcommon();
                     67: use Apache::loncoursedata();
1.344     albertel   68: use Apache::lontexconvert();
1.444     albertel   69: use Apache::lonclonecourse();
1.479     albertel   70: use LONCAPA qw(:DEFAULT :match);
1.657     raeburn    71: use DateTime::TimeZone;
1.687     raeburn    72: use DateTime::Locale::Catalog;
1.117     www        73: 
1.517     raeburn    74: # ---------------------------------------------- Designs
                     75: use vars qw(%defaultdesign);
                     76: 
1.22      www        77: my $readit;
                     78: 
1.517     raeburn    79: 
1.157     matthew    80: ##
                     81: ## Global Variables
                     82: ##
1.46      matthew    83: 
1.643     foxr       84: 
                     85: # ----------------------------------------------- SSI with retries:
                     86: #
                     87: 
                     88: =pod
                     89: 
1.648     raeburn    90: =head1 Server Side include with retries:
1.643     foxr       91: 
                     92: =over 4
                     93: 
1.648     raeburn    94: =item * &ssi_with_retries(resource,retries form)
1.643     foxr       95: 
                     96: Performs an ssi with some number of retries.  Retries continue either
                     97: until the result is ok or until the retry count supplied by the
                     98: caller is exhausted.  
                     99: 
                    100: Inputs:
1.648     raeburn   101: 
                    102: =over 4
                    103: 
1.643     foxr      104: resource   - Identifies the resource to insert.
1.648     raeburn   105: 
1.643     foxr      106: retries    - Count of the number of retries allowed.
1.648     raeburn   107: 
1.643     foxr      108: form       - Hash that identifies the rendering options.
                    109: 
1.648     raeburn   110: =back
                    111: 
                    112: Returns:
                    113: 
                    114: =over 4
                    115: 
1.643     foxr      116: content    - The content of the response.  If retries were exhausted this is empty.
1.648     raeburn   117: 
1.643     foxr      118: response   - The response from the last attempt (which may or may not have been successful.
                    119: 
1.648     raeburn   120: =back
                    121: 
                    122: =back
                    123: 
1.643     foxr      124: =cut
                    125: 
                    126: sub ssi_with_retries {
                    127:     my ($resource, $retries, %form) = @_;
                    128: 
                    129: 
                    130:     my $ok = 0;			# True if we got a good response.
                    131:     my $content;
                    132:     my $response;
                    133: 
                    134:     # Try to get the ssi done. within the retries count:
                    135: 
                    136:     do {
                    137: 	($content, $response) = &Apache::lonnet::ssi($resource, %form);
                    138: 	$ok      = $response->is_success;
1.650     www       139:         if (!$ok) {
                    140:             &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
                    141:         }
1.643     foxr      142: 	$retries--;
                    143:     } while (!$ok && ($retries > 0));
                    144: 
                    145:     if (!$ok) {
                    146: 	$content = '';		# On error return an empty content.
                    147:     }
                    148:     return ($content, $response);
                    149: 
                    150: }
                    151: 
                    152: 
                    153: 
1.20      www       154: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12      harris41  155: my %language;
1.124     www       156: my %supported_language;
1.12      harris41  157: my %cprtag;
1.192     taceyjo1  158: my %scprtag;
1.351     www       159: my %fe; my %fd; my %fm;
1.41      ng        160: my %category_extensions;
1.12      harris41  161: 
1.46      matthew   162: # ---------------------------------------------- Thesaurus variables
1.144     matthew   163: #
                    164: # %Keywords:
                    165: #      A hash used by &keyword to determine if a word is considered a keyword.
                    166: # $thesaurus_db_file 
                    167: #      Scalar containing the full path to the thesaurus database.
1.46      matthew   168: 
                    169: my %Keywords;
                    170: my $thesaurus_db_file;
                    171: 
1.144     matthew   172: #
                    173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
                    174: # thesaurus.tab, and filecategories.tab.
                    175: #
1.18      www       176: BEGIN {
1.46      matthew   177:     # Variable initialization
                    178:     $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
                    179:     #
1.22      www       180:     unless ($readit) {
1.12      harris41  181: # ------------------------------------------------------------------- languages
                    182:     {
1.158     raeburn   183:         my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    184:                                    '/language.tab';
                    185:         if ( open(my $fh,"<$langtabfile") ) {
1.356     albertel  186:             while (my $line = <$fh>) {
                    187:                 next if ($line=~/^\#/);
                    188:                 chomp($line);
                    189:                 my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158     raeburn   190:                 $language{$key}=$val.' - '.$enc;
                    191:                 if ($sup) {
                    192:                     $supported_language{$key}=$sup;
                    193:                 }
                    194:             }
                    195:             close($fh);
                    196:         }
1.12      harris41  197:     }
                    198: # ------------------------------------------------------------------ copyrights
                    199:     {
1.158     raeburn   200:         my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
                    201:                                   '/copyright.tab';
                    202:         if ( open (my $fh,"<$copyrightfile") ) {
1.356     albertel  203:             while (my $line = <$fh>) {
                    204:                 next if ($line=~/^\#/);
                    205:                 chomp($line);
                    206:                 my ($key,$val)=(split(/\s+/,$line,2));
1.158     raeburn   207:                 $cprtag{$key}=$val;
                    208:             }
                    209:             close($fh);
                    210:         }
1.12      harris41  211:     }
1.351     www       212: # ----------------------------------------------------------- source copyrights
1.192     taceyjo1  213:     {
                    214:         my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
                    215:                                   '/source_copyright.tab';
                    216:         if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356     albertel  217:             while (my $line = <$fh>) {
                    218:                 next if ($line =~ /^\#/);
                    219:                 chomp($line);
                    220:                 my ($key,$val)=(split(/\s+/,$line,2));
1.192     taceyjo1  221:                 $scprtag{$key}=$val;
                    222:             }
                    223:             close($fh);
                    224:         }
                    225:     }
1.63      www       226: 
1.517     raeburn   227: # -------------------------------------------------------------- default domain designs
1.63      www       228:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517     raeburn   229:     my $designfile = $designdir.'/default.tab';
                    230:     if ( open (my $fh,"<$designfile") ) {
                    231:         while (my $line = <$fh>) {
                    232:             next if ($line =~ /^\#/);
                    233:             chomp($line);
                    234:             my ($key,$val)=(split(/\=/,$line));
                    235:             if ($val) { $defaultdesign{$key}=$val; }
                    236:         }
                    237:         close($fh);
1.63      www       238:     }
                    239: 
1.15      harris41  240: # ------------------------------------------------------------- file categories
                    241:     {
1.158     raeburn   242:         my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    243:                                   '/filecategories.tab';
                    244:         if ( open (my $fh,"<$categoryfile") ) {
1.356     albertel  245: 	    while (my $line = <$fh>) {
                    246: 		next if ($line =~ /^\#/);
                    247: 		chomp($line);
                    248:                 my ($extension,$category)=(split(/\s+/,$line,2));
1.158     raeburn   249:                 push @{$category_extensions{lc($category)}},$extension;
                    250:             }
                    251:             close($fh);
                    252:         }
                    253: 
1.15      harris41  254:     }
1.12      harris41  255: # ------------------------------------------------------------------ file types
                    256:     {
1.158     raeburn   257:         my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    258:                '/filetypes.tab';
                    259:         if ( open (my $fh,"<$typesfile") ) {
1.356     albertel  260:             while (my $line = <$fh>) {
                    261: 		next if ($line =~ /^\#/);
                    262: 		chomp($line);
                    263:                 my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158     raeburn   264:                 if ($descr ne '') {
                    265:                     $fe{$ending}=lc($emb);
                    266:                     $fd{$ending}=$descr;
1.351     www       267:                     if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158     raeburn   268:                 }
                    269:             }
                    270:             close($fh);
                    271:         }
1.12      harris41  272:     }
1.22      www       273:     &Apache::lonnet::logthis(
1.705     tempelho  274:              "<span style='color:yellow;'>INFO: Read file types</span>");
1.22      www       275:     $readit=1;
1.46      matthew   276:     }  # end of unless($readit) 
1.32      matthew   277:     
                    278: }
1.112     bowersj2  279: 
1.42      matthew   280: ###############################################################
                    281: ##           HTML and Javascript Helper Functions            ##
                    282: ###############################################################
                    283: 
                    284: =pod 
                    285: 
1.112     bowersj2  286: =head1 HTML and Javascript Functions
1.42      matthew   287: 
1.112     bowersj2  288: =over 4
                    289: 
1.648     raeburn   290: =item * &browser_and_searcher_javascript()
1.112     bowersj2  291: 
                    292: X<browsing, javascript>X<searching, javascript>Returns a string
                    293: containing javascript with two functions, C<openbrowser> and
                    294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
                    295: tags.
1.42      matthew   296: 
1.648     raeburn   297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42      matthew   298: 
                    299: inputs: formname, elementname, only, omit
                    300: 
                    301: formname and elementname indicate the name of the html form and name of
                    302: the element that the results of the browsing selection are to be placed in. 
                    303: 
                    304: Specifying 'only' will restrict the browser to displaying only files
1.185     www       305: with the given extension.  Can be a comma separated list.
1.42      matthew   306: 
                    307: Specifying 'omit' will restrict the browser to NOT displaying files
1.185     www       308: with the given extension.  Can be a comma separated list.
1.42      matthew   309: 
1.648     raeburn   310: =item * &opensearcher(formname,elementname) [javascript]
1.42      matthew   311: 
                    312: Inputs: formname, elementname
                    313: 
                    314: formname and elementname specify the name of the html form and the name
                    315: of the element the selection from the search results will be placed in.
1.542     raeburn   316: 
1.42      matthew   317: =cut
                    318: 
                    319: sub browser_and_searcher_javascript {
1.199     albertel  320:     my ($mode)=@_;
                    321:     if (!defined($mode)) { $mode='edit'; }
1.453     albertel  322:     my $resurl=&escape_single(&lastresurl());
1.42      matthew   323:     return <<END;
1.219     albertel  324: // <!-- BEGIN LON-CAPA Internal
1.50      matthew   325:     var editbrowser = null;
1.135     albertel  326:     function openbrowser(formname,elementname,only,omit,titleelement) {
1.170     www       327:         var url = '$resurl/?';
1.42      matthew   328:         if (editbrowser == null) {
                    329:             url += 'launch=1&';
                    330:         }
                    331:         url += 'catalogmode=interactive&';
1.199     albertel  332:         url += 'mode=$mode&';
1.611     albertel  333:         url += 'inhibitmenu=yes&';
1.42      matthew   334:         url += 'form=' + formname + '&';
                    335:         if (only != null) {
                    336:             url += 'only=' + only + '&';
1.217     albertel  337:         } else {
                    338:             url += 'only=&';
                    339: 	}
1.42      matthew   340:         if (omit != null) {
                    341:             url += 'omit=' + omit + '&';
1.217     albertel  342:         } else {
                    343:             url += 'omit=&';
                    344: 	}
1.135     albertel  345:         if (titleelement != null) {
                    346:             url += 'titleelement=' + titleelement + '&';
1.217     albertel  347:         } else {
                    348: 	    url += 'titleelement=&';
                    349: 	}
1.42      matthew   350:         url += 'element=' + elementname + '';
                    351:         var title = 'Browser';
1.435     albertel  352:         var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42      matthew   353:         options += ',width=700,height=600';
                    354:         editbrowser = open(url,title,options,'1');
                    355:         editbrowser.focus();
                    356:     }
                    357:     var editsearcher;
1.135     albertel  358:     function opensearcher(formname,elementname,titleelement) {
1.42      matthew   359:         var url = '/adm/searchcat?';
                    360:         if (editsearcher == null) {
                    361:             url += 'launch=1&';
                    362:         }
                    363:         url += 'catalogmode=interactive&';
1.199     albertel  364:         url += 'mode=$mode&';
1.42      matthew   365:         url += 'form=' + formname + '&';
1.135     albertel  366:         if (titleelement != null) {
                    367:             url += 'titleelement=' + titleelement + '&';
1.217     albertel  368:         } else {
                    369: 	    url += 'titleelement=&';
                    370: 	}
1.42      matthew   371:         url += 'element=' + elementname + '';
                    372:         var title = 'Search';
1.435     albertel  373:         var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42      matthew   374:         options += ',width=700,height=600';
                    375:         editsearcher = open(url,title,options,'1');
                    376:         editsearcher.focus();
                    377:     }
1.219     albertel  378: // END LON-CAPA Internal -->
1.42      matthew   379: END
1.170     www       380: }
                    381: 
                    382: sub lastresurl {
1.258     albertel  383:     if ($env{'environment.lastresurl'}) {
                    384: 	return $env{'environment.lastresurl'}
1.170     www       385:     } else {
                    386: 	return '/res';
                    387:     }
                    388: }
                    389: 
                    390: sub storeresurl {
                    391:     my $resurl=&Apache::lonnet::clutter(shift);
                    392:     unless ($resurl=~/^\/res/) { return 0; }
                    393:     $resurl=~s/\/$//;
                    394:     &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646     raeburn   395:     &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170     www       396:     return 1;
1.42      matthew   397: }
                    398: 
1.74      www       399: sub studentbrowser_javascript {
1.111     www       400:    unless (
1.258     albertel  401:             (($env{'request.course.id'}) && 
1.302     albertel  402:              (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    403: 	      || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                    404: 					  '/'.$env{'request.course.sec'})
                    405: 	      ))
1.258     albertel  406:          || ($env{'request.role'}=~/^(au|dc|su)/)
1.111     www       407:           ) { return ''; }  
1.74      www       408:    return (<<'ENDSTDBRW');
1.776     bisitz    409: <script type="text/javascript" language="Javascript">
1.74      www       410:     var stdeditbrowser;
1.793     raeburn   411:     function openstdbrowser(formname,uname,udom,roleflag,ignorefilter,courseadvonly) {
1.74      www       412:         var url = '/adm/pickstudent?';
                    413:         var filter;
1.558     albertel  414: 	if (!ignorefilter) {
                    415: 	    eval('filter=document.'+formname+'.'+uname+'.value;');
                    416: 	}
1.74      www       417:         if (filter != null) {
                    418:            if (filter != '') {
                    419:                url += 'filter='+filter+'&';
                    420: 	   }
                    421:         }
                    422:         url += 'form=' + formname + '&unameelement='+uname+
                    423:                                     '&udomelement='+udom;
1.111     www       424: 	if (roleflag) { url+="&roles=1"; }
1.793     raeburn   425:         if (courseadvonly) { url+="&courseadvonly=1"; }
1.102     www       426:         var title = 'Student_Browser';
1.74      www       427:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    428:         options += ',width=700,height=600';
                    429:         stdeditbrowser = open(url,title,options,'1');
                    430:         stdeditbrowser.focus();
                    431:     }
                    432: </script>
                    433: ENDSTDBRW
                    434: }
1.42      matthew   435: 
1.74      www       436: sub selectstudent_link {
1.793     raeburn   437:    my ($form,$unameele,$udomele,$courseadvonly)=@_;
                    438:    my $callargs = "'".$form."','".$unameele."','".$udomele."'";
1.258     albertel  439:    if ($env{'request.course.id'}) {  
1.302     albertel  440:        if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    441: 	   && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                    442: 					'/'.$env{'request.course.sec'})) {
1.111     www       443: 	   return '';
                    444:        }
1.793     raeburn   445:        if ($courseadvonly)  {
                    446:            $callargs .= ",'',1,1";
                    447:        }
                    448:        return '<span class="LC_nobreak">'.
                    449:               '<a href="javascript:openstdbrowser('.$callargs.');">'.
                    450:               &mt('Select User').'</a></span>';
1.74      www       451:    }
1.258     albertel  452:    if ($env{'request.role'}=~/^(au|dc|su)/) {
1.793     raeburn   453:        $callargs .= ",1"; 
                    454:        return '<span class="LC_nobreak">'.
                    455:               '<a href="javascript:openstdbrowser('.$callargs.');">'.
                    456:               &mt('Select User').'</a></span>';
1.111     www       457:    }
                    458:    return '';
1.91      www       459: }
                    460: 
1.653     raeburn   461: sub authorbrowser_javascript {
                    462:     return <<"ENDAUTHORBRW";
1.776     bisitz    463: <script type="text/javascript" language="JavaScript">
1.653     raeburn   464: var stdeditbrowser;
                    465: 
                    466: function openauthorbrowser(formname,udom) {
                    467:     var url = '/adm/pickauthor?';
                    468:     url += 'form='+formname+'&roledom='+udom;
                    469:     var title = 'Author_Browser';
                    470:     var options = 'scrollbars=1,resizable=1,menubar=0';
                    471:     options += ',width=700,height=600';
                    472:     stdeditbrowser = open(url,title,options,'1');
                    473:     stdeditbrowser.focus();
                    474: }
                    475: 
                    476: </script>
                    477: ENDAUTHORBRW
                    478: }
                    479: 
1.91      www       480: sub coursebrowser_javascript {
1.468     raeburn   481:     my ($domainfilter,$sec_element,$formname)=@_;
1.377     raeburn   482:     my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Group - for which you wish to add/modify a user role');
1.468     raeburn   483:    my $output = '
1.776     bisitz    484: <script type="text/javascript" language="JavaScript">
1.468     raeburn   485:     var stdeditbrowser;'."\n";
                    486:    $output .= <<"ENDSTDBRW";
1.377     raeburn   487:     function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
1.91      www       488:         var url = '/adm/pickcourse?';
1.468     raeburn   489:         var domainfilter = '';
                    490:         var formid = getFormIdByName(formname);
                    491:         if (formid > -1) {
                    492:             var domid = getIndexByName(formid,udom);
                    493:             if (domid > -1) {
                    494:                 if (document.forms[formid].elements[domid].type == 'select-one') {
                    495:                     domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
                    496:                 }
                    497:                 if (document.forms[formid].elements[domid].type == 'hidden') {
                    498:                     domainfilter=document.forms[formid].elements[domid].value;
                    499:                 }
                    500:             }
1.91      www       501:         }
1.128     albertel  502:         if (domainfilter != null) {
                    503:            if (domainfilter != '') {
                    504:                url += 'domainfilter='+domainfilter+'&';
                    505: 	   }
                    506:         }
1.91      www       507:         url += 'form=' + formname + '&cnumelement='+uname+
1.187     albertel  508: 	                            '&cdomelement='+udom+
                    509:                                     '&cnameelement='+desc;
1.468     raeburn   510:         if (extra_element !=null && extra_element != '') {
1.594     raeburn   511:             if (formname == 'rolechoice' || formname == 'studentform') {
1.468     raeburn   512:                 url += '&roleelement='+extra_element;
                    513:                 if (domainfilter == null || domainfilter == '') {
                    514:                     url += '&domainfilter='+extra_element;
                    515:                 }
1.234     raeburn   516:             }
1.468     raeburn   517:             else {
                    518:                 if (formname == 'portform') {
                    519:                     url += '&setroles='+extra_element;
1.800     raeburn   520:                 } else {
                    521:                     if (formname == 'rules') {
                    522:                         url += '&fixeddom='+extra_element; 
                    523:                     }
1.468     raeburn   524:                 }
                    525:             }     
1.230     raeburn   526:         }
1.293     raeburn   527:         if (multflag !=null && multflag != '') {
                    528:             url += '&multiple='+multflag;
                    529:         }
1.377     raeburn   530:         if (crstype == 'Course/Group') {
                    531:             if (formname == 'cu') {
                    532:                 crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value; 
                    533:                 if (crstype == "") {
                    534:                     alert("$crs_or_grp_alert");
                    535:                     return;
                    536:                 }
                    537:             }
                    538:         }
                    539:         if (crstype !=null && crstype != '') {
                    540:             url += '&type='+crstype;
                    541:         }
1.102     www       542:         var title = 'Course_Browser';
1.91      www       543:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    544:         options += ',width=700,height=600';
                    545:         stdeditbrowser = open(url,title,options,'1');
                    546:         stdeditbrowser.focus();
                    547:     }
1.468     raeburn   548: 
                    549:     function getFormIdByName(formname) {
                    550:         for (var i=0;i<document.forms.length;i++) {
                    551:             if (document.forms[i].name == formname) {
                    552:                 return i;
                    553:             }
                    554:         }
                    555:         return -1; 
                    556:     }
                    557: 
                    558:     function getIndexByName(formid,item) {
                    559:         for (var i=0;i<document.forms[formid].elements.length;i++) {
                    560:             if (document.forms[formid].elements[i].name == item) {
                    561:                 return i;
                    562:             }
                    563:         }
                    564:         return -1;
                    565:     }
1.91      www       566: ENDSTDBRW
1.468     raeburn   567:     if ($sec_element ne '') {
                    568:         $output .= &setsec_javascript($sec_element,$formname);
                    569:     }
                    570:     $output .= '
                    571: </script>';
                    572:     return $output;
                    573: }
                    574: 
                    575: sub setsec_javascript {
                    576:     my ($sec_element,$formname) = @_;
                    577:     my $setsections = qq|
                    578: function setSect(sectionlist) {
1.629     raeburn   579:     var sectionsArray = new Array();
                    580:     if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
                    581:         sectionsArray = sectionlist.split(",");
                    582:     }
1.468     raeburn   583:     var numSections = sectionsArray.length;
                    584:     document.$formname.$sec_element.length = 0;
                    585:     if (numSections == 0) {
                    586:         document.$formname.$sec_element.multiple=false;
                    587:         document.$formname.$sec_element.size=1;
                    588:         document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
                    589:     } else {
                    590:         if (numSections == 1) {
                    591:             document.$formname.$sec_element.multiple=false;
                    592:             document.$formname.$sec_element.size=1;
                    593:             document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
                    594:             document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
                    595:             document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
                    596:         } else {
                    597:             for (var i=0; i<numSections; i++) {
                    598:                 document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
                    599:             }
                    600:             document.$formname.$sec_element.multiple=true
                    601:             if (numSections < 3) {
                    602:                 document.$formname.$sec_element.size=numSections;
                    603:             } else {
                    604:                 document.$formname.$sec_element.size=3;
                    605:             }
                    606:             document.$formname.$sec_element.options[0].selected = false
                    607:         }
                    608:     }
1.91      www       609: }
1.468     raeburn   610: |;
                    611:     return $setsections;
                    612: }
                    613: 
1.91      www       614: 
                    615: sub selectcourse_link {
1.377     raeburn   616:    my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.787     bisitz    617:    return '<span class="LC_nobreak">'
                    618:          ."<a href='"
                    619:          .'javascript:opencrsbrowser("'.$form.'","'.$unameele
                    620:          .'","'.$udomele.'","'.$desc.'","'.$extra_element
                    621:          .'","'.$multflag.'","'.$selecttype.'");'
                    622:          ."'>".&mt('Select Course').'</a>'
                    623:          .'</span>';
1.74      www       624: }
1.42      matthew   625: 
1.653     raeburn   626: sub selectauthor_link {
                    627:    my ($form,$udom)=@_;
                    628:    return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
                    629:           &mt('Select Author').'</a>';
                    630: }
                    631: 
1.273     raeburn   632: sub check_uncheck_jscript {
                    633:     my $jscript = <<"ENDSCRT";
                    634: function checkAll(field) {
                    635:     if (field.length > 0) {
                    636:         for (i = 0; i < field.length; i++) {
                    637:             field[i].checked = true ;
                    638:         }
                    639:     } else {
                    640:         field.checked = true
                    641:     }
                    642: }
                    643:  
                    644: function uncheckAll(field) {
                    645:     if (field.length > 0) {
                    646:         for (i = 0; i < field.length; i++) {
                    647:             field[i].checked = false ;
1.543     albertel  648:         }
                    649:     } else {
1.273     raeburn   650:         field.checked = false ;
                    651:     }
                    652: }
                    653: ENDSCRT
                    654:     return $jscript;
                    655: }
                    656: 
1.656     www       657: sub select_timezone {
1.659     raeburn   658:    my ($name,$selected,$onchange,$includeempty)=@_;
                    659:    my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    660:    if ($includeempty) {
                    661:        $output .= '<option value=""';
                    662:        if (($selected eq '') || ($selected eq 'local')) {
                    663:            $output .= ' selected="selected" ';
                    664:        }
                    665:        $output .= '> </option>';
                    666:    }
1.657     raeburn   667:    my @timezones = DateTime::TimeZone->all_names;
                    668:    foreach my $tzone (@timezones) {
                    669:        $output.= '<option value="'.$tzone.'"';
                    670:        if ($tzone eq $selected) {
                    671:            $output.=' selected="selected"';
                    672:        }
                    673:        $output.=">$tzone</option>\n";
1.656     www       674:    }
                    675:    $output.="</select>";
                    676:    return $output;
                    677: }
1.273     raeburn   678: 
1.687     raeburn   679: sub select_datelocale {
                    680:     my ($name,$selected,$onchange,$includeempty)=@_;
                    681:     my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    682:     if ($includeempty) {
                    683:         $output .= '<option value=""';
                    684:         if ($selected eq '') {
                    685:             $output .= ' selected="selected" ';
                    686:         }
                    687:         $output .= '> </option>';
                    688:     }
                    689:     my (@possibles,%locale_names);
                    690:     my @locales = DateTime::Locale::Catalog::Locales;
                    691:     foreach my $locale (@locales) {
                    692:         if (ref($locale) eq 'HASH') {
                    693:             my $id = $locale->{'id'};
                    694:             if ($id ne '') {
                    695:                 my $en_terr = $locale->{'en_territory'};
                    696:                 my $native_terr = $locale->{'native_territory'};
1.695     raeburn   697:                 my @languages = &Apache::lonlocal::preferred_languages();
1.687     raeburn   698:                 if (grep(/^en$/,@languages) || !@languages) {
                    699:                     if ($en_terr ne '') {
                    700:                         $locale_names{$id} = '('.$en_terr.')';
                    701:                     } elsif ($native_terr ne '') {
                    702:                         $locale_names{$id} = $native_terr;
                    703:                     }
                    704:                 } else {
                    705:                     if ($native_terr ne '') {
                    706:                         $locale_names{$id} = $native_terr.' ';
                    707:                     } elsif ($en_terr ne '') {
                    708:                         $locale_names{$id} = '('.$en_terr.')';
                    709:                     }
                    710:                 }
                    711:                 push (@possibles,$id);
                    712:             }
                    713:         }
                    714:     }
                    715:     foreach my $item (sort(@possibles)) {
                    716:         $output.= '<option value="'.$item.'"';
                    717:         if ($item eq $selected) {
                    718:             $output.=' selected="selected"';
                    719:         }
                    720:         $output.=">$item";
                    721:         if ($locale_names{$item} ne '') {
                    722:             $output.="  $locale_names{$item}</option>\n";
                    723:         }
                    724:         $output.="</option>\n";
                    725:     }
                    726:     $output.="</select>";
                    727:     return $output;
                    728: }
                    729: 
1.792     raeburn   730: sub select_language {
                    731:     my ($name,$selected,$includeempty) = @_;
                    732:     my %langchoices;
                    733:     if ($includeempty) {
                    734:         %langchoices = ('' => 'No language preference');
                    735:     }
                    736:     foreach my $id (&languageids()) {
                    737:         my $code = &supportedlanguagecode($id);
                    738:         if ($code) {
                    739:             $langchoices{$code} = &plainlanguagedescription($id);
                    740:         }
                    741:     }
                    742:     return &select_form($selected,$name,%langchoices);
                    743: }
                    744: 
1.42      matthew   745: =pod
1.36      matthew   746: 
1.648     raeburn   747: =item * &linked_select_forms(...)
1.36      matthew   748: 
                    749: linked_select_forms returns a string containing a <script></script> block
                    750: and html for two <select> menus.  The select menus will be linked in that
                    751: changing the value of the first menu will result in new values being placed
                    752: in the second menu.  The values in the select menu will appear in alphabetical
1.609     raeburn   753: order unless a defined order is provided.
1.36      matthew   754: 
                    755: linked_select_forms takes the following ordered inputs:
                    756: 
                    757: =over 4
                    758: 
1.112     bowersj2  759: =item * $formname, the name of the <form> tag
1.36      matthew   760: 
1.112     bowersj2  761: =item * $middletext, the text which appears between the <select> tags
1.36      matthew   762: 
1.112     bowersj2  763: =item * $firstdefault, the default value for the first menu
1.36      matthew   764: 
1.112     bowersj2  765: =item * $firstselectname, the name of the first <select> tag
1.36      matthew   766: 
1.112     bowersj2  767: =item * $secondselectname, the name of the second <select> tag
1.36      matthew   768: 
1.112     bowersj2  769: =item * $hashref, a reference to a hash containing the data for the menus.
1.36      matthew   770: 
1.609     raeburn   771: =item * $menuorder, the order of values in the first menu
                    772: 
1.41      ng        773: =back 
                    774: 
1.36      matthew   775: Below is an example of such a hash.  Only the 'text', 'default', and 
                    776: 'select2' keys must appear as stated.  keys(%menu) are the possible 
                    777: values for the first select menu.  The text that coincides with the 
1.41      ng        778: first menu value is given in $menu{$choice1}->{'text'}.  The values 
1.36      matthew   779: and text for the second menu are given in the hash pointed to by 
                    780: $menu{$choice1}->{'select2'}.  
                    781: 
1.112     bowersj2  782:  my %menu = ( A1 => { text =>"Choice A1" ,
                    783:                        default => "B3",
                    784:                        select2 => { 
                    785:                            B1 => "Choice B1",
                    786:                            B2 => "Choice B2",
                    787:                            B3 => "Choice B3",
                    788:                            B4 => "Choice B4"
1.609     raeburn   789:                            },
                    790:                        order => ['B4','B3','B1','B2'],
1.112     bowersj2  791:                    },
                    792:                A2 => { text =>"Choice A2" ,
                    793:                        default => "C2",
                    794:                        select2 => { 
                    795:                            C1 => "Choice C1",
                    796:                            C2 => "Choice C2",
                    797:                            C3 => "Choice C3"
1.609     raeburn   798:                            },
                    799:                        order => ['C2','C1','C3'],
1.112     bowersj2  800:                    },
                    801:                A3 => { text =>"Choice A3" ,
                    802:                        default => "D6",
                    803:                        select2 => { 
                    804:                            D1 => "Choice D1",
                    805:                            D2 => "Choice D2",
                    806:                            D3 => "Choice D3",
                    807:                            D4 => "Choice D4",
                    808:                            D5 => "Choice D5",
                    809:                            D6 => "Choice D6",
                    810:                            D7 => "Choice D7"
1.609     raeburn   811:                            },
                    812:                        order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112     bowersj2  813:                    }
                    814:                );
1.36      matthew   815: 
                    816: =cut
                    817: 
                    818: sub linked_select_forms {
                    819:     my ($formname,
                    820:         $middletext,
                    821:         $firstdefault,
                    822:         $firstselectname,
                    823:         $secondselectname, 
1.609     raeburn   824:         $hashref,
                    825:         $menuorder,
1.36      matthew   826:         ) = @_;
                    827:     my $second = "document.$formname.$secondselectname";
                    828:     my $first = "document.$formname.$firstselectname";
                    829:     # output the javascript to do the changing
                    830:     my $result = '';
1.776     bisitz    831:     $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.36      matthew   832:     $result.="var select2data = new Object();\n";
                    833:     $" = '","';
                    834:     my $debug = '';
                    835:     foreach my $s1 (sort(keys(%$hashref))) {
                    836:         $result.="select2data.d_$s1 = new Object();\n";        
                    837:         $result.="select2data.d_$s1.def = new String('".
                    838:             $hashref->{$s1}->{'default'}."');\n";
1.609     raeburn   839:         $result.="select2data.d_$s1.values = new Array(";
1.36      matthew   840:         my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609     raeburn   841:         if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
                    842:             @s2values = @{$hashref->{$s1}->{'order'}};
                    843:         }
1.36      matthew   844:         $result.="\"@s2values\");\n";
                    845:         $result.="select2data.d_$s1.texts = new Array(";        
                    846:         my @s2texts;
                    847:         foreach my $value (@s2values) {
                    848:             push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
                    849:         }
                    850:         $result.="\"@s2texts\");\n";
                    851:     }
                    852:     $"=' ';
                    853:     $result.= <<"END";
                    854: 
                    855: function select1_changed() {
                    856:     // Determine new choice
                    857:     var newvalue = "d_" + $first.value;
                    858:     // update select2
                    859:     var values     = select2data[newvalue].values;
                    860:     var texts      = select2data[newvalue].texts;
                    861:     var select2def = select2data[newvalue].def;
                    862:     var i;
                    863:     // out with the old
                    864:     for (i = 0; i < $second.options.length; i++) {
                    865:         $second.options[i] = null;
                    866:     }
                    867:     // in with the nuclear
                    868:     for (i=0;i<values.length; i++) {
                    869:         $second.options[i] = new Option(values[i]);
1.143     matthew   870:         $second.options[i].value = values[i];
1.36      matthew   871:         $second.options[i].text = texts[i];
                    872:         if (values[i] == select2def) {
                    873:             $second.options[i].selected = true;
                    874:         }
                    875:     }
                    876: }
                    877: </script>
                    878: END
                    879:     # output the initial values for the selection lists
                    880:     $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609     raeburn   881:     my @order = sort(keys(%{$hashref}));
                    882:     if (ref($menuorder) eq 'ARRAY') {
                    883:         @order = @{$menuorder};
                    884:     }
                    885:     foreach my $value (@order) {
1.36      matthew   886:         $result.="    <option value=\"$value\" ";
1.253     albertel  887:         $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119     www       888:         $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36      matthew   889:     }
                    890:     $result .= "</select>\n";
                    891:     my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
                    892:     $result .= $middletext;
                    893:     $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
                    894:     my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609     raeburn   895:     
                    896:     my @secondorder = sort(keys(%select2));
                    897:     if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
                    898:         @secondorder = @{$hashref->{$firstdefault}->{'order'}};
                    899:     }
                    900:     foreach my $value (@secondorder) {
1.36      matthew   901:         $result.="    <option value=\"$value\" ";        
1.253     albertel  902:         $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119     www       903:         $result.=">".&mt($select2{$value})."</option>\n";
1.36      matthew   904:     }
                    905:     $result .= "</select>\n";
                    906:     #    return $debug;
                    907:     return $result;
                    908: }   #  end of sub linked_select_forms {
                    909: 
1.45      matthew   910: =pod
1.44      bowersj2  911: 
1.648     raeburn   912: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44      bowersj2  913: 
1.112     bowersj2  914: Returns a string corresponding to an HTML link to the given help
                    915: $topic, where $topic corresponds to the name of a .tex file in
                    916: /home/httpd/html/adm/help/tex, with underscores replaced by
                    917: spaces. 
                    918: 
                    919: $text will optionally be linked to the same topic, allowing you to
                    920: link text in addition to the graphic. If you do not want to link
                    921: text, but wish to specify one of the later parameters, pass an
                    922: empty string. 
                    923: 
                    924: $stayOnPage is a value that will be interpreted as a boolean. If true,
                    925: the link will not open a new window. If false, the link will open
                    926: a new window using Javascript. (Default is false.) 
                    927: 
                    928: $width and $height are optional numerical parameters that will
                    929: override the width and height of the popped up window, which may
                    930: be useful for certain help topics with big pictures included. 
1.44      bowersj2  931: 
                    932: =cut
                    933: 
                    934: sub help_open_topic {
1.48      bowersj2  935:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
                    936:     $text = "" if (not defined $text);
1.44      bowersj2  937:     $stayOnPage = 0 if (not defined $stayOnPage);
                    938:     $width = 350 if (not defined $width);
                    939:     $height = 400 if (not defined $height);
                    940:     my $filename = $topic;
                    941:     $filename =~ s/ /_/g;
                    942: 
1.48      bowersj2  943:     my $template = "";
                    944:     my $link;
1.572     banghart  945:     
1.159     www       946:     $topic=~s/\W/\_/g;
1.44      bowersj2  947: 
1.572     banghart  948:     if (!$stayOnPage) {
1.72      bowersj2  949: 	$link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1.572     banghart  950:     } else {
1.48      bowersj2  951: 	$link = "/adm/help/${filename}.hlp";
                    952:     }
                    953: 
                    954:     # Add the text
1.755     neumanie  955:     if ($text ne "") {	
1.763     bisitz    956: 	$template.='<span class="LC_help_open_topic">'
                    957:                   .'<a target="_top" href="'.$link.'">'
                    958:                   .$text.'</a>';
1.48      bowersj2  959:     }
                    960: 
1.763     bisitz    961:     # (Always) Add the graphic
1.179     matthew   962:     my $title = &mt('Online Help');
1.667     raeburn   963:     my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.763     bisitz    964:     $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
                    965:               .'<img src="'.$helpicon.'" border="0"'
                    966:               .' alt="'.&mt('Help: [_1]',$topic).'"'
1.783     amueller  967:               .' title="'.$title.'"' 
1.763     bisitz    968:               .' /></a>';
                    969:     if ($text ne "") {	
                    970:         $template.='</span>';
                    971:     }
1.44      bowersj2  972:     return $template;
                    973: 
1.106     bowersj2  974: }
                    975: 
                    976: # This is a quicky function for Latex cheatsheet editing, since it 
                    977: # appears in at least four places
                    978: sub helpLatexCheatsheet {
1.732     raeburn   979:     my ($topic,$text,$not_author) = @_;
                    980:     my $out;
1.106     bowersj2  981:     my $addOther = '';
1.732     raeburn   982:     if ($topic) {
1.763     bisitz    983: 	$addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
                    984: 							       undef, undef, 600).
                    985: 								   '</span> ';
                    986:     }
                    987:     $out = '<span>' # Start cheatsheet
                    988: 	  .$addOther
                    989:           .'<span>'
                    990: 	  .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
                    991: 					       undef,undef,600)
                    992: 	  .'</span> <span>'
                    993: 	  .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
                    994: 					       undef,undef,600)
                    995: 	  .'</span>';
1.732     raeburn   996:     unless ($not_author) {
1.763     bisitz    997:         $out .= ' <span>'
                    998: 	       .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
                    999: 	                                            undef,undef,600)
                   1000: 	       .'</span>';
1.732     raeburn  1001:     }
1.763     bisitz   1002:     $out .= '</span>'; # End cheatsheet
1.732     raeburn  1003:     return $out;
1.172     www      1004: }
                   1005: 
1.430     albertel 1006: sub general_help {
                   1007:     my $helptopic='Student_Intro';
                   1008:     if ($env{'request.role'}=~/^(ca|au)/) {
                   1009: 	$helptopic='Authoring_Intro';
                   1010:     } elsif ($env{'request.role'}=~/^cc/) {
                   1011: 	$helptopic='Course_Coordination_Intro';
1.672     raeburn  1012:     } elsif ($env{'request.role'}=~/^dc/) {
                   1013:         $helptopic='Domain_Coordination_Intro';
1.430     albertel 1014:     }
                   1015:     return $helptopic;
                   1016: }
                   1017: 
                   1018: sub update_help_link {
                   1019:     my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
                   1020:     my $origurl = $ENV{'REQUEST_URI'};
                   1021:     $origurl=~s|^/~|/priv/|;
                   1022:     my $timestamp = time;
                   1023:     foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
                   1024:         $$datum = &escape($$datum);
                   1025:     }
                   1026: 
                   1027:     my $banner_link = "/adm/helpmenu?page=banner&amp;topic=$topic&amp;component_help=$component_help&amp;faq=$faq&amp;bug=$bug&amp;origurl=$origurl&amp;stamp=$timestamp&amp;stayonpage=$stayOnPage";
                   1028:     my $output .= <<"ENDOUTPUT";
                   1029: <script type="text/javascript">
                   1030: banner_link = '$banner_link';
                   1031: </script>
                   1032: ENDOUTPUT
                   1033:     return $output;
                   1034: }
                   1035: 
                   1036: # now just updates the help link and generates a blue icon
1.193     raeburn  1037: sub help_open_menu {
1.430     albertel 1038:     my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text) 
1.552     banghart 1039: 	= @_;    
1.430     albertel 1040:     $stayOnPage = 0 if (not defined $stayOnPage);
1.572     banghart 1041:     # only use pop-up help (stayOnPage == 0)
1.552     banghart 1042:     # if environment.remote is on (using remote control UI)
1.798     tempelho 1043:     if ($env{'environment.remote'} eq 'off' ) {
1.552     banghart 1044:         $stayOnPage=1;
1.430     albertel 1045:     }
                   1046:     my $output;
                   1047:     if ($component_help) {
                   1048: 	if (!$text) {
                   1049: 	    $output=&help_open_topic($component_help,undef,$stayOnPage,
                   1050: 				       $width,$height);
                   1051: 	} else {
                   1052: 	    my $help_text;
                   1053: 	    $help_text=&unescape($topic);
                   1054: 	    $output='<table><tr><td>'.
                   1055: 		&help_open_topic($component_help,$help_text,$stayOnPage,
                   1056: 				 $width,$height).'</td></tr></table>';
                   1057: 	}
                   1058:     }
                   1059:     my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
                   1060:     return $output.$banner_link;
                   1061: }
                   1062: 
                   1063: sub top_nav_help {
                   1064:     my ($text) = @_;
1.436     albertel 1065:     $text = &mt($text);
1.572     banghart 1066:     my $stay_on_page = 
1.798     tempelho 1067: 	($env{'environment.remote'} eq 'off' );
1.572     banghart 1068:     my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436     albertel 1069: 	                     : "javascript:helpMenu('open')";
1.572     banghart 1070:     my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436     albertel 1071: 
1.201     raeburn  1072:     my $title = &mt('Get help');
1.436     albertel 1073: 
                   1074:     return <<"END";
                   1075: $banner_link
                   1076:  <a href="$link" title="$title">$text</a>
                   1077: END
                   1078: }
                   1079: 
                   1080: sub help_menu_js {
                   1081:     my ($text) = @_;
                   1082: 
                   1083:     my $stayOnPage = 
1.798     tempelho 1084: 	($env{'environment.remote'} eq 'off' );
1.436     albertel 1085: 
                   1086:     my $width = 620;
                   1087:     my $height = 600;
1.430     albertel 1088:     my $helptopic=&general_help();
                   1089:     my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261     albertel 1090:     my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331     albertel 1091:     my $start_page =
                   1092:         &Apache::loncommon::start_page('Help Menu', undef,
                   1093: 				       {'frameset'    => 1,
                   1094: 					'js_ready'    => 1,
                   1095: 					'add_entries' => {
                   1096: 					    'border' => '0',
1.579     raeburn  1097: 					    'rows'   => "110,*",},});
1.331     albertel 1098:     my $end_page =
                   1099:         &Apache::loncommon::end_page({'frameset' => 1,
                   1100: 				      'js_ready' => 1,});
                   1101: 
1.436     albertel 1102:     my $template .= <<"ENDTEMPLATE";
                   1103: <script type="text/javascript">
1.253     albertel 1104: // <!-- BEGIN LON-CAPA Internal
                   1105: // <![CDATA[
1.430     albertel 1106: var banner_link = '';
1.243     raeburn  1107: function helpMenu(target) {
                   1108:     var caller = this;
                   1109:     if (target == 'open') {
                   1110:         var newWindow = null;
                   1111:         try {
1.262     albertel 1112:             newWindow =  window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243     raeburn  1113:         }
                   1114:         catch(error) {
                   1115:             writeHelp(caller);
                   1116:             return;
                   1117:         }
                   1118:         if (newWindow) {
                   1119:             caller = newWindow;
                   1120:         }
1.193     raeburn  1121:     }
1.243     raeburn  1122:     writeHelp(caller);
                   1123:     return;
                   1124: }
                   1125: function writeHelp(caller) {
1.430     albertel 1126:     caller.document.writeln('$start_page<frame name="bannerframe"  src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243     raeburn  1127:     caller.document.close()
                   1128:     caller.focus()
1.193     raeburn  1129: }
1.253     albertel 1130: // ]]>
1.219     albertel 1131: // END LON-CAPA Internal -->
1.436     albertel 1132: </script>
1.193     raeburn  1133: ENDTEMPLATE
                   1134:     return $template;
                   1135: }
                   1136: 
1.172     www      1137: sub help_open_bug {
                   1138:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1139:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1140:     unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
                   1141:     $text = "" if (not defined $text);
                   1142:     $stayOnPage = 0 if (not defined $stayOnPage);
1.798     tempelho 1143:     if ($env{'environment.remote'} eq 'off' ) {
1.172     www      1144: 	$stayOnPage=1;
                   1145:     }
1.184     albertel 1146:     $width = 600 if (not defined $width);
                   1147:     $height = 600 if (not defined $height);
1.172     www      1148: 
                   1149:     $topic=~s/\W+/\+/g;
                   1150:     my $link='';
                   1151:     my $template='';
1.379     albertel 1152:     my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&amp;bug_file_loc='.
                   1153: 	&escape($ENV{'REQUEST_URI'}).'&amp;component='.$topic;
1.172     www      1154:     if (!$stayOnPage)
                   1155:     {
                   1156: 	$link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1157:     }
                   1158:     else
                   1159:     {
                   1160: 	$link = $url;
                   1161:     }
                   1162:     # Add the text
                   1163:     if ($text ne "")
                   1164:     {
                   1165: 	$template .= 
                   1166:   "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1167:   "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172     www      1168:     }
                   1169: 
                   1170:     # Add the graphic
1.179     matthew  1171:     my $title = &mt('Report a Bug');
1.215     albertel 1172:     my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172     www      1173:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1174:  <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172     www      1175: ENDTEMPLATE
                   1176:     if ($text ne '') { $template.='</td></tr></table>' };
                   1177:     return $template;
                   1178: 
                   1179: }
                   1180: 
                   1181: sub help_open_faq {
                   1182:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1183:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1184:     unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
                   1185:     $text = "" if (not defined $text);
                   1186:     $stayOnPage = 0 if (not defined $stayOnPage);
1.798     tempelho 1187:     if ($env{'environment.remote'} eq 'off' ) {
1.172     www      1188: 	$stayOnPage=1;
                   1189:     }
                   1190:     $width = 350 if (not defined $width);
                   1191:     $height = 400 if (not defined $height);
                   1192: 
                   1193:     $topic=~s/\W+/\+/g;
                   1194:     my $link='';
                   1195:     my $template='';
                   1196:     my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
                   1197:     if (!$stayOnPage)
                   1198:     {
                   1199: 	$link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1200:     }
                   1201:     else
                   1202:     {
                   1203: 	$link = $url;
                   1204:     }
                   1205: 
                   1206:     # Add the text
                   1207:     if ($text ne "")
                   1208:     {
                   1209: 	$template .= 
1.173     www      1210:   "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1211:   "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172     www      1212:     }
                   1213: 
                   1214:     # Add the graphic
1.179     matthew  1215:     my $title = &mt('View the FAQ');
1.215     albertel 1216:     my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172     www      1217:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1218:  <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172     www      1219: ENDTEMPLATE
                   1220:     if ($text ne '') { $template.='</td></tr></table>' };
                   1221:     return $template;
                   1222: 
1.44      bowersj2 1223: }
1.37      matthew  1224: 
1.180     matthew  1225: ###############################################################
                   1226: ###############################################################
                   1227: 
1.45      matthew  1228: =pod
                   1229: 
1.648     raeburn  1230: =item * &change_content_javascript():
1.256     matthew  1231: 
                   1232: This and the next function allow you to create small sections of an
                   1233: otherwise static HTML page that you can update on the fly with
                   1234: Javascript, even in Netscape 4.
                   1235: 
                   1236: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
                   1237: must be written to the HTML page once. It will prove the Javascript
                   1238: function "change(name, content)". Calling the change function with the
                   1239: name of the section 
                   1240: you want to update, matching the name passed to C<changable_area>, and
                   1241: the new content you want to put in there, will put the content into
                   1242: that area.
                   1243: 
                   1244: B<Note>: Netscape 4 only reserves enough space for the changable area
                   1245: to contain room for the original contents. You need to "make space"
                   1246: for whatever changes you wish to make, and be B<sure> to check your
                   1247: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
                   1248: it's adequate for updating a one-line status display, but little more.
                   1249: This script will set the space to 100% width, so you only need to
                   1250: worry about height in Netscape 4.
                   1251: 
                   1252: Modern browsers are much less limiting, and if you can commit to the
                   1253: user not using Netscape 4, this feature may be used freely with
                   1254: pretty much any HTML.
                   1255: 
                   1256: =cut
                   1257: 
                   1258: sub change_content_javascript {
                   1259:     # If we're on Netscape 4, we need to use Layer-based code
1.258     albertel 1260:     if ($env{'browser.type'} eq 'netscape' &&
                   1261: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1262: 	return (<<NETSCAPE4);
                   1263: 	function change(name, content) {
                   1264: 	    doc = document.layers[name+"___escape"].layers[0].document;
                   1265: 	    doc.open();
                   1266: 	    doc.write(content);
                   1267: 	    doc.close();
                   1268: 	}
                   1269: NETSCAPE4
                   1270:     } else {
                   1271: 	# Otherwise, we need to use semi-standards-compliant code
                   1272: 	# (technically, "innerHTML" isn't standard but the equivalent
                   1273: 	# is really scary, and every useful browser supports it
                   1274: 	return (<<DOMBASED);
                   1275: 	function change(name, content) {
                   1276: 	    element = document.getElementById(name);
                   1277: 	    element.innerHTML = content;
                   1278: 	}
                   1279: DOMBASED
                   1280:     }
                   1281: }
                   1282: 
                   1283: =pod
                   1284: 
1.648     raeburn  1285: =item * &changable_area($name,$origContent):
1.256     matthew  1286: 
                   1287: This provides a "changable area" that can be modified on the fly via
                   1288: the Javascript code provided in C<change_content_javascript>. $name is
                   1289: the name you will use to reference the area later; do not repeat the
                   1290: same name on a given HTML page more then once. $origContent is what
                   1291: the area will originally contain, which can be left blank.
                   1292: 
                   1293: =cut
                   1294: 
                   1295: sub changable_area {
                   1296:     my ($name, $origContent) = @_;
                   1297: 
1.258     albertel 1298:     if ($env{'browser.type'} eq 'netscape' &&
                   1299: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1300: 	# If this is netscape 4, we need to use the Layer tag
                   1301: 	return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
                   1302:     } else {
                   1303: 	return "<span id='$name'>$origContent</span>";
                   1304:     }
                   1305: }
                   1306: 
                   1307: =pod
                   1308: 
1.648     raeburn  1309: =item * &viewport_geometry_js 
1.590     raeburn  1310: 
                   1311: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
                   1312: 
                   1313: =cut
                   1314: 
                   1315: 
                   1316: sub viewport_geometry_js { 
                   1317:     return <<"GEOMETRY";
                   1318: var Geometry = {};
                   1319: function init_geometry() {
                   1320:     if (Geometry.init) { return };
                   1321:     Geometry.init=1;
                   1322:     if (window.innerHeight) {
                   1323:         Geometry.getViewportHeight   = function() { return window.innerHeight; };
                   1324:         Geometry.getViewportWidth   = function() { return window.innerWidth; };
                   1325:         Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
                   1326:         Geometry.getVerticalScroll   = function() { return window.pageYOffset; };
                   1327:     }
                   1328:     else if (document.documentElement && document.documentElement.clientHeight) {
                   1329:         Geometry.getViewportHeight =
                   1330:             function() { return document.documentElement.clientHeight; };
                   1331:         Geometry.getViewportWidth =
                   1332:             function() { return document.documentElement.clientWidth; };
                   1333: 
                   1334:         Geometry.getHorizontalScroll =
                   1335:             function() { return document.documentElement.scrollLeft; };
                   1336:         Geometry.getVerticalScroll =
                   1337:             function() { return document.documentElement.scrollTop; };
                   1338:     }
                   1339:     else if (document.body.clientHeight) {
                   1340:         Geometry.getViewportHeight =
                   1341:             function() { return document.body.clientHeight; };
                   1342:         Geometry.getViewportWidth =
                   1343:             function() { return document.body.clientWidth; };
                   1344:         Geometry.getHorizontalScroll =
                   1345:             function() { return document.body.scrollLeft; };
                   1346:         Geometry.getVerticalScroll =
                   1347:             function() { return document.body.scrollTop; };
                   1348:     }
                   1349: }
                   1350: 
                   1351: GEOMETRY
                   1352: }
                   1353: 
                   1354: =pod
                   1355: 
1.648     raeburn  1356: =item * &viewport_size_js()
1.590     raeburn  1357: 
                   1358: Provides a javascript function to set values of two form elements - width and height (elements are passed in as arguments to the javascript function) to the dimensions of the user's browser window. 
                   1359: 
                   1360: =cut
                   1361: 
                   1362: sub viewport_size_js {
                   1363:     my $geometry = &viewport_geometry_js();
                   1364:     return <<"DIMS";
                   1365: 
                   1366: $geometry
                   1367: 
                   1368: function getViewportDims(width,height) {
                   1369:     init_geometry();
                   1370:     width.value = Geometry.getViewportWidth();
                   1371:     height.value = Geometry.getViewportHeight();
                   1372:     return;
                   1373: }
                   1374: 
                   1375: DIMS
                   1376: }
                   1377: 
                   1378: =pod
                   1379: 
1.648     raeburn  1380: =item * &resize_textarea_js()
1.565     albertel 1381: 
                   1382: emits the needed javascript to resize a textarea to be as big as possible
                   1383: 
                   1384: creates a function resize_textrea that takes two IDs first should be
                   1385: the id of the element to resize, second should be the id of a div that
                   1386: surrounds everything that comes after the textarea, this routine needs
                   1387: to be attached to the <body> for the onload and onresize events.
                   1388: 
1.648     raeburn  1389: =back
1.565     albertel 1390: 
                   1391: =cut
                   1392: 
                   1393: sub resize_textarea_js {
1.590     raeburn  1394:     my $geometry = &viewport_geometry_js();
1.565     albertel 1395:     return <<"RESIZE";
                   1396:     <script type="text/javascript">
1.590     raeburn  1397: $geometry
1.565     albertel 1398: 
1.588     albertel 1399: function getX(element) {
                   1400:     var x = 0;
                   1401:     while (element) {
                   1402: 	x += element.offsetLeft;
                   1403: 	element = element.offsetParent;
                   1404:     }
                   1405:     return x;
                   1406: }
                   1407: function getY(element) {
                   1408:     var y = 0;
                   1409:     while (element) {
                   1410: 	y += element.offsetTop;
                   1411: 	element = element.offsetParent;
                   1412:     }
                   1413:     return y;
                   1414: }
                   1415: 
                   1416: 
1.565     albertel 1417: function resize_textarea(textarea_id,bottom_id) {
                   1418:     init_geometry();
                   1419:     var textarea        = document.getElementById(textarea_id);
                   1420:     //alert(textarea);
                   1421: 
1.588     albertel 1422:     var textarea_top    = getY(textarea);
1.565     albertel 1423:     var textarea_height = textarea.offsetHeight;
                   1424:     var bottom          = document.getElementById(bottom_id);
1.588     albertel 1425:     var bottom_top      = getY(bottom);
1.565     albertel 1426:     var bottom_height   = bottom.offsetHeight;
                   1427:     var window_height   = Geometry.getViewportHeight();
1.588     albertel 1428:     var fudge           = 23;
1.565     albertel 1429:     var new_height      = window_height-fudge-textarea_top-bottom_height;
                   1430:     if (new_height < 300) {
                   1431: 	new_height = 300;
                   1432:     }
                   1433:     textarea.style.height=new_height+'px';
                   1434: }
                   1435: </script>
                   1436: RESIZE
                   1437: 
                   1438: }
                   1439: 
                   1440: =pod
                   1441: 
1.256     matthew  1442: =head1 Excel and CSV file utility routines
                   1443: 
                   1444: =over 4
                   1445: 
                   1446: =cut
                   1447: 
                   1448: ###############################################################
                   1449: ###############################################################
                   1450: 
                   1451: =pod
                   1452: 
1.648     raeburn  1453: =item * &csv_translate($text) 
1.37      matthew  1454: 
1.185     www      1455: Translate $text to allow it to be output as a 'comma separated values' 
1.37      matthew  1456: format.
                   1457: 
                   1458: =cut
                   1459: 
1.180     matthew  1460: ###############################################################
                   1461: ###############################################################
1.37      matthew  1462: sub csv_translate {
                   1463:     my $text = shift;
                   1464:     $text =~ s/\"/\"\"/g;
1.209     albertel 1465:     $text =~ s/\n/ /g;
1.37      matthew  1466:     return $text;
                   1467: }
1.180     matthew  1468: 
                   1469: ###############################################################
                   1470: ###############################################################
                   1471: 
                   1472: =pod
                   1473: 
1.648     raeburn  1474: =item * &define_excel_formats()
1.180     matthew  1475: 
                   1476: Define some commonly used Excel cell formats.
                   1477: 
                   1478: Currently supported formats:
                   1479: 
                   1480: =over 4
                   1481: 
                   1482: =item header
                   1483: 
                   1484: =item bold
                   1485: 
                   1486: =item h1
                   1487: 
                   1488: =item h2
                   1489: 
                   1490: =item h3
                   1491: 
1.256     matthew  1492: =item h4
                   1493: 
                   1494: =item i
                   1495: 
1.180     matthew  1496: =item date
                   1497: 
                   1498: =back
                   1499: 
                   1500: Inputs: $workbook
                   1501: 
                   1502: Returns: $format, a hash reference.
                   1503: 
                   1504: =cut
                   1505: 
                   1506: ###############################################################
                   1507: ###############################################################
                   1508: sub define_excel_formats {
                   1509:     my ($workbook) = @_;
                   1510:     my $format;
                   1511:     $format->{'header'} = $workbook->add_format(bold      => 1, 
                   1512:                                                 bottom    => 1,
                   1513:                                                 align     => 'center');
                   1514:     $format->{'bold'} = $workbook->add_format(bold=>1);
                   1515:     $format->{'h1'}   = $workbook->add_format(bold=>1, size=>18);
                   1516:     $format->{'h2'}   = $workbook->add_format(bold=>1, size=>16);
                   1517:     $format->{'h3'}   = $workbook->add_format(bold=>1, size=>14);
1.255     matthew  1518:     $format->{'h4'}   = $workbook->add_format(bold=>1, size=>12);
1.246     matthew  1519:     $format->{'i'}    = $workbook->add_format(italic=>1);
1.180     matthew  1520:     $format->{'date'} = $workbook->add_format(num_format=>
1.207     matthew  1521:                                             'mm/dd/yyyy hh:mm:ss');
1.180     matthew  1522:     return $format;
                   1523: }
                   1524: 
                   1525: ###############################################################
                   1526: ###############################################################
1.113     bowersj2 1527: 
                   1528: =pod
                   1529: 
1.648     raeburn  1530: =item * &create_workbook()
1.255     matthew  1531: 
                   1532: Create an Excel worksheet.  If it fails, output message on the
                   1533: request object and return undefs.
                   1534: 
                   1535: Inputs: Apache request object
                   1536: 
                   1537: Returns (undef) on failure, 
                   1538:     Excel worksheet object, scalar with filename, and formats 
                   1539:     from &Apache::loncommon::define_excel_formats on success
                   1540: 
                   1541: =cut
                   1542: 
                   1543: ###############################################################
                   1544: ###############################################################
                   1545: sub create_workbook {
                   1546:     my ($r) = @_;
                   1547:         #
                   1548:     # Create the excel spreadsheet
                   1549:     my $filename = '/prtspool/'.
1.258     albertel 1550:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255     matthew  1551:         time.'_'.rand(1000000000).'.xls';
                   1552:     my $workbook  = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
                   1553:     if (! defined($workbook)) {
                   1554:         $r->log_error("Error creating excel spreadsheet $filename: $!");
                   1555:         $r->print('<p>'.&mt("Unable to create new Excel file.  ".
                   1556:                             "This error has been logged.  ".
                   1557:                             "Please alert your LON-CAPA administrator").
                   1558:                   '</p>');
                   1559:         return (undef);
                   1560:     }
                   1561:     #
                   1562:     $workbook->set_tempdir('/home/httpd/perl/tmp');
                   1563:     #
                   1564:     my $format = &Apache::loncommon::define_excel_formats($workbook);
                   1565:     return ($workbook,$filename,$format);
                   1566: }
                   1567: 
                   1568: ###############################################################
                   1569: ###############################################################
                   1570: 
                   1571: =pod
                   1572: 
1.648     raeburn  1573: =item * &create_text_file()
1.113     bowersj2 1574: 
1.542     raeburn  1575: Create a file to write to and eventually make available to the user.
1.256     matthew  1576: If file creation fails, outputs an error message on the request object and 
                   1577: return undefs.
1.113     bowersj2 1578: 
1.256     matthew  1579: Inputs: Apache request object, and file suffix
1.113     bowersj2 1580: 
1.256     matthew  1581: Returns (undef) on failure, 
                   1582:     Filehandle and filename on success.
1.113     bowersj2 1583: 
                   1584: =cut
                   1585: 
1.256     matthew  1586: ###############################################################
                   1587: ###############################################################
                   1588: sub create_text_file {
                   1589:     my ($r,$suffix) = @_;
                   1590:     if (! defined($suffix)) { $suffix = 'txt'; };
                   1591:     my $fh;
                   1592:     my $filename = '/prtspool/'.
1.258     albertel 1593:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256     matthew  1594:         time.'_'.rand(1000000000).'.'.$suffix;
                   1595:     $fh = Apache::File->new('>/home/httpd'.$filename);
                   1596:     if (! defined($fh)) {
                   1597:         $r->log_error("Couldn't open $filename for output $!");
1.683     bisitz   1598:         $r->print(&mt('Problems occurred in creating the output file. '
                   1599:                      .'This error has been logged. '
                   1600:                      .'Please alert your LON-CAPA administrator.'));
1.113     bowersj2 1601:     }
1.256     matthew  1602:     return ($fh,$filename)
1.113     bowersj2 1603: }
                   1604: 
                   1605: 
1.256     matthew  1606: =pod 
1.113     bowersj2 1607: 
                   1608: =back
                   1609: 
                   1610: =cut
1.37      matthew  1611: 
                   1612: ###############################################################
1.33      matthew  1613: ##        Home server <option> list generating code          ##
                   1614: ###############################################################
1.35      matthew  1615: 
1.169     www      1616: # ------------------------------------------
                   1617: 
                   1618: sub domain_select {
                   1619:     my ($name,$value,$multiple)=@_;
                   1620:     my %domains=map { 
1.514     albertel 1621: 	$_ => $_.' '. &Apache::lonnet::domain($_,'description') 
1.512     albertel 1622:     } &Apache::lonnet::all_domains();
1.169     www      1623:     if ($multiple) {
                   1624: 	$domains{''}=&mt('Any domain');
1.550     albertel 1625: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287     albertel 1626: 	return &multiple_select_form($name,$value,4,\%domains);
1.169     www      1627:     } else {
1.550     albertel 1628: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169     www      1629: 	return &select_form($name,$value,%domains);
                   1630:     }
                   1631: }
                   1632: 
1.282     albertel 1633: #-------------------------------------------
                   1634: 
                   1635: =pod
                   1636: 
1.519     raeburn  1637: =head1 Routines for form select boxes
                   1638: 
                   1639: =over 4
                   1640: 
1.648     raeburn  1641: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282     albertel 1642: 
                   1643: Returns a string containing a <select> element int multiple mode
                   1644: 
                   1645: 
                   1646: Args:
                   1647:   $name - name of the <select> element
1.506     raeburn  1648:   $value - scalar or array ref of values that should already be selected
1.282     albertel 1649:   $size - number of rows long the select element is
1.283     albertel 1650:   $hash - the elements should be 'option' => 'shown text'
1.282     albertel 1651:           (shown text should already have been &mt())
1.506     raeburn  1652:   $order - (optional) array ref of the order to show the elements in
1.283     albertel 1653: 
1.282     albertel 1654: =cut
                   1655: 
                   1656: #-------------------------------------------
1.169     www      1657: sub multiple_select_form {
1.284     albertel 1658:     my ($name,$value,$size,$hash,$order)=@_;
1.169     www      1659:     my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
                   1660:     my $output='';
1.191     matthew  1661:     if (! defined($size)) {
                   1662:         $size = 4;
1.283     albertel 1663:         if (scalar(keys(%$hash))<4) {
                   1664:             $size = scalar(keys(%$hash));
1.191     matthew  1665:         }
                   1666:     }
1.734     bisitz   1667:     $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501     banghart 1668:     my @order;
1.506     raeburn  1669:     if (ref($order) eq 'ARRAY')  {
                   1670:         @order = @{$order};
                   1671:     } else {
                   1672:         @order = sort(keys(%$hash));
1.501     banghart 1673:     }
                   1674:     if (exists($$hash{'select_form_order'})) {
                   1675:         @order = @{$$hash{'select_form_order'}};
                   1676:     }
                   1677:         
1.284     albertel 1678:     foreach my $key (@order) {
1.356     albertel 1679:         $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284     albertel 1680:         $output.='selected="selected" ' if ($selected{$key});
                   1681:         $output.='>'.$hash->{$key}."</option>\n";
1.169     www      1682:     }
                   1683:     $output.="</select>\n";
                   1684:     return $output;
                   1685: }
                   1686: 
1.88      www      1687: #-------------------------------------------
                   1688: 
                   1689: =pod
                   1690: 
1.648     raeburn  1691: =item * &select_form($defdom,$name,%hash)
1.88      www      1692: 
                   1693: Returns a string containing a <select name='$name' size='1'> form to 
                   1694: allow a user to select options from a hash option_name => displayed text.  
                   1695: See lonrights.pm for an example invocation and use.
                   1696: 
                   1697: =cut
                   1698: 
                   1699: #-------------------------------------------
                   1700: sub select_form {
                   1701:     my ($def,$name,%hash) = @_;
                   1702:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128     albertel 1703:     my @keys;
                   1704:     if (exists($hash{'select_form_order'})) {
                   1705: 	@keys=@{$hash{'select_form_order'}};
                   1706:     } else {
                   1707: 	@keys=sort(keys(%hash));
                   1708:     }
1.356     albertel 1709:     foreach my $key (@keys) {
                   1710:         $selectform.=
                   1711: 	    '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
                   1712:             ($key eq $def ? 'selected="selected" ' : '').
                   1713:                 ">".&mt($hash{$key})."</option>\n";
1.88      www      1714:     }
                   1715:     $selectform.="</select>";
                   1716:     return $selectform;
                   1717: }
                   1718: 
1.475     www      1719: # For display filters
                   1720: 
                   1721: sub display_filter {
                   1722:     if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477     www      1723:     if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714     bisitz   1724:     return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475     www      1725: 			       &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
                   1726: 							   (&mt('all'),10,20,50,100,1000,10000))).
1.714     bisitz   1727: 	   '</label></span> <span class="LC_nobreak">'.
1.475     www      1728:            &mt('Filter [_1]',
1.477     www      1729: 	   &select_form($env{'form.displayfilter'},
                   1730: 			'displayfilter',
                   1731: 			('currentfolder' => 'Current folder/page',
                   1732: 			 'containing' => 'Containing phrase',
                   1733: 			 'none' => 'None'))).
1.714     bisitz   1734: 			 '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475     www      1735: }
                   1736: 
1.167     www      1737: sub gradeleveldescription {
                   1738:     my $gradelevel=shift;
                   1739:     my %gradelevels=(0 => 'Not specified',
                   1740: 		     1 => 'Grade 1',
                   1741: 		     2 => 'Grade 2',
                   1742: 		     3 => 'Grade 3',
                   1743: 		     4 => 'Grade 4',
                   1744: 		     5 => 'Grade 5',
                   1745: 		     6 => 'Grade 6',
                   1746: 		     7 => 'Grade 7',
                   1747: 		     8 => 'Grade 8',
                   1748: 		     9 => 'Grade 9',
                   1749: 		     10 => 'Grade 10',
                   1750: 		     11 => 'Grade 11',
                   1751: 		     12 => 'Grade 12',
                   1752: 		     13 => 'Grade 13',
                   1753: 		     14 => '100 Level',
                   1754: 		     15 => '200 Level',
                   1755: 		     16 => '300 Level',
                   1756: 		     17 => '400 Level',
                   1757: 		     18 => 'Graduate Level');
                   1758:     return &mt($gradelevels{$gradelevel});
                   1759: }
                   1760: 
1.163     www      1761: sub select_level_form {
                   1762:     my ($deflevel,$name)=@_;
                   1763:     unless ($deflevel) { $deflevel=0; }
1.167     www      1764:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
                   1765:     for (my $i=0; $i<=18; $i++) {
                   1766:         $selectform.="<option value=\"$i\" ".
1.253     albertel 1767:             ($i==$deflevel ? 'selected="selected" ' : '').
1.167     www      1768:                 ">".&gradeleveldescription($i)."</option>\n";
                   1769:     }
                   1770:     $selectform.="</select>";
                   1771:     return $selectform;
1.163     www      1772: }
1.167     www      1773: 
1.35      matthew  1774: #-------------------------------------------
                   1775: 
1.45      matthew  1776: =pod
                   1777: 
1.743     raeburn  1778: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$autosubmit)
1.35      matthew  1779: 
                   1780: Returns a string containing a <select name='$name' size='1'> form to 
                   1781: allow a user to select the domain to preform an operation in.  
                   1782: See loncreateuser.pm for an example invocation and use.
                   1783: 
1.90      www      1784: If the $includeempty flag is set, it also includes an empty choice ("no domain
                   1785: selected");
                   1786: 
1.743     raeburn  1787: If the $showdomdesc flag is set, the domain name is followed by the domain description.
                   1788: 
                   1789: If the $autosubmit flag is set, the form containing the domain selector will be auto-submitted by an onchange action.  
1.563     raeburn  1790: 
1.35      matthew  1791: =cut
                   1792: 
                   1793: #-------------------------------------------
1.34      matthew  1794: sub select_dom_form {
1.743     raeburn  1795:     my ($defdom,$name,$includeempty,$showdomdesc,$autosubmit) = @_;
                   1796:     my $onchange;
                   1797:     if ($autosubmit) {
                   1798:         $onchange = ' onchange="this.form.submit()"';
                   1799:     }
1.550     albertel 1800:     my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90      www      1801:     if ($includeempty) { @domains=('',@domains); }
1.743     raeburn  1802:     my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356     albertel 1803:     foreach my $dom (@domains) {
                   1804:         $selectdomain.="<option value=\"$dom\" ".
1.563     raeburn  1805:             ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
                   1806:         if ($showdomdesc) {
                   1807:             if ($dom ne '') {
                   1808:                 my $domdesc = &Apache::lonnet::domain($dom,'description');
                   1809:                 if ($domdesc ne '') {
                   1810:                     $selectdomain .= ' ('.$domdesc.')';
                   1811:                 }
                   1812:             } 
                   1813:         }
                   1814:         $selectdomain .= "</option>\n";
1.34      matthew  1815:     }
                   1816:     $selectdomain.="</select>";
                   1817:     return $selectdomain;
                   1818: }
                   1819: 
1.35      matthew  1820: #-------------------------------------------
                   1821: 
1.45      matthew  1822: =pod
                   1823: 
1.648     raeburn  1824: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35      matthew  1825: 
1.586     raeburn  1826: input: 4 arguments (two required, two optional) - 
                   1827:     $domain - domain of new user
                   1828:     $name - name of form element
                   1829:     $default - Value of 'default' causes a default item to be first 
                   1830:                             option, and selected by default. 
                   1831:     $hide - Value of 'hide' causes hiding of the name of the server, 
                   1832:                             if 1 server found, or default, if 0 found.
1.594     raeburn  1833: output: returns 2 items: 
1.586     raeburn  1834: (a) form element which contains either:
                   1835:    (i) <select name="$name">
                   1836:         <option value="$hostid1">$hostid $servers{$hostid}</option>
                   1837:         <option value="$hostid2">$hostid $servers{$hostid}</option>       
                   1838:        </select>
                   1839:        form item if there are multiple library servers in $domain, or
                   1840:    (ii) an <input type="hidden" name="$name" value="$hostid" /> form item 
                   1841:        if there is only one library server in $domain.
                   1842: 
                   1843: (b) number of library servers found.
                   1844: 
                   1845: See loncreateuser.pm for example of use.
1.35      matthew  1846: 
                   1847: =cut
                   1848: 
                   1849: #-------------------------------------------
1.586     raeburn  1850: sub home_server_form_item {
                   1851:     my ($domain,$name,$default,$hide) = @_;
1.513     albertel 1852:     my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586     raeburn  1853:     my $result;
                   1854:     my $numlib = keys(%servers);
                   1855:     if ($numlib > 1) {
                   1856:         $result .= '<select name="'.$name.'" />'."\n";
                   1857:         if ($default) {
1.804     bisitz   1858:             $result .= '<option value="default" selected="selected">'.&mt('default').
1.586     raeburn  1859:                        '</option>'."\n";
                   1860:         }
                   1861:         foreach my $hostid (sort(keys(%servers))) {
                   1862:             $result.= '<option value="'.$hostid.'">'.
                   1863: 	              $hostid.' '.$servers{$hostid}."</option>\n";
                   1864:         }
                   1865:         $result .= '</select>'."\n";
                   1866:     } elsif ($numlib == 1) {
                   1867:         my $hostid;
                   1868:         foreach my $item (keys(%servers)) {
                   1869:             $hostid = $item;
                   1870:         }
                   1871:         $result .= '<input type="hidden" name="'.$name.'" value="'.
                   1872:                    $hostid.'" />';
                   1873:                    if (!$hide) {
                   1874:                        $result .= $hostid.' '.$servers{$hostid};
                   1875:                    }
                   1876:                    $result .= "\n";
                   1877:     } elsif ($default) {
                   1878:         $result .= '<input type="hidden" name="'.$name.
                   1879:                    '" value="default" />';
                   1880:                    if (!$hide) {
                   1881:                        $result .= &mt('default');
                   1882:                    }
                   1883:                    $result .= "\n";
1.33      matthew  1884:     }
1.586     raeburn  1885:     return ($result,$numlib);
1.33      matthew  1886: }
1.112     bowersj2 1887: 
                   1888: =pod
                   1889: 
1.534     albertel 1890: =back 
                   1891: 
1.112     bowersj2 1892: =cut
1.87      matthew  1893: 
                   1894: ###############################################################
1.112     bowersj2 1895: ##                  Decoding User Agent                      ##
1.87      matthew  1896: ###############################################################
                   1897: 
                   1898: =pod
                   1899: 
1.112     bowersj2 1900: =head1 Decoding the User Agent
                   1901: 
                   1902: =over 4
                   1903: 
                   1904: =item * &decode_user_agent()
1.87      matthew  1905: 
                   1906: Inputs: $r
                   1907: 
                   1908: Outputs:
                   1909: 
                   1910: =over 4
                   1911: 
1.112     bowersj2 1912: =item * $httpbrowser
1.87      matthew  1913: 
1.112     bowersj2 1914: =item * $clientbrowser
1.87      matthew  1915: 
1.112     bowersj2 1916: =item * $clientversion
1.87      matthew  1917: 
1.112     bowersj2 1918: =item * $clientmathml
1.87      matthew  1919: 
1.112     bowersj2 1920: =item * $clientunicode
1.87      matthew  1921: 
1.112     bowersj2 1922: =item * $clientos
1.87      matthew  1923: 
                   1924: =back
                   1925: 
1.157     matthew  1926: =back 
                   1927: 
1.87      matthew  1928: =cut
                   1929: 
                   1930: ###############################################################
                   1931: ###############################################################
                   1932: sub decode_user_agent {
1.247     albertel 1933:     my ($r)=@_;
1.87      matthew  1934:     my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
                   1935:     my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
                   1936:     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247     albertel 1937:     if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87      matthew  1938:     my $clientbrowser='unknown';
                   1939:     my $clientversion='0';
                   1940:     my $clientmathml='';
                   1941:     my $clientunicode='0';
                   1942:     for (my $i=0;$i<=$#browsertype;$i++) {
                   1943:         my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
                   1944: 	if (($httpbrowser=~/$match/i)  && ($httpbrowser!~/$notmatch/i)) {
                   1945: 	    $clientbrowser=$bname;
                   1946:             $httpbrowser=~/$vreg/i;
                   1947: 	    $clientversion=$1;
                   1948:             $clientmathml=($clientversion>=$minv);
                   1949:             $clientunicode=($clientversion>=$univ);
                   1950: 	}
                   1951:     }
                   1952:     my $clientos='unknown';
                   1953:     if (($httpbrowser=~/linux/i) ||
                   1954:         ($httpbrowser=~/unix/i) ||
                   1955:         ($httpbrowser=~/ux/i) ||
                   1956:         ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
                   1957:     if (($httpbrowser=~/vax/i) ||
                   1958:         ($httpbrowser=~/vms/i)) { $clientos='vms'; }
                   1959:     if ($httpbrowser=~/next/i) { $clientos='next'; }
                   1960:     if (($httpbrowser=~/mac/i) ||
                   1961:         ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
                   1962:     if ($httpbrowser=~/win/i) { $clientos='win'; }
                   1963:     if ($httpbrowser=~/embed/i) { $clientos='pda'; }
                   1964:     return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   1965:             $clientunicode,$clientos,);
                   1966: }
                   1967: 
1.32      matthew  1968: ###############################################################
                   1969: ##    Authentication changing form generation subroutines    ##
                   1970: ###############################################################
                   1971: ##
                   1972: ## All of the authform_xxxxxxx subroutines take their inputs in a
                   1973: ## hash, and have reasonable default values.
                   1974: ##
                   1975: ##    formname = the name given in the <form> tag.
1.35      matthew  1976: #-------------------------------------------
                   1977: 
1.45      matthew  1978: =pod
                   1979: 
1.112     bowersj2 1980: =head1 Authentication Routines
                   1981: 
                   1982: =over 4
                   1983: 
1.648     raeburn  1984: =item * &authform_xxxxxx()
1.35      matthew  1985: 
                   1986: The authform_xxxxxx subroutines provide javascript and html forms which 
                   1987: handle some of the conveniences required for authentication forms.  
                   1988: This is not an optimal method, but it works.  
                   1989: 
                   1990: =over 4
                   1991: 
1.112     bowersj2 1992: =item * authform_header
1.35      matthew  1993: 
1.112     bowersj2 1994: =item * authform_authorwarning
1.35      matthew  1995: 
1.112     bowersj2 1996: =item * authform_nochange
1.35      matthew  1997: 
1.112     bowersj2 1998: =item * authform_kerberos
1.35      matthew  1999: 
1.112     bowersj2 2000: =item * authform_internal
1.35      matthew  2001: 
1.112     bowersj2 2002: =item * authform_filesystem
1.35      matthew  2003: 
                   2004: =back
                   2005: 
1.648     raeburn  2006: See loncreateuser.pm for invocation and use examples.
1.157     matthew  2007: 
1.35      matthew  2008: =cut
                   2009: 
                   2010: #-------------------------------------------
1.32      matthew  2011: sub authform_header{  
                   2012:     my %in = (
                   2013:         formname => 'cu',
1.80      albertel 2014:         kerb_def_dom => '',
1.32      matthew  2015:         @_,
                   2016:     );
                   2017:     $in{'formname'} = 'document.' . $in{'formname'};
                   2018:     my $result='';
1.80      albertel 2019: 
                   2020: #---------------------------------------------- Code for upper case translation
                   2021:     my $Javascript_toUpperCase;
                   2022:     unless ($in{kerb_def_dom}) {
                   2023:         $Javascript_toUpperCase =<<"END";
                   2024:         switch (choice) {
                   2025:            case 'krb': currentform.elements[choicearg].value =
                   2026:                currentform.elements[choicearg].value.toUpperCase();
                   2027:                break;
                   2028:            default:
                   2029:         }
                   2030: END
                   2031:     } else {
                   2032:         $Javascript_toUpperCase = "";
                   2033:     }
                   2034: 
1.165     raeburn  2035:     my $radioval = "'nochange'";
1.591     raeburn  2036:     if (defined($in{'curr_authtype'})) {
                   2037:         if ($in{'curr_authtype'} ne '') {
                   2038:             $radioval = "'".$in{'curr_authtype'}."arg'";
                   2039:         }
1.174     matthew  2040:     }
1.165     raeburn  2041:     my $argfield = 'null';
1.591     raeburn  2042:     if (defined($in{'mode'})) {
1.165     raeburn  2043:         if ($in{'mode'} eq 'modifycourse')  {
1.591     raeburn  2044:             if (defined($in{'curr_autharg'})) {
                   2045:                 if ($in{'curr_autharg'} ne '') {
1.165     raeburn  2046:                     $argfield = "'$in{'curr_autharg'}'";
                   2047:                 }
                   2048:             }
                   2049:         }
                   2050:     }
                   2051: 
1.32      matthew  2052:     $result.=<<"END";
                   2053: var current = new Object();
1.165     raeburn  2054: current.radiovalue = $radioval;
                   2055: current.argfield = $argfield;
1.32      matthew  2056: 
                   2057: function changed_radio(choice,currentform) {
                   2058:     var choicearg = choice + 'arg';
                   2059:     // If a radio button in changed, we need to change the argfield
                   2060:     if (current.radiovalue != choice) {
                   2061:         current.radiovalue = choice;
                   2062:         if (current.argfield != null) {
                   2063:             currentform.elements[current.argfield].value = '';
                   2064:         }
                   2065:         if (choice == 'nochange') {
                   2066:             current.argfield = null;
                   2067:         } else {
                   2068:             current.argfield = choicearg;
                   2069:             switch(choice) {
                   2070:                 case 'krb': 
                   2071:                     currentform.elements[current.argfield].value = 
                   2072:                         "$in{'kerb_def_dom'}";
                   2073:                 break;
                   2074:               default:
                   2075:                 break;
                   2076:             }
                   2077:         }
                   2078:     }
                   2079:     return;
                   2080: }
1.22      www      2081: 
1.32      matthew  2082: function changed_text(choice,currentform) {
                   2083:     var choicearg = choice + 'arg';
                   2084:     if (currentform.elements[choicearg].value !='') {
1.80      albertel 2085:         $Javascript_toUpperCase
1.32      matthew  2086:         // clear old field
                   2087:         if ((current.argfield != choicearg) && (current.argfield != null)) {
                   2088:             currentform.elements[current.argfield].value = '';
                   2089:         }
                   2090:         current.argfield = choicearg;
                   2091:     }
                   2092:     set_auth_radio_buttons(choice,currentform);
                   2093:     return;
1.20      www      2094: }
1.32      matthew  2095: 
                   2096: function set_auth_radio_buttons(newvalue,currentform) {
                   2097:     var i=0;
                   2098:     while (i < currentform.login.length) {
                   2099:         if (currentform.login[i].value == newvalue) { break; }
                   2100:         i++;
                   2101:     }
                   2102:     if (i == currentform.login.length) {
                   2103:         return;
                   2104:     }
                   2105:     current.radiovalue = newvalue;
                   2106:     currentform.login[i].checked = true;
                   2107:     return;
                   2108: }
                   2109: END
                   2110:     return $result;
                   2111: }
                   2112: 
                   2113: sub authform_authorwarning{
                   2114:     my $result='';
1.144     matthew  2115:     $result='<i>'.
                   2116:         &mt('As a general rule, only authors or co-authors should be '.
                   2117:             'filesystem authenticated '.
                   2118:             '(which allows access to the server filesystem).')."</i>\n";
1.32      matthew  2119:     return $result;
                   2120: }
                   2121: 
                   2122: sub authform_nochange{  
                   2123:     my %in = (
                   2124:               formname => 'document.cu',
                   2125:               kerb_def_dom => 'MSU.EDU',
                   2126:               @_,
                   2127:           );
1.586     raeburn  2128:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'}); 
                   2129:     my $result;
                   2130:     if (keys(%can_assign) == 0) {
                   2131:         $result = &mt('Under you current role you are not permitted to change login settings for this user');  
                   2132:     } else {
                   2133:         $result = '<label>'.&mt('[_1] Do not change login data',
                   2134:                   '<input type="radio" name="login" value="nochange" '.
                   2135:                   'checked="checked" onclick="'.
1.281     albertel 2136:             "javascript:changed_radio('nochange',$in{'formname'});".'" />').
                   2137: 	    '</label>';
1.586     raeburn  2138:     }
1.32      matthew  2139:     return $result;
                   2140: }
                   2141: 
1.591     raeburn  2142: sub authform_kerberos {
1.32      matthew  2143:     my %in = (
                   2144:               formname => 'document.cu',
                   2145:               kerb_def_dom => 'MSU.EDU',
1.80      albertel 2146:               kerb_def_auth => 'krb4',
1.32      matthew  2147:               @_,
                   2148:               );
1.586     raeburn  2149:     my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
                   2150:         $autharg,$jscall);
                   2151:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.80      albertel 2152:     if ($in{'kerb_def_auth'} eq 'krb5') {
1.772     bisitz   2153:        $check5 = ' checked="checked"';
1.80      albertel 2154:     } else {
1.772     bisitz   2155:        $check4 = ' checked="checked"';
1.80      albertel 2156:     }
1.165     raeburn  2157:     $krbarg = $in{'kerb_def_dom'};
1.591     raeburn  2158:     if (defined($in{'curr_authtype'})) {
                   2159:         if ($in{'curr_authtype'} eq 'krb') {
1.772     bisitz   2160:             $krbcheck = ' checked="checked"';
1.623     raeburn  2161:             if (defined($in{'mode'})) {
                   2162:                 if ($in{'mode'} eq 'modifyuser') {
                   2163:                     $krbcheck = '';
                   2164:                 }
                   2165:             }
1.591     raeburn  2166:             if (defined($in{'curr_kerb_ver'})) {
                   2167:                 if ($in{'curr_krb_ver'} eq '5') {
1.772     bisitz   2168:                     $check5 = ' checked="checked"';
1.591     raeburn  2169:                     $check4 = '';
                   2170:                 } else {
1.772     bisitz   2171:                     $check4 = ' checked="checked"';
1.591     raeburn  2172:                     $check5 = '';
                   2173:                 }
1.586     raeburn  2174:             }
1.591     raeburn  2175:             if (defined($in{'curr_autharg'})) {
1.165     raeburn  2176:                 $krbarg = $in{'curr_autharg'};
                   2177:             }
1.586     raeburn  2178:             if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591     raeburn  2179:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2180:                     $result = 
                   2181:     &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
                   2182:         $in{'curr_autharg'},$krbver);
                   2183:                 } else {
                   2184:                     $result =
                   2185:     &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
                   2186:                 }
                   2187:                 return $result; 
                   2188:             }
                   2189:         }
                   2190:     } else {
                   2191:         if ($authnum == 1) {
1.784     bisitz   2192:             $authtype = '<input type="hidden" name="login" value="krb" />';
1.165     raeburn  2193:         }
                   2194:     }
1.586     raeburn  2195:     if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
                   2196:         return;
1.587     raeburn  2197:     } elsif ($authtype eq '') {
1.591     raeburn  2198:         if (defined($in{'mode'})) {
1.587     raeburn  2199:             if ($in{'mode'} eq 'modifycourse') {
                   2200:                 if ($authnum == 1) {
1.784     bisitz   2201:                     $authtype = '<input type="hidden" name="login" value="krb" />';
1.587     raeburn  2202:                 }
                   2203:             }
                   2204:         }
1.586     raeburn  2205:     }
                   2206:     $jscall = "javascript:changed_radio('krb',$in{'formname'});";
                   2207:     if ($authtype eq '') {
                   2208:         $authtype = '<input type="radio" name="login" value="krb" '.
                   2209:                     'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
                   2210:                     $krbcheck.' />';
                   2211:     }
                   2212:     if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
                   2213:         ($can_assign{'krb4'} && !$can_assign{'krb5'} && 
                   2214:          $in{'curr_authtype'} eq 'krb5') ||
                   2215:         (!$can_assign{'krb4'} && $can_assign{'krb5'} && 
                   2216:          $in{'curr_authtype'} eq 'krb4')) {
                   2217:         $result .= &mt
1.144     matthew  2218:         ('[_1] Kerberos authenticated with domain [_2] '.
1.281     albertel 2219:          '[_3] Version 4 [_4] Version 5 [_5]',
1.586     raeburn  2220:          '<label>'.$authtype,
1.281     albertel 2221:          '</label><input type="text" size="10" name="krbarg" '.
1.165     raeburn  2222:              'value="'.$krbarg.'" '.
1.144     matthew  2223:              'onchange="'.$jscall.'" />',
1.281     albertel 2224:          '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
                   2225:          '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
                   2226: 	 '</label>');
1.586     raeburn  2227:     } elsif ($can_assign{'krb4'}) {
                   2228:         $result .= &mt
                   2229:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2230:          '[_3] Version 4 [_4]',
                   2231:          '<label>'.$authtype,
                   2232:          '</label><input type="text" size="10" name="krbarg" '.
                   2233:              'value="'.$krbarg.'" '.
                   2234:              'onchange="'.$jscall.'" />',
                   2235:          '<label><input type="hidden" name="krbver" value="4" />',
                   2236:          '</label>');
                   2237:     } elsif ($can_assign{'krb5'}) {
                   2238:         $result .= &mt
                   2239:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2240:          '[_3] Version 5 [_4]',
                   2241:          '<label>'.$authtype,
                   2242:          '</label><input type="text" size="10" name="krbarg" '.
                   2243:              'value="'.$krbarg.'" '.
                   2244:              'onchange="'.$jscall.'" />',
                   2245:          '<label><input type="hidden" name="krbver" value="5" />',
                   2246:          '</label>');
                   2247:     }
1.32      matthew  2248:     return $result;
                   2249: }
                   2250: 
                   2251: sub authform_internal{  
1.586     raeburn  2252:     my %in = (
1.32      matthew  2253:                 formname => 'document.cu',
                   2254:                 kerb_def_dom => 'MSU.EDU',
                   2255:                 @_,
                   2256:                 );
1.586     raeburn  2257:     my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
                   2258:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2259:     if (defined($in{'curr_authtype'})) {
                   2260:         if ($in{'curr_authtype'} eq 'int') {
1.586     raeburn  2261:             if ($can_assign{'int'}) {
1.772     bisitz   2262:                 $intcheck = 'checked="checked" ';
1.623     raeburn  2263:                 if (defined($in{'mode'})) {
                   2264:                     if ($in{'mode'} eq 'modifyuser') {
                   2265:                         $intcheck = '';
                   2266:                     }
                   2267:                 }
1.591     raeburn  2268:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2269:                     $intarg = $in{'curr_autharg'};
                   2270:                 }
                   2271:             } else {
                   2272:                 $result = &mt('Currently internally authenticated.');
                   2273:                 return $result;
1.165     raeburn  2274:             }
                   2275:         }
1.586     raeburn  2276:     } else {
                   2277:         if ($authnum == 1) {
1.784     bisitz   2278:             $authtype = '<input type="hidden" name="login" value="int" />';
1.586     raeburn  2279:         }
                   2280:     }
                   2281:     if (!$can_assign{'int'}) {
                   2282:         return;
1.587     raeburn  2283:     } elsif ($authtype eq '') {
1.591     raeburn  2284:         if (defined($in{'mode'})) {
1.587     raeburn  2285:             if ($in{'mode'} eq 'modifycourse') {
                   2286:                 if ($authnum == 1) {
1.784     bisitz   2287:                     $authtype = '<input type="hidden" name="login" value="int" />';
1.587     raeburn  2288:                 }
                   2289:             }
                   2290:         }
1.165     raeburn  2291:     }
1.586     raeburn  2292:     $jscall = "javascript:changed_radio('int',$in{'formname'});";
                   2293:     if ($authtype eq '') {
                   2294:         $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
                   2295:                     ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
                   2296:     }
1.605     bisitz   2297:     $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586     raeburn  2298:                $intarg.'" onchange="'.$jscall.'" />';
                   2299:     $result = &mt
1.144     matthew  2300:         ('[_1] Internally authenticated (with initial password [_2])',
1.586     raeburn  2301:          '<label>'.$authtype,'</label>'.$autharg);
1.620     www      2302:     $result.="<label><input type=\"checkbox\" name=\"visible\" onClick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.32      matthew  2303:     return $result;
                   2304: }
                   2305: 
                   2306: sub authform_local{  
                   2307:     my %in = (
                   2308:               formname => 'document.cu',
                   2309:               kerb_def_dom => 'MSU.EDU',
                   2310:               @_,
                   2311:               );
1.586     raeburn  2312:     my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
                   2313:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2314:     if (defined($in{'curr_authtype'})) {
                   2315:         if ($in{'curr_authtype'} eq 'loc') {
1.586     raeburn  2316:             if ($can_assign{'loc'}) {
1.772     bisitz   2317:                 $loccheck = 'checked="checked" ';
1.623     raeburn  2318:                 if (defined($in{'mode'})) {
                   2319:                     if ($in{'mode'} eq 'modifyuser') {
                   2320:                         $loccheck = '';
                   2321:                     }
                   2322:                 }
1.591     raeburn  2323:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2324:                     $locarg = $in{'curr_autharg'};
                   2325:                 }
                   2326:             } else {
                   2327:                 $result = &mt('Currently using local (institutional) authentication.');
                   2328:                 return $result;
1.165     raeburn  2329:             }
                   2330:         }
1.586     raeburn  2331:     } else {
                   2332:         if ($authnum == 1) {
1.784     bisitz   2333:             $authtype = '<input type="hidden" name="login" value="loc" />';
1.586     raeburn  2334:         }
                   2335:     }
                   2336:     if (!$can_assign{'loc'}) {
                   2337:         return;
1.587     raeburn  2338:     } elsif ($authtype eq '') {
1.591     raeburn  2339:         if (defined($in{'mode'})) {
1.587     raeburn  2340:             if ($in{'mode'} eq 'modifycourse') {
                   2341:                 if ($authnum == 1) {
1.784     bisitz   2342:                     $authtype = '<input type="hidden" name="login" value="loc" />';
1.587     raeburn  2343:                 }
                   2344:             }
                   2345:         }
1.165     raeburn  2346:     }
1.586     raeburn  2347:     $jscall = "javascript:changed_radio('loc',$in{'formname'});";
                   2348:     if ($authtype eq '') {
                   2349:         $authtype = '<input type="radio" name="login" value="loc" '.
                   2350:                     $loccheck.' onchange="'.$jscall.'" onclick="'.
                   2351:                     $jscall.'" />';
                   2352:     }
                   2353:     $autharg = '<input type="text" size="10" name="locarg" value="'.
                   2354:                $locarg.'" onchange="'.$jscall.'" />';
                   2355:     $result = &mt('[_1] Local Authentication with argument [_2]',
                   2356:                   '<label>'.$authtype,'</label>'.$autharg);
1.32      matthew  2357:     return $result;
                   2358: }
                   2359: 
                   2360: sub authform_filesystem{  
                   2361:     my %in = (
                   2362:               formname => 'document.cu',
                   2363:               kerb_def_dom => 'MSU.EDU',
                   2364:               @_,
                   2365:               );
1.586     raeburn  2366:     my ($fsyscheck,$result,$authtype,$autharg,$jscall);
                   2367:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2368:     if (defined($in{'curr_authtype'})) {
                   2369:         if ($in{'curr_authtype'} eq 'fsys') {
1.586     raeburn  2370:             if ($can_assign{'fsys'}) {
1.772     bisitz   2371:                 $fsyscheck = 'checked="checked" ';
1.623     raeburn  2372:                 if (defined($in{'mode'})) {
                   2373:                     if ($in{'mode'} eq 'modifyuser') {
                   2374:                         $fsyscheck = '';
                   2375:                     }
                   2376:                 }
1.586     raeburn  2377:             } else {
                   2378:                 $result = &mt('Currently Filesystem Authenticated.');
                   2379:                 return $result;
                   2380:             }           
                   2381:         }
                   2382:     } else {
                   2383:         if ($authnum == 1) {
1.784     bisitz   2384:             $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586     raeburn  2385:         }
                   2386:     }
                   2387:     if (!$can_assign{'fsys'}) {
                   2388:         return;
1.587     raeburn  2389:     } elsif ($authtype eq '') {
1.591     raeburn  2390:         if (defined($in{'mode'})) {
1.587     raeburn  2391:             if ($in{'mode'} eq 'modifycourse') {
                   2392:                 if ($authnum == 1) {
1.784     bisitz   2393:                     $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587     raeburn  2394:                 }
                   2395:             }
                   2396:         }
1.586     raeburn  2397:     }
                   2398:     $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
                   2399:     if ($authtype eq '') {
                   2400:         $authtype = '<input type="radio" name="login" value="fsys" '.
                   2401:                     $fsyscheck.' onchange="'.$jscall.'" onclick="'.
                   2402:                     $jscall.'" />';
                   2403:     }
                   2404:     $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
                   2405:                ' onchange="'.$jscall.'" />';
                   2406:     $result = &mt
1.144     matthew  2407:         ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281     albertel 2408:          '<label><input type="radio" name="login" value="fsys" '.
1.586     raeburn  2409:          $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605     bisitz   2410:          '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144     matthew  2411:                   'onchange="'.$jscall.'" />');
1.32      matthew  2412:     return $result;
                   2413: }
                   2414: 
1.586     raeburn  2415: sub get_assignable_auth {
                   2416:     my ($dom) = @_;
                   2417:     if ($dom eq '') {
                   2418:         $dom = $env{'request.role.domain'};
                   2419:     }
                   2420:     my %can_assign = (
                   2421:                           krb4 => 1,
                   2422:                           krb5 => 1,
                   2423:                           int  => 1,
                   2424:                           loc  => 1,
                   2425:                      );
                   2426:     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
                   2427:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   2428:         if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
                   2429:             my $authhash = $domconfig{'usercreation'}{'authtypes'};
                   2430:             my $context;
                   2431:             if ($env{'request.role'} =~ /^au/) {
                   2432:                 $context = 'author';
                   2433:             } elsif ($env{'request.role'} =~ /^dc/) {
                   2434:                 $context = 'domain';
                   2435:             } elsif ($env{'request.course.id'}) {
                   2436:                 $context = 'course';
                   2437:             }
                   2438:             if ($context) {
                   2439:                 if (ref($authhash->{$context}) eq 'HASH') {
                   2440:                    %can_assign = %{$authhash->{$context}}; 
                   2441:                 }
                   2442:             }
                   2443:         }
                   2444:     }
                   2445:     my $authnum = 0;
                   2446:     foreach my $key (keys(%can_assign)) {
                   2447:         if ($can_assign{$key}) {
                   2448:             $authnum ++;
                   2449:         }
                   2450:     }
                   2451:     if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
                   2452:         $authnum --;
                   2453:     }
                   2454:     return ($authnum,%can_assign);
                   2455: }
                   2456: 
1.80      albertel 2457: ###############################################################
                   2458: ##    Get Kerberos Defaults for Domain                 ##
                   2459: ###############################################################
                   2460: ##
                   2461: ## Returns default kerberos version and an associated argument
                   2462: ## as listed in file domain.tab. If not listed, provides
                   2463: ## appropriate default domain and kerberos version.
                   2464: ##
                   2465: #-------------------------------------------
                   2466: 
                   2467: =pod
                   2468: 
1.648     raeburn  2469: =item * &get_kerberos_defaults()
1.80      albertel 2470: 
                   2471: get_kerberos_defaults($target_domain) returns the default kerberos
1.641     raeburn  2472: version and domain. If not found, it defaults to version 4 and the 
                   2473: domain of the server.
1.80      albertel 2474: 
1.648     raeburn  2475: =over 4
                   2476: 
1.80      albertel 2477: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
                   2478: 
1.648     raeburn  2479: =back
                   2480: 
                   2481: =back
                   2482: 
1.80      albertel 2483: =cut
                   2484: 
                   2485: #-------------------------------------------
                   2486: sub get_kerberos_defaults {
                   2487:     my $domain=shift;
1.641     raeburn  2488:     my ($krbdef,$krbdefdom);
                   2489:     my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
                   2490:     if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
                   2491:         $krbdef = $domdefaults{'auth_def'};
                   2492:         $krbdefdom = $domdefaults{'auth_arg_def'};
                   2493:     } else {
1.80      albertel 2494:         $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
                   2495:         my $krbdefdom=$1;
                   2496:         $krbdefdom=~tr/a-z/A-Z/;
                   2497:         $krbdef = "krb4";
                   2498:     }
                   2499:     return ($krbdef,$krbdefdom);
                   2500: }
1.112     bowersj2 2501: 
1.32      matthew  2502: 
1.46      matthew  2503: ###############################################################
                   2504: ##                Thesaurus Functions                        ##
                   2505: ###############################################################
1.20      www      2506: 
1.46      matthew  2507: =pod
1.20      www      2508: 
1.112     bowersj2 2509: =head1 Thesaurus Functions
                   2510: 
                   2511: =over 4
                   2512: 
1.648     raeburn  2513: =item * &initialize_keywords()
1.46      matthew  2514: 
                   2515: Initializes the package variable %Keywords if it is empty.  Uses the
                   2516: package variable $thesaurus_db_file.
                   2517: 
                   2518: =cut
                   2519: 
                   2520: ###################################################
                   2521: 
                   2522: sub initialize_keywords {
                   2523:     return 1 if (scalar keys(%Keywords));
                   2524:     # If we are here, %Keywords is empty, so fill it up
                   2525:     #   Make sure the file we need exists...
                   2526:     if (! -e $thesaurus_db_file) {
                   2527:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
                   2528:                                  " failed because it does not exist");
                   2529:         return 0;
                   2530:     }
                   2531:     #   Set up the hash as a database
                   2532:     my %thesaurus_db;
                   2533:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2534:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2535:         &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
                   2536:                                  $thesaurus_db_file);
                   2537:         return 0;
                   2538:     } 
                   2539:     #  Get the average number of appearances of a word.
                   2540:     my $avecount = $thesaurus_db{'average.count'};
                   2541:     #  Put keywords (those that appear > average) into %Keywords
                   2542:     while (my ($word,$data)=each (%thesaurus_db)) {
                   2543:         my ($count,undef) = split /:/,$data;
                   2544:         $Keywords{$word}++ if ($count > $avecount);
                   2545:     }
                   2546:     untie %thesaurus_db;
                   2547:     # Remove special values from %Keywords.
1.356     albertel 2548:     foreach my $value ('total.count','average.count') {
                   2549:         delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586     raeburn  2550:   }
1.46      matthew  2551:     return 1;
                   2552: }
                   2553: 
                   2554: ###################################################
                   2555: 
                   2556: =pod
                   2557: 
1.648     raeburn  2558: =item * &keyword($word)
1.46      matthew  2559: 
                   2560: Returns true if $word is a keyword.  A keyword is a word that appears more 
                   2561: than the average number of times in the thesaurus database.  Calls 
                   2562: &initialize_keywords
                   2563: 
                   2564: =cut
                   2565: 
                   2566: ###################################################
1.20      www      2567: 
                   2568: sub keyword {
1.46      matthew  2569:     return if (!&initialize_keywords());
                   2570:     my $word=lc(shift());
                   2571:     $word=~s/\W//g;
                   2572:     return exists($Keywords{$word});
1.20      www      2573: }
1.46      matthew  2574: 
                   2575: ###############################################################
                   2576: 
                   2577: =pod 
1.20      www      2578: 
1.648     raeburn  2579: =item * &get_related_words()
1.46      matthew  2580: 
1.160     matthew  2581: Look up a word in the thesaurus.  Takes a scalar argument and returns
1.46      matthew  2582: an array of words.  If the keyword is not in the thesaurus, an empty array
                   2583: will be returned.  The order of the words returned is determined by the
                   2584: database which holds them.
                   2585: 
                   2586: Uses global $thesaurus_db_file.
                   2587: 
                   2588: =cut
                   2589: 
                   2590: ###############################################################
                   2591: sub get_related_words {
                   2592:     my $keyword = shift;
                   2593:     my %thesaurus_db;
                   2594:     if (! -e $thesaurus_db_file) {
                   2595:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
                   2596:                                  "failed because the file does not exist");
                   2597:         return ();
                   2598:     }
                   2599:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2600:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2601:         return ();
                   2602:     } 
                   2603:     my @Words=();
1.429     www      2604:     my $count=0;
1.46      matthew  2605:     if (exists($thesaurus_db{$keyword})) {
1.356     albertel 2606: 	# The first element is the number of times
                   2607: 	# the word appears.  We do not need it now.
1.429     www      2608: 	my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
                   2609: 	my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
                   2610: 	my $threshold=$mostfrequentcount/10;
                   2611:         foreach my $possibleword (@RelatedWords) {
                   2612:             my ($word,$wordcount)=split(/\,/,$possibleword);
                   2613:             if ($wordcount>$threshold) {
                   2614: 		push(@Words,$word);
                   2615:                 $count++;
                   2616:                 if ($count>10) { last; }
                   2617: 	    }
1.20      www      2618:         }
                   2619:     }
1.46      matthew  2620:     untie %thesaurus_db;
                   2621:     return @Words;
1.14      harris41 2622: }
1.46      matthew  2623: 
1.112     bowersj2 2624: =pod
                   2625: 
                   2626: =back
                   2627: 
                   2628: =cut
1.61      www      2629: 
                   2630: # -------------------------------------------------------------- Plaintext name
1.81      albertel 2631: =pod
                   2632: 
1.112     bowersj2 2633: =head1 User Name Functions
                   2634: 
                   2635: =over 4
                   2636: 
1.648     raeburn  2637: =item * &plainname($uname,$udom,$first)
1.81      albertel 2638: 
1.112     bowersj2 2639: Takes a users logon name and returns it as a string in
1.226     albertel 2640: "first middle last generation" form 
                   2641: if $first is set to 'lastname' then it returns it as
                   2642: 'lastname generation, firstname middlename' if their is a lastname
1.81      albertel 2643: 
                   2644: =cut
1.61      www      2645: 
1.295     www      2646: 
1.81      albertel 2647: ###############################################################
1.61      www      2648: sub plainname {
1.226     albertel 2649:     my ($uname,$udom,$first)=@_;
1.537     albertel 2650:     return if (!defined($uname) || !defined($udom));
1.295     www      2651:     my %names=&getnames($uname,$udom);
1.226     albertel 2652:     my $name=&Apache::lonnet::format_name($names{'firstname'},
                   2653: 					  $names{'middlename'},
                   2654: 					  $names{'lastname'},
                   2655: 					  $names{'generation'},$first);
                   2656:     $name=~s/^\s+//;
1.62      www      2657:     $name=~s/\s+$//;
                   2658:     $name=~s/\s+/ /g;
1.353     albertel 2659:     if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62      www      2660:     return $name;
1.61      www      2661: }
1.66      www      2662: 
                   2663: # -------------------------------------------------------------------- Nickname
1.81      albertel 2664: =pod
                   2665: 
1.648     raeburn  2666: =item * &nickname($uname,$udom)
1.81      albertel 2667: 
                   2668: Gets a users name and returns it as a string as
                   2669: 
                   2670: "&quot;nickname&quot;"
1.66      www      2671: 
1.81      albertel 2672: if the user has a nickname or
                   2673: 
                   2674: "first middle last generation"
                   2675: 
                   2676: if the user does not
                   2677: 
                   2678: =cut
1.66      www      2679: 
                   2680: sub nickname {
                   2681:     my ($uname,$udom)=@_;
1.537     albertel 2682:     return if (!defined($uname) || !defined($udom));
1.295     www      2683:     my %names=&getnames($uname,$udom);
1.68      albertel 2684:     my $name=$names{'nickname'};
1.66      www      2685:     if ($name) {
                   2686:        $name='&quot;'.$name.'&quot;'; 
                   2687:     } else {
                   2688:        $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
                   2689: 	     $names{'lastname'}.' '.$names{'generation'};
                   2690:        $name=~s/\s+$//;
                   2691:        $name=~s/\s+/ /g;
                   2692:     }
                   2693:     return $name;
                   2694: }
                   2695: 
1.295     www      2696: sub getnames {
                   2697:     my ($uname,$udom)=@_;
1.537     albertel 2698:     return if (!defined($uname) || !defined($udom));
1.433     albertel 2699:     if ($udom eq 'public' && $uname eq 'public') {
                   2700: 	return ('lastname' => &mt('Public'));
                   2701:     }
1.295     www      2702:     my $id=$uname.':'.$udom;
                   2703:     my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
                   2704:     if ($cached) {
                   2705: 	return %{$names};
                   2706:     } else {
                   2707: 	my %loadnames=&Apache::lonnet::get('environment',
                   2708:                     ['firstname','middlename','lastname','generation','nickname'],
                   2709: 					 $udom,$uname);
                   2710: 	&Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
                   2711: 	return %loadnames;
                   2712:     }
                   2713: }
1.61      www      2714: 
1.542     raeburn  2715: # -------------------------------------------------------------------- getemails
1.648     raeburn  2716: 
1.542     raeburn  2717: =pod
                   2718: 
1.648     raeburn  2719: =item * &getemails($uname,$udom)
1.542     raeburn  2720: 
                   2721: Gets a user's email information and returns it as a hash with keys:
                   2722: notification, critnotification, permanentemail
                   2723: 
                   2724: For notification and critnotification, values are comma-separated lists 
1.648     raeburn  2725: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542     raeburn  2726:  
1.648     raeburn  2727: 
1.542     raeburn  2728: =cut
                   2729: 
1.648     raeburn  2730: 
1.466     albertel 2731: sub getemails {
                   2732:     my ($uname,$udom)=@_;
                   2733:     if ($udom eq 'public' && $uname eq 'public') {
                   2734: 	return;
                   2735:     }
1.467     www      2736:     if (!$udom) { $udom=$env{'user.domain'}; }
                   2737:     if (!$uname) { $uname=$env{'user.name'}; }
1.466     albertel 2738:     my $id=$uname.':'.$udom;
                   2739:     my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
                   2740:     if ($cached) {
                   2741: 	return %{$names};
                   2742:     } else {
                   2743: 	my %loadnames=&Apache::lonnet::get('environment',
                   2744:                     			   ['notification','critnotification',
                   2745: 					    'permanentemail'],
                   2746: 					   $udom,$uname);
                   2747: 	&Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
                   2748: 	return %loadnames;
                   2749:     }
                   2750: }
                   2751: 
1.551     albertel 2752: sub flush_email_cache {
                   2753:     my ($uname,$udom)=@_;
                   2754:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2755:     if (!$uname) { $uname=$env{'user.name'};   }
                   2756:     return if ($udom eq 'public' && $uname eq 'public');
                   2757:     my $id=$uname.':'.$udom;
                   2758:     &Apache::lonnet::devalidate_cache_new('emailscache',$id);
                   2759: }
                   2760: 
1.728     raeburn  2761: # -------------------------------------------------------------------- getlangs
                   2762: 
                   2763: =pod
                   2764: 
                   2765: =item * &getlangs($uname,$udom)
                   2766: 
                   2767: Gets a user's language preference and returns it as a hash with key:
                   2768: language.
                   2769: 
                   2770: =cut
                   2771: 
                   2772: 
                   2773: sub getlangs {
                   2774:     my ($uname,$udom) = @_;
                   2775:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2776:     if (!$uname) { $uname=$env{'user.name'};   }
                   2777:     my $id=$uname.':'.$udom;
                   2778:     my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
                   2779:     if ($cached) {
                   2780:         return %{$langs};
                   2781:     } else {
                   2782:         my %loadlangs=&Apache::lonnet::get('environment',['languages'],
                   2783:                                            $udom,$uname);
                   2784:         &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
                   2785:         return %loadlangs;
                   2786:     }
                   2787: }
                   2788: 
                   2789: sub flush_langs_cache {
                   2790:     my ($uname,$udom)=@_;
                   2791:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2792:     if (!$uname) { $uname=$env{'user.name'};   }
                   2793:     return if ($udom eq 'public' && $uname eq 'public');
                   2794:     my $id=$uname.':'.$udom;
                   2795:     &Apache::lonnet::devalidate_cache_new('userlangs',$id);
                   2796: }
                   2797: 
1.61      www      2798: # ------------------------------------------------------------------ Screenname
1.81      albertel 2799: 
                   2800: =pod
                   2801: 
1.648     raeburn  2802: =item * &screenname($uname,$udom)
1.81      albertel 2803: 
                   2804: Gets a users screenname and returns it as a string
                   2805: 
                   2806: =cut
1.61      www      2807: 
                   2808: sub screenname {
                   2809:     my ($uname,$udom)=@_;
1.258     albertel 2810:     if ($uname eq $env{'user.name'} &&
                   2811: 	$udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212     albertel 2812:     my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68      albertel 2813:     return $names{'screenname'};
1.62      www      2814: }
                   2815: 
1.212     albertel 2816: 
1.802     bisitz   2817: # ------------------------------------------------------------- Confirm Wrapper
                   2818: =pod
                   2819: 
                   2820: =item confirmwrapper
                   2821: 
                   2822: Wrap messages about completion of operation in box
                   2823: 
                   2824: =cut
                   2825: 
                   2826: sub confirmwrapper {
                   2827:     my ($message)=@_;
                   2828:     if ($message) {
                   2829:         return "\n".'<div class="LC_confirm_box">'."\n"
                   2830:                .$message."\n"
                   2831:                .'</div>'."\n";
                   2832:     } else {
                   2833:         return $message;
                   2834:     }
                   2835: }
                   2836: 
1.62      www      2837: # ------------------------------------------------------------- Message Wrapper
                   2838: 
                   2839: sub messagewrapper {
1.369     www      2840:     my ($link,$username,$domain,$subject,$text)=@_;
1.62      www      2841:     return 
1.441     albertel 2842:         '<a href="/adm/email?compose=individual&amp;'.
                   2843:         'recname='.$username.'&amp;recdom='.$domain.
                   2844: 	'&amp;subject='.&escape($subject).'&amp;text='.&escape($text).'" '.
1.200     matthew  2845:         'title="'.&mt('Send message').'">'.$link.'</a>';
1.74      www      2846: }
1.802     bisitz   2847: 
1.74      www      2848: # --------------------------------------------------------------- Notes Wrapper
                   2849: 
                   2850: sub noteswrapper {
                   2851:     my ($link,$un,$do)=@_;
                   2852:     return 
                   2853: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62      www      2854: }
1.802     bisitz   2855: 
1.62      www      2856: # ------------------------------------------------------------- Aboutme Wrapper
                   2857: 
                   2858: sub aboutmewrapper {
1.166     www      2859:     my ($link,$username,$domain,$target)=@_;
1.447     raeburn  2860:     if (!defined($username)  && !defined($domain)) {
                   2861:         return;
                   2862:     }
1.205     www      2863:     return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.756     weissno  2864: 	($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62      www      2865: }
                   2866: 
                   2867: # ------------------------------------------------------------ Syllabus Wrapper
                   2868: 
                   2869: sub syllabuswrapper {
1.707     bisitz   2870:     my ($linktext,$coursedir,$domain)=@_;
1.208     matthew  2871:     return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61      www      2872: }
1.14      harris41 2873: 
1.802     bisitz   2874: # -----------------------------------------------------------------------------
                   2875: 
1.208     matthew  2876: sub track_student_link {
1.268     albertel 2877:     my ($linktext,$sname,$sdom,$target,$start) = @_;
                   2878:     my $link ="/adm/trackstudent?";
1.208     matthew  2879:     my $title = 'View recent activity';
                   2880:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   2881:         defined($sdom)  && $sdom  !~ /^\s*$/) {
1.268     albertel 2882:         $link .= "selected_student=$sname:$sdom";
1.208     matthew  2883:         $title .= ' of this student';
1.268     albertel 2884:     } 
1.208     matthew  2885:     if (defined($target) && $target !~ /^\s*$/) {
                   2886:         $target = qq{target="$target"};
                   2887:     } else {
                   2888:         $target = '';
                   2889:     }
1.268     albertel 2890:     if ($start) { $link.='&amp;start='.$start; }
1.554     albertel 2891:     $title = &mt($title);
                   2892:     $linktext = &mt($linktext);
1.448     albertel 2893:     return qq{<a href="$link" title="$title" $target>$linktext</a>}.
                   2894: 	&help_open_topic('View_recent_activity');
1.208     matthew  2895: }
                   2896: 
1.781     raeburn  2897: sub slot_reservations_link {
                   2898:     my ($linktext,$sname,$sdom,$target) = @_;
                   2899:     my $link ="/adm/slotrequest?command=showresv&amp;origin=aboutme";
                   2900:     my $title = 'View slot reservation history';
                   2901:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   2902:         defined($sdom)  && $sdom  !~ /^\s*$/) {
                   2903:         $link .= "&amp;uname=$sname&amp;udom=$sdom";
                   2904:         $title .= ' of this student';
                   2905:     }
                   2906:     if (defined($target) && $target !~ /^\s*$/) {
                   2907:         $target = qq{target="$target"};
                   2908:     } else {
                   2909:         $target = '';
                   2910:     }
                   2911:     $title = &mt($title);
                   2912:     $linktext = &mt($linktext);
                   2913:     return qq{<a href="$link" title="$title" $target>$linktext</a>};
                   2914: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
                   2915: 
                   2916: }
                   2917: 
1.508     www      2918: # ===================================================== Display a student photo
                   2919: 
                   2920: 
1.509     albertel 2921: sub student_image_tag {
1.508     www      2922:     my ($domain,$user)=@_;
                   2923:     my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
                   2924:     if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
                   2925: 	return '<img src="'.$imgsrc.'" align="right" />';
                   2926:     } else {
                   2927: 	return '';
                   2928:     }
                   2929: }
                   2930: 
1.112     bowersj2 2931: =pod
                   2932: 
                   2933: =back
                   2934: 
                   2935: =head1 Access .tab File Data
                   2936: 
                   2937: =over 4
                   2938: 
1.648     raeburn  2939: =item * &languageids() 
1.112     bowersj2 2940: 
                   2941: returns list of all language ids
                   2942: 
                   2943: =cut
                   2944: 
1.14      harris41 2945: sub languageids {
1.16      harris41 2946:     return sort(keys(%language));
1.14      harris41 2947: }
                   2948: 
1.112     bowersj2 2949: =pod
                   2950: 
1.648     raeburn  2951: =item * &languagedescription() 
1.112     bowersj2 2952: 
                   2953: returns description of a specified language id
                   2954: 
                   2955: =cut
                   2956: 
1.14      harris41 2957: sub languagedescription {
1.125     www      2958:     my $code=shift;
                   2959:     return  ($supported_language{$code}?'* ':'').
                   2960:             $language{$code}.
1.126     www      2961: 	    ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145     www      2962: }
                   2963: 
                   2964: sub plainlanguagedescription {
                   2965:     my $code=shift;
                   2966:     return $language{$code};
                   2967: }
                   2968: 
                   2969: sub supportedlanguagecode {
                   2970:     my $code=shift;
                   2971:     return $supported_language{$code};
1.97      www      2972: }
                   2973: 
1.112     bowersj2 2974: =pod
                   2975: 
1.648     raeburn  2976: =item * &copyrightids() 
1.112     bowersj2 2977: 
                   2978: returns list of all copyrights
                   2979: 
                   2980: =cut
                   2981: 
                   2982: sub copyrightids {
                   2983:     return sort(keys(%cprtag));
                   2984: }
                   2985: 
                   2986: =pod
                   2987: 
1.648     raeburn  2988: =item * &copyrightdescription() 
1.112     bowersj2 2989: 
                   2990: returns description of a specified copyright id
                   2991: 
                   2992: =cut
                   2993: 
                   2994: sub copyrightdescription {
1.166     www      2995:     return &mt($cprtag{shift(@_)});
1.112     bowersj2 2996: }
1.197     matthew  2997: 
                   2998: =pod
                   2999: 
1.648     raeburn  3000: =item * &source_copyrightids() 
1.192     taceyjo1 3001: 
                   3002: returns list of all source copyrights
                   3003: 
                   3004: =cut
                   3005: 
                   3006: sub source_copyrightids {
                   3007:     return sort(keys(%scprtag));
                   3008: }
                   3009: 
                   3010: =pod
                   3011: 
1.648     raeburn  3012: =item * &source_copyrightdescription() 
1.192     taceyjo1 3013: 
                   3014: returns description of a specified source copyright id
                   3015: 
                   3016: =cut
                   3017: 
                   3018: sub source_copyrightdescription {
                   3019:     return &mt($scprtag{shift(@_)});
                   3020: }
1.112     bowersj2 3021: 
                   3022: =pod
                   3023: 
1.648     raeburn  3024: =item * &filecategories() 
1.112     bowersj2 3025: 
                   3026: returns list of all file categories
                   3027: 
                   3028: =cut
                   3029: 
                   3030: sub filecategories {
                   3031:     return sort(keys(%category_extensions));
                   3032: }
                   3033: 
                   3034: =pod
                   3035: 
1.648     raeburn  3036: =item * &filecategorytypes() 
1.112     bowersj2 3037: 
                   3038: returns list of file types belonging to a given file
                   3039: category
                   3040: 
                   3041: =cut
                   3042: 
                   3043: sub filecategorytypes {
1.356     albertel 3044:     my ($cat) = @_;
                   3045:     return @{$category_extensions{lc($cat)}};
1.112     bowersj2 3046: }
                   3047: 
                   3048: =pod
                   3049: 
1.648     raeburn  3050: =item * &fileembstyle() 
1.112     bowersj2 3051: 
                   3052: returns embedding style for a specified file type
                   3053: 
                   3054: =cut
                   3055: 
                   3056: sub fileembstyle {
                   3057:     return $fe{lc(shift(@_))};
1.169     www      3058: }
                   3059: 
1.351     www      3060: sub filemimetype {
                   3061:     return $fm{lc(shift(@_))};
                   3062: }
                   3063: 
1.169     www      3064: 
                   3065: sub filecategoryselect {
                   3066:     my ($name,$value)=@_;
1.189     matthew  3067:     return &select_form($value,$name,
1.169     www      3068: 			'' => &mt('Any category'),
                   3069: 			map { $_,$_ } sort(keys(%category_extensions)));
1.112     bowersj2 3070: }
                   3071: 
                   3072: =pod
                   3073: 
1.648     raeburn  3074: =item * &filedescription() 
1.112     bowersj2 3075: 
                   3076: returns description for a specified file type
                   3077: 
                   3078: =cut
                   3079: 
                   3080: sub filedescription {
1.188     matthew  3081:     my $file_description = $fd{lc(shift())};
                   3082:     $file_description =~ s:([\[\]]):~$1:g;
                   3083:     return &mt($file_description);
1.112     bowersj2 3084: }
                   3085: 
                   3086: =pod
                   3087: 
1.648     raeburn  3088: =item * &filedescriptionex() 
1.112     bowersj2 3089: 
                   3090: returns description for a specified file type with
                   3091: extra formatting
                   3092: 
                   3093: =cut
                   3094: 
                   3095: sub filedescriptionex {
                   3096:     my $ex=shift;
1.188     matthew  3097:     my $file_description = $fd{lc($ex)};
                   3098:     $file_description =~ s:([\[\]]):~$1:g;
                   3099:     return '.'.$ex.' '.&mt($file_description);
1.112     bowersj2 3100: }
                   3101: 
                   3102: # End of .tab access
                   3103: =pod
                   3104: 
                   3105: =back
                   3106: 
                   3107: =cut
                   3108: 
                   3109: # ------------------------------------------------------------------ File Types
                   3110: sub fileextensions {
                   3111:     return sort(keys(%fe));
                   3112: }
                   3113: 
1.97      www      3114: # ----------------------------------------------------------- Display Languages
                   3115: # returns a hash with all desired display languages
                   3116: #
                   3117: 
                   3118: sub display_languages {
                   3119:     my %languages=();
1.695     raeburn  3120:     foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356     albertel 3121: 	$languages{$lang}=1;
1.97      www      3122:     }
                   3123:     &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258     albertel 3124:     if ($env{'form.displaylanguage'}) {
1.356     albertel 3125: 	foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
                   3126: 	    $languages{$lang}=1;
1.97      www      3127:         }
                   3128:     }
                   3129:     return %languages;
1.14      harris41 3130: }
                   3131: 
1.582     albertel 3132: sub languages {
                   3133:     my ($possible_langs) = @_;
1.695     raeburn  3134:     my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582     albertel 3135:     if (!ref($possible_langs)) {
                   3136: 	if( wantarray ) {
                   3137: 	    return @preferred_langs;
                   3138: 	} else {
                   3139: 	    return $preferred_langs[0];
                   3140: 	}
                   3141:     }
                   3142:     my %possibilities = map { $_ => 1 } (@$possible_langs);
                   3143:     my @preferred_possibilities;
                   3144:     foreach my $preferred_lang (@preferred_langs) {
                   3145: 	if (exists($possibilities{$preferred_lang})) {
                   3146: 	    push(@preferred_possibilities, $preferred_lang);
                   3147: 	}
                   3148:     }
                   3149:     if( wantarray ) {
                   3150: 	return @preferred_possibilities;
                   3151:     }
                   3152:     return $preferred_possibilities[0];
                   3153: }
                   3154: 
1.742     raeburn  3155: sub user_lang {
                   3156:     my ($touname,$toudom,$fromcid) = @_;
                   3157:     my @userlangs;
                   3158:     if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
                   3159:         @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
                   3160:                     $env{'course.'.$fromcid.'.languages'}));
                   3161:     } else {
                   3162:         my %langhash = &getlangs($touname,$toudom);
                   3163:         if ($langhash{'languages'} ne '') {
                   3164:             @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
                   3165:         } else {
                   3166:             my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
                   3167:             if ($domdefs{'lang_def'} ne '') {
                   3168:                 @userlangs = ($domdefs{'lang_def'});
                   3169:             }
                   3170:         }
                   3171:     }
                   3172:     my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
                   3173:     my $user_lh = Apache::localize->get_handle(@languages);
                   3174:     return $user_lh;
                   3175: }
                   3176: 
                   3177: 
1.112     bowersj2 3178: ###############################################################
                   3179: ##               Student Answer Attempts                     ##
                   3180: ###############################################################
                   3181: 
                   3182: =pod
                   3183: 
                   3184: =head1 Alternate Problem Views
                   3185: 
                   3186: =over 4
                   3187: 
1.648     raeburn  3188: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112     bowersj2 3189:     $getattempt, $regexp, $gradesub)
                   3190: 
                   3191: Return string with previous attempt on problem. Arguments:
                   3192: 
                   3193: =over 4
                   3194: 
                   3195: =item * $symb: Problem, including path
                   3196: 
                   3197: =item * $username: username of the desired student
                   3198: 
                   3199: =item * $domain: domain of the desired student
1.14      harris41 3200: 
1.112     bowersj2 3201: =item * $course: Course ID
1.14      harris41 3202: 
1.112     bowersj2 3203: =item * $getattempt: Leave blank for all attempts, otherwise put
                   3204:     something
1.14      harris41 3205: 
1.112     bowersj2 3206: =item * $regexp: if string matches this regexp, the string will be
                   3207:     sent to $gradesub
1.14      harris41 3208: 
1.112     bowersj2 3209: =item * $gradesub: routine that processes the string if it matches $regexp
1.14      harris41 3210: 
1.112     bowersj2 3211: =back
1.14      harris41 3212: 
1.112     bowersj2 3213: The output string is a table containing all desired attempts, if any.
1.16      harris41 3214: 
1.112     bowersj2 3215: =cut
1.1       albertel 3216: 
                   3217: sub get_previous_attempt {
1.43      ng       3218:   my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1       albertel 3219:   my $prevattempts='';
1.43      ng       3220:   no strict 'refs';
1.1       albertel 3221:   if ($symb) {
1.3       albertel 3222:     my (%returnhash)=
                   3223:       &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1       albertel 3224:     if ($returnhash{'version'}) {
                   3225:       my %lasthash=();
                   3226:       my $version;
                   3227:       for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356     albertel 3228:         foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
                   3229: 	  $lasthash{$key}=$returnhash{$version.':'.$key};
1.19      harris41 3230:         }
1.1       albertel 3231:       }
1.596     albertel 3232:       $prevattempts=&start_data_table().&start_data_table_header_row();
                   3233:       $prevattempts.='<th>'.&mt('History').'</th>';
1.356     albertel 3234:       foreach my $key (sort(keys(%lasthash))) {
                   3235: 	my ($ign,@parts) = split(/\./,$key);
1.41      ng       3236: 	if ($#parts > 0) {
1.31      albertel 3237: 	  my $data=$parts[-1];
                   3238: 	  pop(@parts);
1.596     albertel 3239: 	  $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.'&nbsp;</th>';
1.31      albertel 3240: 	} else {
1.41      ng       3241: 	  if ($#parts == 0) {
                   3242: 	    $prevattempts.='<th>'.$parts[0].'</th>';
                   3243: 	  } else {
                   3244: 	    $prevattempts.='<th>'.$ign.'</th>';
                   3245: 	  }
1.31      albertel 3246: 	}
1.16      harris41 3247:       }
1.596     albertel 3248:       $prevattempts.=&end_data_table_header_row();
1.40      ng       3249:       if ($getattempt eq '') {
                   3250: 	for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596     albertel 3251: 	  $prevattempts.=&start_data_table_row().
                   3252: 	      '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356     albertel 3253: 	    foreach my $key (sort(keys(%lasthash))) {
1.581     albertel 3254: 		my $value = &format_previous_attempt_value($key,
                   3255: 							   $returnhash{$version.':'.$key});
                   3256: 		$prevattempts.='<td>'.$value.'&nbsp;</td>';   
1.40      ng       3257: 	    }
1.596     albertel 3258: 	  $prevattempts.=&end_data_table_row();
1.40      ng       3259: 	 }
1.1       albertel 3260:       }
1.596     albertel 3261:       $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356     albertel 3262:       foreach my $key (sort(keys(%lasthash))) {
1.581     albertel 3263: 	my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356     albertel 3264: 	if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40      ng       3265: 	$prevattempts.='<td>'.$value.'&nbsp;</td>';
1.16      harris41 3266:       }
1.596     albertel 3267:       $prevattempts.= &end_data_table_row().&end_data_table();
1.1       albertel 3268:     } else {
1.596     albertel 3269:       $prevattempts=
                   3270: 	  &start_data_table().&start_data_table_row().
                   3271: 	  '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
                   3272: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3273:     }
                   3274:   } else {
1.596     albertel 3275:     $prevattempts=
                   3276: 	  &start_data_table().&start_data_table_row().
                   3277: 	  '<td>'.&mt('No data.').'</td>'.
                   3278: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3279:   }
1.10      albertel 3280: }
                   3281: 
1.581     albertel 3282: sub format_previous_attempt_value {
                   3283:     my ($key,$value) = @_;
                   3284:     if ($key =~ /timestamp/) {
                   3285: 	$value = &Apache::lonlocal::locallocaltime($value);
                   3286:     } elsif (ref($value) eq 'ARRAY') {
                   3287: 	$value = '('.join(', ', @{ $value }).')';
                   3288:     } else {
                   3289: 	$value = &unescape($value);
                   3290:     }
                   3291:     return $value;
                   3292: }
                   3293: 
                   3294: 
1.107     albertel 3295: sub relative_to_absolute {
                   3296:     my ($url,$output)=@_;
                   3297:     my $parser=HTML::TokeParser->new(\$output);
                   3298:     my $token;
                   3299:     my $thisdir=$url;
                   3300:     my @rlinks=();
                   3301:     while ($token=$parser->get_token) {
                   3302: 	if ($token->[0] eq 'S') {
                   3303: 	    if ($token->[1] eq 'a') {
                   3304: 		if ($token->[2]->{'href'}) {
                   3305: 		    $rlinks[$#rlinks+1]=$token->[2]->{'href'};
                   3306: 		}
                   3307: 	    } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
                   3308: 		$rlinks[$#rlinks+1]=$token->[2]->{'src'};
                   3309: 	    } elsif ($token->[1] eq 'base') {
                   3310: 		$thisdir=$token->[2]->{'href'};
                   3311: 	    }
                   3312: 	}
                   3313:     }
                   3314:     $thisdir=~s-/[^/]*$--;
1.356     albertel 3315:     foreach my $link (@rlinks) {
1.726     raeburn  3316: 	unless (($link=~/^https?\:\/\//i) ||
1.356     albertel 3317: 		($link=~/^\//) ||
                   3318: 		($link=~/^javascript:/i) ||
                   3319: 		($link=~/^mailto:/i) ||
                   3320: 		($link=~/^\#/)) {
                   3321: 	    my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
                   3322: 	    $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107     albertel 3323: 	}
                   3324:     }
                   3325: # -------------------------------------------------- Deal with Applet codebases
                   3326:     $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
                   3327:     return $output;
                   3328: }
                   3329: 
1.112     bowersj2 3330: =pod
                   3331: 
1.648     raeburn  3332: =item * &get_student_view()
1.112     bowersj2 3333: 
                   3334: show a snapshot of what student was looking at
                   3335: 
                   3336: =cut
                   3337: 
1.10      albertel 3338: sub get_student_view {
1.186     albertel 3339:   my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114     www      3340:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3341:   my (%form);
1.10      albertel 3342:   my @elements=('symb','courseid','domain','username');
                   3343:   foreach my $element (@elements) {
1.186     albertel 3344:       $form{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3345:   }
1.186     albertel 3346:   if (defined($moreenv)) {
                   3347:       %form=(%form,%{$moreenv});
                   3348:   }
1.236     albertel 3349:   if (defined($target)) { $form{'grade_target'} = $target; }
1.107     albertel 3350:   $feedurl=&Apache::lonnet::clutter($feedurl);
1.650     www      3351:   my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11      albertel 3352:   $userview=~s/\<body[^\>]*\>//gi;
                   3353:   $userview=~s/\<\/body\>//gi;
                   3354:   $userview=~s/\<html\>//gi;
                   3355:   $userview=~s/\<\/html\>//gi;
                   3356:   $userview=~s/\<head\>//gi;
                   3357:   $userview=~s/\<\/head\>//gi;
                   3358:   $userview=~s/action\s*\=/would_be_action\=/gi;
1.107     albertel 3359:   $userview=&relative_to_absolute($feedurl,$userview);
1.650     www      3360:   if (wantarray) {
                   3361:      return ($userview,$response);
                   3362:   } else {
                   3363:      return $userview;
                   3364:   }
                   3365: }
                   3366: 
                   3367: sub get_student_view_with_retries {
                   3368:   my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
                   3369: 
                   3370:     my $ok = 0;                 # True if we got a good response.
                   3371:     my $content;
                   3372:     my $response;
                   3373: 
                   3374:     # Try to get the student_view done. within the retries count:
                   3375:     
                   3376:     do {
                   3377:          ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
                   3378:          $ok      = $response->is_success;
                   3379:          if (!$ok) {
                   3380:             &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
                   3381:          }
                   3382:          $retries--;
                   3383:     } while (!$ok && ($retries > 0));
                   3384:     
                   3385:     if (!$ok) {
                   3386:        $content = '';          # On error return an empty content.
                   3387:     }
1.651     www      3388:     if (wantarray) {
                   3389:        return ($content, $response);
                   3390:     } else {
                   3391:        return $content;
                   3392:     }
1.11      albertel 3393: }
                   3394: 
1.112     bowersj2 3395: =pod
                   3396: 
1.648     raeburn  3397: =item * &get_student_answers() 
1.112     bowersj2 3398: 
                   3399: show a snapshot of how student was answering problem
                   3400: 
                   3401: =cut
                   3402: 
1.11      albertel 3403: sub get_student_answers {
1.100     sakharuk 3404:   my ($symb,$username,$domain,$courseid,%form) = @_;
1.114     www      3405:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3406:   my (%moreenv);
1.11      albertel 3407:   my @elements=('symb','courseid','domain','username');
                   3408:   foreach my $element (@elements) {
1.186     albertel 3409:     $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3410:   }
1.186     albertel 3411:   $moreenv{'grade_target'}='answer';
                   3412:   %moreenv=(%form,%moreenv);
1.497     raeburn  3413:   $feedurl = &Apache::lonnet::clutter($feedurl);
                   3414:   my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10      albertel 3415:   return $userview;
1.1       albertel 3416: }
1.116     albertel 3417: 
                   3418: =pod
                   3419: 
                   3420: =item * &submlink()
                   3421: 
1.242     albertel 3422: Inputs: $text $uname $udom $symb $target
1.116     albertel 3423: 
                   3424: Returns: A link to grades.pm such as to see the SUBM view of a student
                   3425: 
                   3426: =cut
                   3427: 
                   3428: ###############################################
                   3429: sub submlink {
1.242     albertel 3430:     my ($text,$uname,$udom,$symb,$target)=@_;
1.116     albertel 3431:     if (!($uname && $udom)) {
                   3432: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3433: 	    &Apache::lonnet::whichuser($symb);
1.116     albertel 3434: 	if (!$symb) { $symb=$cursymb; }
                   3435:     }
1.254     matthew  3436:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3437:     $symb=&escape($symb);
1.242     albertel 3438:     if ($target) { $target="target=\"$target\""; }
                   3439:     return '<a href="/adm/grades?&command=submission&'.
                   3440: 	'symb='.$symb.'&student='.$uname.
                   3441: 	'&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
                   3442: }
                   3443: ##############################################
                   3444: 
                   3445: =pod
                   3446: 
                   3447: =item * &pgrdlink()
                   3448: 
                   3449: Inputs: $text $uname $udom $symb $target
                   3450: 
                   3451: Returns: A link to grades.pm such as to see the PGRD view of a student
                   3452: 
                   3453: =cut
                   3454: 
                   3455: ###############################################
                   3456: sub pgrdlink {
                   3457:     my $link=&submlink(@_);
                   3458:     $link=~s/(&command=submission)/$1&showgrading=yes/;
                   3459:     return $link;
                   3460: }
                   3461: ##############################################
                   3462: 
                   3463: =pod
                   3464: 
                   3465: =item * &pprmlink()
                   3466: 
                   3467: Inputs: $text $uname $udom $symb $target
                   3468: 
                   3469: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283     albertel 3470: student and a specific resource
1.242     albertel 3471: 
                   3472: =cut
                   3473: 
                   3474: ###############################################
                   3475: sub pprmlink {
                   3476:     my ($text,$uname,$udom,$symb,$target)=@_;
                   3477:     if (!($uname && $udom)) {
                   3478: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3479: 	    &Apache::lonnet::whichuser($symb);
1.242     albertel 3480: 	if (!$symb) { $symb=$cursymb; }
                   3481:     }
1.254     matthew  3482:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3483:     $symb=&escape($symb);
1.242     albertel 3484:     if ($target) { $target="target=\"$target\""; }
1.595     albertel 3485:     return '<a href="/adm/parmset?command=set&amp;'.
                   3486: 	'symb='.$symb.'&amp;uname='.$uname.
                   3487: 	'&amp;udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116     albertel 3488: }
                   3489: ##############################################
1.37      matthew  3490: 
1.112     bowersj2 3491: =pod
                   3492: 
                   3493: =back
                   3494: 
                   3495: =cut
                   3496: 
1.37      matthew  3497: ###############################################
1.51      www      3498: 
                   3499: 
                   3500: sub timehash {
1.687     raeburn  3501:     my ($thistime) = @_;
                   3502:     my $timezone = &Apache::lonlocal::gettimezone();
                   3503:     my $dt = DateTime->from_epoch(epoch => $thistime)
                   3504:                      ->set_time_zone($timezone);
                   3505:     my $wday = $dt->day_of_week();
                   3506:     if ($wday == 7) { $wday = 0; }
                   3507:     return ( 'second' => $dt->second(),
                   3508:              'minute' => $dt->minute(),
                   3509:              'hour'   => $dt->hour(),
                   3510:              'day'     => $dt->day_of_month(),
                   3511:              'month'   => $dt->month(),
                   3512:              'year'    => $dt->year(),
                   3513:              'weekday' => $wday,
                   3514:              'dayyear' => $dt->day_of_year(),
                   3515:              'dlsav'   => $dt->is_dst() );
1.51      www      3516: }
                   3517: 
1.370     www      3518: sub utc_string {
                   3519:     my ($date)=@_;
1.371     www      3520:     return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370     www      3521: }
                   3522: 
1.51      www      3523: sub maketime {
                   3524:     my %th=@_;
1.687     raeburn  3525:     my ($epoch_time,$timezone,$dt);
                   3526:     $timezone = &Apache::lonlocal::gettimezone();
                   3527:     eval {
                   3528:         $dt = DateTime->new( year   => $th{'year'},
                   3529:                              month  => $th{'month'},
                   3530:                              day    => $th{'day'},
                   3531:                              hour   => $th{'hour'},
                   3532:                              minute => $th{'minute'},
                   3533:                              second => $th{'second'},
                   3534:                              time_zone => $timezone,
                   3535:                          );
                   3536:     };
                   3537:     if (!$@) {
                   3538:         $epoch_time = $dt->epoch;
                   3539:         if ($epoch_time) {
                   3540:             return $epoch_time;
                   3541:         }
                   3542:     }
1.51      www      3543:     return POSIX::mktime(
                   3544:         ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210     www      3545:          $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70      www      3546: }
                   3547: 
                   3548: #########################################
1.51      www      3549: 
                   3550: sub findallcourses {
1.482     raeburn  3551:     my ($roles,$uname,$udom) = @_;
1.355     albertel 3552:     my %roles;
                   3553:     if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348     albertel 3554:     my %courses;
1.51      www      3555:     my $now=time;
1.482     raeburn  3556:     if (!defined($uname)) {
                   3557:         $uname = $env{'user.name'};
                   3558:     }
                   3559:     if (!defined($udom)) {
                   3560:         $udom = $env{'user.domain'};
                   3561:     }
                   3562:     if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
                   3563:         my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
                   3564:         if (!%roles) {
                   3565:             %roles = (
                   3566:                        cc => 1,
                   3567:                        in => 1,
                   3568:                        ep => 1,
                   3569:                        ta => 1,
                   3570:                        cr => 1,
                   3571:                        st => 1,
                   3572:              );
                   3573:         }
                   3574:         foreach my $entry (keys(%roleshash)) {
                   3575:             my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
                   3576:             if ($trole =~ /^cr/) { 
                   3577:                 next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
                   3578:             } else {
                   3579:                 next if (!exists($roles{$trole}));
                   3580:             }
                   3581:             if ($tend) {
                   3582:                 next if ($tend < $now);
                   3583:             }
                   3584:             if ($tstart) {
                   3585:                 next if ($tstart > $now);
                   3586:             }
                   3587:             my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
                   3588:             (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
                   3589:             if ($secpart eq '') {
                   3590:                 ($cnum,$role) = split(/_/,$cnumpart); 
                   3591:                 $sec = 'none';
                   3592:                 $realsec = '';
                   3593:             } else {
                   3594:                 $cnum = $cnumpart;
                   3595:                 ($sec,$role) = split(/_/,$secpart);
                   3596:                 $realsec = $sec;
1.490     raeburn  3597:             }
1.482     raeburn  3598:             $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
                   3599:         }
                   3600:     } else {
                   3601:         foreach my $key (keys(%env)) {
1.483     albertel 3602: 	    if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
                   3603:                  $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482     raeburn  3604: 	        my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
                   3605: 	        next if ($role eq 'ca' || $role eq 'aa');
                   3606: 	        next if (%roles && !exists($roles{$role}));
                   3607: 	        my ($starttime,$endtime)=split(/\./,$env{$key});
                   3608:                 my $active=1;
                   3609:                 if ($starttime) {
                   3610: 		    if ($now<$starttime) { $active=0; }
                   3611:                 }
                   3612:                 if ($endtime) {
                   3613:                     if ($now>$endtime) { $active=0; }
                   3614:                 }
                   3615:                 if ($active) {
                   3616:                     if ($sec eq '') {
                   3617:                         $sec = 'none';
                   3618:                     }
                   3619:                     $courses{$cdom.'_'.$cnum}{$sec} = 
                   3620:                                      $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474     raeburn  3621:                 }
                   3622:             }
1.51      www      3623:         }
                   3624:     }
1.474     raeburn  3625:     return %courses;
1.51      www      3626: }
1.37      matthew  3627: 
1.54      www      3628: ###############################################
1.474     raeburn  3629: 
                   3630: sub blockcheck {
1.482     raeburn  3631:     my ($setters,$activity,$uname,$udom) = @_;
1.490     raeburn  3632: 
                   3633:     if (!defined($udom)) {
                   3634:         $udom = $env{'user.domain'};
                   3635:     }
                   3636:     if (!defined($uname)) {
                   3637:         $uname = $env{'user.name'};
                   3638:     }
                   3639: 
                   3640:     # If uname and udom are for a course, check for blocks in the course.
                   3641: 
                   3642:     if (&Apache::lonnet::is_course($udom,$uname)) {
                   3643:         my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502     raeburn  3644:         my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490     raeburn  3645:         return ($startblock,$endblock);
                   3646:     }
1.474     raeburn  3647: 
1.502     raeburn  3648:     my $startblock = 0;
                   3649:     my $endblock = 0;
1.482     raeburn  3650:     my %live_courses = &findallcourses(undef,$uname,$udom);
1.474     raeburn  3651: 
1.490     raeburn  3652:     # If uname is for a user, and activity is course-specific, i.e.,
                   3653:     # boards, chat or groups, check for blocking in current course only.
1.474     raeburn  3654: 
1.490     raeburn  3655:     if (($activity eq 'boards' || $activity eq 'chat' ||
                   3656:          $activity eq 'groups') && ($env{'request.course.id'})) {
                   3657:         foreach my $key (keys(%live_courses)) {
                   3658:             if ($key ne $env{'request.course.id'}) {
                   3659:                 delete($live_courses{$key});
                   3660:             }
                   3661:         }
                   3662:     }
                   3663: 
                   3664:     my $otheruser = 0;
                   3665:     my %own_courses;
                   3666:     if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
                   3667:         # Resource belongs to user other than current user.
                   3668:         $otheruser = 1;
                   3669:         # Gather courses for current user
                   3670:         %own_courses = 
                   3671:             &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
                   3672:     }
                   3673: 
                   3674:     # Gather active course roles - course coordinator, instructor, 
                   3675:     # exam proctor, ta, student, or custom role.
1.474     raeburn  3676: 
                   3677:     foreach my $course (keys(%live_courses)) {
1.482     raeburn  3678:         my ($cdom,$cnum);
                   3679:         if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
                   3680:             $cdom = $env{'course.'.$course.'.domain'};
                   3681:             $cnum = $env{'course.'.$course.'.num'};
                   3682:         } else {
1.490     raeburn  3683:             ($cdom,$cnum) = split(/_/,$course); 
1.482     raeburn  3684:         }
                   3685:         my $no_ownblock = 0;
                   3686:         my $no_userblock = 0;
1.533     raeburn  3687:         if ($otheruser && $activity ne 'com') {
1.490     raeburn  3688:             # Check if current user has 'evb' priv for this
                   3689:             if (defined($own_courses{$course})) {
                   3690:                 foreach my $sec (keys(%{$own_courses{$course}})) {
                   3691:                     my $checkrole = 'cm./'.$cdom.'/'.$cnum;
                   3692:                     if ($sec ne 'none') {
                   3693:                         $checkrole .= '/'.$sec;
                   3694:                     }
                   3695:                     if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   3696:                         $no_ownblock = 1;
                   3697:                         last;
                   3698:                     }
                   3699:                 }
                   3700:             }
                   3701:             # if they have 'evb' priv and are currently not playing student
                   3702:             next if (($no_ownblock) &&
                   3703:                  ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
                   3704:         }
1.474     raeburn  3705:         foreach my $sec (keys(%{$live_courses{$course}})) {
1.482     raeburn  3706:             my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474     raeburn  3707:             if ($sec ne 'none') {
1.482     raeburn  3708:                 $checkrole .= '/'.$sec;
1.474     raeburn  3709:             }
1.490     raeburn  3710:             if ($otheruser) {
                   3711:                 # Resource belongs to user other than current user.
                   3712:                 # Assemble privs for that user, and check for 'evb' priv.
1.482     raeburn  3713:                 my ($trole,$tdom,$tnum,$tsec);
                   3714:                 my $entry = $live_courses{$course}{$sec};
                   3715:                 if ($entry =~ /^cr/) {
                   3716:                     ($trole,$tdom,$tnum,$tsec) = 
                   3717:                       ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
                   3718:                 } else {
                   3719:                     ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
                   3720:                 }
                   3721:                 my ($spec,$area,$trest,%allroles,%userroles);
                   3722:                 $area = '/'.$tdom.'/'.$tnum;
                   3723:                 $trest = $tnum;
                   3724:                 if ($tsec ne '') {
                   3725:                     $area .= '/'.$tsec;
                   3726:                     $trest .= '/'.$tsec;
                   3727:                 }
                   3728:                 $spec = $trole.'.'.$area;
                   3729:                 if ($trole =~ /^cr/) {
                   3730:                     &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
                   3731:                                                       $tdom,$spec,$trest,$area);
                   3732:                 } else {
                   3733:                     &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
                   3734:                                                        $tdom,$spec,$trest,$area);
                   3735:                 }
                   3736:                 my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486     raeburn  3737:                 if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
                   3738:                     if ($1) {
                   3739:                         $no_userblock = 1;
                   3740:                         last;
                   3741:                     }
                   3742:                 }
1.490     raeburn  3743:             } else {
                   3744:                 # Resource belongs to current user
                   3745:                 # Check for 'evb' priv via lonnet::allowed().
1.482     raeburn  3746:                 if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   3747:                     $no_ownblock = 1;
                   3748:                     last;
                   3749:                 }
1.474     raeburn  3750:             }
                   3751:         }
                   3752:         # if they have the evb priv and are currently not playing student
1.482     raeburn  3753:         next if (($no_ownblock) &&
1.491     albertel 3754:                  ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482     raeburn  3755:         next if ($no_userblock);
1.474     raeburn  3756: 
1.490     raeburn  3757:         # Retrieve blocking times and identity of blocker for course
                   3758:         # of specified user, unless user has 'evb' privilege.
1.502     raeburn  3759:         
                   3760:         my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
                   3761:         if (($start != 0) && 
                   3762:             (($startblock == 0) || ($startblock > $start))) {
                   3763:             $startblock = $start;
                   3764:         }
                   3765:         if (($end != 0)  &&
                   3766:             (($endblock == 0) || ($endblock < $end))) {
                   3767:             $endblock = $end;
                   3768:         }
1.490     raeburn  3769:     }
                   3770:     return ($startblock,$endblock);
                   3771: }
                   3772: 
                   3773: sub get_blocks {
                   3774:     my ($setters,$activity,$cdom,$cnum) = @_;
                   3775:     my $startblock = 0;
                   3776:     my $endblock = 0;
                   3777:     my $course = $cdom.'_'.$cnum;
                   3778:     $setters->{$course} = {};
                   3779:     $setters->{$course}{'staff'} = [];
                   3780:     $setters->{$course}{'times'} = [];
                   3781:     my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
                   3782:     foreach my $record (keys(%records)) {
                   3783:         my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
                   3784:         if ($start <= time && $end >= time) {
                   3785:             my ($staff_name,$staff_dom,$title,$blocks) =
                   3786:                 &parse_block_record($records{$record});
                   3787:             if ($blocks->{$activity} eq 'on') {
                   3788:                 push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
                   3789:                 push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491     albertel 3790:                 if ( ($startblock == 0) || ($startblock > $start) ) {
                   3791:                     $startblock = $start;
1.490     raeburn  3792:                 }
1.491     albertel 3793:                 if ( ($endblock == 0) || ($endblock < $end) ) {
                   3794:                     $endblock = $end;
1.474     raeburn  3795:                 }
                   3796:             }
                   3797:         }
                   3798:     }
                   3799:     return ($startblock,$endblock);
                   3800: }
                   3801: 
                   3802: sub parse_block_record {
                   3803:     my ($record) = @_;
                   3804:     my ($setuname,$setudom,$title,$blocks);
                   3805:     if (ref($record) eq 'HASH') {
                   3806:         ($setuname,$setudom) = split(/:/,$record->{'setter'});
                   3807:         $title = &unescape($record->{'event'});
                   3808:         $blocks = $record->{'blocks'};
                   3809:     } else {
                   3810:         my @data = split(/:/,$record,3);
                   3811:         if (scalar(@data) eq 2) {
                   3812:             $title = $data[1];
                   3813:             ($setuname,$setudom) = split(/@/,$data[0]);
                   3814:         } else {
                   3815:             ($setuname,$setudom,$title) = @data;
                   3816:         }
                   3817:         $blocks = { 'com' => 'on' };
                   3818:     }
                   3819:     return ($setuname,$setudom,$title,$blocks);
                   3820: }
                   3821: 
                   3822: sub build_block_table {
                   3823:     my ($startblock,$endblock,$setters) = @_;
                   3824:     my %lt = &Apache::lonlocal::texthash(
                   3825:         'cacb' => 'Currently active communication blocks',
                   3826:         'cour' => 'Course',
                   3827:         'dura' => 'Duration',
                   3828:         'blse' => 'Block set by'
                   3829:     );
                   3830:     my $output;
1.476     raeburn  3831:     $output = '<br />'.$lt{'cacb'}.':<br />';
1.474     raeburn  3832:     $output .= &start_data_table();
                   3833:     $output .= '
                   3834: <tr>
                   3835:  <th>'.$lt{'cour'}.'</th>
                   3836:  <th>'.$lt{'dura'}.'</th>
                   3837:  <th>'.$lt{'blse'}.'</th>
                   3838: </tr>
                   3839: ';
                   3840:     foreach my $course (keys(%{$setters})) {
                   3841:         my %courseinfo=&Apache::lonnet::coursedescription($course);
                   3842:         for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
                   3843:             my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490     raeburn  3844:             my $fullname = &plainname($uname,$udom);
                   3845:             if (defined($env{'user.name'}) && defined($env{'user.domain'})
                   3846:                 && $env{'user.name'} ne 'public' 
                   3847:                 && $env{'user.domain'} ne 'public') {
                   3848:                 $fullname = &aboutmewrapper($fullname,$uname,$udom);
                   3849:             }
1.474     raeburn  3850:             my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
                   3851:             $openblock = &Apache::lonlocal::locallocaltime($openblock);
                   3852:             $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
                   3853:             $output .= &Apache::loncommon::start_data_table_row().
                   3854:                        '<td>'.$courseinfo{'description'}.'</td>'.
                   3855:                        '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490     raeburn  3856:                        '<td>'.$fullname.'</td>'.
1.474     raeburn  3857:                         &Apache::loncommon::end_data_table_row();
                   3858:         }
                   3859:     }
                   3860:     $output .= &end_data_table();
                   3861: }
                   3862: 
1.490     raeburn  3863: sub blocking_status {
                   3864:     my ($activity,$uname,$udom) = @_;
                   3865:     my %setters;
                   3866:     my ($blocked,$output,$ownitem,$is_course);
                   3867:     my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
                   3868:     if ($startblock && $endblock) {
                   3869:         $blocked = 1;
                   3870:         if (wantarray) {
                   3871:             my $category;
                   3872:             if ($activity eq 'boards') {
                   3873:                 $category = 'Discussion posts in this course';
                   3874:             } elsif ($activity eq 'blogs') {
                   3875:                 $category = 'Blogs';
                   3876:             } elsif ($activity eq 'port') {
                   3877:                 if (defined($uname) && defined($udom)) {
                   3878:                     if ($uname eq $env{'user.name'} &&
                   3879:                         $udom eq $env{'user.domain'}) {
                   3880:                         $ownitem = 1;
                   3881:                     }
                   3882:                 }
                   3883:                 $is_course = &Apache::lonnet::is_course($udom,$uname);
                   3884:                 if ($ownitem) { 
                   3885:                     $category = 'Your portfolio files';  
                   3886:                 } elsif ($is_course) {
                   3887:                     my $coursedesc;
                   3888:                     foreach my $course (keys(%setters)) {
                   3889:                         my %courseinfo =
                   3890:                              &Apache::lonnet::coursedescription($course);
                   3891:                         $coursedesc = $courseinfo{'description'};
                   3892:                     }
1.764     weissno  3893:                     $category = "Group portfolio in the course '$coursedesc'";
1.490     raeburn  3894:                 } else {
                   3895:                     $category = 'Portfolio files belonging to ';
                   3896:                     if ($env{'user.name'} eq 'public' && 
                   3897:                         $env{'user.domain'} eq 'public') {
                   3898:                         $category .= &plainname($uname,$udom);
                   3899:                     } else {
                   3900:                         $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);  
                   3901:                     }
                   3902:                 }
                   3903:             } elsif ($activity eq 'groups') {
                   3904:                 $category = 'Groups in this course';
                   3905:             }
                   3906:             my $showstart = &Apache::lonlocal::locallocaltime($startblock);
                   3907:             my $showend = &Apache::lonlocal::locallocaltime($endblock);
                   3908:             $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
                   3909:             if (!($activity eq 'port' && !($ownitem) && !($is_course))) { 
                   3910:                 $output .= &build_block_table($startblock,$endblock,\%setters);
                   3911:             }
                   3912:         }
                   3913:     }
                   3914:     if (wantarray) {
                   3915:         return ($blocked,$output);
                   3916:     } else {
                   3917:         return $blocked;
                   3918:     }
                   3919: }
                   3920: 
1.60      matthew  3921: ###############################################
                   3922: 
1.682     raeburn  3923: sub check_ip_acc {
                   3924:     my ($acc)=@_;
                   3925:     &Apache::lonxml::debug("acc is $acc");
                   3926:     if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
                   3927:         return 1;
                   3928:     }
                   3929:     my $allowed=0;
                   3930:     my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
                   3931: 
                   3932:     my $name;
                   3933:     foreach my $pattern (split(',',$acc)) {
                   3934:         $pattern =~ s/^\s*//;
                   3935:         $pattern =~ s/\s*$//;
                   3936:         if ($pattern =~ /\*$/) {
                   3937:             #35.8.*
                   3938:             $pattern=~s/\*//;
                   3939:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   3940:         } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
                   3941:             #35.8.3.[34-56]
                   3942:             my $low=$2;
                   3943:             my $high=$3;
                   3944:             $pattern=$1;
                   3945:             if ($ip =~ /^\Q$pattern\E/) {
                   3946:                 my $last=(split(/\./,$ip))[3];
                   3947:                 if ($last <=$high && $last >=$low) { $allowed=1; }
                   3948:             }
                   3949:         } elsif ($pattern =~ /^\*/) {
                   3950:             #*.msu.edu
                   3951:             $pattern=~s/\*//;
                   3952:             if (!defined($name)) {
                   3953:                 use Socket;
                   3954:                 my $netaddr=inet_aton($ip);
                   3955:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   3956:             }
                   3957:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   3958:         } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
                   3959:             #127.0.0.1
                   3960:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   3961:         } else {
                   3962:             #some.name.com
                   3963:             if (!defined($name)) {
                   3964:                 use Socket;
                   3965:                 my $netaddr=inet_aton($ip);
                   3966:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   3967:             }
                   3968:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   3969:         }
                   3970:         if ($allowed) { last; }
                   3971:     }
                   3972:     return $allowed;
                   3973: }
                   3974: 
                   3975: ###############################################
                   3976: 
1.60      matthew  3977: =pod
                   3978: 
1.112     bowersj2 3979: =head1 Domain Template Functions
                   3980: 
                   3981: =over 4
                   3982: 
                   3983: =item * &determinedomain()
1.60      matthew  3984: 
                   3985: Inputs: $domain (usually will be undef)
                   3986: 
1.63      www      3987: Returns: Determines which domain should be used for designs
1.60      matthew  3988: 
                   3989: =cut
1.54      www      3990: 
1.60      matthew  3991: ###############################################
1.63      www      3992: sub determinedomain {
                   3993:     my $domain=shift;
1.531     albertel 3994:     if (! $domain) {
1.60      matthew  3995:         # Determine domain if we have not been given one
                   3996:         $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258     albertel 3997:         if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
                   3998:         if ($env{'request.role.domain'}) { 
                   3999:             $domain=$env{'request.role.domain'}; 
1.60      matthew  4000:         }
                   4001:     }
1.63      www      4002:     return $domain;
                   4003: }
                   4004: ###############################################
1.517     raeburn  4005: 
1.518     albertel 4006: sub devalidate_domconfig_cache {
                   4007:     my ($udom)=@_;
                   4008:     &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
                   4009: }
                   4010: 
                   4011: # ---------------------- Get domain configuration for a domain
                   4012: sub get_domainconf {
                   4013:     my ($udom) = @_;
                   4014:     my $cachetime=1800;
                   4015:     my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
                   4016:     if (defined($cached)) { return %{$result}; }
                   4017: 
                   4018:     my %domconfig = &Apache::lonnet::get_dom('configuration',
                   4019: 					     ['login','rolecolors'],$udom);
1.632     raeburn  4020:     my (%designhash,%legacy);
1.518     albertel 4021:     if (keys(%domconfig) > 0) {
                   4022:         if (ref($domconfig{'login'}) eq 'HASH') {
1.632     raeburn  4023:             if (keys(%{$domconfig{'login'}})) {
                   4024:                 foreach my $key (keys(%{$domconfig{'login'}})) {
1.699     raeburn  4025:                     if (ref($domconfig{'login'}{$key}) eq 'HASH') {
                   4026:                         foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
                   4027:                             $designhash{$udom.'.login.'.$key.'_'.$img} = 
                   4028:                                 $domconfig{'login'}{$key}{$img};
                   4029:                         }
                   4030:                     } else {
                   4031:                         $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
                   4032:                     }
1.632     raeburn  4033:                 }
                   4034:             } else {
                   4035:                 $legacy{'login'} = 1;
1.518     albertel 4036:             }
1.632     raeburn  4037:         } else {
                   4038:             $legacy{'login'} = 1;
1.518     albertel 4039:         }
                   4040:         if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632     raeburn  4041:             if (keys(%{$domconfig{'rolecolors'}})) {
                   4042:                 foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
                   4043:                     if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
                   4044:                         foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
                   4045:                             $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
                   4046:                         }
1.518     albertel 4047:                     }
                   4048:                 }
1.632     raeburn  4049:             } else {
                   4050:                 $legacy{'rolecolors'} = 1;
1.518     albertel 4051:             }
1.632     raeburn  4052:         } else {
                   4053:             $legacy{'rolecolors'} = 1;
1.518     albertel 4054:         }
1.632     raeburn  4055:         if (keys(%legacy) > 0) {
                   4056:             my %legacyhash = &get_legacy_domconf($udom);
                   4057:             foreach my $item (keys(%legacyhash)) {
                   4058:                 if ($item =~ /^\Q$udom\E\.login/) {
                   4059:                     if ($legacy{'login'}) { 
                   4060:                         $designhash{$item} = $legacyhash{$item};
                   4061:                     }
                   4062:                 } else {
                   4063:                     if ($legacy{'rolecolors'}) {
                   4064:                         $designhash{$item} = $legacyhash{$item};
                   4065:                     }
1.518     albertel 4066:                 }
                   4067:             }
                   4068:         }
1.632     raeburn  4069:     } else {
                   4070:         %designhash = &get_legacy_domconf($udom); 
1.518     albertel 4071:     }
                   4072:     &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
                   4073: 				  $cachetime);
                   4074:     return %designhash;
                   4075: }
                   4076: 
1.632     raeburn  4077: sub get_legacy_domconf {
                   4078:     my ($udom) = @_;
                   4079:     my %legacyhash;
                   4080:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
                   4081:     my $designfile =  $designdir.'/'.$udom.'.tab';
                   4082:     if (-e $designfile) {
                   4083:         if ( open (my $fh,"<$designfile") ) {
                   4084:             while (my $line = <$fh>) {
                   4085:                 next if ($line =~ /^\#/);
                   4086:                 chomp($line);
                   4087:                 my ($key,$val)=(split(/\=/,$line));
                   4088:                 if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
                   4089:             }
                   4090:             close($fh);
                   4091:         }
                   4092:     }
                   4093:     if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
                   4094:         $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
                   4095:     }
                   4096:     return %legacyhash;
                   4097: }
                   4098: 
1.63      www      4099: =pod
                   4100: 
1.112     bowersj2 4101: =item * &domainlogo()
1.63      www      4102: 
                   4103: Inputs: $domain (usually will be undef)
                   4104: 
                   4105: Returns: A link to a domain logo, if the domain logo exists.
                   4106: If the domain logo does not exist, a description of the domain.
                   4107: 
                   4108: =cut
1.112     bowersj2 4109: 
1.63      www      4110: ###############################################
                   4111: sub domainlogo {
1.517     raeburn  4112:     my $domain = &determinedomain(shift);
1.518     albertel 4113:     my %designhash = &get_domainconf($domain);    
1.517     raeburn  4114:     # See if there is a logo
                   4115:     if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519     raeburn  4116:         my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538     albertel 4117:         if ($imgsrc =~ m{^/(adm|res)/}) {
                   4118: 	    if ($imgsrc =~ m{^/res/}) {
                   4119: 		my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
                   4120: 		&Apache::lonnet::repcopy($local_name);
                   4121: 	    }
                   4122: 	   $imgsrc = &lonhttpdurl($imgsrc);
1.519     raeburn  4123:         } 
                   4124:         return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514     albertel 4125:     } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
                   4126:         return &Apache::lonnet::domain($domain,'description');
1.59      www      4127:     } else {
1.60      matthew  4128:         return '';
1.59      www      4129:     }
                   4130: }
1.63      www      4131: ##############################################
                   4132: 
                   4133: =pod
                   4134: 
1.112     bowersj2 4135: =item * &designparm()
1.63      www      4136: 
                   4137: Inputs: $which parameter; $domain (usually will be undef)
                   4138: 
                   4139: Returns: value of designparamter $which
                   4140: 
                   4141: =cut
1.112     bowersj2 4142: 
1.397     albertel 4143: 
1.400     albertel 4144: ##############################################
1.397     albertel 4145: sub designparm {
                   4146:     my ($which,$domain)=@_;
1.258     albertel 4147:     if ($env{'browser.blackwhite'} eq 'on') {
1.635     raeburn  4148: 	if ($which=~/\.(font|alink|vlink|link|textcol)$/) {
1.110     www      4149: 	    return '#000000';
                   4150: 	}
1.635     raeburn  4151: 	if ($which=~/\.(pgbg|sidebg|bgcol)$/) {
1.110     www      4152: 	    return '#FFFFFF';
                   4153: 	}
                   4154: 	if ($which=~/\.tabbg$/) {
                   4155: 	    return '#CCCCCC';
                   4156: 	}
                   4157:     }
1.397     albertel 4158:     if (exists($env{'environment.color.'.$which})) {
1.258     albertel 4159: 	return $env{'environment.color.'.$which};
1.96      www      4160:     }
1.63      www      4161:     $domain=&determinedomain($domain);
1.518     albertel 4162:     my %domdesign = &get_domainconf($domain);
1.520     raeburn  4163:     my $output;
1.517     raeburn  4164:     if ($domdesign{$domain.'.'.$which} ne '') {
1.520     raeburn  4165: 	$output = $domdesign{$domain.'.'.$which};
1.63      www      4166:     } else {
1.520     raeburn  4167:         $output = $defaultdesign{$which};
                   4168:     }
                   4169:     if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635     raeburn  4170:         ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538     albertel 4171:         if ($output =~ m{^/(adm|res)/}) {
                   4172: 	    if ($output =~ m{^/res/}) {
                   4173: 		my $local_name = &Apache::lonnet::filelocation('',$output);
                   4174: 		&Apache::lonnet::repcopy($local_name);
                   4175: 	    }
1.520     raeburn  4176:             $output = &lonhttpdurl($output);
                   4177:         }
1.63      www      4178:     }
1.520     raeburn  4179:     return $output;
1.63      www      4180: }
1.59      www      4181: 
1.60      matthew  4182: ###############################################
                   4183: ###############################################
                   4184: 
                   4185: =pod
                   4186: 
1.112     bowersj2 4187: =back
                   4188: 
1.549     albertel 4189: =head1 HTML Helpers
1.112     bowersj2 4190: 
                   4191: =over 4
                   4192: 
                   4193: =item * &bodytag()
1.60      matthew  4194: 
                   4195: Returns a uniform header for LON-CAPA web pages.
                   4196: 
                   4197: Inputs: 
                   4198: 
1.112     bowersj2 4199: =over 4
                   4200: 
                   4201: =item * $title, A title to be displayed on the page.
                   4202: 
                   4203: =item * $function, the current role (can be undef).
                   4204: 
                   4205: =item * $addentries, extra parameters for the <body> tag.
                   4206: 
                   4207: =item * $bodyonly, if defined, only return the <body> tag.
                   4208: 
                   4209: =item * $domain, if defined, force a given domain.
                   4210: 
                   4211: =item * $forcereg, if page should register as content page (relevant for 
1.86      www      4212:             text interface only)
1.60      matthew  4213: 
1.326     albertel 4214: =item * $customtitle, alternate text to use instead of $title
                   4215:                       in the title box that appears, this text
                   4216:                       is not auto translated like the $title is
1.309     albertel 4217: 
                   4218: =item * $notopbar, if true, keep the 'what is this' info but remove the
                   4219:                    navigational links
1.317     albertel 4220: 
1.338     albertel 4221: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
                   4222: 
                   4223: =item * $notitle, if true keep the nav controls, but remove the title bar
                   4224: 
1.361     albertel 4225: =item * $no_inline_link, if true and in remote mode, don't show the 
                   4226:          'Switch To Inline Menu' link
                   4227: 
1.460     albertel 4228: =item * $args, optional argument valid values are
                   4229:             no_auto_mt_title -> prevents &mt()ing the title arg
1.562     albertel 4230:             inherit_jsmath -> when creating popup window in a page,
                   4231:                               should it have jsmath forced on by the
                   4232:                               current page
1.460     albertel 4233: 
1.112     bowersj2 4234: =back
                   4235: 
1.60      matthew  4236: Returns: A uniform header for LON-CAPA web pages.  
                   4237: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
                   4238: If $bodyonly is undef or zero, an html string containing a <body> tag and 
                   4239: other decorations will be returned.
                   4240: 
                   4241: =cut
                   4242: 
1.54      www      4243: sub bodytag {
1.309     albertel 4244:     my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
1.460     albertel 4245: 	$notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
1.339     albertel 4246: 
1.460     albertel 4247:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339     albertel 4248: 
1.183     matthew  4249:     $function = &get_users_function() if (!$function);
1.339     albertel 4250:     my $img =    &designparm($function.'.img',$domain);
                   4251:     my $font =   &designparm($function.'.font',$domain);
                   4252:     my $pgbg   = $bgcolor || &designparm($function.'.pgbg',$domain);
                   4253: 
1.803     bisitz   4254:     my %design = ( 'style'   => 'margin-top: 0',
1.535     albertel 4255: 		   'bgcolor' => $pgbg,
1.339     albertel 4256: 		   'text'    => $font,
                   4257:                    'alink'   => &designparm($function.'.alink',$domain),
                   4258: 		   'vlink'   => &designparm($function.'.vlink',$domain),
                   4259: 		   'link'    => &designparm($function.'.link',$domain),);
1.438     albertel 4260:     @design{keys(%$addentries)} = @$addentries{keys(%$addentries)}; 
1.339     albertel 4261: 
1.63      www      4262:  # role and realm
1.378     raeburn  4263:     my ($role,$realm) = split(/\./,$env{'request.role'},2);
                   4264:     if ($role  eq 'ca') {
1.479     albertel 4265:         my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500     albertel 4266:         $realm = &plainname($rname,$rdom);
1.378     raeburn  4267:     } 
1.55      www      4268: # realm
1.258     albertel 4269:     if ($env{'request.course.id'}) {
1.378     raeburn  4270:         if ($env{'request.role'} !~ /^cr/) {
                   4271:             $role = &Apache::lonnet::plaintext($role,&course_type());
                   4272:         }
1.359     albertel 4273: 	$realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378     raeburn  4274:     } else {
                   4275:         $role = &Apache::lonnet::plaintext($role);
1.54      www      4276:     }
1.433     albertel 4277: 
1.359     albertel 4278:     if (!$realm) { $realm='&nbsp;'; }
1.55      www      4279: # Set messages
1.60      matthew  4280:     my $messages=&domainlogo($domain);
1.330     albertel 4281: 
1.438     albertel 4282:     my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329     albertel 4283: 
1.101     www      4284: # construct main body tag
1.359     albertel 4285:     my $bodytag = "<body $extra_body_attr>".
1.562     albertel 4286: 	&Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252     albertel 4287: 
1.530     albertel 4288:     if ($bodyonly) {
1.60      matthew  4289:         return $bodytag;
1.798     tempelho 4290:     } 
1.359     albertel 4291: 
1.410     albertel 4292:     my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433     albertel 4293:     if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
                   4294: 	undef($role);
1.434     albertel 4295:     } else {
                   4296: 	$name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433     albertel 4297:     }
1.359     albertel 4298:     
                   4299:     my $roleinfo=(<<ENDROLE);
                   4300: <td class="LC_title_bar_who">
                   4301: <div class="LC_title_bar_name">
1.410     albertel 4302:     $name
1.361     albertel 4303:     &nbsp;
1.359     albertel 4304: </div>
                   4305: <div class="LC_title_bar_role">
1.361     albertel 4306: $role&nbsp;
1.359     albertel 4307: </div>
                   4308: <div class="LC_title_bar_realm">
1.361     albertel 4309: $realm&nbsp;
1.359     albertel 4310: </div>
1.206     albertel 4311: </td>
                   4312: ENDROLE
1.235     raeburn  4313: 
1.762     bisitz   4314:     my $titleinfo = '<h1>'.$title.'</h1>';
1.359     albertel 4315:     if ($customtitle) {
                   4316:         $titleinfo = $customtitle;
                   4317:     }
                   4318:     #
                   4319:     # Extra info if you are the DC
                   4320:     my $dc_info = '';
                   4321:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   4322:                         $env{'course.'.$env{'request.course.id'}.
                   4323:                                  '.domain'}.'/'})) {
                   4324:         my $cid = $env{'request.course.id'};
                   4325:         $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380     www      4326:         $dc_info =~ s/\s+$//;
1.359     albertel 4327:         $dc_info = '('.$dc_info.')';
                   4328:     }
                   4329: 
1.644     www      4330:     if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) {
1.359     albertel 4331:         # No Remote
1.258     albertel 4332: 	if ($env{'request.state'} eq 'construct') {
1.359     albertel 4333: 	    $forcereg=1;
                   4334: 	}
                   4335: 
                   4336: 	if (!$customtitle && $env{'request.state'} eq 'construct') {
                   4337: 	    # this is for resources; directories have customtitle, and crumbs
                   4338:             # and select recent are created in lonpubdir.pm  
1.229     albertel 4339: 	    my ($uname,$thisdisfn)=
1.258     albertel 4340: 		($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
1.229     albertel 4341: 	    my $formaction='/priv/'.$uname.'/'.$thisdisfn;
                   4342: 	    $formaction=~s/\/+/\//g;
                   4343: 
1.359     albertel 4344: 	    my $parentpath = '';
                   4345: 	    my $lastitem = '';
                   4346: 	    if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
                   4347: 		$parentpath = $1;
                   4348: 		$lastitem = $2;
                   4349: 	    } else {
                   4350: 		$lastitem = $thisdisfn;
                   4351: 	    }
                   4352: 	    $titleinfo = 
1.640     bisitz   4353: 		&Apache::loncommon::help_open_menu('','',3,'Authoring')
                   4354: 		.'<b>'.&mt('Construction Space').'</b>:&nbsp;'
                   4355: 		.'<form name="dirs" method="post" action="'.$formaction
1.359     albertel 4356: 		.'" target="_top"><tt><b>'
1.705     tempelho 4357: 		.&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<span class=\"LC_fontsize_big\">$lastitem</span></b></tt><br />"
1.359     albertel 4358: 		.&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
                   4359: 		.'</form>'
                   4360: 		.&Apache::lonmenu::constspaceform();
1.235     raeburn  4361:         }
1.359     albertel 4362: 
1.337     albertel 4363:         my $titletable;
1.338     albertel 4364: 	if (!$notitle) {
1.337     albertel 4365: 	    $titletable =
1.359     albertel 4366: 		'<table id="LC_title_bar">'.
                   4367:                          "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
                   4368: 			 '</tr></table>';
1.337     albertel 4369: 	}
1.359     albertel 4370: 	if ($notopbar) {
                   4371: 	    $bodytag .= $titletable;
                   4372: 	} else {
1.807     droeschl 4373:         $bodytag .= qq|<div id="head_userinfo">$name ($role) <br/>
1.808     droeschl 4374:             <em>$realm</em>$dc_info</div>|;
1.359     albertel 4375: 	    if ($env{'request.state'} eq 'construct') {
1.337     albertel 4376:                 $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
                   4377: 							  $titletable);
1.272     raeburn  4378:             } else {
1.336     albertel 4379:                 $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
1.359     albertel 4380: 		    $titletable;
1.272     raeburn  4381:             }
1.235     raeburn  4382:         }
                   4383:         return $bodytag;
1.94      www      4384:     }
1.95      www      4385: 
1.93      www      4386: #
1.95      www      4387: # Top frame rendering, Remote is up
1.93      www      4388: #
1.359     albertel 4389: 
1.517     raeburn  4390:     my $imgsrc = $img;
                   4391:     if ($img =~ /^\/adm/) {
1.575     albertel 4392:         $imgsrc = &lonhttpdurl($img);
1.517     raeburn  4393:     }
                   4394:     my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359     albertel 4395: 
1.305     www      4396:     # Explicit link to get inline menu
1.361     albertel 4397:     my $menu= ($no_inline_link?''
                   4398: 	       :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
1.245     matthew  4399:     #
1.338     albertel 4400:     if ($notitle) {
1.337     albertel 4401: 	return $bodytag;
                   4402:     }
1.94      www      4403:     return(<<ENDBODY);
1.60      matthew  4404: $bodytag
1.359     albertel 4405: <table id="LC_title_bar" class="LC_with_remote">
1.791     tempelho 4406: <tr><td>$upperleft</td>
                   4407:     <td>$messages&nbsp;</td>
1.54      www      4408: </tr>
1.359     albertel 4409: <tr><td>$titleinfo $dc_info $menu</td>
                   4410: $roleinfo
1.368     albertel 4411: </tr>
1.356     albertel 4412: </table>
1.54      www      4413: ENDBODY
1.182     matthew  4414: }
                   4415: 
1.330     albertel 4416: sub make_attr_string {
                   4417:     my ($register,$attr_ref) = @_;
                   4418: 
                   4419:     if ($attr_ref && !ref($attr_ref)) {
                   4420: 	die("addentries Must be a hash ref ".
                   4421: 	    join(':',caller(1))." ".
                   4422: 	    join(':',caller(0))." ");
                   4423:     }
                   4424: 
                   4425:     if ($register) {
1.339     albertel 4426: 	my ($on_load,$on_unload);
                   4427: 	foreach my $key (keys(%{$attr_ref})) {
                   4428: 	    if      (lc($key) eq 'onload') {
                   4429: 		$on_load.=$attr_ref->{$key}.';';
                   4430: 		delete($attr_ref->{$key});
                   4431: 
                   4432: 	    } elsif (lc($key) eq 'onunload') {
                   4433: 		$on_unload.=$attr_ref->{$key}.';';
                   4434: 		delete($attr_ref->{$key});
                   4435: 	    }
                   4436: 	}
                   4437: 	$attr_ref->{'onload'}  =
                   4438: 	    &Apache::lonmenu::loadevents().  $on_load;
                   4439: 	$attr_ref->{'onunload'}=
                   4440: 	    &Apache::lonmenu::unloadevents().$on_unload;
                   4441:     }
                   4442: 
                   4443: # Accessibility font enhance
                   4444:     if ($env{'browser.fontenhance'} eq 'on') {
                   4445: 	my $style;
                   4446: 	foreach my $key (keys(%{$attr_ref})) {
                   4447: 	    if (lc($key) eq 'style') {
                   4448: 		$style.=$attr_ref->{$key}.';';
                   4449: 		delete($attr_ref->{$key});
                   4450: 	    }
                   4451: 	}
                   4452: 	$attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330     albertel 4453:     }
1.339     albertel 4454: 
                   4455:     if ($env{'browser.blackwhite'} eq 'on') {
                   4456: 	delete($attr_ref->{'font'});
                   4457: 	delete($attr_ref->{'link'});
                   4458: 	delete($attr_ref->{'alink'});
                   4459: 	delete($attr_ref->{'vlink'});
                   4460: 	delete($attr_ref->{'bgcolor'});
                   4461: 	delete($attr_ref->{'background'});
                   4462:     }
                   4463: 
1.330     albertel 4464:     my $attr_string;
                   4465:     foreach my $attr (keys(%$attr_ref)) {
                   4466: 	$attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
                   4467:     }
                   4468:     return $attr_string;
                   4469: }
                   4470: 
                   4471: 
1.182     matthew  4472: ###############################################
1.251     albertel 4473: ###############################################
                   4474: 
                   4475: =pod
                   4476: 
                   4477: =item * &endbodytag()
                   4478: 
                   4479: Returns a uniform footer for LON-CAPA web pages.
                   4480: 
1.635     raeburn  4481: Inputs: 1 - optional reference to an args hash
                   4482: If in the hash, key for noredirectlink has a value which evaluates to true,
                   4483: a 'Continue' link is not displayed if the page contains an
                   4484: internal redirect in the <head></head> section,
                   4485: i.e., $env{'internal.head.redirect'} exists   
1.251     albertel 4486: 
                   4487: =cut
                   4488: 
                   4489: sub endbodytag {
1.635     raeburn  4490:     my ($args) = @_;
1.251     albertel 4491:     my $endbodytag='</body>';
1.269     albertel 4492:     $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315     albertel 4493:     if ( exists( $env{'internal.head.redirect'} ) ) {
1.635     raeburn  4494:         if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
                   4495: 	    $endbodytag=
                   4496: 	        "<br /><a href=\"$env{'internal.head.redirect'}\">".
                   4497: 	        &mt('Continue').'</a>'.
                   4498: 	        $endbodytag;
                   4499:         }
1.315     albertel 4500:     }
1.251     albertel 4501:     return $endbodytag;
                   4502: }
                   4503: 
1.352     albertel 4504: =pod
                   4505: 
                   4506: =item * &standard_css()
                   4507: 
                   4508: Returns a style sheet
                   4509: 
                   4510: Inputs: (all optional)
                   4511:             domain         -> force to color decorate a page for a specific
                   4512:                                domain
                   4513:             function       -> force usage of a specific rolish color scheme
                   4514:             bgcolor        -> override the default page bgcolor
                   4515: 
                   4516: =cut
                   4517: 
1.343     albertel 4518: sub standard_css {
1.345     albertel 4519:     my ($function,$domain,$bgcolor) = @_;
1.352     albertel 4520:     $function  = &get_users_function() if (!$function);
                   4521:     my $img    = &designparm($function.'.img',   $domain);
                   4522:     my $tabbg  = &designparm($function.'.tabbg', $domain);
                   4523:     my $font   = &designparm($function.'.font',  $domain);
1.801     tempelho 4524:     my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791     tempelho 4525: #second colour for later usage
1.345     albertel 4526:     my $sidebg = &designparm($function.'.sidebg',$domain);
1.382     albertel 4527:     my $pgbg_or_bgcolor =
                   4528: 	         $bgcolor ||
1.352     albertel 4529: 	         &designparm($function.'.pgbg',  $domain);
1.382     albertel 4530:     my $pgbg   = &designparm($function.'.pgbg',  $domain);
1.352     albertel 4531:     my $alink  = &designparm($function.'.alink', $domain);
                   4532:     my $vlink  = &designparm($function.'.vlink', $domain);
                   4533:     my $link   = &designparm($function.'.link',  $domain);
                   4534: 
1.704     muellerd 4535:     my $loginbg = &designparm('login.sidebg',$domain);
1.712     muellerd 4536:     my $bgcol = &designparm('login.bgcol',$domain);
                   4537:     my $textcol = &designparm('login.textcol',$domain);
1.704     muellerd 4538: 
1.602     albertel 4539:     my $sans                 = 'Verdana,Arial,Helvetica,sans-serif';
1.395     albertel 4540:     my $mono                 = 'monospace';
1.352     albertel 4541:     my $data_table_head      = $tabbg;
                   4542:     my $data_table_light     = '#EEEEEE';
1.470     banghart 4543:     my $data_table_dark      = '#DDDDDD';
                   4544:     my $data_table_darker    = '#CCCCCC';
1.349     albertel 4545:     my $data_table_highlight = '#FFFF00';
1.352     albertel 4546:     my $mail_new             = '#FFBB77';
                   4547:     my $mail_new_hover       = '#DD9955';
                   4548:     my $mail_read            = '#BBBB77';
                   4549:     my $mail_read_hover      = '#999944';
                   4550:     my $mail_replied         = '#AAAA88';
                   4551:     my $mail_replied_hover   = '#888855';
                   4552:     my $mail_other           = '#99BBBB';
                   4553:     my $mail_other_hover     = '#669999';
1.391     albertel 4554:     my $table_header         = '#DDDDDD';
1.489     raeburn  4555:     my $feedback_link_bg     = '#BBBBBB';
1.701     harmsja  4556:     my $lg_border_color	     = '#C8C8C8';
1.392     albertel 4557: 
1.608     albertel 4558:     my $border = ($env{'browser.type'} eq 'explorer' ||
1.803     bisitz   4559: 		  $env{'browser.type'} eq 'safari'     ) ? '0 2px 0 2px'
                   4560: 	                                                 : '0 3px 0 4px';
1.448     albertel 4561: 
1.523     albertel 4562: 
1.343     albertel 4563:     return <<END;
1.795     www      4564: body {
                   4565:    font-family: $sans;
                   4566:    line-height:130%;
                   4567:    font-size:0.83em;
                   4568:    color:$font;
                   4569: }
                   4570: 
                   4571: a:link, a:visited { 
                   4572:   font-size:100%; 
                   4573: }
                   4574: 
                   4575: a:focus { 
                   4576:   color: red;
                   4577:   background: yellow 
                   4578: }
1.698     harmsja  4579: 
1.795     www      4580: form, .inline { 
                   4581:    display: inline; 
                   4582: }
1.721     harmsja  4583: 
1.795     www      4584: .LC_right {
                   4585:    text-align:right;
                   4586: }
                   4587: 
                   4588: .LC_middle {
                   4589:    vertical-align:middle;
                   4590: }
1.721     harmsja  4591: 
                   4592: /* just for tests */
1.754     droeschl 4593: .LC_400Box {width:400px; }
1.721     harmsja  4594: /* end */
                   4595: 
1.778     bisitz   4596: .LC_filename {
                   4597:   font-family: $mono;
                   4598:   white-space:pre;
                   4599: }
                   4600: 
                   4601: .LC_fileicon {
                   4602:   border: none;
                   4603:   height: 1.3em;
                   4604:   vertical-align: text-bottom;
                   4605:   margin-right: 0.3em;
                   4606:   text-decoration:none;
                   4607: }
                   4608: 
1.350     albertel 4609: .LC_error {
                   4610:   color: red;
                   4611:   font-size: larger;
                   4612: }
1.795     www      4613: 
1.457     albertel 4614: .LC_warning,
                   4615: .LC_diff_removed {
1.733     bisitz   4616:   color: red;
1.394     albertel 4617: }
1.532     albertel 4618: 
                   4619: .LC_info,
1.457     albertel 4620: .LC_success,
                   4621: .LC_diff_added {
1.350     albertel 4622:   color: green;
                   4623: }
1.795     www      4624: 
1.802     bisitz   4625: div.LC_confirm_box {
                   4626:   background-color: #FAFAFA;
                   4627:   border: 1px solid $lg_border_color;
                   4628:   margin-right: 0;
                   4629:   padding: 5px;
                   4630: }
                   4631: 
                   4632: div.LC_confirm_box .LC_error img,
                   4633: div.LC_confirm_box .LC_success img {
                   4634:   vertical-align: middle;
                   4635: }
                   4636: 
1.543     albertel 4637: .LC_unknown {
                   4638:   color: yellow;
                   4639: }
                   4640: 
1.440     albertel 4641: .LC_icon {
1.771     droeschl 4642:   border: none;
1.790     droeschl 4643:   vertical-align: middle;
1.771     droeschl 4644: }
                   4645: 
1.539     albertel 4646: .LC_indexer_icon {
1.803     bisitz   4647:   border: none;
1.539     albertel 4648:   height: 22px;
                   4649: }
1.795     www      4650: 
1.543     albertel 4651: .LC_docs_spacer {
                   4652:   width: 25px;
                   4653:   height: 1px;
1.771     droeschl 4654:   border: none;
1.543     albertel 4655: }
1.346     albertel 4656: 
1.532     albertel 4657: .LC_internal_info {
1.735     bisitz   4658:   color: #999999;
1.532     albertel 4659: }
                   4660: 
1.794     www      4661: .LC_discussion {
                   4662:    background: $tabbg;
                   4663:    border: 1px solid black;
                   4664:    margin: 2px;
                   4665: }
                   4666: 
                   4667: .LC_disc_action_links_bar {
                   4668:    background: $tabbg;
                   4669:    font-family: $sans;
1.803     bisitz   4670:    border: none;
1.795     www      4671:    margin: 4px;
1.794     www      4672: }
                   4673: 
                   4674: .LC_disc_action_left {
                   4675:    text-align: left;
                   4676: }
                   4677: 
                   4678: .LC_disc_action_right {
                   4679:    text-align: right;
                   4680: }
                   4681: 
                   4682: .LC_disc_new_item {
                   4683:    background: white;
                   4684:    border: 2px solid red;
                   4685:    margin: 2px;
                   4686: }
                   4687: 
                   4688: .LC_disc_old_item {
                   4689:    background: white;
                   4690:    border: 1px solid black;
                   4691:    margin: 2px;
                   4692: }
                   4693: 
1.458     albertel 4694: table.LC_pastsubmission {
                   4695:   border: 1px solid black;
                   4696:   margin: 2px;
                   4697: }
                   4698: 
1.795     www      4699: table#LC_top_nav,
                   4700: table#LC_menubuttons,
                   4701: table#LC_nav_location {
1.345     albertel 4702:   width: 100%;
                   4703:   background: $pgbg;
1.392     albertel 4704:   border: 2px;
1.402     albertel 4705:   border-collapse: separate;
1.803     bisitz   4706:   padding: 0;
1.345     albertel 4707: }
1.392     albertel 4708: 
1.801     tempelho 4709: table#LC_title_bar a {
                   4710:   color: $fontmenu;
                   4711: }
1.808     droeschl 4712:     
1.807     droeschl 4713: table#LC_title_bar {
                   4714:   /*display: none;*/
                   4715: }
                   4716: 
1.795     www      4717: table#LC_title_bar,
                   4718: table.LC_breadcrumbs,
1.393     albertel 4719: table#LC_title_bar.LC_with_remote {
1.359     albertel 4720:   width: 100%;
1.392     albertel 4721:   border-color: $pgbg;
                   4722:   border-style: solid;
                   4723:   border-width: $border;
1.379     albertel 4724:   background: $pgbg;
1.801     tempelho 4725:   color: $fontmenu;
1.379     albertel 4726:   font-family: $sans;
1.392     albertel 4727:   border-collapse: collapse;
1.803     bisitz   4728:   padding: 0;
1.359     albertel 4729: }
1.795     www      4730: 
1.409     albertel 4731: table.LC_docs_path {
                   4732:   width: 100%;
                   4733:   border: 0;
                   4734:   background: $pgbg;
                   4735:   font-family: $sans;
                   4736:   border-collapse: collapse;
1.803     bisitz   4737:   padding: 0;
1.409     albertel 4738: }
                   4739: 
1.359     albertel 4740: table#LC_title_bar td {
                   4741:   background: $tabbg;
                   4742: }
1.795     www      4743: 
1.773     ehlerst  4744: table#LC_title_bar .LC_title_bar_who {
1.359     albertel 4745:   background: $tabbg;
1.801     tempelho 4746:   color: $fontmenu;
1.427     albertel 4747:   font: small $sans;
1.359     albertel 4748:   text-align: right;
1.803     bisitz   4749:   margin: 0;
1.773     ehlerst  4750: }
1.795     www      4751: 
1.773     ehlerst  4752: table#LC_title_bar .LC_title_bar_name {
1.803     bisitz   4753:   margin: 0;
1.773     ehlerst  4754: }
1.795     www      4755: 
1.773     ehlerst  4756: table#LC_title_bar .LC_title_bar_role {
1.803     bisitz   4757:   margin: 0;
1.773     ehlerst  4758: }
1.795     www      4759: 
1.775     bisitz   4760: table#LC_title_bar .LC_title_bar_realm {
1.803     bisitz   4761:   margin: 0;
1.359     albertel 4762: }
1.795     www      4763: 
1.469     banghart 4764: span.LC_metadata {
1.795     www      4765:   font-family: $sans;
1.469     banghart 4766: }
1.359     albertel 4767: 
1.706     harmsja  4768: table#LC_menubuttons img{
1.803     bisitz   4769:   border: none;
1.346     albertel 4770: }
1.795     www      4771: 
1.345     albertel 4772: table#LC_top_nav td {
                   4773:   background: $tabbg;
1.803     bisitz   4774:   border: none;
1.407     albertel 4775:   font-size: small;
1.706     harmsja  4776:   vertical-align:top;
                   4777:   padding:2px 5px 2px 5px;
1.345     albertel 4778: }
1.795     www      4779: 
                   4780: table#LC_top_nav td a,
                   4781: div#LC_top_nav a {
1.345     albertel 4782:   color: $font;
                   4783:   font-family: $sans;
                   4784: }
1.795     www      4785: 
1.364     albertel 4786: table#LC_top_nav td.LC_top_nav_logo {
                   4787:   background: $tabbg;
1.432     albertel 4788:   text-align: left;
1.408     albertel 4789:   white-space: nowrap;
1.432     albertel 4790:   width: 31px;
1.408     albertel 4791: }
1.795     www      4792: 
1.408     albertel 4793: table#LC_top_nav td.LC_top_nav_logo img {
1.803     bisitz   4794:   border: none;
1.408     albertel 4795:   vertical-align: bottom;
1.364     albertel 4796: }
1.795     www      4797: 
1.777     tempelho 4798: table#LC_top_nav td.LC_top_nav_exit,
1.779     bisitz   4799: table#LC_top_nav td.LC_top_nav_help {
1.777     tempelho 4800:   width: 2.0em;
                   4801: }
1.795     www      4802: 
1.442     albertel 4803: table#LC_top_nav td.LC_top_nav_login {
                   4804:   width: 4.0em;
                   4805:   text-align: center;
                   4806: }
1.795     www      4807: 
                   4808: table.LC_breadcrumbs td,
                   4809: table.LC_docs_path td  {
1.357     albertel 4810:   background: $tabbg;
1.801     tempelho 4811:   color: $fontmenu;
1.357     albertel 4812:   font-family: $sans;
1.358     albertel 4813:   font-size: smaller;
1.357     albertel 4814: }
1.795     www      4815: 
1.777     tempelho 4816: table.LC_breadcrumbs td.LC_breadcrumbs_component,
                   4817: table.LC_docs_path td.LC_docs_path_component {
1.779     bisitz   4818:   background: $tabbg;
1.801     tempelho 4819:   color: $fontmenu;
1.777     tempelho 4820:   font-family: $sans;
1.779     bisitz   4821:   font-size: larger;
                   4822:   text-align: right;
1.777     tempelho 4823: }
1.795     www      4824: 
1.383     albertel 4825: td.LC_table_cell_checkbox {
                   4826:   text-align: center;
                   4827: }
1.795     www      4828: 
1.779     bisitz   4829: table#LC_mainmenu td.LC_mainmenu_column {
                   4830:     vertical-align: top;
1.777     tempelho 4831: }
1.522     albertel 4832: 
1.795     www      4833: .LC_fontsize_small {
1.705     tempelho 4834:  font-size: 70%;
                   4835: }
                   4836: 
1.795     www      4837: .LC_fontsize_medium {
1.705     tempelho 4838:  font-size: 85%;
                   4839: }
                   4840: 
1.795     www      4841: .LC_fontsize_large {
1.705     tempelho 4842:  font-size: 120%;
                   4843: }
                   4844: 
1.346     albertel 4845: .LC_menubuttons_inline_text {
                   4846:   color: $font;
                   4847:   font-family: $sans;
1.698     harmsja  4848:   font-size: 90%;
1.701     harmsja  4849:   padding-left:3px;
1.346     albertel 4850: }
                   4851: 
1.526     www      4852: .LC_menubuttons_link {
                   4853:   text-decoration: none;
                   4854: }
1.795     www      4855: 
1.522     albertel 4856: .LC_menubuttons_category {
1.521     www      4857:   color: $font;
1.526     www      4858:   background: $pgbg;
1.521     www      4859:   font-family: $sans;
                   4860:   font-size: larger;
                   4861:   font-weight: bold;
                   4862: }
                   4863: 
1.346     albertel 4864: td.LC_menubuttons_text {
1.779     bisitz   4865:  	color: $font;
1.346     albertel 4866: }
1.706     harmsja  4867: 
1.346     albertel 4868: .LC_current_location {
                   4869:   font-family: $sans;
                   4870:   background: $tabbg;
                   4871: }
1.795     www      4872: 
1.346     albertel 4873: .LC_new_mail {
                   4874:   font-family: $sans;
1.634     www      4875:   background: $tabbg;
1.346     albertel 4876:   font-weight: bold;
                   4877: }
1.347     albertel 4878: 
1.527     www      4879: .LC_dropadd_labeltext {
                   4880:   font-family: $sans;
                   4881:   text-align: right;
                   4882: }
                   4883: 
                   4884: .LC_preferences_labeltext {
                   4885:   font-family: $sans;
                   4886:   text-align: right;
                   4887: }
                   4888: 
1.666     raeburn  4889: .LC_roleslog_note {
1.701     harmsja  4890:   font-size: small;
1.666     raeburn  4891: }
                   4892: 
1.715     raeburn  4893: .LC_mail_functions {
                   4894:     font-weight: bold;
                   4895: }
                   4896: 
1.795     www      4897: table.LC_data_table,
                   4898: table.LC_mail_list {
1.347     albertel 4899:   border: 1px solid #000000;
1.402     albertel 4900:   border-collapse: separate;
1.426     albertel 4901:   border-spacing: 1px;
1.610     albertel 4902:   background: $pgbg;
1.347     albertel 4903: }
1.795     www      4904: 
1.422     albertel 4905: .LC_data_table_dense {
                   4906:   font-size: small;
                   4907: }
1.795     www      4908: 
1.507     raeburn  4909: table.LC_nested_outer {
                   4910:   border: 1px solid #000000;
1.589     raeburn  4911:   border-collapse: collapse;
1.803     bisitz   4912:   border-spacing: 0;
1.507     raeburn  4913:   width: 100%;
                   4914: }
1.795     www      4915: 
1.507     raeburn  4916: table.LC_nested {
1.803     bisitz   4917:   border: none;
1.589     raeburn  4918:   border-collapse: collapse;
1.803     bisitz   4919:   border-spacing: 0;
1.507     raeburn  4920:   width: 100%;
                   4921: }
1.795     www      4922: 
                   4923: table.LC_data_table tr th, 
                   4924: table.LC_calendar tr th, 
                   4925: table.LC_mail_list tr th,
1.523     albertel 4926: table.LC_prior_tries tr th {
1.349     albertel 4927:   font-weight: bold;
                   4928:   background-color: $data_table_head;
1.801     tempelho 4929:   color:$fontmenu;
1.701     harmsja  4930:   font-size:90%;
1.347     albertel 4931: }
1.795     www      4932: 
1.711     raeburn  4933: table.LC_data_table tr.LC_info_row > td {
1.735     bisitz   4934:   background-color: #CCCCCC;
1.711     raeburn  4935:   font-weight: bold;
                   4936:   text-align: left;
                   4937: }
1.795     www      4938: 
1.779     bisitz   4939: table.LC_data_table tr.LC_odd_row > td,
1.809     bisitz   4940: table.LC_pick_box tr > td.LC_odd_row {
1.349     albertel 4941:   background-color: $data_table_light;
1.425     albertel 4942:   padding: 2px;
1.347     albertel 4943: }
1.795     www      4944: 
1.610     albertel 4945: table.LC_data_table tr.LC_even_row > td,
1.809     bisitz   4946: table.LC_pick_box tr > td.LC_even_row {
1.349     albertel 4947:   background-color: $data_table_dark;
1.709     bisitz   4948:   padding: 2px;
1.347     albertel 4949: }
1.795     www      4950: 
1.425     albertel 4951: table.LC_data_table tr.LC_data_table_highlight td {
                   4952:   background-color: $data_table_darker;
                   4953: }
1.795     www      4954: 
1.639     raeburn  4955: table.LC_data_table tr td.LC_leftcol_header {
                   4956:   background-color: $data_table_head;
                   4957:   font-weight: bold;
                   4958: }
1.795     www      4959: 
1.451     albertel 4960: table.LC_data_table tr.LC_empty_row td,
1.507     raeburn  4961: table.LC_nested tr.LC_empty_row td {
1.347     albertel 4962:   background-color: #FFFFFF;
1.421     albertel 4963:   font-weight: bold;
                   4964:   font-style: italic;
                   4965:   text-align: center;
                   4966:   padding: 8px;
1.347     albertel 4967: }
1.795     www      4968: 
1.507     raeburn  4969: table.LC_nested tr.LC_empty_row td {
1.465     albertel 4970:   padding: 4ex
                   4971: }
1.795     www      4972: 
1.507     raeburn  4973: table.LC_nested_outer tr th {
                   4974:   font-weight: bold;
1.801     tempelho 4975:   color:$fontmenu;
1.507     raeburn  4976:   background-color: $data_table_head;
1.701     harmsja  4977:   font-size: small;
1.507     raeburn  4978:   border-bottom: 1px solid #000000;
                   4979: }
1.795     www      4980: 
1.507     raeburn  4981: table.LC_nested_outer tr td.LC_subheader {
                   4982:   background-color: $data_table_head;
                   4983:   font-weight: bold;
                   4984:   font-size: small;
                   4985:   border-bottom: 1px solid #000000;
                   4986:   text-align: right;
1.451     albertel 4987: }
1.795     www      4988: 
1.507     raeburn  4989: table.LC_nested tr.LC_info_row td {
1.735     bisitz   4990:   background-color: #CCCCCC;
1.451     albertel 4991:   font-weight: bold;
                   4992:   font-size: small;
1.507     raeburn  4993:   text-align: center;
                   4994: }
1.795     www      4995: 
1.589     raeburn  4996: table.LC_nested tr.LC_info_row td.LC_left_item,
                   4997: table.LC_nested_outer tr th.LC_left_item {
1.507     raeburn  4998:   text-align: left;
1.451     albertel 4999: }
1.795     www      5000: 
1.507     raeburn  5001: table.LC_nested td {
1.735     bisitz   5002:   background-color: #FFFFFF;
1.451     albertel 5003:   font-size: small;
1.507     raeburn  5004: }
1.795     www      5005: 
1.507     raeburn  5006: table.LC_nested_outer tr th.LC_right_item,
                   5007: table.LC_nested tr.LC_info_row td.LC_right_item,
                   5008: table.LC_nested tr.LC_odd_row td.LC_right_item,
                   5009: table.LC_nested tr td.LC_right_item {
1.451     albertel 5010:   text-align: right;
                   5011: }
                   5012: 
1.507     raeburn  5013: table.LC_nested tr.LC_odd_row td {
1.735     bisitz   5014:   background-color: #EEEEEE;
1.451     albertel 5015: }
                   5016: 
1.473     raeburn  5017: table.LC_createuser {
                   5018: }
                   5019: 
                   5020: table.LC_createuser tr.LC_section_row td {
1.701     harmsja  5021:   font-size: small;
1.473     raeburn  5022: }
                   5023: 
                   5024: table.LC_createuser tr.LC_info_row td  {
1.735     bisitz   5025:   background-color: #CCCCCC;
1.473     raeburn  5026:   font-weight: bold;
                   5027:   text-align: center;
                   5028: }
                   5029: 
1.349     albertel 5030: table.LC_calendar {
                   5031:   border: 1px solid #000000;
                   5032:   border-collapse: collapse;
                   5033: }
1.795     www      5034: 
1.349     albertel 5035: table.LC_calendar_pickdate {
                   5036:   font-size: xx-small;
                   5037: }
1.795     www      5038: 
1.349     albertel 5039: table.LC_calendar tr td {
                   5040:   border: 1px solid #000000;
                   5041:   vertical-align: top;
                   5042: }
1.795     www      5043: 
1.349     albertel 5044: table.LC_calendar tr td.LC_calendar_day_empty {
                   5045:   background-color: $data_table_dark;
                   5046: }
1.795     www      5047: 
1.779     bisitz   5048: table.LC_calendar tr td.LC_calendar_day_current {
                   5049:   background-color: $data_table_highlight;
1.777     tempelho 5050: }
1.795     www      5051: 
1.349     albertel 5052: table.LC_mail_list tr.LC_mail_new {
                   5053:   background-color: $mail_new;
                   5054: }
1.795     www      5055: 
1.349     albertel 5056: table.LC_mail_list tr.LC_mail_new:hover {
                   5057:   background-color: $mail_new_hover;
                   5058: }
1.795     www      5059: 
                   5060: table.LC_mail_list tr.LC_mail_even {
1.777     tempelho 5061: }
1.795     www      5062: 
                   5063: table.LC_mail_list tr.LC_mail_odd {
1.777     tempelho 5064: }
1.795     www      5065: 
1.349     albertel 5066: table.LC_mail_list tr.LC_mail_read {
                   5067:   background-color: $mail_read;
                   5068: }
1.795     www      5069: 
1.349     albertel 5070: table.LC_mail_list tr.LC_mail_read:hover {
                   5071:   background-color: $mail_read_hover;
                   5072: }
1.795     www      5073: 
1.349     albertel 5074: table.LC_mail_list tr.LC_mail_replied {
                   5075:   background-color: $mail_replied;
                   5076: }
1.795     www      5077: 
1.349     albertel 5078: table.LC_mail_list tr.LC_mail_replied:hover {
                   5079:   background-color: $mail_replied_hover;
                   5080: }
1.795     www      5081: 
1.349     albertel 5082: table.LC_mail_list tr.LC_mail_other {
                   5083:   background-color: $mail_other;
                   5084: }
1.795     www      5085: 
1.349     albertel 5086: table.LC_mail_list tr.LC_mail_other:hover {
                   5087:   background-color: $mail_other_hover;
                   5088: }
1.494     raeburn  5089: 
1.777     tempelho 5090: table.LC_data_table tr > td.LC_browser_file,
                   5091: table.LC_data_table tr > td.LC_browser_file_published {
1.389     albertel 5092:   background: #CCFF88;
                   5093: }
1.795     www      5094: 
1.777     tempelho 5095: table.LC_data_table tr > td.LC_browser_file_locked,
                   5096: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389     albertel 5097:   background: #FFAA99;
1.387     albertel 5098: }
1.795     www      5099: 
1.777     tempelho 5100: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.779     bisitz   5101:   background: #AAAAAA;
                   5102: }
1.795     www      5103: 
1.777     tempelho 5104: table.LC_data_table tr > td.LC_browser_file_modified,
1.779     bisitz   5105: table.LC_data_table tr > td.LC_browser_file_metamodified {
                   5106:   background: #FFFF77;
1.777     tempelho 5107: }
1.795     www      5108: 
1.696     bisitz   5109: table.LC_data_table tr.LC_browser_folder > td {
1.389     albertel 5110:   background: #CCCCFF;
1.387     albertel 5111: }
1.696     bisitz   5112: 
1.707     bisitz   5113: table.LC_data_table tr > td.LC_roles_is {
                   5114: /*  background: #77FF77; */
                   5115: }
1.795     www      5116: 
1.707     bisitz   5117: table.LC_data_table tr > td.LC_roles_future {
                   5118:   background: #FFFF77;
                   5119: }
1.795     www      5120: 
1.707     bisitz   5121: table.LC_data_table tr > td.LC_roles_will {
                   5122:   background: #FFAA77;
                   5123: }
1.795     www      5124: 
1.707     bisitz   5125: table.LC_data_table tr > td.LC_roles_expired {
                   5126:   background: #FF7777;
                   5127: }
1.795     www      5128: 
1.707     bisitz   5129: table.LC_data_table tr > td.LC_roles_will_not {
                   5130:   background: #AAFF77;
                   5131: }
1.795     www      5132: 
1.707     bisitz   5133: table.LC_data_table tr > td.LC_roles_selected {
                   5134:   background: #11CC55;
                   5135: }
                   5136: 
1.388     albertel 5137: span.LC_current_location {
1.701     harmsja  5138:   font-size:larger;
1.388     albertel 5139:   background: $pgbg;
                   5140: }
1.387     albertel 5141: 
1.395     albertel 5142: span.LC_parm_menu_item {
                   5143:   font-size: larger;
                   5144:   font-family: $sans;
                   5145: }
1.795     www      5146: 
1.395     albertel 5147: span.LC_parm_scope_all {
                   5148:   color: red;
                   5149: }
1.795     www      5150: 
1.395     albertel 5151: span.LC_parm_scope_folder {
                   5152:   color: green;
                   5153: }
1.795     www      5154: 
1.395     albertel 5155: span.LC_parm_scope_resource {
                   5156:   color: orange;
                   5157: }
1.795     www      5158: 
1.395     albertel 5159: span.LC_parm_part {
                   5160:   color: blue;
                   5161: }
1.795     www      5162: 
1.395     albertel 5163: span.LC_parm_folder, span.LC_parm_symb {
                   5164:   font-size: x-small;
                   5165:   font-family: $mono;
                   5166:   color: #AAAAAA;
                   5167: }
                   5168: 
1.795     www      5169: td.LC_parm_overview_level_menu,
                   5170: td.LC_parm_overview_map_menu,
                   5171: td.LC_parm_overview_parm_selectors,
                   5172: td.LC_parm_overview_restrictions  {
1.396     albertel 5173:   border: 1px solid black;
                   5174:   border-collapse: collapse;
                   5175: }
1.795     www      5176: 
1.396     albertel 5177: table.LC_parm_overview_restrictions td {
                   5178:   border-width: 1px 4px 1px 4px;
                   5179:   border-style: solid;
                   5180:   border-color: $pgbg;
                   5181:   text-align: center;
                   5182: }
1.795     www      5183: 
1.396     albertel 5184: table.LC_parm_overview_restrictions th {
                   5185:   background: $tabbg;
                   5186:   border-width: 1px 4px 1px 4px;
                   5187:   border-style: solid;
                   5188:   border-color: $pgbg;
                   5189: }
1.795     www      5190: 
1.398     albertel 5191: table#LC_helpmenu {
1.803     bisitz   5192:   border: none;
1.398     albertel 5193:   height: 55px;
1.803     bisitz   5194:   border-spacing: 0;
1.398     albertel 5195: }
                   5196: 
                   5197: table#LC_helpmenu fieldset legend {
                   5198:   font-size: larger;
                   5199:   font-weight: bold;
                   5200: }
1.795     www      5201: 
1.397     albertel 5202: table#LC_helpmenu_links {
                   5203:   width: 100%;
                   5204:   border: 1px solid black;
                   5205:   background: $pgbg;
1.803     bisitz   5206:   padding: 0;
1.397     albertel 5207:   border-spacing: 1px;
                   5208: }
1.795     www      5209: 
1.397     albertel 5210: table#LC_helpmenu_links tr td {
                   5211:   padding: 1px;
                   5212:   background: $tabbg;
1.399     albertel 5213:   text-align: center;
                   5214:   font-weight: bold;
1.397     albertel 5215: }
1.396     albertel 5216: 
1.795     www      5217: table#LC_helpmenu_links a:link,
                   5218: table#LC_helpmenu_links a:visited,
1.397     albertel 5219: table#LC_helpmenu_links a:active {
                   5220:   text-decoration: none;
                   5221:   color: $font;
                   5222: }
1.795     www      5223: 
1.397     albertel 5224: table#LC_helpmenu_links a:hover {
                   5225:   text-decoration: underline;
                   5226:   color: $vlink;
                   5227: }
1.396     albertel 5228: 
1.417     albertel 5229: .LC_chrt_popup_exists {
                   5230:   border: 1px solid #339933;
                   5231:   margin: -1px;
                   5232: }
1.795     www      5233: 
1.417     albertel 5234: .LC_chrt_popup_up {
                   5235:   border: 1px solid yellow;
                   5236:   margin: -1px;
                   5237: }
1.795     www      5238: 
1.417     albertel 5239: .LC_chrt_popup {
                   5240:   border: 1px solid #8888FF;
                   5241:   background: #CCCCFF;
                   5242: }
1.795     www      5243: 
1.421     albertel 5244: table.LC_pick_box {
                   5245:   border-collapse: separate;
                   5246:   background: white;
                   5247:   border: 1px solid black;
                   5248:   border-spacing: 1px;
                   5249: }
1.795     www      5250: 
1.421     albertel 5251: table.LC_pick_box td.LC_pick_box_title {
                   5252:   background: $tabbg;
                   5253:   font-weight: bold;
                   5254:   text-align: right;
1.740     bisitz   5255:   vertical-align: top;
1.421     albertel 5256:   width: 184px;
                   5257:   padding: 8px;
                   5258: }
1.795     www      5259: 
1.645     raeburn  5260: table.LC_pick_box td.LC_selfenroll_pick_box_title {
                   5261:   background: $tabbg;
                   5262:   font-weight: bold;
                   5263:   text-align: right;
                   5264:   width: 350px;
                   5265:   padding: 8px;
                   5266: }
                   5267: 
1.579     raeburn  5268: table.LC_pick_box td.LC_pick_box_value {
                   5269:   text-align: left;
                   5270:   padding: 8px;
                   5271: }
1.795     www      5272: 
1.579     raeburn  5273: table.LC_pick_box td.LC_pick_box_select {
                   5274:   text-align: left;
                   5275:   padding: 8px;
                   5276: }
1.795     www      5277: 
1.424     albertel 5278: table.LC_pick_box td.LC_pick_box_separator {
1.803     bisitz   5279:   padding: 0;
1.421     albertel 5280:   height: 1px;
                   5281:   background: black;
                   5282: }
1.795     www      5283: 
1.421     albertel 5284: table.LC_pick_box td.LC_pick_box_submit {
                   5285:   text-align: right;
                   5286: }
1.795     www      5287: 
1.579     raeburn  5288: table.LC_pick_box td.LC_evenrow_value {
                   5289:   text-align: left;
                   5290:   padding: 8px;
                   5291:   background-color: $data_table_light;
                   5292: }
1.795     www      5293: 
1.579     raeburn  5294: table.LC_pick_box td.LC_oddrow_value {
                   5295:   text-align: left;
                   5296:   padding: 8px;
                   5297:   background-color: $data_table_light;
                   5298: }
1.795     www      5299: 
1.579     raeburn  5300: table.LC_helpform_receipt {
                   5301:   width: 620px;
                   5302:   border-collapse: separate;
                   5303:   background: white;
                   5304:   border: 1px solid black;
                   5305:   border-spacing: 1px;
                   5306: }
1.795     www      5307: 
1.579     raeburn  5308: table.LC_helpform_receipt td.LC_pick_box_title {
                   5309:   background: $tabbg;
                   5310:   font-weight: bold;
                   5311:   text-align: right;
                   5312:   width: 184px;
                   5313:   padding: 8px;
                   5314: }
1.795     www      5315: 
1.579     raeburn  5316: table.LC_helpform_receipt td.LC_evenrow_value {
                   5317:   text-align: left;
                   5318:   padding: 8px;
                   5319:   background-color: $data_table_light;
                   5320: }
1.795     www      5321: 
1.579     raeburn  5322: table.LC_helpform_receipt td.LC_oddrow_value {
                   5323:   text-align: left;
                   5324:   padding: 8px;
                   5325:   background-color: $data_table_light;
                   5326: }
1.795     www      5327: 
1.579     raeburn  5328: table.LC_helpform_receipt td.LC_pick_box_separator {
1.803     bisitz   5329:   padding: 0;
1.579     raeburn  5330:   height: 1px;
                   5331:   background: black;
                   5332: }
1.795     www      5333: 
1.579     raeburn  5334: span.LC_helpform_receipt_cat {
                   5335:   font-weight: bold;
                   5336: }
1.795     www      5337: 
1.424     albertel 5338: table.LC_group_priv_box {
                   5339:   background: white;
                   5340:   border: 1px solid black;
                   5341:   border-spacing: 1px;
                   5342: }
1.795     www      5343: 
1.424     albertel 5344: table.LC_group_priv_box td.LC_pick_box_title {
                   5345:   background: $tabbg;
                   5346:   font-weight: bold;
                   5347:   text-align: right;
                   5348:   width: 184px;
                   5349: }
1.795     www      5350: 
1.424     albertel 5351: table.LC_group_priv_box td.LC_groups_fixed {
                   5352:   background: $data_table_light;
                   5353:   text-align: center;
                   5354: }
1.795     www      5355: 
1.424     albertel 5356: table.LC_group_priv_box td.LC_groups_optional {
                   5357:   background: $data_table_dark;
                   5358:   text-align: center;
                   5359: }
1.795     www      5360: 
1.424     albertel 5361: table.LC_group_priv_box td.LC_groups_functionality {
                   5362:   background: $data_table_darker;
                   5363:   text-align: center;
                   5364:   font-weight: bold;
                   5365: }
1.795     www      5366: 
1.424     albertel 5367: table.LC_group_priv td {
                   5368:   text-align: left;
1.803     bisitz   5369:   padding: 0;
1.424     albertel 5370: }
                   5371: 
1.421     albertel 5372: table.LC_notify_front_page {
                   5373:   background: white;
                   5374:   border: 1px solid black;
                   5375:   padding: 8px;
                   5376: }
1.795     www      5377: 
1.421     albertel 5378: table.LC_notify_front_page td {
                   5379:   padding: 8px;
                   5380: }
1.795     www      5381: 
1.424     albertel 5382: .LC_navbuttons {
                   5383:   margin: 2ex 0ex 2ex 0ex;
                   5384: }
1.795     www      5385: 
1.423     albertel 5386: .LC_topic_bar {
                   5387:   font-family: $sans;
                   5388:   font-weight: bold;
                   5389:   width: 100%;
                   5390:   background: $tabbg;
                   5391:   vertical-align: middle;
                   5392:   margin: 2ex 0ex 2ex 0ex;
1.805     bisitz   5393:   padding: 3px;
1.423     albertel 5394: }
1.795     www      5395: 
1.423     albertel 5396: .LC_topic_bar span {
                   5397:   vertical-align: middle;
                   5398: }
1.795     www      5399: 
1.423     albertel 5400: .LC_topic_bar img {
                   5401:   vertical-align: bottom;
                   5402: }
1.795     www      5403: 
1.423     albertel 5404: table.LC_course_group_status {
                   5405:   margin: 20px;
                   5406: }
1.795     www      5407: 
1.423     albertel 5408: table.LC_status_selector td {
                   5409:   vertical-align: top;
                   5410:   text-align: center;
1.424     albertel 5411:   padding: 4px;
                   5412: }
1.795     www      5413: 
1.599     albertel 5414: div.LC_feedback_link {
1.616     albertel 5415:   clear: both;
1.599     albertel 5416:   background: white;
1.779     bisitz   5417:   width: 100%;
1.489     raeburn  5418: }
1.795     www      5419: 
1.489     raeburn  5420: span.LC_feedback_link {
1.599     albertel 5421:   background: $feedback_link_bg;
                   5422:   font-size: larger;
                   5423: }
1.795     www      5424: 
1.599     albertel 5425: span.LC_message_link {
                   5426:   background: $feedback_link_bg;
                   5427:   font-size: larger;
                   5428:   position: absolute;
                   5429:   right: 1em;
1.489     raeburn  5430: }
1.421     albertel 5431: 
1.515     albertel 5432: table.LC_prior_tries {
1.524     albertel 5433:   border: 1px solid #000000;
                   5434:   border-collapse: separate;
                   5435:   border-spacing: 1px;
1.515     albertel 5436: }
1.523     albertel 5437: 
1.515     albertel 5438: table.LC_prior_tries td {
1.524     albertel 5439:   padding: 2px;
1.515     albertel 5440: }
1.523     albertel 5441: 
                   5442: .LC_answer_correct {
1.795     www      5443:   background: lightgreen;
                   5444:   font-family: $sans;
                   5445:   color: darkgreen;
                   5446:   padding: 6px;
1.523     albertel 5447: }
1.795     www      5448: 
1.523     albertel 5449: .LC_answer_charged_try {
1.797     www      5450:   background: #FFAAAA;
1.795     www      5451:   font-family: $sans;
                   5452:   color: darkred;
                   5453:   padding: 6px;
1.523     albertel 5454: }
1.795     www      5455: 
1.779     bisitz   5456: .LC_answer_not_charged_try,
1.523     albertel 5457: .LC_answer_no_grade,
                   5458: .LC_answer_late {
1.795     www      5459:   background: lightyellow;
                   5460:   font-family: $sans;
1.523     albertel 5461:   color: black;
1.795     www      5462:   padding: 6px;
1.523     albertel 5463: }
1.795     www      5464: 
1.523     albertel 5465: .LC_answer_previous {
1.795     www      5466:   background: lightblue;
                   5467:   font-family: $sans;
                   5468:   color: darkblue;
                   5469:   padding: 6px;
1.523     albertel 5470: }
1.795     www      5471: 
1.779     bisitz   5472: .LC_answer_no_message {
1.777     tempelho 5473:   background: #FFFFFF;
1.795     www      5474:   font-family: $sans;
1.777     tempelho 5475:   color: black;
1.795     www      5476:   padding: 6px;
1.779     bisitz   5477: }
1.795     www      5478: 
1.779     bisitz   5479: .LC_answer_unknown {
                   5480:   background: orange;
1.795     www      5481:   font-family: $sans;
1.779     bisitz   5482:   color: black;
1.795     www      5483:   padding: 6px;
1.777     tempelho 5484: }
1.795     www      5485: 
1.529     albertel 5486: span.LC_prior_numerical,
                   5487: span.LC_prior_string,
                   5488: span.LC_prior_custom,
                   5489: span.LC_prior_reaction,
                   5490: span.LC_prior_math {
1.523     albertel 5491:   font-family: monospace;
                   5492:   white-space: pre;
                   5493: }
                   5494: 
1.525     albertel 5495: span.LC_prior_string {
                   5496:   font-family: monospace;
                   5497:   white-space: pre;
                   5498: }
                   5499: 
1.523     albertel 5500: table.LC_prior_option {
                   5501:   width: 100%;
                   5502:   border-collapse: collapse;
                   5503: }
1.795     www      5504: 
                   5505: table.LC_prior_rank, 
                   5506: table.LC_prior_match {
1.528     albertel 5507:   border-collapse: collapse;
                   5508: }
1.795     www      5509: 
1.528     albertel 5510: table.LC_prior_option tr td,
                   5511: table.LC_prior_rank tr td,
                   5512: table.LC_prior_match tr td {
1.524     albertel 5513:   border: 1px solid #000000;
1.515     albertel 5514: }
                   5515: 
1.770     droeschl 5516: td.LC_nobreak,
1.519     raeburn  5517: span.LC_nobreak {
1.544     albertel 5518:   white-space: nowrap;
1.519     raeburn  5519: }
                   5520: 
1.576     raeburn  5521: span.LC_cusr_emph {
                   5522:   font-style: italic;
                   5523: }
                   5524: 
1.633     raeburn  5525: span.LC_cusr_subheading {
                   5526:   font-weight: normal;
                   5527:   font-size: 85%;
                   5528: }
                   5529: 
1.545     albertel 5530: table.LC_docs_documents {
                   5531:   background: #BBBBBB;
1.803     bisitz   5532:   border-width: 0;
1.545     albertel 5533:   border-collapse: collapse;
                   5534: }
1.795     www      5535: 
1.777     tempelho 5536: table.LC_docs_documents td.LC_docs_document {
1.779     bisitz   5537:   border: 2px solid black;
                   5538:   padding: 4px;
1.777     tempelho 5539: }
1.795     www      5540: 
1.545     albertel 5541: .LC_docs_entry_move {
1.803     bisitz   5542:   border: none;
1.545     albertel 5543:   border-collapse: collapse;
1.544     albertel 5544: }
                   5545: 
1.545     albertel 5546: .LC_docs_entry_move td {
                   5547:   border: 2px solid #BBBBBB;
                   5548:   background: #DDDDDD;
                   5549: }
                   5550: 
                   5551: .LC_docs_editor td.LC_docs_entry_commands {
                   5552:   background: #DDDDDD;
                   5553:   font-size: x-small;
                   5554: }
1.795     www      5555: 
1.544     albertel 5556: .LC_docs_copy {
1.545     albertel 5557:   color: #000099;
1.544     albertel 5558: }
1.795     www      5559: 
1.544     albertel 5560: .LC_docs_cut {
1.545     albertel 5561:   color: #550044;
1.544     albertel 5562: }
1.795     www      5563: 
1.544     albertel 5564: .LC_docs_rename {
1.545     albertel 5565:   color: #009900;
1.544     albertel 5566: }
1.795     www      5567: 
1.544     albertel 5568: .LC_docs_remove {
1.545     albertel 5569:   color: #990000;
                   5570: }
                   5571: 
1.547     albertel 5572: .LC_docs_reinit_warn,
                   5573: .LC_docs_ext_edit {
                   5574:   font-size: x-small;
                   5575: }
                   5576: 
1.545     albertel 5577: .LC_docs_editor td.LC_docs_entry_title,
                   5578: .LC_docs_editor td.LC_docs_entry_icon {
                   5579:   background: #FFFFBB;
                   5580: }
1.795     www      5581: 
1.545     albertel 5582: .LC_docs_editor td.LC_docs_entry_parameter {
                   5583:   background: #BBBBFF;
                   5584:   font-size: x-small;
                   5585:   white-space: nowrap;
                   5586: }
                   5587: 
                   5588: table.LC_docs_adddocs td,
                   5589: table.LC_docs_adddocs th {
                   5590:   border: 1px solid #BBBBBB;
                   5591:   padding: 4px;
                   5592:   background: #DDDDDD;
1.543     albertel 5593: }
                   5594: 
1.584     albertel 5595: table.LC_sty_begin {
                   5596:   background: #BBFFBB;
                   5597: }
1.795     www      5598: 
1.584     albertel 5599: table.LC_sty_end {
                   5600:   background: #FFBBBB;
                   5601: }
                   5602: 
1.589     raeburn  5603: table.LC_double_column {
1.803     bisitz   5604:   border-width: 0;
1.589     raeburn  5605:   border-collapse: collapse;
                   5606:   width: 100%;
                   5607:   padding: 2px;
                   5608: }
                   5609: 
                   5610: table.LC_double_column tr td.LC_left_col {
1.590     raeburn  5611:   top: 2px;
1.589     raeburn  5612:   left: 2px;
                   5613:   width: 47%;
                   5614:   vertical-align: top;
                   5615: }
                   5616: 
                   5617: table.LC_double_column tr td.LC_right_col {
                   5618:   top: 2px;
1.779     bisitz   5619:   right: 2px;
1.589     raeburn  5620:   width: 47%;
                   5621:   vertical-align: top;
                   5622: }
                   5623: 
1.594     raeburn  5624: span.LC_role_level {
                   5625:   font-weight: bold;
                   5626: }
                   5627: 
1.591     raeburn  5628: div.LC_left_float {
                   5629:   float: left;
                   5630:   padding-right: 5%;
1.597     albertel 5631:   padding-bottom: 4px;
1.591     raeburn  5632: }
                   5633: 
                   5634: div.LC_clear_float_header {
1.597     albertel 5635:   padding-bottom: 2px;
1.591     raeburn  5636: }
                   5637: 
                   5638: div.LC_clear_float_footer {
1.597     albertel 5639:   padding-top: 10px;
1.591     raeburn  5640:   clear: both;
                   5641: }
                   5642: 
1.597     albertel 5643: div.LC_grade_show_user {
                   5644:   margin-top: 20px;
                   5645:   border: 1px solid black;
                   5646: }
1.795     www      5647: 
1.597     albertel 5648: div.LC_grade_user_name {
                   5649:   background: #DDDDEE;
                   5650:   border-bottom: 1px solid black;
1.705     tempelho 5651:   font-weight: bold;
                   5652:   font-size: large;
1.597     albertel 5653: }
1.795     www      5654: 
1.597     albertel 5655: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
                   5656:   background: #DDEEDD;
                   5657: }
                   5658: 
                   5659: div.LC_grade_show_problem,
                   5660: div.LC_grade_submissions,
                   5661: div.LC_grade_message_center,
                   5662: div.LC_grade_info_links,
                   5663: div.LC_grade_assign {
                   5664:   margin: 5px;
                   5665:   width: 99%;
                   5666:   background: #FFFFFF;
                   5667: }
1.795     www      5668: 
1.597     albertel 5669: div.LC_grade_show_problem_header,
                   5670: div.LC_grade_submissions_header,
                   5671: div.LC_grade_message_center_header,
                   5672: div.LC_grade_assign_header {
1.705     tempelho 5673:   font-weight: bold;
                   5674:   font-size: large;
1.597     albertel 5675: }
1.795     www      5676: 
1.597     albertel 5677: div.LC_grade_show_problem_problem,
                   5678: div.LC_grade_submissions_body,
                   5679: div.LC_grade_message_center_body,
                   5680: div.LC_grade_assign_body {
                   5681:   border: 1px solid black;
                   5682:   width: 99%;
                   5683:   background: #FFFFFF;
                   5684: }
1.795     www      5685: 
1.598     albertel 5686: span.LC_grade_check_note {
1.705     tempelho 5687:   font-weight: normal;
                   5688:   font-size: medium;
1.598     albertel 5689:   display: inline;
                   5690:   position: absolute;
                   5691:   right: 1em;
                   5692: }
1.597     albertel 5693: 
1.613     albertel 5694: table.LC_scantron_action {
                   5695:   width: 100%;
                   5696: }
1.795     www      5697: 
1.613     albertel 5698: table.LC_scantron_action tr th {
1.698     harmsja  5699:   font-weight:bold;
                   5700:   font-style:normal;
1.613     albertel 5701: }
1.795     www      5702: 
1.779     bisitz   5703: .LC_edit_problem_header,
1.614     albertel 5704: div.LC_edit_problem_footer {
1.705     tempelho 5705:   font-weight: normal;
                   5706:   font-size:  medium;
1.602     albertel 5707:   margin: 2px;
1.600     albertel 5708: }
1.795     www      5709: 
1.600     albertel 5710: div.LC_edit_problem_header,
1.602     albertel 5711: div.LC_edit_problem_header div,
1.614     albertel 5712: div.LC_edit_problem_footer,
                   5713: div.LC_edit_problem_footer div,
1.602     albertel 5714: div.LC_edit_problem_editxml_header,
                   5715: div.LC_edit_problem_editxml_header div {
1.600     albertel 5716:   margin-top: 5px;
                   5717: }
1.795     www      5718: 
1.602     albertel 5719: div.LC_edit_problem_header_edit_row {
                   5720:   background: $tabbg;
                   5721:   padding: 3px;
                   5722:   margin-bottom: 5px;
                   5723: }
1.795     www      5724: 
1.600     albertel 5725: div.LC_edit_problem_header_title {
1.705     tempelho 5726:   font-weight: bold;
                   5727:   font-size: larger;
1.602     albertel 5728:   background: $tabbg;
                   5729:   padding: 3px;
                   5730: }
1.795     www      5731: 
1.602     albertel 5732: table.LC_edit_problem_header_title {
1.705     tempelho 5733:   font-size: larger;
                   5734:   font-weight:  bold;
1.602     albertel 5735:   width: 100%;
                   5736:   border-color: $pgbg;
                   5737:   border-style: solid;
                   5738:   border-width: $border;
1.600     albertel 5739:   background: $tabbg;
1.602     albertel 5740:   border-collapse: collapse;
1.803     bisitz   5741:   padding: 0;
1.602     albertel 5742: }
                   5743: 
                   5744: div.LC_edit_problem_discards {
                   5745:   float: left;
                   5746:   padding-bottom: 5px;
                   5747: }
1.795     www      5748: 
1.602     albertel 5749: div.LC_edit_problem_saves {
                   5750:   float: right;
                   5751:   padding-bottom: 5px;
1.600     albertel 5752: }
1.795     www      5753: 
1.600     albertel 5754: hr.LC_edit_problem_divide {
1.602     albertel 5755:   clear: both;
1.600     albertel 5756:   color: $tabbg;
                   5757:   background-color: $tabbg;
                   5758:   height: 3px;
1.803     bisitz   5759:   border: none;
1.600     albertel 5760: }
1.795     www      5761: 
1.679     riegler  5762: img.stift{
1.803     bisitz   5763:   border-width: 0;
                   5764:   vertical-align: middle;
1.677     riegler  5765: }
1.680     riegler  5766: 
1.681     riegler  5767: table#LC_mainmenu{
                   5768:  margin-top:10px;
                   5769:  width:80%;
                   5770: }
                   5771: 
1.680     riegler  5772: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
                   5773:   vertical-align: top;
                   5774:   width: 45%;
                   5775: }
1.795     www      5776: 
1.779     bisitz   5777: .LC_mainmenu_fieldset_category {
                   5778:   color: $font;
                   5779:   background: $pgbg;
                   5780:   font-family: $sans;
                   5781:   font-size: small;
                   5782:   font-weight: bold;
1.777     tempelho 5783: }
1.795     www      5784: 
1.716     raeburn  5785: div.LC_createcourse {
                   5786:     margin: 10px 10px 10px 10px;
                   5787: }
                   5788: 
1.693     droeschl 5789: /* ---- Remove when done ----
                   5790: # The following styles is part of the redesign of LON-CAPA and are
                   5791: # subject to change during this project.
                   5792: # Don't rely on their current functionality as they might be 
                   5793: # changed or removed.
                   5794: # --------------------------*/
                   5795: 
1.698     harmsja  5796: a:hover,
1.721     harmsja  5797: ol.LC_smallMenu a:hover,
                   5798: ol#LC_MenuBreadcrumbs a:hover,
                   5799: ol#LC_PathBreadcrumbs a:hover,
                   5800: ul#LC_TabMainMenuContent a:hover,
                   5801: .LC_FormSectionClearButton input:hover
1.795     www      5802: ul.LC_TabContent   li:hover a {
1.698     harmsja  5803: 	color:#BF2317;
                   5804:         text-decoration:none;
1.693     droeschl 5805: }
                   5806: 
1.779     bisitz   5807: h1 {
1.721     harmsja  5808: 	padding:5px 10px 5px 20px;
1.693     droeschl 5809: 	line-height:130%;
                   5810: }
1.698     harmsja  5811: 
1.795     www      5812: h2,h3,h4,h5,h6 {
1.803     bisitz   5813: 	margin: 5px 0 5px 0;
                   5814: 	padding: 0;
1.721     harmsja  5815: 	line-height:130%;
1.693     droeschl 5816: }
1.795     www      5817: 
                   5818: .LC_hcell {
1.698     harmsja  5819:         padding:3px 15px 3px 15px;
1.803     bisitz   5820:         margin: 0;
1.703     harmsja  5821: 	background-color:$tabbg;
1.801     tempelho 5822: 	color:$fontmenu;
1.779     bisitz   5823: 	border-bottom:solid 1px $lg_border_color;
1.693     droeschl 5824: }
1.795     www      5825: 
1.721     harmsja  5826: .LC_noBorder {
1.803     bisitz   5827:         border: 0;
1.698     harmsja  5828: }
1.693     droeschl 5829: 
                   5830: 
1.698     harmsja  5831: /* Main Header with discription of Person, Course, etc. */
1.693     droeschl 5832: 
1.761     tempelho 5833: .LC_Right {
                   5834:         float: right;
1.803     bisitz   5835:         margin: 0;
                   5836:         padding: 0;
1.761     tempelho 5837: }
                   5838: 
1.721     harmsja  5839: .LC_FormSectionClearButton input {
1.779     bisitz   5840:         background-color:transparent;
1.803     bisitz   5841:         border: none;
1.698     harmsja  5842:         cursor:pointer;
                   5843:         text-decoration:underline;
1.693     droeschl 5844: }
1.763     bisitz   5845: 
                   5846: .LC_help_open_topic {
                   5847:         color: #FFFFFF;
                   5848:         background-color: #EEEEFF;
                   5849:         margin: 1px;
                   5850:         padding: 4px;
                   5851:         border: 1px solid #000033;
                   5852:         white-space: nowrap;
1.783     amueller 5853: /*		vertical-align: middle; */
1.759     neumanie 5854: }
1.693     droeschl 5855: 
1.698     harmsja  5856: dl,ul,div,fieldset {
1.803     bisitz   5857: 	margin: 10px 10px 10px 0;
1.806     bisitz   5858: /*	overflow: hidden; */
1.693     droeschl 5859: }
1.795     www      5860: 
1.807     droeschl 5861: #head_userinfo {
                   5862:     float: left;
                   5863:     margin: 0;
                   5864: }
                   5865: 
                   5866: #head_userinfo em{
                   5867:     font-weight: bold;
                   5868:     font-style: normal;
                   5869: }
                   5870: 
                   5871: ol.LC_smallMenu {
                   5872:     float: right;
                   5873: }
                   5874: 
1.721     harmsja  5875: ol.LC_smallMenu, ol#LC_PathBreadcrumbs {
1.803     bisitz   5876: 	margin: 0;
1.693     droeschl 5877: }
                   5878: 
1.721     harmsja  5879: ol.LC_smallMenu li {
1.693     droeschl 5880: 	display: inline;
1.803     bisitz   5881: 	padding: 5px 5px 0 10px;
1.693     droeschl 5882: 	vertical-align: top;
                   5883: }
                   5884: 
1.721     harmsja  5885: ol.LC_smallMenu li img {
1.693     droeschl 5886: 	vertical-align: bottom;
                   5887: }
                   5888: 
1.721     harmsja  5889: ol.LC_smallMenu a {
1.693     droeschl 5890: 	font-size: 90%;
                   5891: 	color: RGB(80, 80, 80);
                   5892: 	text-decoration: none;
                   5893: }
1.795     www      5894: 
1.808     droeschl 5895: ul#LC_TabMainMenuContent {
1.807     droeschl 5896:     clear: both;
1.808     droeschl 5897:     color: $fontmenu;
                   5898:     background: $tabbg;
                   5899:     list-style: none;
                   5900:     padding: 0;
                   5901:     margin: 0;
                   5902:     float:left;
                   5903:     width: 100%;
                   5904: }
                   5905: 
                   5906: ul#LC_TabMainMenuContent li {
                   5907:     float: left;
                   5908:     font-weight: bold;
                   5909:     line-height: 1.8em;
                   5910:     padding: 0 0.8em; 
                   5911:     border-right: 1px solid black;
                   5912:     display: inline;
                   5913:     vertical-align: middle;
1.807     droeschl 5914: }
                   5915: 
1.795     www      5916: ul.LC_TabContent ,
1.741     harmsja  5917: ul.LC_TabContentBigger {
1.721     harmsja  5918: 	display:block;
                   5919: 	list-style:none;
1.803     bisitz   5920: 	margin: 0;
                   5921: 	padding: 0;
1.693     droeschl 5922: }
                   5923: 
1.795     www      5924: ul.LC_TabContent li,
                   5925: ul.LC_TabContentBigger li {
1.693     droeschl 5926: 	display: inline;
1.741     harmsja  5927: 	border-right: solid 1px $lg_border_color;
                   5928: 	float:left;
                   5929: 	line-height:140%;
                   5930: 	white-space:nowrap;
                   5931: }
1.795     www      5932: 
1.808     droeschl 5933: ul#LC_TabMainMenuContent li a {
                   5934:     color: $fontmenu;
1.693     droeschl 5935: 	text-decoration: none;
                   5936: }
1.795     www      5937: 
1.721     harmsja  5938: ul.LC_TabContent {
1.741     harmsja  5939: 	min-height:1.6em;
1.721     harmsja  5940: }
1.795     www      5941: 
                   5942: ul.LC_TabContent li {
1.741     harmsja  5943: 	vertical-align:middle;
1.803     bisitz   5944: 	padding: 0 10px 0 10px;
1.745     ehlerst  5945: 	background-color:$tabbg;
                   5946: 	border-bottom:solid 1px $lg_border_color;
1.721     harmsja  5947: }
1.795     www      5948: 
                   5949: ul.LC_TabContent li a, ul.LC_TabContent li {
1.721     harmsja  5950: 	color:rgb(47,47,47);
                   5951: 	text-decoration:none;
                   5952: 	font-size:95%;
                   5953: 	font-weight:bold;
1.761     tempelho 5954: 	padding-right: 16px;
1.721     harmsja  5955: }
1.795     www      5956: 
                   5957: ul.LC_TabContent li:hover, ul.LC_TabContent li.active {
1.761     tempelho 5958:         background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.745     ehlerst  5959: 	border-bottom:solid 1px #FFFFFF;
1.761     tempelho 5960: 	padding-right: 16px;
1.744     ehlerst  5961: }
1.795     www      5962: 
                   5963: ul.LC_TabContentBigger li {
1.741     harmsja  5964: 	vertical-align:bottom;
                   5965: 	border-top:solid 1px $lg_border_color;
                   5966: 	border-left:solid 1px $lg_border_color;
                   5967: 	padding:5px 10px 5px 10px;
                   5968: 	margin-left:2px;
                   5969: 	background:url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
                   5970: }
1.795     www      5971: 
                   5972: ul.LC_TabContentBigger li:hover, 
                   5973: ul.LC_TabContentBigger li.active {
1.744     ehlerst  5974: 	background:url(/adm/lonIcons/lightGreyBG.png) repeat-x right bottom;
                   5975: }
1.795     www      5976: 
                   5977: ul.LC_TabContentBigger li, 
                   5978: ul.LC_TabContentBigger li a {
1.741     harmsja  5979: 	font-size:110%;
                   5980: 	font-weight:bold;
                   5981: }
1.693     droeschl 5982: 
1.795     www      5983: ol#LC_MenuBreadcrumbs, 
                   5984: ol#LC_PathBreadcrumbs, 
                   5985: ul.LC_CourseBreadcrumbs {
1.693     droeschl 5986: 	border-top: solid 1px RGB(255, 255, 255);
                   5987: 	height: 20px;
                   5988: 	line-height: 20px;
                   5989: 	vertical-align: bottom;
1.803     bisitz   5990: 	margin: 0 0 30px 0;
1.693     droeschl 5991: 	padding-left: 10px;
                   5992: 	list-style-position: inside;
1.723     riegler  5993: 	background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693     droeschl 5994: }
                   5995: 
1.795     www      5996: ol#LC_MenuBreadcrumbs li, 
                   5997: ol#LC_PathBreadcrumbs li, 
                   5998: ul.LC_CourseBreadcrumbs li {
1.741     harmsja  5999: /*
1.723     riegler  6000: 	background: url(/adm/lonIcons/arrow_white.png) no-repeat left center;
1.779     bisitz   6001: */
1.693     droeschl 6002: 	display: inline;
1.803     bisitz   6003: 	padding: 0 0 0 10px;
1.783     amueller 6004: /*	vertical-align: bottom; */
1.693     droeschl 6005: 	overflow:hidden;
                   6006: }
                   6007: 
1.783     amueller 6008: ol#LC_MenuBreadcrumbs li a, ul.LC_CourseBreadcrumbs li a {
1.693     droeschl 6009: 	text-decoration: none;
                   6010: 	font-size:90%;
                   6011: }
1.795     www      6012: 
                   6013: ol#LC_PathBreadcrumbs li a {
1.698     harmsja  6014: 	text-decoration:none;
                   6015: 	font-size:100%;
                   6016: 	font-weight:bold;
1.693     droeschl 6017: }
1.795     www      6018: 
                   6019: .LC_BoxPadding {
1.786     neumanie 6020: 	padding: 10px;
                   6021: }
1.795     www      6022: 
                   6023: .LC_ContentBoxSpecial {
1.701     harmsja  6024: 	border: solid 1px $lg_border_color;
1.746     neumanie 6025: }
1.795     www      6026: 
                   6027: .LC_ContentBoxSpecialContactInfo {
1.746     neumanie 6028: 	border: solid 1px $lg_border_color;
                   6029: 	max-width:25%;
                   6030: 	min-width:25%;
1.698     harmsja  6031: }
1.795     www      6032: 
                   6033: .LC_AboutMe_Image {
1.747     neumanie 6034: 	float:left;
                   6035: 	margin-right:10px;
                   6036: }
1.795     www      6037: 
                   6038: .LC_Clear_AboutMe_Image {
1.747     neumanie 6039: 	clear:left;
                   6040: }
1.795     www      6041: 
1.721     harmsja  6042: dl.LC_ListStyleClean dt {
1.693     droeschl 6043: 	padding-right: 5px;
                   6044: 	display: table-header-group;
                   6045: }
                   6046: 
1.721     harmsja  6047: dl.LC_ListStyleClean dd {
1.693     droeschl 6048: 	display: table-row;
                   6049: }
                   6050: 
1.721     harmsja  6051: .LC_ListStyleClean,
                   6052: .LC_ListStyleSimple,
                   6053: .LC_ListStyleNormal,
1.777     tempelho 6054: .LC_ListStyle_Border,
1.795     www      6055: .LC_ListStyleSpecial {
1.693     droeschl 6056: 	/*display:block;	*/
                   6057: 	list-style-position: inside;
                   6058: 	list-style-type: none;
                   6059: 	overflow: hidden;
1.803     bisitz   6060: 	padding: 0;
1.693     droeschl 6061: }
                   6062: 
1.721     harmsja  6063: .LC_ListStyleSimple li,
                   6064: .LC_ListStyleSimple dd,
                   6065: .LC_ListStyleNormal li,
                   6066: .LC_ListStyleNormal dd,
                   6067: .LC_ListStyleSpecial li,
1.795     www      6068: .LC_ListStyleSpecial dd {
1.803     bisitz   6069: 	margin: 0;
1.693     droeschl 6070: 	padding: 5px 5px 5px 10px;
                   6071: 	clear: both;
                   6072: }
                   6073: 
1.721     harmsja  6074: .LC_ListStyleClean li,
                   6075: .LC_ListStyleClean dd {
1.803     bisitz   6076: 	padding-top: 0;
                   6077: 	padding-bottom: 0;
1.693     droeschl 6078: }
                   6079: 
1.721     harmsja  6080: .LC_ListStyleSimple dd,
1.795     www      6081: .LC_ListStyleSimple li {
1.698     harmsja  6082: 	border-bottom: solid 1px $lg_border_color;
1.693     droeschl 6083: }
                   6084: 
1.721     harmsja  6085: .LC_ListStyleSpecial li,
                   6086: .LC_ListStyleSpecial dd {
1.693     droeschl 6087: 	list-style-type: none;
                   6088: 	background-color: RGB(220, 220, 220);
                   6089: 	margin-bottom: 4px;
                   6090: }
                   6091: 
1.721     harmsja  6092: table.LC_SimpleTable {
1.698     harmsja  6093: 	margin:5px;
                   6094: 	border:solid 1px $lg_border_color;
1.795     www      6095: }
1.693     droeschl 6096: 
1.721     harmsja  6097: table.LC_SimpleTable tr {
1.803     bisitz   6098: 	padding: 0;
1.698     harmsja  6099: 	border:solid 1px $lg_border_color;
1.693     droeschl 6100: }
1.795     www      6101: 
                   6102: table.LC_SimpleTable thead {
1.698     harmsja  6103: 	 background:rgb(220,220,220);
1.693     droeschl 6104: }
                   6105: 
1.721     harmsja  6106: div.LC_columnSection {
1.693     droeschl 6107: 	display: block;
                   6108: 	clear: both;
                   6109: 	overflow: hidden;
1.803     bisitz   6110: 	margin: 0;
1.693     droeschl 6111: }
                   6112: 
1.721     harmsja  6113: div.LC_columnSection>* {
1.693     droeschl 6114: 	float: left;
1.803     bisitz   6115: 	margin: 10px 20px 10px 0;
1.747     neumanie 6116: 	overflow:hidden;
1.693     droeschl 6117: }
1.721     harmsja  6118: 
1.795     www      6119: .ContentBoxSpecialTemplate {
1.747     neumanie 6120:         border: solid 1px $lg_border_color;
1.719     ehlerst  6121: }
1.795     www      6122: 
1.719     ehlerst  6123: .ContentBoxTemplate {
                   6124:         padding:10px;
                   6125: }
                   6126: 
1.721     harmsja  6127: div.LC_columnSection > .ContentBoxTemplate,
1.795     www      6128: div.LC_columnSection > .ContentBoxSpecialTemplate {
1.719     ehlerst  6129:         width: 600px;
                   6130: }
1.753     droeschl 6131: 
1.795     www      6132: .clear {
1.720     ehlerst  6133: 	clear: both;
1.803     bisitz   6134: 	line-height: 0;
                   6135: 	font-size: 0;
                   6136: 	height: 0;
1.720     ehlerst  6137: }
1.693     droeschl 6138: 
1.694     tempelho 6139: .LC_loginpage_container {
                   6140: 	text-align:left;
                   6141: 	margin : 0 auto;
1.785     tempelho 6142: 	width:90%;
1.694     tempelho 6143: 	padding: 10px;
                   6144: 	height: auto;
1.712     muellerd 6145: 	background-color:#FFFFFF;
1.694     tempelho 6146: 	border:1px solid #CCCCCC;
                   6147: }
                   6148: 
                   6149: 
                   6150: .LC_loginpage_loginContainer {
                   6151: 	float:left;
1.712     muellerd 6152: 	width: 182px;
1.785     tempelho 6153: 	padding: 2px;
1.712     muellerd 6154: 	border:1px solid #CCCCCC;
                   6155: 	background-color:$loginbg;
1.694     tempelho 6156: }
                   6157: 
1.795     www      6158: .LC_loginpage_loginContainer h2 {
1.803     bisitz   6159: 	margin-top: 0;
1.712     muellerd 6160: 	display:block;
                   6161: 	background:$bgcol;
                   6162: 	color:$textcol;
                   6163: 	padding-left:5px;
                   6164: }
1.785     tempelho 6165: 
1.694     tempelho 6166: .LC_loginpage_loginInfo {
                   6167: 	float:left;
1.785     tempelho 6168: 	width:182px;
1.694     tempelho 6169: 	border:1px solid #CCCCCC;
1.785     tempelho 6170: 	padding:2px;
1.712     muellerd 6171: }
                   6172: 
1.694     tempelho 6173: .LC_loginpage_space {
1.754     droeschl 6174: 	clear: both;
                   6175: 	margin-bottom: 20px;
1.694     tempelho 6176: 	border-bottom: 1px solid #CCCCCC;
                   6177: }
                   6178: 
1.785     tempelho 6179: .LC_loginpage_floatLeft {
                   6180: 	float: left;
                   6181: 	width: 200px;
                   6182: 	margin: 0;
                   6183: }
                   6184: 
1.795     www      6185: table em {
1.754     droeschl 6186: 	font-weight: bold;
                   6187: 	font-style: normal;
1.748     schulted 6188: }
1.795     www      6189: 
1.779     bisitz   6190: table.LC_tableBrowseRes,
1.795     www      6191: table.LC_tableOfContent {
1.769     schulted 6192:         border:none;
                   6193: 	border-spacing: 1;
1.754     droeschl 6194: 	padding: 3px;
                   6195: 	background-color: #FFFFFF;
                   6196: 	font-size: 90%;
1.753     droeschl 6197: }
1.789     droeschl 6198: 
                   6199: table.LC_tableOfContent{
                   6200:     border-collapse: collapse;
                   6201: }
                   6202: 
1.771     droeschl 6203: table.LC_tableBrowseRes a,
1.768     schulted 6204: table.LC_tableOfContent a {
1.771     droeschl 6205:         background-color: transparent;
1.753     droeschl 6206: 	text-decoration: none;
                   6207: }
                   6208: 
1.771     droeschl 6209: table.LC_tableBrowseRes tr.LC_trOdd,
1.768     schulted 6210: table.LC_tableOfContent tr.LC_trOdd{
1.754     droeschl 6211: 	background-color: #EEEEEE;
1.753     droeschl 6212: }
                   6213: 
1.795     www      6214: table.LC_tableOfContent img {
1.753     droeschl 6215: 	border: none;
                   6216: 	height: 1.3em;
                   6217: 	vertical-align: text-bottom;
                   6218: 	margin-right: 0.3em;
                   6219: }
1.757     schulted 6220: 
1.795     www      6221: a#LC_content_toolbar_firsthomework {
1.774     ehlerst  6222: 	background-image:url(/res/adm/pages/open-first-problem.gif);
                   6223: }
                   6224: 
1.795     www      6225: a#LC_content_toolbar_launchnav {
1.774     ehlerst  6226: 	background-image:url(/res/adm/pages/start-navigation.gif);
                   6227: }
                   6228: 
1.795     www      6229: a#LC_content_toolbar_closenav {
1.774     ehlerst  6230: 	background-image:url(/res/adm/pages/close-navigation.gif);
                   6231: }
                   6232: 
1.795     www      6233: a#LC_content_toolbar_everything {
1.774     ehlerst  6234: 	background-image:url(/res/adm/pages/show-all.gif);
                   6235: }
                   6236: 
1.795     www      6237: a#LC_content_toolbar_uncompleted {
1.774     ehlerst  6238: 	background-image:url(/res/adm/pages/show-incomplete-problems.gif);
                   6239: }
                   6240: 
1.795     www      6241: #LC_content_toolbar_clearbubbles {
1.774     ehlerst  6242: 	background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
                   6243: }
                   6244: 
1.795     www      6245: a#LC_content_toolbar_changefolder {
1.757     schulted 6246: 	background : url(/res/adm/pages/close-all-folders.gif) top center ;
                   6247: }
                   6248: 
1.795     www      6249: a#LC_content_toolbar_changefolder_toggled {
1.757     schulted 6250: 	background-image:url(/res/adm/pages/open-all-folders.gif);
                   6251: }
                   6252: 
1.795     www      6253: ul#LC_toolbar li a:hover {
1.757     schulted 6254: 	background-position: bottom center;
                   6255: }
                   6256: 
1.795     www      6257: ul#LC_toolbar {
1.803     bisitz   6258: 	padding: 0;
1.757     schulted 6259: 	margin: 2px;
                   6260: 	list-style:none;
                   6261: 	position:relative;
                   6262: 	background-color:white;
                   6263: }
                   6264: 
1.795     www      6265: ul#LC_toolbar li {
1.757     schulted 6266: 	border:1px solid white;
1.803     bisitz   6267: 	padding: 0;
1.757     schulted 6268: 	margin: 0;
1.795     www      6269:         float: left;
1.767     droeschl 6270: 	display:inline;
1.757     schulted 6271: 	vertical-align:middle;
1.795     www      6272: } 
1.757     schulted 6273: 
1.783     amueller 6274: 
1.795     www      6275: a.LC_toolbarItem {
1.767     droeschl 6276: 	display:block;
1.803     bisitz   6277: 	padding: 0;
                   6278: 	margin: 0;
1.757     schulted 6279: 	height: 32px;
                   6280: 	width: 32px;
1.779     bisitz   6281: 	color:white;
1.803     bisitz   6282: 	border: none;
1.757     schulted 6283: 	background-repeat:no-repeat;
                   6284: 	background-color:transparent;
                   6285: }
                   6286: 
1.782     bisitz   6287: ul.LC_functionslist li {
                   6288:   float: left;
                   6289:   white-space: nowrap;
                   6290:   height: 35px; /* at least as high as heighest list item */
1.803     bisitz   6291:   margin: 0 15px 15px 10px;
1.782     bisitz   6292: }
                   6293: 
1.757     schulted 6294: 
1.343     albertel 6295: END
                   6296: }
                   6297: 
1.306     albertel 6298: =pod
                   6299: 
                   6300: =item * &headtag()
                   6301: 
                   6302: Returns a uniform footer for LON-CAPA web pages.
                   6303: 
1.307     albertel 6304: Inputs: $title - optional title for the head
                   6305:         $head_extra - optional extra HTML to put inside the <head>
1.315     albertel 6306:         $args - optional arguments
1.319     albertel 6307:             force_register - if is true call registerurl so the remote is 
                   6308:                              informed
1.415     albertel 6309:             redirect       -> array ref of
                   6310:                                    1- seconds before redirect occurs
                   6311:                                    2- url to redirect to
                   6312:                                    3- whether the side effect should occur
1.315     albertel 6313:                            (side effect of setting 
                   6314:                                $env{'internal.head.redirect'} to the url 
                   6315:                                redirected too)
1.352     albertel 6316:             domain         -> force to color decorate a page for a specific
                   6317:                                domain
                   6318:             function       -> force usage of a specific rolish color scheme
                   6319:             bgcolor        -> override the default page bgcolor
1.460     albertel 6320:             no_auto_mt_title
                   6321:                            -> prevent &mt()ing the title arg
1.464     albertel 6322: 
1.306     albertel 6323: =cut
                   6324: 
                   6325: sub headtag {
1.313     albertel 6326:     my ($title,$head_extra,$args) = @_;
1.306     albertel 6327:     
1.363     albertel 6328:     my $function = $args->{'function'} || &get_users_function();
                   6329:     my $domain   = $args->{'domain'}   || &determinedomain();
                   6330:     my $bgcolor  = $args->{'bgcolor'}  || &designparm($function.'.pgbg',$domain);
1.418     albertel 6331:     my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458     albertel 6332: 		   $Apache::lonnet::perlvar{'lonVersion'},
1.531     albertel 6333: 		   #time(),
1.418     albertel 6334: 		   $env{'environment.color.timestamp'},
1.363     albertel 6335: 		   $function,$domain,$bgcolor);
                   6336: 
1.369     www      6337:     $url = '/adm/css/'.&escape($url).'.css';
1.363     albertel 6338: 
1.308     albertel 6339:     my $result =
                   6340: 	'<head>'.
1.461     albertel 6341: 	&font_settings();
1.319     albertel 6342: 
1.461     albertel 6343:     if (!$args->{'frameset'}) {
                   6344: 	$result .= &Apache::lonhtmlcommon::htmlareaheaders();
                   6345:     }
1.319     albertel 6346:     if ($args->{'force_register'}) {
                   6347: 	$result .= &Apache::lonmenu::registerurl(1);
                   6348:     }
1.436     albertel 6349:     if (!$args->{'no_nav_bar'} 
                   6350: 	&& !$args->{'only_body'}
                   6351: 	&& !$args->{'frameset'}) {
                   6352: 	$result .= &help_menu_js();
                   6353:     }
1.319     albertel 6354: 
1.314     albertel 6355:     if (ref($args->{'redirect'})) {
1.414     albertel 6356: 	my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315     albertel 6357: 	$url = &Apache::lonenc::check_encrypt($url);
1.414     albertel 6358: 	if (!$inhibit_continue) {
                   6359: 	    $env{'internal.head.redirect'} = $url;
                   6360: 	}
1.313     albertel 6361: 	$result.=<<ADDMETA
                   6362: <meta http-equiv="pragma" content="no-cache" />
1.344     albertel 6363: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313     albertel 6364: ADDMETA
                   6365:     }
1.306     albertel 6366:     if (!defined($title)) {
                   6367: 	$title = 'The LearningOnline Network with CAPA';
                   6368:     }
1.460     albertel 6369:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
                   6370:     $result .= '<title> LON-CAPA '.$title.'</title>'
1.414     albertel 6371: 	.'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
                   6372: 	.$head_extra;
1.306     albertel 6373:     return $result;
                   6374: }
                   6375: 
                   6376: =pod
                   6377: 
1.340     albertel 6378: =item * &font_settings()
                   6379: 
                   6380: Returns neccessary <meta> to set the proper encoding
                   6381: 
                   6382: Inputs: none
                   6383: 
                   6384: =cut
                   6385: 
                   6386: sub font_settings {
                   6387:     my $headerstring='';
1.647     www      6388:     if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340     albertel 6389: 	$headerstring.=
                   6390: 	    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
                   6391:     }
                   6392:     return $headerstring;
                   6393: }
                   6394: 
1.341     albertel 6395: =pod
                   6396: 
                   6397: =item * &xml_begin()
                   6398: 
                   6399: Returns the needed doctype and <html>
                   6400: 
                   6401: Inputs: none
                   6402: 
                   6403: =cut
                   6404: 
                   6405: sub xml_begin {
                   6406:     my $output='';
                   6407: 
1.592     albertel 6408:     if ($env{'internal.start_page'}==1) {
                   6409: 	&Apache::lonhtmlcommon::init_htmlareafields();
                   6410:     }
1.342     albertel 6411: 
1.341     albertel 6412:     if ($env{'browser.mathml'}) {
                   6413: 	$output='<?xml version="1.0"?>'
                   6414:             #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
                   6415: #            .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
                   6416:             
                   6417: #	    .'<!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">] >'
                   6418: 	    .'<!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">'
                   6419:             .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" ' 
                   6420: 	    .'xmlns="http://www.w3.org/1999/xhtml">';
                   6421:     } else {
                   6422: 	$output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
                   6423:     }
                   6424:     return $output;
                   6425: }
1.340     albertel 6426: 
                   6427: =pod
                   6428: 
1.306     albertel 6429: =item * &endheadtag()
                   6430: 
                   6431: Returns a uniform </head> for LON-CAPA web pages.
                   6432: 
                   6433: Inputs: none
                   6434: 
                   6435: =cut
                   6436: 
                   6437: sub endheadtag {
                   6438:     return '</head>';
                   6439: }
                   6440: 
                   6441: =pod
                   6442: 
                   6443: =item * &head()
                   6444: 
                   6445: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
                   6446: 
1.648     raeburn  6447: Inputs:
                   6448: 
                   6449: =over 4
                   6450: 
                   6451: $title - optional title for the page
                   6452: 
                   6453: $head_extra - optional extra HTML to put inside the <head>
                   6454: 
                   6455: =back
1.405     albertel 6456: 
1.306     albertel 6457: =cut
                   6458: 
                   6459: sub head {
1.325     albertel 6460:     my ($title,$head_extra,$args) = @_;
                   6461:     return &headtag($title,$head_extra,$args).&endheadtag();
1.306     albertel 6462: }
                   6463: 
                   6464: =pod
                   6465: 
                   6466: =item * &start_page()
                   6467: 
                   6468: Returns a complete <html> .. <body> section for LON-CAPA web pages.
                   6469: 
1.648     raeburn  6470: Inputs:
                   6471: 
                   6472: =over 4
                   6473: 
                   6474: $title - optional title for the page
                   6475: 
                   6476: $head_extra - optional extra HTML to incude inside the <head>
                   6477: 
                   6478: $args - additional optional args supported are:
                   6479: 
                   6480: =over 8
                   6481: 
                   6482:              only_body      -> is true will set &bodytag() onlybodytag
1.317     albertel 6483:                                     arg on
1.648     raeburn  6484:              no_nav_bar     -> is true will set &bodytag() notopbar arg on
                   6485:              add_entries    -> additional attributes to add to the  <body>
                   6486:              domain         -> force to color decorate a page for a 
1.317     albertel 6487:                                     specific domain
1.648     raeburn  6488:              function       -> force usage of a specific rolish color
1.317     albertel 6489:                                     scheme
1.648     raeburn  6490:              redirect       -> see &headtag()
                   6491:              bgcolor        -> override the default page bg color
                   6492:              js_ready       -> return a string ready for being used in 
1.317     albertel 6493:                                     a javascript writeln
1.648     raeburn  6494:              html_encode    -> return a string ready for being used in 
1.320     albertel 6495:                                     a html attribute
1.648     raeburn  6496:              force_register -> if is true will turn on the &bodytag()
1.317     albertel 6497:                                     $forcereg arg
1.648     raeburn  6498:              body_title     -> alternate text to use instead of $title
1.326     albertel 6499:                                     in the title box that appears, this text
                   6500:                                     is not auto translated like the $title is
1.648     raeburn  6501:              frameset       -> if true will start with a <frameset>
1.330     albertel 6502:                                     rather than <body>
1.648     raeburn  6503:              no_title       -> if true the title bar won't be shown
                   6504:              skip_phases    -> hash ref of 
1.338     albertel 6505:                                     head -> skip the <html><head> generation
                   6506:                                     body -> skip all <body> generation
1.648     raeburn  6507:              no_inline_link -> if true and in remote mode, don't show the 
1.361     albertel 6508:                                     'Switch To Inline Menu' link
1.648     raeburn  6509:              no_auto_mt_title -> prevent &mt()ing the title arg
                   6510:              inherit_jsmath -> when creating popup window in a page,
                   6511:                                     should it have jsmath forced on by the
                   6512:                                     current page
1.361     albertel 6513: 
1.648     raeburn  6514: =back
1.460     albertel 6515: 
1.648     raeburn  6516: =back
1.562     albertel 6517: 
1.306     albertel 6518: =cut
                   6519: 
                   6520: sub start_page {
1.309     albertel 6521:     my ($title,$head_extra,$args) = @_;
1.318     albertel 6522:     #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313     albertel 6523:     my %head_args;
1.352     albertel 6524:     foreach my $arg ('redirect','force_register','domain','function',
1.460     albertel 6525: 		     'bgcolor','frameset','no_nav_bar','only_body',
                   6526: 		     'no_auto_mt_title') {
1.319     albertel 6527: 	if (defined($args->{$arg})) {
1.324     raeburn  6528: 	    $head_args{$arg} = $args->{$arg};
1.319     albertel 6529: 	}
1.313     albertel 6530:     }
1.319     albertel 6531: 
1.315     albertel 6532:     $env{'internal.start_page'}++;
1.338     albertel 6533:     my $result;
                   6534:     if (! exists($args->{'skip_phases'}{'head'}) ) {
                   6535: 	$result.=
1.341     albertel 6536: 	    &xml_begin().
1.338     albertel 6537: 	    &headtag($title,$head_extra,\%head_args).&endheadtag();
                   6538:     }
                   6539:     
                   6540:     if (! exists($args->{'skip_phases'}{'body'}) ) {
                   6541: 	if ($args->{'frameset'}) {
                   6542: 	    my $attr_string = &make_attr_string($args->{'force_register'},
                   6543: 						$args->{'add_entries'});
                   6544: 	    $result .= "\n<frameset $attr_string>\n";
                   6545: 	} else {
                   6546: 	    $result .=
                   6547: 		&bodytag($title, 
                   6548: 			 $args->{'function'},       $args->{'add_entries'},
                   6549: 			 $args->{'only_body'},      $args->{'domain'},
                   6550: 			 $args->{'force_register'}, $args->{'body_title'},
                   6551: 			 $args->{'no_nav_bar'},     $args->{'bgcolor'},
1.460     albertel 6552: 			 $args->{'no_title'},       $args->{'no_inline_link'},
                   6553: 			 $args);
1.338     albertel 6554: 	}
1.330     albertel 6555:     }
1.338     albertel 6556: 
1.315     albertel 6557:     if ($args->{'js_ready'}) {
1.713     kaisler  6558: 		$result = &js_ready($result);
1.315     albertel 6559:     }
1.320     albertel 6560:     if ($args->{'html_encode'}) {
1.713     kaisler  6561: 		$result = &html_encode($result);
                   6562:     }
                   6563: 
1.758     kaisler  6564: 	#Breadcrumbs
                   6565:     if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
                   6566: 		&Apache::lonhtmlcommon::clear_breadcrumbs();
                   6567: 		#if any br links exists, add them to the breadcrumbs
                   6568: 		if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {         
                   6569: 			foreach my $crumb (@{$args->{'bread_crumbs'}}){
                   6570: 				&Apache::lonhtmlcommon::add_breadcrumb($crumb);
                   6571: 			}
                   6572: 		}
                   6573: 
                   6574: 		#if bread_crumbs_component exists show it as headline else show only the breadcrumbs
                   6575: 		if(exists($args->{'bread_crumbs_component'})){
                   6576: 			$result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
                   6577: 		}else{
                   6578: 			$result .= &Apache::lonhtmlcommon::breadcrumbs();
                   6579: 		}
1.320     albertel 6580:     }
1.315     albertel 6581:     return $result;
1.306     albertel 6582: }
                   6583: 
1.330     albertel 6584: 
1.306     albertel 6585: =pod
                   6586: 
                   6587: =item * &head()
                   6588: 
                   6589: Returns a complete </body></html> section for LON-CAPA web pages.
                   6590: 
1.315     albertel 6591: Inputs:         $args - additional optional args supported are:
                   6592:                  js_ready     -> return a string ready for being used in 
                   6593:                                  a javascript writeln
1.320     albertel 6594:                  html_encode  -> return a string ready for being used in 
                   6595:                                  a html attribute
1.330     albertel 6596:                  frameset     -> if true will start with a <frameset>
                   6597:                                  rather than <body>
1.493     albertel 6598:                  dicsussion   -> if true will get discussion from
                   6599:                                   lonxml::xmlend
                   6600:                                  (you can pass the target and parser arguments
                   6601:                                   through optional 'target' and 'parser' args
                   6602:                                   to this routine)
1.306     albertel 6603: 
                   6604: =cut
                   6605: 
                   6606: sub end_page {
1.315     albertel 6607:     my ($args) = @_;
                   6608:     $env{'internal.end_page'}++;
1.330     albertel 6609:     my $result;
1.335     albertel 6610:     if ($args->{'discussion'}) {
                   6611: 	my ($target,$parser);
                   6612: 	if (ref($args->{'discussion'})) {
                   6613: 	    ($target,$parser) =($args->{'discussion'}{'target'},
                   6614: 				$args->{'discussion'}{'parser'});
                   6615: 	}
                   6616: 	$result .= &Apache::lonxml::xmlend($target,$parser);
                   6617:     }
                   6618: 
1.330     albertel 6619:     if ($args->{'frameset'}) {
                   6620: 	$result .= '</frameset>';
                   6621:     } else {
1.635     raeburn  6622: 	$result .= &endbodytag($args);
1.330     albertel 6623:     }
                   6624:     $result .= "\n</html>";
                   6625: 
1.315     albertel 6626:     if ($args->{'js_ready'}) {
1.317     albertel 6627: 	$result = &js_ready($result);
1.315     albertel 6628:     }
1.335     albertel 6629: 
1.320     albertel 6630:     if ($args->{'html_encode'}) {
                   6631: 	$result = &html_encode($result);
                   6632:     }
1.335     albertel 6633: 
1.315     albertel 6634:     return $result;
                   6635: }
                   6636: 
1.320     albertel 6637: sub html_encode {
                   6638:     my ($result) = @_;
                   6639: 
1.322     albertel 6640:     $result = &HTML::Entities::encode($result,'<>&"');
1.320     albertel 6641:     
                   6642:     return $result;
                   6643: }
1.317     albertel 6644: sub js_ready {
                   6645:     my ($result) = @_;
                   6646: 
1.323     albertel 6647:     $result =~ s/[\n\r]/ /xmsg;
                   6648:     $result =~ s/\\/\\\\/xmsg;
                   6649:     $result =~ s/'/\\'/xmsg;
1.372     albertel 6650:     $result =~ s{</}{<\\/}xmsg;
1.317     albertel 6651:     
                   6652:     return $result;
                   6653: }
                   6654: 
1.315     albertel 6655: sub validate_page {
                   6656:     if (  exists($env{'internal.start_page'})
1.316     albertel 6657: 	  &&     $env{'internal.start_page'} > 1) {
                   6658: 	&Apache::lonnet::logthis('start_page called multiple times '.
1.318     albertel 6659: 				 $env{'internal.start_page'}.' '.
1.316     albertel 6660: 				 $ENV{'request.filename'});
1.315     albertel 6661:     }
                   6662:     if (  exists($env{'internal.end_page'})
1.316     albertel 6663: 	  &&     $env{'internal.end_page'} > 1) {
                   6664: 	&Apache::lonnet::logthis('end_page called multiple times '.
1.318     albertel 6665: 				 $env{'internal.end_page'}.' '.
1.316     albertel 6666: 				 $env{'request.filename'});
1.315     albertel 6667:     }
                   6668:     if (     exists($env{'internal.start_page'})
                   6669: 	&& ! exists($env{'internal.end_page'})) {
1.316     albertel 6670: 	&Apache::lonnet::logthis('start_page called without end_page '.
                   6671: 				 $env{'request.filename'});
1.315     albertel 6672:     }
                   6673:     if (   ! exists($env{'internal.start_page'})
                   6674: 	&&   exists($env{'internal.end_page'})) {
1.316     albertel 6675: 	&Apache::lonnet::logthis('end_page called without start_page'.
                   6676: 				 $env{'request.filename'});
1.315     albertel 6677:     }
1.306     albertel 6678: }
1.315     albertel 6679: 
1.318     albertel 6680: sub simple_error_page {
                   6681:     my ($r,$title,$msg) = @_;
                   6682:     my $page =
                   6683: 	&Apache::loncommon::start_page($title).
                   6684: 	&mt($msg).
                   6685: 	&Apache::loncommon::end_page();
                   6686:     if (ref($r)) {
                   6687: 	$r->print($page);
1.327     albertel 6688: 	return;
1.318     albertel 6689:     }
                   6690:     return $page;
                   6691: }
1.347     albertel 6692: 
                   6693: {
1.610     albertel 6694:     my @row_count;
1.347     albertel 6695:     sub start_data_table {
1.422     albertel 6696: 	my ($add_class) = @_;
                   6697: 	my $css_class = (join(' ','LC_data_table',$add_class));
1.610     albertel 6698: 	unshift(@row_count,0);
1.422     albertel 6699: 	return '<table class="'.$css_class.'">'."\n";
1.347     albertel 6700:     }
                   6701: 
                   6702:     sub end_data_table {
1.610     albertel 6703: 	shift(@row_count);
1.389     albertel 6704: 	return '</table>'."\n";;
1.347     albertel 6705:     }
                   6706: 
                   6707:     sub start_data_table_row {
1.422     albertel 6708: 	my ($add_class) = @_;
1.610     albertel 6709: 	$row_count[0]++;
                   6710: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428     albertel 6711: 	$css_class = (join(' ',$css_class,$add_class));
1.422     albertel 6712: 	return  '<tr class="'.$css_class.'">'."\n";;
1.347     albertel 6713:     }
1.471     banghart 6714:     
                   6715:     sub continue_data_table_row {
                   6716: 	my ($add_class) = @_;
1.610     albertel 6717: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471     banghart 6718: 	$css_class = (join(' ',$css_class,$add_class));
                   6719: 	return  '<tr class="'.$css_class.'">'."\n";;
                   6720:     }
1.347     albertel 6721: 
                   6722:     sub end_data_table_row {
1.389     albertel 6723: 	return '</tr>'."\n";;
1.347     albertel 6724:     }
1.367     www      6725: 
1.421     albertel 6726:     sub start_data_table_empty_row {
1.707     bisitz   6727: #	$row_count[0]++;
1.421     albertel 6728: 	return  '<tr class="LC_empty_row" >'."\n";;
                   6729:     }
                   6730: 
                   6731:     sub end_data_table_empty_row {
                   6732: 	return '</tr>'."\n";;
                   6733:     }
                   6734: 
1.367     www      6735:     sub start_data_table_header_row {
1.389     albertel 6736: 	return  '<tr class="LC_header_row">'."\n";;
1.367     www      6737:     }
                   6738: 
                   6739:     sub end_data_table_header_row {
1.389     albertel 6740: 	return '</tr>'."\n";;
1.367     www      6741:     }
1.347     albertel 6742: }
                   6743: 
1.548     albertel 6744: =pod
                   6745: 
                   6746: =item * &inhibit_menu_check($arg)
                   6747: 
                   6748: Checks for a inhibitmenu state and generates output to preserve it
                   6749: 
                   6750: Inputs:         $arg - can be any of
                   6751:                      - undef - in which case the return value is a string 
                   6752:                                to add  into arguments list of a uri
                   6753:                      - 'input' - in which case the return value is a HTML
                   6754:                                  <form> <input> field of type hidden to
                   6755:                                  preserve the value
                   6756:                      - a url - in which case the return value is the url with
                   6757:                                the neccesary cgi args added to preserve the
                   6758:                                inhibitmenu state
                   6759:                      - a ref to a url - no return value, but the string is
                   6760:                                         updated to include the neccessary cgi
                   6761:                                         args to preserve the inhibitmenu state
                   6762: 
                   6763: =cut
                   6764: 
                   6765: sub inhibit_menu_check {
                   6766:     my ($arg) = @_;
                   6767:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   6768:     if ($arg eq 'input') {
                   6769: 	if ($env{'form.inhibitmenu'}) {
                   6770: 	    return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
                   6771: 	} else {
                   6772: 	    return
                   6773: 	}
                   6774:     }
                   6775:     if ($env{'form.inhibitmenu'}) {
                   6776: 	if (ref($arg)) {
                   6777: 	    $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   6778: 	} elsif ($arg eq '') {
                   6779: 	    $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
                   6780: 	} else {
                   6781: 	    $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   6782: 	}
                   6783:     }
                   6784:     if (!ref($arg)) {
                   6785: 	return $arg;
                   6786:     }
                   6787: }
                   6788: 
1.251     albertel 6789: ###############################################
1.182     matthew  6790: 
                   6791: =pod
                   6792: 
1.549     albertel 6793: =back
                   6794: 
                   6795: =head1 User Information Routines
                   6796: 
                   6797: =over 4
                   6798: 
1.405     albertel 6799: =item * &get_users_function()
1.182     matthew  6800: 
                   6801: Used by &bodytag to determine the current users primary role.
                   6802: Returns either 'student','coordinator','admin', or 'author'.
                   6803: 
                   6804: =cut
                   6805: 
                   6806: ###############################################
                   6807: sub get_users_function {
                   6808:     my $function = 'student';
1.258     albertel 6809:     if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182     matthew  6810:         $function='coordinator';
                   6811:     }
1.258     albertel 6812:     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182     matthew  6813:         $function='admin';
                   6814:     }
1.258     albertel 6815:     if (($env{'request.role'}=~/^(au|ca)/) ||
1.182     matthew  6816:         ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
                   6817:         $function='author';
                   6818:     }
                   6819:     return $function;
1.54      www      6820: }
1.99      www      6821: 
                   6822: ###############################################
                   6823: 
1.233     raeburn  6824: =pod
                   6825: 
1.542     raeburn  6826: =item * &check_user_status()
1.274     raeburn  6827: 
                   6828: Determines current status of supplied role for a
                   6829: specific user. Roles can be active, previous or future.
                   6830: 
                   6831: Inputs: 
                   6832: user's domain, user's username, course's domain,
1.375     raeburn  6833: course's number, optional section ID.
1.274     raeburn  6834: 
                   6835: Outputs:
                   6836: role status: active, previous or future. 
                   6837: 
                   6838: =cut
                   6839: 
                   6840: sub check_user_status {
1.412     raeburn  6841:     my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274     raeburn  6842:     my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
                   6843:     my @uroles = keys %userinfo;
                   6844:     my $srchstr;
                   6845:     my $active_chk = 'none';
1.412     raeburn  6846:     my $now = time;
1.274     raeburn  6847:     if (@uroles > 0) {
1.412     raeburn  6848:         if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274     raeburn  6849:             $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
                   6850:         } else {
1.412     raeburn  6851:             $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
                   6852:         }
                   6853:         if (grep/^\Q$srchstr\E$/,@uroles) {
1.274     raeburn  6854:             my $role_end = 0;
                   6855:             my $role_start = 0;
                   6856:             $active_chk = 'active';
1.412     raeburn  6857:             if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
                   6858:                 $role_end = $1;
                   6859:                 if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
                   6860:                     $role_start = $1;
1.274     raeburn  6861:                 }
                   6862:             }
                   6863:             if ($role_start > 0) {
1.412     raeburn  6864:                 if ($now < $role_start) {
1.274     raeburn  6865:                     $active_chk = 'future';
                   6866:                 }
                   6867:             }
                   6868:             if ($role_end > 0) {
1.412     raeburn  6869:                 if ($now > $role_end) {
1.274     raeburn  6870:                     $active_chk = 'previous';
                   6871:                 }
                   6872:             }
                   6873:         }
                   6874:     }
                   6875:     return $active_chk;
                   6876: }
                   6877: 
                   6878: ###############################################
                   6879: 
                   6880: =pod
                   6881: 
1.405     albertel 6882: =item * &get_sections()
1.233     raeburn  6883: 
                   6884: Determines all the sections for a course including
                   6885: sections with students and sections containing other roles.
1.419     raeburn  6886: Incoming parameters: 
                   6887: 
                   6888: 1. domain
                   6889: 2. course number 
                   6890: 3. reference to array containing roles for which sections should 
                   6891: be gathered (optional).
                   6892: 4. reference to array containing status types for which sections 
                   6893: should be gathered (optional).
                   6894: 
                   6895: If the third argument is undefined, sections are gathered for any role. 
                   6896: If the fourth argument is undefined, sections are gathered for any status.
                   6897: Permissible values are 'active' or 'future' or 'previous'.
1.233     raeburn  6898:  
1.374     raeburn  6899: Returns section hash (keys are section IDs, values are
                   6900: number of users in each section), subject to the
1.419     raeburn  6901: optional roles filter, optional status filter 
1.233     raeburn  6902: 
                   6903: =cut
                   6904: 
                   6905: ###############################################
                   6906: sub get_sections {
1.419     raeburn  6907:     my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366     albertel 6908:     if (!defined($cdom) || !defined($cnum)) {
                   6909:         my $cid =  $env{'request.course.id'};
                   6910: 
                   6911: 	return if (!defined($cid));
                   6912: 
                   6913:         $cdom = $env{'course.'.$cid.'.domain'};
                   6914:         $cnum = $env{'course.'.$cid.'.num'};
                   6915:     }
                   6916: 
                   6917:     my %sectioncount;
1.419     raeburn  6918:     my $now = time;
1.240     albertel 6919: 
1.366     albertel 6920:     if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276     albertel 6921: 	my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240     albertel 6922: 	my $sec_index = &Apache::loncoursedata::CL_SECTION();
                   6923: 	my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419     raeburn  6924:         my $start_index = &Apache::loncoursedata::CL_START();
                   6925:         my $end_index = &Apache::loncoursedata::CL_END();
                   6926:         my $status;
1.366     albertel 6927: 	while (my ($student,$data) = each(%$classlist)) {
1.419     raeburn  6928: 	    my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
                   6929: 				                     $data->[$status_index],
                   6930:                                                      $data->[$start_index],
                   6931:                                                      $data->[$end_index]);
                   6932:             if ($stu_status eq 'Active') {
                   6933:                 $status = 'active';
                   6934:             } elsif ($end < $now) {
                   6935:                 $status = 'previous';
                   6936:             } elsif ($start > $now) {
                   6937:                 $status = 'future';
                   6938:             } 
                   6939: 	    if ($section ne '-1' && $section !~ /^\s*$/) {
                   6940:                 if ((!defined($possible_status)) || (($status ne '') && 
                   6941:                     (grep/^\Q$status\E$/,@{$possible_status}))) { 
                   6942: 		    $sectioncount{$section}++;
                   6943:                 }
1.240     albertel 6944: 	    }
                   6945: 	}
                   6946:     }
                   6947:     my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   6948:     foreach my $user (sort(keys(%courseroles))) {
                   6949: 	if ($user !~ /^(\w{2})/) { next; }
                   6950: 	my ($role) = ($user =~ /^(\w{2})/);
                   6951: 	if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419     raeburn  6952: 	my ($section,$status);
1.240     albertel 6953: 	if ($role eq 'cr' &&
                   6954: 	    $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
                   6955: 	    $section=$1;
                   6956: 	}
                   6957: 	if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
                   6958: 	if (!defined($section) || $section eq '-1') { next; }
1.419     raeburn  6959:         my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
                   6960:         if ($end == -1 && $start == -1) {
                   6961:             next; #deleted role
                   6962:         }
                   6963:         if (!defined($possible_status)) { 
                   6964:             $sectioncount{$section}++;
                   6965:         } else {
                   6966:             if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
                   6967:                 $status = 'active';
                   6968:             } elsif ($end < $now) {
                   6969:                 $status = 'future';
                   6970:             } elsif ($start > $now) {
                   6971:                 $status = 'previous';
                   6972:             }
                   6973:             if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
                   6974:                 $sectioncount{$section}++;
                   6975:             }
                   6976:         }
1.233     raeburn  6977:     }
1.366     albertel 6978:     return %sectioncount;
1.233     raeburn  6979: }
                   6980: 
1.274     raeburn  6981: ###############################################
1.294     raeburn  6982: 
                   6983: =pod
1.405     albertel 6984: 
                   6985: =item * &get_course_users()
                   6986: 
1.275     raeburn  6987: Retrieves usernames:domains for users in the specified course
                   6988: with specific role(s), and access status. 
                   6989: 
                   6990: Incoming parameters:
1.277     albertel 6991: 1. course domain
                   6992: 2. course number
                   6993: 3. access status: users must have - either active, 
1.275     raeburn  6994: previous, future, or all.
1.277     albertel 6995: 4. reference to array of permissible roles
1.288     raeburn  6996: 5. reference to array of section restrictions (optional)
                   6997: 6. reference to results object (hash of hashes).
                   6998: 7. reference to optional userdata hash
1.609     raeburn  6999: 8. reference to optional statushash
1.630     raeburn  7000: 9. flag if privileged users (except those set to unhide in
                   7001:    course settings) should be excluded    
1.609     raeburn  7002: Keys of top level results hash are roles.
1.275     raeburn  7003: Keys of inner hashes are username:domain, with 
                   7004: values set to access type.
1.288     raeburn  7005: Optional userdata hash returns an array with arguments in the 
                   7006: same order as loncoursedata::get_classlist() for student data.
                   7007: 
1.609     raeburn  7008: Optional statushash returns
                   7009: 
1.288     raeburn  7010: Entries for end, start, section and status are blank because
                   7011: of the possibility of multiple values for non-student roles.
                   7012: 
1.275     raeburn  7013: =cut
1.405     albertel 7014: 
1.275     raeburn  7015: ###############################################
1.405     albertel 7016: 
1.275     raeburn  7017: sub get_course_users {
1.630     raeburn  7018:     my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288     raeburn  7019:     my %idx = ();
1.419     raeburn  7020:     my %seclists;
1.288     raeburn  7021: 
                   7022:     $idx{udom} = &Apache::loncoursedata::CL_SDOM();
                   7023:     $idx{uname} =  &Apache::loncoursedata::CL_SNAME();
                   7024:     $idx{end} = &Apache::loncoursedata::CL_END();
                   7025:     $idx{start} = &Apache::loncoursedata::CL_START();
                   7026:     $idx{id} = &Apache::loncoursedata::CL_ID();
                   7027:     $idx{section} = &Apache::loncoursedata::CL_SECTION();
                   7028:     $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
                   7029:     $idx{status} = &Apache::loncoursedata::CL_STATUS();
                   7030: 
1.290     albertel 7031:     if (grep(/^st$/,@{$roles})) {
1.276     albertel 7032:         my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278     raeburn  7033:         my $now = time;
1.277     albertel 7034:         foreach my $student (keys(%{$classlist})) {
1.288     raeburn  7035:             my $match = 0;
1.412     raeburn  7036:             my $secmatch = 0;
1.419     raeburn  7037:             my $section = $$classlist{$student}[$idx{section}];
1.609     raeburn  7038:             my $status = $$classlist{$student}[$idx{status}];
1.419     raeburn  7039:             if ($section eq '') {
                   7040:                 $section = 'none';
                   7041:             }
1.291     albertel 7042:             if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 7043:                 if (grep(/^all$/,@{$sections})) {
1.412     raeburn  7044:                     $secmatch = 1;
                   7045:                 } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420     albertel 7046:                     if (grep(/^none$/,@{$sections})) {
1.412     raeburn  7047:                         $secmatch = 1;
                   7048:                     }
                   7049:                 } else {  
1.419     raeburn  7050: 		    if (grep(/^\Q$section\E$/,@{$sections})) {
1.412     raeburn  7051: 		        $secmatch = 1;
                   7052:                     }
1.290     albertel 7053: 		}
1.412     raeburn  7054:                 if (!$secmatch) {
                   7055:                     next;
                   7056:                 }
1.419     raeburn  7057:             }
1.275     raeburn  7058:             if (defined($$types{'active'})) {
1.288     raeburn  7059:                 if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275     raeburn  7060:                     push(@{$$users{st}{$student}},'active');
1.288     raeburn  7061:                     $match = 1;
1.275     raeburn  7062:                 }
                   7063:             }
                   7064:             if (defined($$types{'previous'})) {
1.609     raeburn  7065:                 if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275     raeburn  7066:                     push(@{$$users{st}{$student}},'previous');
1.288     raeburn  7067:                     $match = 1;
1.275     raeburn  7068:                 }
                   7069:             }
                   7070:             if (defined($$types{'future'})) {
1.609     raeburn  7071:                 if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275     raeburn  7072:                     push(@{$$users{st}{$student}},'future');
1.288     raeburn  7073:                     $match = 1;
1.275     raeburn  7074:                 }
                   7075:             }
1.609     raeburn  7076:             if ($match) {
                   7077:                 push(@{$seclists{$student}},$section);
                   7078:                 if (ref($userdata) eq 'HASH') {
                   7079:                     $$userdata{$student} = $$classlist{$student};
                   7080:                 }
                   7081:                 if (ref($statushash) eq 'HASH') {
                   7082:                     $statushash->{$student}{'st'}{$section} = $status;
                   7083:                 }
1.288     raeburn  7084:             }
1.275     raeburn  7085:         }
                   7086:     }
1.412     raeburn  7087:     if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439     raeburn  7088:         my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7089:         my $now = time;
1.609     raeburn  7090:         my %displaystatus = ( previous => 'Expired',
                   7091:                               active   => 'Active',
                   7092:                               future   => 'Future',
                   7093:                             );
1.630     raeburn  7094:         my %nothide;
                   7095:         if ($hidepriv) {
                   7096:             my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
                   7097:             foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
                   7098:                 if ($user !~ /:/) {
                   7099:                     $nothide{join(':',split(/[\@]/,$user))}=1;
                   7100:                 } else {
                   7101:                     $nothide{$user} = 1;
                   7102:                 }
                   7103:             }
                   7104:         }
1.439     raeburn  7105:         foreach my $person (sort(keys(%coursepersonnel))) {
1.288     raeburn  7106:             my $match = 0;
1.412     raeburn  7107:             my $secmatch = 0;
1.439     raeburn  7108:             my $status;
1.412     raeburn  7109:             my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275     raeburn  7110:             $user =~ s/:$//;
1.439     raeburn  7111:             my ($end,$start) = split(/:/,$coursepersonnel{$person});
                   7112:             if ($end == -1 || $start == -1) {
                   7113:                 next;
                   7114:             }
                   7115:             if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
                   7116:                 (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412     raeburn  7117:                 my ($uname,$udom) = split(/:/,$user);
                   7118:                 if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 7119:                     if (grep(/^all$/,@{$sections})) {
1.412     raeburn  7120:                         $secmatch = 1;
                   7121:                     } elsif ($usec eq '') {
1.420     albertel 7122:                         if (grep(/^none$/,@{$sections})) {
1.412     raeburn  7123:                             $secmatch = 1;
                   7124:                         }
                   7125:                     } else {
                   7126:                         if (grep(/^\Q$usec\E$/,@{$sections})) {
                   7127:                             $secmatch = 1;
                   7128:                         }
                   7129:                     }
                   7130:                     if (!$secmatch) {
                   7131:                         next;
                   7132:                     }
1.288     raeburn  7133:                 }
1.419     raeburn  7134:                 if ($usec eq '') {
                   7135:                     $usec = 'none';
                   7136:                 }
1.275     raeburn  7137:                 if ($uname ne '' && $udom ne '') {
1.630     raeburn  7138:                     if ($hidepriv) {
                   7139:                         if ((&Apache::lonnet::privileged($uname,$udom)) &&
                   7140:                             (!$nothide{$uname.':'.$udom})) {
                   7141:                             next;
                   7142:                         }
                   7143:                     }
1.503     raeburn  7144:                     if ($end > 0 && $end < $now) {
1.439     raeburn  7145:                         $status = 'previous';
                   7146:                     } elsif ($start > $now) {
                   7147:                         $status = 'future';
                   7148:                     } else {
                   7149:                         $status = 'active';
                   7150:                     }
1.277     albertel 7151:                     foreach my $type (keys(%{$types})) { 
1.275     raeburn  7152:                         if ($status eq $type) {
1.420     albertel 7153:                             if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419     raeburn  7154:                                 push(@{$$users{$role}{$user}},$type);
                   7155:                             }
1.288     raeburn  7156:                             $match = 1;
                   7157:                         }
                   7158:                     }
1.419     raeburn  7159:                     if (($match) && (ref($userdata) eq 'HASH')) {
                   7160:                         if (!exists($$userdata{$uname.':'.$udom})) {
                   7161: 			    &get_user_info($udom,$uname,\%idx,$userdata);
                   7162:                         }
1.420     albertel 7163:                         if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419     raeburn  7164:                             push(@{$seclists{$uname.':'.$udom}},$usec);
                   7165:                         }
1.609     raeburn  7166:                         if (ref($statushash) eq 'HASH') {
                   7167:                             $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
                   7168:                         }
1.275     raeburn  7169:                     }
                   7170:                 }
                   7171:             }
                   7172:         }
1.290     albertel 7173:         if (grep(/^ow$/,@{$roles})) {
1.279     raeburn  7174:             if ((defined($cdom)) && (defined($cnum))) {
                   7175:                 my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
                   7176:                 if ( defined($csettings{'internal.courseowner'}) ) {
                   7177:                     my $owner = $csettings{'internal.courseowner'};
1.609     raeburn  7178:                     next if ($owner eq '');
                   7179:                     my ($ownername,$ownerdom);
                   7180:                     if ($owner =~ /^([^:]+):([^:]+)$/) {
                   7181:                         $ownername = $1;
                   7182:                         $ownerdom = $2;
                   7183:                     } else {
                   7184:                         $ownername = $owner;
                   7185:                         $ownerdom = $cdom;
                   7186:                         $owner = $ownername.':'.$ownerdom;
1.439     raeburn  7187:                     }
                   7188:                     @{$$users{'ow'}{$owner}} = 'any';
1.290     albertel 7189:                     if (defined($userdata) && 
1.609     raeburn  7190: 			!exists($$userdata{$owner})) {
                   7191: 			&get_user_info($ownerdom,$ownername,\%idx,$userdata);
                   7192:                         if (!grep(/^none$/,@{$seclists{$owner}})) {
                   7193:                             push(@{$seclists{$owner}},'none');
                   7194:                         }
                   7195:                         if (ref($statushash) eq 'HASH') {
                   7196:                             $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419     raeburn  7197:                         }
1.290     albertel 7198: 		    }
1.279     raeburn  7199:                 }
                   7200:             }
                   7201:         }
1.419     raeburn  7202:         foreach my $user (keys(%seclists)) {
                   7203:             @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
                   7204:             $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
                   7205:         }
1.275     raeburn  7206:     }
                   7207:     return;
                   7208: }
                   7209: 
1.288     raeburn  7210: sub get_user_info {
                   7211:     my ($udom,$uname,$idx,$userdata) = @_;
1.289     albertel 7212:     $$userdata{$uname.':'.$udom}[$$idx{fullname}] = 
                   7213: 	&plainname($uname,$udom,'lastname');
1.291     albertel 7214:     $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297     raeburn  7215:     $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609     raeburn  7216:     my %idhash =  &Apache::lonnet::idrget($udom,($uname));
                   7217:     $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname}; 
1.288     raeburn  7218:     return;
                   7219: }
1.275     raeburn  7220: 
1.472     raeburn  7221: ###############################################
                   7222: 
                   7223: =pod
                   7224: 
                   7225: =item * &get_user_quota()
                   7226: 
                   7227: Retrieves quota assigned for storage of portfolio files for a user  
                   7228: 
                   7229: Incoming parameters:
                   7230: 1. user's username
                   7231: 2. user's domain
                   7232: 
                   7233: Returns:
1.536     raeburn  7234: 1. Disk quota (in Mb) assigned to student.
                   7235: 2. (Optional) Type of setting: custom or default
                   7236:    (individually assigned or default for user's 
                   7237:    institutional status).
                   7238: 3. (Optional) - User's institutional status (e.g., faculty, staff
                   7239:    or student - types as defined in localenroll::inst_usertypes 
                   7240:    for user's domain, which determines default quota for user.
                   7241: 4. (Optional) - Default quota which would apply to the user.
1.472     raeburn  7242: 
                   7243: If a value has been stored in the user's environment, 
1.536     raeburn  7244: it will return that, otherwise it returns the maximal default
                   7245: defined for the user's instituional status(es) in the domain.
1.472     raeburn  7246: 
                   7247: =cut
                   7248: 
                   7249: ###############################################
                   7250: 
                   7251: 
                   7252: sub get_user_quota {
                   7253:     my ($uname,$udom) = @_;
1.536     raeburn  7254:     my ($quota,$quotatype,$settingstatus,$defquota);
1.472     raeburn  7255:     if (!defined($udom)) {
                   7256:         $udom = $env{'user.domain'};
                   7257:     }
                   7258:     if (!defined($uname)) {
                   7259:         $uname = $env{'user.name'};
                   7260:     }
                   7261:     if (($udom eq '' || $uname eq '') ||
                   7262:         ($udom eq 'public') && ($uname eq 'public')) {
                   7263:         $quota = 0;
1.536     raeburn  7264:         $quotatype = 'default';
                   7265:         $defquota = 0; 
1.472     raeburn  7266:     } else {
1.536     raeburn  7267:         my $inststatus;
1.472     raeburn  7268:         if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
                   7269:             $quota = $env{'environment.portfolioquota'};
1.536     raeburn  7270:             $inststatus = $env{'environment.inststatus'};
1.472     raeburn  7271:         } else {
1.536     raeburn  7272:             my %userenv = 
                   7273:                 &Apache::lonnet::get('environment',['portfolioquota',
                   7274:                                      'inststatus'],$udom,$uname);
1.472     raeburn  7275:             my ($tmp) = keys(%userenv);
                   7276:             if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   7277:                 $quota = $userenv{'portfolioquota'};
1.536     raeburn  7278:                 $inststatus = $userenv{'inststatus'};
1.472     raeburn  7279:             } else {
                   7280:                 undef(%userenv);
                   7281:             }
                   7282:         }
1.536     raeburn  7283:         ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472     raeburn  7284:         if ($quota eq '') {
1.536     raeburn  7285:             $quota = $defquota;
                   7286:             $quotatype = 'default';
                   7287:         } else {
                   7288:             $quotatype = 'custom';
1.472     raeburn  7289:         }
                   7290:     }
1.536     raeburn  7291:     if (wantarray) {
                   7292:         return ($quota,$quotatype,$settingstatus,$defquota);
                   7293:     } else {
                   7294:         return $quota;
                   7295:     }
1.472     raeburn  7296: }
                   7297: 
                   7298: ###############################################
                   7299: 
                   7300: =pod
                   7301: 
                   7302: =item * &default_quota()
                   7303: 
1.536     raeburn  7304: Retrieves default quota assigned for storage of user portfolio files,
                   7305: given an (optional) user's institutional status.
1.472     raeburn  7306: 
                   7307: Incoming parameters:
                   7308: 1. domain
1.536     raeburn  7309: 2. (Optional) institutional status(es).  This is a : separated list of 
                   7310:    status types (e.g., faculty, staff, student etc.)
                   7311:    which apply to the user for whom the default is being retrieved.
                   7312:    If the institutional status string in undefined, the domain
                   7313:    default quota will be returned. 
1.472     raeburn  7314: 
                   7315: Returns:
                   7316: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536     raeburn  7317: 2. (Optional) institutional type which determined the value of the
                   7318:    default quota.
1.472     raeburn  7319: 
                   7320: If a value has been stored in the domain's configuration db,
                   7321: it will return that, otherwise it returns 20 (for backwards 
                   7322: compatibility with domains which have not set up a configuration
                   7323: db file; the original statically defined portfolio quota was 20 Mb). 
                   7324: 
1.536     raeburn  7325: If the user's status includes multiple types (e.g., staff and student),
                   7326: the largest default quota which applies to the user determines the
                   7327: default quota returned.
                   7328: 
1.780     raeburn  7329: =back
                   7330: 
1.472     raeburn  7331: =cut
                   7332: 
                   7333: ###############################################
                   7334: 
                   7335: 
                   7336: sub default_quota {
1.536     raeburn  7337:     my ($udom,$inststatus) = @_;
                   7338:     my ($defquota,$settingstatus);
                   7339:     my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622     raeburn  7340:                                             ['quotas'],$udom);
                   7341:     if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536     raeburn  7342:         if ($inststatus ne '') {
1.765     raeburn  7343:             my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536     raeburn  7344:             foreach my $item (@statuses) {
1.711     raeburn  7345:                 if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7346:                     if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
                   7347:                         if ($defquota eq '') {
                   7348:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7349:                             $settingstatus = $item;
                   7350:                         } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
                   7351:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7352:                             $settingstatus = $item;
                   7353:                         }
                   7354:                     }
                   7355:                 } else {
                   7356:                     if ($quotahash{'quotas'}{$item} ne '') {
                   7357:                         if ($defquota eq '') {
                   7358:                             $defquota = $quotahash{'quotas'}{$item};
                   7359:                             $settingstatus = $item;
                   7360:                         } elsif ($quotahash{'quotas'}{$item} > $defquota) {
                   7361:                             $defquota = $quotahash{'quotas'}{$item};
                   7362:                             $settingstatus = $item;
                   7363:                         }
1.536     raeburn  7364:                     }
                   7365:                 }
                   7366:             }
                   7367:         }
                   7368:         if ($defquota eq '') {
1.711     raeburn  7369:             if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7370:                 $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
                   7371:             } else {
                   7372:                 $defquota = $quotahash{'quotas'}{'default'};
                   7373:             }
1.536     raeburn  7374:             $settingstatus = 'default';
                   7375:         }
                   7376:     } else {
                   7377:         $settingstatus = 'default';
                   7378:         $defquota = 20;
                   7379:     }
                   7380:     if (wantarray) {
                   7381:         return ($defquota,$settingstatus);
1.472     raeburn  7382:     } else {
1.536     raeburn  7383:         return $defquota;
1.472     raeburn  7384:     }
                   7385: }
                   7386: 
1.384     raeburn  7387: sub get_secgrprole_info {
                   7388:     my ($cdom,$cnum,$needroles,$type)  = @_;
                   7389:     my %sections_count = &get_sections($cdom,$cnum);
                   7390:     my @sections =  (sort {$a <=> $b} keys(%sections_count));
                   7391:     my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
                   7392:     my @groups = sort(keys(%curr_groups));
                   7393:     my $allroles = [];
                   7394:     my $rolehash;
                   7395:     my $accesshash = {
                   7396:                      active => 'Currently has access',
                   7397:                      future => 'Will have future access',
                   7398:                      previous => 'Previously had access',
                   7399:                   };
                   7400:     if ($needroles) {
                   7401:         $rolehash = {'all' => 'all'};
1.385     albertel 7402:         my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7403: 	if (&Apache::lonnet::error(%user_roles)) {
                   7404: 	    undef(%user_roles);
                   7405: 	}
                   7406:         foreach my $item (keys(%user_roles)) {
1.384     raeburn  7407:             my ($role)=split(/\:/,$item,2);
                   7408:             if ($role eq 'cr') { next; }
                   7409:             if ($role =~ /^cr/) {
                   7410:                 $$rolehash{$role} = (split('/',$role))[3];
                   7411:             } else {
                   7412:                 $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
                   7413:             }
                   7414:         }
                   7415:         foreach my $key (sort(keys(%{$rolehash}))) {
                   7416:             push(@{$allroles},$key);
                   7417:         }
                   7418:         push (@{$allroles},'st');
                   7419:         $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
                   7420:     }
                   7421:     return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
                   7422: }
                   7423: 
1.555     raeburn  7424: sub user_picker {
1.627     raeburn  7425:     my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555     raeburn  7426:     my $currdom = $dom;
                   7427:     my %curr_selected = (
                   7428:                         srchin => 'dom',
1.580     raeburn  7429:                         srchby => 'lastname',
1.555     raeburn  7430:                       );
                   7431:     my $srchterm;
1.625     raeburn  7432:     if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555     raeburn  7433:         if ($srch->{'srchby'} ne '') {
                   7434:             $curr_selected{'srchby'} = $srch->{'srchby'};
                   7435:         }
                   7436:         if ($srch->{'srchin'} ne '') {
                   7437:             $curr_selected{'srchin'} = $srch->{'srchin'};
                   7438:         }
                   7439:         if ($srch->{'srchtype'} ne '') {
                   7440:             $curr_selected{'srchtype'} = $srch->{'srchtype'};
                   7441:         }
                   7442:         if ($srch->{'srchdomain'} ne '') {
                   7443:             $currdom = $srch->{'srchdomain'};
                   7444:         }
                   7445:         $srchterm = $srch->{'srchterm'};
                   7446:     }
                   7447:     my %lt=&Apache::lonlocal::texthash(
1.573     raeburn  7448:                     'usr'       => 'Search criteria',
1.563     raeburn  7449:                     'doma'      => 'Domain/institution to search',
1.558     albertel 7450:                     'uname'     => 'username',
                   7451:                     'lastname'  => 'last name',
1.555     raeburn  7452:                     'lastfirst' => 'last name, first name',
1.558     albertel 7453:                     'crs'       => 'in this course',
1.576     raeburn  7454:                     'dom'       => 'in selected LON-CAPA domain', 
1.558     albertel 7455:                     'alc'       => 'all LON-CAPA',
1.573     raeburn  7456:                     'instd'     => 'in institutional directory for selected domain',
1.558     albertel 7457:                     'exact'     => 'is',
                   7458:                     'contains'  => 'contains',
1.569     raeburn  7459:                     'begins'    => 'begins with',
1.571     raeburn  7460:                     'youm'      => "You must include some text to search for.",
                   7461:                     'thte'      => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
                   7462:                     'thet'      => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
                   7463:                     'yomc'      => "You must choose a domain when using an institutional directory search.",
                   7464:                     'ymcd'      => "You must choose a domain when using a domain search.",
                   7465:                     'whus'      => "When using searching by last,first you must include a comma as separator between last name and first name.",
                   7466:                     'whse'      => "When searching by last,first you must include at least one character in the first name.",
                   7467:                      'thfo'     => "The following need to be corrected before the search can be run:",
1.555     raeburn  7468:                                        );
1.563     raeburn  7469:     my $domform = &select_dom_form($currdom,'srchdomain',1,1);
                   7470:     my $srchinsel = ' <select name="srchin">';
1.555     raeburn  7471: 
                   7472:     my @srchins = ('crs','dom','alc','instd');
                   7473: 
                   7474:     foreach my $option (@srchins) {
                   7475:         # FIXME 'alc' option unavailable until 
                   7476:         #       loncreateuser::print_user_query_page()
                   7477:         #       has been completed.
                   7478:         next if ($option eq 'alc');
                   7479:         next if ($option eq 'crs' && !$env{'request.course.id'});
1.563     raeburn  7480:         if ($curr_selected{'srchin'} eq $option) {
                   7481:             $srchinsel .= ' 
                   7482:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7483:         } else {
                   7484:             $srchinsel .= '
                   7485:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7486:         }
1.555     raeburn  7487:     }
1.563     raeburn  7488:     $srchinsel .= "\n  </select>\n";
1.555     raeburn  7489: 
                   7490:     my $srchbysel =  ' <select name="srchby">';
1.580     raeburn  7491:     foreach my $option ('lastname','lastfirst','uname') {
1.555     raeburn  7492:         if ($curr_selected{'srchby'} eq $option) {
                   7493:             $srchbysel .= '
                   7494:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7495:         } else {
                   7496:             $srchbysel .= '
                   7497:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7498:          }
                   7499:     }
                   7500:     $srchbysel .= "\n  </select>\n";
                   7501: 
                   7502:     my $srchtypesel = ' <select name="srchtype">';
1.580     raeburn  7503:     foreach my $option ('begins','contains','exact') {
1.555     raeburn  7504:         if ($curr_selected{'srchtype'} eq $option) {
                   7505:             $srchtypesel .= '
                   7506:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7507:         } else {
                   7508:             $srchtypesel .= '
                   7509:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7510:         }
                   7511:     }
                   7512:     $srchtypesel .= "\n  </select>\n";
                   7513: 
1.558     albertel 7514:     my ($newuserscript,$new_user_create);
1.556     raeburn  7515: 
                   7516:     if ($forcenewuser) {
1.576     raeburn  7517:         if (ref($srch) eq 'HASH') {
                   7518:             if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627     raeburn  7519:                 if ($cancreate) {
                   7520:                     $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>';
                   7521:                 } else {
1.799     bisitz   7522:                     my $helplink = 'javascript:helpMenu('."'display'".')';
1.627     raeburn  7523:                     my %usertypetext = (
                   7524:                         official   => 'institutional',
                   7525:                         unofficial => 'non-institutional',
                   7526:                     );
1.799     bisitz   7527:                     $new_user_create = '<p class="LC_warning">'
                   7528:                                       .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
                   7529:                                       .' '
                   7530:                                       .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
                   7531:                                           ,'<a href="'.$helplink.'">','</a>')
                   7532:                                       .'</p><br />';
1.627     raeburn  7533:                 }
1.576     raeburn  7534:             }
                   7535:         }
                   7536: 
1.556     raeburn  7537:         $newuserscript = <<"ENDSCRIPT";
                   7538: 
1.570     raeburn  7539: function setSearch(createnew,callingForm) {
1.556     raeburn  7540:     if (createnew == 1) {
1.570     raeburn  7541:         for (var i=0; i<callingForm.srchby.length; i++) {
                   7542:             if (callingForm.srchby.options[i].value == 'uname') {
                   7543:                 callingForm.srchby.selectedIndex = i;
1.556     raeburn  7544:             }
                   7545:         }
1.570     raeburn  7546:         for (var i=0; i<callingForm.srchin.length; i++) {
                   7547:             if ( callingForm.srchin.options[i].value == 'dom') {
                   7548: 		callingForm.srchin.selectedIndex = i;
1.556     raeburn  7549:             }
                   7550:         }
1.570     raeburn  7551:         for (var i=0; i<callingForm.srchtype.length; i++) {
                   7552:             if (callingForm.srchtype.options[i].value == 'exact') {
                   7553:                 callingForm.srchtype.selectedIndex = i;
1.556     raeburn  7554:             }
                   7555:         }
1.570     raeburn  7556:         for (var i=0; i<callingForm.srchdomain.length; i++) {
                   7557:             if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
                   7558:                 callingForm.srchdomain.selectedIndex = i;
1.556     raeburn  7559:             }
                   7560:         }
                   7561:     }
                   7562: }
                   7563: ENDSCRIPT
1.558     albertel 7564: 
1.556     raeburn  7565:     }
                   7566: 
1.555     raeburn  7567:     my $output = <<"END_BLOCK";
1.556     raeburn  7568: <script type="text/javascript">
1.570     raeburn  7569: function validateEntry(callingForm) {
1.558     albertel 7570: 
1.556     raeburn  7571:     var checkok = 1;
1.558     albertel 7572:     var srchin;
1.570     raeburn  7573:     for (var i=0; i<callingForm.srchin.length; i++) {
                   7574: 	if ( callingForm.srchin[i].checked ) {
                   7575: 	    srchin = callingForm.srchin[i].value;
1.558     albertel 7576: 	}
                   7577:     }
                   7578: 
1.570     raeburn  7579:     var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
                   7580:     var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
                   7581:     var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
                   7582:     var srchterm =  callingForm.srchterm.value;
                   7583:     var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556     raeburn  7584:     var msg = "";
                   7585: 
                   7586:     if (srchterm == "") {
                   7587:         checkok = 0;
1.571     raeburn  7588:         msg += "$lt{'youm'}\\n";
1.556     raeburn  7589:     }
                   7590: 
1.569     raeburn  7591:     if (srchtype== 'begins') {
                   7592:         if (srchterm.length < 2) {
                   7593:             checkok = 0;
1.571     raeburn  7594:             msg += "$lt{'thte'}\\n";
1.569     raeburn  7595:         }
                   7596:     }
                   7597: 
1.556     raeburn  7598:     if (srchtype== 'contains') {
                   7599:         if (srchterm.length < 3) {
                   7600:             checkok = 0;
1.571     raeburn  7601:             msg += "$lt{'thet'}\\n";
1.556     raeburn  7602:         }
                   7603:     }
                   7604:     if (srchin == 'instd') {
                   7605:         if (srchdomain == '') {
                   7606:             checkok = 0;
1.571     raeburn  7607:             msg += "$lt{'yomc'}\\n";
1.556     raeburn  7608:         }
                   7609:     }
                   7610:     if (srchin == 'dom') {
                   7611:         if (srchdomain == '') {
                   7612:             checkok = 0;
1.571     raeburn  7613:             msg += "$lt{'ymcd'}\\n";
1.556     raeburn  7614:         }
                   7615:     }
                   7616:     if (srchby == 'lastfirst') {
                   7617:         if (srchterm.indexOf(",") == -1) {
                   7618:             checkok = 0;
1.571     raeburn  7619:             msg += "$lt{'whus'}\\n";
1.556     raeburn  7620:         }
                   7621:         if (srchterm.indexOf(",") == srchterm.length -1) {
                   7622:             checkok = 0;
1.571     raeburn  7623:             msg += "$lt{'whse'}\\n";
1.556     raeburn  7624:         }
                   7625:     }
                   7626:     if (checkok == 0) {
1.571     raeburn  7627:         alert("$lt{'thfo'}\\n"+msg);
1.556     raeburn  7628:         return;
                   7629:     }
                   7630:     if (checkok == 1) {
1.570     raeburn  7631:         callingForm.submit();
1.556     raeburn  7632:     }
                   7633: }
                   7634: 
                   7635: $newuserscript
                   7636: 
                   7637: </script>
1.558     albertel 7638: 
                   7639: $new_user_create
                   7640: 
1.555     raeburn  7641: <table>
1.558     albertel 7642:  <tr>
1.573     raeburn  7643:   <td>$lt{'doma'}:</td>
                   7644:   <td>$domform</td>
                   7645:   </td>
                   7646:  </tr>
                   7647:  <tr>
                   7648:   <td>$lt{'usr'}:</td>
1.563     raeburn  7649:   <td>$srchbysel
                   7650:       $srchtypesel 
                   7651:       <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564     albertel 7652:       $srchinsel 
1.563     raeburn  7653:   </td>
                   7654:  </tr>
1.555     raeburn  7655: </table>
                   7656: <br />
                   7657: END_BLOCK
1.558     albertel 7658: 
1.555     raeburn  7659:     return $output;
                   7660: }
                   7661: 
1.612     raeburn  7662: sub user_rule_check {
1.615     raeburn  7663:     my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612     raeburn  7664:     my $response;
                   7665:     if (ref($usershash) eq 'HASH') {
                   7666:         foreach my $user (keys(%{$usershash})) {
                   7667:             my ($uname,$udom) = split(/:/,$user);
                   7668:             next if ($udom eq '' || $uname eq '');
1.615     raeburn  7669:             my ($id,$newuser);
1.612     raeburn  7670:             if (ref($usershash->{$user}) eq 'HASH') {
1.615     raeburn  7671:                 $newuser = $usershash->{$user}->{'newuser'};
1.612     raeburn  7672:                 $id = $usershash->{$user}->{'id'};
                   7673:             }
                   7674:             my $inst_response;
                   7675:             if (ref($checks) eq 'HASH') {
                   7676:                 if (defined($checks->{'username'})) {
1.615     raeburn  7677:                     ($inst_response,%{$inst_results->{$user}}) = 
1.612     raeburn  7678:                         &Apache::lonnet::get_instuser($udom,$uname);
                   7679:                 } elsif (defined($checks->{'id'})) {
1.615     raeburn  7680:                     ($inst_response,%{$inst_results->{$user}}) =
1.612     raeburn  7681:                         &Apache::lonnet::get_instuser($udom,undef,$id);
                   7682:                 }
1.615     raeburn  7683:             } else {
                   7684:                 ($inst_response,%{$inst_results->{$user}}) =
                   7685:                     &Apache::lonnet::get_instuser($udom,$uname);
                   7686:                 return;
1.612     raeburn  7687:             }
1.615     raeburn  7688:             if (!$got_rules->{$udom}) {
1.612     raeburn  7689:                 my %domconfig = &Apache::lonnet::get_dom('configuration',
                   7690:                                                   ['usercreation'],$udom);
                   7691:                 if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615     raeburn  7692:                     foreach my $item ('username','id') {
1.612     raeburn  7693:                         if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
                   7694:                             $$curr_rules{$udom}{$item} = 
                   7695:                                 $domconfig{'usercreation'}{$item.'_rule'};
1.585     raeburn  7696:                         }
                   7697:                     }
                   7698:                 }
1.615     raeburn  7699:                 $got_rules->{$udom} = 1;  
1.585     raeburn  7700:             }
1.612     raeburn  7701:             foreach my $item (keys(%{$checks})) {
                   7702:                 if (ref($$curr_rules{$udom}) eq 'HASH') {
                   7703:                     if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
                   7704:                         if (@{$$curr_rules{$udom}{$item}} > 0) {
                   7705:                             my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
                   7706:                             foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
                   7707:                                 if ($rule_check{$rule}) {
                   7708:                                     $$rulematch{$user}{$item} = $rule;
                   7709:                                     if ($inst_response eq 'ok') {
1.615     raeburn  7710:                                         if (ref($inst_results) eq 'HASH') {
                   7711:                                             if (ref($inst_results->{$user}) eq 'HASH') {
                   7712:                                                 if (keys(%{$inst_results->{$user}}) == 0) {
                   7713:                                                     $$alerts{$item}{$udom}{$uname} = 1;
                   7714:                                                 }
1.612     raeburn  7715:                                             }
                   7716:                                         }
1.615     raeburn  7717:                                     }
                   7718:                                     last;
1.585     raeburn  7719:                                 }
                   7720:                             }
                   7721:                         }
                   7722:                     }
                   7723:                 }
                   7724:             }
                   7725:         }
                   7726:     }
1.612     raeburn  7727:     return;
                   7728: }
                   7729: 
                   7730: sub user_rule_formats {
                   7731:     my ($domain,$domdesc,$curr_rules,$check) = @_;
                   7732:     my %text = ( 
                   7733:                  'username' => 'Usernames',
                   7734:                  'id'       => 'IDs',
                   7735:                );
                   7736:     my $output;
                   7737:     my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
                   7738:     if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
                   7739:         if (@{$ruleorder} > 0) {
                   7740:             $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>';
                   7741:             foreach my $rule (@{$ruleorder}) {
                   7742:                 if (ref($curr_rules) eq 'ARRAY') {
                   7743:                     if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
                   7744:                         if (ref($rules->{$rule}) eq 'HASH') {
                   7745:                             $output .= '<li>'.$rules->{$rule}{'name'}.': '.
                   7746:                                         $rules->{$rule}{'desc'}.'</li>';
                   7747:                         }
                   7748:                     }
                   7749:                 }
                   7750:             }
                   7751:             $output .= '</ul>';
                   7752:         }
                   7753:     }
                   7754:     return $output;
                   7755: }
                   7756: 
                   7757: sub instrule_disallow_msg {
1.615     raeburn  7758:     my ($checkitem,$domdesc,$count,$mode) = @_;
1.612     raeburn  7759:     my $response;
                   7760:     my %text = (
                   7761:                   item   => 'username',
                   7762:                   items  => 'usernames',
                   7763:                   match  => 'matches',
                   7764:                   do     => 'does',
                   7765:                   action => 'a username',
                   7766:                   one    => 'one',
                   7767:                );
                   7768:     if ($count > 1) {
                   7769:         $text{'item'} = 'usernames';
                   7770:         $text{'match'} ='match';
                   7771:         $text{'do'} = 'do';
                   7772:         $text{'action'} = 'usernames',
                   7773:         $text{'one'} = 'ones';
                   7774:     }
                   7775:     if ($checkitem eq 'id') {
                   7776:         $text{'items'} = 'IDs';
                   7777:         $text{'item'} = 'ID';
                   7778:         $text{'action'} = 'an ID';
1.615     raeburn  7779:         if ($count > 1) {
                   7780:             $text{'item'} = 'IDs';
                   7781:             $text{'action'} = 'IDs';
                   7782:         }
1.612     raeburn  7783:     }
1.674     bisitz   7784:     $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  7785:     if ($mode eq 'upload') {
                   7786:         if ($checkitem eq 'username') {
                   7787:             $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'}.");
                   7788:         } elsif ($checkitem eq 'id') {
1.674     bisitz   7789:             $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  7790:         }
1.669     raeburn  7791:     } elsif ($mode eq 'selfcreate') {
                   7792:         if ($checkitem eq 'id') {
                   7793:             $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.");
                   7794:         }
1.615     raeburn  7795:     } else {
                   7796:         if ($checkitem eq 'username') {
                   7797:             $response .= &mt("You must choose $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
                   7798:         } elsif ($checkitem eq 'id') {
                   7799:             $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.");
                   7800:         }
1.612     raeburn  7801:     }
                   7802:     return $response;
1.585     raeburn  7803: }
                   7804: 
1.624     raeburn  7805: sub personal_data_fieldtitles {
                   7806:     my %fieldtitles = &Apache::lonlocal::texthash (
                   7807:                         id => 'Student/Employee ID',
                   7808:                         permanentemail => 'E-mail address',
                   7809:                         lastname => 'Last Name',
                   7810:                         firstname => 'First Name',
                   7811:                         middlename => 'Middle Name',
                   7812:                         generation => 'Generation',
                   7813:                         gen => 'Generation',
1.765     raeburn  7814:                         inststatus => 'Affiliation',
1.624     raeburn  7815:                    );
                   7816:     return %fieldtitles;
                   7817: }
                   7818: 
1.642     raeburn  7819: sub sorted_inst_types {
                   7820:     my ($dom) = @_;
                   7821:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
                   7822:     my $othertitle = &mt('All users');
                   7823:     if ($env{'request.course.id'}) {
1.668     raeburn  7824:         $othertitle  = &mt('Any users');
1.642     raeburn  7825:     }
                   7826:     my @types;
                   7827:     if (ref($order) eq 'ARRAY') {
                   7828:         @types = @{$order};
                   7829:     }
                   7830:     if (@types == 0) {
                   7831:         if (ref($usertypes) eq 'HASH') {
                   7832:             @types = sort(keys(%{$usertypes}));
                   7833:         }
                   7834:     }
                   7835:     if (keys(%{$usertypes}) > 0) {
                   7836:         $othertitle = &mt('Other users');
                   7837:     }
                   7838:     return ($othertitle,$usertypes,\@types);
                   7839: }
                   7840: 
1.645     raeburn  7841: sub get_institutional_codes {
                   7842:     my ($settings,$allcourses,$LC_code) = @_;
                   7843: # Get complete list of course sections to update
                   7844:     my @currsections = ();
                   7845:     my @currxlists = ();
                   7846:     my $coursecode = $$settings{'internal.coursecode'};
                   7847: 
                   7848:     if ($$settings{'internal.sectionnums'} ne '') {
                   7849:         @currsections = split(/,/,$$settings{'internal.sectionnums'});
                   7850:     }
                   7851: 
                   7852:     if ($$settings{'internal.crosslistings'} ne '') {
                   7853:         @currxlists = split(/,/,$$settings{'internal.crosslistings'});
                   7854:     }
                   7855: 
                   7856:     if (@currxlists > 0) {
                   7857:         foreach (@currxlists) {
                   7858:             if (m/^([^:]+):(\w*)$/) {
                   7859:                 unless (grep/^$1$/,@{$allcourses}) {
                   7860:                     push @{$allcourses},$1;
                   7861:                     $$LC_code{$1} = $2;
                   7862:                 }
                   7863:             }
                   7864:         }
                   7865:     }
                   7866:  
                   7867:     if (@currsections > 0) {
                   7868:         foreach (@currsections) {
                   7869:             if (m/^(\w+):(\w*)$/) {
                   7870:                 my $sec = $coursecode.$1;
                   7871:                 my $lc_sec = $2;
                   7872:                 unless (grep/^$sec$/,@{$allcourses}) {
                   7873:                     push @{$allcourses},$sec;
                   7874:                     $$LC_code{$sec} = $lc_sec;
                   7875:                 }
                   7876:             }
                   7877:         }
                   7878:     }
                   7879:     return;
                   7880: }
                   7881: 
1.112     bowersj2 7882: =pod
                   7883: 
1.780     raeburn  7884: =head1 Slot Helpers
                   7885: 
                   7886: =over 4
                   7887: 
                   7888: =item * sorted_slots()
                   7889: 
                   7890: Sorts an array of slot names in order of slot start time (earliest first). 
                   7891: 
                   7892: Inputs:
                   7893: 
                   7894: =over 4
                   7895: 
                   7896: slotsarr  - Reference to array of unsorted slot names.
                   7897: 
                   7898: slots     - Reference to hash of hash, where outer hash keys are slot names.
                   7899: 
1.549     albertel 7900: =back
                   7901: 
1.780     raeburn  7902: Returns:
                   7903: 
                   7904: =over 4
                   7905: 
                   7906: sorted   - An array of slot names sorted by the start time of the slot.
                   7907: 
                   7908: =back
                   7909: 
                   7910: =back
                   7911: 
                   7912: =cut
                   7913: 
                   7914: 
                   7915: sub sorted_slots {
                   7916:     my ($slotsarr,$slots) = @_;
                   7917:     my @sorted;
                   7918:     if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
                   7919:         @sorted =
                   7920:             sort {
                   7921:                      if (ref($slots->{$a}) && ref($slots->{$b})) {
                   7922:                          return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
                   7923:                      }
                   7924:                      if (ref($slots->{$a})) { return -1;}
                   7925:                      if (ref($slots->{$b})) { return 1;}
                   7926:                      return 0;
                   7927:                  } @{$slotsarr};
                   7928:     }
                   7929:     return @sorted;
                   7930: }
                   7931: 
                   7932: 
                   7933: =pod
                   7934: 
1.549     albertel 7935: =head1 HTTP Helpers
                   7936: 
                   7937: =over 4
                   7938: 
1.648     raeburn  7939: =item * &get_unprocessed_cgi($query,$possible_names)
1.112     bowersj2 7940: 
1.258     albertel 7941: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112     bowersj2 7942: $query.  The parameters listed in $possible_names (an array reference),
1.258     albertel 7943: will be set in $env{'form.name'} if they do not already exist.
1.112     bowersj2 7944: 
                   7945: Typically called with $ENV{'QUERY_STRING'} as the first parameter.  
                   7946: $possible_names is an ref to an array of form element names.  As an example:
                   7947: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258     albertel 7948: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112     bowersj2 7949: 
                   7950: =cut
1.1       albertel 7951: 
1.6       albertel 7952: sub get_unprocessed_cgi {
1.25      albertel 7953:   my ($query,$possible_names)= @_;
1.26      matthew  7954:   # $Apache::lonxml::debug=1;
1.356     albertel 7955:   foreach my $pair (split(/&/,$query)) {
                   7956:     my ($name, $value) = split(/=/,$pair);
1.369     www      7957:     $name = &unescape($name);
1.25      albertel 7958:     if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
                   7959:       $value =~ tr/+/ /;
                   7960:       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258     albertel 7961:       unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25      albertel 7962:     }
1.16      harris41 7963:   }
1.6       albertel 7964: }
                   7965: 
1.112     bowersj2 7966: =pod
                   7967: 
1.648     raeburn  7968: =item * &cacheheader() 
1.112     bowersj2 7969: 
                   7970: returns cache-controlling header code
                   7971: 
                   7972: =cut
                   7973: 
1.7       albertel 7974: sub cacheheader {
1.258     albertel 7975:     unless ($env{'request.method'} eq 'GET') { return ''; }
1.216     albertel 7976:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
                   7977:     my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7       albertel 7978:                 <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
                   7979:                 <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216     albertel 7980:     return $output;
1.7       albertel 7981: }
                   7982: 
1.112     bowersj2 7983: =pod
                   7984: 
1.648     raeburn  7985: =item * &no_cache($r) 
1.112     bowersj2 7986: 
                   7987: specifies header code to not have cache
                   7988: 
                   7989: =cut
                   7990: 
1.9       albertel 7991: sub no_cache {
1.216     albertel 7992:     my ($r) = @_;
                   7993:     if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258     albertel 7994: 	$env{'request.method'} ne 'GET') { return ''; }
1.216     albertel 7995:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
                   7996:     $r->no_cache(1);
                   7997:     $r->header_out("Expires" => $date);
                   7998:     $r->header_out("Pragma" => "no-cache");
1.123     www      7999: }
                   8000: 
                   8001: sub content_type {
1.181     albertel 8002:     my ($r,$type,$charset) = @_;
1.299     foxr     8003:     if ($r) {
                   8004: 	#  Note that printout.pl calls this with undef for $r.
                   8005: 	&no_cache($r);
                   8006:     }
1.258     albertel 8007:     if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181     albertel 8008:     unless ($charset) {
                   8009: 	$charset=&Apache::lonlocal::current_encoding;
                   8010:     }
                   8011:     if ($charset) { $type.='; charset='.$charset; }
                   8012:     if ($r) {
                   8013: 	$r->content_type($type);
                   8014:     } else {
                   8015: 	print("Content-type: $type\n\n");
                   8016:     }
1.9       albertel 8017: }
1.25      albertel 8018: 
1.112     bowersj2 8019: =pod
                   8020: 
1.648     raeburn  8021: =item * &add_to_env($name,$value) 
1.112     bowersj2 8022: 
1.258     albertel 8023: adds $name to the %env hash with value
1.112     bowersj2 8024: $value, if $name already exists, the entry is converted to an array
                   8025: reference and $value is added to the array.
                   8026: 
                   8027: =cut
                   8028: 
1.25      albertel 8029: sub add_to_env {
                   8030:   my ($name,$value)=@_;
1.258     albertel 8031:   if (defined($env{$name})) {
                   8032:     if (ref($env{$name})) {
1.25      albertel 8033:       #already have multiple values
1.258     albertel 8034:       push(@{ $env{$name} },$value);
1.25      albertel 8035:     } else {
                   8036:       #first time seeing multiple values, convert hash entry to an arrayref
1.258     albertel 8037:       my $first=$env{$name};
                   8038:       undef($env{$name});
                   8039:       push(@{ $env{$name} },$first,$value);
1.25      albertel 8040:     }
                   8041:   } else {
1.258     albertel 8042:     $env{$name}=$value;
1.25      albertel 8043:   }
1.31      albertel 8044: }
1.149     albertel 8045: 
                   8046: =pod
                   8047: 
1.648     raeburn  8048: =item * &get_env_multiple($name) 
1.149     albertel 8049: 
1.258     albertel 8050: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149     albertel 8051: values may be defined and end up as an array ref.
                   8052: 
                   8053: returns an array of values
                   8054: 
                   8055: =cut
                   8056: 
                   8057: sub get_env_multiple {
                   8058:     my ($name) = @_;
                   8059:     my @values;
1.258     albertel 8060:     if (defined($env{$name})) {
1.149     albertel 8061:         # exists is it an array
1.258     albertel 8062:         if (ref($env{$name})) {
                   8063:             @values=@{ $env{$name} };
1.149     albertel 8064:         } else {
1.258     albertel 8065:             $values[0]=$env{$name};
1.149     albertel 8066:         }
                   8067:     }
                   8068:     return(@values);
                   8069: }
                   8070: 
1.660     raeburn  8071: sub ask_for_embedded_content {
                   8072:     my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
                   8073:     my $upload_output = '
                   8074:    <form name="upload_embedded" action="'.$actionurl.'"
                   8075:                   method="post" enctype="multipart/form-data">';
                   8076:     $upload_output .= $state;
1.661     raeburn  8077:     $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660     raeburn  8078: 
                   8079:     my $num = 0;
                   8080:     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
                   8081:         $upload_output .= &start_data_table_row().
                   8082:             '<td>'.$embed_file.'</td><td>';
                   8083:         if ($args->{'ignore_remote_references'}
                   8084:             && $embed_file =~ m{^\w+://}) {
                   8085:             $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
                   8086:         } elsif ($args->{'error_on_invalid_names'}
                   8087:             && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
                   8088: 
                   8089:             $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
                   8090: 
                   8091:         } else {
                   8092:             $upload_output .='
1.661     raeburn  8093:            <input name="embedded_item_'.$num.'" type="file" value="" />
1.660     raeburn  8094:            <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
                   8095:             my $attrib = join(':',@{$$allfiles{$embed_file}});
                   8096:             $upload_output .=
                   8097:                 "\n\t\t".
                   8098:                 '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
                   8099:                 $attrib.'" />';
                   8100:             if (exists($$codebase{$embed_file})) {
                   8101:                 $upload_output .=
                   8102:                     "\n\t\t".
                   8103:                     '<input name="codebase_'.$num.'" type="hidden" value="'.
                   8104:                     &escape($$codebase{$embed_file}).'" />';
                   8105:             }
                   8106:         }
                   8107:         $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
                   8108:         $num++;
                   8109:     }
                   8110:     $upload_output .= &Apache::loncommon::end_data_table().'<br />
                   8111:    <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
                   8112:    <input type ="submit" value="'.&mt('Upload Listed Files').'" />
                   8113:    '.&mt('(only files for which a location has been provided will be uploaded)').'
                   8114:    </form>';
                   8115:     return $upload_output;
                   8116: }
                   8117: 
1.661     raeburn  8118: sub upload_embedded {
                   8119:     my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
                   8120:         $current_disk_usage) = @_;
                   8121:     my $output;
                   8122:     for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
                   8123:         next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
                   8124:         my $orig_uploaded_filename =
                   8125:             $env{'form.embedded_item_'.$i.'.filename'};
                   8126: 
                   8127:         $env{'form.embedded_orig_'.$i} =
                   8128:             &unescape($env{'form.embedded_orig_'.$i});
                   8129:         my ($path,$fname) =
                   8130:             ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
                   8131:         # no path, whole string is fname
                   8132:         if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
                   8133: 
                   8134:         $path = $env{'form.currentpath'}.$path;
                   8135:         $fname = &Apache::lonnet::clean_filename($fname);
                   8136:         # See if there is anything left
                   8137:         next if ($fname eq '');
                   8138: 
                   8139:         # Check if file already exists as a file or directory.
                   8140:         my ($state,$msg);
                   8141:         if ($context eq 'portfolio') {
                   8142:             my $port_path = $dirpath;
                   8143:             if ($group ne '') {
                   8144:                 $port_path = "groups/$group/$port_path";
                   8145:             }
                   8146:             ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
                   8147:                                               $dir_root,$port_path,$disk_quota,
                   8148:                                               $current_disk_usage,$uname,$udom);
                   8149:             if ($state eq 'will_exceed_quota'
                   8150:                 || $state eq 'file_locked'
                   8151:                 || $state eq 'file_exists' ) {
                   8152:                 $output .= $msg;
                   8153:                 next;
                   8154:             }
                   8155:         } elsif (($context eq 'author') || ($context eq 'testbank')) {
                   8156:             ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
                   8157:             if ($state eq 'exists') {
                   8158:                 $output .= $msg;
                   8159:                 next;
                   8160:             }
                   8161:         }
                   8162:         # Check if extension is valid
                   8163:         if (($fname =~ /\.(\w+)$/) &&
                   8164:             (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   8165:             $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
                   8166:             next;
                   8167:         } elsif (($fname =~ /\.(\w+)$/) &&
                   8168:                  (!defined(&Apache::loncommon::fileembstyle($1)))) {
                   8169:             $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   8170:             next;
                   8171:         } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
                   8172:             $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
                   8173:             next;
                   8174:         }
                   8175: 
                   8176:         $env{'form.embedded_item_'.$i.'.filename'}=$fname;
                   8177:         if ($context eq 'portfolio') {
                   8178:             my $result=
                   8179:                 &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
                   8180:                                                 $dirpath.$path);
                   8181:             if ($result !~ m|^/uploaded/|) {
                   8182:                 $output .= '<span class="LC_error">'
                   8183:                       .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
                   8184:                            ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
                   8185:                       .'</span><br />';
                   8186:                 next;
                   8187:             } else {
                   8188:                 $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
                   8189:                            $path.$fname.'</span>').'</p>';     
                   8190:             }
                   8191:         } else {
                   8192: # Save the file
                   8193:             my $target = $env{'form.embedded_item_'.$i};
                   8194:             my $fullpath = $dir_root.$dirpath.'/'.$path;
                   8195:             my $dest = $fullpath.$fname;
                   8196:             my $url = $url_root.$dirpath.'/'.$path.$fname;
                   8197:             my @parts=split(/\//,$fullpath);
                   8198:             my $count;
                   8199:             my $filepath = $dir_root;
                   8200:             for ($count=4;$count<=$#parts;$count++) {
                   8201:                 $filepath .= "/$parts[$count]";
                   8202:                 if ((-e $filepath)!=1) {
                   8203:                     mkdir($filepath,0770);
                   8204:                 }
                   8205:             }
                   8206:             my $fh;
                   8207:             if (!open($fh,'>'.$dest)) {
                   8208:                 &Apache::lonnet::logthis('Failed to create '.$dest);
                   8209:                 $output .= '<span class="LC_error">'.
                   8210:                            &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   8211:                            '</span><br />';
                   8212:             } else {
                   8213:                 if (!print $fh $env{'form.embedded_item_'.$i}) {
                   8214:                     &Apache::lonnet::logthis('Failed to write to '.$dest);
                   8215:                     $output .= '<span class="LC_error">'.
                   8216:                               &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   8217:                               '</span><br />';
                   8218:                 } else {
                   8219:                     if ($context eq 'testbank') {
                   8220:                         $output .= &mt('Embedded file uploaded successfully:').
                   8221:                                    '&nbsp;<a href="'.$url.'">'.
                   8222:                                    $orig_uploaded_filename.'</a><br />';
                   8223:                     } else {
1.705     tempelho 8224:                         $output .= '<span class=\"LC_fontsize_large\">'.
1.661     raeburn  8225:                                    &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705     tempelho 8226:                                    $orig_uploaded_filename.'</a>').'</span><br />';
1.661     raeburn  8227:                     }
                   8228:                 }
                   8229:                 close($fh);
                   8230:             }
                   8231:         }
                   8232:     }
                   8233:     return $output;
                   8234: }
                   8235: 
                   8236: sub check_for_existing {
                   8237:     my ($path,$fname,$element) = @_;
                   8238:     my ($state,$msg);
                   8239:     if (-d $path.'/'.$fname) {
                   8240:         $state = 'exists';
                   8241:         $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   8242:     } elsif (-e $path.'/'.$fname) {
                   8243:         $state = 'exists';
                   8244:         $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   8245:     }
                   8246:     if ($state eq 'exists') {
                   8247:         $msg = '<span class="LC_error">'.$msg.'</span><br />';
                   8248:     }
                   8249:     return ($state,$msg);
                   8250: }
                   8251: 
                   8252: sub check_for_upload {
                   8253:     my ($path,$fname,$group,$element,$portfolio_root,$port_path,
                   8254:         $disk_quota,$current_disk_usage,$uname,$udom) = @_;
                   8255:     my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
                   8256:     my $getpropath = 1;
                   8257:     my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
                   8258:                                             $getpropath);
                   8259:     my $found_file = 0;
                   8260:     my $locked_file = 0;
                   8261:     foreach my $line (@dir_list) {
                   8262:         my ($file_name)=split(/\&/,$line,2);
                   8263:         if ($file_name eq $fname){
                   8264:             $file_name = $path.$file_name;
                   8265:             if ($group ne '') {
                   8266:                 $file_name = $group.$file_name;
                   8267:             }
                   8268:             $found_file = 1;
                   8269:             if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
                   8270:                 $locked_file = 1;
                   8271:             }
                   8272:         }
                   8273:     }
                   8274:     if (($current_disk_usage + $filesize) > $disk_quota){
                   8275:         my $msg = '<span class="LC_error">'.
                   8276:                 &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
                   8277:                   '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
                   8278:         return ('will_exceed_quota',$msg);
                   8279:     } elsif ($found_file) {
                   8280:         if ($locked_file) {
                   8281:             my $msg = '<span class="LC_error">';
                   8282:             $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>');
                   8283:             $msg .= '</span><br />';
                   8284:             $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
                   8285:             return ('file_locked',$msg);
                   8286:         } else {
                   8287:             my $msg = '<span class="LC_error">';
                   8288:             $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'});
                   8289:             $msg .= '</span>';
                   8290:             $msg .= '<br />';
                   8291:             $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
                   8292:             return ('file_exists',$msg);
                   8293:         }
                   8294:     }
                   8295: }
                   8296: 
1.31      albertel 8297: 
1.41      ng       8298: =pod
1.45      matthew  8299: 
1.464     albertel 8300: =back
1.41      ng       8301: 
1.112     bowersj2 8302: =head1 CSV Upload/Handling functions
1.38      albertel 8303: 
1.41      ng       8304: =over 4
                   8305: 
1.648     raeburn  8306: =item * &upfile_store($r)
1.41      ng       8307: 
                   8308: Store uploaded file, $r should be the HTTP Request object,
1.258     albertel 8309: needs $env{'form.upfile'}
1.41      ng       8310: returns $datatoken to be put into hidden field
                   8311: 
                   8312: =cut
1.31      albertel 8313: 
                   8314: sub upfile_store {
                   8315:     my $r=shift;
1.258     albertel 8316:     $env{'form.upfile'}=~s/\r/\n/gs;
                   8317:     $env{'form.upfile'}=~s/\f/\n/gs;
                   8318:     $env{'form.upfile'}=~s/\n+/\n/gs;
                   8319:     $env{'form.upfile'}=~s/\n+$//gs;
1.31      albertel 8320: 
1.258     albertel 8321:     my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
                   8322: 	'_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31      albertel 8323:     {
1.158     raeburn  8324:         my $datafile = $r->dir_config('lonDaemons').
                   8325:                            '/tmp/'.$datatoken.'.tmp';
                   8326:         if ( open(my $fh,">$datafile") ) {
1.258     albertel 8327:             print $fh $env{'form.upfile'};
1.158     raeburn  8328:             close($fh);
                   8329:         }
1.31      albertel 8330:     }
                   8331:     return $datatoken;
                   8332: }
                   8333: 
1.56      matthew  8334: =pod
                   8335: 
1.648     raeburn  8336: =item * &load_tmp_file($r)
1.41      ng       8337: 
                   8338: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258     albertel 8339: needs $env{'form.datatoken'},
                   8340: sets $env{'form.upfile'} to the contents of the file
1.41      ng       8341: 
                   8342: =cut
1.31      albertel 8343: 
                   8344: sub load_tmp_file {
                   8345:     my $r=shift;
                   8346:     my @studentdata=();
                   8347:     {
1.158     raeburn  8348:         my $studentfile = $r->dir_config('lonDaemons').
1.258     albertel 8349:                               '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158     raeburn  8350:         if ( open(my $fh,"<$studentfile") ) {
                   8351:             @studentdata=<$fh>;
                   8352:             close($fh);
                   8353:         }
1.31      albertel 8354:     }
1.258     albertel 8355:     $env{'form.upfile'}=join('',@studentdata);
1.31      albertel 8356: }
                   8357: 
1.56      matthew  8358: =pod
                   8359: 
1.648     raeburn  8360: =item * &upfile_record_sep()
1.41      ng       8361: 
                   8362: Separate uploaded file into records
                   8363: returns array of records,
1.258     albertel 8364: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41      ng       8365: 
                   8366: =cut
1.31      albertel 8367: 
                   8368: sub upfile_record_sep {
1.258     albertel 8369:     if ($env{'form.upfiletype'} eq 'xml') {
1.31      albertel 8370:     } else {
1.248     albertel 8371: 	my @records;
1.258     albertel 8372: 	foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248     albertel 8373: 	    if ($line=~/^\s*$/) { next; }
                   8374: 	    push(@records,$line);
                   8375: 	}
                   8376: 	return @records;
1.31      albertel 8377:     }
                   8378: }
                   8379: 
1.56      matthew  8380: =pod
                   8381: 
1.648     raeburn  8382: =item * &record_sep($record)
1.41      ng       8383: 
1.258     albertel 8384: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41      ng       8385: 
                   8386: =cut
                   8387: 
1.263     www      8388: sub takeleft {
                   8389:     my $index=shift;
                   8390:     return substr('0000'.$index,-4,4);
                   8391: }
                   8392: 
1.31      albertel 8393: sub record_sep {
                   8394:     my $record=shift;
                   8395:     my %components=();
1.258     albertel 8396:     if ($env{'form.upfiletype'} eq 'xml') {
                   8397:     } elsif ($env{'form.upfiletype'} eq 'space') {
1.31      albertel 8398:         my $i=0;
1.356     albertel 8399:         foreach my $field (split(/\s+/,$record)) {
1.31      albertel 8400:             $field=~s/^(\"|\')//;
                   8401:             $field=~s/(\"|\')$//;
1.263     www      8402:             $components{&takeleft($i)}=$field;
1.31      albertel 8403:             $i++;
                   8404:         }
1.258     albertel 8405:     } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31      albertel 8406:         my $i=0;
1.356     albertel 8407:         foreach my $field (split(/\t/,$record)) {
1.31      albertel 8408:             $field=~s/^(\"|\')//;
                   8409:             $field=~s/(\"|\')$//;
1.263     www      8410:             $components{&takeleft($i)}=$field;
1.31      albertel 8411:             $i++;
                   8412:         }
                   8413:     } else {
1.561     www      8414:         my $separator=',';
1.480     banghart 8415:         if ($env{'form.upfiletype'} eq 'semisv') {
1.561     www      8416:             $separator=';';
1.480     banghart 8417:         }
1.31      albertel 8418:         my $i=0;
1.561     www      8419: # the character we are looking for to indicate the end of a quote or a record 
                   8420:         my $looking_for=$separator;
                   8421: # do not add the characters to the fields
                   8422:         my $ignore=0;
                   8423: # we just encountered a separator (or the beginning of the record)
                   8424:         my $just_found_separator=1;
                   8425: # store the field we are working on here
                   8426:         my $field='';
                   8427: # work our way through all characters in record
                   8428:         foreach my $character ($record=~/(.)/g) {
                   8429:             if ($character eq $looking_for) {
                   8430:                if ($character ne $separator) {
                   8431: # Found the end of a quote, again looking for separator
                   8432:                   $looking_for=$separator;
                   8433:                   $ignore=1;
                   8434:                } else {
                   8435: # Found a separator, store away what we got
                   8436:                   $components{&takeleft($i)}=$field;
                   8437: 	          $i++;
                   8438:                   $just_found_separator=1;
                   8439:                   $ignore=0;
                   8440:                   $field='';
                   8441:                }
                   8442:                next;
                   8443:             }
                   8444: # single or double quotation marks after a separator indicate beginning of a quote
                   8445: # we are now looking for the end of the quote and need to ignore separators
                   8446:             if ((($character eq '"') || ($character eq "'")) && ($just_found_separator))  {
                   8447:                $looking_for=$character;
                   8448:                next;
                   8449:             }
                   8450: # ignore would be true after we reached the end of a quote
                   8451:             if ($ignore) { next; }
                   8452:             if (($just_found_separator) && ($character=~/\s/)) { next; }
                   8453:             $field.=$character;
                   8454:             $just_found_separator=0; 
1.31      albertel 8455:         }
1.561     www      8456: # catch the very last entry, since we never encountered the separator
                   8457:         $components{&takeleft($i)}=$field;
1.31      albertel 8458:     }
                   8459:     return %components;
                   8460: }
                   8461: 
1.144     matthew  8462: ######################################################
                   8463: ######################################################
                   8464: 
1.56      matthew  8465: =pod
                   8466: 
1.648     raeburn  8467: =item * &upfile_select_html()
1.41      ng       8468: 
1.144     matthew  8469: Return HTML code to select a file from the users machine and specify 
                   8470: the file type.
1.41      ng       8471: 
                   8472: =cut
                   8473: 
1.144     matthew  8474: ######################################################
                   8475: ######################################################
1.31      albertel 8476: sub upfile_select_html {
1.144     matthew  8477:     my %Types = (
                   8478:                  csv   => &mt('CSV (comma separated values, spreadsheet)'),
1.480     banghart 8479:                  semisv => &mt('Semicolon separated values'),
1.144     matthew  8480:                  space => &mt('Space separated'),
                   8481:                  tab   => &mt('Tabulator separated'),
                   8482: #                 xml   => &mt('HTML/XML'),
                   8483:                  );
                   8484:     my $Str = '<input type="file" name="upfile" size="50" />'.
1.727     riegler  8485:         '<br />'.&mt('Type').': <select name="upfiletype">';
1.144     matthew  8486:     foreach my $type (sort(keys(%Types))) {
                   8487:         $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
                   8488:     }
                   8489:     $Str .= "</select>\n";
                   8490:     return $Str;
1.31      albertel 8491: }
                   8492: 
1.301     albertel 8493: sub get_samples {
                   8494:     my ($records,$toget) = @_;
                   8495:     my @samples=({});
                   8496:     my $got=0;
                   8497:     foreach my $rec (@$records) {
                   8498: 	my %temp = &record_sep($rec);
                   8499: 	if (! grep(/\S/, values(%temp))) { next; }
                   8500: 	if (%temp) {
                   8501: 	    $samples[$got]=\%temp;
                   8502: 	    $got++;
                   8503: 	    if ($got == $toget) { last; }
                   8504: 	}
                   8505:     }
                   8506:     return \@samples;
                   8507: }
                   8508: 
1.144     matthew  8509: ######################################################
                   8510: ######################################################
                   8511: 
1.56      matthew  8512: =pod
                   8513: 
1.648     raeburn  8514: =item * &csv_print_samples($r,$records)
1.41      ng       8515: 
                   8516: Prints a table of sample values from each column uploaded $r is an
                   8517: Apache Request ref, $records is an arrayref from
                   8518: &Apache::loncommon::upfile_record_sep
                   8519: 
                   8520: =cut
                   8521: 
1.144     matthew  8522: ######################################################
                   8523: ######################################################
1.31      albertel 8524: sub csv_print_samples {
                   8525:     my ($r,$records) = @_;
1.662     bisitz   8526:     my $samples = &get_samples($records,5);
1.301     albertel 8527: 
1.594     raeburn  8528:     $r->print(&mt('Samples').'<br />'.&start_data_table().
                   8529:               &start_data_table_header_row());
1.356     albertel 8530:     foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) { 
                   8531:         $r->print('<th>'.&mt('Column&nbsp;[_1]',($sample+1)).'</th>'); }
1.594     raeburn  8532:     $r->print(&end_data_table_header_row());
1.301     albertel 8533:     foreach my $hash (@$samples) {
1.594     raeburn  8534: 	$r->print(&start_data_table_row());
1.356     albertel 8535: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31      albertel 8536: 	    $r->print('<td>');
1.356     albertel 8537: 	    if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31      albertel 8538: 	    $r->print('</td>');
                   8539: 	}
1.594     raeburn  8540: 	$r->print(&end_data_table_row());
1.31      albertel 8541:     }
1.594     raeburn  8542:     $r->print(&end_data_table().'<br />'."\n");
1.31      albertel 8543: }
                   8544: 
1.144     matthew  8545: ######################################################
                   8546: ######################################################
                   8547: 
1.56      matthew  8548: =pod
                   8549: 
1.648     raeburn  8550: =item * &csv_print_select_table($r,$records,$d)
1.41      ng       8551: 
                   8552: Prints a table to create associations between values and table columns.
1.144     matthew  8553: 
1.41      ng       8554: $r is an Apache Request ref,
                   8555: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174     matthew  8556: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41      ng       8557: 
                   8558: =cut
                   8559: 
1.144     matthew  8560: ######################################################
                   8561: ######################################################
1.31      albertel 8562: sub csv_print_select_table {
                   8563:     my ($r,$records,$d) = @_;
1.301     albertel 8564:     my $i=0;
                   8565:     my $samples = &get_samples($records,1);
1.144     matthew  8566:     $r->print(&mt('Associate columns with student attributes.')."\n".
1.594     raeburn  8567: 	      &start_data_table().&start_data_table_header_row().
1.144     matthew  8568:               '<th>'.&mt('Attribute').'</th>'.
1.594     raeburn  8569:               '<th>'.&mt('Column').'</th>'.
                   8570:               &end_data_table_header_row()."\n");
1.356     albertel 8571:     foreach my $array_ref (@$d) {
                   8572: 	my ($value,$display,$defaultcol)=@{ $array_ref };
1.729     raeburn  8573: 	$r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31      albertel 8574: 
                   8575: 	$r->print('<td><select name=f'.$i.
1.32      matthew  8576: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.31      albertel 8577: 	$r->print('<option value="none"></option>');
1.356     albertel 8578: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
                   8579: 	    $r->print('<option value="'.$sample.'"'.
                   8580:                       ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662     bisitz   8581:                       '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31      albertel 8582: 	}
1.594     raeburn  8583: 	$r->print('</select></td>'.&end_data_table_row()."\n");
1.31      albertel 8584: 	$i++;
                   8585:     }
1.594     raeburn  8586:     $r->print(&end_data_table());
1.31      albertel 8587:     $i--;
                   8588:     return $i;
                   8589: }
1.56      matthew  8590: 
1.144     matthew  8591: ######################################################
                   8592: ######################################################
                   8593: 
1.56      matthew  8594: =pod
1.31      albertel 8595: 
1.648     raeburn  8596: =item * &csv_samples_select_table($r,$records,$d)
1.41      ng       8597: 
                   8598: Prints a table of sample values from the upload and can make associate samples to internal names.
                   8599: 
                   8600: $r is an Apache Request ref,
                   8601: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
                   8602: $d is an array of 2 element arrays (internal name, displayed name)
                   8603: 
                   8604: =cut
                   8605: 
1.144     matthew  8606: ######################################################
                   8607: ######################################################
1.31      albertel 8608: sub csv_samples_select_table {
                   8609:     my ($r,$records,$d) = @_;
                   8610:     my $i=0;
1.144     matthew  8611:     #
1.662     bisitz   8612:     my $max_samples = 5;
                   8613:     my $samples = &get_samples($records,$max_samples);
1.594     raeburn  8614:     $r->print(&start_data_table().
                   8615:               &start_data_table_header_row().'<th>'.
                   8616:               &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
                   8617:               &end_data_table_header_row());
1.301     albertel 8618: 
                   8619:     foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594     raeburn  8620: 	$r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32      matthew  8621: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.301     albertel 8622: 	foreach my $option (@$d) {
                   8623: 	    my ($value,$display,$defaultcol)=@{ $option };
1.174     matthew  8624: 	    $r->print('<option value="'.$value.'"'.
1.253     albertel 8625:                       ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174     matthew  8626:                       $display.'</option>');
1.31      albertel 8627: 	}
                   8628: 	$r->print('</select></td><td>');
1.662     bisitz   8629: 	foreach my $line (0..($max_samples-1)) {
1.301     albertel 8630: 	    if (defined($samples->[$line]{$key})) { 
                   8631: 		$r->print($samples->[$line]{$key}."<br />\n"); 
                   8632: 	    }
                   8633: 	}
1.594     raeburn  8634: 	$r->print('</td>'.&end_data_table_row());
1.31      albertel 8635: 	$i++;
                   8636:     }
1.594     raeburn  8637:     $r->print(&end_data_table());
1.31      albertel 8638:     $i--;
                   8639:     return($i);
1.115     matthew  8640: }
                   8641: 
1.144     matthew  8642: ######################################################
                   8643: ######################################################
                   8644: 
1.115     matthew  8645: =pod
                   8646: 
1.648     raeburn  8647: =item * &clean_excel_name($name)
1.115     matthew  8648: 
                   8649: Returns a replacement for $name which does not contain any illegal characters.
                   8650: 
                   8651: =cut
                   8652: 
1.144     matthew  8653: ######################################################
                   8654: ######################################################
1.115     matthew  8655: sub clean_excel_name {
                   8656:     my ($name) = @_;
                   8657:     $name =~ s/[:\*\?\/\\]//g;
                   8658:     if (length($name) > 31) {
                   8659:         $name = substr($name,0,31);
                   8660:     }
                   8661:     return $name;
1.25      albertel 8662: }
1.84      albertel 8663: 
1.85      albertel 8664: =pod
                   8665: 
1.648     raeburn  8666: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85      albertel 8667: 
                   8668: Returns either 1 or undef
                   8669: 
                   8670: 1 if the part is to be hidden, undef if it is to be shown
                   8671: 
                   8672: Arguments are:
                   8673: 
                   8674: $id the id of the part to be checked
                   8675: $symb, optional the symb of the resource to check
                   8676: $udom, optional the domain of the user to check for
                   8677: $uname, optional the username of the user to check for
                   8678: 
                   8679: =cut
1.84      albertel 8680: 
                   8681: sub check_if_partid_hidden {
                   8682:     my ($id,$symb,$udom,$uname) = @_;
1.133     albertel 8683:     my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84      albertel 8684: 					 $symb,$udom,$uname);
1.141     albertel 8685:     my $truth=1;
                   8686:     #if the string starts with !, then the list is the list to show not hide
                   8687:     if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84      albertel 8688:     my @hiddenlist=split(/,/,$hiddenparts);
                   8689:     foreach my $checkid (@hiddenlist) {
1.141     albertel 8690: 	if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84      albertel 8691:     }
1.141     albertel 8692:     return !$truth;
1.84      albertel 8693: }
1.127     matthew  8694: 
1.138     matthew  8695: 
                   8696: ############################################################
                   8697: ############################################################
                   8698: 
                   8699: =pod
                   8700: 
1.157     matthew  8701: =back 
                   8702: 
1.138     matthew  8703: =head1 cgi-bin script and graphing routines
                   8704: 
1.157     matthew  8705: =over 4
                   8706: 
1.648     raeburn  8707: =item * &get_cgi_id()
1.138     matthew  8708: 
                   8709: Inputs: none
                   8710: 
                   8711: Returns an id which can be used to pass environment variables
                   8712: to various cgi-bin scripts.  These environment variables will
                   8713: be removed from the users environment after a given time by
                   8714: the routine &Apache::lonnet::transfer_profile_to_env.
                   8715: 
                   8716: =cut
                   8717: 
                   8718: ############################################################
                   8719: ############################################################
1.152     albertel 8720: my $uniq=0;
1.136     matthew  8721: sub get_cgi_id {
1.154     albertel 8722:     $uniq=($uniq+1)%100000;
1.280     albertel 8723:     return (time.'_'.$$.'_'.$uniq);
1.136     matthew  8724: }
                   8725: 
1.127     matthew  8726: ############################################################
                   8727: ############################################################
                   8728: 
                   8729: =pod
                   8730: 
1.648     raeburn  8731: =item * &DrawBarGraph()
1.127     matthew  8732: 
1.138     matthew  8733: Facilitates the plotting of data in a (stacked) bar graph.
                   8734: Puts plot definition data into the users environment in order for 
                   8735: graph.png to plot it.  Returns an <img> tag for the plot.
                   8736: The bars on the plot are labeled '1','2',...,'n'.
                   8737: 
                   8738: Inputs:
                   8739: 
                   8740: =over 4
                   8741: 
                   8742: =item $Title: string, the title of the plot
                   8743: 
                   8744: =item $xlabel: string, text describing the X-axis of the plot
                   8745: 
                   8746: =item $ylabel: string, text describing the Y-axis of the plot
                   8747: 
                   8748: =item $Max: scalar, the maximum Y value to use in the plot
                   8749: If $Max is < any data point, the graph will not be rendered.
                   8750: 
1.140     matthew  8751: =item $colors: array ref holding the colors to be used for the data sets when
1.138     matthew  8752: they are plotted.  If undefined, default values will be used.
                   8753: 
1.178     matthew  8754: =item $labels: array ref holding the labels to use on the x-axis for the bars.
                   8755: 
1.138     matthew  8756: =item @Values: An array of array references.  Each array reference holds data
                   8757: to be plotted in a stacked bar chart.
                   8758: 
1.239     matthew  8759: =item If the final element of @Values is a hash reference the key/value
                   8760: pairs will be added to the graph definition.
                   8761: 
1.138     matthew  8762: =back
                   8763: 
                   8764: Returns:
                   8765: 
                   8766: An <img> tag which references graph.png and the appropriate identifying
                   8767: information for the plot.
                   8768: 
1.127     matthew  8769: =cut
                   8770: 
                   8771: ############################################################
                   8772: ############################################################
1.134     matthew  8773: sub DrawBarGraph {
1.178     matthew  8774:     my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134     matthew  8775:     #
                   8776:     if (! defined($colors)) {
                   8777:         $colors = ['#33ff00', 
                   8778:                   '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
                   8779:                   '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
                   8780:                   ]; 
                   8781:     }
1.228     matthew  8782:     my $extra_settings = {};
                   8783:     if (ref($Values[-1]) eq 'HASH') {
                   8784:         $extra_settings = pop(@Values);
                   8785:     }
1.127     matthew  8786:     #
1.136     matthew  8787:     my $identifier = &get_cgi_id();
                   8788:     my $id = 'cgi.'.$identifier;        
1.129     matthew  8789:     if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127     matthew  8790:         return '';
                   8791:     }
1.225     matthew  8792:     #
                   8793:     my @Labels;
                   8794:     if (defined($labels)) {
                   8795:         @Labels = @$labels;
                   8796:     } else {
                   8797:         for (my $i=0;$i<@{$Values[0]};$i++) {
                   8798:             push (@Labels,$i+1);
                   8799:         }
                   8800:     }
                   8801:     #
1.129     matthew  8802:     my $NumBars = scalar(@{$Values[0]});
1.225     matthew  8803:     if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129     matthew  8804:     my %ValuesHash;
                   8805:     my $NumSets=1;
                   8806:     foreach my $array (@Values) {
                   8807:         next if (! ref($array));
1.136     matthew  8808:         $ValuesHash{$id.'.data.'.$NumSets++} = 
1.132     matthew  8809:             join(',',@$array);
1.129     matthew  8810:     }
1.127     matthew  8811:     #
1.136     matthew  8812:     my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225     matthew  8813:     if ($NumBars < 3) {
                   8814:         $width = 120+$NumBars*32;
1.220     matthew  8815:         $xskip = 1;
1.225     matthew  8816:         $bar_width = 30;
                   8817:     } elsif ($NumBars < 5) {
                   8818:         $width = 120+$NumBars*20;
                   8819:         $xskip = 1;
                   8820:         $bar_width = 20;
1.220     matthew  8821:     } elsif ($NumBars < 10) {
1.136     matthew  8822:         $width = 120+$NumBars*15;
                   8823:         $xskip = 1;
                   8824:         $bar_width = 15;
                   8825:     } elsif ($NumBars <= 25) {
                   8826:         $width = 120+$NumBars*11;
                   8827:         $xskip = 5;
                   8828:         $bar_width = 8;
                   8829:     } elsif ($NumBars <= 50) {
                   8830:         $width = 120+$NumBars*8;
                   8831:         $xskip = 5;
                   8832:         $bar_width = 4;
                   8833:     } else {
                   8834:         $width = 120+$NumBars*8;
                   8835:         $xskip = 5;
                   8836:         $bar_width = 4;
                   8837:     }
                   8838:     #
1.137     matthew  8839:     $Max = 1 if ($Max < 1);
                   8840:     if ( int($Max) < $Max ) {
                   8841:         $Max++;
                   8842:         $Max = int($Max);
                   8843:     }
1.127     matthew  8844:     $Title  = '' if (! defined($Title));
                   8845:     $xlabel = '' if (! defined($xlabel));
                   8846:     $ylabel = '' if (! defined($ylabel));
1.369     www      8847:     $ValuesHash{$id.'.title'}    = &escape($Title);
                   8848:     $ValuesHash{$id.'.xlabel'}   = &escape($xlabel);
                   8849:     $ValuesHash{$id.'.ylabel'}   = &escape($ylabel);
1.137     matthew  8850:     $ValuesHash{$id.'.y_max_value'} = $Max;
1.136     matthew  8851:     $ValuesHash{$id.'.NumBars'}  = $NumBars;
                   8852:     $ValuesHash{$id.'.NumSets'}  = $NumSets;
                   8853:     $ValuesHash{$id.'.PlotType'} = 'bar';
                   8854:     $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8855:     $ValuesHash{$id.'.height'}   = $height;
                   8856:     $ValuesHash{$id.'.width'}    = $width;
                   8857:     $ValuesHash{$id.'.xskip'}    = $xskip;
                   8858:     $ValuesHash{$id.'.bar_width'} = $bar_width;
                   8859:     $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127     matthew  8860:     #
1.228     matthew  8861:     # Deal with other parameters
                   8862:     while (my ($key,$value) = each(%$extra_settings)) {
                   8863:         $ValuesHash{$id.'.'.$key} = $value;
                   8864:     }
                   8865:     #
1.646     raeburn  8866:     &Apache::lonnet::appenv(\%ValuesHash);
1.137     matthew  8867:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   8868: }
                   8869: 
                   8870: ############################################################
                   8871: ############################################################
                   8872: 
                   8873: =pod
                   8874: 
1.648     raeburn  8875: =item * &DrawXYGraph()
1.137     matthew  8876: 
1.138     matthew  8877: Facilitates the plotting of data in an XY graph.
                   8878: Puts plot definition data into the users environment in order for 
                   8879: graph.png to plot it.  Returns an <img> tag for the plot.
                   8880: 
                   8881: Inputs:
                   8882: 
                   8883: =over 4
                   8884: 
                   8885: =item $Title: string, the title of the plot
                   8886: 
                   8887: =item $xlabel: string, text describing the X-axis of the plot
                   8888: 
                   8889: =item $ylabel: string, text describing the Y-axis of the plot
                   8890: 
                   8891: =item $Max: scalar, the maximum Y value to use in the plot
                   8892: If $Max is < any data point, the graph will not be rendered.
                   8893: 
                   8894: =item $colors: Array ref containing the hex color codes for the data to be 
                   8895: plotted in.  If undefined, default values will be used.
                   8896: 
                   8897: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   8898: 
                   8899: =item $Ydata: Array ref containing Array refs.  
1.185     www      8900: Each of the contained arrays will be plotted as a separate curve.
1.138     matthew  8901: 
                   8902: =item %Values: hash indicating or overriding any default values which are 
                   8903: passed to graph.png.  
                   8904: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   8905: 
                   8906: =back
                   8907: 
                   8908: Returns:
                   8909: 
                   8910: An <img> tag which references graph.png and the appropriate identifying
                   8911: information for the plot.
                   8912: 
1.137     matthew  8913: =cut
                   8914: 
                   8915: ############################################################
                   8916: ############################################################
                   8917: sub DrawXYGraph {
                   8918:     my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
                   8919:     #
                   8920:     # Create the identifier for the graph
                   8921:     my $identifier = &get_cgi_id();
                   8922:     my $id = 'cgi.'.$identifier;
                   8923:     #
                   8924:     $Title  = '' if (! defined($Title));
                   8925:     $xlabel = '' if (! defined($xlabel));
                   8926:     $ylabel = '' if (! defined($ylabel));
                   8927:     my %ValuesHash = 
                   8928:         (
1.369     www      8929:          $id.'.title'  => &escape($Title),
                   8930:          $id.'.xlabel' => &escape($xlabel),
                   8931:          $id.'.ylabel' => &escape($ylabel),
1.137     matthew  8932:          $id.'.y_max_value'=> $Max,
                   8933:          $id.'.labels'     => join(',',@$Xlabels),
                   8934:          $id.'.PlotType'   => 'XY',
                   8935:          );
                   8936:     #
                   8937:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   8938:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8939:     }
                   8940:     #
                   8941:     if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
                   8942:         return '';
                   8943:     }
                   8944:     my $NumSets=1;
1.138     matthew  8945:     foreach my $array (@{$Ydata}){
1.137     matthew  8946:         next if (! ref($array));
                   8947:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
                   8948:     }
1.138     matthew  8949:     $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137     matthew  8950:     #
                   8951:     # Deal with other parameters
                   8952:     while (my ($key,$value) = each(%Values)) {
                   8953:         $ValuesHash{$id.'.'.$key} = $value;
1.127     matthew  8954:     }
                   8955:     #
1.646     raeburn  8956:     &Apache::lonnet::appenv(\%ValuesHash);
1.136     matthew  8957:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   8958: }
                   8959: 
                   8960: ############################################################
                   8961: ############################################################
                   8962: 
                   8963: =pod
                   8964: 
1.648     raeburn  8965: =item * &DrawXYYGraph()
1.138     matthew  8966: 
                   8967: Facilitates the plotting of data in an XY graph with two Y axes.
                   8968: Puts plot definition data into the users environment in order for 
                   8969: graph.png to plot it.  Returns an <img> tag for the plot.
                   8970: 
                   8971: Inputs:
                   8972: 
                   8973: =over 4
                   8974: 
                   8975: =item $Title: string, the title of the plot
                   8976: 
                   8977: =item $xlabel: string, text describing the X-axis of the plot
                   8978: 
                   8979: =item $ylabel: string, text describing the Y-axis of the plot
                   8980: 
                   8981: =item $colors: Array ref containing the hex color codes for the data to be 
                   8982: plotted in.  If undefined, default values will be used.
                   8983: 
                   8984: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   8985: 
                   8986: =item $Ydata1: The first data set
                   8987: 
                   8988: =item $Min1: The minimum value of the left Y-axis
                   8989: 
                   8990: =item $Max1: The maximum value of the left Y-axis
                   8991: 
                   8992: =item $Ydata2: The second data set
                   8993: 
                   8994: =item $Min2: The minimum value of the right Y-axis
                   8995: 
                   8996: =item $Max2: The maximum value of the left Y-axis
                   8997: 
                   8998: =item %Values: hash indicating or overriding any default values which are 
                   8999: passed to graph.png.  
                   9000: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   9001: 
                   9002: =back
                   9003: 
                   9004: Returns:
                   9005: 
                   9006: An <img> tag which references graph.png and the appropriate identifying
                   9007: information for the plot.
1.136     matthew  9008: 
                   9009: =cut
                   9010: 
                   9011: ############################################################
                   9012: ############################################################
1.137     matthew  9013: sub DrawXYYGraph {
                   9014:     my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
                   9015:                                         $Ydata2,$Min2,$Max2,%Values)=@_;
1.136     matthew  9016:     #
                   9017:     # Create the identifier for the graph
                   9018:     my $identifier = &get_cgi_id();
                   9019:     my $id = 'cgi.'.$identifier;
                   9020:     #
                   9021:     $Title  = '' if (! defined($Title));
                   9022:     $xlabel = '' if (! defined($xlabel));
                   9023:     $ylabel = '' if (! defined($ylabel));
                   9024:     my %ValuesHash = 
                   9025:         (
1.369     www      9026:          $id.'.title'  => &escape($Title),
                   9027:          $id.'.xlabel' => &escape($xlabel),
                   9028:          $id.'.ylabel' => &escape($ylabel),
1.136     matthew  9029:          $id.'.labels' => join(',',@$Xlabels),
                   9030:          $id.'.PlotType' => 'XY',
                   9031:          $id.'.NumSets' => 2,
1.137     matthew  9032:          $id.'.two_axes' => 1,
                   9033:          $id.'.y1_max_value' => $Max1,
                   9034:          $id.'.y1_min_value' => $Min1,
                   9035:          $id.'.y2_max_value' => $Max2,
                   9036:          $id.'.y2_min_value' => $Min2,
1.136     matthew  9037:          );
                   9038:     #
1.137     matthew  9039:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   9040:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   9041:     }
                   9042:     #
                   9043:     if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
                   9044:         ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136     matthew  9045:         return '';
                   9046:     }
                   9047:     my $NumSets=1;
1.137     matthew  9048:     foreach my $array ($Ydata1,$Ydata2){
1.136     matthew  9049:         next if (! ref($array));
                   9050:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137     matthew  9051:     }
                   9052:     #
                   9053:     # Deal with other parameters
                   9054:     while (my ($key,$value) = each(%Values)) {
                   9055:         $ValuesHash{$id.'.'.$key} = $value;
1.136     matthew  9056:     }
                   9057:     #
1.646     raeburn  9058:     &Apache::lonnet::appenv(\%ValuesHash);
1.130     albertel 9059:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139     matthew  9060: }
                   9061: 
                   9062: ############################################################
                   9063: ############################################################
                   9064: 
                   9065: =pod
                   9066: 
1.157     matthew  9067: =back 
                   9068: 
1.139     matthew  9069: =head1 Statistics helper routines?  
                   9070: 
                   9071: Bad place for them but what the hell.
                   9072: 
1.157     matthew  9073: =over 4
                   9074: 
1.648     raeburn  9075: =item * &chartlink()
1.139     matthew  9076: 
                   9077: Returns a link to the chart for a specific student.  
                   9078: 
                   9079: Inputs:
                   9080: 
                   9081: =over 4
                   9082: 
                   9083: =item $linktext: The text of the link
                   9084: 
                   9085: =item $sname: The students username
                   9086: 
                   9087: =item $sdomain: The students domain
                   9088: 
                   9089: =back
                   9090: 
1.157     matthew  9091: =back
                   9092: 
1.139     matthew  9093: =cut
                   9094: 
                   9095: ############################################################
                   9096: ############################################################
                   9097: sub chartlink {
                   9098:     my ($linktext, $sname, $sdomain) = @_;
                   9099:     my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369     www      9100:         '&amp;SelectedStudent='.&escape($sname.':'.$sdomain).
1.219     albertel 9101:         '&amp;chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139     matthew  9102:        '">'.$linktext.'</a>';
1.153     matthew  9103: }
                   9104: 
                   9105: #######################################################
                   9106: #######################################################
                   9107: 
                   9108: =pod
                   9109: 
                   9110: =head1 Course Environment Routines
1.157     matthew  9111: 
                   9112: =over 4
1.153     matthew  9113: 
1.648     raeburn  9114: =item * &restore_course_settings()
1.153     matthew  9115: 
1.648     raeburn  9116: =item * &store_course_settings()
1.153     matthew  9117: 
                   9118: Restores/Store indicated form parameters from the course environment.
                   9119: Will not overwrite existing values of the form parameters.
                   9120: 
                   9121: Inputs: 
                   9122: a scalar describing the data (e.g. 'chart', 'problem_analysis')
                   9123: 
                   9124: a hash ref describing the data to be stored.  For example:
                   9125:    
                   9126: %Save_Parameters = ('Status' => 'scalar',
                   9127:     'chartoutputmode' => 'scalar',
                   9128:     'chartoutputdata' => 'scalar',
                   9129:     'Section' => 'array',
1.373     raeburn  9130:     'Group' => 'array',
1.153     matthew  9131:     'StudentData' => 'array',
                   9132:     'Maps' => 'array');
                   9133: 
                   9134: Returns: both routines return nothing
                   9135: 
1.631     raeburn  9136: =back
                   9137: 
1.153     matthew  9138: =cut
                   9139: 
                   9140: #######################################################
                   9141: #######################################################
                   9142: sub store_course_settings {
1.496     albertel 9143:     return &store_settings($env{'request.course.id'},@_);
                   9144: }
                   9145: 
                   9146: sub store_settings {
1.153     matthew  9147:     # save to the environment
                   9148:     # appenv the same items, just to be safe
1.300     albertel 9149:     my $udom  = $env{'user.domain'};
                   9150:     my $uname = $env{'user.name'};
1.496     albertel 9151:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  9152:     my %SaveHash;
                   9153:     my %AppHash;
                   9154:     while (my ($setting,$type) = each(%$Settings)) {
1.496     albertel 9155:         my $basename = join('.','internal',$context,$prefix,$setting);
1.300     albertel 9156:         my $envname = 'environment.'.$basename;
1.258     albertel 9157:         if (exists($env{'form.'.$setting})) {
1.153     matthew  9158:             # Save this value away
                   9159:             if ($type eq 'scalar' &&
1.258     albertel 9160:                 (! exists($env{$envname}) || 
                   9161:                  $env{$envname} ne $env{'form.'.$setting})) {
                   9162:                 $SaveHash{$basename} = $env{'form.'.$setting};
                   9163:                 $AppHash{$envname}   = $env{'form.'.$setting};
1.153     matthew  9164:             } elsif ($type eq 'array') {
                   9165:                 my $stored_form;
1.258     albertel 9166:                 if (ref($env{'form.'.$setting})) {
1.153     matthew  9167:                     $stored_form = join(',',
                   9168:                                         map {
1.369     www      9169:                                             &escape($_);
1.258     albertel 9170:                                         } sort(@{$env{'form.'.$setting}}));
1.153     matthew  9171:                 } else {
                   9172:                     $stored_form = 
1.369     www      9173:                         &escape($env{'form.'.$setting});
1.153     matthew  9174:                 }
                   9175:                 # Determine if the array contents are the same.
1.258     albertel 9176:                 if ($stored_form ne $env{$envname}) {
1.153     matthew  9177:                     $SaveHash{$basename} = $stored_form;
                   9178:                     $AppHash{$envname}   = $stored_form;
                   9179:                 }
                   9180:             }
                   9181:         }
                   9182:     }
                   9183:     my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300     albertel 9184:                                           $udom,$uname);
1.153     matthew  9185:     if ($put_result !~ /^(ok|delayed)/) {
                   9186:         &Apache::lonnet::logthis('unable to save form parameters, '.
                   9187:                                  'got error:'.$put_result);
                   9188:     }
                   9189:     # Make sure these settings stick around in this session, too
1.646     raeburn  9190:     &Apache::lonnet::appenv(\%AppHash);
1.153     matthew  9191:     return;
                   9192: }
                   9193: 
                   9194: sub restore_course_settings {
1.499     albertel 9195:     return &restore_settings($env{'request.course.id'},@_);
1.496     albertel 9196: }
                   9197: 
                   9198: sub restore_settings {
                   9199:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  9200:     while (my ($setting,$type) = each(%$Settings)) {
1.258     albertel 9201:         next if (exists($env{'form.'.$setting}));
1.496     albertel 9202:         my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153     matthew  9203:             '.'.$setting;
1.258     albertel 9204:         if (exists($env{$envname})) {
1.153     matthew  9205:             if ($type eq 'scalar') {
1.258     albertel 9206:                 $env{'form.'.$setting} = $env{$envname};
1.153     matthew  9207:             } elsif ($type eq 'array') {
1.258     albertel 9208:                 $env{'form.'.$setting} = [ 
1.153     matthew  9209:                                            map { 
1.369     www      9210:                                                &unescape($_); 
1.258     albertel 9211:                                            } split(',',$env{$envname})
1.153     matthew  9212:                                            ];
                   9213:             }
                   9214:         }
                   9215:     }
1.127     matthew  9216: }
                   9217: 
1.618     raeburn  9218: #######################################################
                   9219: #######################################################
                   9220: 
                   9221: =pod
                   9222: 
                   9223: =head1 Domain E-mail Routines  
                   9224: 
                   9225: =over 4
                   9226: 
1.648     raeburn  9227: =item * &build_recipient_list()
1.618     raeburn  9228: 
1.766     raeburn  9229: Build recipient lists for four types of e-mail:
                   9230: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
                   9231: (d) Help requests, generated by
                   9232: lonerrorhandler.pm, CHECKRPMS, loncron, and lonsupportreq.pm respectively.
1.618     raeburn  9233: 
                   9234: Inputs:
1.619     raeburn  9235: defmail (scalar - email address of default recipient), 
1.618     raeburn  9236: mailing type (scalar - errormail, packagesmail, or helpdeskmail), 
1.619     raeburn  9237: defdom (domain for which to retrieve configuration settings),
                   9238: origmail (scalar - email address of recipient from loncapa.conf, 
                   9239: i.e., predates configuration by DC via domainprefs.pm 
1.618     raeburn  9240: 
1.655     raeburn  9241: Returns: comma separated list of addresses to which to send e-mail.
                   9242: 
                   9243: =back
1.618     raeburn  9244: 
                   9245: =cut
                   9246: 
                   9247: ############################################################
                   9248: ############################################################
                   9249: sub build_recipient_list {
1.619     raeburn  9250:     my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618     raeburn  9251:     my @recipients;
                   9252:     my $otheremails;
                   9253:     my %domconfig =
                   9254:          &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
                   9255:     if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766     raeburn  9256:         if (exists($domconfig{'contacts'}{$mailing})) {
                   9257:             if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
                   9258:                 my @contacts = ('adminemail','supportemail');
                   9259:                 foreach my $item (@contacts) {
                   9260:                     if ($domconfig{'contacts'}{$mailing}{$item}) {
                   9261:                         my $addr = $domconfig{'contacts'}{$item}; 
                   9262:                         if (!grep(/^\Q$addr\E$/,@recipients)) {
                   9263:                             push(@recipients,$addr);
                   9264:                         }
1.619     raeburn  9265:                     }
1.766     raeburn  9266:                     $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618     raeburn  9267:                 }
                   9268:             }
1.766     raeburn  9269:         } elsif ($origmail ne '') {
                   9270:             push(@recipients,$origmail);
1.618     raeburn  9271:         }
1.619     raeburn  9272:     } elsif ($origmail ne '') {
                   9273:         push(@recipients,$origmail);
1.618     raeburn  9274:     }
1.688     raeburn  9275:     if (defined($defmail)) {
                   9276:         if ($defmail ne '') {
                   9277:             push(@recipients,$defmail);
                   9278:         }
1.618     raeburn  9279:     }
                   9280:     if ($otheremails) {
1.619     raeburn  9281:         my @others;
                   9282:         if ($otheremails =~ /,/) {
                   9283:             @others = split(/,/,$otheremails);
1.618     raeburn  9284:         } else {
1.619     raeburn  9285:             push(@others,$otheremails);
                   9286:         }
                   9287:         foreach my $addr (@others) {
                   9288:             if (!grep(/^\Q$addr\E$/,@recipients)) {
                   9289:                 push(@recipients,$addr);
                   9290:             }
1.618     raeburn  9291:         }
                   9292:     }
1.619     raeburn  9293:     my $recipientlist = join(',',@recipients); 
1.618     raeburn  9294:     return $recipientlist;
                   9295: }
                   9296: 
1.127     matthew  9297: ############################################################
                   9298: ############################################################
1.154     albertel 9299: 
1.655     raeburn  9300: =pod
                   9301: 
                   9302: =head1 Course Catalog Routines
                   9303: 
                   9304: =over 4
                   9305: 
                   9306: =item * &gather_categories()
                   9307: 
                   9308: Converts category definitions - keys of categories hash stored in  
                   9309: coursecategories in configuration.db on the primary library server in a 
                   9310: domain - to an array.  Also generates javascript and idx hash used to 
                   9311: generate Domain Coordinator interface for editing Course Categories.
                   9312: 
                   9313: Inputs:
1.663     raeburn  9314: 
1.655     raeburn  9315: categories (reference to hash of category definitions).
1.663     raeburn  9316: 
1.655     raeburn  9317: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9318:       categories and subcategories).
1.663     raeburn  9319: 
1.655     raeburn  9320: idx (reference to hash of counters used in Domain Coordinator interface for 
                   9321:       editing Course Categories).
1.663     raeburn  9322: 
1.655     raeburn  9323: jsarray (reference to array of categories used to create Javascript arrays for
                   9324:          Domain Coordinator interface for editing Course Categories).
                   9325: 
                   9326: Returns: nothing
                   9327: 
                   9328: Side effects: populates cats, idx and jsarray. 
                   9329: 
                   9330: =cut
                   9331: 
                   9332: sub gather_categories {
                   9333:     my ($categories,$cats,$idx,$jsarray) = @_;
                   9334:     my %counters;
                   9335:     my $num = 0;
                   9336:     foreach my $item (keys(%{$categories})) {
                   9337:         my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   9338:         if ($container eq '' && $depth == 0) {
                   9339:             $cats->[$depth][$categories->{$item}] = $cat;
                   9340:         } else {
                   9341:             $cats->[$depth]{$container}[$categories->{$item}] = $cat;
                   9342:         }
                   9343:         my ($escitem,$tail) = split(/:/,$item,2);
                   9344:         if ($counters{$tail} eq '') {
                   9345:             $counters{$tail} = $num;
                   9346:             $num ++;
                   9347:         }
                   9348:         if (ref($idx) eq 'HASH') {
                   9349:             $idx->{$item} = $counters{$tail};
                   9350:         }
                   9351:         if (ref($jsarray) eq 'ARRAY') {
                   9352:             push(@{$jsarray->[$counters{$tail}]},$item);
                   9353:         }
                   9354:     }
                   9355:     return;
                   9356: }
                   9357: 
                   9358: =pod
                   9359: 
                   9360: =item * &extract_categories()
                   9361: 
                   9362: Used to generate breadcrumb trails for course categories.
                   9363: 
                   9364: Inputs:
1.663     raeburn  9365: 
1.655     raeburn  9366: categories (reference to hash of category definitions).
1.663     raeburn  9367: 
1.655     raeburn  9368: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9369:       categories and subcategories).
1.663     raeburn  9370: 
1.655     raeburn  9371: trails (reference to array of breacrumb trails for each category).
1.663     raeburn  9372: 
1.655     raeburn  9373: allitems (reference to hash - key is category key 
                   9374:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  9375: 
1.655     raeburn  9376: idx (reference to hash of counters used in Domain Coordinator interface for
                   9377:       editing Course Categories).
1.663     raeburn  9378: 
1.655     raeburn  9379: jsarray (reference to array of categories used to create Javascript arrays for
                   9380:          Domain Coordinator interface for editing Course Categories).
                   9381: 
1.665     raeburn  9382: subcats (reference to hash of arrays containing all subcategories within each 
                   9383:          category, -recursive)
                   9384: 
1.655     raeburn  9385: Returns: nothing
                   9386: 
                   9387: Side effects: populates trails and allitems hash references.
                   9388: 
                   9389: =cut
                   9390: 
                   9391: sub extract_categories {
1.665     raeburn  9392:     my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655     raeburn  9393:     if (ref($categories) eq 'HASH') {
                   9394:         &gather_categories($categories,$cats,$idx,$jsarray);
                   9395:         if (ref($cats->[0]) eq 'ARRAY') {
                   9396:             for (my $i=0; $i<@{$cats->[0]}; $i++) {
                   9397:                 my $name = $cats->[0][$i];
                   9398:                 my $item = &escape($name).'::0';
                   9399:                 my $trailstr;
                   9400:                 if ($name eq 'instcode') {
                   9401:                     $trailstr = &mt('Official courses (with institutional codes)');
                   9402:                 } else {
                   9403:                     $trailstr = $name;
                   9404:                 }
                   9405:                 if ($allitems->{$item} eq '') {
                   9406:                     push(@{$trails},$trailstr);
                   9407:                     $allitems->{$item} = scalar(@{$trails})-1;
                   9408:                 }
                   9409:                 my @parents = ($name);
                   9410:                 if (ref($cats->[1]{$name}) eq 'ARRAY') {
                   9411:                     for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
                   9412:                         my $category = $cats->[1]{$name}[$j];
1.665     raeburn  9413:                         if (ref($subcats) eq 'HASH') {
                   9414:                             push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
                   9415:                         }
                   9416:                         &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
                   9417:                     }
                   9418:                 } else {
                   9419:                     if (ref($subcats) eq 'HASH') {
                   9420:                         $subcats->{$item} = [];
1.655     raeburn  9421:                     }
                   9422:                 }
                   9423:             }
                   9424:         }
                   9425:     }
                   9426:     return;
                   9427: }
                   9428: 
                   9429: =pod
                   9430: 
                   9431: =item *&recurse_categories()
                   9432: 
                   9433: Recursively used to generate breadcrumb trails for course categories.
                   9434: 
                   9435: Inputs:
1.663     raeburn  9436: 
1.655     raeburn  9437: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9438:       categories and subcategories).
1.663     raeburn  9439: 
1.655     raeburn  9440: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663     raeburn  9441: 
                   9442: category (current course category, for which breadcrumb trail is being generated).
                   9443: 
                   9444: trails (reference to array of breadcrumb trails for each category).
                   9445: 
1.655     raeburn  9446: allitems (reference to hash - key is category key
                   9447:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  9448: 
1.655     raeburn  9449: parents (array containing containers directories for current category, 
                   9450:          back to top level). 
                   9451: 
                   9452: Returns: nothing
                   9453: 
                   9454: Side effects: populates trails and allitems hash references
                   9455: 
                   9456: =cut
                   9457: 
                   9458: sub recurse_categories {
1.665     raeburn  9459:     my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655     raeburn  9460:     my $shallower = $depth - 1;
                   9461:     if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
                   9462:         for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
                   9463:             my $name = $cats->[$depth]{$category}[$k];
                   9464:             my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   9465:             my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   9466:             if ($allitems->{$item} eq '') {
                   9467:                 push(@{$trails},$trailstr);
                   9468:                 $allitems->{$item} = scalar(@{$trails})-1;
                   9469:             }
                   9470:             my $deeper = $depth+1;
                   9471:             push(@{$parents},$category);
1.665     raeburn  9472:             if (ref($subcats) eq 'HASH') {
                   9473:                 my $subcat = &escape($name).':'.$category.':'.$depth;
                   9474:                 for (my $j=@{$parents}; $j>=0; $j--) {
                   9475:                     my $higher;
                   9476:                     if ($j > 0) {
                   9477:                         $higher = &escape($parents->[$j]).':'.
                   9478:                                   &escape($parents->[$j-1]).':'.$j;
                   9479:                     } else {
                   9480:                         $higher = &escape($parents->[$j]).'::'.$j;
                   9481:                     }
                   9482:                     push(@{$subcats->{$higher}},$subcat);
                   9483:                 }
                   9484:             }
                   9485:             &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
                   9486:                                 $subcats);
1.655     raeburn  9487:             pop(@{$parents});
                   9488:         }
                   9489:     } else {
                   9490:         my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   9491:         my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   9492:         if ($allitems->{$item} eq '') {
                   9493:             push(@{$trails},$trailstr);
                   9494:             $allitems->{$item} = scalar(@{$trails})-1;
                   9495:         }
                   9496:     }
                   9497:     return;
                   9498: }
                   9499: 
1.663     raeburn  9500: =pod
                   9501: 
                   9502: =item *&assign_categories_table()
                   9503: 
                   9504: Create a datatable for display of hierarchical categories in a domain,
                   9505: with checkboxes to allow a course to be categorized. 
                   9506: 
                   9507: Inputs:
                   9508: 
                   9509: cathash - reference to hash of categories defined for the domain (from
                   9510:           configuration.db)
                   9511: 
                   9512: currcat - scalar with an & separated list of categories assigned to a course. 
                   9513: 
                   9514: Returns: $output (markup to be displayed) 
                   9515: 
                   9516: =cut
                   9517: 
                   9518: sub assign_categories_table {
                   9519:     my ($cathash,$currcat) = @_;
                   9520:     my $output;
                   9521:     if (ref($cathash) eq 'HASH') {
                   9522:         my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
                   9523:         &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
                   9524:         $maxdepth = scalar(@cats);
                   9525:         if (@cats > 0) {
                   9526:             my $itemcount = 0;
                   9527:             if (ref($cats[0]) eq 'ARRAY') {
                   9528:                 $output = &Apache::loncommon::start_data_table();
                   9529:                 my @currcategories;
                   9530:                 if ($currcat ne '') {
                   9531:                     @currcategories = split('&',$currcat);
                   9532:                 }
                   9533:                 for (my $i=0; $i<@{$cats[0]}; $i++) {
                   9534:                     my $parent = $cats[0][$i];
                   9535:                     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9536:                     next if ($parent eq 'instcode');
                   9537:                     my $item = &escape($parent).'::0';
                   9538:                     my $checked = '';
                   9539:                     if (@currcategories > 0) {
                   9540:                         if (grep(/^\Q$item\E$/,@currcategories)) {
1.772     bisitz   9541:                             $checked = ' checked="checked"';
1.663     raeburn  9542:                         }
                   9543:                     }
1.675     raeburn  9544:                     $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
                   9545:                                '<input type="checkbox" name="usecategory" value="'.
                   9546:                                $item.'"'.$checked.' />'.$parent.'</span>'.
                   9547:                                '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663     raeburn  9548:                     my $depth = 1;
                   9549:                     push(@path,$parent);
                   9550:                     $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
                   9551:                     pop(@path);
                   9552:                     $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   9553:                     $itemcount ++;
                   9554:                 }
                   9555:                 $output .= &Apache::loncommon::end_data_table();
                   9556:             }
                   9557:         }
                   9558:     }
                   9559:     return $output;
                   9560: }
                   9561: 
                   9562: =pod
                   9563: 
                   9564: =item *&assign_category_rows()
                   9565: 
                   9566: Create a datatable row for display of nested categories in a domain,
                   9567: with checkboxes to allow a course to be categorized,called recursively.
                   9568: 
                   9569: Inputs:
                   9570: 
                   9571: itemcount - track row number for alternating colors
                   9572: 
                   9573: cats - reference to array of arrays/hashes which encapsulates hierarchy of
                   9574:       categories and subcategories.
                   9575: 
                   9576: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
                   9577: 
                   9578: parent - parent of current category item
                   9579: 
                   9580: path - Array containing all categories back up through the hierarchy from the
                   9581:        current category to the top level.
                   9582: 
                   9583: currcategories - reference to array of current categories assigned to the course
                   9584: 
                   9585: Returns: $output (markup to be displayed).
                   9586: 
                   9587: =cut
                   9588: 
                   9589: sub assign_category_rows {
                   9590:     my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
                   9591:     my ($text,$name,$item,$chgstr);
                   9592:     if (ref($cats) eq 'ARRAY') {
                   9593:         my $maxdepth = scalar(@{$cats});
                   9594:         if (ref($cats->[$depth]) eq 'HASH') {
                   9595:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   9596:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   9597:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9598:                 $text .= '<td><table class="LC_datatable">';
                   9599:                 for (my $j=0; $j<$numchildren; $j++) {
                   9600:                     $name = $cats->[$depth]{$parent}[$j];
                   9601:                     $item = &escape($name).':'.&escape($parent).':'.$depth;
                   9602:                     my $deeper = $depth+1;
                   9603:                     my $checked = '';
                   9604:                     if (ref($currcategories) eq 'ARRAY') {
                   9605:                         if (@{$currcategories} > 0) {
                   9606:                             if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772     bisitz   9607:                                 $checked = ' checked="checked"';
1.663     raeburn  9608:                             }
                   9609:                         }
                   9610:                     }
1.664     raeburn  9611:                     $text .= '<tr><td><span class="LC_nobreak"><label>'.
                   9612:                              '<input type="checkbox" name="usecategory" value="'.
1.675     raeburn  9613:                              $item.'"'.$checked.' />'.$name.'</label></span>'.
                   9614:                              '<input type="hidden" name="catname" value="'.$name.'" />'.
                   9615:                              '</td><td>';
1.663     raeburn  9616:                     if (ref($path) eq 'ARRAY') {
                   9617:                         push(@{$path},$name);
                   9618:                         $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
                   9619:                         pop(@{$path});
                   9620:                     }
                   9621:                     $text .= '</td></tr>';
                   9622:                 }
                   9623:                 $text .= '</table></td>';
                   9624:             }
                   9625:         }
                   9626:     }
                   9627:     return $text;
                   9628: }
                   9629: 
1.655     raeburn  9630: ############################################################
                   9631: ############################################################
                   9632: 
                   9633: 
1.443     albertel 9634: sub commit_customrole {
1.664     raeburn  9635:     my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630     raeburn  9636:     my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443     albertel 9637:                          ($start?', '.&mt('starting').' '.localtime($start):'').
                   9638:                          ($end?', ending '.localtime($end):'').': <b>'.
                   9639:               &Apache::lonnet::assigncustomrole(
1.664     raeburn  9640:                  $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443     albertel 9641:                  '</b><br />';
                   9642:     return $output;
                   9643: }
                   9644: 
                   9645: sub commit_standardrole {
1.541     raeburn  9646:     my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
                   9647:     my ($output,$logmsg,$linefeed);
                   9648:     if ($context eq 'auto') {
                   9649:         $linefeed = "\n";
                   9650:     } else {
                   9651:         $linefeed = "<br />\n";
                   9652:     }  
1.443     albertel 9653:     if ($three eq 'st') {
1.541     raeburn  9654:         my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
                   9655:                                          $one,$two,$sec,$context);
                   9656:         if (($result =~ /^error/) || ($result eq 'not_in_class') || 
1.626     raeburn  9657:             ($result eq 'unknown_course') || ($result eq 'refused')) {
                   9658:             $output = $logmsg.' '.&mt('Error: ').$result."\n"; 
1.443     albertel 9659:         } else {
1.541     raeburn  9660:             $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443     albertel 9661:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  9662:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
                   9663:             if ($context eq 'auto') {
                   9664:                 $output .= $result.$linefeed.&mt('Add to classlist').': ok';
                   9665:             } else {
                   9666:                $output .= '<b>'.$result.'</b>'.$linefeed.
                   9667:                &mt('Add to classlist').': <b>ok</b>';
                   9668:             }
                   9669:             $output .= $linefeed;
1.443     albertel 9670:         }
                   9671:     } else {
                   9672:         $output = &mt('Assigning').' '.$three.' in '.$url.
                   9673:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  9674:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652     raeburn  9675:         my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541     raeburn  9676:         if ($context eq 'auto') {
                   9677:             $output .= $result.$linefeed;
                   9678:         } else {
                   9679:             $output .= '<b>'.$result.'</b>'.$linefeed;
                   9680:         }
1.443     albertel 9681:     }
                   9682:     return $output;
                   9683: }
                   9684: 
                   9685: sub commit_studentrole {
1.541     raeburn  9686:     my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626     raeburn  9687:     my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541     raeburn  9688:     if ($context eq 'auto') {
                   9689:         $linefeed = "\n";
                   9690:     } else {
                   9691:         $linefeed = '<br />'."\n";
                   9692:     }
1.443     albertel 9693:     if (defined($one) && defined($two)) {
                   9694:         my $cid=$one.'_'.$two;
                   9695:         my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
                   9696:         my $secchange = 0;
                   9697:         my $expire_role_result;
                   9698:         my $modify_section_result;
1.628     raeburn  9699:         if ($oldsec ne '-1') { 
                   9700:             if ($oldsec ne $sec) {
1.443     albertel 9701:                 $secchange = 1;
1.628     raeburn  9702:                 my $now = time;
1.443     albertel 9703:                 my $uurl='/'.$cid;
                   9704:                 $uurl=~s/\_/\//g;
                   9705:                 if ($oldsec) {
                   9706:                     $uurl.='/'.$oldsec;
                   9707:                 }
1.626     raeburn  9708:                 $oldsecurl = $uurl;
1.628     raeburn  9709:                 $expire_role_result = 
1.652     raeburn  9710:                     &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628     raeburn  9711:                 if ($env{'request.course.sec'} ne '') { 
                   9712:                     if ($expire_role_result eq 'refused') {
                   9713:                         my @roles = ('st');
                   9714:                         my @statuses = ('previous');
                   9715:                         my @roledoms = ($one);
                   9716:                         my $withsec = 1;
                   9717:                         my %roleshash = 
                   9718:                             &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
                   9719:                                               \@statuses,\@roles,\@roledoms,$withsec);
                   9720:                         if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
                   9721:                             my ($oldstart,$oldend) = 
                   9722:                                 split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
                   9723:                             if ($oldend > 0 && $oldend <= $now) {
                   9724:                                 $expire_role_result = 'ok';
                   9725:                             }
                   9726:                         }
                   9727:                     }
                   9728:                 }
1.443     albertel 9729:                 $result = $expire_role_result;
                   9730:             }
                   9731:         }
                   9732:         if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652     raeburn  9733:             $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443     albertel 9734:             if ($modify_section_result =~ /^ok/) {
                   9735:                 if ($secchange == 1) {
1.628     raeburn  9736:                     if ($sec eq '') {
                   9737:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
                   9738:                     } else {
                   9739:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
                   9740:                     }
1.443     albertel 9741:                 } elsif ($oldsec eq '-1') {
1.628     raeburn  9742:                     if ($sec eq '') {
                   9743:                         $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
                   9744:                     } else {
                   9745:                         $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   9746:                     }
1.443     albertel 9747:                 } else {
1.628     raeburn  9748:                     if ($sec eq '') {
                   9749:                         $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
                   9750:                     } else {
                   9751:                         $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   9752:                     }
1.443     albertel 9753:                 }
                   9754:             } else {
1.628     raeburn  9755:                 if ($secchange) {       
                   9756:                     $$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;
                   9757:                 } else {
                   9758:                     $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
                   9759:                 }
1.443     albertel 9760:             }
                   9761:             $result = $modify_section_result;
                   9762:         } elsif ($secchange == 1) {
1.628     raeburn  9763:             if ($oldsec eq '') {
                   9764:                 $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
                   9765:             } else {
                   9766:                 $$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;
                   9767:             }
1.626     raeburn  9768:             if ($expire_role_result eq 'refused') {
                   9769:                 my $newsecurl = '/'.$cid;
                   9770:                 $newsecurl =~ s/\_/\//g;
                   9771:                 if ($sec ne '') {
                   9772:                     $newsecurl.='/'.$sec;
                   9773:                 }
                   9774:                 if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
                   9775:                     if ($sec eq '') {
                   9776:                         $$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;
                   9777:                     } else {
                   9778:                         $$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;
                   9779:                     }
                   9780:                 }
                   9781:             }
1.443     albertel 9782:         }
                   9783:     } else {
1.626     raeburn  9784:         $$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 9785:         $result = "error: incomplete course id\n";
                   9786:     }
                   9787:     return $result;
                   9788: }
                   9789: 
                   9790: ############################################################
                   9791: ############################################################
                   9792: 
1.566     albertel 9793: sub check_clone {
1.578     raeburn  9794:     my ($args,$linefeed) = @_;
1.566     albertel 9795:     my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
                   9796:     my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
                   9797:     my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
                   9798:     my $clonemsg;
                   9799:     my $can_clone = 0;
                   9800: 
                   9801:     if ($clonehome eq 'no_host') {
1.578     raeburn  9802:         $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 9803:     } else {
                   9804: 	my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568     albertel 9805: 	if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566     albertel 9806: 	    $can_clone = 1;
                   9807: 	} else {
                   9808: 	    my %clonehash = &Apache::lonnet::get('environment',['cloners'],
                   9809: 						 $args->{'clonedomain'},$args->{'clonecourse'});
                   9810: 	    my @cloners = split(/,/,$clonehash{'cloners'});
1.578     raeburn  9811:             if (grep(/^\*$/,@cloners)) {
                   9812:                 $can_clone = 1;
                   9813:             } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
                   9814:                 $can_clone = 1;
                   9815:             } else {
                   9816: 	        my %roleshash =
                   9817: 		    &Apache::lonnet::get_my_roles($args->{'ccuname'},
                   9818: 					 $args->{'ccdomain'},
                   9819:                                          'userroles',['active'],['cc'],
                   9820: 					 [$args->{'clonedomain'}]);
                   9821: 	        if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
                   9822: 		    $can_clone = 1;
                   9823: 	        } else {
                   9824:                     $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'});
                   9825: 	        }
1.566     albertel 9826: 	    }
1.578     raeburn  9827:         }
1.566     albertel 9828:     }
                   9829:     return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   9830: }
                   9831: 
1.444     albertel 9832: sub construct_course {
1.541     raeburn  9833:     my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444     albertel 9834:     my $outcome;
1.541     raeburn  9835:     my $linefeed =  '<br />'."\n";
                   9836:     if ($context eq 'auto') {
                   9837:         $linefeed = "\n";
                   9838:     }
1.566     albertel 9839: 
                   9840: #
                   9841: # Are we cloning?
                   9842: #
                   9843:     my ($can_clone, $clonemsg, $cloneid, $clonehome);
                   9844:     if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578     raeburn  9845: 	($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566     albertel 9846: 	if ($context ne 'auto') {
1.578     raeburn  9847:             if ($clonemsg ne '') {
                   9848: 	        $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
                   9849:             }
1.566     albertel 9850: 	}
                   9851: 	$outcome .= $clonemsg.$linefeed;
                   9852: 
                   9853:         if (!$can_clone) {
                   9854: 	    return (0,$outcome);
                   9855: 	}
                   9856:     }
                   9857: 
1.444     albertel 9858: #
                   9859: # Open course
                   9860: #
                   9861:     my $crstype = lc($args->{'crstype'});
                   9862:     my %cenv=();
                   9863:     $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
                   9864:                                              $args->{'cdescr'},
                   9865:                                              $args->{'curl'},
                   9866:                                              $args->{'course_home'},
                   9867:                                              $args->{'nonstandard'},
                   9868:                                              $args->{'crscode'},
                   9869:                                              $args->{'ccuname'}.':'.
                   9870:                                              $args->{'ccdomain'},
                   9871:                                              $args->{'crstype'});
                   9872: 
                   9873:     # Note: The testing routines depend on this being output; see 
                   9874:     # Utils::Course. This needs to at least be output as a comment
                   9875:     # if anyone ever decides to not show this, and Utils::Course::new
                   9876:     # will need to be suitably modified.
1.541     raeburn  9877:     $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444     albertel 9878: #
                   9879: # Check if created correctly
                   9880: #
1.479     albertel 9881:     ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444     albertel 9882:     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541     raeburn  9883:     $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566     albertel 9884: 
1.444     albertel 9885: #
1.566     albertel 9886: # Do the cloning
                   9887: #   
                   9888:     if ($can_clone && $cloneid) {
                   9889: 	$clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
                   9890: 	if ($context ne 'auto') {
                   9891: 	    $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
                   9892: 	}
                   9893: 	$outcome .= $clonemsg.$linefeed;
                   9894: 	my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444     albertel 9895: # Copy all files
1.637     www      9896: 	&Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444     albertel 9897: # Restore URL
1.566     albertel 9898: 	$cenv{'url'}=$oldcenv{'url'};
1.444     albertel 9899: # Restore title
1.566     albertel 9900: 	$cenv{'description'}=$oldcenv{'description'};
1.444     albertel 9901: # Mark as cloned
1.566     albertel 9902: 	$cenv{'clonedfrom'}=$cloneid;
1.638     www      9903: # Need to clone grading mode
                   9904:         my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
                   9905:         $cenv{'grading'}=$newenv{'grading'};
                   9906: # Do not clone these environment entries
                   9907:         &Apache::lonnet::del('environment',
                   9908:                   ['default_enrollment_start_date',
                   9909:                    'default_enrollment_end_date',
                   9910:                    'question.email',
                   9911:                    'policy.email',
                   9912:                    'comment.email',
                   9913:                    'pch.users.denied',
1.725     raeburn  9914:                    'plc.users.denied',
                   9915:                    'hidefromcat',
                   9916:                    'categories'],
1.638     www      9917:                    $$crsudom,$$crsunum);
1.444     albertel 9918:     }
1.566     albertel 9919: 
1.444     albertel 9920: #
                   9921: # Set environment (will override cloned, if existing)
                   9922: #
                   9923:     my @sections = ();
                   9924:     my @xlists = ();
                   9925:     if ($args->{'crstype'}) {
                   9926:         $cenv{'type'}=$args->{'crstype'};
                   9927:     }
                   9928:     if ($args->{'crsid'}) {
                   9929:         $cenv{'courseid'}=$args->{'crsid'};
                   9930:     }
                   9931:     if ($args->{'crscode'}) {
                   9932:         $cenv{'internal.coursecode'}=$args->{'crscode'};
                   9933:     }
                   9934:     if ($args->{'crsquota'} ne '') {
                   9935:         $cenv{'internal.coursequota'}=$args->{'crsquota'};
                   9936:     } else {
                   9937:         $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
                   9938:     }
                   9939:     if ($args->{'ccuname'}) {
                   9940:         $cenv{'internal.courseowner'} = $args->{'ccuname'}.
                   9941:                                         ':'.$args->{'ccdomain'};
                   9942:     } else {
                   9943:         $cenv{'internal.courseowner'} = $args->{'curruser'};
                   9944:     }
                   9945:     my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
                   9946:     if ($args->{'crssections'}) {
                   9947:         $cenv{'internal.sectionnums'} = '';
                   9948:         if ($args->{'crssections'} =~ m/,/) {
                   9949:             @sections = split/,/,$args->{'crssections'};
                   9950:         } else {
                   9951:             $sections[0] = $args->{'crssections'};
                   9952:         }
                   9953:         if (@sections > 0) {
                   9954:             foreach my $item (@sections) {
                   9955:                 my ($sec,$gp) = split/:/,$item;
                   9956:                 my $class = $args->{'crscode'}.$sec;
                   9957:                 my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
                   9958:                 $cenv{'internal.sectionnums'} .= $item.',';
                   9959:                 unless ($addcheck eq 'ok') {
                   9960:                     push @badclasses, $class;
                   9961:                 }
                   9962:             }
                   9963:             $cenv{'internal.sectionnums'} =~ s/,$//;
                   9964:         }
                   9965:     }
                   9966: # do not hide course coordinator from staff listing, 
                   9967: # even if privileged
                   9968:     $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   9969: # add crosslistings
                   9970:     if ($args->{'crsxlist'}) {
                   9971:         $cenv{'internal.crosslistings'}='';
                   9972:         if ($args->{'crsxlist'} =~ m/,/) {
                   9973:             @xlists = split/,/,$args->{'crsxlist'};
                   9974:         } else {
                   9975:             $xlists[0] = $args->{'crsxlist'};
                   9976:         }
                   9977:         if (@xlists > 0) {
                   9978:             foreach my $item (@xlists) {
                   9979:                 my ($xl,$gp) = split/:/,$item;
                   9980:                 my $addcheck =  &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
                   9981:                 $cenv{'internal.crosslistings'} .= $item.',';
                   9982:                 unless ($addcheck eq 'ok') {
                   9983:                     push @badclasses, $xl;
                   9984:                 }
                   9985:             }
                   9986:             $cenv{'internal.crosslistings'} =~ s/,$//;
                   9987:         }
                   9988:     }
                   9989:     if ($args->{'autoadds'}) {
                   9990:         $cenv{'internal.autoadds'}=$args->{'autoadds'};
                   9991:     }
                   9992:     if ($args->{'autodrops'}) {
                   9993:         $cenv{'internal.autodrops'}=$args->{'autodrops'};
                   9994:     }
                   9995: # check for notification of enrollment changes
                   9996:     my @notified = ();
                   9997:     if ($args->{'notify_owner'}) {
                   9998:         if ($args->{'ccuname'} ne '') {
                   9999:             push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
                   10000:         }
                   10001:     }
                   10002:     if ($args->{'notify_dc'}) {
                   10003:         if ($uname ne '') { 
1.630     raeburn  10004:             push(@notified,$uname.':'.$udom);
1.444     albertel 10005:         }
                   10006:     }
                   10007:     if (@notified > 0) {
                   10008:         my $notifylist;
                   10009:         if (@notified > 1) {
                   10010:             $notifylist = join(',',@notified);
                   10011:         } else {
                   10012:             $notifylist = $notified[0];
                   10013:         }
                   10014:         $cenv{'internal.notifylist'} = $notifylist;
                   10015:     }
                   10016:     if (@badclasses > 0) {
                   10017:         my %lt=&Apache::lonlocal::texthash(
                   10018:                 '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',
                   10019:                 'dnhr' => 'does not have rights to access enrollment in these classes',
                   10020:                 'adby' => 'as determined by the policies of your institution on access to official classlists'
                   10021:         );
1.541     raeburn  10022:         my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
                   10023:                            ' ('.$lt{'adby'}.')';
                   10024:         if ($context eq 'auto') {
                   10025:             $outcome .= $badclass_msg.$linefeed;
1.566     albertel 10026:             $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541     raeburn  10027:             foreach my $item (@badclasses) {
                   10028:                 if ($context eq 'auto') {
                   10029:                     $outcome .= " - $item\n";
                   10030:                 } else {
                   10031:                     $outcome .= "<li>$item</li>\n";
                   10032:                 }
                   10033:             }
                   10034:             if ($context eq 'auto') {
                   10035:                 $outcome .= $linefeed;
                   10036:             } else {
1.566     albertel 10037:                 $outcome .= "</ul><br /><br /></div>\n";
1.541     raeburn  10038:             }
                   10039:         } 
1.444     albertel 10040:     }
                   10041:     if ($args->{'no_end_date'}) {
                   10042:         $args->{'endaccess'} = 0;
                   10043:     }
                   10044:     $cenv{'internal.autostart'}=$args->{'enrollstart'};
                   10045:     $cenv{'internal.autoend'}=$args->{'enrollend'};
                   10046:     $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
                   10047:     $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
                   10048:     if ($args->{'showphotos'}) {
                   10049:       $cenv{'internal.showphotos'}=$args->{'showphotos'};
                   10050:     }
                   10051:     $cenv{'internal.authtype'} = $args->{'authtype'};
                   10052:     $cenv{'internal.autharg'} = $args->{'autharg'}; 
                   10053:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
                   10054:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
1.541     raeburn  10055:             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'); 
                   10056:             if ($context eq 'auto') {
                   10057:                 $outcome .= $krb_msg;
                   10058:             } else {
1.566     albertel 10059:                 $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541     raeburn  10060:             }
                   10061:             $outcome .= $linefeed;
1.444     albertel 10062:         }
                   10063:     }
                   10064:     if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
                   10065:        if ($args->{'setpolicy'}) {
                   10066:            $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   10067:        }
                   10068:        if ($args->{'setcontent'}) {
                   10069:            $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   10070:        }
                   10071:     }
                   10072:     if ($args->{'reshome'}) {
                   10073: 	$cenv{'reshome'}=$args->{'reshome'}.'/';
                   10074: 	$cenv{'reshome'}=~s/\/+$/\//;
                   10075:     }
                   10076: #
                   10077: # course has keyed access
                   10078: #
                   10079:     if ($args->{'setkeys'}) {
                   10080:        $cenv{'keyaccess'}='yes';
                   10081:     }
                   10082: # if specified, key authority is not course, but user
                   10083: # only active if keyaccess is yes
                   10084:     if ($args->{'keyauth'}) {
1.487     albertel 10085: 	my ($user,$domain) = split(':',$args->{'keyauth'});
                   10086: 	$user = &LONCAPA::clean_username($user);
                   10087: 	$domain = &LONCAPA::clean_username($domain);
1.488     foxr     10088: 	if ($user ne '' && $domain ne '') {
1.487     albertel 10089: 	    $cenv{'keyauth'}=$user.':'.$domain;
1.444     albertel 10090: 	}
                   10091:     }
                   10092: 
                   10093:     if ($args->{'disresdis'}) {
                   10094:         $cenv{'pch.roles.denied'}='st';
                   10095:     }
                   10096:     if ($args->{'disablechat'}) {
                   10097:         $cenv{'plc.roles.denied'}='st';
                   10098:     }
                   10099: 
                   10100:     # Record we've not yet viewed the Course Initialization Helper for this 
                   10101:     # course
                   10102:     $cenv{'course.helper.not.run'} = 1;
                   10103:     #
                   10104:     # Use new Randomseed
                   10105:     #
                   10106:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
                   10107:     $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
                   10108:     #
                   10109:     # The encryption code and receipt prefix for this course
                   10110:     #
                   10111:     $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
                   10112:     $cenv{'internal.encpref'}=100+int(9*rand(99));
                   10113:     #
                   10114:     # By default, use standard grading
                   10115:     if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
                   10116: 
1.541     raeburn  10117:     $outcome .= $linefeed.&mt('Setting environment').': '.                 
                   10118:           &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 10119: #
                   10120: # Open all assignments
                   10121: #
                   10122:     if ($args->{'openall'}) {
                   10123:        my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
                   10124:        my %storecontent = ($storeunder         => time,
                   10125:                            $storeunder.'.type' => 'date_start');
                   10126:        
                   10127:        $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541     raeburn  10128:                  ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 10129:    }
                   10130: #
                   10131: # Set first page
                   10132: #
                   10133:     unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
                   10134: 	    || ($cloneid)) {
1.445     albertel 10135: 	use LONCAPA::map;
1.444     albertel 10136: 	$outcome .= &mt('Setting first resource').': ';
1.445     albertel 10137: 
                   10138: 	my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
                   10139:         my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
                   10140: 
1.444     albertel 10141:         $outcome .= ($fatal?$errtext:'read ok').' - ';
                   10142:         my $title; my $url;
                   10143:         if ($args->{'firstres'} eq 'syl') {
1.690     bisitz   10144: 	    $title=&mt('Syllabus');
1.444     albertel 10145:             $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
                   10146:         } else {
1.690     bisitz   10147:             $title=&mt('Navigate Contents');
1.444     albertel 10148:             $url='/adm/navmaps';
                   10149:         }
1.445     albertel 10150: 
                   10151:         $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
                   10152: 	(my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
                   10153: 
                   10154: 	if ($errtext) { $fatal=2; }
1.541     raeburn  10155:         $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444     albertel 10156:     }
1.566     albertel 10157: 
                   10158:     return (1,$outcome);
1.444     albertel 10159: }
                   10160: 
                   10161: ############################################################
                   10162: ############################################################
                   10163: 
1.378     raeburn  10164: sub course_type {
                   10165:     my ($cid) = @_;
                   10166:     if (!defined($cid)) {
                   10167:         $cid = $env{'request.course.id'};
                   10168:     }
1.404     albertel 10169:     if (defined($env{'course.'.$cid.'.type'})) {
                   10170:         return $env{'course.'.$cid.'.type'};
1.378     raeburn  10171:     } else {
                   10172:         return 'Course';
1.377     raeburn  10173:     }
                   10174: }
1.156     albertel 10175: 
1.406     raeburn  10176: sub group_term {
                   10177:     my $crstype = &course_type();
                   10178:     my %names = (
                   10179:                   'Course' => 'group',
                   10180:                   'Group' => 'team',
                   10181:                 );
                   10182:     return $names{$crstype};
                   10183: }
                   10184: 
1.156     albertel 10185: sub icon {
                   10186:     my ($file)=@_;
1.505     albertel 10187:     my $curfext = lc((split(/\./,$file))[-1]);
1.168     albertel 10188:     my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156     albertel 10189:     my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168     albertel 10190:     if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
                   10191: 	if (-e  $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
                   10192: 	          $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   10193: 	            $curfext.".gif") {
                   10194: 	    $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   10195: 		$curfext.".gif";
                   10196: 	}
                   10197:     }
1.249     albertel 10198:     return &lonhttpdurl($iconname);
1.154     albertel 10199: } 
1.84      albertel 10200: 
1.575     albertel 10201: sub lonhttpdurl {
1.692     www      10202: #
                   10203: # Had been used for "small fry" static images on separate port 8080.
                   10204: # Modify here if lightweight http functionality desired again.
                   10205: # Currently eliminated due to increasing firewall issues.
                   10206: #
1.575     albertel 10207:     my ($url)=@_;
1.692     www      10208:     return $url;
1.215     albertel 10209: }
                   10210: 
1.213     albertel 10211: sub connection_aborted {
                   10212:     my ($r)=@_;
                   10213:     $r->print(" ");$r->rflush();
                   10214:     my $c = $r->connection;
                   10215:     return $c->aborted();
                   10216: }
                   10217: 
1.221     foxr     10218: #    Escapes strings that may have embedded 's that will be put into
1.222     foxr     10219: #    strings as 'strings'.
                   10220: sub escape_single {
1.221     foxr     10221:     my ($input) = @_;
1.223     albertel 10222:     $input =~ s/\\/\\\\/g;	# Escape the \'s..(must be first)>
1.221     foxr     10223:     $input =~ s/\'/\\\'/g;	# Esacpe the 's....
                   10224:     return $input;
                   10225: }
1.223     albertel 10226: 
1.222     foxr     10227: #  Same as escape_single, but escape's "'s  This 
                   10228: #  can be used for  "strings"
                   10229: sub escape_double {
                   10230:     my ($input) = @_;
                   10231:     $input =~ s/\\/\\\\/g;	# Escape the /'s..(must be first)>
                   10232:     $input =~ s/\"/\\\"/g;	# Esacpe the "s....
                   10233:     return $input;
                   10234: }
1.223     albertel 10235:  
1.222     foxr     10236: #   Escapes the last element of a full URL.
                   10237: sub escape_url {
                   10238:     my ($url)   = @_;
1.238     raeburn  10239:     my @urlslices = split(/\//, $url,-1);
1.369     www      10240:     my $lastitem = &escape(pop(@urlslices));
1.223     albertel 10241:     return join('/',@urlslices).'/'.$lastitem;
1.222     foxr     10242: }
1.462     albertel 10243: 
                   10244: # -------------------------------------------------------- Initliaze user login
                   10245: sub init_user_environment {
1.463     albertel 10246:     my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462     albertel 10247:     my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
                   10248: 
                   10249:     my $public=($username eq 'public' && $domain eq 'public');
                   10250: 
                   10251: # See if old ID present, if so, remove
                   10252: 
                   10253:     my ($filename,$cookie,$userroles);
                   10254:     my $now=time;
                   10255: 
                   10256:     if ($public) {
                   10257: 	my $max_public=100;
                   10258: 	my $oldest;
                   10259: 	my $oldest_time=0;
                   10260: 	for(my $next=1;$next<=$max_public;$next++) {
                   10261: 	    if (-e $lonids."/publicuser_$next.id") {
                   10262: 		my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
                   10263: 		if ($mtime<$oldest_time || !$oldest_time) {
                   10264: 		    $oldest_time=$mtime;
                   10265: 		    $oldest=$next;
                   10266: 		}
                   10267: 	    } else {
                   10268: 		$cookie="publicuser_$next";
                   10269: 		last;
                   10270: 	    }
                   10271: 	}
                   10272: 	if (!$cookie) { $cookie="publicuser_$oldest"; }
                   10273:     } else {
1.463     albertel 10274: 	# if this isn't a robot, kill any existing non-robot sessions
                   10275: 	if (!$args->{'robot'}) {
                   10276: 	    opendir(DIR,$lonids);
                   10277: 	    while ($filename=readdir(DIR)) {
                   10278: 		if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
                   10279: 		    unlink($lonids.'/'.$filename);
                   10280: 		}
1.462     albertel 10281: 	    }
1.463     albertel 10282: 	    closedir(DIR);
1.462     albertel 10283: 	}
                   10284: # Give them a new cookie
1.463     albertel 10285: 	my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684     www      10286: 		                   : $now.$$.int(rand(10000)));
1.463     albertel 10287: 	$cookie="$username\_$id\_$domain\_$authhost";
1.462     albertel 10288:     
                   10289: # Initialize roles
                   10290: 
                   10291: 	$userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
                   10292:     }
                   10293: # ------------------------------------ Check browser type and MathML capability
                   10294: 
                   10295:     my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   10296:         $clientunicode,$clientos) = &decode_user_agent($r);
                   10297: 
                   10298: # -------------------------------------- Any accessibility options to remember?
                   10299:     if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
                   10300: 	foreach my $option ('imagesuppress','appletsuppress',
                   10301: 			    'embedsuppress','fontenhance','blackwhite') {
                   10302: 	    if ($form->{$option} eq 'true') {
                   10303: 		&Apache::lonnet::put('environment',{$option => 'on'},
                   10304: 				     $domain,$username);
                   10305: 	    } else {
                   10306: 		&Apache::lonnet::del('environment',[$option],
                   10307: 				     $domain,$username);
                   10308: 	    }
                   10309: 	}
                   10310:     }
                   10311: # ------------------------------------------------------------- Get environment
                   10312: 
                   10313:     my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
                   10314:     my ($tmp) = keys(%userenv);
                   10315:     if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   10316: 	# default remote control to off
                   10317: 	if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
                   10318:     } else {
                   10319: 	undef(%userenv);
                   10320:     }
                   10321:     if (($userenv{'interface'}) && (!$form->{'interface'})) {
                   10322: 	$form->{'interface'}=$userenv{'interface'};
                   10323:     }
                   10324:     $env{'environment.remote'}=$userenv{'remote'};
                   10325:     if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
                   10326: 
                   10327: # --------------- Do not trust query string to be put directly into environment
                   10328:     foreach my $option ('imagesuppress','appletsuppress',
                   10329: 			'embedsuppress','fontenhance','blackwhite',
                   10330: 			'interface','localpath','localres') {
                   10331: 	$form->{$option}=~s/[\n\r\=]//gs;
                   10332:     }
                   10333: # --------------------------------------------------------- Write first profile
                   10334: 
                   10335:     {
                   10336: 	my %initial_env = 
                   10337: 	    ("user.name"          => $username,
                   10338: 	     "user.domain"        => $domain,
                   10339: 	     "user.home"          => $authhost,
                   10340: 	     "browser.type"       => $clientbrowser,
                   10341: 	     "browser.version"    => $clientversion,
                   10342: 	     "browser.mathml"     => $clientmathml,
                   10343: 	     "browser.unicode"    => $clientunicode,
                   10344: 	     "browser.os"         => $clientos,
                   10345: 	     "server.domain"      => $Apache::lonnet::perlvar{'lonDefDomain'},
                   10346: 	     "request.course.fn"  => '',
                   10347: 	     "request.course.uri" => '',
                   10348: 	     "request.course.sec" => '',
                   10349: 	     "request.role"       => 'cm',
                   10350: 	     "request.role.adv"   => $env{'user.adv'},
                   10351: 	     "request.host"       => $ENV{'REMOTE_ADDR'},);
                   10352: 
                   10353:         if ($form->{'localpath'}) {
                   10354: 	    $initial_env{"browser.localpath"}  = $form->{'localpath'};
                   10355: 	    $initial_env{"browser.localres"}   = $form->{'localres'};
                   10356:         }
                   10357: 	
                   10358: 	if ($public) {
                   10359: 	    $initial_env{"environment.remote"} = "off";
                   10360: 	}
                   10361: 	if ($form->{'interface'}) {
                   10362: 	    $form->{'interface'}=~s/\W//gs;
                   10363: 	    $initial_env{"browser.interface"} = $form->{'interface'};
                   10364: 	    $env{'browser.interface'}=$form->{'interface'};
                   10365: 	    foreach my $option ('imagesuppress','appletsuppress',
                   10366: 				'embedsuppress','fontenhance','blackwhite') {
                   10367: 		if (($form->{$option} eq 'true') ||
                   10368: 		    ($userenv{$option} eq 'on')) {
                   10369: 		    $initial_env{"browser.$option"} = "on";
                   10370: 		}
                   10371: 	    }
                   10372: 	}
                   10373: 
1.724     raeburn  10374:         foreach my $tool ('aboutme','blog','portfolio') {
                   10375:             $userenv{'availabletools.'.$tool} = 
                   10376:                 &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
                   10377:         }
                   10378: 
1.765     raeburn  10379:         foreach my $crstype ('official','unofficial') {
                   10380:             $userenv{'canrequest.'.$crstype} =
                   10381:                 &Apache::lonnet::usertools_access($username,$domain,$crstype,
                   10382:                                                   'reload','requestcourses');
                   10383:         }
                   10384: 
1.462     albertel 10385: 	$env{'user.environment'} = "$lonids/$cookie.id";
                   10386: 	
                   10387: 	if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
                   10388: 		 &GDBM_WRCREAT(),0640)) {
                   10389: 	    &_add_to_env(\%disk_env,\%initial_env);
                   10390: 	    &_add_to_env(\%disk_env,\%userenv,'environment.');
                   10391: 	    &_add_to_env(\%disk_env,$userroles);
1.463     albertel 10392: 	    if (ref($args->{'extra_env'})) {
                   10393: 		&_add_to_env(\%disk_env,$args->{'extra_env'});
                   10394: 	    }
1.462     albertel 10395: 	    untie(%disk_env);
                   10396: 	} else {
1.705     tempelho 10397: 	    &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
                   10398: 			   'Could not create environment storage in lonauth: '.$!.'</span>');
1.462     albertel 10399: 	    return 'error: '.$!;
                   10400: 	}
                   10401:     }
                   10402:     $env{'request.role'}='cm';
                   10403:     $env{'request.role.adv'}=$env{'user.adv'};
                   10404:     $env{'browser.type'}=$clientbrowser;
                   10405: 
                   10406:     return $cookie;
                   10407: 
                   10408: }
                   10409: 
                   10410: sub _add_to_env {
                   10411:     my ($idf,$env_data,$prefix) = @_;
1.676     raeburn  10412:     if (ref($env_data) eq 'HASH') {
                   10413:         while (my ($key,$value) = each(%$env_data)) {
                   10414: 	    $idf->{$prefix.$key} = $value;
                   10415: 	    $env{$prefix.$key}   = $value;
                   10416:         }
1.462     albertel 10417:     }
                   10418: }
                   10419: 
1.685     tempelho 10420: # --- Get the symbolic name of a problem and the url
                   10421: sub get_symb {
                   10422:     my ($request,$silent) = @_;
1.726     raeburn  10423:     (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685     tempelho 10424:     my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
                   10425:     if ($symb eq '') {
                   10426:         if (!$silent) {
                   10427:             $request->print("Unable to handle ambiguous references:$url:.");
                   10428:             return ();
                   10429:         }
                   10430:     }
                   10431:     &Apache::lonenc::check_decrypt(\$symb);
                   10432:     return ($symb);
                   10433: }
                   10434: 
                   10435: # --------------------------------------------------------------Get annotation
                   10436: 
                   10437: sub get_annotation {
                   10438:     my ($symb,$enc) = @_;
                   10439: 
                   10440:     my $key = $symb;
                   10441:     if (!$enc) {
                   10442:         $key =
                   10443:             &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
                   10444:     }
                   10445:     my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
                   10446:     return $annotation{$key};
                   10447: }
                   10448: 
                   10449: sub clean_symb {
1.731     raeburn  10450:     my ($symb,$delete_enc) = @_;
1.685     tempelho 10451: 
                   10452:     &Apache::lonenc::check_decrypt(\$symb);
                   10453:     my $enc = $env{'request.enc'};
1.731     raeburn  10454:     if ($delete_enc) {
1.730     raeburn  10455:         delete($env{'request.enc'});
                   10456:     }
1.685     tempelho 10457: 
                   10458:     return ($symb,$enc);
                   10459: }
1.462     albertel 10460: 
1.41      ng       10461: =pod
                   10462: 
                   10463: =back
                   10464: 
1.112     bowersj2 10465: =cut
1.41      ng       10466: 
1.112     bowersj2 10467: 1;
                   10468: __END__;
1.41      ng       10469: 

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