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

1.10      albertel    1: # The LearningOnline Network with CAPA
1.1       albertel    2: # a pile of common routines
1.10      albertel    3: #
1.880   ! raeburn     4: # $Id: loncommon.pm,v 1.879 2009/08/05 23:44:52 raeburn Exp $
1.10      albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
1.1       albertel   28: 
                     29: # Makes a table out of the previous attempts
1.2       albertel   30: # Inputs result_from_symbread, user, domain, course_id
1.16      harris41   31: # Reads in non-network-related .tab files
1.1       albertel   32: 
1.35      matthew    33: # POD header:
                     34: 
1.45      matthew    35: =pod
                     36: 
1.35      matthew    37: =head1 NAME
                     38: 
                     39: Apache::loncommon - pile of common routines
                     40: 
                     41: =head1 SYNOPSIS
                     42: 
1.112     bowersj2   43: Common routines for manipulating connections, student answers,
                     44:     domains, common Javascript fragments, etc.
1.35      matthew    45: 
1.112     bowersj2   46: =head1 OVERVIEW
1.35      matthew    47: 
1.112     bowersj2   48: A collection of commonly used subroutines that don't have a natural
                     49: home anywhere else. This collection helps remove
1.35      matthew    50: redundancy from other modules and increase efficiency of memory usage.
                     51: 
                     52: =cut 
                     53: 
                     54: # End of POD header
1.1       albertel   55: package Apache::loncommon;
                     56: 
                     57: use strict;
1.258     albertel   58: use Apache::lonnet;
1.46      matthew    59: use GDBM_File;
1.51      www        60: use POSIX qw(strftime mktime);
1.82      www        61: use Apache::lonmenu();
1.498     albertel   62: use Apache::lonenc();
1.117     www        63: use Apache::lonlocal;
1.685     tempelho   64: use Apache::lonnet();
1.139     matthew    65: use HTML::Entities;
1.334     albertel   66: use Apache::lonhtmlcommon();
                     67: use Apache::loncoursedata();
1.344     albertel   68: use Apache::lontexconvert();
1.444     albertel   69: use Apache::lonclonecourse();
1.479     albertel   70: use LONCAPA qw(:DEFAULT :match);
1.657     raeburn    71: use DateTime::TimeZone;
1.687     raeburn    72: use DateTime::Locale::Catalog;
1.117     www        73: 
1.517     raeburn    74: # ---------------------------------------------- Designs
                     75: use vars qw(%defaultdesign);
                     76: 
1.22      www        77: my $readit;
                     78: 
1.517     raeburn    79: 
1.157     matthew    80: ##
                     81: ## Global Variables
                     82: ##
1.46      matthew    83: 
1.643     foxr       84: 
                     85: # ----------------------------------------------- SSI with retries:
                     86: #
                     87: 
                     88: =pod
                     89: 
1.648     raeburn    90: =head1 Server Side include with retries:
1.643     foxr       91: 
                     92: =over 4
                     93: 
1.648     raeburn    94: =item * &ssi_with_retries(resource,retries form)
1.643     foxr       95: 
                     96: Performs an ssi with some number of retries.  Retries continue either
                     97: until the result is ok or until the retry count supplied by the
                     98: caller is exhausted.  
                     99: 
                    100: Inputs:
1.648     raeburn   101: 
                    102: =over 4
                    103: 
1.643     foxr      104: resource   - Identifies the resource to insert.
1.648     raeburn   105: 
1.643     foxr      106: retries    - Count of the number of retries allowed.
1.648     raeburn   107: 
1.643     foxr      108: form       - Hash that identifies the rendering options.
                    109: 
1.648     raeburn   110: =back
                    111: 
                    112: Returns:
                    113: 
                    114: =over 4
                    115: 
1.643     foxr      116: content    - The content of the response.  If retries were exhausted this is empty.
1.648     raeburn   117: 
1.643     foxr      118: response   - The response from the last attempt (which may or may not have been successful.
                    119: 
1.648     raeburn   120: =back
                    121: 
                    122: =back
                    123: 
1.643     foxr      124: =cut
                    125: 
                    126: sub ssi_with_retries {
                    127:     my ($resource, $retries, %form) = @_;
                    128: 
                    129: 
                    130:     my $ok = 0;			# True if we got a good response.
                    131:     my $content;
                    132:     my $response;
                    133: 
                    134:     # Try to get the ssi done. within the retries count:
                    135: 
                    136:     do {
                    137: 	($content, $response) = &Apache::lonnet::ssi($resource, %form);
                    138: 	$ok      = $response->is_success;
1.650     www       139:         if (!$ok) {
                    140:             &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
                    141:         }
1.643     foxr      142: 	$retries--;
                    143:     } while (!$ok && ($retries > 0));
                    144: 
                    145:     if (!$ok) {
                    146: 	$content = '';		# On error return an empty content.
                    147:     }
                    148:     return ($content, $response);
                    149: 
                    150: }
                    151: 
                    152: 
                    153: 
1.20      www       154: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12      harris41  155: my %language;
1.124     www       156: my %supported_language;
1.12      harris41  157: my %cprtag;
1.192     taceyjo1  158: my %scprtag;
1.351     www       159: my %fe; my %fd; my %fm;
1.41      ng        160: my %category_extensions;
1.12      harris41  161: 
1.46      matthew   162: # ---------------------------------------------- Thesaurus variables
1.144     matthew   163: #
                    164: # %Keywords:
                    165: #      A hash used by &keyword to determine if a word is considered a keyword.
                    166: # $thesaurus_db_file 
                    167: #      Scalar containing the full path to the thesaurus database.
1.46      matthew   168: 
                    169: my %Keywords;
                    170: my $thesaurus_db_file;
                    171: 
1.144     matthew   172: #
                    173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
                    174: # thesaurus.tab, and filecategories.tab.
                    175: #
1.18      www       176: BEGIN {
1.46      matthew   177:     # Variable initialization
                    178:     $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
                    179:     #
1.22      www       180:     unless ($readit) {
1.12      harris41  181: # ------------------------------------------------------------------- languages
                    182:     {
1.158     raeburn   183:         my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    184:                                    '/language.tab';
                    185:         if ( open(my $fh,"<$langtabfile") ) {
1.356     albertel  186:             while (my $line = <$fh>) {
                    187:                 next if ($line=~/^\#/);
                    188:                 chomp($line);
                    189:                 my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158     raeburn   190:                 $language{$key}=$val.' - '.$enc;
                    191:                 if ($sup) {
                    192:                     $supported_language{$key}=$sup;
                    193:                 }
                    194:             }
                    195:             close($fh);
                    196:         }
1.12      harris41  197:     }
                    198: # ------------------------------------------------------------------ copyrights
                    199:     {
1.158     raeburn   200:         my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
                    201:                                   '/copyright.tab';
                    202:         if ( open (my $fh,"<$copyrightfile") ) {
1.356     albertel  203:             while (my $line = <$fh>) {
                    204:                 next if ($line=~/^\#/);
                    205:                 chomp($line);
                    206:                 my ($key,$val)=(split(/\s+/,$line,2));
1.158     raeburn   207:                 $cprtag{$key}=$val;
                    208:             }
                    209:             close($fh);
                    210:         }
1.12      harris41  211:     }
1.351     www       212: # ----------------------------------------------------------- source copyrights
1.192     taceyjo1  213:     {
                    214:         my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
                    215:                                   '/source_copyright.tab';
                    216:         if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356     albertel  217:             while (my $line = <$fh>) {
                    218:                 next if ($line =~ /^\#/);
                    219:                 chomp($line);
                    220:                 my ($key,$val)=(split(/\s+/,$line,2));
1.192     taceyjo1  221:                 $scprtag{$key}=$val;
                    222:             }
                    223:             close($fh);
                    224:         }
                    225:     }
1.63      www       226: 
1.517     raeburn   227: # -------------------------------------------------------------- default domain designs
1.63      www       228:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517     raeburn   229:     my $designfile = $designdir.'/default.tab';
                    230:     if ( open (my $fh,"<$designfile") ) {
                    231:         while (my $line = <$fh>) {
                    232:             next if ($line =~ /^\#/);
                    233:             chomp($line);
                    234:             my ($key,$val)=(split(/\=/,$line));
                    235:             if ($val) { $defaultdesign{$key}=$val; }
                    236:         }
                    237:         close($fh);
1.63      www       238:     }
                    239: 
1.15      harris41  240: # ------------------------------------------------------------- file categories
                    241:     {
1.158     raeburn   242:         my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    243:                                   '/filecategories.tab';
                    244:         if ( open (my $fh,"<$categoryfile") ) {
1.356     albertel  245: 	    while (my $line = <$fh>) {
                    246: 		next if ($line =~ /^\#/);
                    247: 		chomp($line);
                    248:                 my ($extension,$category)=(split(/\s+/,$line,2));
1.158     raeburn   249:                 push @{$category_extensions{lc($category)}},$extension;
                    250:             }
                    251:             close($fh);
                    252:         }
                    253: 
1.15      harris41  254:     }
1.12      harris41  255: # ------------------------------------------------------------------ file types
                    256:     {
1.158     raeburn   257:         my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    258:                '/filetypes.tab';
                    259:         if ( open (my $fh,"<$typesfile") ) {
1.356     albertel  260:             while (my $line = <$fh>) {
                    261: 		next if ($line =~ /^\#/);
                    262: 		chomp($line);
                    263:                 my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158     raeburn   264:                 if ($descr ne '') {
                    265:                     $fe{$ending}=lc($emb);
                    266:                     $fd{$ending}=$descr;
1.351     www       267:                     if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158     raeburn   268:                 }
                    269:             }
                    270:             close($fh);
                    271:         }
1.12      harris41  272:     }
1.22      www       273:     &Apache::lonnet::logthis(
1.705     tempelho  274:              "<span style='color:yellow;'>INFO: Read file types</span>");
1.22      www       275:     $readit=1;
1.46      matthew   276:     }  # end of unless($readit) 
1.32      matthew   277:     
                    278: }
1.112     bowersj2  279: 
1.42      matthew   280: ###############################################################
                    281: ##           HTML and Javascript Helper Functions            ##
                    282: ###############################################################
                    283: 
                    284: =pod 
                    285: 
1.112     bowersj2  286: =head1 HTML and Javascript Functions
1.42      matthew   287: 
1.112     bowersj2  288: =over 4
                    289: 
1.648     raeburn   290: =item * &browser_and_searcher_javascript()
1.112     bowersj2  291: 
                    292: X<browsing, javascript>X<searching, javascript>Returns a string
                    293: containing javascript with two functions, C<openbrowser> and
                    294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
                    295: tags.
1.42      matthew   296: 
1.648     raeburn   297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42      matthew   298: 
                    299: inputs: formname, elementname, only, omit
                    300: 
                    301: formname and elementname indicate the name of the html form and name of
                    302: the element that the results of the browsing selection are to be placed in. 
                    303: 
                    304: Specifying 'only' will restrict the browser to displaying only files
1.185     www       305: with the given extension.  Can be a comma separated list.
1.42      matthew   306: 
                    307: Specifying 'omit' will restrict the browser to NOT displaying files
1.185     www       308: with the given extension.  Can be a comma separated list.
1.42      matthew   309: 
1.648     raeburn   310: =item * &opensearcher(formname,elementname) [javascript]
1.42      matthew   311: 
                    312: Inputs: formname, elementname
                    313: 
                    314: formname and elementname specify the name of the html form and the name
                    315: of the element the selection from the search results will be placed in.
1.542     raeburn   316: 
1.42      matthew   317: =cut
                    318: 
                    319: sub browser_and_searcher_javascript {
1.199     albertel  320:     my ($mode)=@_;
                    321:     if (!defined($mode)) { $mode='edit'; }
1.453     albertel  322:     my $resurl=&escape_single(&lastresurl());
1.42      matthew   323:     return <<END;
1.219     albertel  324: // <!-- BEGIN LON-CAPA Internal
1.50      matthew   325:     var editbrowser = null;
1.135     albertel  326:     function openbrowser(formname,elementname,only,omit,titleelement) {
1.170     www       327:         var url = '$resurl/?';
1.42      matthew   328:         if (editbrowser == null) {
                    329:             url += 'launch=1&';
                    330:         }
                    331:         url += 'catalogmode=interactive&';
1.199     albertel  332:         url += 'mode=$mode&';
1.611     albertel  333:         url += 'inhibitmenu=yes&';
1.42      matthew   334:         url += 'form=' + formname + '&';
                    335:         if (only != null) {
                    336:             url += 'only=' + only + '&';
1.217     albertel  337:         } else {
                    338:             url += 'only=&';
                    339: 	}
1.42      matthew   340:         if (omit != null) {
                    341:             url += 'omit=' + omit + '&';
1.217     albertel  342:         } else {
                    343:             url += 'omit=&';
                    344: 	}
1.135     albertel  345:         if (titleelement != null) {
                    346:             url += 'titleelement=' + titleelement + '&';
1.217     albertel  347:         } else {
                    348: 	    url += 'titleelement=&';
                    349: 	}
1.42      matthew   350:         url += 'element=' + elementname + '';
                    351:         var title = 'Browser';
1.435     albertel  352:         var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42      matthew   353:         options += ',width=700,height=600';
                    354:         editbrowser = open(url,title,options,'1');
                    355:         editbrowser.focus();
                    356:     }
                    357:     var editsearcher;
1.135     albertel  358:     function opensearcher(formname,elementname,titleelement) {
1.42      matthew   359:         var url = '/adm/searchcat?';
                    360:         if (editsearcher == null) {
                    361:             url += 'launch=1&';
                    362:         }
                    363:         url += 'catalogmode=interactive&';
1.199     albertel  364:         url += 'mode=$mode&';
1.42      matthew   365:         url += 'form=' + formname + '&';
1.135     albertel  366:         if (titleelement != null) {
                    367:             url += 'titleelement=' + titleelement + '&';
1.217     albertel  368:         } else {
                    369: 	    url += 'titleelement=&';
                    370: 	}
1.42      matthew   371:         url += 'element=' + elementname + '';
                    372:         var title = 'Search';
1.435     albertel  373:         var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42      matthew   374:         options += ',width=700,height=600';
                    375:         editsearcher = open(url,title,options,'1');
                    376:         editsearcher.focus();
                    377:     }
1.219     albertel  378: // END LON-CAPA Internal -->
1.42      matthew   379: END
1.170     www       380: }
                    381: 
                    382: sub lastresurl {
1.258     albertel  383:     if ($env{'environment.lastresurl'}) {
                    384: 	return $env{'environment.lastresurl'}
1.170     www       385:     } else {
                    386: 	return '/res';
                    387:     }
                    388: }
                    389: 
                    390: sub storeresurl {
                    391:     my $resurl=&Apache::lonnet::clutter(shift);
                    392:     unless ($resurl=~/^\/res/) { return 0; }
                    393:     $resurl=~s/\/$//;
                    394:     &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646     raeburn   395:     &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170     www       396:     return 1;
1.42      matthew   397: }
                    398: 
1.74      www       399: sub studentbrowser_javascript {
1.111     www       400:    unless (
1.258     albertel  401:             (($env{'request.course.id'}) && 
1.302     albertel  402:              (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    403: 	      || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                    404: 					  '/'.$env{'request.course.sec'})
                    405: 	      ))
1.258     albertel  406:          || ($env{'request.role'}=~/^(au|dc|su)/)
1.111     www       407:           ) { return ''; }  
1.74      www       408:    return (<<'ENDSTDBRW');
1.776     bisitz    409: <script type="text/javascript" language="Javascript">
1.824     bisitz    410: // <![CDATA[
1.74      www       411:     var stdeditbrowser;
1.793     raeburn   412:     function openstdbrowser(formname,uname,udom,roleflag,ignorefilter,courseadvonly) {
1.74      www       413:         var url = '/adm/pickstudent?';
                    414:         var filter;
1.558     albertel  415: 	if (!ignorefilter) {
                    416: 	    eval('filter=document.'+formname+'.'+uname+'.value;');
                    417: 	}
1.74      www       418:         if (filter != null) {
                    419:            if (filter != '') {
                    420:                url += 'filter='+filter+'&';
                    421: 	   }
                    422:         }
                    423:         url += 'form=' + formname + '&unameelement='+uname+
                    424:                                     '&udomelement='+udom;
1.111     www       425: 	if (roleflag) { url+="&roles=1"; }
1.793     raeburn   426:         if (courseadvonly) { url+="&courseadvonly=1"; }
1.102     www       427:         var title = 'Student_Browser';
1.74      www       428:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    429:         options += ',width=700,height=600';
                    430:         stdeditbrowser = open(url,title,options,'1');
                    431:         stdeditbrowser.focus();
                    432:     }
1.824     bisitz    433: // ]]>
1.74      www       434: </script>
                    435: ENDSTDBRW
                    436: }
1.42      matthew   437: 
1.74      www       438: sub selectstudent_link {
1.793     raeburn   439:    my ($form,$unameele,$udomele,$courseadvonly)=@_;
                    440:    my $callargs = "'".$form."','".$unameele."','".$udomele."'";
1.258     albertel  441:    if ($env{'request.course.id'}) {  
1.302     albertel  442:        if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    443: 	   && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                    444: 					'/'.$env{'request.course.sec'})) {
1.111     www       445: 	   return '';
                    446:        }
1.793     raeburn   447:        if ($courseadvonly)  {
                    448:            $callargs .= ",'',1,1";
                    449:        }
                    450:        return '<span class="LC_nobreak">'.
                    451:               '<a href="javascript:openstdbrowser('.$callargs.');">'.
                    452:               &mt('Select User').'</a></span>';
1.74      www       453:    }
1.258     albertel  454:    if ($env{'request.role'}=~/^(au|dc|su)/) {
1.793     raeburn   455:        $callargs .= ",1"; 
                    456:        return '<span class="LC_nobreak">'.
                    457:               '<a href="javascript:openstdbrowser('.$callargs.');">'.
                    458:               &mt('Select User').'</a></span>';
1.111     www       459:    }
                    460:    return '';
1.91      www       461: }
                    462: 
1.653     raeburn   463: sub authorbrowser_javascript {
                    464:     return <<"ENDAUTHORBRW";
1.776     bisitz    465: <script type="text/javascript" language="JavaScript">
1.824     bisitz    466: // <![CDATA[
1.653     raeburn   467: var stdeditbrowser;
                    468: 
                    469: function openauthorbrowser(formname,udom) {
                    470:     var url = '/adm/pickauthor?';
                    471:     url += 'form='+formname+'&roledom='+udom;
                    472:     var title = 'Author_Browser';
                    473:     var options = 'scrollbars=1,resizable=1,menubar=0';
                    474:     options += ',width=700,height=600';
                    475:     stdeditbrowser = open(url,title,options,'1');
                    476:     stdeditbrowser.focus();
                    477: }
                    478: 
1.824     bisitz    479: // ]]>
1.653     raeburn   480: </script>
                    481: ENDAUTHORBRW
                    482: }
                    483: 
1.91      www       484: sub coursebrowser_javascript {
1.468     raeburn   485:     my ($domainfilter,$sec_element,$formname)=@_;
1.865     raeburn   486:     my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Community - for which you wish to add/modify a user role');
1.876     raeburn   487:     my $id_functions = &javascript_index_functions();
                    488:     my $output = '
1.776     bisitz    489: <script type="text/javascript" language="JavaScript">
1.824     bisitz    490: // <![CDATA[
1.468     raeburn   491:     var stdeditbrowser;'."\n";
1.876     raeburn   492: 
                    493:     $output .= <<"ENDSTDBRW";
1.377     raeburn   494:     function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
1.91      www       495:         var url = '/adm/pickcourse?';
1.876     raeburn   496:         var domainfilter = getDomainFromSelectbox(formname,udom);
1.128     albertel  497:         if (domainfilter != null) {
                    498:            if (domainfilter != '') {
                    499:                url += 'domainfilter='+domainfilter+'&';
                    500: 	   }
                    501:         }
1.91      www       502:         url += 'form=' + formname + '&cnumelement='+uname+
1.187     albertel  503: 	                            '&cdomelement='+udom+
                    504:                                     '&cnameelement='+desc;
1.468     raeburn   505:         if (extra_element !=null && extra_element != '') {
1.594     raeburn   506:             if (formname == 'rolechoice' || formname == 'studentform') {
1.468     raeburn   507:                 url += '&roleelement='+extra_element;
                    508:                 if (domainfilter == null || domainfilter == '') {
                    509:                     url += '&domainfilter='+extra_element;
                    510:                 }
1.234     raeburn   511:             }
1.468     raeburn   512:             else {
                    513:                 if (formname == 'portform') {
                    514:                     url += '&setroles='+extra_element;
1.800     raeburn   515:                 } else {
                    516:                     if (formname == 'rules') {
                    517:                         url += '&fixeddom='+extra_element; 
                    518:                     }
1.468     raeburn   519:                 }
                    520:             }     
1.230     raeburn   521:         }
1.872     raeburn   522:         if (formname == 'ccrs') {
                    523:             var ownername = document.forms[formid].ccuname.value;
                    524:             var ownerdom =  document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
                    525:             url += '&cloner='+ownername+':'+ownerdom;
                    526:         }
1.293     raeburn   527:         if (multflag !=null && multflag != '') {
                    528:             url += '&multiple='+multflag;
                    529:         }
1.865     raeburn   530:         if (crstype == 'Course/Community') {
1.377     raeburn   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.876     raeburn   548: $id_functions
                    549: ENDSTDBRW
                    550:     if ($sec_element ne '') {
                    551:         $output .= &setsec_javascript($sec_element,$formname);
                    552:     }
                    553:     $output .= '
                    554: // ]]>
                    555: </script>';
                    556:     return $output;
                    557: }
                    558: 
                    559: sub javascript_index_functions {
                    560:     return <<"ENDJS";
                    561: 
                    562: function getFormIdByName(formname) {
                    563:     for (var i=0;i<document.forms.length;i++) {
                    564:         if (document.forms[i].name == formname) {
                    565:             return i;
                    566:         }
                    567:     }
                    568:     return -1;
                    569: }
                    570: 
                    571: function getIndexByName(formid,item) {
                    572:     for (var i=0;i<document.forms[formid].elements.length;i++) {
                    573:         if (document.forms[formid].elements[i].name == item) {
                    574:             return i;
                    575:         }
                    576:     }
                    577:     return -1;
                    578: }
1.468     raeburn   579: 
1.876     raeburn   580: function getDomainFromSelectbox(formname,udom) {
                    581:     var userdom;
                    582:     var formid = getFormIdByName(formname);
                    583:     if (formid > -1) {
                    584:         var domid = getIndexByName(formid,udom);
                    585:         if (domid > -1) {
                    586:             if (document.forms[formid].elements[domid].type == 'select-one') {
                    587:                 userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
                    588:             }
                    589:             if (document.forms[formid].elements[domid].type == 'hidden') {
                    590:                 userdom=document.forms[formid].elements[domid].value;
1.468     raeburn   591:             }
                    592:         }
                    593:     }
1.876     raeburn   594:     return userdom;
                    595: }
                    596: 
                    597: ENDJS
1.468     raeburn   598: 
1.876     raeburn   599: }
                    600: 
                    601: sub userbrowser_javascript {
                    602:     my $id_functions = &javascript_index_functions();
                    603:     return <<"ENDUSERBRW";
                    604: 
                    605: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom) {
                    606:     var url = '/adm/pickuser?';
                    607:     var userdom = getDomainFromSelectbox(formname,udom);
                    608:     if (userdom != null) {
                    609:        if (userdom != '') {
                    610:            url += 'srchdom='+userdom+'&';
                    611:        }
                    612:     }
                    613:     url += 'form=' + formname + '&unameelement='+uname+
                    614:                                 '&udomelement='+udom+
                    615:                                 '&ulastelement='+ulast+
                    616:                                 '&ufirstelement='+ufirst+
                    617:                                 '&uemailelement='+uemail+
                    618:                                 '&hideudomelement='+hideudom;
                    619:     var title = 'User_Browser';
                    620:     var options = 'scrollbars=1,resizable=1,menubar=0';
                    621:     options += ',width=700,height=600';
                    622:     var stdeditbrowser = open(url,title,options,'1');
                    623:     stdeditbrowser.focus();
                    624: }
                    625: 
                    626: function fix_domain (formname,udom,origdom) {
                    627:     var formid = getFormIdByName(formname);
                    628:     if (formid > -1) {
                    629:         var domid = getIndexByName(formid,udom);
                    630:         var hidedomid = getIndexByName(formid,origdom);
                    631:         if (hidedomid > -1) {
                    632:             var fixeddom = document.forms[formid].elements[hidedomid].value;
                    633:             if (domid > -1) {
                    634:                 var slct = document.forms[formid].elements[domid];
                    635:                 if (slct.type == 'select-one') {
                    636:                     var i;
                    637:                     for (i=0;i<slct.length;i++) {
                    638:                         if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
                    639:                     }
                    640:                 }
                    641:                 if (slct.type == 'hidden') {
                    642:                     slct.value = fixeddom;
                    643:                 }
1.468     raeburn   644:             }
                    645:         }
                    646:     }
1.876     raeburn   647:     return;
                    648: }
                    649: 
                    650: $id_functions
                    651: ENDUSERBRW
1.468     raeburn   652: }
                    653: 
                    654: sub setsec_javascript {
                    655:     my ($sec_element,$formname) = @_;
                    656:     my $setsections = qq|
                    657: function setSect(sectionlist) {
1.629     raeburn   658:     var sectionsArray = new Array();
                    659:     if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
                    660:         sectionsArray = sectionlist.split(",");
                    661:     }
1.468     raeburn   662:     var numSections = sectionsArray.length;
                    663:     document.$formname.$sec_element.length = 0;
                    664:     if (numSections == 0) {
                    665:         document.$formname.$sec_element.multiple=false;
                    666:         document.$formname.$sec_element.size=1;
                    667:         document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
                    668:     } else {
                    669:         if (numSections == 1) {
                    670:             document.$formname.$sec_element.multiple=false;
                    671:             document.$formname.$sec_element.size=1;
                    672:             document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
                    673:             document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
                    674:             document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
                    675:         } else {
                    676:             for (var i=0; i<numSections; i++) {
                    677:                 document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
                    678:             }
                    679:             document.$formname.$sec_element.multiple=true
                    680:             if (numSections < 3) {
                    681:                 document.$formname.$sec_element.size=numSections;
                    682:             } else {
                    683:                 document.$formname.$sec_element.size=3;
                    684:             }
                    685:             document.$formname.$sec_element.options[0].selected = false
                    686:         }
                    687:     }
1.91      www       688: }
1.468     raeburn   689: |;
                    690:     return $setsections;
                    691: }
                    692: 
1.91      www       693: 
                    694: sub selectcourse_link {
1.377     raeburn   695:    my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.871     raeburn   696:    my $linktext = &mt('Select Course');
                    697:    if ($selecttype eq 'Community') {
                    698:        $linktext = &mt('Select Community'); 
                    699:    }
1.787     bisitz    700:    return '<span class="LC_nobreak">'
                    701:          ."<a href='"
                    702:          .'javascript:opencrsbrowser("'.$form.'","'.$unameele
                    703:          .'","'.$udomele.'","'.$desc.'","'.$extra_element
                    704:          .'","'.$multflag.'","'.$selecttype.'");'
1.871     raeburn   705:          ."'>".$linktext.'</a>'
1.787     bisitz    706:          .'</span>';
1.74      www       707: }
1.42      matthew   708: 
1.653     raeburn   709: sub selectauthor_link {
                    710:    my ($form,$udom)=@_;
                    711:    return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
                    712:           &mt('Select Author').'</a>';
                    713: }
                    714: 
1.876     raeburn   715: sub selectuser_link {
                    716:     my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,$linktext) = @_;
                    717:     return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
                    718:            "'$lastelem','$firstelem','$emailelem','$hdomelem'".');">'.$linktext.'</a>';
                    719: }
                    720: 
1.273     raeburn   721: sub check_uncheck_jscript {
                    722:     my $jscript = <<"ENDSCRT";
                    723: function checkAll(field) {
                    724:     if (field.length > 0) {
                    725:         for (i = 0; i < field.length; i++) {
                    726:             field[i].checked = true ;
                    727:         }
                    728:     } else {
                    729:         field.checked = true
                    730:     }
                    731: }
                    732:  
                    733: function uncheckAll(field) {
                    734:     if (field.length > 0) {
                    735:         for (i = 0; i < field.length; i++) {
                    736:             field[i].checked = false ;
1.543     albertel  737:         }
                    738:     } else {
1.273     raeburn   739:         field.checked = false ;
                    740:     }
                    741: }
                    742: ENDSCRT
                    743:     return $jscript;
                    744: }
                    745: 
1.656     www       746: sub select_timezone {
1.659     raeburn   747:    my ($name,$selected,$onchange,$includeempty)=@_;
                    748:    my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    749:    if ($includeempty) {
                    750:        $output .= '<option value=""';
                    751:        if (($selected eq '') || ($selected eq 'local')) {
                    752:            $output .= ' selected="selected" ';
                    753:        }
                    754:        $output .= '> </option>';
                    755:    }
1.657     raeburn   756:    my @timezones = DateTime::TimeZone->all_names;
                    757:    foreach my $tzone (@timezones) {
                    758:        $output.= '<option value="'.$tzone.'"';
                    759:        if ($tzone eq $selected) {
                    760:            $output.=' selected="selected"';
                    761:        }
                    762:        $output.=">$tzone</option>\n";
1.656     www       763:    }
                    764:    $output.="</select>";
                    765:    return $output;
                    766: }
1.273     raeburn   767: 
1.687     raeburn   768: sub select_datelocale {
                    769:     my ($name,$selected,$onchange,$includeempty)=@_;
                    770:     my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    771:     if ($includeempty) {
                    772:         $output .= '<option value=""';
                    773:         if ($selected eq '') {
                    774:             $output .= ' selected="selected" ';
                    775:         }
                    776:         $output .= '> </option>';
                    777:     }
                    778:     my (@possibles,%locale_names);
                    779:     my @locales = DateTime::Locale::Catalog::Locales;
                    780:     foreach my $locale (@locales) {
                    781:         if (ref($locale) eq 'HASH') {
                    782:             my $id = $locale->{'id'};
                    783:             if ($id ne '') {
                    784:                 my $en_terr = $locale->{'en_territory'};
                    785:                 my $native_terr = $locale->{'native_territory'};
1.695     raeburn   786:                 my @languages = &Apache::lonlocal::preferred_languages();
1.687     raeburn   787:                 if (grep(/^en$/,@languages) || !@languages) {
                    788:                     if ($en_terr ne '') {
                    789:                         $locale_names{$id} = '('.$en_terr.')';
                    790:                     } elsif ($native_terr ne '') {
                    791:                         $locale_names{$id} = $native_terr;
                    792:                     }
                    793:                 } else {
                    794:                     if ($native_terr ne '') {
                    795:                         $locale_names{$id} = $native_terr.' ';
                    796:                     } elsif ($en_terr ne '') {
                    797:                         $locale_names{$id} = '('.$en_terr.')';
                    798:                     }
                    799:                 }
                    800:                 push (@possibles,$id);
                    801:             }
                    802:         }
                    803:     }
                    804:     foreach my $item (sort(@possibles)) {
                    805:         $output.= '<option value="'.$item.'"';
                    806:         if ($item eq $selected) {
                    807:             $output.=' selected="selected"';
                    808:         }
                    809:         $output.=">$item";
                    810:         if ($locale_names{$item} ne '') {
                    811:             $output.="  $locale_names{$item}</option>\n";
                    812:         }
                    813:         $output.="</option>\n";
                    814:     }
                    815:     $output.="</select>";
                    816:     return $output;
                    817: }
                    818: 
1.792     raeburn   819: sub select_language {
                    820:     my ($name,$selected,$includeempty) = @_;
                    821:     my %langchoices;
                    822:     if ($includeempty) {
                    823:         %langchoices = ('' => 'No language preference');
                    824:     }
                    825:     foreach my $id (&languageids()) {
                    826:         my $code = &supportedlanguagecode($id);
                    827:         if ($code) {
                    828:             $langchoices{$code} = &plainlanguagedescription($id);
                    829:         }
                    830:     }
                    831:     return &select_form($selected,$name,%langchoices);
                    832: }
                    833: 
1.42      matthew   834: =pod
1.36      matthew   835: 
1.648     raeburn   836: =item * &linked_select_forms(...)
1.36      matthew   837: 
                    838: linked_select_forms returns a string containing a <script></script> block
                    839: and html for two <select> menus.  The select menus will be linked in that
                    840: changing the value of the first menu will result in new values being placed
                    841: in the second menu.  The values in the select menu will appear in alphabetical
1.609     raeburn   842: order unless a defined order is provided.
1.36      matthew   843: 
                    844: linked_select_forms takes the following ordered inputs:
                    845: 
                    846: =over 4
                    847: 
1.112     bowersj2  848: =item * $formname, the name of the <form> tag
1.36      matthew   849: 
1.112     bowersj2  850: =item * $middletext, the text which appears between the <select> tags
1.36      matthew   851: 
1.112     bowersj2  852: =item * $firstdefault, the default value for the first menu
1.36      matthew   853: 
1.112     bowersj2  854: =item * $firstselectname, the name of the first <select> tag
1.36      matthew   855: 
1.112     bowersj2  856: =item * $secondselectname, the name of the second <select> tag
1.36      matthew   857: 
1.112     bowersj2  858: =item * $hashref, a reference to a hash containing the data for the menus.
1.36      matthew   859: 
1.609     raeburn   860: =item * $menuorder, the order of values in the first menu
                    861: 
1.41      ng        862: =back 
                    863: 
1.36      matthew   864: Below is an example of such a hash.  Only the 'text', 'default', and 
                    865: 'select2' keys must appear as stated.  keys(%menu) are the possible 
                    866: values for the first select menu.  The text that coincides with the 
1.41      ng        867: first menu value is given in $menu{$choice1}->{'text'}.  The values 
1.36      matthew   868: and text for the second menu are given in the hash pointed to by 
                    869: $menu{$choice1}->{'select2'}.  
                    870: 
1.112     bowersj2  871:  my %menu = ( A1 => { text =>"Choice A1" ,
                    872:                        default => "B3",
                    873:                        select2 => { 
                    874:                            B1 => "Choice B1",
                    875:                            B2 => "Choice B2",
                    876:                            B3 => "Choice B3",
                    877:                            B4 => "Choice B4"
1.609     raeburn   878:                            },
                    879:                        order => ['B4','B3','B1','B2'],
1.112     bowersj2  880:                    },
                    881:                A2 => { text =>"Choice A2" ,
                    882:                        default => "C2",
                    883:                        select2 => { 
                    884:                            C1 => "Choice C1",
                    885:                            C2 => "Choice C2",
                    886:                            C3 => "Choice C3"
1.609     raeburn   887:                            },
                    888:                        order => ['C2','C1','C3'],
1.112     bowersj2  889:                    },
                    890:                A3 => { text =>"Choice A3" ,
                    891:                        default => "D6",
                    892:                        select2 => { 
                    893:                            D1 => "Choice D1",
                    894:                            D2 => "Choice D2",
                    895:                            D3 => "Choice D3",
                    896:                            D4 => "Choice D4",
                    897:                            D5 => "Choice D5",
                    898:                            D6 => "Choice D6",
                    899:                            D7 => "Choice D7"
1.609     raeburn   900:                            },
                    901:                        order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112     bowersj2  902:                    }
                    903:                );
1.36      matthew   904: 
                    905: =cut
                    906: 
                    907: sub linked_select_forms {
                    908:     my ($formname,
                    909:         $middletext,
                    910:         $firstdefault,
                    911:         $firstselectname,
                    912:         $secondselectname, 
1.609     raeburn   913:         $hashref,
                    914:         $menuorder,
1.36      matthew   915:         ) = @_;
                    916:     my $second = "document.$formname.$secondselectname";
                    917:     my $first = "document.$formname.$firstselectname";
                    918:     # output the javascript to do the changing
                    919:     my $result = '';
1.776     bisitz    920:     $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824     bisitz    921:     $result.="// <![CDATA[\n";
1.36      matthew   922:     $result.="var select2data = new Object();\n";
                    923:     $" = '","';
                    924:     my $debug = '';
                    925:     foreach my $s1 (sort(keys(%$hashref))) {
                    926:         $result.="select2data.d_$s1 = new Object();\n";        
                    927:         $result.="select2data.d_$s1.def = new String('".
                    928:             $hashref->{$s1}->{'default'}."');\n";
1.609     raeburn   929:         $result.="select2data.d_$s1.values = new Array(";
1.36      matthew   930:         my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609     raeburn   931:         if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
                    932:             @s2values = @{$hashref->{$s1}->{'order'}};
                    933:         }
1.36      matthew   934:         $result.="\"@s2values\");\n";
                    935:         $result.="select2data.d_$s1.texts = new Array(";        
                    936:         my @s2texts;
                    937:         foreach my $value (@s2values) {
                    938:             push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
                    939:         }
                    940:         $result.="\"@s2texts\");\n";
                    941:     }
                    942:     $"=' ';
                    943:     $result.= <<"END";
                    944: 
                    945: function select1_changed() {
                    946:     // Determine new choice
                    947:     var newvalue = "d_" + $first.value;
                    948:     // update select2
                    949:     var values     = select2data[newvalue].values;
                    950:     var texts      = select2data[newvalue].texts;
                    951:     var select2def = select2data[newvalue].def;
                    952:     var i;
                    953:     // out with the old
                    954:     for (i = 0; i < $second.options.length; i++) {
                    955:         $second.options[i] = null;
                    956:     }
                    957:     // in with the nuclear
                    958:     for (i=0;i<values.length; i++) {
                    959:         $second.options[i] = new Option(values[i]);
1.143     matthew   960:         $second.options[i].value = values[i];
1.36      matthew   961:         $second.options[i].text = texts[i];
                    962:         if (values[i] == select2def) {
                    963:             $second.options[i].selected = true;
                    964:         }
                    965:     }
                    966: }
1.824     bisitz    967: // ]]>
1.36      matthew   968: </script>
                    969: END
                    970:     # output the initial values for the selection lists
                    971:     $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609     raeburn   972:     my @order = sort(keys(%{$hashref}));
                    973:     if (ref($menuorder) eq 'ARRAY') {
                    974:         @order = @{$menuorder};
                    975:     }
                    976:     foreach my $value (@order) {
1.36      matthew   977:         $result.="    <option value=\"$value\" ";
1.253     albertel  978:         $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119     www       979:         $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36      matthew   980:     }
                    981:     $result .= "</select>\n";
                    982:     my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
                    983:     $result .= $middletext;
                    984:     $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
                    985:     my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609     raeburn   986:     
                    987:     my @secondorder = sort(keys(%select2));
                    988:     if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
                    989:         @secondorder = @{$hashref->{$firstdefault}->{'order'}};
                    990:     }
                    991:     foreach my $value (@secondorder) {
1.36      matthew   992:         $result.="    <option value=\"$value\" ";        
1.253     albertel  993:         $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119     www       994:         $result.=">".&mt($select2{$value})."</option>\n";
1.36      matthew   995:     }
                    996:     $result .= "</select>\n";
                    997:     #    return $debug;
                    998:     return $result;
                    999: }   #  end of sub linked_select_forms {
                   1000: 
1.45      matthew  1001: =pod
1.44      bowersj2 1002: 
1.648     raeburn  1003: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44      bowersj2 1004: 
1.112     bowersj2 1005: Returns a string corresponding to an HTML link to the given help
                   1006: $topic, where $topic corresponds to the name of a .tex file in
                   1007: /home/httpd/html/adm/help/tex, with underscores replaced by
                   1008: spaces. 
                   1009: 
                   1010: $text will optionally be linked to the same topic, allowing you to
                   1011: link text in addition to the graphic. If you do not want to link
                   1012: text, but wish to specify one of the later parameters, pass an
                   1013: empty string. 
                   1014: 
                   1015: $stayOnPage is a value that will be interpreted as a boolean. If true,
                   1016: the link will not open a new window. If false, the link will open
                   1017: a new window using Javascript. (Default is false.) 
                   1018: 
                   1019: $width and $height are optional numerical parameters that will
                   1020: override the width and height of the popped up window, which may
                   1021: be useful for certain help topics with big pictures included. 
1.44      bowersj2 1022: 
                   1023: =cut
                   1024: 
                   1025: sub help_open_topic {
1.48      bowersj2 1026:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
                   1027:     $text = "" if (not defined $text);
1.44      bowersj2 1028:     $stayOnPage = 0 if (not defined $stayOnPage);
                   1029:     $width = 350 if (not defined $width);
                   1030:     $height = 400 if (not defined $height);
                   1031:     my $filename = $topic;
                   1032:     $filename =~ s/ /_/g;
                   1033: 
1.48      bowersj2 1034:     my $template = "";
                   1035:     my $link;
1.572     banghart 1036:     
1.159     www      1037:     $topic=~s/\W/\_/g;
1.44      bowersj2 1038: 
1.572     banghart 1039:     if (!$stayOnPage) {
1.72      bowersj2 1040: 	$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 1041:     } else {
1.48      bowersj2 1042: 	$link = "/adm/help/${filename}.hlp";
                   1043:     }
                   1044: 
                   1045:     # Add the text
1.755     neumanie 1046:     if ($text ne "") {	
1.763     bisitz   1047: 	$template.='<span class="LC_help_open_topic">'
                   1048:                   .'<a target="_top" href="'.$link.'">'
                   1049:                   .$text.'</a>';
1.48      bowersj2 1050:     }
                   1051: 
1.763     bisitz   1052:     # (Always) Add the graphic
1.179     matthew  1053:     my $title = &mt('Online Help');
1.667     raeburn  1054:     my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.763     bisitz   1055:     $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
                   1056:               .'<img src="'.$helpicon.'" border="0"'
                   1057:               .' alt="'.&mt('Help: [_1]',$topic).'"'
1.783     amueller 1058:               .' title="'.$title.'"' 
1.763     bisitz   1059:               .' /></a>';
                   1060:     if ($text ne "") {	
                   1061:         $template.='</span>';
                   1062:     }
1.44      bowersj2 1063:     return $template;
                   1064: 
1.106     bowersj2 1065: }
                   1066: 
                   1067: # This is a quicky function for Latex cheatsheet editing, since it 
                   1068: # appears in at least four places
                   1069: sub helpLatexCheatsheet {
1.732     raeburn  1070:     my ($topic,$text,$not_author) = @_;
                   1071:     my $out;
1.106     bowersj2 1072:     my $addOther = '';
1.732     raeburn  1073:     if ($topic) {
1.763     bisitz   1074: 	$addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
                   1075: 							       undef, undef, 600).
                   1076: 								   '</span> ';
                   1077:     }
                   1078:     $out = '<span>' # Start cheatsheet
                   1079: 	  .$addOther
                   1080:           .'<span>'
                   1081: 	  .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
                   1082: 					       undef,undef,600)
                   1083: 	  .'</span> <span>'
                   1084: 	  .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
                   1085: 					       undef,undef,600)
                   1086: 	  .'</span>';
1.732     raeburn  1087:     unless ($not_author) {
1.763     bisitz   1088:         $out .= ' <span>'
                   1089: 	       .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
                   1090: 	                                            undef,undef,600)
                   1091: 	       .'</span>';
1.732     raeburn  1092:     }
1.763     bisitz   1093:     $out .= '</span>'; # End cheatsheet
1.732     raeburn  1094:     return $out;
1.172     www      1095: }
                   1096: 
1.430     albertel 1097: sub general_help {
                   1098:     my $helptopic='Student_Intro';
                   1099:     if ($env{'request.role'}=~/^(ca|au)/) {
                   1100: 	$helptopic='Authoring_Intro';
                   1101:     } elsif ($env{'request.role'}=~/^cc/) {
                   1102: 	$helptopic='Course_Coordination_Intro';
1.672     raeburn  1103:     } elsif ($env{'request.role'}=~/^dc/) {
                   1104:         $helptopic='Domain_Coordination_Intro';
1.430     albertel 1105:     }
                   1106:     return $helptopic;
                   1107: }
                   1108: 
                   1109: sub update_help_link {
                   1110:     my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
                   1111:     my $origurl = $ENV{'REQUEST_URI'};
                   1112:     $origurl=~s|^/~|/priv/|;
                   1113:     my $timestamp = time;
                   1114:     foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
                   1115:         $$datum = &escape($$datum);
                   1116:     }
                   1117: 
                   1118:     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";
                   1119:     my $output .= <<"ENDOUTPUT";
                   1120: <script type="text/javascript">
1.824     bisitz   1121: // <![CDATA[
1.430     albertel 1122: banner_link = '$banner_link';
1.824     bisitz   1123: // ]]>
1.430     albertel 1124: </script>
                   1125: ENDOUTPUT
                   1126:     return $output;
                   1127: }
                   1128: 
                   1129: # now just updates the help link and generates a blue icon
1.193     raeburn  1130: sub help_open_menu {
1.430     albertel 1131:     my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text) 
1.552     banghart 1132: 	= @_;    
1.430     albertel 1133:     $stayOnPage = 0 if (not defined $stayOnPage);
1.572     banghart 1134:     # only use pop-up help (stayOnPage == 0)
1.552     banghart 1135:     # if environment.remote is on (using remote control UI)
1.798     tempelho 1136:     if ($env{'environment.remote'} eq 'off' ) {
1.552     banghart 1137:         $stayOnPage=1;
1.430     albertel 1138:     }
                   1139:     my $output;
                   1140:     if ($component_help) {
                   1141: 	if (!$text) {
                   1142: 	    $output=&help_open_topic($component_help,undef,$stayOnPage,
                   1143: 				       $width,$height);
                   1144: 	} else {
                   1145: 	    my $help_text;
                   1146: 	    $help_text=&unescape($topic);
                   1147: 	    $output='<table><tr><td>'.
                   1148: 		&help_open_topic($component_help,$help_text,$stayOnPage,
                   1149: 				 $width,$height).'</td></tr></table>';
                   1150: 	}
                   1151:     }
                   1152:     my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
                   1153:     return $output.$banner_link;
                   1154: }
                   1155: 
                   1156: sub top_nav_help {
                   1157:     my ($text) = @_;
1.436     albertel 1158:     $text = &mt($text);
1.572     banghart 1159:     my $stay_on_page = 
1.798     tempelho 1160: 	($env{'environment.remote'} eq 'off' );
1.572     banghart 1161:     my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436     albertel 1162: 	                     : "javascript:helpMenu('open')";
1.572     banghart 1163:     my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436     albertel 1164: 
1.201     raeburn  1165:     my $title = &mt('Get help');
1.436     albertel 1166: 
                   1167:     return <<"END";
                   1168: $banner_link
                   1169:  <a href="$link" title="$title">$text</a>
                   1170: END
                   1171: }
                   1172: 
                   1173: sub help_menu_js {
                   1174:     my ($text) = @_;
                   1175: 
                   1176:     my $stayOnPage = 
1.798     tempelho 1177: 	($env{'environment.remote'} eq 'off' );
1.436     albertel 1178: 
                   1179:     my $width = 620;
                   1180:     my $height = 600;
1.430     albertel 1181:     my $helptopic=&general_help();
                   1182:     my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261     albertel 1183:     my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331     albertel 1184:     my $start_page =
                   1185:         &Apache::loncommon::start_page('Help Menu', undef,
                   1186: 				       {'frameset'    => 1,
                   1187: 					'js_ready'    => 1,
                   1188: 					'add_entries' => {
                   1189: 					    'border' => '0',
1.579     raeburn  1190: 					    'rows'   => "110,*",},});
1.331     albertel 1191:     my $end_page =
                   1192:         &Apache::loncommon::end_page({'frameset' => 1,
                   1193: 				      'js_ready' => 1,});
                   1194: 
1.436     albertel 1195:     my $template .= <<"ENDTEMPLATE";
                   1196: <script type="text/javascript">
1.877     bisitz   1197: // <![CDATA[
1.253     albertel 1198: // <!-- BEGIN LON-CAPA Internal
1.430     albertel 1199: var banner_link = '';
1.243     raeburn  1200: function helpMenu(target) {
                   1201:     var caller = this;
                   1202:     if (target == 'open') {
                   1203:         var newWindow = null;
                   1204:         try {
1.262     albertel 1205:             newWindow =  window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243     raeburn  1206:         }
                   1207:         catch(error) {
                   1208:             writeHelp(caller);
                   1209:             return;
                   1210:         }
                   1211:         if (newWindow) {
                   1212:             caller = newWindow;
                   1213:         }
1.193     raeburn  1214:     }
1.243     raeburn  1215:     writeHelp(caller);
                   1216:     return;
                   1217: }
                   1218: function writeHelp(caller) {
1.430     albertel 1219:     caller.document.writeln('$start_page<frame name="bannerframe"  src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243     raeburn  1220:     caller.document.close()
                   1221:     caller.focus()
1.193     raeburn  1222: }
1.877     bisitz   1223: // END LON-CAPA Internal -->
1.253     albertel 1224: // ]]>
1.436     albertel 1225: </script>
1.193     raeburn  1226: ENDTEMPLATE
                   1227:     return $template;
                   1228: }
                   1229: 
1.172     www      1230: sub help_open_bug {
                   1231:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1232:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1233:     unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
                   1234:     $text = "" if (not defined $text);
                   1235:     $stayOnPage = 0 if (not defined $stayOnPage);
1.798     tempelho 1236:     if ($env{'environment.remote'} eq 'off' ) {
1.172     www      1237: 	$stayOnPage=1;
                   1238:     }
1.184     albertel 1239:     $width = 600 if (not defined $width);
                   1240:     $height = 600 if (not defined $height);
1.172     www      1241: 
                   1242:     $topic=~s/\W+/\+/g;
                   1243:     my $link='';
                   1244:     my $template='';
1.379     albertel 1245:     my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&amp;bug_file_loc='.
                   1246: 	&escape($ENV{'REQUEST_URI'}).'&amp;component='.$topic;
1.172     www      1247:     if (!$stayOnPage)
                   1248:     {
                   1249: 	$link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1250:     }
                   1251:     else
                   1252:     {
                   1253: 	$link = $url;
                   1254:     }
                   1255:     # Add the text
                   1256:     if ($text ne "")
                   1257:     {
                   1258: 	$template .= 
                   1259:   "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1260:   "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172     www      1261:     }
                   1262: 
                   1263:     # Add the graphic
1.179     matthew  1264:     my $title = &mt('Report a Bug');
1.215     albertel 1265:     my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172     www      1266:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1267:  <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172     www      1268: ENDTEMPLATE
                   1269:     if ($text ne '') { $template.='</td></tr></table>' };
                   1270:     return $template;
                   1271: 
                   1272: }
                   1273: 
                   1274: sub help_open_faq {
                   1275:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1276:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1277:     unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
                   1278:     $text = "" if (not defined $text);
                   1279:     $stayOnPage = 0 if (not defined $stayOnPage);
1.798     tempelho 1280:     if ($env{'environment.remote'} eq 'off' ) {
1.172     www      1281: 	$stayOnPage=1;
                   1282:     }
                   1283:     $width = 350 if (not defined $width);
                   1284:     $height = 400 if (not defined $height);
                   1285: 
                   1286:     $topic=~s/\W+/\+/g;
                   1287:     my $link='';
                   1288:     my $template='';
                   1289:     my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
                   1290:     if (!$stayOnPage)
                   1291:     {
                   1292: 	$link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1293:     }
                   1294:     else
                   1295:     {
                   1296: 	$link = $url;
                   1297:     }
                   1298: 
                   1299:     # Add the text
                   1300:     if ($text ne "")
                   1301:     {
                   1302: 	$template .= 
1.173     www      1303:   "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1304:   "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172     www      1305:     }
                   1306: 
                   1307:     # Add the graphic
1.179     matthew  1308:     my $title = &mt('View the FAQ');
1.215     albertel 1309:     my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172     www      1310:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1311:  <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172     www      1312: ENDTEMPLATE
                   1313:     if ($text ne '') { $template.='</td></tr></table>' };
                   1314:     return $template;
                   1315: 
1.44      bowersj2 1316: }
1.37      matthew  1317: 
1.180     matthew  1318: ###############################################################
                   1319: ###############################################################
                   1320: 
1.45      matthew  1321: =pod
                   1322: 
1.648     raeburn  1323: =item * &change_content_javascript():
1.256     matthew  1324: 
                   1325: This and the next function allow you to create small sections of an
                   1326: otherwise static HTML page that you can update on the fly with
                   1327: Javascript, even in Netscape 4.
                   1328: 
                   1329: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
                   1330: must be written to the HTML page once. It will prove the Javascript
                   1331: function "change(name, content)". Calling the change function with the
                   1332: name of the section 
                   1333: you want to update, matching the name passed to C<changable_area>, and
                   1334: the new content you want to put in there, will put the content into
                   1335: that area.
                   1336: 
                   1337: B<Note>: Netscape 4 only reserves enough space for the changable area
                   1338: to contain room for the original contents. You need to "make space"
                   1339: for whatever changes you wish to make, and be B<sure> to check your
                   1340: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
                   1341: it's adequate for updating a one-line status display, but little more.
                   1342: This script will set the space to 100% width, so you only need to
                   1343: worry about height in Netscape 4.
                   1344: 
                   1345: Modern browsers are much less limiting, and if you can commit to the
                   1346: user not using Netscape 4, this feature may be used freely with
                   1347: pretty much any HTML.
                   1348: 
                   1349: =cut
                   1350: 
                   1351: sub change_content_javascript {
                   1352:     # If we're on Netscape 4, we need to use Layer-based code
1.258     albertel 1353:     if ($env{'browser.type'} eq 'netscape' &&
                   1354: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1355: 	return (<<NETSCAPE4);
                   1356: 	function change(name, content) {
                   1357: 	    doc = document.layers[name+"___escape"].layers[0].document;
                   1358: 	    doc.open();
                   1359: 	    doc.write(content);
                   1360: 	    doc.close();
                   1361: 	}
                   1362: NETSCAPE4
                   1363:     } else {
                   1364: 	# Otherwise, we need to use semi-standards-compliant code
                   1365: 	# (technically, "innerHTML" isn't standard but the equivalent
                   1366: 	# is really scary, and every useful browser supports it
                   1367: 	return (<<DOMBASED);
                   1368: 	function change(name, content) {
                   1369: 	    element = document.getElementById(name);
                   1370: 	    element.innerHTML = content;
                   1371: 	}
                   1372: DOMBASED
                   1373:     }
                   1374: }
                   1375: 
                   1376: =pod
                   1377: 
1.648     raeburn  1378: =item * &changable_area($name,$origContent):
1.256     matthew  1379: 
                   1380: This provides a "changable area" that can be modified on the fly via
                   1381: the Javascript code provided in C<change_content_javascript>. $name is
                   1382: the name you will use to reference the area later; do not repeat the
                   1383: same name on a given HTML page more then once. $origContent is what
                   1384: the area will originally contain, which can be left blank.
                   1385: 
                   1386: =cut
                   1387: 
                   1388: sub changable_area {
                   1389:     my ($name, $origContent) = @_;
                   1390: 
1.258     albertel 1391:     if ($env{'browser.type'} eq 'netscape' &&
                   1392: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1393: 	# If this is netscape 4, we need to use the Layer tag
                   1394: 	return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
                   1395:     } else {
                   1396: 	return "<span id='$name'>$origContent</span>";
                   1397:     }
                   1398: }
                   1399: 
                   1400: =pod
                   1401: 
1.648     raeburn  1402: =item * &viewport_geometry_js 
1.590     raeburn  1403: 
                   1404: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
                   1405: 
                   1406: =cut
                   1407: 
                   1408: 
                   1409: sub viewport_geometry_js { 
                   1410:     return <<"GEOMETRY";
                   1411: var Geometry = {};
                   1412: function init_geometry() {
                   1413:     if (Geometry.init) { return };
                   1414:     Geometry.init=1;
                   1415:     if (window.innerHeight) {
                   1416:         Geometry.getViewportHeight   = function() { return window.innerHeight; };
                   1417:         Geometry.getViewportWidth   = function() { return window.innerWidth; };
                   1418:         Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
                   1419:         Geometry.getVerticalScroll   = function() { return window.pageYOffset; };
                   1420:     }
                   1421:     else if (document.documentElement && document.documentElement.clientHeight) {
                   1422:         Geometry.getViewportHeight =
                   1423:             function() { return document.documentElement.clientHeight; };
                   1424:         Geometry.getViewportWidth =
                   1425:             function() { return document.documentElement.clientWidth; };
                   1426: 
                   1427:         Geometry.getHorizontalScroll =
                   1428:             function() { return document.documentElement.scrollLeft; };
                   1429:         Geometry.getVerticalScroll =
                   1430:             function() { return document.documentElement.scrollTop; };
                   1431:     }
                   1432:     else if (document.body.clientHeight) {
                   1433:         Geometry.getViewportHeight =
                   1434:             function() { return document.body.clientHeight; };
                   1435:         Geometry.getViewportWidth =
                   1436:             function() { return document.body.clientWidth; };
                   1437:         Geometry.getHorizontalScroll =
                   1438:             function() { return document.body.scrollLeft; };
                   1439:         Geometry.getVerticalScroll =
                   1440:             function() { return document.body.scrollTop; };
                   1441:     }
                   1442: }
                   1443: 
                   1444: GEOMETRY
                   1445: }
                   1446: 
                   1447: =pod
                   1448: 
1.648     raeburn  1449: =item * &viewport_size_js()
1.590     raeburn  1450: 
                   1451: 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. 
                   1452: 
                   1453: =cut
                   1454: 
                   1455: sub viewport_size_js {
                   1456:     my $geometry = &viewport_geometry_js();
                   1457:     return <<"DIMS";
                   1458: 
                   1459: $geometry
                   1460: 
                   1461: function getViewportDims(width,height) {
                   1462:     init_geometry();
                   1463:     width.value = Geometry.getViewportWidth();
                   1464:     height.value = Geometry.getViewportHeight();
                   1465:     return;
                   1466: }
                   1467: 
                   1468: DIMS
                   1469: }
                   1470: 
                   1471: =pod
                   1472: 
1.648     raeburn  1473: =item * &resize_textarea_js()
1.565     albertel 1474: 
                   1475: emits the needed javascript to resize a textarea to be as big as possible
                   1476: 
                   1477: creates a function resize_textrea that takes two IDs first should be
                   1478: the id of the element to resize, second should be the id of a div that
                   1479: surrounds everything that comes after the textarea, this routine needs
                   1480: to be attached to the <body> for the onload and onresize events.
                   1481: 
1.648     raeburn  1482: =back
1.565     albertel 1483: 
                   1484: =cut
                   1485: 
                   1486: sub resize_textarea_js {
1.590     raeburn  1487:     my $geometry = &viewport_geometry_js();
1.565     albertel 1488:     return <<"RESIZE";
                   1489:     <script type="text/javascript">
1.824     bisitz   1490: // <![CDATA[
1.590     raeburn  1491: $geometry
1.565     albertel 1492: 
1.588     albertel 1493: function getX(element) {
                   1494:     var x = 0;
                   1495:     while (element) {
                   1496: 	x += element.offsetLeft;
                   1497: 	element = element.offsetParent;
                   1498:     }
                   1499:     return x;
                   1500: }
                   1501: function getY(element) {
                   1502:     var y = 0;
                   1503:     while (element) {
                   1504: 	y += element.offsetTop;
                   1505: 	element = element.offsetParent;
                   1506:     }
                   1507:     return y;
                   1508: }
                   1509: 
                   1510: 
1.565     albertel 1511: function resize_textarea(textarea_id,bottom_id) {
                   1512:     init_geometry();
                   1513:     var textarea        = document.getElementById(textarea_id);
                   1514:     //alert(textarea);
                   1515: 
1.588     albertel 1516:     var textarea_top    = getY(textarea);
1.565     albertel 1517:     var textarea_height = textarea.offsetHeight;
                   1518:     var bottom          = document.getElementById(bottom_id);
1.588     albertel 1519:     var bottom_top      = getY(bottom);
1.565     albertel 1520:     var bottom_height   = bottom.offsetHeight;
                   1521:     var window_height   = Geometry.getViewportHeight();
1.588     albertel 1522:     var fudge           = 23;
1.565     albertel 1523:     var new_height      = window_height-fudge-textarea_top-bottom_height;
                   1524:     if (new_height < 300) {
                   1525: 	new_height = 300;
                   1526:     }
                   1527:     textarea.style.height=new_height+'px';
                   1528: }
1.824     bisitz   1529: // ]]>
1.565     albertel 1530: </script>
                   1531: RESIZE
                   1532: 
                   1533: }
                   1534: 
                   1535: =pod
                   1536: 
1.256     matthew  1537: =head1 Excel and CSV file utility routines
                   1538: 
                   1539: =over 4
                   1540: 
                   1541: =cut
                   1542: 
                   1543: ###############################################################
                   1544: ###############################################################
                   1545: 
                   1546: =pod
                   1547: 
1.648     raeburn  1548: =item * &csv_translate($text) 
1.37      matthew  1549: 
1.185     www      1550: Translate $text to allow it to be output as a 'comma separated values' 
1.37      matthew  1551: format.
                   1552: 
                   1553: =cut
                   1554: 
1.180     matthew  1555: ###############################################################
                   1556: ###############################################################
1.37      matthew  1557: sub csv_translate {
                   1558:     my $text = shift;
                   1559:     $text =~ s/\"/\"\"/g;
1.209     albertel 1560:     $text =~ s/\n/ /g;
1.37      matthew  1561:     return $text;
                   1562: }
1.180     matthew  1563: 
                   1564: ###############################################################
                   1565: ###############################################################
                   1566: 
                   1567: =pod
                   1568: 
1.648     raeburn  1569: =item * &define_excel_formats()
1.180     matthew  1570: 
                   1571: Define some commonly used Excel cell formats.
                   1572: 
                   1573: Currently supported formats:
                   1574: 
                   1575: =over 4
                   1576: 
                   1577: =item header
                   1578: 
                   1579: =item bold
                   1580: 
                   1581: =item h1
                   1582: 
                   1583: =item h2
                   1584: 
                   1585: =item h3
                   1586: 
1.256     matthew  1587: =item h4
                   1588: 
                   1589: =item i
                   1590: 
1.180     matthew  1591: =item date
                   1592: 
                   1593: =back
                   1594: 
                   1595: Inputs: $workbook
                   1596: 
                   1597: Returns: $format, a hash reference.
                   1598: 
                   1599: =cut
                   1600: 
                   1601: ###############################################################
                   1602: ###############################################################
                   1603: sub define_excel_formats {
                   1604:     my ($workbook) = @_;
                   1605:     my $format;
                   1606:     $format->{'header'} = $workbook->add_format(bold      => 1, 
                   1607:                                                 bottom    => 1,
                   1608:                                                 align     => 'center');
                   1609:     $format->{'bold'} = $workbook->add_format(bold=>1);
                   1610:     $format->{'h1'}   = $workbook->add_format(bold=>1, size=>18);
                   1611:     $format->{'h2'}   = $workbook->add_format(bold=>1, size=>16);
                   1612:     $format->{'h3'}   = $workbook->add_format(bold=>1, size=>14);
1.255     matthew  1613:     $format->{'h4'}   = $workbook->add_format(bold=>1, size=>12);
1.246     matthew  1614:     $format->{'i'}    = $workbook->add_format(italic=>1);
1.180     matthew  1615:     $format->{'date'} = $workbook->add_format(num_format=>
1.207     matthew  1616:                                             'mm/dd/yyyy hh:mm:ss');
1.180     matthew  1617:     return $format;
                   1618: }
                   1619: 
                   1620: ###############################################################
                   1621: ###############################################################
1.113     bowersj2 1622: 
                   1623: =pod
                   1624: 
1.648     raeburn  1625: =item * &create_workbook()
1.255     matthew  1626: 
                   1627: Create an Excel worksheet.  If it fails, output message on the
                   1628: request object and return undefs.
                   1629: 
                   1630: Inputs: Apache request object
                   1631: 
                   1632: Returns (undef) on failure, 
                   1633:     Excel worksheet object, scalar with filename, and formats 
                   1634:     from &Apache::loncommon::define_excel_formats on success
                   1635: 
                   1636: =cut
                   1637: 
                   1638: ###############################################################
                   1639: ###############################################################
                   1640: sub create_workbook {
                   1641:     my ($r) = @_;
                   1642:         #
                   1643:     # Create the excel spreadsheet
                   1644:     my $filename = '/prtspool/'.
1.258     albertel 1645:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255     matthew  1646:         time.'_'.rand(1000000000).'.xls';
                   1647:     my $workbook  = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
                   1648:     if (! defined($workbook)) {
                   1649:         $r->log_error("Error creating excel spreadsheet $filename: $!");
                   1650:         $r->print('<p>'.&mt("Unable to create new Excel file.  ".
                   1651:                             "This error has been logged.  ".
                   1652:                             "Please alert your LON-CAPA administrator").
                   1653:                   '</p>');
                   1654:         return (undef);
                   1655:     }
                   1656:     #
                   1657:     $workbook->set_tempdir('/home/httpd/perl/tmp');
                   1658:     #
                   1659:     my $format = &Apache::loncommon::define_excel_formats($workbook);
                   1660:     return ($workbook,$filename,$format);
                   1661: }
                   1662: 
                   1663: ###############################################################
                   1664: ###############################################################
                   1665: 
                   1666: =pod
                   1667: 
1.648     raeburn  1668: =item * &create_text_file()
1.113     bowersj2 1669: 
1.542     raeburn  1670: Create a file to write to and eventually make available to the user.
1.256     matthew  1671: If file creation fails, outputs an error message on the request object and 
                   1672: return undefs.
1.113     bowersj2 1673: 
1.256     matthew  1674: Inputs: Apache request object, and file suffix
1.113     bowersj2 1675: 
1.256     matthew  1676: Returns (undef) on failure, 
                   1677:     Filehandle and filename on success.
1.113     bowersj2 1678: 
                   1679: =cut
                   1680: 
1.256     matthew  1681: ###############################################################
                   1682: ###############################################################
                   1683: sub create_text_file {
                   1684:     my ($r,$suffix) = @_;
                   1685:     if (! defined($suffix)) { $suffix = 'txt'; };
                   1686:     my $fh;
                   1687:     my $filename = '/prtspool/'.
1.258     albertel 1688:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256     matthew  1689:         time.'_'.rand(1000000000).'.'.$suffix;
                   1690:     $fh = Apache::File->new('>/home/httpd'.$filename);
                   1691:     if (! defined($fh)) {
                   1692:         $r->log_error("Couldn't open $filename for output $!");
1.683     bisitz   1693:         $r->print(&mt('Problems occurred in creating the output file. '
                   1694:                      .'This error has been logged. '
                   1695:                      .'Please alert your LON-CAPA administrator.'));
1.113     bowersj2 1696:     }
1.256     matthew  1697:     return ($fh,$filename)
1.113     bowersj2 1698: }
                   1699: 
                   1700: 
1.256     matthew  1701: =pod 
1.113     bowersj2 1702: 
                   1703: =back
                   1704: 
                   1705: =cut
1.37      matthew  1706: 
                   1707: ###############################################################
1.33      matthew  1708: ##        Home server <option> list generating code          ##
                   1709: ###############################################################
1.35      matthew  1710: 
1.169     www      1711: # ------------------------------------------
                   1712: 
                   1713: sub domain_select {
                   1714:     my ($name,$value,$multiple)=@_;
                   1715:     my %domains=map { 
1.514     albertel 1716: 	$_ => $_.' '. &Apache::lonnet::domain($_,'description') 
1.512     albertel 1717:     } &Apache::lonnet::all_domains();
1.169     www      1718:     if ($multiple) {
                   1719: 	$domains{''}=&mt('Any domain');
1.550     albertel 1720: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287     albertel 1721: 	return &multiple_select_form($name,$value,4,\%domains);
1.169     www      1722:     } else {
1.550     albertel 1723: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169     www      1724: 	return &select_form($name,$value,%domains);
                   1725:     }
                   1726: }
                   1727: 
1.282     albertel 1728: #-------------------------------------------
                   1729: 
                   1730: =pod
                   1731: 
1.519     raeburn  1732: =head1 Routines for form select boxes
                   1733: 
                   1734: =over 4
                   1735: 
1.648     raeburn  1736: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282     albertel 1737: 
                   1738: Returns a string containing a <select> element int multiple mode
                   1739: 
                   1740: 
                   1741: Args:
                   1742:   $name - name of the <select> element
1.506     raeburn  1743:   $value - scalar or array ref of values that should already be selected
1.282     albertel 1744:   $size - number of rows long the select element is
1.283     albertel 1745:   $hash - the elements should be 'option' => 'shown text'
1.282     albertel 1746:           (shown text should already have been &mt())
1.506     raeburn  1747:   $order - (optional) array ref of the order to show the elements in
1.283     albertel 1748: 
1.282     albertel 1749: =cut
                   1750: 
                   1751: #-------------------------------------------
1.169     www      1752: sub multiple_select_form {
1.284     albertel 1753:     my ($name,$value,$size,$hash,$order)=@_;
1.169     www      1754:     my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
                   1755:     my $output='';
1.191     matthew  1756:     if (! defined($size)) {
                   1757:         $size = 4;
1.283     albertel 1758:         if (scalar(keys(%$hash))<4) {
                   1759:             $size = scalar(keys(%$hash));
1.191     matthew  1760:         }
                   1761:     }
1.734     bisitz   1762:     $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501     banghart 1763:     my @order;
1.506     raeburn  1764:     if (ref($order) eq 'ARRAY')  {
                   1765:         @order = @{$order};
                   1766:     } else {
                   1767:         @order = sort(keys(%$hash));
1.501     banghart 1768:     }
                   1769:     if (exists($$hash{'select_form_order'})) {
                   1770:         @order = @{$$hash{'select_form_order'}};
                   1771:     }
                   1772:         
1.284     albertel 1773:     foreach my $key (@order) {
1.356     albertel 1774:         $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284     albertel 1775:         $output.='selected="selected" ' if ($selected{$key});
                   1776:         $output.='>'.$hash->{$key}."</option>\n";
1.169     www      1777:     }
                   1778:     $output.="</select>\n";
                   1779:     return $output;
                   1780: }
                   1781: 
1.88      www      1782: #-------------------------------------------
                   1783: 
                   1784: =pod
                   1785: 
1.648     raeburn  1786: =item * &select_form($defdom,$name,%hash)
1.88      www      1787: 
                   1788: Returns a string containing a <select name='$name' size='1'> form to 
                   1789: allow a user to select options from a hash option_name => displayed text.  
                   1790: See lonrights.pm for an example invocation and use.
                   1791: 
                   1792: =cut
                   1793: 
                   1794: #-------------------------------------------
                   1795: sub select_form {
                   1796:     my ($def,$name,%hash) = @_;
                   1797:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128     albertel 1798:     my @keys;
                   1799:     if (exists($hash{'select_form_order'})) {
                   1800: 	@keys=@{$hash{'select_form_order'}};
                   1801:     } else {
                   1802: 	@keys=sort(keys(%hash));
                   1803:     }
1.356     albertel 1804:     foreach my $key (@keys) {
                   1805:         $selectform.=
                   1806: 	    '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
                   1807:             ($key eq $def ? 'selected="selected" ' : '').
                   1808:                 ">".&mt($hash{$key})."</option>\n";
1.88      www      1809:     }
                   1810:     $selectform.="</select>";
                   1811:     return $selectform;
                   1812: }
                   1813: 
1.475     www      1814: # For display filters
                   1815: 
                   1816: sub display_filter {
                   1817:     if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477     www      1818:     if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714     bisitz   1819:     return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475     www      1820: 			       &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
                   1821: 							   (&mt('all'),10,20,50,100,1000,10000))).
1.714     bisitz   1822: 	   '</label></span> <span class="LC_nobreak">'.
1.475     www      1823:            &mt('Filter [_1]',
1.477     www      1824: 	   &select_form($env{'form.displayfilter'},
                   1825: 			'displayfilter',
                   1826: 			('currentfolder' => 'Current folder/page',
                   1827: 			 'containing' => 'Containing phrase',
                   1828: 			 'none' => 'None'))).
1.714     bisitz   1829: 			 '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475     www      1830: }
                   1831: 
1.167     www      1832: sub gradeleveldescription {
                   1833:     my $gradelevel=shift;
                   1834:     my %gradelevels=(0 => 'Not specified',
                   1835: 		     1 => 'Grade 1',
                   1836: 		     2 => 'Grade 2',
                   1837: 		     3 => 'Grade 3',
                   1838: 		     4 => 'Grade 4',
                   1839: 		     5 => 'Grade 5',
                   1840: 		     6 => 'Grade 6',
                   1841: 		     7 => 'Grade 7',
                   1842: 		     8 => 'Grade 8',
                   1843: 		     9 => 'Grade 9',
                   1844: 		     10 => 'Grade 10',
                   1845: 		     11 => 'Grade 11',
                   1846: 		     12 => 'Grade 12',
                   1847: 		     13 => 'Grade 13',
                   1848: 		     14 => '100 Level',
                   1849: 		     15 => '200 Level',
                   1850: 		     16 => '300 Level',
                   1851: 		     17 => '400 Level',
                   1852: 		     18 => 'Graduate Level');
                   1853:     return &mt($gradelevels{$gradelevel});
                   1854: }
                   1855: 
1.163     www      1856: sub select_level_form {
                   1857:     my ($deflevel,$name)=@_;
                   1858:     unless ($deflevel) { $deflevel=0; }
1.167     www      1859:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
                   1860:     for (my $i=0; $i<=18; $i++) {
                   1861:         $selectform.="<option value=\"$i\" ".
1.253     albertel 1862:             ($i==$deflevel ? 'selected="selected" ' : '').
1.167     www      1863:                 ">".&gradeleveldescription($i)."</option>\n";
                   1864:     }
                   1865:     $selectform.="</select>";
                   1866:     return $selectform;
1.163     www      1867: }
1.167     www      1868: 
1.35      matthew  1869: #-------------------------------------------
                   1870: 
1.45      matthew  1871: =pod
                   1872: 
1.873     raeburn  1873: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange)
1.35      matthew  1874: 
                   1875: Returns a string containing a <select name='$name' size='1'> form to 
                   1876: allow a user to select the domain to preform an operation in.  
                   1877: See loncreateuser.pm for an example invocation and use.
                   1878: 
1.90      www      1879: If the $includeempty flag is set, it also includes an empty choice ("no domain
                   1880: selected");
                   1881: 
1.743     raeburn  1882: If the $showdomdesc flag is set, the domain name is followed by the domain description.
                   1883: 
1.872     raeburn  1884: The optional $onchange argumnet specifies what should occur if the domain selector is changed, e.g., 'this.form.submit()' if the form is to be automatically submitted.  
1.563     raeburn  1885: 
1.35      matthew  1886: =cut
                   1887: 
                   1888: #-------------------------------------------
1.34      matthew  1889: sub select_dom_form {
1.872     raeburn  1890:     my ($defdom,$name,$includeempty,$showdomdesc,$onchange) = @_;
                   1891:     if ($onchange) {
1.874     raeburn  1892:         $onchange = ' onchange="'.$onchange.'"';
1.743     raeburn  1893:     }
1.550     albertel 1894:     my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90      www      1895:     if ($includeempty) { @domains=('',@domains); }
1.743     raeburn  1896:     my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356     albertel 1897:     foreach my $dom (@domains) {
                   1898:         $selectdomain.="<option value=\"$dom\" ".
1.563     raeburn  1899:             ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
                   1900:         if ($showdomdesc) {
                   1901:             if ($dom ne '') {
                   1902:                 my $domdesc = &Apache::lonnet::domain($dom,'description');
                   1903:                 if ($domdesc ne '') {
                   1904:                     $selectdomain .= ' ('.$domdesc.')';
                   1905:                 }
                   1906:             } 
                   1907:         }
                   1908:         $selectdomain .= "</option>\n";
1.34      matthew  1909:     }
                   1910:     $selectdomain.="</select>";
                   1911:     return $selectdomain;
                   1912: }
                   1913: 
1.35      matthew  1914: #-------------------------------------------
                   1915: 
1.45      matthew  1916: =pod
                   1917: 
1.648     raeburn  1918: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35      matthew  1919: 
1.586     raeburn  1920: input: 4 arguments (two required, two optional) - 
                   1921:     $domain - domain of new user
                   1922:     $name - name of form element
                   1923:     $default - Value of 'default' causes a default item to be first 
                   1924:                             option, and selected by default. 
                   1925:     $hide - Value of 'hide' causes hiding of the name of the server, 
                   1926:                             if 1 server found, or default, if 0 found.
1.594     raeburn  1927: output: returns 2 items: 
1.586     raeburn  1928: (a) form element which contains either:
                   1929:    (i) <select name="$name">
                   1930:         <option value="$hostid1">$hostid $servers{$hostid}</option>
                   1931:         <option value="$hostid2">$hostid $servers{$hostid}</option>       
                   1932:        </select>
                   1933:        form item if there are multiple library servers in $domain, or
                   1934:    (ii) an <input type="hidden" name="$name" value="$hostid" /> form item 
                   1935:        if there is only one library server in $domain.
                   1936: 
                   1937: (b) number of library servers found.
                   1938: 
                   1939: See loncreateuser.pm for example of use.
1.35      matthew  1940: 
                   1941: =cut
                   1942: 
                   1943: #-------------------------------------------
1.586     raeburn  1944: sub home_server_form_item {
                   1945:     my ($domain,$name,$default,$hide) = @_;
1.513     albertel 1946:     my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586     raeburn  1947:     my $result;
                   1948:     my $numlib = keys(%servers);
                   1949:     if ($numlib > 1) {
                   1950:         $result .= '<select name="'.$name.'" />'."\n";
                   1951:         if ($default) {
1.804     bisitz   1952:             $result .= '<option value="default" selected="selected">'.&mt('default').
1.586     raeburn  1953:                        '</option>'."\n";
                   1954:         }
                   1955:         foreach my $hostid (sort(keys(%servers))) {
                   1956:             $result.= '<option value="'.$hostid.'">'.
                   1957: 	              $hostid.' '.$servers{$hostid}."</option>\n";
                   1958:         }
                   1959:         $result .= '</select>'."\n";
                   1960:     } elsif ($numlib == 1) {
                   1961:         my $hostid;
                   1962:         foreach my $item (keys(%servers)) {
                   1963:             $hostid = $item;
                   1964:         }
                   1965:         $result .= '<input type="hidden" name="'.$name.'" value="'.
                   1966:                    $hostid.'" />';
                   1967:                    if (!$hide) {
                   1968:                        $result .= $hostid.' '.$servers{$hostid};
                   1969:                    }
                   1970:                    $result .= "\n";
                   1971:     } elsif ($default) {
                   1972:         $result .= '<input type="hidden" name="'.$name.
                   1973:                    '" value="default" />';
                   1974:                    if (!$hide) {
                   1975:                        $result .= &mt('default');
                   1976:                    }
                   1977:                    $result .= "\n";
1.33      matthew  1978:     }
1.586     raeburn  1979:     return ($result,$numlib);
1.33      matthew  1980: }
1.112     bowersj2 1981: 
                   1982: =pod
                   1983: 
1.534     albertel 1984: =back 
                   1985: 
1.112     bowersj2 1986: =cut
1.87      matthew  1987: 
                   1988: ###############################################################
1.112     bowersj2 1989: ##                  Decoding User Agent                      ##
1.87      matthew  1990: ###############################################################
                   1991: 
                   1992: =pod
                   1993: 
1.112     bowersj2 1994: =head1 Decoding the User Agent
                   1995: 
                   1996: =over 4
                   1997: 
                   1998: =item * &decode_user_agent()
1.87      matthew  1999: 
                   2000: Inputs: $r
                   2001: 
                   2002: Outputs:
                   2003: 
                   2004: =over 4
                   2005: 
1.112     bowersj2 2006: =item * $httpbrowser
1.87      matthew  2007: 
1.112     bowersj2 2008: =item * $clientbrowser
1.87      matthew  2009: 
1.112     bowersj2 2010: =item * $clientversion
1.87      matthew  2011: 
1.112     bowersj2 2012: =item * $clientmathml
1.87      matthew  2013: 
1.112     bowersj2 2014: =item * $clientunicode
1.87      matthew  2015: 
1.112     bowersj2 2016: =item * $clientos
1.87      matthew  2017: 
                   2018: =back
                   2019: 
1.157     matthew  2020: =back 
                   2021: 
1.87      matthew  2022: =cut
                   2023: 
                   2024: ###############################################################
                   2025: ###############################################################
                   2026: sub decode_user_agent {
1.247     albertel 2027:     my ($r)=@_;
1.87      matthew  2028:     my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
                   2029:     my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
                   2030:     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247     albertel 2031:     if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87      matthew  2032:     my $clientbrowser='unknown';
                   2033:     my $clientversion='0';
                   2034:     my $clientmathml='';
                   2035:     my $clientunicode='0';
                   2036:     for (my $i=0;$i<=$#browsertype;$i++) {
                   2037:         my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
                   2038: 	if (($httpbrowser=~/$match/i)  && ($httpbrowser!~/$notmatch/i)) {
                   2039: 	    $clientbrowser=$bname;
                   2040:             $httpbrowser=~/$vreg/i;
                   2041: 	    $clientversion=$1;
                   2042:             $clientmathml=($clientversion>=$minv);
                   2043:             $clientunicode=($clientversion>=$univ);
                   2044: 	}
                   2045:     }
                   2046:     my $clientos='unknown';
                   2047:     if (($httpbrowser=~/linux/i) ||
                   2048:         ($httpbrowser=~/unix/i) ||
                   2049:         ($httpbrowser=~/ux/i) ||
                   2050:         ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
                   2051:     if (($httpbrowser=~/vax/i) ||
                   2052:         ($httpbrowser=~/vms/i)) { $clientos='vms'; }
                   2053:     if ($httpbrowser=~/next/i) { $clientos='next'; }
                   2054:     if (($httpbrowser=~/mac/i) ||
                   2055:         ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
                   2056:     if ($httpbrowser=~/win/i) { $clientos='win'; }
                   2057:     if ($httpbrowser=~/embed/i) { $clientos='pda'; }
                   2058:     return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   2059:             $clientunicode,$clientos,);
                   2060: }
                   2061: 
1.32      matthew  2062: ###############################################################
                   2063: ##    Authentication changing form generation subroutines    ##
                   2064: ###############################################################
                   2065: ##
                   2066: ## All of the authform_xxxxxxx subroutines take their inputs in a
                   2067: ## hash, and have reasonable default values.
                   2068: ##
                   2069: ##    formname = the name given in the <form> tag.
1.35      matthew  2070: #-------------------------------------------
                   2071: 
1.45      matthew  2072: =pod
                   2073: 
1.112     bowersj2 2074: =head1 Authentication Routines
                   2075: 
                   2076: =over 4
                   2077: 
1.648     raeburn  2078: =item * &authform_xxxxxx()
1.35      matthew  2079: 
                   2080: The authform_xxxxxx subroutines provide javascript and html forms which 
                   2081: handle some of the conveniences required for authentication forms.  
                   2082: This is not an optimal method, but it works.  
                   2083: 
                   2084: =over 4
                   2085: 
1.112     bowersj2 2086: =item * authform_header
1.35      matthew  2087: 
1.112     bowersj2 2088: =item * authform_authorwarning
1.35      matthew  2089: 
1.112     bowersj2 2090: =item * authform_nochange
1.35      matthew  2091: 
1.112     bowersj2 2092: =item * authform_kerberos
1.35      matthew  2093: 
1.112     bowersj2 2094: =item * authform_internal
1.35      matthew  2095: 
1.112     bowersj2 2096: =item * authform_filesystem
1.35      matthew  2097: 
                   2098: =back
                   2099: 
1.648     raeburn  2100: See loncreateuser.pm for invocation and use examples.
1.157     matthew  2101: 
1.35      matthew  2102: =cut
                   2103: 
                   2104: #-------------------------------------------
1.32      matthew  2105: sub authform_header{  
                   2106:     my %in = (
                   2107:         formname => 'cu',
1.80      albertel 2108:         kerb_def_dom => '',
1.32      matthew  2109:         @_,
                   2110:     );
                   2111:     $in{'formname'} = 'document.' . $in{'formname'};
                   2112:     my $result='';
1.80      albertel 2113: 
                   2114: #---------------------------------------------- Code for upper case translation
                   2115:     my $Javascript_toUpperCase;
                   2116:     unless ($in{kerb_def_dom}) {
                   2117:         $Javascript_toUpperCase =<<"END";
                   2118:         switch (choice) {
                   2119:            case 'krb': currentform.elements[choicearg].value =
                   2120:                currentform.elements[choicearg].value.toUpperCase();
                   2121:                break;
                   2122:            default:
                   2123:         }
                   2124: END
                   2125:     } else {
                   2126:         $Javascript_toUpperCase = "";
                   2127:     }
                   2128: 
1.165     raeburn  2129:     my $radioval = "'nochange'";
1.591     raeburn  2130:     if (defined($in{'curr_authtype'})) {
                   2131:         if ($in{'curr_authtype'} ne '') {
                   2132:             $radioval = "'".$in{'curr_authtype'}."arg'";
                   2133:         }
1.174     matthew  2134:     }
1.165     raeburn  2135:     my $argfield = 'null';
1.591     raeburn  2136:     if (defined($in{'mode'})) {
1.165     raeburn  2137:         if ($in{'mode'} eq 'modifycourse')  {
1.591     raeburn  2138:             if (defined($in{'curr_autharg'})) {
                   2139:                 if ($in{'curr_autharg'} ne '') {
1.165     raeburn  2140:                     $argfield = "'$in{'curr_autharg'}'";
                   2141:                 }
                   2142:             }
                   2143:         }
                   2144:     }
                   2145: 
1.32      matthew  2146:     $result.=<<"END";
                   2147: var current = new Object();
1.165     raeburn  2148: current.radiovalue = $radioval;
                   2149: current.argfield = $argfield;
1.32      matthew  2150: 
                   2151: function changed_radio(choice,currentform) {
                   2152:     var choicearg = choice + 'arg';
                   2153:     // If a radio button in changed, we need to change the argfield
                   2154:     if (current.radiovalue != choice) {
                   2155:         current.radiovalue = choice;
                   2156:         if (current.argfield != null) {
                   2157:             currentform.elements[current.argfield].value = '';
                   2158:         }
                   2159:         if (choice == 'nochange') {
                   2160:             current.argfield = null;
                   2161:         } else {
                   2162:             current.argfield = choicearg;
                   2163:             switch(choice) {
                   2164:                 case 'krb': 
                   2165:                     currentform.elements[current.argfield].value = 
                   2166:                         "$in{'kerb_def_dom'}";
                   2167:                 break;
                   2168:               default:
                   2169:                 break;
                   2170:             }
                   2171:         }
                   2172:     }
                   2173:     return;
                   2174: }
1.22      www      2175: 
1.32      matthew  2176: function changed_text(choice,currentform) {
                   2177:     var choicearg = choice + 'arg';
                   2178:     if (currentform.elements[choicearg].value !='') {
1.80      albertel 2179:         $Javascript_toUpperCase
1.32      matthew  2180:         // clear old field
                   2181:         if ((current.argfield != choicearg) && (current.argfield != null)) {
                   2182:             currentform.elements[current.argfield].value = '';
                   2183:         }
                   2184:         current.argfield = choicearg;
                   2185:     }
                   2186:     set_auth_radio_buttons(choice,currentform);
                   2187:     return;
1.20      www      2188: }
1.32      matthew  2189: 
                   2190: function set_auth_radio_buttons(newvalue,currentform) {
                   2191:     var i=0;
                   2192:     while (i < currentform.login.length) {
                   2193:         if (currentform.login[i].value == newvalue) { break; }
                   2194:         i++;
                   2195:     }
                   2196:     if (i == currentform.login.length) {
                   2197:         return;
                   2198:     }
                   2199:     current.radiovalue = newvalue;
                   2200:     currentform.login[i].checked = true;
                   2201:     return;
                   2202: }
                   2203: END
                   2204:     return $result;
                   2205: }
                   2206: 
                   2207: sub authform_authorwarning{
                   2208:     my $result='';
1.144     matthew  2209:     $result='<i>'.
                   2210:         &mt('As a general rule, only authors or co-authors should be '.
                   2211:             'filesystem authenticated '.
                   2212:             '(which allows access to the server filesystem).')."</i>\n";
1.32      matthew  2213:     return $result;
                   2214: }
                   2215: 
                   2216: sub authform_nochange{  
                   2217:     my %in = (
                   2218:               formname => 'document.cu',
                   2219:               kerb_def_dom => 'MSU.EDU',
                   2220:               @_,
                   2221:           );
1.586     raeburn  2222:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'}); 
                   2223:     my $result;
                   2224:     if (keys(%can_assign) == 0) {
                   2225:         $result = &mt('Under you current role you are not permitted to change login settings for this user');  
                   2226:     } else {
                   2227:         $result = '<label>'.&mt('[_1] Do not change login data',
                   2228:                   '<input type="radio" name="login" value="nochange" '.
                   2229:                   'checked="checked" onclick="'.
1.281     albertel 2230:             "javascript:changed_radio('nochange',$in{'formname'});".'" />').
                   2231: 	    '</label>';
1.586     raeburn  2232:     }
1.32      matthew  2233:     return $result;
                   2234: }
                   2235: 
1.591     raeburn  2236: sub authform_kerberos {
1.32      matthew  2237:     my %in = (
                   2238:               formname => 'document.cu',
                   2239:               kerb_def_dom => 'MSU.EDU',
1.80      albertel 2240:               kerb_def_auth => 'krb4',
1.32      matthew  2241:               @_,
                   2242:               );
1.586     raeburn  2243:     my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
                   2244:         $autharg,$jscall);
                   2245:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.80      albertel 2246:     if ($in{'kerb_def_auth'} eq 'krb5') {
1.772     bisitz   2247:        $check5 = ' checked="checked"';
1.80      albertel 2248:     } else {
1.772     bisitz   2249:        $check4 = ' checked="checked"';
1.80      albertel 2250:     }
1.165     raeburn  2251:     $krbarg = $in{'kerb_def_dom'};
1.591     raeburn  2252:     if (defined($in{'curr_authtype'})) {
                   2253:         if ($in{'curr_authtype'} eq 'krb') {
1.772     bisitz   2254:             $krbcheck = ' checked="checked"';
1.623     raeburn  2255:             if (defined($in{'mode'})) {
                   2256:                 if ($in{'mode'} eq 'modifyuser') {
                   2257:                     $krbcheck = '';
                   2258:                 }
                   2259:             }
1.591     raeburn  2260:             if (defined($in{'curr_kerb_ver'})) {
                   2261:                 if ($in{'curr_krb_ver'} eq '5') {
1.772     bisitz   2262:                     $check5 = ' checked="checked"';
1.591     raeburn  2263:                     $check4 = '';
                   2264:                 } else {
1.772     bisitz   2265:                     $check4 = ' checked="checked"';
1.591     raeburn  2266:                     $check5 = '';
                   2267:                 }
1.586     raeburn  2268:             }
1.591     raeburn  2269:             if (defined($in{'curr_autharg'})) {
1.165     raeburn  2270:                 $krbarg = $in{'curr_autharg'};
                   2271:             }
1.586     raeburn  2272:             if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591     raeburn  2273:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2274:                     $result = 
                   2275:     &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
                   2276:         $in{'curr_autharg'},$krbver);
                   2277:                 } else {
                   2278:                     $result =
                   2279:     &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
                   2280:                 }
                   2281:                 return $result; 
                   2282:             }
                   2283:         }
                   2284:     } else {
                   2285:         if ($authnum == 1) {
1.784     bisitz   2286:             $authtype = '<input type="hidden" name="login" value="krb" />';
1.165     raeburn  2287:         }
                   2288:     }
1.586     raeburn  2289:     if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
                   2290:         return;
1.587     raeburn  2291:     } elsif ($authtype eq '') {
1.591     raeburn  2292:         if (defined($in{'mode'})) {
1.587     raeburn  2293:             if ($in{'mode'} eq 'modifycourse') {
                   2294:                 if ($authnum == 1) {
1.784     bisitz   2295:                     $authtype = '<input type="hidden" name="login" value="krb" />';
1.587     raeburn  2296:                 }
                   2297:             }
                   2298:         }
1.586     raeburn  2299:     }
                   2300:     $jscall = "javascript:changed_radio('krb',$in{'formname'});";
                   2301:     if ($authtype eq '') {
                   2302:         $authtype = '<input type="radio" name="login" value="krb" '.
                   2303:                     'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
                   2304:                     $krbcheck.' />';
                   2305:     }
                   2306:     if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
                   2307:         ($can_assign{'krb4'} && !$can_assign{'krb5'} && 
                   2308:          $in{'curr_authtype'} eq 'krb5') ||
                   2309:         (!$can_assign{'krb4'} && $can_assign{'krb5'} && 
                   2310:          $in{'curr_authtype'} eq 'krb4')) {
                   2311:         $result .= &mt
1.144     matthew  2312:         ('[_1] Kerberos authenticated with domain [_2] '.
1.281     albertel 2313:          '[_3] Version 4 [_4] Version 5 [_5]',
1.586     raeburn  2314:          '<label>'.$authtype,
1.281     albertel 2315:          '</label><input type="text" size="10" name="krbarg" '.
1.165     raeburn  2316:              'value="'.$krbarg.'" '.
1.144     matthew  2317:              'onchange="'.$jscall.'" />',
1.281     albertel 2318:          '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
                   2319:          '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
                   2320: 	 '</label>');
1.586     raeburn  2321:     } elsif ($can_assign{'krb4'}) {
                   2322:         $result .= &mt
                   2323:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2324:          '[_3] Version 4 [_4]',
                   2325:          '<label>'.$authtype,
                   2326:          '</label><input type="text" size="10" name="krbarg" '.
                   2327:              'value="'.$krbarg.'" '.
                   2328:              'onchange="'.$jscall.'" />',
                   2329:          '<label><input type="hidden" name="krbver" value="4" />',
                   2330:          '</label>');
                   2331:     } elsif ($can_assign{'krb5'}) {
                   2332:         $result .= &mt
                   2333:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2334:          '[_3] Version 5 [_4]',
                   2335:          '<label>'.$authtype,
                   2336:          '</label><input type="text" size="10" name="krbarg" '.
                   2337:              'value="'.$krbarg.'" '.
                   2338:              'onchange="'.$jscall.'" />',
                   2339:          '<label><input type="hidden" name="krbver" value="5" />',
                   2340:          '</label>');
                   2341:     }
1.32      matthew  2342:     return $result;
                   2343: }
                   2344: 
                   2345: sub authform_internal{  
1.586     raeburn  2346:     my %in = (
1.32      matthew  2347:                 formname => 'document.cu',
                   2348:                 kerb_def_dom => 'MSU.EDU',
                   2349:                 @_,
                   2350:                 );
1.586     raeburn  2351:     my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
                   2352:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2353:     if (defined($in{'curr_authtype'})) {
                   2354:         if ($in{'curr_authtype'} eq 'int') {
1.586     raeburn  2355:             if ($can_assign{'int'}) {
1.772     bisitz   2356:                 $intcheck = 'checked="checked" ';
1.623     raeburn  2357:                 if (defined($in{'mode'})) {
                   2358:                     if ($in{'mode'} eq 'modifyuser') {
                   2359:                         $intcheck = '';
                   2360:                     }
                   2361:                 }
1.591     raeburn  2362:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2363:                     $intarg = $in{'curr_autharg'};
                   2364:                 }
                   2365:             } else {
                   2366:                 $result = &mt('Currently internally authenticated.');
                   2367:                 return $result;
1.165     raeburn  2368:             }
                   2369:         }
1.586     raeburn  2370:     } else {
                   2371:         if ($authnum == 1) {
1.784     bisitz   2372:             $authtype = '<input type="hidden" name="login" value="int" />';
1.586     raeburn  2373:         }
                   2374:     }
                   2375:     if (!$can_assign{'int'}) {
                   2376:         return;
1.587     raeburn  2377:     } elsif ($authtype eq '') {
1.591     raeburn  2378:         if (defined($in{'mode'})) {
1.587     raeburn  2379:             if ($in{'mode'} eq 'modifycourse') {
                   2380:                 if ($authnum == 1) {
1.784     bisitz   2381:                     $authtype = '<input type="hidden" name="login" value="int" />';
1.587     raeburn  2382:                 }
                   2383:             }
                   2384:         }
1.165     raeburn  2385:     }
1.586     raeburn  2386:     $jscall = "javascript:changed_radio('int',$in{'formname'});";
                   2387:     if ($authtype eq '') {
                   2388:         $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
                   2389:                     ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
                   2390:     }
1.605     bisitz   2391:     $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586     raeburn  2392:                $intarg.'" onchange="'.$jscall.'" />';
                   2393:     $result = &mt
1.144     matthew  2394:         ('[_1] Internally authenticated (with initial password [_2])',
1.586     raeburn  2395:          '<label>'.$authtype,'</label>'.$autharg);
1.824     bisitz   2396:     $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  2397:     return $result;
                   2398: }
                   2399: 
                   2400: sub authform_local{  
                   2401:     my %in = (
                   2402:               formname => 'document.cu',
                   2403:               kerb_def_dom => 'MSU.EDU',
                   2404:               @_,
                   2405:               );
1.586     raeburn  2406:     my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
                   2407:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2408:     if (defined($in{'curr_authtype'})) {
                   2409:         if ($in{'curr_authtype'} eq 'loc') {
1.586     raeburn  2410:             if ($can_assign{'loc'}) {
1.772     bisitz   2411:                 $loccheck = 'checked="checked" ';
1.623     raeburn  2412:                 if (defined($in{'mode'})) {
                   2413:                     if ($in{'mode'} eq 'modifyuser') {
                   2414:                         $loccheck = '';
                   2415:                     }
                   2416:                 }
1.591     raeburn  2417:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2418:                     $locarg = $in{'curr_autharg'};
                   2419:                 }
                   2420:             } else {
                   2421:                 $result = &mt('Currently using local (institutional) authentication.');
                   2422:                 return $result;
1.165     raeburn  2423:             }
                   2424:         }
1.586     raeburn  2425:     } else {
                   2426:         if ($authnum == 1) {
1.784     bisitz   2427:             $authtype = '<input type="hidden" name="login" value="loc" />';
1.586     raeburn  2428:         }
                   2429:     }
                   2430:     if (!$can_assign{'loc'}) {
                   2431:         return;
1.587     raeburn  2432:     } elsif ($authtype eq '') {
1.591     raeburn  2433:         if (defined($in{'mode'})) {
1.587     raeburn  2434:             if ($in{'mode'} eq 'modifycourse') {
                   2435:                 if ($authnum == 1) {
1.784     bisitz   2436:                     $authtype = '<input type="hidden" name="login" value="loc" />';
1.587     raeburn  2437:                 }
                   2438:             }
                   2439:         }
1.165     raeburn  2440:     }
1.586     raeburn  2441:     $jscall = "javascript:changed_radio('loc',$in{'formname'});";
                   2442:     if ($authtype eq '') {
                   2443:         $authtype = '<input type="radio" name="login" value="loc" '.
                   2444:                     $loccheck.' onchange="'.$jscall.'" onclick="'.
                   2445:                     $jscall.'" />';
                   2446:     }
                   2447:     $autharg = '<input type="text" size="10" name="locarg" value="'.
                   2448:                $locarg.'" onchange="'.$jscall.'" />';
                   2449:     $result = &mt('[_1] Local Authentication with argument [_2]',
                   2450:                   '<label>'.$authtype,'</label>'.$autharg);
1.32      matthew  2451:     return $result;
                   2452: }
                   2453: 
                   2454: sub authform_filesystem{  
                   2455:     my %in = (
                   2456:               formname => 'document.cu',
                   2457:               kerb_def_dom => 'MSU.EDU',
                   2458:               @_,
                   2459:               );
1.586     raeburn  2460:     my ($fsyscheck,$result,$authtype,$autharg,$jscall);
                   2461:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2462:     if (defined($in{'curr_authtype'})) {
                   2463:         if ($in{'curr_authtype'} eq 'fsys') {
1.586     raeburn  2464:             if ($can_assign{'fsys'}) {
1.772     bisitz   2465:                 $fsyscheck = 'checked="checked" ';
1.623     raeburn  2466:                 if (defined($in{'mode'})) {
                   2467:                     if ($in{'mode'} eq 'modifyuser') {
                   2468:                         $fsyscheck = '';
                   2469:                     }
                   2470:                 }
1.586     raeburn  2471:             } else {
                   2472:                 $result = &mt('Currently Filesystem Authenticated.');
                   2473:                 return $result;
                   2474:             }           
                   2475:         }
                   2476:     } else {
                   2477:         if ($authnum == 1) {
1.784     bisitz   2478:             $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586     raeburn  2479:         }
                   2480:     }
                   2481:     if (!$can_assign{'fsys'}) {
                   2482:         return;
1.587     raeburn  2483:     } elsif ($authtype eq '') {
1.591     raeburn  2484:         if (defined($in{'mode'})) {
1.587     raeburn  2485:             if ($in{'mode'} eq 'modifycourse') {
                   2486:                 if ($authnum == 1) {
1.784     bisitz   2487:                     $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587     raeburn  2488:                 }
                   2489:             }
                   2490:         }
1.586     raeburn  2491:     }
                   2492:     $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
                   2493:     if ($authtype eq '') {
                   2494:         $authtype = '<input type="radio" name="login" value="fsys" '.
                   2495:                     $fsyscheck.' onchange="'.$jscall.'" onclick="'.
                   2496:                     $jscall.'" />';
                   2497:     }
                   2498:     $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
                   2499:                ' onchange="'.$jscall.'" />';
                   2500:     $result = &mt
1.144     matthew  2501:         ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281     albertel 2502:          '<label><input type="radio" name="login" value="fsys" '.
1.586     raeburn  2503:          $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605     bisitz   2504:          '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144     matthew  2505:                   'onchange="'.$jscall.'" />');
1.32      matthew  2506:     return $result;
                   2507: }
                   2508: 
1.586     raeburn  2509: sub get_assignable_auth {
                   2510:     my ($dom) = @_;
                   2511:     if ($dom eq '') {
                   2512:         $dom = $env{'request.role.domain'};
                   2513:     }
                   2514:     my %can_assign = (
                   2515:                           krb4 => 1,
                   2516:                           krb5 => 1,
                   2517:                           int  => 1,
                   2518:                           loc  => 1,
                   2519:                      );
                   2520:     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
                   2521:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   2522:         if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
                   2523:             my $authhash = $domconfig{'usercreation'}{'authtypes'};
                   2524:             my $context;
                   2525:             if ($env{'request.role'} =~ /^au/) {
                   2526:                 $context = 'author';
                   2527:             } elsif ($env{'request.role'} =~ /^dc/) {
                   2528:                 $context = 'domain';
                   2529:             } elsif ($env{'request.course.id'}) {
                   2530:                 $context = 'course';
                   2531:             }
                   2532:             if ($context) {
                   2533:                 if (ref($authhash->{$context}) eq 'HASH') {
                   2534:                    %can_assign = %{$authhash->{$context}}; 
                   2535:                 }
                   2536:             }
                   2537:         }
                   2538:     }
                   2539:     my $authnum = 0;
                   2540:     foreach my $key (keys(%can_assign)) {
                   2541:         if ($can_assign{$key}) {
                   2542:             $authnum ++;
                   2543:         }
                   2544:     }
                   2545:     if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
                   2546:         $authnum --;
                   2547:     }
                   2548:     return ($authnum,%can_assign);
                   2549: }
                   2550: 
1.80      albertel 2551: ###############################################################
                   2552: ##    Get Kerberos Defaults for Domain                 ##
                   2553: ###############################################################
                   2554: ##
                   2555: ## Returns default kerberos version and an associated argument
                   2556: ## as listed in file domain.tab. If not listed, provides
                   2557: ## appropriate default domain and kerberos version.
                   2558: ##
                   2559: #-------------------------------------------
                   2560: 
                   2561: =pod
                   2562: 
1.648     raeburn  2563: =item * &get_kerberos_defaults()
1.80      albertel 2564: 
                   2565: get_kerberos_defaults($target_domain) returns the default kerberos
1.641     raeburn  2566: version and domain. If not found, it defaults to version 4 and the 
                   2567: domain of the server.
1.80      albertel 2568: 
1.648     raeburn  2569: =over 4
                   2570: 
1.80      albertel 2571: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
                   2572: 
1.648     raeburn  2573: =back
                   2574: 
                   2575: =back
                   2576: 
1.80      albertel 2577: =cut
                   2578: 
                   2579: #-------------------------------------------
                   2580: sub get_kerberos_defaults {
                   2581:     my $domain=shift;
1.641     raeburn  2582:     my ($krbdef,$krbdefdom);
                   2583:     my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
                   2584:     if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
                   2585:         $krbdef = $domdefaults{'auth_def'};
                   2586:         $krbdefdom = $domdefaults{'auth_arg_def'};
                   2587:     } else {
1.80      albertel 2588:         $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
                   2589:         my $krbdefdom=$1;
                   2590:         $krbdefdom=~tr/a-z/A-Z/;
                   2591:         $krbdef = "krb4";
                   2592:     }
                   2593:     return ($krbdef,$krbdefdom);
                   2594: }
1.112     bowersj2 2595: 
1.32      matthew  2596: 
1.46      matthew  2597: ###############################################################
                   2598: ##                Thesaurus Functions                        ##
                   2599: ###############################################################
1.20      www      2600: 
1.46      matthew  2601: =pod
1.20      www      2602: 
1.112     bowersj2 2603: =head1 Thesaurus Functions
                   2604: 
                   2605: =over 4
                   2606: 
1.648     raeburn  2607: =item * &initialize_keywords()
1.46      matthew  2608: 
                   2609: Initializes the package variable %Keywords if it is empty.  Uses the
                   2610: package variable $thesaurus_db_file.
                   2611: 
                   2612: =cut
                   2613: 
                   2614: ###################################################
                   2615: 
                   2616: sub initialize_keywords {
                   2617:     return 1 if (scalar keys(%Keywords));
                   2618:     # If we are here, %Keywords is empty, so fill it up
                   2619:     #   Make sure the file we need exists...
                   2620:     if (! -e $thesaurus_db_file) {
                   2621:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
                   2622:                                  " failed because it does not exist");
                   2623:         return 0;
                   2624:     }
                   2625:     #   Set up the hash as a database
                   2626:     my %thesaurus_db;
                   2627:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2628:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2629:         &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
                   2630:                                  $thesaurus_db_file);
                   2631:         return 0;
                   2632:     } 
                   2633:     #  Get the average number of appearances of a word.
                   2634:     my $avecount = $thesaurus_db{'average.count'};
                   2635:     #  Put keywords (those that appear > average) into %Keywords
                   2636:     while (my ($word,$data)=each (%thesaurus_db)) {
                   2637:         my ($count,undef) = split /:/,$data;
                   2638:         $Keywords{$word}++ if ($count > $avecount);
                   2639:     }
                   2640:     untie %thesaurus_db;
                   2641:     # Remove special values from %Keywords.
1.356     albertel 2642:     foreach my $value ('total.count','average.count') {
                   2643:         delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586     raeburn  2644:   }
1.46      matthew  2645:     return 1;
                   2646: }
                   2647: 
                   2648: ###################################################
                   2649: 
                   2650: =pod
                   2651: 
1.648     raeburn  2652: =item * &keyword($word)
1.46      matthew  2653: 
                   2654: Returns true if $word is a keyword.  A keyword is a word that appears more 
                   2655: than the average number of times in the thesaurus database.  Calls 
                   2656: &initialize_keywords
                   2657: 
                   2658: =cut
                   2659: 
                   2660: ###################################################
1.20      www      2661: 
                   2662: sub keyword {
1.46      matthew  2663:     return if (!&initialize_keywords());
                   2664:     my $word=lc(shift());
                   2665:     $word=~s/\W//g;
                   2666:     return exists($Keywords{$word});
1.20      www      2667: }
1.46      matthew  2668: 
                   2669: ###############################################################
                   2670: 
                   2671: =pod 
1.20      www      2672: 
1.648     raeburn  2673: =item * &get_related_words()
1.46      matthew  2674: 
1.160     matthew  2675: Look up a word in the thesaurus.  Takes a scalar argument and returns
1.46      matthew  2676: an array of words.  If the keyword is not in the thesaurus, an empty array
                   2677: will be returned.  The order of the words returned is determined by the
                   2678: database which holds them.
                   2679: 
                   2680: Uses global $thesaurus_db_file.
                   2681: 
                   2682: =cut
                   2683: 
                   2684: ###############################################################
                   2685: sub get_related_words {
                   2686:     my $keyword = shift;
                   2687:     my %thesaurus_db;
                   2688:     if (! -e $thesaurus_db_file) {
                   2689:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
                   2690:                                  "failed because the file does not exist");
                   2691:         return ();
                   2692:     }
                   2693:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2694:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2695:         return ();
                   2696:     } 
                   2697:     my @Words=();
1.429     www      2698:     my $count=0;
1.46      matthew  2699:     if (exists($thesaurus_db{$keyword})) {
1.356     albertel 2700: 	# The first element is the number of times
                   2701: 	# the word appears.  We do not need it now.
1.429     www      2702: 	my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
                   2703: 	my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
                   2704: 	my $threshold=$mostfrequentcount/10;
                   2705:         foreach my $possibleword (@RelatedWords) {
                   2706:             my ($word,$wordcount)=split(/\,/,$possibleword);
                   2707:             if ($wordcount>$threshold) {
                   2708: 		push(@Words,$word);
                   2709:                 $count++;
                   2710:                 if ($count>10) { last; }
                   2711: 	    }
1.20      www      2712:         }
                   2713:     }
1.46      matthew  2714:     untie %thesaurus_db;
                   2715:     return @Words;
1.14      harris41 2716: }
1.46      matthew  2717: 
1.112     bowersj2 2718: =pod
                   2719: 
                   2720: =back
                   2721: 
                   2722: =cut
1.61      www      2723: 
                   2724: # -------------------------------------------------------------- Plaintext name
1.81      albertel 2725: =pod
                   2726: 
1.112     bowersj2 2727: =head1 User Name Functions
                   2728: 
                   2729: =over 4
                   2730: 
1.648     raeburn  2731: =item * &plainname($uname,$udom,$first)
1.81      albertel 2732: 
1.112     bowersj2 2733: Takes a users logon name and returns it as a string in
1.226     albertel 2734: "first middle last generation" form 
                   2735: if $first is set to 'lastname' then it returns it as
                   2736: 'lastname generation, firstname middlename' if their is a lastname
1.81      albertel 2737: 
                   2738: =cut
1.61      www      2739: 
1.295     www      2740: 
1.81      albertel 2741: ###############################################################
1.61      www      2742: sub plainname {
1.226     albertel 2743:     my ($uname,$udom,$first)=@_;
1.537     albertel 2744:     return if (!defined($uname) || !defined($udom));
1.295     www      2745:     my %names=&getnames($uname,$udom);
1.226     albertel 2746:     my $name=&Apache::lonnet::format_name($names{'firstname'},
                   2747: 					  $names{'middlename'},
                   2748: 					  $names{'lastname'},
                   2749: 					  $names{'generation'},$first);
                   2750:     $name=~s/^\s+//;
1.62      www      2751:     $name=~s/\s+$//;
                   2752:     $name=~s/\s+/ /g;
1.353     albertel 2753:     if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62      www      2754:     return $name;
1.61      www      2755: }
1.66      www      2756: 
                   2757: # -------------------------------------------------------------------- Nickname
1.81      albertel 2758: =pod
                   2759: 
1.648     raeburn  2760: =item * &nickname($uname,$udom)
1.81      albertel 2761: 
                   2762: Gets a users name and returns it as a string as
                   2763: 
                   2764: "&quot;nickname&quot;"
1.66      www      2765: 
1.81      albertel 2766: if the user has a nickname or
                   2767: 
                   2768: "first middle last generation"
                   2769: 
                   2770: if the user does not
                   2771: 
                   2772: =cut
1.66      www      2773: 
                   2774: sub nickname {
                   2775:     my ($uname,$udom)=@_;
1.537     albertel 2776:     return if (!defined($uname) || !defined($udom));
1.295     www      2777:     my %names=&getnames($uname,$udom);
1.68      albertel 2778:     my $name=$names{'nickname'};
1.66      www      2779:     if ($name) {
                   2780:        $name='&quot;'.$name.'&quot;'; 
                   2781:     } else {
                   2782:        $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
                   2783: 	     $names{'lastname'}.' '.$names{'generation'};
                   2784:        $name=~s/\s+$//;
                   2785:        $name=~s/\s+/ /g;
                   2786:     }
                   2787:     return $name;
                   2788: }
                   2789: 
1.295     www      2790: sub getnames {
                   2791:     my ($uname,$udom)=@_;
1.537     albertel 2792:     return if (!defined($uname) || !defined($udom));
1.433     albertel 2793:     if ($udom eq 'public' && $uname eq 'public') {
                   2794: 	return ('lastname' => &mt('Public'));
                   2795:     }
1.295     www      2796:     my $id=$uname.':'.$udom;
                   2797:     my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
                   2798:     if ($cached) {
                   2799: 	return %{$names};
                   2800:     } else {
                   2801: 	my %loadnames=&Apache::lonnet::get('environment',
                   2802:                     ['firstname','middlename','lastname','generation','nickname'],
                   2803: 					 $udom,$uname);
                   2804: 	&Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
                   2805: 	return %loadnames;
                   2806:     }
                   2807: }
1.61      www      2808: 
1.542     raeburn  2809: # -------------------------------------------------------------------- getemails
1.648     raeburn  2810: 
1.542     raeburn  2811: =pod
                   2812: 
1.648     raeburn  2813: =item * &getemails($uname,$udom)
1.542     raeburn  2814: 
                   2815: Gets a user's email information and returns it as a hash with keys:
                   2816: notification, critnotification, permanentemail
                   2817: 
                   2818: For notification and critnotification, values are comma-separated lists 
1.648     raeburn  2819: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542     raeburn  2820:  
1.648     raeburn  2821: 
1.542     raeburn  2822: =cut
                   2823: 
1.648     raeburn  2824: 
1.466     albertel 2825: sub getemails {
                   2826:     my ($uname,$udom)=@_;
                   2827:     if ($udom eq 'public' && $uname eq 'public') {
                   2828: 	return;
                   2829:     }
1.467     www      2830:     if (!$udom) { $udom=$env{'user.domain'}; }
                   2831:     if (!$uname) { $uname=$env{'user.name'}; }
1.466     albertel 2832:     my $id=$uname.':'.$udom;
                   2833:     my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
                   2834:     if ($cached) {
                   2835: 	return %{$names};
                   2836:     } else {
                   2837: 	my %loadnames=&Apache::lonnet::get('environment',
                   2838:                     			   ['notification','critnotification',
                   2839: 					    'permanentemail'],
                   2840: 					   $udom,$uname);
                   2841: 	&Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
                   2842: 	return %loadnames;
                   2843:     }
                   2844: }
                   2845: 
1.551     albertel 2846: sub flush_email_cache {
                   2847:     my ($uname,$udom)=@_;
                   2848:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2849:     if (!$uname) { $uname=$env{'user.name'};   }
                   2850:     return if ($udom eq 'public' && $uname eq 'public');
                   2851:     my $id=$uname.':'.$udom;
                   2852:     &Apache::lonnet::devalidate_cache_new('emailscache',$id);
                   2853: }
                   2854: 
1.728     raeburn  2855: # -------------------------------------------------------------------- getlangs
                   2856: 
                   2857: =pod
                   2858: 
                   2859: =item * &getlangs($uname,$udom)
                   2860: 
                   2861: Gets a user's language preference and returns it as a hash with key:
                   2862: language.
                   2863: 
                   2864: =cut
                   2865: 
                   2866: 
                   2867: sub getlangs {
                   2868:     my ($uname,$udom) = @_;
                   2869:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2870:     if (!$uname) { $uname=$env{'user.name'};   }
                   2871:     my $id=$uname.':'.$udom;
                   2872:     my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
                   2873:     if ($cached) {
                   2874:         return %{$langs};
                   2875:     } else {
                   2876:         my %loadlangs=&Apache::lonnet::get('environment',['languages'],
                   2877:                                            $udom,$uname);
                   2878:         &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
                   2879:         return %loadlangs;
                   2880:     }
                   2881: }
                   2882: 
                   2883: sub flush_langs_cache {
                   2884:     my ($uname,$udom)=@_;
                   2885:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2886:     if (!$uname) { $uname=$env{'user.name'};   }
                   2887:     return if ($udom eq 'public' && $uname eq 'public');
                   2888:     my $id=$uname.':'.$udom;
                   2889:     &Apache::lonnet::devalidate_cache_new('userlangs',$id);
                   2890: }
                   2891: 
1.61      www      2892: # ------------------------------------------------------------------ Screenname
1.81      albertel 2893: 
                   2894: =pod
                   2895: 
1.648     raeburn  2896: =item * &screenname($uname,$udom)
1.81      albertel 2897: 
                   2898: Gets a users screenname and returns it as a string
                   2899: 
                   2900: =cut
1.61      www      2901: 
                   2902: sub screenname {
                   2903:     my ($uname,$udom)=@_;
1.258     albertel 2904:     if ($uname eq $env{'user.name'} &&
                   2905: 	$udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212     albertel 2906:     my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68      albertel 2907:     return $names{'screenname'};
1.62      www      2908: }
                   2909: 
1.212     albertel 2910: 
1.802     bisitz   2911: # ------------------------------------------------------------- Confirm Wrapper
                   2912: =pod
                   2913: 
                   2914: =item confirmwrapper
                   2915: 
                   2916: Wrap messages about completion of operation in box
                   2917: 
                   2918: =cut
                   2919: 
                   2920: sub confirmwrapper {
                   2921:     my ($message)=@_;
                   2922:     if ($message) {
                   2923:         return "\n".'<div class="LC_confirm_box">'."\n"
                   2924:                .$message."\n"
                   2925:                .'</div>'."\n";
                   2926:     } else {
                   2927:         return $message;
                   2928:     }
                   2929: }
                   2930: 
1.62      www      2931: # ------------------------------------------------------------- Message Wrapper
                   2932: 
                   2933: sub messagewrapper {
1.369     www      2934:     my ($link,$username,$domain,$subject,$text)=@_;
1.62      www      2935:     return 
1.441     albertel 2936:         '<a href="/adm/email?compose=individual&amp;'.
                   2937:         'recname='.$username.'&amp;recdom='.$domain.
                   2938: 	'&amp;subject='.&escape($subject).'&amp;text='.&escape($text).'" '.
1.200     matthew  2939:         'title="'.&mt('Send message').'">'.$link.'</a>';
1.74      www      2940: }
1.802     bisitz   2941: 
1.74      www      2942: # --------------------------------------------------------------- Notes Wrapper
                   2943: 
                   2944: sub noteswrapper {
                   2945:     my ($link,$un,$do)=@_;
                   2946:     return 
                   2947: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62      www      2948: }
1.802     bisitz   2949: 
1.62      www      2950: # ------------------------------------------------------------- Aboutme Wrapper
                   2951: 
                   2952: sub aboutmewrapper {
1.166     www      2953:     my ($link,$username,$domain,$target)=@_;
1.447     raeburn  2954:     if (!defined($username)  && !defined($domain)) {
                   2955:         return;
                   2956:     }
1.205     www      2957:     return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.756     weissno  2958: 	($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62      www      2959: }
                   2960: 
                   2961: # ------------------------------------------------------------ Syllabus Wrapper
                   2962: 
                   2963: sub syllabuswrapper {
1.707     bisitz   2964:     my ($linktext,$coursedir,$domain)=@_;
1.208     matthew  2965:     return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61      www      2966: }
1.14      harris41 2967: 
1.802     bisitz   2968: # -----------------------------------------------------------------------------
                   2969: 
1.208     matthew  2970: sub track_student_link {
1.268     albertel 2971:     my ($linktext,$sname,$sdom,$target,$start) = @_;
                   2972:     my $link ="/adm/trackstudent?";
1.208     matthew  2973:     my $title = 'View recent activity';
                   2974:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   2975:         defined($sdom)  && $sdom  !~ /^\s*$/) {
1.268     albertel 2976:         $link .= "selected_student=$sname:$sdom";
1.208     matthew  2977:         $title .= ' of this student';
1.268     albertel 2978:     } 
1.208     matthew  2979:     if (defined($target) && $target !~ /^\s*$/) {
                   2980:         $target = qq{target="$target"};
                   2981:     } else {
                   2982:         $target = '';
                   2983:     }
1.268     albertel 2984:     if ($start) { $link.='&amp;start='.$start; }
1.554     albertel 2985:     $title = &mt($title);
                   2986:     $linktext = &mt($linktext);
1.448     albertel 2987:     return qq{<a href="$link" title="$title" $target>$linktext</a>}.
                   2988: 	&help_open_topic('View_recent_activity');
1.208     matthew  2989: }
                   2990: 
1.781     raeburn  2991: sub slot_reservations_link {
                   2992:     my ($linktext,$sname,$sdom,$target) = @_;
                   2993:     my $link ="/adm/slotrequest?command=showresv&amp;origin=aboutme";
                   2994:     my $title = 'View slot reservation history';
                   2995:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   2996:         defined($sdom)  && $sdom  !~ /^\s*$/) {
                   2997:         $link .= "&amp;uname=$sname&amp;udom=$sdom";
                   2998:         $title .= ' of this student';
                   2999:     }
                   3000:     if (defined($target) && $target !~ /^\s*$/) {
                   3001:         $target = qq{target="$target"};
                   3002:     } else {
                   3003:         $target = '';
                   3004:     }
                   3005:     $title = &mt($title);
                   3006:     $linktext = &mt($linktext);
                   3007:     return qq{<a href="$link" title="$title" $target>$linktext</a>};
                   3008: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
                   3009: 
                   3010: }
                   3011: 
1.508     www      3012: # ===================================================== Display a student photo
                   3013: 
                   3014: 
1.509     albertel 3015: sub student_image_tag {
1.508     www      3016:     my ($domain,$user)=@_;
                   3017:     my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
                   3018:     if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
                   3019: 	return '<img src="'.$imgsrc.'" align="right" />';
                   3020:     } else {
                   3021: 	return '';
                   3022:     }
                   3023: }
                   3024: 
1.112     bowersj2 3025: =pod
                   3026: 
                   3027: =back
                   3028: 
                   3029: =head1 Access .tab File Data
                   3030: 
                   3031: =over 4
                   3032: 
1.648     raeburn  3033: =item * &languageids() 
1.112     bowersj2 3034: 
                   3035: returns list of all language ids
                   3036: 
                   3037: =cut
                   3038: 
1.14      harris41 3039: sub languageids {
1.16      harris41 3040:     return sort(keys(%language));
1.14      harris41 3041: }
                   3042: 
1.112     bowersj2 3043: =pod
                   3044: 
1.648     raeburn  3045: =item * &languagedescription() 
1.112     bowersj2 3046: 
                   3047: returns description of a specified language id
                   3048: 
                   3049: =cut
                   3050: 
1.14      harris41 3051: sub languagedescription {
1.125     www      3052:     my $code=shift;
                   3053:     return  ($supported_language{$code}?'* ':'').
                   3054:             $language{$code}.
1.126     www      3055: 	    ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145     www      3056: }
                   3057: 
                   3058: sub plainlanguagedescription {
                   3059:     my $code=shift;
                   3060:     return $language{$code};
                   3061: }
                   3062: 
                   3063: sub supportedlanguagecode {
                   3064:     my $code=shift;
                   3065:     return $supported_language{$code};
1.97      www      3066: }
                   3067: 
1.112     bowersj2 3068: =pod
                   3069: 
1.648     raeburn  3070: =item * &copyrightids() 
1.112     bowersj2 3071: 
                   3072: returns list of all copyrights
                   3073: 
                   3074: =cut
                   3075: 
                   3076: sub copyrightids {
                   3077:     return sort(keys(%cprtag));
                   3078: }
                   3079: 
                   3080: =pod
                   3081: 
1.648     raeburn  3082: =item * &copyrightdescription() 
1.112     bowersj2 3083: 
                   3084: returns description of a specified copyright id
                   3085: 
                   3086: =cut
                   3087: 
                   3088: sub copyrightdescription {
1.166     www      3089:     return &mt($cprtag{shift(@_)});
1.112     bowersj2 3090: }
1.197     matthew  3091: 
                   3092: =pod
                   3093: 
1.648     raeburn  3094: =item * &source_copyrightids() 
1.192     taceyjo1 3095: 
                   3096: returns list of all source copyrights
                   3097: 
                   3098: =cut
                   3099: 
                   3100: sub source_copyrightids {
                   3101:     return sort(keys(%scprtag));
                   3102: }
                   3103: 
                   3104: =pod
                   3105: 
1.648     raeburn  3106: =item * &source_copyrightdescription() 
1.192     taceyjo1 3107: 
                   3108: returns description of a specified source copyright id
                   3109: 
                   3110: =cut
                   3111: 
                   3112: sub source_copyrightdescription {
                   3113:     return &mt($scprtag{shift(@_)});
                   3114: }
1.112     bowersj2 3115: 
                   3116: =pod
                   3117: 
1.648     raeburn  3118: =item * &filecategories() 
1.112     bowersj2 3119: 
                   3120: returns list of all file categories
                   3121: 
                   3122: =cut
                   3123: 
                   3124: sub filecategories {
                   3125:     return sort(keys(%category_extensions));
                   3126: }
                   3127: 
                   3128: =pod
                   3129: 
1.648     raeburn  3130: =item * &filecategorytypes() 
1.112     bowersj2 3131: 
                   3132: returns list of file types belonging to a given file
                   3133: category
                   3134: 
                   3135: =cut
                   3136: 
                   3137: sub filecategorytypes {
1.356     albertel 3138:     my ($cat) = @_;
                   3139:     return @{$category_extensions{lc($cat)}};
1.112     bowersj2 3140: }
                   3141: 
                   3142: =pod
                   3143: 
1.648     raeburn  3144: =item * &fileembstyle() 
1.112     bowersj2 3145: 
                   3146: returns embedding style for a specified file type
                   3147: 
                   3148: =cut
                   3149: 
                   3150: sub fileembstyle {
                   3151:     return $fe{lc(shift(@_))};
1.169     www      3152: }
                   3153: 
1.351     www      3154: sub filemimetype {
                   3155:     return $fm{lc(shift(@_))};
                   3156: }
                   3157: 
1.169     www      3158: 
                   3159: sub filecategoryselect {
                   3160:     my ($name,$value)=@_;
1.189     matthew  3161:     return &select_form($value,$name,
1.169     www      3162: 			'' => &mt('Any category'),
                   3163: 			map { $_,$_ } sort(keys(%category_extensions)));
1.112     bowersj2 3164: }
                   3165: 
                   3166: =pod
                   3167: 
1.648     raeburn  3168: =item * &filedescription() 
1.112     bowersj2 3169: 
                   3170: returns description for a specified file type
                   3171: 
                   3172: =cut
                   3173: 
                   3174: sub filedescription {
1.188     matthew  3175:     my $file_description = $fd{lc(shift())};
                   3176:     $file_description =~ s:([\[\]]):~$1:g;
                   3177:     return &mt($file_description);
1.112     bowersj2 3178: }
                   3179: 
                   3180: =pod
                   3181: 
1.648     raeburn  3182: =item * &filedescriptionex() 
1.112     bowersj2 3183: 
                   3184: returns description for a specified file type with
                   3185: extra formatting
                   3186: 
                   3187: =cut
                   3188: 
                   3189: sub filedescriptionex {
                   3190:     my $ex=shift;
1.188     matthew  3191:     my $file_description = $fd{lc($ex)};
                   3192:     $file_description =~ s:([\[\]]):~$1:g;
                   3193:     return '.'.$ex.' '.&mt($file_description);
1.112     bowersj2 3194: }
                   3195: 
                   3196: # End of .tab access
                   3197: =pod
                   3198: 
                   3199: =back
                   3200: 
                   3201: =cut
                   3202: 
                   3203: # ------------------------------------------------------------------ File Types
                   3204: sub fileextensions {
                   3205:     return sort(keys(%fe));
                   3206: }
                   3207: 
1.97      www      3208: # ----------------------------------------------------------- Display Languages
                   3209: # returns a hash with all desired display languages
                   3210: #
                   3211: 
                   3212: sub display_languages {
                   3213:     my %languages=();
1.695     raeburn  3214:     foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356     albertel 3215: 	$languages{$lang}=1;
1.97      www      3216:     }
                   3217:     &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258     albertel 3218:     if ($env{'form.displaylanguage'}) {
1.356     albertel 3219: 	foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
                   3220: 	    $languages{$lang}=1;
1.97      www      3221:         }
                   3222:     }
                   3223:     return %languages;
1.14      harris41 3224: }
                   3225: 
1.582     albertel 3226: sub languages {
                   3227:     my ($possible_langs) = @_;
1.695     raeburn  3228:     my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582     albertel 3229:     if (!ref($possible_langs)) {
                   3230: 	if( wantarray ) {
                   3231: 	    return @preferred_langs;
                   3232: 	} else {
                   3233: 	    return $preferred_langs[0];
                   3234: 	}
                   3235:     }
                   3236:     my %possibilities = map { $_ => 1 } (@$possible_langs);
                   3237:     my @preferred_possibilities;
                   3238:     foreach my $preferred_lang (@preferred_langs) {
                   3239: 	if (exists($possibilities{$preferred_lang})) {
                   3240: 	    push(@preferred_possibilities, $preferred_lang);
                   3241: 	}
                   3242:     }
                   3243:     if( wantarray ) {
                   3244: 	return @preferred_possibilities;
                   3245:     }
                   3246:     return $preferred_possibilities[0];
                   3247: }
                   3248: 
1.742     raeburn  3249: sub user_lang {
                   3250:     my ($touname,$toudom,$fromcid) = @_;
                   3251:     my @userlangs;
                   3252:     if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
                   3253:         @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
                   3254:                     $env{'course.'.$fromcid.'.languages'}));
                   3255:     } else {
                   3256:         my %langhash = &getlangs($touname,$toudom);
                   3257:         if ($langhash{'languages'} ne '') {
                   3258:             @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
                   3259:         } else {
                   3260:             my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
                   3261:             if ($domdefs{'lang_def'} ne '') {
                   3262:                 @userlangs = ($domdefs{'lang_def'});
                   3263:             }
                   3264:         }
                   3265:     }
                   3266:     my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
                   3267:     my $user_lh = Apache::localize->get_handle(@languages);
                   3268:     return $user_lh;
                   3269: }
                   3270: 
                   3271: 
1.112     bowersj2 3272: ###############################################################
                   3273: ##               Student Answer Attempts                     ##
                   3274: ###############################################################
                   3275: 
                   3276: =pod
                   3277: 
                   3278: =head1 Alternate Problem Views
                   3279: 
                   3280: =over 4
                   3281: 
1.648     raeburn  3282: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112     bowersj2 3283:     $getattempt, $regexp, $gradesub)
                   3284: 
                   3285: Return string with previous attempt on problem. Arguments:
                   3286: 
                   3287: =over 4
                   3288: 
                   3289: =item * $symb: Problem, including path
                   3290: 
                   3291: =item * $username: username of the desired student
                   3292: 
                   3293: =item * $domain: domain of the desired student
1.14      harris41 3294: 
1.112     bowersj2 3295: =item * $course: Course ID
1.14      harris41 3296: 
1.112     bowersj2 3297: =item * $getattempt: Leave blank for all attempts, otherwise put
                   3298:     something
1.14      harris41 3299: 
1.112     bowersj2 3300: =item * $regexp: if string matches this regexp, the string will be
                   3301:     sent to $gradesub
1.14      harris41 3302: 
1.112     bowersj2 3303: =item * $gradesub: routine that processes the string if it matches $regexp
1.14      harris41 3304: 
1.112     bowersj2 3305: =back
1.14      harris41 3306: 
1.112     bowersj2 3307: The output string is a table containing all desired attempts, if any.
1.16      harris41 3308: 
1.112     bowersj2 3309: =cut
1.1       albertel 3310: 
                   3311: sub get_previous_attempt {
1.43      ng       3312:   my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1       albertel 3313:   my $prevattempts='';
1.43      ng       3314:   no strict 'refs';
1.1       albertel 3315:   if ($symb) {
1.3       albertel 3316:     my (%returnhash)=
                   3317:       &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1       albertel 3318:     if ($returnhash{'version'}) {
                   3319:       my %lasthash=();
                   3320:       my $version;
                   3321:       for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356     albertel 3322:         foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
                   3323: 	  $lasthash{$key}=$returnhash{$version.':'.$key};
1.19      harris41 3324:         }
1.1       albertel 3325:       }
1.596     albertel 3326:       $prevattempts=&start_data_table().&start_data_table_header_row();
                   3327:       $prevattempts.='<th>'.&mt('History').'</th>';
1.356     albertel 3328:       foreach my $key (sort(keys(%lasthash))) {
                   3329: 	my ($ign,@parts) = split(/\./,$key);
1.41      ng       3330: 	if ($#parts > 0) {
1.31      albertel 3331: 	  my $data=$parts[-1];
                   3332: 	  pop(@parts);
1.596     albertel 3333: 	  $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.'&nbsp;</th>';
1.31      albertel 3334: 	} else {
1.41      ng       3335: 	  if ($#parts == 0) {
                   3336: 	    $prevattempts.='<th>'.$parts[0].'</th>';
                   3337: 	  } else {
                   3338: 	    $prevattempts.='<th>'.$ign.'</th>';
                   3339: 	  }
1.31      albertel 3340: 	}
1.16      harris41 3341:       }
1.596     albertel 3342:       $prevattempts.=&end_data_table_header_row();
1.40      ng       3343:       if ($getattempt eq '') {
                   3344: 	for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596     albertel 3345: 	  $prevattempts.=&start_data_table_row().
                   3346: 	      '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356     albertel 3347: 	    foreach my $key (sort(keys(%lasthash))) {
1.581     albertel 3348: 		my $value = &format_previous_attempt_value($key,
                   3349: 							   $returnhash{$version.':'.$key});
                   3350: 		$prevattempts.='<td>'.$value.'&nbsp;</td>';   
1.40      ng       3351: 	    }
1.596     albertel 3352: 	  $prevattempts.=&end_data_table_row();
1.40      ng       3353: 	 }
1.1       albertel 3354:       }
1.596     albertel 3355:       $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356     albertel 3356:       foreach my $key (sort(keys(%lasthash))) {
1.581     albertel 3357: 	my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356     albertel 3358: 	if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40      ng       3359: 	$prevattempts.='<td>'.$value.'&nbsp;</td>';
1.16      harris41 3360:       }
1.596     albertel 3361:       $prevattempts.= &end_data_table_row().&end_data_table();
1.1       albertel 3362:     } else {
1.596     albertel 3363:       $prevattempts=
                   3364: 	  &start_data_table().&start_data_table_row().
                   3365: 	  '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
                   3366: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3367:     }
                   3368:   } else {
1.596     albertel 3369:     $prevattempts=
                   3370: 	  &start_data_table().&start_data_table_row().
                   3371: 	  '<td>'.&mt('No data.').'</td>'.
                   3372: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3373:   }
1.10      albertel 3374: }
                   3375: 
1.581     albertel 3376: sub format_previous_attempt_value {
                   3377:     my ($key,$value) = @_;
                   3378:     if ($key =~ /timestamp/) {
                   3379: 	$value = &Apache::lonlocal::locallocaltime($value);
                   3380:     } elsif (ref($value) eq 'ARRAY') {
                   3381: 	$value = '('.join(', ', @{ $value }).')';
                   3382:     } else {
                   3383: 	$value = &unescape($value);
                   3384:     }
                   3385:     return $value;
                   3386: }
                   3387: 
                   3388: 
1.107     albertel 3389: sub relative_to_absolute {
                   3390:     my ($url,$output)=@_;
                   3391:     my $parser=HTML::TokeParser->new(\$output);
                   3392:     my $token;
                   3393:     my $thisdir=$url;
                   3394:     my @rlinks=();
                   3395:     while ($token=$parser->get_token) {
                   3396: 	if ($token->[0] eq 'S') {
                   3397: 	    if ($token->[1] eq 'a') {
                   3398: 		if ($token->[2]->{'href'}) {
                   3399: 		    $rlinks[$#rlinks+1]=$token->[2]->{'href'};
                   3400: 		}
                   3401: 	    } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
                   3402: 		$rlinks[$#rlinks+1]=$token->[2]->{'src'};
                   3403: 	    } elsif ($token->[1] eq 'base') {
                   3404: 		$thisdir=$token->[2]->{'href'};
                   3405: 	    }
                   3406: 	}
                   3407:     }
                   3408:     $thisdir=~s-/[^/]*$--;
1.356     albertel 3409:     foreach my $link (@rlinks) {
1.726     raeburn  3410: 	unless (($link=~/^https?\:\/\//i) ||
1.356     albertel 3411: 		($link=~/^\//) ||
                   3412: 		($link=~/^javascript:/i) ||
                   3413: 		($link=~/^mailto:/i) ||
                   3414: 		($link=~/^\#/)) {
                   3415: 	    my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
                   3416: 	    $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107     albertel 3417: 	}
                   3418:     }
                   3419: # -------------------------------------------------- Deal with Applet codebases
                   3420:     $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
                   3421:     return $output;
                   3422: }
                   3423: 
1.112     bowersj2 3424: =pod
                   3425: 
1.648     raeburn  3426: =item * &get_student_view()
1.112     bowersj2 3427: 
                   3428: show a snapshot of what student was looking at
                   3429: 
                   3430: =cut
                   3431: 
1.10      albertel 3432: sub get_student_view {
1.186     albertel 3433:   my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114     www      3434:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3435:   my (%form);
1.10      albertel 3436:   my @elements=('symb','courseid','domain','username');
                   3437:   foreach my $element (@elements) {
1.186     albertel 3438:       $form{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3439:   }
1.186     albertel 3440:   if (defined($moreenv)) {
                   3441:       %form=(%form,%{$moreenv});
                   3442:   }
1.236     albertel 3443:   if (defined($target)) { $form{'grade_target'} = $target; }
1.107     albertel 3444:   $feedurl=&Apache::lonnet::clutter($feedurl);
1.650     www      3445:   my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11      albertel 3446:   $userview=~s/\<body[^\>]*\>//gi;
                   3447:   $userview=~s/\<\/body\>//gi;
                   3448:   $userview=~s/\<html\>//gi;
                   3449:   $userview=~s/\<\/html\>//gi;
                   3450:   $userview=~s/\<head\>//gi;
                   3451:   $userview=~s/\<\/head\>//gi;
                   3452:   $userview=~s/action\s*\=/would_be_action\=/gi;
1.107     albertel 3453:   $userview=&relative_to_absolute($feedurl,$userview);
1.650     www      3454:   if (wantarray) {
                   3455:      return ($userview,$response);
                   3456:   } else {
                   3457:      return $userview;
                   3458:   }
                   3459: }
                   3460: 
                   3461: sub get_student_view_with_retries {
                   3462:   my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
                   3463: 
                   3464:     my $ok = 0;                 # True if we got a good response.
                   3465:     my $content;
                   3466:     my $response;
                   3467: 
                   3468:     # Try to get the student_view done. within the retries count:
                   3469:     
                   3470:     do {
                   3471:          ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
                   3472:          $ok      = $response->is_success;
                   3473:          if (!$ok) {
                   3474:             &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
                   3475:          }
                   3476:          $retries--;
                   3477:     } while (!$ok && ($retries > 0));
                   3478:     
                   3479:     if (!$ok) {
                   3480:        $content = '';          # On error return an empty content.
                   3481:     }
1.651     www      3482:     if (wantarray) {
                   3483:        return ($content, $response);
                   3484:     } else {
                   3485:        return $content;
                   3486:     }
1.11      albertel 3487: }
                   3488: 
1.112     bowersj2 3489: =pod
                   3490: 
1.648     raeburn  3491: =item * &get_student_answers() 
1.112     bowersj2 3492: 
                   3493: show a snapshot of how student was answering problem
                   3494: 
                   3495: =cut
                   3496: 
1.11      albertel 3497: sub get_student_answers {
1.100     sakharuk 3498:   my ($symb,$username,$domain,$courseid,%form) = @_;
1.114     www      3499:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3500:   my (%moreenv);
1.11      albertel 3501:   my @elements=('symb','courseid','domain','username');
                   3502:   foreach my $element (@elements) {
1.186     albertel 3503:     $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3504:   }
1.186     albertel 3505:   $moreenv{'grade_target'}='answer';
                   3506:   %moreenv=(%form,%moreenv);
1.497     raeburn  3507:   $feedurl = &Apache::lonnet::clutter($feedurl);
                   3508:   my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10      albertel 3509:   return $userview;
1.1       albertel 3510: }
1.116     albertel 3511: 
                   3512: =pod
                   3513: 
                   3514: =item * &submlink()
                   3515: 
1.242     albertel 3516: Inputs: $text $uname $udom $symb $target
1.116     albertel 3517: 
                   3518: Returns: A link to grades.pm such as to see the SUBM view of a student
                   3519: 
                   3520: =cut
                   3521: 
                   3522: ###############################################
                   3523: sub submlink {
1.242     albertel 3524:     my ($text,$uname,$udom,$symb,$target)=@_;
1.116     albertel 3525:     if (!($uname && $udom)) {
                   3526: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3527: 	    &Apache::lonnet::whichuser($symb);
1.116     albertel 3528: 	if (!$symb) { $symb=$cursymb; }
                   3529:     }
1.254     matthew  3530:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3531:     $symb=&escape($symb);
1.242     albertel 3532:     if ($target) { $target="target=\"$target\""; }
                   3533:     return '<a href="/adm/grades?&command=submission&'.
                   3534: 	'symb='.$symb.'&student='.$uname.
                   3535: 	'&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
                   3536: }
                   3537: ##############################################
                   3538: 
                   3539: =pod
                   3540: 
                   3541: =item * &pgrdlink()
                   3542: 
                   3543: Inputs: $text $uname $udom $symb $target
                   3544: 
                   3545: Returns: A link to grades.pm such as to see the PGRD view of a student
                   3546: 
                   3547: =cut
                   3548: 
                   3549: ###############################################
                   3550: sub pgrdlink {
                   3551:     my $link=&submlink(@_);
                   3552:     $link=~s/(&command=submission)/$1&showgrading=yes/;
                   3553:     return $link;
                   3554: }
                   3555: ##############################################
                   3556: 
                   3557: =pod
                   3558: 
                   3559: =item * &pprmlink()
                   3560: 
                   3561: Inputs: $text $uname $udom $symb $target
                   3562: 
                   3563: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283     albertel 3564: student and a specific resource
1.242     albertel 3565: 
                   3566: =cut
                   3567: 
                   3568: ###############################################
                   3569: sub pprmlink {
                   3570:     my ($text,$uname,$udom,$symb,$target)=@_;
                   3571:     if (!($uname && $udom)) {
                   3572: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3573: 	    &Apache::lonnet::whichuser($symb);
1.242     albertel 3574: 	if (!$symb) { $symb=$cursymb; }
                   3575:     }
1.254     matthew  3576:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3577:     $symb=&escape($symb);
1.242     albertel 3578:     if ($target) { $target="target=\"$target\""; }
1.595     albertel 3579:     return '<a href="/adm/parmset?command=set&amp;'.
                   3580: 	'symb='.$symb.'&amp;uname='.$uname.
                   3581: 	'&amp;udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116     albertel 3582: }
                   3583: ##############################################
1.37      matthew  3584: 
1.112     bowersj2 3585: =pod
                   3586: 
                   3587: =back
                   3588: 
                   3589: =cut
                   3590: 
1.37      matthew  3591: ###############################################
1.51      www      3592: 
                   3593: 
                   3594: sub timehash {
1.687     raeburn  3595:     my ($thistime) = @_;
                   3596:     my $timezone = &Apache::lonlocal::gettimezone();
                   3597:     my $dt = DateTime->from_epoch(epoch => $thistime)
                   3598:                      ->set_time_zone($timezone);
                   3599:     my $wday = $dt->day_of_week();
                   3600:     if ($wday == 7) { $wday = 0; }
                   3601:     return ( 'second' => $dt->second(),
                   3602:              'minute' => $dt->minute(),
                   3603:              'hour'   => $dt->hour(),
                   3604:              'day'     => $dt->day_of_month(),
                   3605:              'month'   => $dt->month(),
                   3606:              'year'    => $dt->year(),
                   3607:              'weekday' => $wday,
                   3608:              'dayyear' => $dt->day_of_year(),
                   3609:              'dlsav'   => $dt->is_dst() );
1.51      www      3610: }
                   3611: 
1.370     www      3612: sub utc_string {
                   3613:     my ($date)=@_;
1.371     www      3614:     return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370     www      3615: }
                   3616: 
1.51      www      3617: sub maketime {
                   3618:     my %th=@_;
1.687     raeburn  3619:     my ($epoch_time,$timezone,$dt);
                   3620:     $timezone = &Apache::lonlocal::gettimezone();
                   3621:     eval {
                   3622:         $dt = DateTime->new( year   => $th{'year'},
                   3623:                              month  => $th{'month'},
                   3624:                              day    => $th{'day'},
                   3625:                              hour   => $th{'hour'},
                   3626:                              minute => $th{'minute'},
                   3627:                              second => $th{'second'},
                   3628:                              time_zone => $timezone,
                   3629:                          );
                   3630:     };
                   3631:     if (!$@) {
                   3632:         $epoch_time = $dt->epoch;
                   3633:         if ($epoch_time) {
                   3634:             return $epoch_time;
                   3635:         }
                   3636:     }
1.51      www      3637:     return POSIX::mktime(
                   3638:         ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210     www      3639:          $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70      www      3640: }
                   3641: 
                   3642: #########################################
1.51      www      3643: 
                   3644: sub findallcourses {
1.482     raeburn  3645:     my ($roles,$uname,$udom) = @_;
1.355     albertel 3646:     my %roles;
                   3647:     if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348     albertel 3648:     my %courses;
1.51      www      3649:     my $now=time;
1.482     raeburn  3650:     if (!defined($uname)) {
                   3651:         $uname = $env{'user.name'};
                   3652:     }
                   3653:     if (!defined($udom)) {
                   3654:         $udom = $env{'user.domain'};
                   3655:     }
                   3656:     if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
                   3657:         my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
                   3658:         if (!%roles) {
                   3659:             %roles = (
                   3660:                        cc => 1,
                   3661:                        in => 1,
                   3662:                        ep => 1,
                   3663:                        ta => 1,
                   3664:                        cr => 1,
                   3665:                        st => 1,
                   3666:              );
                   3667:         }
                   3668:         foreach my $entry (keys(%roleshash)) {
                   3669:             my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
                   3670:             if ($trole =~ /^cr/) { 
                   3671:                 next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
                   3672:             } else {
                   3673:                 next if (!exists($roles{$trole}));
                   3674:             }
                   3675:             if ($tend) {
                   3676:                 next if ($tend < $now);
                   3677:             }
                   3678:             if ($tstart) {
                   3679:                 next if ($tstart > $now);
                   3680:             }
                   3681:             my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
                   3682:             (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
                   3683:             if ($secpart eq '') {
                   3684:                 ($cnum,$role) = split(/_/,$cnumpart); 
                   3685:                 $sec = 'none';
                   3686:                 $realsec = '';
                   3687:             } else {
                   3688:                 $cnum = $cnumpart;
                   3689:                 ($sec,$role) = split(/_/,$secpart);
                   3690:                 $realsec = $sec;
1.490     raeburn  3691:             }
1.482     raeburn  3692:             $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
                   3693:         }
                   3694:     } else {
                   3695:         foreach my $key (keys(%env)) {
1.483     albertel 3696: 	    if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
                   3697:                  $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482     raeburn  3698: 	        my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
                   3699: 	        next if ($role eq 'ca' || $role eq 'aa');
                   3700: 	        next if (%roles && !exists($roles{$role}));
                   3701: 	        my ($starttime,$endtime)=split(/\./,$env{$key});
                   3702:                 my $active=1;
                   3703:                 if ($starttime) {
                   3704: 		    if ($now<$starttime) { $active=0; }
                   3705:                 }
                   3706:                 if ($endtime) {
                   3707:                     if ($now>$endtime) { $active=0; }
                   3708:                 }
                   3709:                 if ($active) {
                   3710:                     if ($sec eq '') {
                   3711:                         $sec = 'none';
                   3712:                     }
                   3713:                     $courses{$cdom.'_'.$cnum}{$sec} = 
                   3714:                                      $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474     raeburn  3715:                 }
                   3716:             }
1.51      www      3717:         }
                   3718:     }
1.474     raeburn  3719:     return %courses;
1.51      www      3720: }
1.37      matthew  3721: 
1.54      www      3722: ###############################################
1.474     raeburn  3723: 
                   3724: sub blockcheck {
1.482     raeburn  3725:     my ($setters,$activity,$uname,$udom) = @_;
1.490     raeburn  3726: 
                   3727:     if (!defined($udom)) {
                   3728:         $udom = $env{'user.domain'};
                   3729:     }
                   3730:     if (!defined($uname)) {
                   3731:         $uname = $env{'user.name'};
                   3732:     }
                   3733: 
                   3734:     # If uname and udom are for a course, check for blocks in the course.
                   3735: 
                   3736:     if (&Apache::lonnet::is_course($udom,$uname)) {
                   3737:         my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502     raeburn  3738:         my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490     raeburn  3739:         return ($startblock,$endblock);
                   3740:     }
1.474     raeburn  3741: 
1.502     raeburn  3742:     my $startblock = 0;
                   3743:     my $endblock = 0;
1.482     raeburn  3744:     my %live_courses = &findallcourses(undef,$uname,$udom);
1.474     raeburn  3745: 
1.490     raeburn  3746:     # If uname is for a user, and activity is course-specific, i.e.,
                   3747:     # boards, chat or groups, check for blocking in current course only.
1.474     raeburn  3748: 
1.490     raeburn  3749:     if (($activity eq 'boards' || $activity eq 'chat' ||
                   3750:          $activity eq 'groups') && ($env{'request.course.id'})) {
                   3751:         foreach my $key (keys(%live_courses)) {
                   3752:             if ($key ne $env{'request.course.id'}) {
                   3753:                 delete($live_courses{$key});
                   3754:             }
                   3755:         }
                   3756:     }
                   3757: 
                   3758:     my $otheruser = 0;
                   3759:     my %own_courses;
                   3760:     if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
                   3761:         # Resource belongs to user other than current user.
                   3762:         $otheruser = 1;
                   3763:         # Gather courses for current user
                   3764:         %own_courses = 
                   3765:             &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
                   3766:     }
                   3767: 
                   3768:     # Gather active course roles - course coordinator, instructor, 
                   3769:     # exam proctor, ta, student, or custom role.
1.474     raeburn  3770: 
                   3771:     foreach my $course (keys(%live_courses)) {
1.482     raeburn  3772:         my ($cdom,$cnum);
                   3773:         if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
                   3774:             $cdom = $env{'course.'.$course.'.domain'};
                   3775:             $cnum = $env{'course.'.$course.'.num'};
                   3776:         } else {
1.490     raeburn  3777:             ($cdom,$cnum) = split(/_/,$course); 
1.482     raeburn  3778:         }
                   3779:         my $no_ownblock = 0;
                   3780:         my $no_userblock = 0;
1.533     raeburn  3781:         if ($otheruser && $activity ne 'com') {
1.490     raeburn  3782:             # Check if current user has 'evb' priv for this
                   3783:             if (defined($own_courses{$course})) {
                   3784:                 foreach my $sec (keys(%{$own_courses{$course}})) {
                   3785:                     my $checkrole = 'cm./'.$cdom.'/'.$cnum;
                   3786:                     if ($sec ne 'none') {
                   3787:                         $checkrole .= '/'.$sec;
                   3788:                     }
                   3789:                     if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   3790:                         $no_ownblock = 1;
                   3791:                         last;
                   3792:                     }
                   3793:                 }
                   3794:             }
                   3795:             # if they have 'evb' priv and are currently not playing student
                   3796:             next if (($no_ownblock) &&
                   3797:                  ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
                   3798:         }
1.474     raeburn  3799:         foreach my $sec (keys(%{$live_courses{$course}})) {
1.482     raeburn  3800:             my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474     raeburn  3801:             if ($sec ne 'none') {
1.482     raeburn  3802:                 $checkrole .= '/'.$sec;
1.474     raeburn  3803:             }
1.490     raeburn  3804:             if ($otheruser) {
                   3805:                 # Resource belongs to user other than current user.
                   3806:                 # Assemble privs for that user, and check for 'evb' priv.
1.482     raeburn  3807:                 my ($trole,$tdom,$tnum,$tsec);
                   3808:                 my $entry = $live_courses{$course}{$sec};
                   3809:                 if ($entry =~ /^cr/) {
                   3810:                     ($trole,$tdom,$tnum,$tsec) = 
                   3811:                       ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
                   3812:                 } else {
                   3813:                     ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
                   3814:                 }
                   3815:                 my ($spec,$area,$trest,%allroles,%userroles);
                   3816:                 $area = '/'.$tdom.'/'.$tnum;
                   3817:                 $trest = $tnum;
                   3818:                 if ($tsec ne '') {
                   3819:                     $area .= '/'.$tsec;
                   3820:                     $trest .= '/'.$tsec;
                   3821:                 }
                   3822:                 $spec = $trole.'.'.$area;
                   3823:                 if ($trole =~ /^cr/) {
                   3824:                     &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
                   3825:                                                       $tdom,$spec,$trest,$area);
                   3826:                 } else {
                   3827:                     &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
                   3828:                                                        $tdom,$spec,$trest,$area);
                   3829:                 }
                   3830:                 my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486     raeburn  3831:                 if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
                   3832:                     if ($1) {
                   3833:                         $no_userblock = 1;
                   3834:                         last;
                   3835:                     }
                   3836:                 }
1.490     raeburn  3837:             } else {
                   3838:                 # Resource belongs to current user
                   3839:                 # Check for 'evb' priv via lonnet::allowed().
1.482     raeburn  3840:                 if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   3841:                     $no_ownblock = 1;
                   3842:                     last;
                   3843:                 }
1.474     raeburn  3844:             }
                   3845:         }
                   3846:         # if they have the evb priv and are currently not playing student
1.482     raeburn  3847:         next if (($no_ownblock) &&
1.491     albertel 3848:                  ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482     raeburn  3849:         next if ($no_userblock);
1.474     raeburn  3850: 
1.866     kalberla 3851:         # Retrieve blocking times and identity of locker for course
1.490     raeburn  3852:         # of specified user, unless user has 'evb' privilege.
1.502     raeburn  3853:         
                   3854:         my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
                   3855:         if (($start != 0) && 
                   3856:             (($startblock == 0) || ($startblock > $start))) {
                   3857:             $startblock = $start;
                   3858:         }
                   3859:         if (($end != 0)  &&
                   3860:             (($endblock == 0) || ($endblock < $end))) {
                   3861:             $endblock = $end;
                   3862:         }
1.490     raeburn  3863:     }
                   3864:     return ($startblock,$endblock);
                   3865: }
                   3866: 
                   3867: sub get_blocks {
                   3868:     my ($setters,$activity,$cdom,$cnum) = @_;
                   3869:     my $startblock = 0;
                   3870:     my $endblock = 0;
                   3871:     my $course = $cdom.'_'.$cnum;
                   3872:     $setters->{$course} = {};
                   3873:     $setters->{$course}{'staff'} = [];
                   3874:     $setters->{$course}{'times'} = [];
                   3875:     my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
                   3876:     foreach my $record (keys(%records)) {
                   3877:         my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
                   3878:         if ($start <= time && $end >= time) {
                   3879:             my ($staff_name,$staff_dom,$title,$blocks) =
                   3880:                 &parse_block_record($records{$record});
                   3881:             if ($blocks->{$activity} eq 'on') {
                   3882:                 push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
                   3883:                 push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491     albertel 3884:                 if ( ($startblock == 0) || ($startblock > $start) ) {
                   3885:                     $startblock = $start;
1.490     raeburn  3886:                 }
1.491     albertel 3887:                 if ( ($endblock == 0) || ($endblock < $end) ) {
                   3888:                     $endblock = $end;
1.474     raeburn  3889:                 }
                   3890:             }
                   3891:         }
                   3892:     }
                   3893:     return ($startblock,$endblock);
                   3894: }
                   3895: 
                   3896: sub parse_block_record {
                   3897:     my ($record) = @_;
                   3898:     my ($setuname,$setudom,$title,$blocks);
                   3899:     if (ref($record) eq 'HASH') {
                   3900:         ($setuname,$setudom) = split(/:/,$record->{'setter'});
                   3901:         $title = &unescape($record->{'event'});
                   3902:         $blocks = $record->{'blocks'};
                   3903:     } else {
                   3904:         my @data = split(/:/,$record,3);
                   3905:         if (scalar(@data) eq 2) {
                   3906:             $title = $data[1];
                   3907:             ($setuname,$setudom) = split(/@/,$data[0]);
                   3908:         } else {
                   3909:             ($setuname,$setudom,$title) = @data;
                   3910:         }
                   3911:         $blocks = { 'com' => 'on' };
                   3912:     }
                   3913:     return ($setuname,$setudom,$title,$blocks);
                   3914: }
                   3915: 
1.854     kalberla 3916: sub blocking_status {
1.867     kalberla 3917:   my $blocked;
1.854     kalberla 3918:   my ($activity,$uname,$udom) = @_;
1.867     kalberla 3919:   my %setters;
                   3920:   my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
                   3921:   if ($startblock && $endblock) {
                   3922:     $blocked = 1;
                   3923:   }
1.854     kalberla 3924:   if(!wantarray) {
                   3925:     return $blocked;
                   3926:   }
                   3927:   my $output;
                   3928:   my $querystring;
                   3929:   $querystring = "?activity=$activity";
                   3930: 
                   3931:       $output .= <<"END_MYBLOCK";
                   3932: <script type="text/javascript">
                   3933: // <![CDATA[
                   3934:     function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
                   3935:         var options = "width=" + w + ",height=" + h + ",";
                   3936:         options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
                   3937:         options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
                   3938:         var newWin = window.open(url, wdwName, options);
                   3939:         newWin.focus();
                   3940:     }
                   3941: 
                   3942: // ]]>
                   3943: </script>
                   3944: END_MYBLOCK
                   3945:   my $popupUrl = "/adm/blockingstatus/$querystring";
1.867     kalberla 3946:   $output .= <<"END_BLOCK";
                   3947: <div class='LC_comblock'>
1.869     kalberla 3948:   <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
                   3949:   title='Communication Blocked'>
                   3950:   <img class='LC_noBorder LC_middle' title='Communication Blocked' src='/res/adm/pages/comblock.png' alt='Communication Blocked'/></a>
                   3951:   <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring' 
                   3952:   title='Communication Blocked'>Communication Blocked</a>
1.867     kalberla 3953: </div>
                   3954: 
                   3955: END_BLOCK
1.474     raeburn  3956: 
1.854     kalberla 3957:   return ($blocked, $output);
                   3958: }
1.490     raeburn  3959: 
1.60      matthew  3960: ###############################################
                   3961: 
1.682     raeburn  3962: sub check_ip_acc {
                   3963:     my ($acc)=@_;
                   3964:     &Apache::lonxml::debug("acc is $acc");
                   3965:     if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
                   3966:         return 1;
                   3967:     }
                   3968:     my $allowed=0;
                   3969:     my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
                   3970: 
                   3971:     my $name;
                   3972:     foreach my $pattern (split(',',$acc)) {
                   3973:         $pattern =~ s/^\s*//;
                   3974:         $pattern =~ s/\s*$//;
                   3975:         if ($pattern =~ /\*$/) {
                   3976:             #35.8.*
                   3977:             $pattern=~s/\*//;
                   3978:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   3979:         } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
                   3980:             #35.8.3.[34-56]
                   3981:             my $low=$2;
                   3982:             my $high=$3;
                   3983:             $pattern=$1;
                   3984:             if ($ip =~ /^\Q$pattern\E/) {
                   3985:                 my $last=(split(/\./,$ip))[3];
                   3986:                 if ($last <=$high && $last >=$low) { $allowed=1; }
                   3987:             }
                   3988:         } elsif ($pattern =~ /^\*/) {
                   3989:             #*.msu.edu
                   3990:             $pattern=~s/\*//;
                   3991:             if (!defined($name)) {
                   3992:                 use Socket;
                   3993:                 my $netaddr=inet_aton($ip);
                   3994:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   3995:             }
                   3996:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   3997:         } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
                   3998:             #127.0.0.1
                   3999:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   4000:         } else {
                   4001:             #some.name.com
                   4002:             if (!defined($name)) {
                   4003:                 use Socket;
                   4004:                 my $netaddr=inet_aton($ip);
                   4005:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   4006:             }
                   4007:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   4008:         }
                   4009:         if ($allowed) { last; }
                   4010:     }
                   4011:     return $allowed;
                   4012: }
                   4013: 
                   4014: ###############################################
                   4015: 
1.60      matthew  4016: =pod
                   4017: 
1.112     bowersj2 4018: =head1 Domain Template Functions
                   4019: 
                   4020: =over 4
                   4021: 
                   4022: =item * &determinedomain()
1.60      matthew  4023: 
                   4024: Inputs: $domain (usually will be undef)
                   4025: 
1.63      www      4026: Returns: Determines which domain should be used for designs
1.60      matthew  4027: 
                   4028: =cut
1.54      www      4029: 
1.60      matthew  4030: ###############################################
1.63      www      4031: sub determinedomain {
                   4032:     my $domain=shift;
1.531     albertel 4033:     if (! $domain) {
1.60      matthew  4034:         # Determine domain if we have not been given one
                   4035:         $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258     albertel 4036:         if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
                   4037:         if ($env{'request.role.domain'}) { 
                   4038:             $domain=$env{'request.role.domain'}; 
1.60      matthew  4039:         }
                   4040:     }
1.63      www      4041:     return $domain;
                   4042: }
                   4043: ###############################################
1.517     raeburn  4044: 
1.518     albertel 4045: sub devalidate_domconfig_cache {
                   4046:     my ($udom)=@_;
                   4047:     &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
                   4048: }
                   4049: 
                   4050: # ---------------------- Get domain configuration for a domain
                   4051: sub get_domainconf {
                   4052:     my ($udom) = @_;
                   4053:     my $cachetime=1800;
                   4054:     my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
                   4055:     if (defined($cached)) { return %{$result}; }
                   4056: 
                   4057:     my %domconfig = &Apache::lonnet::get_dom('configuration',
                   4058: 					     ['login','rolecolors'],$udom);
1.632     raeburn  4059:     my (%designhash,%legacy);
1.518     albertel 4060:     if (keys(%domconfig) > 0) {
                   4061:         if (ref($domconfig{'login'}) eq 'HASH') {
1.632     raeburn  4062:             if (keys(%{$domconfig{'login'}})) {
                   4063:                 foreach my $key (keys(%{$domconfig{'login'}})) {
1.699     raeburn  4064:                     if (ref($domconfig{'login'}{$key}) eq 'HASH') {
                   4065:                         foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
                   4066:                             $designhash{$udom.'.login.'.$key.'_'.$img} = 
                   4067:                                 $domconfig{'login'}{$key}{$img};
                   4068:                         }
                   4069:                     } else {
                   4070:                         $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
                   4071:                     }
1.632     raeburn  4072:                 }
                   4073:             } else {
                   4074:                 $legacy{'login'} = 1;
1.518     albertel 4075:             }
1.632     raeburn  4076:         } else {
                   4077:             $legacy{'login'} = 1;
1.518     albertel 4078:         }
                   4079:         if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632     raeburn  4080:             if (keys(%{$domconfig{'rolecolors'}})) {
                   4081:                 foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
                   4082:                     if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
                   4083:                         foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
                   4084:                             $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
                   4085:                         }
1.518     albertel 4086:                     }
                   4087:                 }
1.632     raeburn  4088:             } else {
                   4089:                 $legacy{'rolecolors'} = 1;
1.518     albertel 4090:             }
1.632     raeburn  4091:         } else {
                   4092:             $legacy{'rolecolors'} = 1;
1.518     albertel 4093:         }
1.632     raeburn  4094:         if (keys(%legacy) > 0) {
                   4095:             my %legacyhash = &get_legacy_domconf($udom);
                   4096:             foreach my $item (keys(%legacyhash)) {
                   4097:                 if ($item =~ /^\Q$udom\E\.login/) {
                   4098:                     if ($legacy{'login'}) { 
                   4099:                         $designhash{$item} = $legacyhash{$item};
                   4100:                     }
                   4101:                 } else {
                   4102:                     if ($legacy{'rolecolors'}) {
                   4103:                         $designhash{$item} = $legacyhash{$item};
                   4104:                     }
1.518     albertel 4105:                 }
                   4106:             }
                   4107:         }
1.632     raeburn  4108:     } else {
                   4109:         %designhash = &get_legacy_domconf($udom); 
1.518     albertel 4110:     }
                   4111:     &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
                   4112: 				  $cachetime);
                   4113:     return %designhash;
                   4114: }
                   4115: 
1.632     raeburn  4116: sub get_legacy_domconf {
                   4117:     my ($udom) = @_;
                   4118:     my %legacyhash;
                   4119:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
                   4120:     my $designfile =  $designdir.'/'.$udom.'.tab';
                   4121:     if (-e $designfile) {
                   4122:         if ( open (my $fh,"<$designfile") ) {
                   4123:             while (my $line = <$fh>) {
                   4124:                 next if ($line =~ /^\#/);
                   4125:                 chomp($line);
                   4126:                 my ($key,$val)=(split(/\=/,$line));
                   4127:                 if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
                   4128:             }
                   4129:             close($fh);
                   4130:         }
                   4131:     }
                   4132:     if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
                   4133:         $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
                   4134:     }
                   4135:     return %legacyhash;
                   4136: }
                   4137: 
1.63      www      4138: =pod
                   4139: 
1.112     bowersj2 4140: =item * &domainlogo()
1.63      www      4141: 
                   4142: Inputs: $domain (usually will be undef)
                   4143: 
                   4144: Returns: A link to a domain logo, if the domain logo exists.
                   4145: If the domain logo does not exist, a description of the domain.
                   4146: 
                   4147: =cut
1.112     bowersj2 4148: 
1.63      www      4149: ###############################################
                   4150: sub domainlogo {
1.517     raeburn  4151:     my $domain = &determinedomain(shift);
1.518     albertel 4152:     my %designhash = &get_domainconf($domain);    
1.517     raeburn  4153:     # See if there is a logo
                   4154:     if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519     raeburn  4155:         my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538     albertel 4156:         if ($imgsrc =~ m{^/(adm|res)/}) {
                   4157: 	    if ($imgsrc =~ m{^/res/}) {
                   4158: 		my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
                   4159: 		&Apache::lonnet::repcopy($local_name);
                   4160: 	    }
                   4161: 	   $imgsrc = &lonhttpdurl($imgsrc);
1.519     raeburn  4162:         } 
                   4163:         return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514     albertel 4164:     } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
                   4165:         return &Apache::lonnet::domain($domain,'description');
1.59      www      4166:     } else {
1.60      matthew  4167:         return '';
1.59      www      4168:     }
                   4169: }
1.63      www      4170: ##############################################
                   4171: 
                   4172: =pod
                   4173: 
1.112     bowersj2 4174: =item * &designparm()
1.63      www      4175: 
                   4176: Inputs: $which parameter; $domain (usually will be undef)
                   4177: 
                   4178: Returns: value of designparamter $which
                   4179: 
                   4180: =cut
1.112     bowersj2 4181: 
1.397     albertel 4182: 
1.400     albertel 4183: ##############################################
1.397     albertel 4184: sub designparm {
                   4185:     my ($which,$domain)=@_;
                   4186:     if (exists($env{'environment.color.'.$which})) {
1.817     bisitz   4187:         return $env{'environment.color.'.$which};
1.96      www      4188:     }
1.63      www      4189:     $domain=&determinedomain($domain);
1.518     albertel 4190:     my %domdesign = &get_domainconf($domain);
1.520     raeburn  4191:     my $output;
1.517     raeburn  4192:     if ($domdesign{$domain.'.'.$which} ne '') {
1.817     bisitz   4193:         $output = $domdesign{$domain.'.'.$which};
1.63      www      4194:     } else {
1.520     raeburn  4195:         $output = $defaultdesign{$which};
                   4196:     }
                   4197:     if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635     raeburn  4198:         ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538     albertel 4199:         if ($output =~ m{^/(adm|res)/}) {
1.817     bisitz   4200:             if ($output =~ m{^/res/}) {
                   4201:                 my $local_name = &Apache::lonnet::filelocation('',$output);
                   4202:                 &Apache::lonnet::repcopy($local_name);
                   4203:             }
1.520     raeburn  4204:             $output = &lonhttpdurl($output);
                   4205:         }
1.63      www      4206:     }
1.520     raeburn  4207:     return $output;
1.63      www      4208: }
1.59      www      4209: 
1.822     bisitz   4210: ##############################################
                   4211: =pod
                   4212: 
1.832     bisitz   4213: =item * &authorspace()
                   4214: 
                   4215: Inputs: ./.
                   4216: 
                   4217: Returns: Path to the Construction Space of the current user's
                   4218:          accessed author space
                   4219:          The author space will be that of the current user
                   4220:          when accessing the own author space
                   4221:          and that of the co-author/assistent co-author
                   4222:          when accessing the co-author's/assistent co-author's
                   4223:          space
                   4224: 
                   4225: =cut
                   4226: 
                   4227: sub authorspace {
                   4228:     my $caname = '';
                   4229:     if ($env{'request.role'} =~ /^ca|^aa/) {
                   4230:         (undef,$caname) =
                   4231:             ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
                   4232:     } else {
                   4233:         $caname = $env{'user.name'};
                   4234:     }
                   4235:     return '/priv/'.$caname.'/';
                   4236: }
                   4237: 
                   4238: ##############################################
                   4239: =pod
                   4240: 
1.822     bisitz   4241: =item * &head_subbox()
                   4242: 
                   4243: Inputs: $content (contains HTML code with page functions, etc.)
                   4244: 
                   4245: Returns: HTML div with $content
                   4246:          To be included in page header
                   4247: 
                   4248: =cut
                   4249: 
                   4250: sub head_subbox {
                   4251:     my ($content)=@_;
                   4252:     my $output =
1.844     bisitz   4253:         '<div id="LC_head_subbox">'
1.822     bisitz   4254:        .$content
                   4255:        .'</div>'
                   4256: }
                   4257: 
                   4258: ##############################################
                   4259: =pod
                   4260: 
                   4261: =item * &CSTR_pageheader()
                   4262: 
                   4263: Inputs: ./.
                   4264: 
                   4265: Returns: HTML div with CSTR path and recent box
                   4266:          To be included on Construction Space pages
                   4267: 
                   4268: =cut
                   4269: 
                   4270: sub CSTR_pageheader {
                   4271:     # this is for resources; directories have customtitle, and crumbs
                   4272:             # and select recent are created in lonpubdir.pm  
                   4273:     my ($uname,$thisdisfn)=
                   4274:         ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
                   4275:     my $formaction='/priv/'.$uname.'/'.$thisdisfn;
                   4276:     $formaction=~s/\/+/\//g;
                   4277: 
                   4278:     my $parentpath = '';
                   4279:     my $lastitem = '';
                   4280:     if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
                   4281:         $parentpath = $1;
                   4282:         $lastitem = $2;
                   4283:     } else {
                   4284:         $lastitem = $thisdisfn;
                   4285:     }
                   4286:     return
                   4287:          '<div>'
                   4288:         .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
                   4289:         .'<b>'.&mt('Construction Space:').'</b> '
                   4290:         .'<form name="dirs" method="post" action="'.$formaction
                   4291:         .'" target="_top"><tt><b>' #FIXME lonpubdir: target="_parent"
                   4292:         .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."$lastitem</b></tt><br />"
                   4293:         #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
                   4294:         .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
                   4295:         .'</form>'
                   4296:         .&Apache::lonmenu::constspaceform()
                   4297:         .'</div>';
                   4298: }
                   4299: 
1.60      matthew  4300: ###############################################
                   4301: ###############################################
                   4302: 
                   4303: =pod
                   4304: 
1.112     bowersj2 4305: =back
                   4306: 
1.549     albertel 4307: =head1 HTML Helpers
1.112     bowersj2 4308: 
                   4309: =over 4
                   4310: 
                   4311: =item * &bodytag()
1.60      matthew  4312: 
                   4313: Returns a uniform header for LON-CAPA web pages.
                   4314: 
                   4315: Inputs: 
                   4316: 
1.112     bowersj2 4317: =over 4
                   4318: 
                   4319: =item * $title, A title to be displayed on the page.
                   4320: 
                   4321: =item * $function, the current role (can be undef).
                   4322: 
                   4323: =item * $addentries, extra parameters for the <body> tag.
                   4324: 
                   4325: =item * $bodyonly, if defined, only return the <body> tag.
                   4326: 
                   4327: =item * $domain, if defined, force a given domain.
                   4328: 
                   4329: =item * $forcereg, if page should register as content page (relevant for 
1.86      www      4330:             text interface only)
1.60      matthew  4331: 
1.814     bisitz   4332: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
                   4333:                      navigational links
1.317     albertel 4334: 
1.338     albertel 4335: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
                   4336: 
1.361     albertel 4337: =item * $no_inline_link, if true and in remote mode, don't show the 
                   4338:          'Switch To Inline Menu' link
                   4339: 
1.460     albertel 4340: =item * $args, optional argument valid values are
                   4341:             no_auto_mt_title -> prevents &mt()ing the title arg
1.562     albertel 4342:             inherit_jsmath -> when creating popup window in a page,
                   4343:                               should it have jsmath forced on by the
                   4344:                               current page
1.460     albertel 4345: 
1.112     bowersj2 4346: =back
                   4347: 
1.60      matthew  4348: Returns: A uniform header for LON-CAPA web pages.  
                   4349: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
                   4350: If $bodyonly is undef or zero, an html string containing a <body> tag and 
                   4351: other decorations will be returned.
                   4352: 
                   4353: =cut
                   4354: 
1.54      www      4355: sub bodytag {
1.831     bisitz   4356:     my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.816     bisitz   4357:         $no_nav_bar,$bgcolor,$no_inline_link,$args)=@_;
1.339     albertel 4358: 
1.460     albertel 4359:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339     albertel 4360: 
1.183     matthew  4361:     $function = &get_users_function() if (!$function);
1.339     albertel 4362:     my $img =    &designparm($function.'.img',$domain);
                   4363:     my $font =   &designparm($function.'.font',$domain);
                   4364:     my $pgbg   = $bgcolor || &designparm($function.'.pgbg',$domain);
                   4365: 
1.803     bisitz   4366:     my %design = ( 'style'   => 'margin-top: 0',
1.535     albertel 4367: 		   'bgcolor' => $pgbg,
1.339     albertel 4368: 		   'text'    => $font,
                   4369:                    'alink'   => &designparm($function.'.alink',$domain),
                   4370: 		   'vlink'   => &designparm($function.'.vlink',$domain),
                   4371: 		   'link'    => &designparm($function.'.link',$domain),);
1.438     albertel 4372:     @design{keys(%$addentries)} = @$addentries{keys(%$addentries)}; 
1.339     albertel 4373: 
1.63      www      4374:  # role and realm
1.378     raeburn  4375:     my ($role,$realm) = split(/\./,$env{'request.role'},2);
                   4376:     if ($role  eq 'ca') {
1.479     albertel 4377:         my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500     albertel 4378:         $realm = &plainname($rname,$rdom);
1.378     raeburn  4379:     } 
1.55      www      4380: # realm
1.258     albertel 4381:     if ($env{'request.course.id'}) {
1.378     raeburn  4382:         if ($env{'request.role'} !~ /^cr/) {
                   4383:             $role = &Apache::lonnet::plaintext($role,&course_type());
                   4384:         }
1.359     albertel 4385: 	$realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378     raeburn  4386:     } else {
                   4387:         $role = &Apache::lonnet::plaintext($role);
1.54      www      4388:     }
1.433     albertel 4389: 
1.359     albertel 4390:     if (!$realm) { $realm='&nbsp;'; }
1.55      www      4391: # Set messages
1.60      matthew  4392:     my $messages=&domainlogo($domain);
1.330     albertel 4393: 
1.438     albertel 4394:     my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329     albertel 4395: 
1.101     www      4396: # construct main body tag
1.359     albertel 4397:     my $bodytag = "<body $extra_body_attr>".
1.562     albertel 4398: 	&Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252     albertel 4399: 
1.530     albertel 4400:     if ($bodyonly) {
1.60      matthew  4401:         return $bodytag;
1.798     tempelho 4402:     } 
1.359     albertel 4403: 
1.410     albertel 4404:     my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433     albertel 4405:     if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
                   4406: 	undef($role);
1.434     albertel 4407:     } else {
                   4408: 	$name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433     albertel 4409:     }
1.359     albertel 4410:     
1.762     bisitz   4411:     my $titleinfo = '<h1>'.$title.'</h1>';
1.359     albertel 4412:     #
                   4413:     # Extra info if you are the DC
                   4414:     my $dc_info = '';
                   4415:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   4416:                         $env{'course.'.$env{'request.course.id'}.
                   4417:                                  '.domain'}.'/'})) {
                   4418:         my $cid = $env{'request.course.id'};
                   4419:         $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380     www      4420:         $dc_info =~ s/\s+$//;
1.359     albertel 4421:         $dc_info = '('.$dc_info.')';
                   4422:     }
                   4423: 
1.853     droeschl 4424:     $role = "($role)" if $role;
                   4425:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   4426: 
1.837     bisitz   4427:     if ($env{'environment.remote'} eq 'off') {
1.359     albertel 4428:         # No Remote
1.258     albertel 4429: 	if ($env{'request.state'} eq 'construct') {
1.359     albertel 4430: 	    $forcereg=1;
                   4431: 	}
                   4432: 
1.836     bisitz   4433: #    if ($env{'request.state'} eq 'construct') {
                   4434: #        $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
                   4435: #    }
1.359     albertel 4436: 
1.816     bisitz   4437:         my $titletable = '<table id="LC_title_bar">'
1.836     bisitz   4438:                         ."<tr><td> $titleinfo $dc_info</td>"
1.816     bisitz   4439:                         .'</tr></table>';
                   4440: 
1.814     bisitz   4441: 	if ($no_nav_bar) {
1.359     albertel 4442: 	    $bodytag .= $titletable;
                   4443: 	} else {
1.852     droeschl 4444:         $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
                   4445:             <em>$realm</em> $dc_info</div>| unless $env{'form.inhibitmenu'};
                   4446: 
1.359     albertel 4447: 	    if ($env{'request.state'} eq 'construct') {
1.863     droeschl 4448:                 $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$titletable);
1.272     raeburn  4449:             } else {
1.863     droeschl 4450:                 $bodytag .= &Apache::lonmenu::menubuttons($forcereg).$titletable;
1.272     raeburn  4451:             }
1.235     raeburn  4452:         }
                   4453:         return $bodytag;
1.94      www      4454:     }
1.95      www      4455: 
1.93      www      4456: #
1.95      www      4457: # Top frame rendering, Remote is up
1.93      www      4458: #
1.359     albertel 4459: 
1.517     raeburn  4460:     my $imgsrc = $img;
                   4461:     if ($img =~ /^\/adm/) {
1.575     albertel 4462:         $imgsrc = &lonhttpdurl($img);
1.517     raeburn  4463:     }
                   4464:     my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359     albertel 4465: 
1.305     www      4466:     # Explicit link to get inline menu
1.361     albertel 4467:     my $menu= ($no_inline_link?''
1.853     droeschl 4468: 	       :'<a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
                   4469:     $bodytag .= qq|<div id="LC_nav_bar">$name $role
                   4470:             <em>$realm</em> $dc_info </div>
                   4471:             <ol class="LC_smallMenu LC_right">
                   4472:                 <li>$menu</li>
                   4473:             </ol>| unless $env{'form.inhibitmenu'};
1.245     matthew  4474:     #
1.94      www      4475:     return(<<ENDBODY);
1.60      matthew  4476: $bodytag
1.359     albertel 4477: <table id="LC_title_bar" class="LC_with_remote">
1.791     tempelho 4478: <tr><td>$upperleft</td>
                   4479:     <td>$messages&nbsp;</td>
1.54      www      4480: </tr>
1.359     albertel 4481: <tr><td>$titleinfo $dc_info $menu</td>
1.368     albertel 4482: </tr>
1.356     albertel 4483: </table>
1.54      www      4484: ENDBODY
1.182     matthew  4485: }
                   4486: 
1.330     albertel 4487: sub make_attr_string {
                   4488:     my ($register,$attr_ref) = @_;
                   4489: 
                   4490:     if ($attr_ref && !ref($attr_ref)) {
                   4491: 	die("addentries Must be a hash ref ".
                   4492: 	    join(':',caller(1))." ".
                   4493: 	    join(':',caller(0))." ");
                   4494:     }
                   4495: 
                   4496:     if ($register) {
1.339     albertel 4497: 	my ($on_load,$on_unload);
                   4498: 	foreach my $key (keys(%{$attr_ref})) {
                   4499: 	    if      (lc($key) eq 'onload') {
                   4500: 		$on_load.=$attr_ref->{$key}.';';
                   4501: 		delete($attr_ref->{$key});
                   4502: 
                   4503: 	    } elsif (lc($key) eq 'onunload') {
                   4504: 		$on_unload.=$attr_ref->{$key}.';';
                   4505: 		delete($attr_ref->{$key});
                   4506: 	    }
                   4507: 	}
                   4508: 	$attr_ref->{'onload'}  =
                   4509: 	    &Apache::lonmenu::loadevents().  $on_load;
                   4510: 	$attr_ref->{'onunload'}=
                   4511: 	    &Apache::lonmenu::unloadevents().$on_unload;
                   4512:     }
                   4513: 
                   4514: # Accessibility font enhance
                   4515:     if ($env{'browser.fontenhance'} eq 'on') {
                   4516: 	my $style;
                   4517: 	foreach my $key (keys(%{$attr_ref})) {
                   4518: 	    if (lc($key) eq 'style') {
                   4519: 		$style.=$attr_ref->{$key}.';';
                   4520: 		delete($attr_ref->{$key});
                   4521: 	    }
                   4522: 	}
                   4523: 	$attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330     albertel 4524:     }
1.339     albertel 4525: 
1.330     albertel 4526:     my $attr_string;
                   4527:     foreach my $attr (keys(%$attr_ref)) {
                   4528: 	$attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
                   4529:     }
                   4530:     return $attr_string;
                   4531: }
                   4532: 
                   4533: 
1.182     matthew  4534: ###############################################
1.251     albertel 4535: ###############################################
                   4536: 
                   4537: =pod
                   4538: 
                   4539: =item * &endbodytag()
                   4540: 
                   4541: Returns a uniform footer for LON-CAPA web pages.
                   4542: 
1.635     raeburn  4543: Inputs: 1 - optional reference to an args hash
                   4544: If in the hash, key for noredirectlink has a value which evaluates to true,
                   4545: a 'Continue' link is not displayed if the page contains an
                   4546: internal redirect in the <head></head> section,
                   4547: i.e., $env{'internal.head.redirect'} exists   
1.251     albertel 4548: 
                   4549: =cut
                   4550: 
                   4551: sub endbodytag {
1.635     raeburn  4552:     my ($args) = @_;
1.251     albertel 4553:     my $endbodytag='</body>';
1.269     albertel 4554:     $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315     albertel 4555:     if ( exists( $env{'internal.head.redirect'} ) ) {
1.635     raeburn  4556:         if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
                   4557: 	    $endbodytag=
                   4558: 	        "<br /><a href=\"$env{'internal.head.redirect'}\">".
                   4559: 	        &mt('Continue').'</a>'.
                   4560: 	        $endbodytag;
                   4561:         }
1.315     albertel 4562:     }
1.251     albertel 4563:     return $endbodytag;
                   4564: }
                   4565: 
1.352     albertel 4566: =pod
                   4567: 
                   4568: =item * &standard_css()
                   4569: 
                   4570: Returns a style sheet
                   4571: 
                   4572: Inputs: (all optional)
                   4573:             domain         -> force to color decorate a page for a specific
                   4574:                                domain
                   4575:             function       -> force usage of a specific rolish color scheme
                   4576:             bgcolor        -> override the default page bgcolor
                   4577: 
                   4578: =cut
                   4579: 
1.343     albertel 4580: sub standard_css {
1.345     albertel 4581:     my ($function,$domain,$bgcolor) = @_;
1.352     albertel 4582:     $function  = &get_users_function() if (!$function);
                   4583:     my $img    = &designparm($function.'.img',   $domain);
                   4584:     my $tabbg  = &designparm($function.'.tabbg', $domain);
                   4585:     my $font   = &designparm($function.'.font',  $domain);
1.801     tempelho 4586:     my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791     tempelho 4587: #second colour for later usage
1.345     albertel 4588:     my $sidebg = &designparm($function.'.sidebg',$domain);
1.382     albertel 4589:     my $pgbg_or_bgcolor =
                   4590: 	         $bgcolor ||
1.352     albertel 4591: 	         &designparm($function.'.pgbg',  $domain);
1.382     albertel 4592:     my $pgbg   = &designparm($function.'.pgbg',  $domain);
1.352     albertel 4593:     my $alink  = &designparm($function.'.alink', $domain);
                   4594:     my $vlink  = &designparm($function.'.vlink', $domain);
                   4595:     my $link   = &designparm($function.'.link',  $domain);
                   4596: 
1.704     muellerd 4597:     my $loginbg = &designparm('login.sidebg',$domain);
1.712     muellerd 4598:     my $bgcol = &designparm('login.bgcol',$domain);
                   4599:     my $textcol = &designparm('login.textcol',$domain);
1.704     muellerd 4600: 
1.602     albertel 4601:     my $sans                 = 'Verdana,Arial,Helvetica,sans-serif';
1.395     albertel 4602:     my $mono                 = 'monospace';
1.850     bisitz   4603:     my $data_table_head      = $sidebg;
                   4604:     my $data_table_light     = '#FAFAFA';
                   4605:     my $data_table_dark      = '#F0F0F0';
1.470     banghart 4606:     my $data_table_darker    = '#CCCCCC';
1.349     albertel 4607:     my $data_table_highlight = '#FFFF00';
1.352     albertel 4608:     my $mail_new             = '#FFBB77';
                   4609:     my $mail_new_hover       = '#DD9955';
                   4610:     my $mail_read            = '#BBBB77';
                   4611:     my $mail_read_hover      = '#999944';
                   4612:     my $mail_replied         = '#AAAA88';
                   4613:     my $mail_replied_hover   = '#888855';
                   4614:     my $mail_other           = '#99BBBB';
                   4615:     my $mail_other_hover     = '#669999';
1.391     albertel 4616:     my $table_header         = '#DDDDDD';
1.489     raeburn  4617:     my $feedback_link_bg     = '#BBBBBB';
1.701     harmsja  4618:     my $lg_border_color	     = '#C8C8C8';
1.392     albertel 4619: 
1.608     albertel 4620:     my $border = ($env{'browser.type'} eq 'explorer' ||
1.803     bisitz   4621: 		  $env{'browser.type'} eq 'safari'     ) ? '0 2px 0 2px'
                   4622: 	                                                 : '0 3px 0 4px';
1.448     albertel 4623: 
1.523     albertel 4624: 
1.343     albertel 4625:     return <<END;
1.795     www      4626: body {
                   4627:    font-family: $sans;
                   4628:    line-height:130%;
                   4629:    font-size:0.83em;
                   4630:    color:$font;
                   4631: }
                   4632: 
                   4633: a:link, a:visited { 
                   4634:   font-size:100%; 
                   4635: }
                   4636: 
                   4637: a:focus { 
                   4638:   color: red;
                   4639:   background: yellow 
                   4640: }
1.698     harmsja  4641: 
1.846     bisitz   4642: hr {
                   4643:   clear: both;
                   4644:   color: $tabbg;
                   4645:   background-color: $tabbg;
                   4646:   height: 3px;
                   4647:   border: none;
                   4648: }
                   4649: 
1.795     www      4650: form, .inline { 
                   4651:    display: inline; 
                   4652: }
1.721     harmsja  4653: 
1.795     www      4654: .LC_right {
                   4655:    text-align:right;
                   4656: }
                   4657: 
                   4658: .LC_middle {
                   4659:    vertical-align:middle;
                   4660: }
1.721     harmsja  4661: 
                   4662: /* just for tests */
1.754     droeschl 4663: .LC_400Box {width:400px; }
1.721     harmsja  4664: /* end */
                   4665: 
1.778     bisitz   4666: .LC_filename {
                   4667:   font-family: $mono;
                   4668:   white-space:pre;
                   4669: }
                   4670: 
                   4671: .LC_fileicon {
                   4672:   border: none;
                   4673:   height: 1.3em;
                   4674:   vertical-align: text-bottom;
                   4675:   margin-right: 0.3em;
                   4676:   text-decoration:none;
                   4677: }
                   4678: 
1.350     albertel 4679: .LC_error {
                   4680:   color: red;
                   4681:   font-size: larger;
                   4682: }
1.795     www      4683: 
1.457     albertel 4684: .LC_warning,
                   4685: .LC_diff_removed {
1.733     bisitz   4686:   color: red;
1.394     albertel 4687: }
1.532     albertel 4688: 
                   4689: .LC_info,
1.457     albertel 4690: .LC_success,
                   4691: .LC_diff_added {
1.350     albertel 4692:   color: green;
                   4693: }
1.795     www      4694: 
1.802     bisitz   4695: div.LC_confirm_box {
                   4696:   background-color: #FAFAFA;
                   4697:   border: 1px solid $lg_border_color;
                   4698:   margin-right: 0;
                   4699:   padding: 5px;
                   4700: }
                   4701: 
                   4702: div.LC_confirm_box .LC_error img,
                   4703: div.LC_confirm_box .LC_success img {
                   4704:   vertical-align: middle;
                   4705: }
                   4706: 
1.440     albertel 4707: .LC_icon {
1.771     droeschl 4708:   border: none;
1.790     droeschl 4709:   vertical-align: middle;
1.771     droeschl 4710: }
                   4711: 
1.543     albertel 4712: .LC_docs_spacer {
                   4713:   width: 25px;
                   4714:   height: 1px;
1.771     droeschl 4715:   border: none;
1.543     albertel 4716: }
1.346     albertel 4717: 
1.532     albertel 4718: .LC_internal_info {
1.735     bisitz   4719:   color: #999999;
1.532     albertel 4720: }
                   4721: 
1.794     www      4722: .LC_discussion {
                   4723:    background: $tabbg;
                   4724:    border: 1px solid black;
                   4725:    margin: 2px;
                   4726: }
                   4727: 
                   4728: .LC_disc_action_links_bar {
                   4729:    background: $tabbg;
1.803     bisitz   4730:    border: none;
1.795     www      4731:    margin: 4px;
1.794     www      4732: }
                   4733: 
                   4734: .LC_disc_action_left {
                   4735:    text-align: left;
                   4736: }
                   4737: 
                   4738: .LC_disc_action_right {
                   4739:    text-align: right;
                   4740: }
                   4741: 
                   4742: .LC_disc_new_item {
                   4743:    background: white;
                   4744:    border: 2px solid red;
                   4745:    margin: 2px;
                   4746: }
                   4747: 
                   4748: .LC_disc_old_item {
                   4749:    background: white;
                   4750:    border: 1px solid black;
                   4751:    margin: 2px;
                   4752: }
                   4753: 
1.458     albertel 4754: table.LC_pastsubmission {
                   4755:   border: 1px solid black;
                   4756:   margin: 2px;
                   4757: }
                   4758: 
1.795     www      4759: table#LC_top_nav,
                   4760: table#LC_menubuttons,
                   4761: table#LC_nav_location {
1.345     albertel 4762:   width: 100%;
                   4763:   background: $pgbg;
1.392     albertel 4764:   border: 2px;
1.402     albertel 4765:   border-collapse: separate;
1.803     bisitz   4766:   padding: 0;
1.345     albertel 4767: }
1.392     albertel 4768: 
1.801     tempelho 4769: table#LC_title_bar a {
                   4770:   color: $fontmenu;
                   4771: }
1.836     bisitz   4772: 
1.807     droeschl 4773: table#LC_title_bar {
1.819     tempelho 4774:   clear: both;
1.836     bisitz   4775:   display: none;
1.807     droeschl 4776: }
                   4777: 
1.795     www      4778: table#LC_title_bar,
                   4779: table.LC_breadcrumbs,
1.393     albertel 4780: table#LC_title_bar.LC_with_remote {
1.359     albertel 4781:   width: 100%;
1.392     albertel 4782:   border-color: $pgbg;
                   4783:   border-style: solid;
                   4784:   border-width: $border;
1.379     albertel 4785:   background: $pgbg;
1.801     tempelho 4786:   color: $fontmenu;
1.392     albertel 4787:   border-collapse: collapse;
1.803     bisitz   4788:   padding: 0;
1.819     tempelho 4789:   margin: 0;
1.359     albertel 4790: }
1.795     www      4791: 
1.359     albertel 4792: table#LC_title_bar td {
                   4793:   background: $tabbg;
                   4794: }
1.795     www      4795: 
1.706     harmsja  4796: table#LC_menubuttons img{
1.803     bisitz   4797:   border: none;
1.346     albertel 4798: }
1.795     www      4799: 
1.345     albertel 4800: table#LC_top_nav td {
                   4801:   background: $tabbg;
1.803     bisitz   4802:   border: none;
1.407     albertel 4803:   font-size: small;
1.706     harmsja  4804:   vertical-align:top;
                   4805:   padding:2px 5px 2px 5px;
1.345     albertel 4806: }
1.795     www      4807: 
                   4808: table#LC_top_nav td a,
                   4809: div#LC_top_nav a {
1.345     albertel 4810:   color: $font;
                   4811: }
1.795     www      4812: 
1.364     albertel 4813: table#LC_top_nav td.LC_top_nav_logo {
                   4814:   background: $tabbg;
1.432     albertel 4815:   text-align: left;
1.408     albertel 4816:   white-space: nowrap;
1.432     albertel 4817:   width: 31px;
1.408     albertel 4818: }
1.795     www      4819: 
1.408     albertel 4820: table#LC_top_nav td.LC_top_nav_logo img {
1.803     bisitz   4821:   border: none;
1.408     albertel 4822:   vertical-align: bottom;
1.364     albertel 4823: }
1.795     www      4824: 
1.777     tempelho 4825: table#LC_top_nav td.LC_top_nav_exit,
1.779     bisitz   4826: table#LC_top_nav td.LC_top_nav_help {
1.777     tempelho 4827:   width: 2.0em;
                   4828: }
1.795     www      4829: 
1.442     albertel 4830: table#LC_top_nav td.LC_top_nav_login {
                   4831:   width: 4.0em;
                   4832:   text-align: center;
                   4833: }
1.795     www      4834: 
1.842     droeschl 4835: .LC_breadcrumbs_component {
                   4836:     float: right;
                   4837:     margin: 0 1em;
1.357     albertel 4838: }
1.842     droeschl 4839: .LC_breadcrumbs_component img {
                   4840:     vertical-align: middle;
1.777     tempelho 4841: }
1.795     www      4842: 
1.383     albertel 4843: td.LC_table_cell_checkbox {
                   4844:   text-align: center;
                   4845: }
1.795     www      4846: 
1.779     bisitz   4847: table#LC_mainmenu td.LC_mainmenu_column {
                   4848:     vertical-align: top;
1.777     tempelho 4849: }
1.522     albertel 4850: 
1.795     www      4851: .LC_fontsize_small {
1.705     tempelho 4852:  font-size: 70%;
                   4853: }
                   4854: 
1.844     bisitz   4855: #LC_breadcrumbs {
1.819     tempelho 4856:  clear:both;
                   4857:  background: $sidebg;
1.822     bisitz   4858:  border-bottom: 1px solid $lg_border_color;
1.819     tempelho 4859:  line-height: 32px; 
1.822     bisitz   4860:  margin: 0;
1.819     tempelho 4861:  padding: 0;
                   4862: }
1.862     bisitz   4863: 
1.839     droeschl 4864: /* Preliminary fix to hide breadcrumbs inside remote control window */
1.844     bisitz   4865: #LC_remote #LC_breadcrumbs {
1.839     droeschl 4866:     display:none;
                   4867: }
1.819     tempelho 4868: 
1.844     bisitz   4869: #LC_head_subbox {
1.822     bisitz   4870:  clear:both;
                   4871:  background: #F8F8F8; /* $sidebg; */
                   4872:  border-bottom: 1px solid $lg_border_color;
                   4873:  margin: 0 0 10px 0;
                   4874:  padding: 5px;
                   4875: }
                   4876: 
1.795     www      4877: .LC_fontsize_medium {
1.705     tempelho 4878:  font-size: 85%;
                   4879: }
                   4880: 
1.795     www      4881: .LC_fontsize_large {
1.705     tempelho 4882:  font-size: 120%;
                   4883: }
                   4884: 
1.346     albertel 4885: .LC_menubuttons_inline_text {
                   4886:   color: $font;
1.698     harmsja  4887:   font-size: 90%;
1.701     harmsja  4888:   padding-left:3px;
1.346     albertel 4889: }
                   4890: 
1.526     www      4891: .LC_menubuttons_link {
                   4892:   text-decoration: none;
                   4893: }
1.795     www      4894: 
1.522     albertel 4895: .LC_menubuttons_category {
1.521     www      4896:   color: $font;
1.526     www      4897:   background: $pgbg;
1.521     www      4898:   font-size: larger;
                   4899:   font-weight: bold;
                   4900: }
                   4901: 
1.346     albertel 4902: td.LC_menubuttons_text {
1.779     bisitz   4903:  	color: $font;
1.346     albertel 4904: }
1.706     harmsja  4905: 
1.346     albertel 4906: .LC_current_location {
                   4907:   background: $tabbg;
                   4908: }
1.795     www      4909: 
1.346     albertel 4910: .LC_new_mail {
1.634     www      4911:   background: $tabbg;
1.346     albertel 4912:   font-weight: bold;
                   4913: }
1.347     albertel 4914: 
1.795     www      4915: table.LC_data_table,
                   4916: table.LC_mail_list {
1.347     albertel 4917:   border: 1px solid #000000;
1.402     albertel 4918:   border-collapse: separate;
1.426     albertel 4919:   border-spacing: 1px;
1.610     albertel 4920:   background: $pgbg;
1.347     albertel 4921: }
1.795     www      4922: 
1.422     albertel 4923: .LC_data_table_dense {
                   4924:   font-size: small;
                   4925: }
1.795     www      4926: 
1.507     raeburn  4927: table.LC_nested_outer {
                   4928:   border: 1px solid #000000;
1.589     raeburn  4929:   border-collapse: collapse;
1.803     bisitz   4930:   border-spacing: 0;
1.507     raeburn  4931:   width: 100%;
                   4932: }
1.795     www      4933: 
1.879     raeburn  4934: table.LC_innerpickbox,
1.507     raeburn  4935: table.LC_nested {
1.803     bisitz   4936:   border: none;
1.589     raeburn  4937:   border-collapse: collapse;
1.803     bisitz   4938:   border-spacing: 0;
1.507     raeburn  4939:   width: 100%;
                   4940: }
1.795     www      4941: 
                   4942: table.LC_data_table tr th, 
                   4943: table.LC_calendar tr th, 
                   4944: table.LC_mail_list tr th,
1.879     raeburn  4945: table.LC_prior_tries tr th,
                   4946: table.LC_innerpickbox tr th {
1.349     albertel 4947:   font-weight: bold;
                   4948:   background-color: $data_table_head;
1.801     tempelho 4949:   color:$fontmenu;
1.701     harmsja  4950:   font-size:90%;
1.347     albertel 4951: }
1.795     www      4952: 
1.879     raeburn  4953: table.LC_innerpickbox tr th,
                   4954: table.LC_innerpickbox tr td {
                   4955:   vertical-align: top;
                   4956: }
                   4957: 
1.711     raeburn  4958: table.LC_data_table tr.LC_info_row > td {
1.735     bisitz   4959:   background-color: #CCCCCC;
1.711     raeburn  4960:   font-weight: bold;
                   4961:   text-align: left;
                   4962: }
1.795     www      4963: 
1.779     bisitz   4964: table.LC_data_table tr.LC_odd_row > td,
1.809     bisitz   4965: table.LC_pick_box tr > td.LC_odd_row {
1.349     albertel 4966:   background-color: $data_table_light;
1.425     albertel 4967:   padding: 2px;
1.347     albertel 4968: }
1.795     www      4969: 
1.610     albertel 4970: table.LC_data_table tr.LC_even_row > td,
1.809     bisitz   4971: table.LC_pick_box tr > td.LC_even_row {
1.349     albertel 4972:   background-color: $data_table_dark;
1.709     bisitz   4973:   padding: 2px;
1.347     albertel 4974: }
1.795     www      4975: 
1.425     albertel 4976: table.LC_data_table tr.LC_data_table_highlight td {
                   4977:   background-color: $data_table_darker;
                   4978: }
1.795     www      4979: 
1.639     raeburn  4980: table.LC_data_table tr td.LC_leftcol_header {
                   4981:   background-color: $data_table_head;
                   4982:   font-weight: bold;
                   4983: }
1.795     www      4984: 
1.451     albertel 4985: table.LC_data_table tr.LC_empty_row td,
1.507     raeburn  4986: table.LC_nested tr.LC_empty_row td {
1.347     albertel 4987:   background-color: #FFFFFF;
1.421     albertel 4988:   font-weight: bold;
                   4989:   font-style: italic;
                   4990:   text-align: center;
                   4991:   padding: 8px;
1.347     albertel 4992: }
1.795     www      4993: 
1.507     raeburn  4994: table.LC_nested tr.LC_empty_row td {
1.465     albertel 4995:   padding: 4ex
                   4996: }
1.795     www      4997: 
1.507     raeburn  4998: table.LC_nested_outer tr th {
                   4999:   font-weight: bold;
1.801     tempelho 5000:   color:$fontmenu;
1.507     raeburn  5001:   background-color: $data_table_head;
1.701     harmsja  5002:   font-size: small;
1.507     raeburn  5003:   border-bottom: 1px solid #000000;
                   5004: }
1.795     www      5005: 
1.507     raeburn  5006: table.LC_nested_outer tr td.LC_subheader {
                   5007:   background-color: $data_table_head;
                   5008:   font-weight: bold;
                   5009:   font-size: small;
                   5010:   border-bottom: 1px solid #000000;
                   5011:   text-align: right;
1.451     albertel 5012: }
1.795     www      5013: 
1.507     raeburn  5014: table.LC_nested tr.LC_info_row td {
1.735     bisitz   5015:   background-color: #CCCCCC;
1.451     albertel 5016:   font-weight: bold;
                   5017:   font-size: small;
1.507     raeburn  5018:   text-align: center;
                   5019: }
1.795     www      5020: 
1.589     raeburn  5021: table.LC_nested tr.LC_info_row td.LC_left_item,
                   5022: table.LC_nested_outer tr th.LC_left_item {
1.507     raeburn  5023:   text-align: left;
1.451     albertel 5024: }
1.795     www      5025: 
1.507     raeburn  5026: table.LC_nested td {
1.735     bisitz   5027:   background-color: #FFFFFF;
1.451     albertel 5028:   font-size: small;
1.507     raeburn  5029: }
1.795     www      5030: 
1.507     raeburn  5031: table.LC_nested_outer tr th.LC_right_item,
                   5032: table.LC_nested tr.LC_info_row td.LC_right_item,
                   5033: table.LC_nested tr.LC_odd_row td.LC_right_item,
                   5034: table.LC_nested tr td.LC_right_item {
1.451     albertel 5035:   text-align: right;
                   5036: }
                   5037: 
1.507     raeburn  5038: table.LC_nested tr.LC_odd_row td {
1.735     bisitz   5039:   background-color: #EEEEEE;
1.451     albertel 5040: }
                   5041: 
1.473     raeburn  5042: table.LC_createuser {
                   5043: }
                   5044: 
                   5045: table.LC_createuser tr.LC_section_row td {
1.701     harmsja  5046:   font-size: small;
1.473     raeburn  5047: }
                   5048: 
                   5049: table.LC_createuser tr.LC_info_row td  {
1.735     bisitz   5050:   background-color: #CCCCCC;
1.473     raeburn  5051:   font-weight: bold;
                   5052:   text-align: center;
                   5053: }
                   5054: 
1.349     albertel 5055: table.LC_calendar {
                   5056:   border: 1px solid #000000;
                   5057:   border-collapse: collapse;
                   5058: }
1.795     www      5059: 
1.349     albertel 5060: table.LC_calendar_pickdate {
                   5061:   font-size: xx-small;
                   5062: }
1.795     www      5063: 
1.349     albertel 5064: table.LC_calendar tr td {
                   5065:   border: 1px solid #000000;
                   5066:   vertical-align: top;
                   5067: }
1.795     www      5068: 
1.349     albertel 5069: table.LC_calendar tr td.LC_calendar_day_empty {
                   5070:   background-color: $data_table_dark;
                   5071: }
1.795     www      5072: 
1.779     bisitz   5073: table.LC_calendar tr td.LC_calendar_day_current {
                   5074:   background-color: $data_table_highlight;
1.777     tempelho 5075: }
1.795     www      5076: 
1.349     albertel 5077: table.LC_mail_list tr.LC_mail_new {
                   5078:   background-color: $mail_new;
                   5079: }
1.795     www      5080: 
1.349     albertel 5081: table.LC_mail_list tr.LC_mail_new:hover {
                   5082:   background-color: $mail_new_hover;
                   5083: }
1.795     www      5084: 
                   5085: table.LC_mail_list tr.LC_mail_even {
1.777     tempelho 5086: }
1.795     www      5087: 
                   5088: table.LC_mail_list tr.LC_mail_odd {
1.777     tempelho 5089: }
1.795     www      5090: 
1.349     albertel 5091: table.LC_mail_list tr.LC_mail_read {
                   5092:   background-color: $mail_read;
                   5093: }
1.795     www      5094: 
1.349     albertel 5095: table.LC_mail_list tr.LC_mail_read:hover {
                   5096:   background-color: $mail_read_hover;
                   5097: }
1.795     www      5098: 
1.349     albertel 5099: table.LC_mail_list tr.LC_mail_replied {
                   5100:   background-color: $mail_replied;
                   5101: }
1.795     www      5102: 
1.349     albertel 5103: table.LC_mail_list tr.LC_mail_replied:hover {
                   5104:   background-color: $mail_replied_hover;
                   5105: }
1.795     www      5106: 
1.349     albertel 5107: table.LC_mail_list tr.LC_mail_other {
                   5108:   background-color: $mail_other;
                   5109: }
1.795     www      5110: 
1.349     albertel 5111: table.LC_mail_list tr.LC_mail_other:hover {
                   5112:   background-color: $mail_other_hover;
                   5113: }
1.494     raeburn  5114: 
1.777     tempelho 5115: table.LC_data_table tr > td.LC_browser_file,
                   5116: table.LC_data_table tr > td.LC_browser_file_published {
1.389     albertel 5117:   background: #CCFF88;
                   5118: }
1.795     www      5119: 
1.777     tempelho 5120: table.LC_data_table tr > td.LC_browser_file_locked,
                   5121: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389     albertel 5122:   background: #FFAA99;
1.387     albertel 5123: }
1.795     www      5124: 
1.777     tempelho 5125: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.779     bisitz   5126:   background: #AAAAAA;
                   5127: }
1.795     www      5128: 
1.777     tempelho 5129: table.LC_data_table tr > td.LC_browser_file_modified,
1.779     bisitz   5130: table.LC_data_table tr > td.LC_browser_file_metamodified {
                   5131:   background: #FFFF77;
1.777     tempelho 5132: }
1.795     www      5133: 
1.696     bisitz   5134: table.LC_data_table tr.LC_browser_folder > td {
1.389     albertel 5135:   background: #CCCCFF;
1.387     albertel 5136: }
1.696     bisitz   5137: 
1.707     bisitz   5138: table.LC_data_table tr > td.LC_roles_is {
                   5139: /*  background: #77FF77; */
                   5140: }
1.795     www      5141: 
1.707     bisitz   5142: table.LC_data_table tr > td.LC_roles_future {
                   5143:   background: #FFFF77;
                   5144: }
1.795     www      5145: 
1.707     bisitz   5146: table.LC_data_table tr > td.LC_roles_will {
                   5147:   background: #FFAA77;
                   5148: }
1.795     www      5149: 
1.707     bisitz   5150: table.LC_data_table tr > td.LC_roles_expired {
                   5151:   background: #FF7777;
                   5152: }
1.795     www      5153: 
1.707     bisitz   5154: table.LC_data_table tr > td.LC_roles_will_not {
                   5155:   background: #AAFF77;
                   5156: }
1.795     www      5157: 
1.707     bisitz   5158: table.LC_data_table tr > td.LC_roles_selected {
                   5159:   background: #11CC55;
                   5160: }
                   5161: 
1.388     albertel 5162: span.LC_current_location {
1.701     harmsja  5163:   font-size:larger;
1.388     albertel 5164:   background: $pgbg;
                   5165: }
1.387     albertel 5166: 
1.395     albertel 5167: span.LC_parm_menu_item {
                   5168:   font-size: larger;
                   5169: }
1.795     www      5170: 
1.395     albertel 5171: span.LC_parm_scope_all {
                   5172:   color: red;
                   5173: }
1.795     www      5174: 
1.395     albertel 5175: span.LC_parm_scope_folder {
                   5176:   color: green;
                   5177: }
1.795     www      5178: 
1.395     albertel 5179: span.LC_parm_scope_resource {
                   5180:   color: orange;
                   5181: }
1.795     www      5182: 
1.395     albertel 5183: span.LC_parm_part {
                   5184:   color: blue;
                   5185: }
1.795     www      5186: 
1.395     albertel 5187: span.LC_parm_folder, span.LC_parm_symb {
                   5188:   font-size: x-small;
                   5189:   font-family: $mono;
                   5190:   color: #AAAAAA;
                   5191: }
                   5192: 
1.795     www      5193: td.LC_parm_overview_level_menu,
                   5194: td.LC_parm_overview_map_menu,
                   5195: td.LC_parm_overview_parm_selectors,
                   5196: td.LC_parm_overview_restrictions  {
1.396     albertel 5197:   border: 1px solid black;
                   5198:   border-collapse: collapse;
                   5199: }
1.795     www      5200: 
1.396     albertel 5201: table.LC_parm_overview_restrictions td {
                   5202:   border-width: 1px 4px 1px 4px;
                   5203:   border-style: solid;
                   5204:   border-color: $pgbg;
                   5205:   text-align: center;
                   5206: }
1.795     www      5207: 
1.396     albertel 5208: table.LC_parm_overview_restrictions th {
                   5209:   background: $tabbg;
                   5210:   border-width: 1px 4px 1px 4px;
                   5211:   border-style: solid;
                   5212:   border-color: $pgbg;
                   5213: }
1.795     www      5214: 
1.398     albertel 5215: table#LC_helpmenu {
1.803     bisitz   5216:   border: none;
1.398     albertel 5217:   height: 55px;
1.803     bisitz   5218:   border-spacing: 0;
1.398     albertel 5219: }
                   5220: 
                   5221: table#LC_helpmenu fieldset legend {
                   5222:   font-size: larger;
                   5223: }
1.795     www      5224: 
1.397     albertel 5225: table#LC_helpmenu_links {
                   5226:   width: 100%;
                   5227:   border: 1px solid black;
                   5228:   background: $pgbg;
1.803     bisitz   5229:   padding: 0;
1.397     albertel 5230:   border-spacing: 1px;
                   5231: }
1.795     www      5232: 
1.397     albertel 5233: table#LC_helpmenu_links tr td {
                   5234:   padding: 1px;
                   5235:   background: $tabbg;
1.399     albertel 5236:   text-align: center;
                   5237:   font-weight: bold;
1.397     albertel 5238: }
1.396     albertel 5239: 
1.795     www      5240: table#LC_helpmenu_links a:link,
                   5241: table#LC_helpmenu_links a:visited,
1.397     albertel 5242: table#LC_helpmenu_links a:active {
                   5243:   text-decoration: none;
                   5244:   color: $font;
                   5245: }
1.795     www      5246: 
1.397     albertel 5247: table#LC_helpmenu_links a:hover {
                   5248:   text-decoration: underline;
                   5249:   color: $vlink;
                   5250: }
1.396     albertel 5251: 
1.417     albertel 5252: .LC_chrt_popup_exists {
                   5253:   border: 1px solid #339933;
                   5254:   margin: -1px;
                   5255: }
1.795     www      5256: 
1.417     albertel 5257: .LC_chrt_popup_up {
                   5258:   border: 1px solid yellow;
                   5259:   margin: -1px;
                   5260: }
1.795     www      5261: 
1.417     albertel 5262: .LC_chrt_popup {
                   5263:   border: 1px solid #8888FF;
                   5264:   background: #CCCCFF;
                   5265: }
1.795     www      5266: 
1.421     albertel 5267: table.LC_pick_box {
                   5268:   border-collapse: separate;
                   5269:   background: white;
                   5270:   border: 1px solid black;
                   5271:   border-spacing: 1px;
                   5272: }
1.795     www      5273: 
1.421     albertel 5274: table.LC_pick_box td.LC_pick_box_title {
1.850     bisitz   5275:   background: $sidebg;
1.421     albertel 5276:   font-weight: bold;
                   5277:   text-align: right;
1.740     bisitz   5278:   vertical-align: top;
1.421     albertel 5279:   width: 184px;
                   5280:   padding: 8px;
                   5281: }
1.795     www      5282: 
1.579     raeburn  5283: table.LC_pick_box td.LC_pick_box_value {
                   5284:   text-align: left;
                   5285:   padding: 8px;
                   5286: }
1.795     www      5287: 
1.579     raeburn  5288: table.LC_pick_box td.LC_pick_box_select {
                   5289:   text-align: left;
                   5290:   padding: 8px;
                   5291: }
1.795     www      5292: 
1.424     albertel 5293: table.LC_pick_box td.LC_pick_box_separator {
1.803     bisitz   5294:   padding: 0;
1.421     albertel 5295:   height: 1px;
                   5296:   background: black;
                   5297: }
1.795     www      5298: 
1.421     albertel 5299: table.LC_pick_box td.LC_pick_box_submit {
                   5300:   text-align: right;
                   5301: }
1.795     www      5302: 
1.579     raeburn  5303: table.LC_pick_box td.LC_evenrow_value {
                   5304:   text-align: left;
                   5305:   padding: 8px;
                   5306:   background-color: $data_table_light;
                   5307: }
1.795     www      5308: 
1.579     raeburn  5309: table.LC_pick_box td.LC_oddrow_value {
                   5310:   text-align: left;
                   5311:   padding: 8px;
                   5312:   background-color: $data_table_light;
                   5313: }
1.795     www      5314: 
1.579     raeburn  5315: table.LC_helpform_receipt {
                   5316:   width: 620px;
                   5317:   border-collapse: separate;
                   5318:   background: white;
                   5319:   border: 1px solid black;
                   5320:   border-spacing: 1px;
                   5321: }
1.795     www      5322: 
1.579     raeburn  5323: table.LC_helpform_receipt td.LC_pick_box_title {
                   5324:   background: $tabbg;
                   5325:   font-weight: bold;
                   5326:   text-align: right;
                   5327:   width: 184px;
                   5328:   padding: 8px;
                   5329: }
1.795     www      5330: 
1.579     raeburn  5331: table.LC_helpform_receipt td.LC_evenrow_value {
                   5332:   text-align: left;
                   5333:   padding: 8px;
                   5334:   background-color: $data_table_light;
                   5335: }
1.795     www      5336: 
1.579     raeburn  5337: table.LC_helpform_receipt td.LC_oddrow_value {
                   5338:   text-align: left;
                   5339:   padding: 8px;
                   5340:   background-color: $data_table_light;
                   5341: }
1.795     www      5342: 
1.579     raeburn  5343: table.LC_helpform_receipt td.LC_pick_box_separator {
1.803     bisitz   5344:   padding: 0;
1.579     raeburn  5345:   height: 1px;
                   5346:   background: black;
                   5347: }
1.795     www      5348: 
1.579     raeburn  5349: span.LC_helpform_receipt_cat {
                   5350:   font-weight: bold;
                   5351: }
1.795     www      5352: 
1.424     albertel 5353: table.LC_group_priv_box {
                   5354:   background: white;
                   5355:   border: 1px solid black;
                   5356:   border-spacing: 1px;
                   5357: }
1.795     www      5358: 
1.424     albertel 5359: table.LC_group_priv_box td.LC_pick_box_title {
                   5360:   background: $tabbg;
                   5361:   font-weight: bold;
                   5362:   text-align: right;
                   5363:   width: 184px;
                   5364: }
1.795     www      5365: 
1.424     albertel 5366: table.LC_group_priv_box td.LC_groups_fixed {
                   5367:   background: $data_table_light;
                   5368:   text-align: center;
                   5369: }
1.795     www      5370: 
1.424     albertel 5371: table.LC_group_priv_box td.LC_groups_optional {
                   5372:   background: $data_table_dark;
                   5373:   text-align: center;
                   5374: }
1.795     www      5375: 
1.424     albertel 5376: table.LC_group_priv_box td.LC_groups_functionality {
                   5377:   background: $data_table_darker;
                   5378:   text-align: center;
                   5379:   font-weight: bold;
                   5380: }
1.795     www      5381: 
1.424     albertel 5382: table.LC_group_priv td {
                   5383:   text-align: left;
1.803     bisitz   5384:   padding: 0;
1.424     albertel 5385: }
                   5386: 
1.421     albertel 5387: table.LC_notify_front_page {
                   5388:   background: white;
                   5389:   border: 1px solid black;
                   5390:   padding: 8px;
                   5391: }
1.795     www      5392: 
1.421     albertel 5393: table.LC_notify_front_page td {
                   5394:   padding: 8px;
                   5395: }
1.795     www      5396: 
1.424     albertel 5397: .LC_navbuttons {
                   5398:   margin: 2ex 0ex 2ex 0ex;
                   5399: }
1.795     www      5400: 
1.423     albertel 5401: .LC_topic_bar {
                   5402:   font-weight: bold;
                   5403:   width: 100%;
                   5404:   background: $tabbg;
                   5405:   vertical-align: middle;
                   5406:   margin: 2ex 0ex 2ex 0ex;
1.805     bisitz   5407:   padding: 3px;
1.423     albertel 5408: }
1.795     www      5409: 
1.423     albertel 5410: .LC_topic_bar span {
                   5411:   vertical-align: middle;
                   5412: }
1.795     www      5413: 
1.423     albertel 5414: .LC_topic_bar img {
                   5415:   vertical-align: bottom;
                   5416: }
1.795     www      5417: 
1.423     albertel 5418: table.LC_course_group_status {
                   5419:   margin: 20px;
                   5420: }
1.795     www      5421: 
1.423     albertel 5422: table.LC_status_selector td {
                   5423:   vertical-align: top;
                   5424:   text-align: center;
1.424     albertel 5425:   padding: 4px;
                   5426: }
1.795     www      5427: 
1.599     albertel 5428: div.LC_feedback_link {
1.616     albertel 5429:   clear: both;
1.829     kalberla 5430:   background: $sidebg;
1.779     bisitz   5431:   width: 100%;
1.829     kalberla 5432:   padding-bottom: 10px;
                   5433:   border: 1px $tabbg solid;
1.833     kalberla 5434:   height: 22px;
                   5435:   line-height: 22px;
                   5436:   padding-top: 5px;
                   5437: }
                   5438: 
                   5439: div.LC_feedback_link img {
                   5440:   height: 22px;
1.867     kalberla 5441:   vertical-align:middle;
1.829     kalberla 5442: }
                   5443: 
                   5444: div.LC_feedback_link a{
                   5445:   text-decoration: none;
1.489     raeburn  5446: }
1.795     www      5447: 
1.867     kalberla 5448: div.LC_comblock {
                   5449:   display:inline; 
                   5450:   color:$font;
                   5451:   font-size:90%;
                   5452: }
                   5453: 
                   5454: div.LC_feedback_link div.LC_comblock {
                   5455:   padding-left:5px;
                   5456: }
                   5457: 
                   5458: div.LC_feedback_link div.LC_comblock a {
                   5459:   color:$font;
                   5460: }
                   5461: 
1.489     raeburn  5462: span.LC_feedback_link {
1.858     bisitz   5463:   /* background: $feedback_link_bg; */
1.599     albertel 5464:   font-size: larger;
                   5465: }
1.795     www      5466: 
1.599     albertel 5467: span.LC_message_link {
1.858     bisitz   5468:   /* background: $feedback_link_bg; */
1.599     albertel 5469:   font-size: larger;
                   5470:   position: absolute;
                   5471:   right: 1em;
1.489     raeburn  5472: }
1.421     albertel 5473: 
1.515     albertel 5474: table.LC_prior_tries {
1.524     albertel 5475:   border: 1px solid #000000;
                   5476:   border-collapse: separate;
                   5477:   border-spacing: 1px;
1.515     albertel 5478: }
1.523     albertel 5479: 
1.515     albertel 5480: table.LC_prior_tries td {
1.524     albertel 5481:   padding: 2px;
1.515     albertel 5482: }
1.523     albertel 5483: 
                   5484: .LC_answer_correct {
1.795     www      5485:   background: lightgreen;
                   5486:   color: darkgreen;
                   5487:   padding: 6px;
1.523     albertel 5488: }
1.795     www      5489: 
1.523     albertel 5490: .LC_answer_charged_try {
1.797     www      5491:   background: #FFAAAA;
1.795     www      5492:   color: darkred;
                   5493:   padding: 6px;
1.523     albertel 5494: }
1.795     www      5495: 
1.779     bisitz   5496: .LC_answer_not_charged_try,
1.523     albertel 5497: .LC_answer_no_grade,
                   5498: .LC_answer_late {
1.795     www      5499:   background: lightyellow;
1.523     albertel 5500:   color: black;
1.795     www      5501:   padding: 6px;
1.523     albertel 5502: }
1.795     www      5503: 
1.523     albertel 5504: .LC_answer_previous {
1.795     www      5505:   background: lightblue;
                   5506:   color: darkblue;
                   5507:   padding: 6px;
1.523     albertel 5508: }
1.795     www      5509: 
1.779     bisitz   5510: .LC_answer_no_message {
1.777     tempelho 5511:   background: #FFFFFF;
                   5512:   color: black;
1.795     www      5513:   padding: 6px;
1.779     bisitz   5514: }
1.795     www      5515: 
1.779     bisitz   5516: .LC_answer_unknown {
                   5517:   background: orange;
                   5518:   color: black;
1.795     www      5519:   padding: 6px;
1.777     tempelho 5520: }
1.795     www      5521: 
1.529     albertel 5522: span.LC_prior_numerical,
                   5523: span.LC_prior_string,
                   5524: span.LC_prior_custom,
                   5525: span.LC_prior_reaction,
                   5526: span.LC_prior_math {
1.523     albertel 5527:   font-family: monospace;
                   5528:   white-space: pre;
                   5529: }
                   5530: 
1.525     albertel 5531: span.LC_prior_string {
                   5532:   font-family: monospace;
                   5533:   white-space: pre;
                   5534: }
                   5535: 
1.523     albertel 5536: table.LC_prior_option {
                   5537:   width: 100%;
                   5538:   border-collapse: collapse;
                   5539: }
1.795     www      5540: 
                   5541: table.LC_prior_rank, 
                   5542: table.LC_prior_match {
1.528     albertel 5543:   border-collapse: collapse;
                   5544: }
1.795     www      5545: 
1.528     albertel 5546: table.LC_prior_option tr td,
                   5547: table.LC_prior_rank tr td,
                   5548: table.LC_prior_match tr td {
1.524     albertel 5549:   border: 1px solid #000000;
1.515     albertel 5550: }
                   5551: 
1.855     bisitz   5552: .LC_nobreak {
1.544     albertel 5553:   white-space: nowrap;
1.519     raeburn  5554: }
                   5555: 
1.576     raeburn  5556: span.LC_cusr_emph {
                   5557:   font-style: italic;
                   5558: }
                   5559: 
1.633     raeburn  5560: span.LC_cusr_subheading {
                   5561:   font-weight: normal;
                   5562:   font-size: 85%;
                   5563: }
                   5564: 
1.545     albertel 5565: table.LC_docs_documents {
                   5566:   background: #BBBBBB;
1.803     bisitz   5567:   border-width: 0;
1.545     albertel 5568:   border-collapse: collapse;
                   5569: }
1.795     www      5570: 
1.777     tempelho 5571: table.LC_docs_documents td.LC_docs_document {
1.779     bisitz   5572:   border: 2px solid black;
                   5573:   padding: 4px;
1.777     tempelho 5574: }
1.795     www      5575: 
1.861     bisitz   5576: div.LC_docs_entry_move {
1.859     bisitz   5577:   border: 1px solid #BBBBBB;
1.545     albertel 5578:   background: #DDDDDD;
1.861     bisitz   5579:   width: 22px;
1.859     bisitz   5580:   padding: 1px;
                   5581:   margin: 0;
1.545     albertel 5582: }
                   5583: 
1.861     bisitz   5584: table.LC_data_table tr > td.LC_docs_entry_commands,
                   5585: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545     albertel 5586:   background: #DDDDDD;
                   5587:   font-size: x-small;
                   5588: }
1.795     www      5589: 
1.861     bisitz   5590: .LC_docs_entry_parameter {
                   5591:   white-space: nowrap;
                   5592: }
                   5593: 
1.544     albertel 5594: .LC_docs_copy {
1.545     albertel 5595:   color: #000099;
1.544     albertel 5596: }
1.795     www      5597: 
1.544     albertel 5598: .LC_docs_cut {
1.545     albertel 5599:   color: #550044;
1.544     albertel 5600: }
1.795     www      5601: 
1.544     albertel 5602: .LC_docs_rename {
1.545     albertel 5603:   color: #009900;
1.544     albertel 5604: }
1.795     www      5605: 
1.544     albertel 5606: .LC_docs_remove {
1.545     albertel 5607:   color: #990000;
                   5608: }
                   5609: 
1.547     albertel 5610: .LC_docs_reinit_warn,
                   5611: .LC_docs_ext_edit {
                   5612:   font-size: x-small;
                   5613: }
                   5614: 
1.545     albertel 5615: table.LC_docs_adddocs td,
                   5616: table.LC_docs_adddocs th {
                   5617:   border: 1px solid #BBBBBB;
                   5618:   padding: 4px;
                   5619:   background: #DDDDDD;
1.543     albertel 5620: }
                   5621: 
1.584     albertel 5622: table.LC_sty_begin {
                   5623:   background: #BBFFBB;
                   5624: }
1.795     www      5625: 
1.584     albertel 5626: table.LC_sty_end {
                   5627:   background: #FFBBBB;
                   5628: }
                   5629: 
1.589     raeburn  5630: table.LC_double_column {
1.803     bisitz   5631:   border-width: 0;
1.589     raeburn  5632:   border-collapse: collapse;
                   5633:   width: 100%;
                   5634:   padding: 2px;
                   5635: }
                   5636: 
                   5637: table.LC_double_column tr td.LC_left_col {
1.590     raeburn  5638:   top: 2px;
1.589     raeburn  5639:   left: 2px;
                   5640:   width: 47%;
                   5641:   vertical-align: top;
                   5642: }
                   5643: 
                   5644: table.LC_double_column tr td.LC_right_col {
                   5645:   top: 2px;
1.779     bisitz   5646:   right: 2px;
1.589     raeburn  5647:   width: 47%;
                   5648:   vertical-align: top;
                   5649: }
                   5650: 
1.591     raeburn  5651: div.LC_left_float {
                   5652:   float: left;
                   5653:   padding-right: 5%;
1.597     albertel 5654:   padding-bottom: 4px;
1.591     raeburn  5655: }
                   5656: 
                   5657: div.LC_clear_float_header {
1.597     albertel 5658:   padding-bottom: 2px;
1.591     raeburn  5659: }
                   5660: 
                   5661: div.LC_clear_float_footer {
1.597     albertel 5662:   padding-top: 10px;
1.591     raeburn  5663:   clear: both;
                   5664: }
                   5665: 
1.597     albertel 5666: div.LC_grade_show_user {
                   5667:   margin-top: 20px;
                   5668:   border: 1px solid black;
                   5669: }
1.795     www      5670: 
1.597     albertel 5671: div.LC_grade_user_name {
                   5672:   background: #DDDDEE;
                   5673:   border-bottom: 1px solid black;
1.705     tempelho 5674:   font-weight: bold;
                   5675:   font-size: large;
1.597     albertel 5676: }
1.795     www      5677: 
1.597     albertel 5678: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
                   5679:   background: #DDEEDD;
                   5680: }
                   5681: 
                   5682: div.LC_grade_show_problem,
                   5683: div.LC_grade_submissions,
                   5684: div.LC_grade_message_center,
                   5685: div.LC_grade_info_links,
                   5686: div.LC_grade_assign {
                   5687:   margin: 5px;
                   5688:   width: 99%;
                   5689:   background: #FFFFFF;
                   5690: }
1.795     www      5691: 
1.597     albertel 5692: div.LC_grade_show_problem_header,
                   5693: div.LC_grade_submissions_header,
                   5694: div.LC_grade_message_center_header,
                   5695: div.LC_grade_assign_header {
1.705     tempelho 5696:   font-weight: bold;
                   5697:   font-size: large;
1.597     albertel 5698: }
1.795     www      5699: 
1.597     albertel 5700: div.LC_grade_show_problem_problem,
                   5701: div.LC_grade_submissions_body,
                   5702: div.LC_grade_message_center_body,
                   5703: div.LC_grade_assign_body {
                   5704:   border: 1px solid black;
                   5705:   width: 99%;
                   5706:   background: #FFFFFF;
                   5707: }
1.795     www      5708: 
1.598     albertel 5709: span.LC_grade_check_note {
1.705     tempelho 5710:   font-weight: normal;
                   5711:   font-size: medium;
1.598     albertel 5712:   display: inline;
                   5713:   position: absolute;
                   5714:   right: 1em;
                   5715: }
1.597     albertel 5716: 
1.613     albertel 5717: table.LC_scantron_action {
                   5718:   width: 100%;
                   5719: }
1.795     www      5720: 
1.613     albertel 5721: table.LC_scantron_action tr th {
1.698     harmsja  5722:   font-weight:bold;
                   5723:   font-style:normal;
1.613     albertel 5724: }
1.795     www      5725: 
1.779     bisitz   5726: .LC_edit_problem_header,
1.614     albertel 5727: div.LC_edit_problem_footer {
1.705     tempelho 5728:   font-weight: normal;
                   5729:   font-size:  medium;
1.602     albertel 5730:   margin: 2px;
1.600     albertel 5731: }
1.795     www      5732: 
1.600     albertel 5733: div.LC_edit_problem_header,
1.602     albertel 5734: div.LC_edit_problem_header div,
1.614     albertel 5735: div.LC_edit_problem_footer,
                   5736: div.LC_edit_problem_footer div,
1.602     albertel 5737: div.LC_edit_problem_editxml_header,
                   5738: div.LC_edit_problem_editxml_header div {
1.600     albertel 5739:   margin-top: 5px;
                   5740: }
1.795     www      5741: 
1.600     albertel 5742: div.LC_edit_problem_header_title {
1.705     tempelho 5743:   font-weight: bold;
                   5744:   font-size: larger;
1.602     albertel 5745:   background: $tabbg;
                   5746:   padding: 3px;
                   5747: }
1.795     www      5748: 
1.602     albertel 5749: table.LC_edit_problem_header_title {
1.705     tempelho 5750:   font-size: larger;
                   5751:   font-weight:  bold;
1.602     albertel 5752:   width: 100%;
                   5753:   border-color: $pgbg;
                   5754:   border-style: solid;
                   5755:   border-width: $border;
1.600     albertel 5756:   background: $tabbg;
1.602     albertel 5757:   border-collapse: collapse;
1.803     bisitz   5758:   padding: 0;
1.602     albertel 5759: }
                   5760: 
                   5761: div.LC_edit_problem_discards {
                   5762:   float: left;
                   5763:   padding-bottom: 5px;
                   5764: }
1.795     www      5765: 
1.602     albertel 5766: div.LC_edit_problem_saves {
                   5767:   float: right;
                   5768:   padding-bottom: 5px;
1.600     albertel 5769: }
1.795     www      5770: 
1.679     riegler  5771: img.stift{
1.803     bisitz   5772:   border-width: 0;
                   5773:   vertical-align: middle;
1.677     riegler  5774: }
1.680     riegler  5775: 
1.681     riegler  5776: table#LC_mainmenu{
                   5777:  margin-top:10px;
                   5778:  width:80%;
                   5779: }
                   5780: 
1.680     riegler  5781: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
                   5782:   vertical-align: top;
                   5783:   width: 45%;
                   5784: }
1.795     www      5785: 
1.779     bisitz   5786: .LC_mainmenu_fieldset_category {
                   5787:   color: $font;
                   5788:   background: $pgbg;
                   5789:   font-size: small;
                   5790:   font-weight: bold;
1.777     tempelho 5791: }
1.795     www      5792: 
1.716     raeburn  5793: div.LC_createcourse {
                   5794:     margin: 10px 10px 10px 10px;
                   5795: }
                   5796: 
1.693     droeschl 5797: /* ---- Remove when done ----
                   5798: # The following styles is part of the redesign of LON-CAPA and are
                   5799: # subject to change during this project.
                   5800: # Don't rely on their current functionality as they might be 
                   5801: # changed or removed.
                   5802: # --------------------------*/
                   5803: 
1.698     harmsja  5804: a:hover,
1.721     harmsja  5805: ol.LC_smallMenu a:hover,
                   5806: ol#LC_MenuBreadcrumbs a:hover,
                   5807: ol#LC_PathBreadcrumbs a:hover,
                   5808: ul#LC_TabMainMenuContent a:hover,
                   5809: .LC_FormSectionClearButton input:hover
1.795     www      5810: ul.LC_TabContent   li:hover a {
1.698     harmsja  5811: 	color:#BF2317;
                   5812:         text-decoration:none;
1.693     droeschl 5813: }
                   5814: 
1.779     bisitz   5815: h1 {
1.813     bisitz   5816: 	padding: 0;
1.693     droeschl 5817: 	line-height:130%;
                   5818: }
1.698     harmsja  5819: 
1.795     www      5820: h2,h3,h4,h5,h6 {
1.803     bisitz   5821: 	margin: 5px 0 5px 0;
                   5822: 	padding: 0;
1.721     harmsja  5823: 	line-height:130%;
1.693     droeschl 5824: }
1.795     www      5825: 
                   5826: .LC_hcell {
1.698     harmsja  5827:         padding:3px 15px 3px 15px;
1.803     bisitz   5828:         margin: 0;
1.703     harmsja  5829: 	background-color:$tabbg;
1.801     tempelho 5830: 	color:$fontmenu;
1.779     bisitz   5831: 	border-bottom:solid 1px $lg_border_color;
1.693     droeschl 5832: }
1.795     www      5833: 
1.840     bisitz   5834: .LC_Box > .LC_hcell {
1.847     tempelho 5835:     margin: 0 -10px 10px -10px;
1.835     bisitz   5836: }
                   5837: 
1.721     harmsja  5838: .LC_noBorder {
1.803     bisitz   5839:         border: 0;
1.698     harmsja  5840: }
1.693     droeschl 5841: 
1.761     tempelho 5842: .LC_Right {
                   5843:         float: right;
1.803     bisitz   5844:         margin: 0;
                   5845:         padding: 0;
1.761     tempelho 5846: }
                   5847: 
1.721     harmsja  5848: .LC_FormSectionClearButton input {
1.779     bisitz   5849:         background-color:transparent;
1.803     bisitz   5850:         border: none;
1.698     harmsja  5851:         cursor:pointer;
                   5852:         text-decoration:underline;
1.693     droeschl 5853: }
1.763     bisitz   5854: 
                   5855: .LC_help_open_topic {
                   5856:         color: #FFFFFF;
                   5857:         background-color: #EEEEFF;
                   5858:         margin: 1px;
                   5859:         padding: 4px;
                   5860:         border: 1px solid #000033;
                   5861:         white-space: nowrap;
1.783     amueller 5862: /*		vertical-align: middle; */
1.759     neumanie 5863: }
1.693     droeschl 5864: 
1.698     harmsja  5865: dl,ul,div,fieldset {
1.803     bisitz   5866: 	margin: 10px 10px 10px 0;
1.806     bisitz   5867: /*	overflow: hidden; */
1.693     droeschl 5868: }
1.795     www      5869: 
1.838     bisitz   5870: fieldset > legend {
                   5871:     font-weight: bold;
                   5872:     padding: 0 5px 0 5px;
                   5873: }
                   5874: 
1.813     bisitz   5875: #LC_nav_bar {
1.807     droeschl 5876:     float: left;
1.852     droeschl 5877:     margin: 0.2em 0 0 0;
1.807     droeschl 5878: }
                   5879: 
1.813     bisitz   5880: #LC_nav_bar em{
1.807     droeschl 5881:     font-weight: bold;
                   5882:     font-style: normal;
                   5883: }
                   5884: 
                   5885: ol.LC_smallMenu {
                   5886:     float: right;
1.852     droeschl 5887:     margin: 0.2em 0 0 0;
1.807     droeschl 5888: }
                   5889: 
1.852     droeschl 5890: ol#LC_PathBreadcrumbs {
1.803     bisitz   5891: 	margin: 0;
1.693     droeschl 5892: }
                   5893: 
1.721     harmsja  5894: ol.LC_smallMenu li {
1.693     droeschl 5895: 	display: inline;
1.803     bisitz   5896: 	padding: 5px 5px 0 10px;
1.693     droeschl 5897: 	vertical-align: top;
                   5898: }
                   5899: 
1.721     harmsja  5900: ol.LC_smallMenu li img {
1.693     droeschl 5901: 	vertical-align: bottom;
                   5902: }
                   5903: 
1.721     harmsja  5904: ol.LC_smallMenu a {
1.693     droeschl 5905: 	font-size: 90%;
                   5906: 	color: RGB(80, 80, 80);
                   5907: 	text-decoration: none;
                   5908: }
1.795     www      5909: 
1.808     droeschl 5910: ul#LC_TabMainMenuContent {
1.807     droeschl 5911:     clear: both;
1.808     droeschl 5912:     color: $fontmenu;
                   5913:     background: $tabbg;
                   5914:     list-style: none;
                   5915:     padding: 0;
                   5916:     margin: 0;
                   5917:     width: 100%;
                   5918: }
                   5919: 
                   5920: ul#LC_TabMainMenuContent li {
                   5921:     font-weight: bold;
                   5922:     line-height: 1.8em;
                   5923:     padding: 0 0.8em; 
                   5924:     border-right: 1px solid black;
                   5925:     display: inline;
                   5926:     vertical-align: middle;
1.807     droeschl 5927: }
                   5928: 
1.847     tempelho 5929: ul.LC_TabContent {
1.721     harmsja  5930: 	display:block;
1.847     tempelho 5931: 	background: $sidebg;
1.858     bisitz   5932: 	border-bottom: solid 1px $lg_border_color;
1.721     harmsja  5933: 	list-style:none;
1.870     tempelho 5934: 	margin: 0 -10px;
1.803     bisitz   5935: 	padding: 0;
1.693     droeschl 5936: }
                   5937: 
1.795     www      5938: ul.LC_TabContent li,
                   5939: ul.LC_TabContentBigger li {
1.741     harmsja  5940: 	float:left;
                   5941: }
1.795     www      5942: 
1.808     droeschl 5943: ul#LC_TabMainMenuContent li a {
                   5944:     color: $fontmenu;
1.693     droeschl 5945: 	text-decoration: none;
                   5946: }
1.795     www      5947: 
1.721     harmsja  5948: ul.LC_TabContent {
1.847     tempelho 5949: 	min-height:1.5em;
1.721     harmsja  5950: }
1.795     www      5951: 
                   5952: ul.LC_TabContent li {
1.741     harmsja  5953: 	vertical-align:middle;
1.803     bisitz   5954: 	padding: 0 10px 0 10px;
1.745     ehlerst  5955: 	background-color:$tabbg;
                   5956: 	border-bottom:solid 1px $lg_border_color;
1.721     harmsja  5957: }
1.795     www      5958: 
1.847     tempelho 5959: ul.LC_TabContent .right {
                   5960: 	float:right;
                   5961: }
                   5962: 
1.795     www      5963: ul.LC_TabContent li a, ul.LC_TabContent li {
1.721     harmsja  5964: 	color:rgb(47,47,47);
                   5965: 	text-decoration:none;
                   5966: 	font-size:95%;
                   5967: 	font-weight:bold;
1.761     tempelho 5968: 	padding-right: 16px;
1.721     harmsja  5969: }
1.795     www      5970: 
                   5971: ul.LC_TabContent li:hover, ul.LC_TabContent li.active {
1.761     tempelho 5972:         background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.841     tempelho 5973: 	border-bottom:solid 2px #FFFFFF;
1.761     tempelho 5974: 	padding-right: 16px;
1.744     ehlerst  5975: }
1.795     www      5976: 
1.870     tempelho 5977: #maincoursedoc {
                   5978: 	clear:both;
                   5979: }
                   5980: 
                   5981: ul.LC_TabContentBigger {
                   5982:         display:block;
                   5983:         list-style:none;
                   5984:         padding: 0;
                   5985: }
                   5986: 
1.795     www      5987: ul.LC_TabContentBigger li {
1.870     tempelho 5988:         vertical-align:bottom;
                   5989:         height: 30px;
                   5990:         font-size:110%;
                   5991:         font-weight:bold;
                   5992:         color: #737373;
1.841     tempelho 5993: }
                   5994: 
1.870     tempelho 5995: 
                   5996: ul.LC_TabContentBigger li a {
                   5997:         background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
                   5998: 	height: 30px;
                   5999: 	line-height: 30px;
                   6000: 	text-align: center;
                   6001: 	display: block;
                   6002: 	text-decoration: none;
1.741     harmsja  6003: }
1.795     www      6004: 
1.870     tempelho 6005: ul.LC_TabContentBigger li:hover a, 
                   6006: ul.LC_TabContentBigger li.active a {
                   6007: 	background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
1.857     tempelho 6008: 	color:$font;
1.870     tempelho 6009: 	text-decoration: underline;
1.744     ehlerst  6010: }
1.795     www      6011: 
1.870     tempelho 6012: 
                   6013: ul.LC_TabContentBigger li b {
                   6014: 	background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
                   6015: 	display: block;
                   6016: 	float: left;
                   6017: 	padding: 0 30px;
                   6018: }
                   6019: 
                   6020: ul.LC_TabContentBigger li:hover b,
                   6021: ul.LC_TabContentBigger li.active b {
                   6022:         background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
                   6023:         color:$font;
                   6024: 	border-bottom: 1px solid #FFFFFF;
1.741     harmsja  6025: }
1.693     droeschl 6026: 
1.870     tempelho 6027: 
1.862     bisitz   6028: ul.LC_CourseBreadcrumbs {
                   6029:   background: $sidebg;
                   6030:   line-height: 32px;
                   6031:   padding-left: 10px;
                   6032:   margin: 0 0 10px 0;
                   6033:   list-style-position: inside;
                   6034: 
                   6035: }
                   6036: 
1.795     www      6037: ol#LC_MenuBreadcrumbs, 
1.862     bisitz   6038: ol#LC_PathBreadcrumbs {
1.693     droeschl 6039: 	padding-left: 10px;
1.819     tempelho 6040: 	margin: 0;
1.693     droeschl 6041: 	list-style-position: inside;
                   6042: }
                   6043: 
1.795     www      6044: ol#LC_MenuBreadcrumbs li, 
                   6045: ol#LC_PathBreadcrumbs li, 
1.862     bisitz   6046: ul.LC_CourseBreadcrumbs li {
1.842     droeschl 6047:     display: inline;
                   6048:     white-space: nowrap;
1.693     droeschl 6049: }
                   6050: 
1.823     bisitz   6051: ol#LC_MenuBreadcrumbs li a,
1.862     bisitz   6052: ul.LC_CourseBreadcrumbs li a {
1.693     droeschl 6053: 	text-decoration: none;
                   6054: 	font-size:90%;
                   6055: }
1.795     www      6056: 
                   6057: ol#LC_PathBreadcrumbs li a {
1.698     harmsja  6058: 	text-decoration:none;
                   6059: 	font-size:100%;
                   6060: 	font-weight:bold;
1.693     droeschl 6061: }
1.795     www      6062: 
1.840     bisitz   6063: .LC_Box {
1.835     bisitz   6064:     border: solid 1px $lg_border_color;
                   6065:     padding: 0 10px 10px 10px;
1.746     neumanie 6066: }
1.795     www      6067: 
                   6068: .LC_AboutMe_Image {
1.747     neumanie 6069: 	float:left;
                   6070: 	margin-right:10px;
                   6071: }
1.795     www      6072: 
                   6073: .LC_Clear_AboutMe_Image {
1.747     neumanie 6074: 	clear:left;
                   6075: }
1.795     www      6076: 
1.721     harmsja  6077: dl.LC_ListStyleClean dt {
1.693     droeschl 6078: 	padding-right: 5px;
                   6079: 	display: table-header-group;
                   6080: }
                   6081: 
1.721     harmsja  6082: dl.LC_ListStyleClean dd {
1.693     droeschl 6083: 	display: table-row;
                   6084: }
                   6085: 
1.721     harmsja  6086: .LC_ListStyleClean,
                   6087: .LC_ListStyleSimple,
                   6088: .LC_ListStyleNormal,
1.777     tempelho 6089: .LC_ListStyle_Border,
1.795     www      6090: .LC_ListStyleSpecial {
1.693     droeschl 6091: 	/*display:block;	*/
                   6092: 	list-style-position: inside;
                   6093: 	list-style-type: none;
                   6094: 	overflow: hidden;
1.803     bisitz   6095: 	padding: 0;
1.693     droeschl 6096: }
                   6097: 
1.721     harmsja  6098: .LC_ListStyleSimple li,
                   6099: .LC_ListStyleSimple dd,
                   6100: .LC_ListStyleNormal li,
                   6101: .LC_ListStyleNormal dd,
                   6102: .LC_ListStyleSpecial li,
1.795     www      6103: .LC_ListStyleSpecial dd {
1.803     bisitz   6104: 	margin: 0;
1.693     droeschl 6105: 	padding: 5px 5px 5px 10px;
                   6106: 	clear: both;
                   6107: }
                   6108: 
1.721     harmsja  6109: .LC_ListStyleClean li,
                   6110: .LC_ListStyleClean dd {
1.803     bisitz   6111: 	padding-top: 0;
                   6112: 	padding-bottom: 0;
1.693     droeschl 6113: }
                   6114: 
1.721     harmsja  6115: .LC_ListStyleSimple dd,
1.795     www      6116: .LC_ListStyleSimple li {
1.698     harmsja  6117: 	border-bottom: solid 1px $lg_border_color;
1.693     droeschl 6118: }
                   6119: 
1.721     harmsja  6120: .LC_ListStyleSpecial li,
                   6121: .LC_ListStyleSpecial dd {
1.693     droeschl 6122: 	list-style-type: none;
                   6123: 	background-color: RGB(220, 220, 220);
                   6124: 	margin-bottom: 4px;
                   6125: }
                   6126: 
1.721     harmsja  6127: table.LC_SimpleTable {
1.698     harmsja  6128: 	margin:5px;
                   6129: 	border:solid 1px $lg_border_color;
1.795     www      6130: }
1.693     droeschl 6131: 
1.721     harmsja  6132: table.LC_SimpleTable tr {
1.803     bisitz   6133: 	padding: 0;
1.698     harmsja  6134: 	border:solid 1px $lg_border_color;
1.693     droeschl 6135: }
1.795     www      6136: 
                   6137: table.LC_SimpleTable thead {
1.698     harmsja  6138: 	 background:rgb(220,220,220);
1.693     droeschl 6139: }
                   6140: 
1.721     harmsja  6141: div.LC_columnSection {
1.693     droeschl 6142: 	display: block;
                   6143: 	clear: both;
                   6144: 	overflow: hidden;
1.803     bisitz   6145: 	margin: 0;
1.693     droeschl 6146: }
                   6147: 
1.721     harmsja  6148: div.LC_columnSection>* {
1.693     droeschl 6149: 	float: left;
1.803     bisitz   6150: 	margin: 10px 20px 10px 0;
1.747     neumanie 6151: 	overflow:hidden;
1.693     droeschl 6152: }
1.721     harmsja  6153: 
1.694     tempelho 6154: .LC_loginpage_container {
                   6155: 	text-align:left;
                   6156: 	margin : 0 auto;
1.785     tempelho 6157: 	width:90%;
1.694     tempelho 6158: 	padding: 10px;
                   6159: 	height: auto;
1.712     muellerd 6160: 	background-color:#FFFFFF;
1.694     tempelho 6161: 	border:1px solid #CCCCCC;
                   6162: }
                   6163: 
                   6164: 
                   6165: .LC_loginpage_loginContainer {
                   6166: 	float:left;
1.712     muellerd 6167: 	width: 182px;
1.785     tempelho 6168: 	padding: 2px;
1.712     muellerd 6169: 	border:1px solid #CCCCCC;
                   6170: 	background-color:$loginbg;
1.694     tempelho 6171: }
                   6172: 
1.795     www      6173: .LC_loginpage_loginContainer h2 {
1.803     bisitz   6174: 	margin-top: 0;
1.712     muellerd 6175: 	display:block;
                   6176: 	background:$bgcol;
                   6177: 	color:$textcol;
                   6178: 	padding-left:5px;
                   6179: }
1.785     tempelho 6180: 
1.694     tempelho 6181: .LC_loginpage_loginInfo {
                   6182: 	float:left;
1.785     tempelho 6183: 	width:182px;
1.694     tempelho 6184: 	border:1px solid #CCCCCC;
1.785     tempelho 6185: 	padding:2px;
1.712     muellerd 6186: }
                   6187: 
1.694     tempelho 6188: .LC_loginpage_space {
1.754     droeschl 6189: 	clear: both;
                   6190: 	margin-bottom: 20px;
1.694     tempelho 6191: 	border-bottom: 1px solid #CCCCCC;
                   6192: }
                   6193: 
1.785     tempelho 6194: .LC_loginpage_floatLeft {
                   6195: 	float: left;
                   6196: 	width: 200px;
                   6197: 	margin: 0;
                   6198: }
                   6199: 
1.795     www      6200: table em {
1.754     droeschl 6201: 	font-weight: bold;
                   6202: 	font-style: normal;
1.748     schulted 6203: }
1.795     www      6204: 
1.779     bisitz   6205: table.LC_tableBrowseRes,
1.795     www      6206: table.LC_tableOfContent {
1.769     schulted 6207:         border:none;
1.858     bisitz   6208: 	border-spacing: 1px;
1.754     droeschl 6209: 	padding: 3px;
                   6210: 	background-color: #FFFFFF;
                   6211: 	font-size: 90%;
1.753     droeschl 6212: }
1.789     droeschl 6213: 
                   6214: table.LC_tableOfContent{
                   6215:     border-collapse: collapse;
                   6216: }
                   6217: 
1.771     droeschl 6218: table.LC_tableBrowseRes a,
1.768     schulted 6219: table.LC_tableOfContent a {
1.771     droeschl 6220:         background-color: transparent;
1.753     droeschl 6221: 	text-decoration: none;
                   6222: }
                   6223: 
1.771     droeschl 6224: table.LC_tableBrowseRes tr.LC_trOdd,
1.768     schulted 6225: table.LC_tableOfContent tr.LC_trOdd{
1.754     droeschl 6226: 	background-color: #EEEEEE;
1.753     droeschl 6227: }
                   6228: 
1.795     www      6229: table.LC_tableOfContent img {
1.753     droeschl 6230: 	border: none;
                   6231: 	height: 1.3em;
                   6232: 	vertical-align: text-bottom;
                   6233: 	margin-right: 0.3em;
                   6234: }
1.757     schulted 6235: 
1.795     www      6236: a#LC_content_toolbar_firsthomework {
1.774     ehlerst  6237: 	background-image:url(/res/adm/pages/open-first-problem.gif);
                   6238: }
                   6239: 
1.795     www      6240: a#LC_content_toolbar_launchnav {
1.774     ehlerst  6241: 	background-image:url(/res/adm/pages/start-navigation.gif);
                   6242: }
                   6243: 
1.795     www      6244: a#LC_content_toolbar_closenav {
1.774     ehlerst  6245: 	background-image:url(/res/adm/pages/close-navigation.gif);
                   6246: }
                   6247: 
1.795     www      6248: a#LC_content_toolbar_everything {
1.774     ehlerst  6249: 	background-image:url(/res/adm/pages/show-all.gif);
                   6250: }
                   6251: 
1.795     www      6252: a#LC_content_toolbar_uncompleted {
1.774     ehlerst  6253: 	background-image:url(/res/adm/pages/show-incomplete-problems.gif);
                   6254: }
                   6255: 
1.795     www      6256: #LC_content_toolbar_clearbubbles {
1.774     ehlerst  6257: 	background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
                   6258: }
                   6259: 
1.795     www      6260: a#LC_content_toolbar_changefolder {
1.757     schulted 6261: 	background : url(/res/adm/pages/close-all-folders.gif) top center ;
                   6262: }
                   6263: 
1.795     www      6264: a#LC_content_toolbar_changefolder_toggled {
1.757     schulted 6265: 	background-image:url(/res/adm/pages/open-all-folders.gif);
                   6266: }
                   6267: 
1.795     www      6268: ul#LC_toolbar li a:hover {
1.757     schulted 6269: 	background-position: bottom center;
                   6270: }
                   6271: 
1.795     www      6272: ul#LC_toolbar {
1.803     bisitz   6273: 	padding: 0;
1.757     schulted 6274: 	margin: 2px;
                   6275: 	list-style:none;
                   6276: 	position:relative;
                   6277: 	background-color:white;
                   6278: }
                   6279: 
1.795     www      6280: ul#LC_toolbar li {
1.757     schulted 6281: 	border:1px solid white;
1.803     bisitz   6282: 	padding: 0;
1.757     schulted 6283: 	margin: 0;
1.795     www      6284:         float: left;
1.767     droeschl 6285: 	display:inline;
1.757     schulted 6286: 	vertical-align:middle;
1.795     www      6287: } 
1.757     schulted 6288: 
1.783     amueller 6289: 
1.795     www      6290: a.LC_toolbarItem {
1.767     droeschl 6291: 	display:block;
1.803     bisitz   6292: 	padding: 0;
                   6293: 	margin: 0;
1.757     schulted 6294: 	height: 32px;
                   6295: 	width: 32px;
1.779     bisitz   6296: 	color:white;
1.803     bisitz   6297: 	border: none;
1.757     schulted 6298: 	background-repeat:no-repeat;
                   6299: 	background-color:transparent;
                   6300: }
                   6301: 
1.843     bisitz   6302: ul.LC_funclist li {
1.782     bisitz   6303:   float: left;
                   6304:   white-space: nowrap;
                   6305:   height: 35px; /* at least as high as heighest list item */
1.803     bisitz   6306:   margin: 0 15px 15px 10px;
1.782     bisitz   6307: }
                   6308: 
1.757     schulted 6309: 
1.343     albertel 6310: END
                   6311: }
                   6312: 
1.306     albertel 6313: =pod
                   6314: 
                   6315: =item * &headtag()
                   6316: 
                   6317: Returns a uniform footer for LON-CAPA web pages.
                   6318: 
1.307     albertel 6319: Inputs: $title - optional title for the head
                   6320:         $head_extra - optional extra HTML to put inside the <head>
1.315     albertel 6321:         $args - optional arguments
1.319     albertel 6322:             force_register - if is true call registerurl so the remote is 
                   6323:                              informed
1.415     albertel 6324:             redirect       -> array ref of
                   6325:                                    1- seconds before redirect occurs
                   6326:                                    2- url to redirect to
                   6327:                                    3- whether the side effect should occur
1.315     albertel 6328:                            (side effect of setting 
                   6329:                                $env{'internal.head.redirect'} to the url 
                   6330:                                redirected too)
1.352     albertel 6331:             domain         -> force to color decorate a page for a specific
                   6332:                                domain
                   6333:             function       -> force usage of a specific rolish color scheme
                   6334:             bgcolor        -> override the default page bgcolor
1.460     albertel 6335:             no_auto_mt_title
                   6336:                            -> prevent &mt()ing the title arg
1.464     albertel 6337: 
1.306     albertel 6338: =cut
                   6339: 
                   6340: sub headtag {
1.313     albertel 6341:     my ($title,$head_extra,$args) = @_;
1.306     albertel 6342:     
1.363     albertel 6343:     my $function = $args->{'function'} || &get_users_function();
                   6344:     my $domain   = $args->{'domain'}   || &determinedomain();
                   6345:     my $bgcolor  = $args->{'bgcolor'}  || &designparm($function.'.pgbg',$domain);
1.418     albertel 6346:     my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458     albertel 6347: 		   $Apache::lonnet::perlvar{'lonVersion'},
1.531     albertel 6348: 		   #time(),
1.418     albertel 6349: 		   $env{'environment.color.timestamp'},
1.363     albertel 6350: 		   $function,$domain,$bgcolor);
                   6351: 
1.369     www      6352:     $url = '/adm/css/'.&escape($url).'.css';
1.363     albertel 6353: 
1.308     albertel 6354:     my $result =
                   6355: 	'<head>'.
1.461     albertel 6356: 	&font_settings();
1.319     albertel 6357: 
1.461     albertel 6358:     if (!$args->{'frameset'}) {
                   6359: 	$result .= &Apache::lonhtmlcommon::htmlareaheaders();
                   6360:     }
1.319     albertel 6361:     if ($args->{'force_register'}) {
                   6362: 	$result .= &Apache::lonmenu::registerurl(1);
                   6363:     }
1.436     albertel 6364:     if (!$args->{'no_nav_bar'} 
                   6365: 	&& !$args->{'only_body'}
                   6366: 	&& !$args->{'frameset'}) {
                   6367: 	$result .= &help_menu_js();
                   6368:     }
1.319     albertel 6369: 
1.314     albertel 6370:     if (ref($args->{'redirect'})) {
1.414     albertel 6371: 	my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315     albertel 6372: 	$url = &Apache::lonenc::check_encrypt($url);
1.414     albertel 6373: 	if (!$inhibit_continue) {
                   6374: 	    $env{'internal.head.redirect'} = $url;
                   6375: 	}
1.313     albertel 6376: 	$result.=<<ADDMETA
                   6377: <meta http-equiv="pragma" content="no-cache" />
1.344     albertel 6378: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313     albertel 6379: ADDMETA
                   6380:     }
1.306     albertel 6381:     if (!defined($title)) {
                   6382: 	$title = 'The LearningOnline Network with CAPA';
                   6383:     }
1.460     albertel 6384:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
                   6385:     $result .= '<title> LON-CAPA '.$title.'</title>'
1.414     albertel 6386: 	.'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
                   6387: 	.$head_extra;
1.306     albertel 6388:     return $result;
                   6389: }
                   6390: 
                   6391: =pod
                   6392: 
1.340     albertel 6393: =item * &font_settings()
                   6394: 
                   6395: Returns neccessary <meta> to set the proper encoding
                   6396: 
                   6397: Inputs: none
                   6398: 
                   6399: =cut
                   6400: 
                   6401: sub font_settings {
                   6402:     my $headerstring='';
1.647     www      6403:     if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340     albertel 6404: 	$headerstring.=
                   6405: 	    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
                   6406:     }
                   6407:     return $headerstring;
                   6408: }
                   6409: 
1.341     albertel 6410: =pod
                   6411: 
                   6412: =item * &xml_begin()
                   6413: 
                   6414: Returns the needed doctype and <html>
                   6415: 
                   6416: Inputs: none
                   6417: 
                   6418: =cut
                   6419: 
                   6420: sub xml_begin {
                   6421:     my $output='';
                   6422: 
1.592     albertel 6423:     if ($env{'internal.start_page'}==1) {
                   6424: 	&Apache::lonhtmlcommon::init_htmlareafields();
                   6425:     }
1.342     albertel 6426: 
1.341     albertel 6427:     if ($env{'browser.mathml'}) {
                   6428: 	$output='<?xml version="1.0"?>'
                   6429:             #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
                   6430: #            .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
                   6431:             
                   6432: #	    .'<!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">] >'
                   6433: 	    .'<!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">'
                   6434:             .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" ' 
                   6435: 	    .'xmlns="http://www.w3.org/1999/xhtml">';
                   6436:     } else {
1.849     bisitz   6437: 	$output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
                   6438:            .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341     albertel 6439:     }
                   6440:     return $output;
                   6441: }
1.340     albertel 6442: 
                   6443: =pod
                   6444: 
1.306     albertel 6445: =item * &endheadtag()
                   6446: 
                   6447: Returns a uniform </head> for LON-CAPA web pages.
                   6448: 
                   6449: Inputs: none
                   6450: 
                   6451: =cut
                   6452: 
                   6453: sub endheadtag {
                   6454:     return '</head>';
                   6455: }
                   6456: 
                   6457: =pod
                   6458: 
                   6459: =item * &head()
                   6460: 
                   6461: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
                   6462: 
1.648     raeburn  6463: Inputs:
                   6464: 
                   6465: =over 4
                   6466: 
                   6467: $title - optional title for the page
                   6468: 
                   6469: $head_extra - optional extra HTML to put inside the <head>
                   6470: 
                   6471: =back
1.405     albertel 6472: 
1.306     albertel 6473: =cut
                   6474: 
                   6475: sub head {
1.325     albertel 6476:     my ($title,$head_extra,$args) = @_;
                   6477:     return &headtag($title,$head_extra,$args).&endheadtag();
1.306     albertel 6478: }
                   6479: 
                   6480: =pod
                   6481: 
                   6482: =item * &start_page()
                   6483: 
                   6484: Returns a complete <html> .. <body> section for LON-CAPA web pages.
                   6485: 
1.648     raeburn  6486: Inputs:
                   6487: 
                   6488: =over 4
                   6489: 
                   6490: $title - optional title for the page
                   6491: 
                   6492: $head_extra - optional extra HTML to incude inside the <head>
                   6493: 
                   6494: $args - additional optional args supported are:
                   6495: 
                   6496: =over 8
                   6497: 
                   6498:              only_body      -> is true will set &bodytag() onlybodytag
1.317     albertel 6499:                                     arg on
1.814     bisitz   6500:              no_nav_bar     -> is true will set &bodytag() no_nav_bar arg on
1.648     raeburn  6501:              add_entries    -> additional attributes to add to the  <body>
                   6502:              domain         -> force to color decorate a page for a 
1.317     albertel 6503:                                     specific domain
1.648     raeburn  6504:              function       -> force usage of a specific rolish color
1.317     albertel 6505:                                     scheme
1.648     raeburn  6506:              redirect       -> see &headtag()
                   6507:              bgcolor        -> override the default page bg color
                   6508:              js_ready       -> return a string ready for being used in 
1.317     albertel 6509:                                     a javascript writeln
1.648     raeburn  6510:              html_encode    -> return a string ready for being used in 
1.320     albertel 6511:                                     a html attribute
1.648     raeburn  6512:              force_register -> if is true will turn on the &bodytag()
1.317     albertel 6513:                                     $forcereg arg
1.648     raeburn  6514:              frameset       -> if true will start with a <frameset>
1.330     albertel 6515:                                     rather than <body>
1.648     raeburn  6516:              skip_phases    -> hash ref of 
1.338     albertel 6517:                                     head -> skip the <html><head> generation
                   6518:                                     body -> skip all <body> generation
1.648     raeburn  6519:              no_inline_link -> if true and in remote mode, don't show the 
1.361     albertel 6520:                                     'Switch To Inline Menu' link
1.648     raeburn  6521:              no_auto_mt_title -> prevent &mt()ing the title arg
                   6522:              inherit_jsmath -> when creating popup window in a page,
                   6523:                                     should it have jsmath forced on by the
                   6524:                                     current page
1.867     kalberla 6525:              bread_crumbs ->             Array containing breadcrumbs
                   6526:              bread_crumbs_components ->  if exists show it as headline else show only the breadcrumbs
1.361     albertel 6527: 
1.648     raeburn  6528: =back
1.460     albertel 6529: 
1.648     raeburn  6530: =back
1.562     albertel 6531: 
1.306     albertel 6532: =cut
                   6533: 
                   6534: sub start_page {
1.309     albertel 6535:     my ($title,$head_extra,$args) = @_;
1.318     albertel 6536:     #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313     albertel 6537:     my %head_args;
1.352     albertel 6538:     foreach my $arg ('redirect','force_register','domain','function',
1.460     albertel 6539: 		     'bgcolor','frameset','no_nav_bar','only_body',
                   6540: 		     'no_auto_mt_title') {
1.319     albertel 6541: 	if (defined($args->{$arg})) {
1.324     raeburn  6542: 	    $head_args{$arg} = $args->{$arg};
1.319     albertel 6543: 	}
1.313     albertel 6544:     }
1.319     albertel 6545: 
1.315     albertel 6546:     $env{'internal.start_page'}++;
1.338     albertel 6547:     my $result;
                   6548:     if (! exists($args->{'skip_phases'}{'head'}) ) {
                   6549: 	$result.=
1.341     albertel 6550: 	    &xml_begin().
1.338     albertel 6551: 	    &headtag($title,$head_extra,\%head_args).&endheadtag();
                   6552:     }
                   6553:     
                   6554:     if (! exists($args->{'skip_phases'}{'body'}) ) {
                   6555: 	if ($args->{'frameset'}) {
                   6556: 	    my $attr_string = &make_attr_string($args->{'force_register'},
                   6557: 						$args->{'add_entries'});
                   6558: 	    $result .= "\n<frameset $attr_string>\n";
1.831     bisitz   6559:         } else {
                   6560:             $result .=
                   6561:                 &bodytag($title, 
                   6562:                          $args->{'function'},       $args->{'add_entries'},
                   6563:                          $args->{'only_body'},      $args->{'domain'},
                   6564:                          $args->{'force_register'}, $args->{'no_nav_bar'},
                   6565:                          $args->{'bgcolor'},        $args->{'no_inline_link'},
                   6566:                          $args);
                   6567:         }
1.330     albertel 6568:     }
1.338     albertel 6569: 
1.315     albertel 6570:     if ($args->{'js_ready'}) {
1.713     kaisler  6571: 		$result = &js_ready($result);
1.315     albertel 6572:     }
1.320     albertel 6573:     if ($args->{'html_encode'}) {
1.713     kaisler  6574: 		$result = &html_encode($result);
                   6575:     }
                   6576: 
1.813     bisitz   6577:     # Preparation for new and consistent functionlist at top of screen
                   6578:     # if ($args->{'functionlist'}) {
                   6579:     #            $result .= &build_functionlist();
                   6580:     #}
                   6581: 
                   6582:     # Don't add anything more if only_body wanted
                   6583:     return $result if $args->{'only_body'};
                   6584: 
                   6585:     #Breadcrumbs
1.758     kaisler  6586:     if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
                   6587: 		&Apache::lonhtmlcommon::clear_breadcrumbs();
                   6588: 		#if any br links exists, add them to the breadcrumbs
                   6589: 		if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {         
                   6590: 			foreach my $crumb (@{$args->{'bread_crumbs'}}){
                   6591: 				&Apache::lonhtmlcommon::add_breadcrumb($crumb);
                   6592: 			}
                   6593: 		}
                   6594: 
                   6595: 		#if bread_crumbs_component exists show it as headline else show only the breadcrumbs
                   6596: 		if(exists($args->{'bread_crumbs_component'})){
                   6597: 			$result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
                   6598: 		}else{
                   6599: 			$result .= &Apache::lonhtmlcommon::breadcrumbs();
                   6600: 		}
1.320     albertel 6601:     }
1.315     albertel 6602:     return $result;
1.306     albertel 6603: }
                   6604: 
1.330     albertel 6605: 
1.306     albertel 6606: =pod
                   6607: 
                   6608: =item * &head()
                   6609: 
                   6610: Returns a complete </body></html> section for LON-CAPA web pages.
                   6611: 
1.315     albertel 6612: Inputs:         $args - additional optional args supported are:
                   6613:                  js_ready     -> return a string ready for being used in 
                   6614:                                  a javascript writeln
1.320     albertel 6615:                  html_encode  -> return a string ready for being used in 
                   6616:                                  a html attribute
1.330     albertel 6617:                  frameset     -> if true will start with a <frameset>
                   6618:                                  rather than <body>
1.493     albertel 6619:                  dicsussion   -> if true will get discussion from
                   6620:                                   lonxml::xmlend
                   6621:                                  (you can pass the target and parser arguments
                   6622:                                   through optional 'target' and 'parser' args
                   6623:                                   to this routine)
1.306     albertel 6624: 
                   6625: =cut
                   6626: 
                   6627: sub end_page {
1.315     albertel 6628:     my ($args) = @_;
                   6629:     $env{'internal.end_page'}++;
1.330     albertel 6630:     my $result;
1.335     albertel 6631:     if ($args->{'discussion'}) {
                   6632: 	my ($target,$parser);
                   6633: 	if (ref($args->{'discussion'})) {
                   6634: 	    ($target,$parser) =($args->{'discussion'}{'target'},
                   6635: 				$args->{'discussion'}{'parser'});
                   6636: 	}
                   6637: 	$result .= &Apache::lonxml::xmlend($target,$parser);
                   6638:     }
                   6639: 
1.330     albertel 6640:     if ($args->{'frameset'}) {
                   6641: 	$result .= '</frameset>';
                   6642:     } else {
1.635     raeburn  6643: 	$result .= &endbodytag($args);
1.330     albertel 6644:     }
                   6645:     $result .= "\n</html>";
                   6646: 
1.315     albertel 6647:     if ($args->{'js_ready'}) {
1.317     albertel 6648: 	$result = &js_ready($result);
1.315     albertel 6649:     }
1.335     albertel 6650: 
1.320     albertel 6651:     if ($args->{'html_encode'}) {
                   6652: 	$result = &html_encode($result);
                   6653:     }
1.335     albertel 6654: 
1.315     albertel 6655:     return $result;
                   6656: }
                   6657: 
1.320     albertel 6658: sub html_encode {
                   6659:     my ($result) = @_;
                   6660: 
1.322     albertel 6661:     $result = &HTML::Entities::encode($result,'<>&"');
1.320     albertel 6662:     
                   6663:     return $result;
                   6664: }
1.317     albertel 6665: sub js_ready {
                   6666:     my ($result) = @_;
                   6667: 
1.323     albertel 6668:     $result =~ s/[\n\r]/ /xmsg;
                   6669:     $result =~ s/\\/\\\\/xmsg;
                   6670:     $result =~ s/'/\\'/xmsg;
1.372     albertel 6671:     $result =~ s{</}{<\\/}xmsg;
1.317     albertel 6672:     
                   6673:     return $result;
                   6674: }
                   6675: 
1.315     albertel 6676: sub validate_page {
                   6677:     if (  exists($env{'internal.start_page'})
1.316     albertel 6678: 	  &&     $env{'internal.start_page'} > 1) {
                   6679: 	&Apache::lonnet::logthis('start_page called multiple times '.
1.318     albertel 6680: 				 $env{'internal.start_page'}.' '.
1.316     albertel 6681: 				 $ENV{'request.filename'});
1.315     albertel 6682:     }
                   6683:     if (  exists($env{'internal.end_page'})
1.316     albertel 6684: 	  &&     $env{'internal.end_page'} > 1) {
                   6685: 	&Apache::lonnet::logthis('end_page called multiple times '.
1.318     albertel 6686: 				 $env{'internal.end_page'}.' '.
1.316     albertel 6687: 				 $env{'request.filename'});
1.315     albertel 6688:     }
                   6689:     if (     exists($env{'internal.start_page'})
                   6690: 	&& ! exists($env{'internal.end_page'})) {
1.316     albertel 6691: 	&Apache::lonnet::logthis('start_page called without end_page '.
                   6692: 				 $env{'request.filename'});
1.315     albertel 6693:     }
                   6694:     if (   ! exists($env{'internal.start_page'})
                   6695: 	&&   exists($env{'internal.end_page'})) {
1.316     albertel 6696: 	&Apache::lonnet::logthis('end_page called without start_page'.
                   6697: 				 $env{'request.filename'});
1.315     albertel 6698:     }
1.306     albertel 6699: }
1.315     albertel 6700: 
1.318     albertel 6701: sub simple_error_page {
                   6702:     my ($r,$title,$msg) = @_;
                   6703:     my $page =
                   6704: 	&Apache::loncommon::start_page($title).
                   6705: 	&mt($msg).
                   6706: 	&Apache::loncommon::end_page();
                   6707:     if (ref($r)) {
                   6708: 	$r->print($page);
1.327     albertel 6709: 	return;
1.318     albertel 6710:     }
                   6711:     return $page;
                   6712: }
1.347     albertel 6713: 
                   6714: {
1.610     albertel 6715:     my @row_count;
1.347     albertel 6716:     sub start_data_table {
1.422     albertel 6717: 	my ($add_class) = @_;
                   6718: 	my $css_class = (join(' ','LC_data_table',$add_class));
1.610     albertel 6719: 	unshift(@row_count,0);
1.422     albertel 6720: 	return '<table class="'.$css_class.'">'."\n";
1.347     albertel 6721:     }
                   6722: 
                   6723:     sub end_data_table {
1.610     albertel 6724: 	shift(@row_count);
1.389     albertel 6725: 	return '</table>'."\n";;
1.347     albertel 6726:     }
                   6727: 
                   6728:     sub start_data_table_row {
1.422     albertel 6729: 	my ($add_class) = @_;
1.610     albertel 6730: 	$row_count[0]++;
                   6731: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428     albertel 6732: 	$css_class = (join(' ',$css_class,$add_class));
1.422     albertel 6733: 	return  '<tr class="'.$css_class.'">'."\n";;
1.347     albertel 6734:     }
1.471     banghart 6735:     
                   6736:     sub continue_data_table_row {
                   6737: 	my ($add_class) = @_;
1.610     albertel 6738: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471     banghart 6739: 	$css_class = (join(' ',$css_class,$add_class));
                   6740: 	return  '<tr class="'.$css_class.'">'."\n";;
                   6741:     }
1.347     albertel 6742: 
                   6743:     sub end_data_table_row {
1.389     albertel 6744: 	return '</tr>'."\n";;
1.347     albertel 6745:     }
1.367     www      6746: 
1.421     albertel 6747:     sub start_data_table_empty_row {
1.707     bisitz   6748: #	$row_count[0]++;
1.421     albertel 6749: 	return  '<tr class="LC_empty_row" >'."\n";;
                   6750:     }
                   6751: 
                   6752:     sub end_data_table_empty_row {
                   6753: 	return '</tr>'."\n";;
                   6754:     }
                   6755: 
1.367     www      6756:     sub start_data_table_header_row {
1.389     albertel 6757: 	return  '<tr class="LC_header_row">'."\n";;
1.367     www      6758:     }
                   6759: 
                   6760:     sub end_data_table_header_row {
1.389     albertel 6761: 	return '</tr>'."\n";;
1.367     www      6762:     }
1.347     albertel 6763: }
                   6764: 
1.548     albertel 6765: =pod
                   6766: 
                   6767: =item * &inhibit_menu_check($arg)
                   6768: 
                   6769: Checks for a inhibitmenu state and generates output to preserve it
                   6770: 
                   6771: Inputs:         $arg - can be any of
                   6772:                      - undef - in which case the return value is a string 
                   6773:                                to add  into arguments list of a uri
                   6774:                      - 'input' - in which case the return value is a HTML
                   6775:                                  <form> <input> field of type hidden to
                   6776:                                  preserve the value
                   6777:                      - a url - in which case the return value is the url with
                   6778:                                the neccesary cgi args added to preserve the
                   6779:                                inhibitmenu state
                   6780:                      - a ref to a url - no return value, but the string is
                   6781:                                         updated to include the neccessary cgi
                   6782:                                         args to preserve the inhibitmenu state
                   6783: 
                   6784: =cut
                   6785: 
                   6786: sub inhibit_menu_check {
                   6787:     my ($arg) = @_;
                   6788:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   6789:     if ($arg eq 'input') {
                   6790: 	if ($env{'form.inhibitmenu'}) {
                   6791: 	    return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
                   6792: 	} else {
                   6793: 	    return
                   6794: 	}
                   6795:     }
                   6796:     if ($env{'form.inhibitmenu'}) {
                   6797: 	if (ref($arg)) {
                   6798: 	    $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   6799: 	} elsif ($arg eq '') {
                   6800: 	    $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
                   6801: 	} else {
                   6802: 	    $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   6803: 	}
                   6804:     }
                   6805:     if (!ref($arg)) {
                   6806: 	return $arg;
                   6807:     }
                   6808: }
                   6809: 
1.251     albertel 6810: ###############################################
1.182     matthew  6811: 
                   6812: =pod
                   6813: 
1.549     albertel 6814: =back
                   6815: 
                   6816: =head1 User Information Routines
                   6817: 
                   6818: =over 4
                   6819: 
1.405     albertel 6820: =item * &get_users_function()
1.182     matthew  6821: 
                   6822: Used by &bodytag to determine the current users primary role.
                   6823: Returns either 'student','coordinator','admin', or 'author'.
                   6824: 
                   6825: =cut
                   6826: 
                   6827: ###############################################
                   6828: sub get_users_function {
1.815     tempelho 6829:     my $function = 'norole';
1.818     tempelho 6830:     if ($env{'request.role'}=~/^(st)/) {
                   6831:         $function='student';
                   6832:     }
1.258     albertel 6833:     if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182     matthew  6834:         $function='coordinator';
                   6835:     }
1.258     albertel 6836:     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182     matthew  6837:         $function='admin';
                   6838:     }
1.826     bisitz   6839:     if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.182     matthew  6840:         ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
                   6841:         $function='author';
                   6842:     }
                   6843:     return $function;
1.54      www      6844: }
1.99      www      6845: 
                   6846: ###############################################
                   6847: 
1.233     raeburn  6848: =pod
                   6849: 
1.821     raeburn  6850: =item * &show_course()
                   6851: 
                   6852: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
                   6853: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
                   6854: 
                   6855: Inputs:
                   6856: None
                   6857: 
                   6858: Outputs:
                   6859: Scalar: 1 if 'Course' to be used, 0 otherwise.
                   6860: 
                   6861: =cut
                   6862: 
                   6863: ###############################################
                   6864: sub show_course {
                   6865:     my $course = !$env{'user.adv'};
                   6866:     if (!$env{'user.adv'}) {
                   6867:         foreach my $env (keys(%env)) {
                   6868:             next if ($env !~ m/^user\.priv\./);
                   6869:             if ($env !~ m/^user\.priv\.(?:st|cm)/) {
                   6870:                 $course = 0;
                   6871:                 last;
                   6872:             }
                   6873:         }
                   6874:     }
                   6875:     return $course;
                   6876: }
                   6877: 
                   6878: ###############################################
                   6879: 
                   6880: =pod
                   6881: 
1.542     raeburn  6882: =item * &check_user_status()
1.274     raeburn  6883: 
                   6884: Determines current status of supplied role for a
                   6885: specific user. Roles can be active, previous or future.
                   6886: 
                   6887: Inputs: 
                   6888: user's domain, user's username, course's domain,
1.375     raeburn  6889: course's number, optional section ID.
1.274     raeburn  6890: 
                   6891: Outputs:
                   6892: role status: active, previous or future. 
                   6893: 
                   6894: =cut
                   6895: 
                   6896: sub check_user_status {
1.412     raeburn  6897:     my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274     raeburn  6898:     my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
                   6899:     my @uroles = keys %userinfo;
                   6900:     my $srchstr;
                   6901:     my $active_chk = 'none';
1.412     raeburn  6902:     my $now = time;
1.274     raeburn  6903:     if (@uroles > 0) {
1.412     raeburn  6904:         if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274     raeburn  6905:             $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
                   6906:         } else {
1.412     raeburn  6907:             $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
                   6908:         }
                   6909:         if (grep/^\Q$srchstr\E$/,@uroles) {
1.274     raeburn  6910:             my $role_end = 0;
                   6911:             my $role_start = 0;
                   6912:             $active_chk = 'active';
1.412     raeburn  6913:             if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
                   6914:                 $role_end = $1;
                   6915:                 if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
                   6916:                     $role_start = $1;
1.274     raeburn  6917:                 }
                   6918:             }
                   6919:             if ($role_start > 0) {
1.412     raeburn  6920:                 if ($now < $role_start) {
1.274     raeburn  6921:                     $active_chk = 'future';
                   6922:                 }
                   6923:             }
                   6924:             if ($role_end > 0) {
1.412     raeburn  6925:                 if ($now > $role_end) {
1.274     raeburn  6926:                     $active_chk = 'previous';
                   6927:                 }
                   6928:             }
                   6929:         }
                   6930:     }
                   6931:     return $active_chk;
                   6932: }
                   6933: 
                   6934: ###############################################
                   6935: 
                   6936: =pod
                   6937: 
1.405     albertel 6938: =item * &get_sections()
1.233     raeburn  6939: 
                   6940: Determines all the sections for a course including
                   6941: sections with students and sections containing other roles.
1.419     raeburn  6942: Incoming parameters: 
                   6943: 
                   6944: 1. domain
                   6945: 2. course number 
                   6946: 3. reference to array containing roles for which sections should 
                   6947: be gathered (optional).
                   6948: 4. reference to array containing status types for which sections 
                   6949: should be gathered (optional).
                   6950: 
                   6951: If the third argument is undefined, sections are gathered for any role. 
                   6952: If the fourth argument is undefined, sections are gathered for any status.
                   6953: Permissible values are 'active' or 'future' or 'previous'.
1.233     raeburn  6954:  
1.374     raeburn  6955: Returns section hash (keys are section IDs, values are
                   6956: number of users in each section), subject to the
1.419     raeburn  6957: optional roles filter, optional status filter 
1.233     raeburn  6958: 
                   6959: =cut
                   6960: 
                   6961: ###############################################
                   6962: sub get_sections {
1.419     raeburn  6963:     my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366     albertel 6964:     if (!defined($cdom) || !defined($cnum)) {
                   6965:         my $cid =  $env{'request.course.id'};
                   6966: 
                   6967: 	return if (!defined($cid));
                   6968: 
                   6969:         $cdom = $env{'course.'.$cid.'.domain'};
                   6970:         $cnum = $env{'course.'.$cid.'.num'};
                   6971:     }
                   6972: 
                   6973:     my %sectioncount;
1.419     raeburn  6974:     my $now = time;
1.240     albertel 6975: 
1.366     albertel 6976:     if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276     albertel 6977: 	my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240     albertel 6978: 	my $sec_index = &Apache::loncoursedata::CL_SECTION();
                   6979: 	my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419     raeburn  6980:         my $start_index = &Apache::loncoursedata::CL_START();
                   6981:         my $end_index = &Apache::loncoursedata::CL_END();
                   6982:         my $status;
1.366     albertel 6983: 	while (my ($student,$data) = each(%$classlist)) {
1.419     raeburn  6984: 	    my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
                   6985: 				                     $data->[$status_index],
                   6986:                                                      $data->[$start_index],
                   6987:                                                      $data->[$end_index]);
                   6988:             if ($stu_status eq 'Active') {
                   6989:                 $status = 'active';
                   6990:             } elsif ($end < $now) {
                   6991:                 $status = 'previous';
                   6992:             } elsif ($start > $now) {
                   6993:                 $status = 'future';
                   6994:             } 
                   6995: 	    if ($section ne '-1' && $section !~ /^\s*$/) {
                   6996:                 if ((!defined($possible_status)) || (($status ne '') && 
                   6997:                     (grep/^\Q$status\E$/,@{$possible_status}))) { 
                   6998: 		    $sectioncount{$section}++;
                   6999:                 }
1.240     albertel 7000: 	    }
                   7001: 	}
                   7002:     }
                   7003:     my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7004:     foreach my $user (sort(keys(%courseroles))) {
                   7005: 	if ($user !~ /^(\w{2})/) { next; }
                   7006: 	my ($role) = ($user =~ /^(\w{2})/);
                   7007: 	if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419     raeburn  7008: 	my ($section,$status);
1.240     albertel 7009: 	if ($role eq 'cr' &&
                   7010: 	    $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
                   7011: 	    $section=$1;
                   7012: 	}
                   7013: 	if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
                   7014: 	if (!defined($section) || $section eq '-1') { next; }
1.419     raeburn  7015:         my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
                   7016:         if ($end == -1 && $start == -1) {
                   7017:             next; #deleted role
                   7018:         }
                   7019:         if (!defined($possible_status)) { 
                   7020:             $sectioncount{$section}++;
                   7021:         } else {
                   7022:             if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
                   7023:                 $status = 'active';
                   7024:             } elsif ($end < $now) {
                   7025:                 $status = 'future';
                   7026:             } elsif ($start > $now) {
                   7027:                 $status = 'previous';
                   7028:             }
                   7029:             if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
                   7030:                 $sectioncount{$section}++;
                   7031:             }
                   7032:         }
1.233     raeburn  7033:     }
1.366     albertel 7034:     return %sectioncount;
1.233     raeburn  7035: }
                   7036: 
1.274     raeburn  7037: ###############################################
1.294     raeburn  7038: 
                   7039: =pod
1.405     albertel 7040: 
                   7041: =item * &get_course_users()
                   7042: 
1.275     raeburn  7043: Retrieves usernames:domains for users in the specified course
                   7044: with specific role(s), and access status. 
                   7045: 
                   7046: Incoming parameters:
1.277     albertel 7047: 1. course domain
                   7048: 2. course number
                   7049: 3. access status: users must have - either active, 
1.275     raeburn  7050: previous, future, or all.
1.277     albertel 7051: 4. reference to array of permissible roles
1.288     raeburn  7052: 5. reference to array of section restrictions (optional)
                   7053: 6. reference to results object (hash of hashes).
                   7054: 7. reference to optional userdata hash
1.609     raeburn  7055: 8. reference to optional statushash
1.630     raeburn  7056: 9. flag if privileged users (except those set to unhide in
                   7057:    course settings) should be excluded    
1.609     raeburn  7058: Keys of top level results hash are roles.
1.275     raeburn  7059: Keys of inner hashes are username:domain, with 
                   7060: values set to access type.
1.288     raeburn  7061: Optional userdata hash returns an array with arguments in the 
                   7062: same order as loncoursedata::get_classlist() for student data.
                   7063: 
1.609     raeburn  7064: Optional statushash returns
                   7065: 
1.288     raeburn  7066: Entries for end, start, section and status are blank because
                   7067: of the possibility of multiple values for non-student roles.
                   7068: 
1.275     raeburn  7069: =cut
1.405     albertel 7070: 
1.275     raeburn  7071: ###############################################
1.405     albertel 7072: 
1.275     raeburn  7073: sub get_course_users {
1.630     raeburn  7074:     my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288     raeburn  7075:     my %idx = ();
1.419     raeburn  7076:     my %seclists;
1.288     raeburn  7077: 
                   7078:     $idx{udom} = &Apache::loncoursedata::CL_SDOM();
                   7079:     $idx{uname} =  &Apache::loncoursedata::CL_SNAME();
                   7080:     $idx{end} = &Apache::loncoursedata::CL_END();
                   7081:     $idx{start} = &Apache::loncoursedata::CL_START();
                   7082:     $idx{id} = &Apache::loncoursedata::CL_ID();
                   7083:     $idx{section} = &Apache::loncoursedata::CL_SECTION();
                   7084:     $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
                   7085:     $idx{status} = &Apache::loncoursedata::CL_STATUS();
                   7086: 
1.290     albertel 7087:     if (grep(/^st$/,@{$roles})) {
1.276     albertel 7088:         my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278     raeburn  7089:         my $now = time;
1.277     albertel 7090:         foreach my $student (keys(%{$classlist})) {
1.288     raeburn  7091:             my $match = 0;
1.412     raeburn  7092:             my $secmatch = 0;
1.419     raeburn  7093:             my $section = $$classlist{$student}[$idx{section}];
1.609     raeburn  7094:             my $status = $$classlist{$student}[$idx{status}];
1.419     raeburn  7095:             if ($section eq '') {
                   7096:                 $section = 'none';
                   7097:             }
1.291     albertel 7098:             if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 7099:                 if (grep(/^all$/,@{$sections})) {
1.412     raeburn  7100:                     $secmatch = 1;
                   7101:                 } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420     albertel 7102:                     if (grep(/^none$/,@{$sections})) {
1.412     raeburn  7103:                         $secmatch = 1;
                   7104:                     }
                   7105:                 } else {  
1.419     raeburn  7106: 		    if (grep(/^\Q$section\E$/,@{$sections})) {
1.412     raeburn  7107: 		        $secmatch = 1;
                   7108:                     }
1.290     albertel 7109: 		}
1.412     raeburn  7110:                 if (!$secmatch) {
                   7111:                     next;
                   7112:                 }
1.419     raeburn  7113:             }
1.275     raeburn  7114:             if (defined($$types{'active'})) {
1.288     raeburn  7115:                 if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275     raeburn  7116:                     push(@{$$users{st}{$student}},'active');
1.288     raeburn  7117:                     $match = 1;
1.275     raeburn  7118:                 }
                   7119:             }
                   7120:             if (defined($$types{'previous'})) {
1.609     raeburn  7121:                 if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275     raeburn  7122:                     push(@{$$users{st}{$student}},'previous');
1.288     raeburn  7123:                     $match = 1;
1.275     raeburn  7124:                 }
                   7125:             }
                   7126:             if (defined($$types{'future'})) {
1.609     raeburn  7127:                 if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275     raeburn  7128:                     push(@{$$users{st}{$student}},'future');
1.288     raeburn  7129:                     $match = 1;
1.275     raeburn  7130:                 }
                   7131:             }
1.609     raeburn  7132:             if ($match) {
                   7133:                 push(@{$seclists{$student}},$section);
                   7134:                 if (ref($userdata) eq 'HASH') {
                   7135:                     $$userdata{$student} = $$classlist{$student};
                   7136:                 }
                   7137:                 if (ref($statushash) eq 'HASH') {
                   7138:                     $statushash->{$student}{'st'}{$section} = $status;
                   7139:                 }
1.288     raeburn  7140:             }
1.275     raeburn  7141:         }
                   7142:     }
1.412     raeburn  7143:     if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439     raeburn  7144:         my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7145:         my $now = time;
1.609     raeburn  7146:         my %displaystatus = ( previous => 'Expired',
                   7147:                               active   => 'Active',
                   7148:                               future   => 'Future',
                   7149:                             );
1.630     raeburn  7150:         my %nothide;
                   7151:         if ($hidepriv) {
                   7152:             my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
                   7153:             foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
                   7154:                 if ($user !~ /:/) {
                   7155:                     $nothide{join(':',split(/[\@]/,$user))}=1;
                   7156:                 } else {
                   7157:                     $nothide{$user} = 1;
                   7158:                 }
                   7159:             }
                   7160:         }
1.439     raeburn  7161:         foreach my $person (sort(keys(%coursepersonnel))) {
1.288     raeburn  7162:             my $match = 0;
1.412     raeburn  7163:             my $secmatch = 0;
1.439     raeburn  7164:             my $status;
1.412     raeburn  7165:             my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275     raeburn  7166:             $user =~ s/:$//;
1.439     raeburn  7167:             my ($end,$start) = split(/:/,$coursepersonnel{$person});
                   7168:             if ($end == -1 || $start == -1) {
                   7169:                 next;
                   7170:             }
                   7171:             if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
                   7172:                 (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412     raeburn  7173:                 my ($uname,$udom) = split(/:/,$user);
                   7174:                 if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 7175:                     if (grep(/^all$/,@{$sections})) {
1.412     raeburn  7176:                         $secmatch = 1;
                   7177:                     } elsif ($usec eq '') {
1.420     albertel 7178:                         if (grep(/^none$/,@{$sections})) {
1.412     raeburn  7179:                             $secmatch = 1;
                   7180:                         }
                   7181:                     } else {
                   7182:                         if (grep(/^\Q$usec\E$/,@{$sections})) {
                   7183:                             $secmatch = 1;
                   7184:                         }
                   7185:                     }
                   7186:                     if (!$secmatch) {
                   7187:                         next;
                   7188:                     }
1.288     raeburn  7189:                 }
1.419     raeburn  7190:                 if ($usec eq '') {
                   7191:                     $usec = 'none';
                   7192:                 }
1.275     raeburn  7193:                 if ($uname ne '' && $udom ne '') {
1.630     raeburn  7194:                     if ($hidepriv) {
                   7195:                         if ((&Apache::lonnet::privileged($uname,$udom)) &&
                   7196:                             (!$nothide{$uname.':'.$udom})) {
                   7197:                             next;
                   7198:                         }
                   7199:                     }
1.503     raeburn  7200:                     if ($end > 0 && $end < $now) {
1.439     raeburn  7201:                         $status = 'previous';
                   7202:                     } elsif ($start > $now) {
                   7203:                         $status = 'future';
                   7204:                     } else {
                   7205:                         $status = 'active';
                   7206:                     }
1.277     albertel 7207:                     foreach my $type (keys(%{$types})) { 
1.275     raeburn  7208:                         if ($status eq $type) {
1.420     albertel 7209:                             if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419     raeburn  7210:                                 push(@{$$users{$role}{$user}},$type);
                   7211:                             }
1.288     raeburn  7212:                             $match = 1;
                   7213:                         }
                   7214:                     }
1.419     raeburn  7215:                     if (($match) && (ref($userdata) eq 'HASH')) {
                   7216:                         if (!exists($$userdata{$uname.':'.$udom})) {
                   7217: 			    &get_user_info($udom,$uname,\%idx,$userdata);
                   7218:                         }
1.420     albertel 7219:                         if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419     raeburn  7220:                             push(@{$seclists{$uname.':'.$udom}},$usec);
                   7221:                         }
1.609     raeburn  7222:                         if (ref($statushash) eq 'HASH') {
                   7223:                             $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
                   7224:                         }
1.275     raeburn  7225:                     }
                   7226:                 }
                   7227:             }
                   7228:         }
1.290     albertel 7229:         if (grep(/^ow$/,@{$roles})) {
1.279     raeburn  7230:             if ((defined($cdom)) && (defined($cnum))) {
                   7231:                 my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
                   7232:                 if ( defined($csettings{'internal.courseowner'}) ) {
                   7233:                     my $owner = $csettings{'internal.courseowner'};
1.609     raeburn  7234:                     next if ($owner eq '');
                   7235:                     my ($ownername,$ownerdom);
                   7236:                     if ($owner =~ /^([^:]+):([^:]+)$/) {
                   7237:                         $ownername = $1;
                   7238:                         $ownerdom = $2;
                   7239:                     } else {
                   7240:                         $ownername = $owner;
                   7241:                         $ownerdom = $cdom;
                   7242:                         $owner = $ownername.':'.$ownerdom;
1.439     raeburn  7243:                     }
                   7244:                     @{$$users{'ow'}{$owner}} = 'any';
1.290     albertel 7245:                     if (defined($userdata) && 
1.609     raeburn  7246: 			!exists($$userdata{$owner})) {
                   7247: 			&get_user_info($ownerdom,$ownername,\%idx,$userdata);
                   7248:                         if (!grep(/^none$/,@{$seclists{$owner}})) {
                   7249:                             push(@{$seclists{$owner}},'none');
                   7250:                         }
                   7251:                         if (ref($statushash) eq 'HASH') {
                   7252:                             $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419     raeburn  7253:                         }
1.290     albertel 7254: 		    }
1.279     raeburn  7255:                 }
                   7256:             }
                   7257:         }
1.419     raeburn  7258:         foreach my $user (keys(%seclists)) {
                   7259:             @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
                   7260:             $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
                   7261:         }
1.275     raeburn  7262:     }
                   7263:     return;
                   7264: }
                   7265: 
1.288     raeburn  7266: sub get_user_info {
                   7267:     my ($udom,$uname,$idx,$userdata) = @_;
1.289     albertel 7268:     $$userdata{$uname.':'.$udom}[$$idx{fullname}] = 
                   7269: 	&plainname($uname,$udom,'lastname');
1.291     albertel 7270:     $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297     raeburn  7271:     $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609     raeburn  7272:     my %idhash =  &Apache::lonnet::idrget($udom,($uname));
                   7273:     $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname}; 
1.288     raeburn  7274:     return;
                   7275: }
1.275     raeburn  7276: 
1.472     raeburn  7277: ###############################################
                   7278: 
                   7279: =pod
                   7280: 
                   7281: =item * &get_user_quota()
                   7282: 
                   7283: Retrieves quota assigned for storage of portfolio files for a user  
                   7284: 
                   7285: Incoming parameters:
                   7286: 1. user's username
                   7287: 2. user's domain
                   7288: 
                   7289: Returns:
1.536     raeburn  7290: 1. Disk quota (in Mb) assigned to student.
                   7291: 2. (Optional) Type of setting: custom or default
                   7292:    (individually assigned or default for user's 
                   7293:    institutional status).
                   7294: 3. (Optional) - User's institutional status (e.g., faculty, staff
                   7295:    or student - types as defined in localenroll::inst_usertypes 
                   7296:    for user's domain, which determines default quota for user.
                   7297: 4. (Optional) - Default quota which would apply to the user.
1.472     raeburn  7298: 
                   7299: If a value has been stored in the user's environment, 
1.536     raeburn  7300: it will return that, otherwise it returns the maximal default
                   7301: defined for the user's instituional status(es) in the domain.
1.472     raeburn  7302: 
                   7303: =cut
                   7304: 
                   7305: ###############################################
                   7306: 
                   7307: 
                   7308: sub get_user_quota {
                   7309:     my ($uname,$udom) = @_;
1.536     raeburn  7310:     my ($quota,$quotatype,$settingstatus,$defquota);
1.472     raeburn  7311:     if (!defined($udom)) {
                   7312:         $udom = $env{'user.domain'};
                   7313:     }
                   7314:     if (!defined($uname)) {
                   7315:         $uname = $env{'user.name'};
                   7316:     }
                   7317:     if (($udom eq '' || $uname eq '') ||
                   7318:         ($udom eq 'public') && ($uname eq 'public')) {
                   7319:         $quota = 0;
1.536     raeburn  7320:         $quotatype = 'default';
                   7321:         $defquota = 0; 
1.472     raeburn  7322:     } else {
1.536     raeburn  7323:         my $inststatus;
1.472     raeburn  7324:         if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
                   7325:             $quota = $env{'environment.portfolioquota'};
1.536     raeburn  7326:             $inststatus = $env{'environment.inststatus'};
1.472     raeburn  7327:         } else {
1.536     raeburn  7328:             my %userenv = 
                   7329:                 &Apache::lonnet::get('environment',['portfolioquota',
                   7330:                                      'inststatus'],$udom,$uname);
1.472     raeburn  7331:             my ($tmp) = keys(%userenv);
                   7332:             if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   7333:                 $quota = $userenv{'portfolioquota'};
1.536     raeburn  7334:                 $inststatus = $userenv{'inststatus'};
1.472     raeburn  7335:             } else {
                   7336:                 undef(%userenv);
                   7337:             }
                   7338:         }
1.536     raeburn  7339:         ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472     raeburn  7340:         if ($quota eq '') {
1.536     raeburn  7341:             $quota = $defquota;
                   7342:             $quotatype = 'default';
                   7343:         } else {
                   7344:             $quotatype = 'custom';
1.472     raeburn  7345:         }
                   7346:     }
1.536     raeburn  7347:     if (wantarray) {
                   7348:         return ($quota,$quotatype,$settingstatus,$defquota);
                   7349:     } else {
                   7350:         return $quota;
                   7351:     }
1.472     raeburn  7352: }
                   7353: 
                   7354: ###############################################
                   7355: 
                   7356: =pod
                   7357: 
                   7358: =item * &default_quota()
                   7359: 
1.536     raeburn  7360: Retrieves default quota assigned for storage of user portfolio files,
                   7361: given an (optional) user's institutional status.
1.472     raeburn  7362: 
                   7363: Incoming parameters:
                   7364: 1. domain
1.536     raeburn  7365: 2. (Optional) institutional status(es).  This is a : separated list of 
                   7366:    status types (e.g., faculty, staff, student etc.)
                   7367:    which apply to the user for whom the default is being retrieved.
                   7368:    If the institutional status string in undefined, the domain
                   7369:    default quota will be returned. 
1.472     raeburn  7370: 
                   7371: Returns:
                   7372: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536     raeburn  7373: 2. (Optional) institutional type which determined the value of the
                   7374:    default quota.
1.472     raeburn  7375: 
                   7376: If a value has been stored in the domain's configuration db,
                   7377: it will return that, otherwise it returns 20 (for backwards 
                   7378: compatibility with domains which have not set up a configuration
                   7379: db file; the original statically defined portfolio quota was 20 Mb). 
                   7380: 
1.536     raeburn  7381: If the user's status includes multiple types (e.g., staff and student),
                   7382: the largest default quota which applies to the user determines the
                   7383: default quota returned.
                   7384: 
1.780     raeburn  7385: =back
                   7386: 
1.472     raeburn  7387: =cut
                   7388: 
                   7389: ###############################################
                   7390: 
                   7391: 
                   7392: sub default_quota {
1.536     raeburn  7393:     my ($udom,$inststatus) = @_;
                   7394:     my ($defquota,$settingstatus);
                   7395:     my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622     raeburn  7396:                                             ['quotas'],$udom);
                   7397:     if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536     raeburn  7398:         if ($inststatus ne '') {
1.765     raeburn  7399:             my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536     raeburn  7400:             foreach my $item (@statuses) {
1.711     raeburn  7401:                 if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7402:                     if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
                   7403:                         if ($defquota eq '') {
                   7404:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7405:                             $settingstatus = $item;
                   7406:                         } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
                   7407:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7408:                             $settingstatus = $item;
                   7409:                         }
                   7410:                     }
                   7411:                 } else {
                   7412:                     if ($quotahash{'quotas'}{$item} ne '') {
                   7413:                         if ($defquota eq '') {
                   7414:                             $defquota = $quotahash{'quotas'}{$item};
                   7415:                             $settingstatus = $item;
                   7416:                         } elsif ($quotahash{'quotas'}{$item} > $defquota) {
                   7417:                             $defquota = $quotahash{'quotas'}{$item};
                   7418:                             $settingstatus = $item;
                   7419:                         }
1.536     raeburn  7420:                     }
                   7421:                 }
                   7422:             }
                   7423:         }
                   7424:         if ($defquota eq '') {
1.711     raeburn  7425:             if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7426:                 $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
                   7427:             } else {
                   7428:                 $defquota = $quotahash{'quotas'}{'default'};
                   7429:             }
1.536     raeburn  7430:             $settingstatus = 'default';
                   7431:         }
                   7432:     } else {
                   7433:         $settingstatus = 'default';
                   7434:         $defquota = 20;
                   7435:     }
                   7436:     if (wantarray) {
                   7437:         return ($defquota,$settingstatus);
1.472     raeburn  7438:     } else {
1.536     raeburn  7439:         return $defquota;
1.472     raeburn  7440:     }
                   7441: }
                   7442: 
1.384     raeburn  7443: sub get_secgrprole_info {
                   7444:     my ($cdom,$cnum,$needroles,$type)  = @_;
                   7445:     my %sections_count = &get_sections($cdom,$cnum);
                   7446:     my @sections =  (sort {$a <=> $b} keys(%sections_count));
                   7447:     my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
                   7448:     my @groups = sort(keys(%curr_groups));
                   7449:     my $allroles = [];
                   7450:     my $rolehash;
                   7451:     my $accesshash = {
                   7452:                      active => 'Currently has access',
                   7453:                      future => 'Will have future access',
                   7454:                      previous => 'Previously had access',
                   7455:                   };
                   7456:     if ($needroles) {
                   7457:         $rolehash = {'all' => 'all'};
1.385     albertel 7458:         my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7459: 	if (&Apache::lonnet::error(%user_roles)) {
                   7460: 	    undef(%user_roles);
                   7461: 	}
                   7462:         foreach my $item (keys(%user_roles)) {
1.384     raeburn  7463:             my ($role)=split(/\:/,$item,2);
                   7464:             if ($role eq 'cr') { next; }
                   7465:             if ($role =~ /^cr/) {
                   7466:                 $$rolehash{$role} = (split('/',$role))[3];
                   7467:             } else {
                   7468:                 $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
                   7469:             }
                   7470:         }
                   7471:         foreach my $key (sort(keys(%{$rolehash}))) {
                   7472:             push(@{$allroles},$key);
                   7473:         }
                   7474:         push (@{$allroles},'st');
                   7475:         $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
                   7476:     }
                   7477:     return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
                   7478: }
                   7479: 
1.555     raeburn  7480: sub user_picker {
1.627     raeburn  7481:     my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555     raeburn  7482:     my $currdom = $dom;
                   7483:     my %curr_selected = (
                   7484:                         srchin => 'dom',
1.580     raeburn  7485:                         srchby => 'lastname',
1.555     raeburn  7486:                       );
                   7487:     my $srchterm;
1.625     raeburn  7488:     if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555     raeburn  7489:         if ($srch->{'srchby'} ne '') {
                   7490:             $curr_selected{'srchby'} = $srch->{'srchby'};
                   7491:         }
                   7492:         if ($srch->{'srchin'} ne '') {
                   7493:             $curr_selected{'srchin'} = $srch->{'srchin'};
                   7494:         }
                   7495:         if ($srch->{'srchtype'} ne '') {
                   7496:             $curr_selected{'srchtype'} = $srch->{'srchtype'};
                   7497:         }
                   7498:         if ($srch->{'srchdomain'} ne '') {
                   7499:             $currdom = $srch->{'srchdomain'};
                   7500:         }
                   7501:         $srchterm = $srch->{'srchterm'};
                   7502:     }
                   7503:     my %lt=&Apache::lonlocal::texthash(
1.573     raeburn  7504:                     'usr'       => 'Search criteria',
1.563     raeburn  7505:                     'doma'      => 'Domain/institution to search',
1.558     albertel 7506:                     'uname'     => 'username',
                   7507:                     'lastname'  => 'last name',
1.555     raeburn  7508:                     'lastfirst' => 'last name, first name',
1.558     albertel 7509:                     'crs'       => 'in this course',
1.576     raeburn  7510:                     'dom'       => 'in selected LON-CAPA domain', 
1.558     albertel 7511:                     'alc'       => 'all LON-CAPA',
1.573     raeburn  7512:                     'instd'     => 'in institutional directory for selected domain',
1.558     albertel 7513:                     'exact'     => 'is',
                   7514:                     'contains'  => 'contains',
1.569     raeburn  7515:                     'begins'    => 'begins with',
1.571     raeburn  7516:                     'youm'      => "You must include some text to search for.",
                   7517:                     'thte'      => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
                   7518:                     'thet'      => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
                   7519:                     'yomc'      => "You must choose a domain when using an institutional directory search.",
                   7520:                     'ymcd'      => "You must choose a domain when using a domain search.",
                   7521:                     'whus'      => "When using searching by last,first you must include a comma as separator between last name and first name.",
                   7522:                     'whse'      => "When searching by last,first you must include at least one character in the first name.",
                   7523:                      'thfo'     => "The following need to be corrected before the search can be run:",
1.555     raeburn  7524:                                        );
1.563     raeburn  7525:     my $domform = &select_dom_form($currdom,'srchdomain',1,1);
                   7526:     my $srchinsel = ' <select name="srchin">';
1.555     raeburn  7527: 
                   7528:     my @srchins = ('crs','dom','alc','instd');
                   7529: 
                   7530:     foreach my $option (@srchins) {
                   7531:         # FIXME 'alc' option unavailable until 
                   7532:         #       loncreateuser::print_user_query_page()
                   7533:         #       has been completed.
                   7534:         next if ($option eq 'alc');
1.880   ! raeburn  7535:         next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));  
1.555     raeburn  7536:         next if ($option eq 'crs' && !$env{'request.course.id'});
1.563     raeburn  7537:         if ($curr_selected{'srchin'} eq $option) {
                   7538:             $srchinsel .= ' 
                   7539:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7540:         } else {
                   7541:             $srchinsel .= '
                   7542:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7543:         }
1.555     raeburn  7544:     }
1.563     raeburn  7545:     $srchinsel .= "\n  </select>\n";
1.555     raeburn  7546: 
                   7547:     my $srchbysel =  ' <select name="srchby">';
1.580     raeburn  7548:     foreach my $option ('lastname','lastfirst','uname') {
1.555     raeburn  7549:         if ($curr_selected{'srchby'} eq $option) {
                   7550:             $srchbysel .= '
                   7551:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7552:         } else {
                   7553:             $srchbysel .= '
                   7554:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7555:          }
                   7556:     }
                   7557:     $srchbysel .= "\n  </select>\n";
                   7558: 
                   7559:     my $srchtypesel = ' <select name="srchtype">';
1.580     raeburn  7560:     foreach my $option ('begins','contains','exact') {
1.555     raeburn  7561:         if ($curr_selected{'srchtype'} eq $option) {
                   7562:             $srchtypesel .= '
                   7563:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7564:         } else {
                   7565:             $srchtypesel .= '
                   7566:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7567:         }
                   7568:     }
                   7569:     $srchtypesel .= "\n  </select>\n";
                   7570: 
1.558     albertel 7571:     my ($newuserscript,$new_user_create);
1.556     raeburn  7572: 
                   7573:     if ($forcenewuser) {
1.576     raeburn  7574:         if (ref($srch) eq 'HASH') {
                   7575:             if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627     raeburn  7576:                 if ($cancreate) {
                   7577:                     $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>';
                   7578:                 } else {
1.799     bisitz   7579:                     my $helplink = 'javascript:helpMenu('."'display'".')';
1.627     raeburn  7580:                     my %usertypetext = (
                   7581:                         official   => 'institutional',
                   7582:                         unofficial => 'non-institutional',
                   7583:                     );
1.799     bisitz   7584:                     $new_user_create = '<p class="LC_warning">'
                   7585:                                       .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
                   7586:                                       .' '
                   7587:                                       .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
                   7588:                                           ,'<a href="'.$helplink.'">','</a>')
                   7589:                                       .'</p><br />';
1.627     raeburn  7590:                 }
1.576     raeburn  7591:             }
                   7592:         }
                   7593: 
1.556     raeburn  7594:         $newuserscript = <<"ENDSCRIPT";
                   7595: 
1.570     raeburn  7596: function setSearch(createnew,callingForm) {
1.556     raeburn  7597:     if (createnew == 1) {
1.570     raeburn  7598:         for (var i=0; i<callingForm.srchby.length; i++) {
                   7599:             if (callingForm.srchby.options[i].value == 'uname') {
                   7600:                 callingForm.srchby.selectedIndex = i;
1.556     raeburn  7601:             }
                   7602:         }
1.570     raeburn  7603:         for (var i=0; i<callingForm.srchin.length; i++) {
                   7604:             if ( callingForm.srchin.options[i].value == 'dom') {
                   7605: 		callingForm.srchin.selectedIndex = i;
1.556     raeburn  7606:             }
                   7607:         }
1.570     raeburn  7608:         for (var i=0; i<callingForm.srchtype.length; i++) {
                   7609:             if (callingForm.srchtype.options[i].value == 'exact') {
                   7610:                 callingForm.srchtype.selectedIndex = i;
1.556     raeburn  7611:             }
                   7612:         }
1.570     raeburn  7613:         for (var i=0; i<callingForm.srchdomain.length; i++) {
                   7614:             if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
                   7615:                 callingForm.srchdomain.selectedIndex = i;
1.556     raeburn  7616:             }
                   7617:         }
                   7618:     }
                   7619: }
                   7620: ENDSCRIPT
1.558     albertel 7621: 
1.556     raeburn  7622:     }
                   7623: 
1.555     raeburn  7624:     my $output = <<"END_BLOCK";
1.556     raeburn  7625: <script type="text/javascript">
1.824     bisitz   7626: // <![CDATA[
1.570     raeburn  7627: function validateEntry(callingForm) {
1.558     albertel 7628: 
1.556     raeburn  7629:     var checkok = 1;
1.558     albertel 7630:     var srchin;
1.570     raeburn  7631:     for (var i=0; i<callingForm.srchin.length; i++) {
                   7632: 	if ( callingForm.srchin[i].checked ) {
                   7633: 	    srchin = callingForm.srchin[i].value;
1.558     albertel 7634: 	}
                   7635:     }
                   7636: 
1.570     raeburn  7637:     var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
                   7638:     var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
                   7639:     var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
                   7640:     var srchterm =  callingForm.srchterm.value;
                   7641:     var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556     raeburn  7642:     var msg = "";
                   7643: 
                   7644:     if (srchterm == "") {
                   7645:         checkok = 0;
1.571     raeburn  7646:         msg += "$lt{'youm'}\\n";
1.556     raeburn  7647:     }
                   7648: 
1.569     raeburn  7649:     if (srchtype== 'begins') {
                   7650:         if (srchterm.length < 2) {
                   7651:             checkok = 0;
1.571     raeburn  7652:             msg += "$lt{'thte'}\\n";
1.569     raeburn  7653:         }
                   7654:     }
                   7655: 
1.556     raeburn  7656:     if (srchtype== 'contains') {
                   7657:         if (srchterm.length < 3) {
                   7658:             checkok = 0;
1.571     raeburn  7659:             msg += "$lt{'thet'}\\n";
1.556     raeburn  7660:         }
                   7661:     }
                   7662:     if (srchin == 'instd') {
                   7663:         if (srchdomain == '') {
                   7664:             checkok = 0;
1.571     raeburn  7665:             msg += "$lt{'yomc'}\\n";
1.556     raeburn  7666:         }
                   7667:     }
                   7668:     if (srchin == 'dom') {
                   7669:         if (srchdomain == '') {
                   7670:             checkok = 0;
1.571     raeburn  7671:             msg += "$lt{'ymcd'}\\n";
1.556     raeburn  7672:         }
                   7673:     }
                   7674:     if (srchby == 'lastfirst') {
                   7675:         if (srchterm.indexOf(",") == -1) {
                   7676:             checkok = 0;
1.571     raeburn  7677:             msg += "$lt{'whus'}\\n";
1.556     raeburn  7678:         }
                   7679:         if (srchterm.indexOf(",") == srchterm.length -1) {
                   7680:             checkok = 0;
1.571     raeburn  7681:             msg += "$lt{'whse'}\\n";
1.556     raeburn  7682:         }
                   7683:     }
                   7684:     if (checkok == 0) {
1.571     raeburn  7685:         alert("$lt{'thfo'}\\n"+msg);
1.556     raeburn  7686:         return;
                   7687:     }
                   7688:     if (checkok == 1) {
1.570     raeburn  7689:         callingForm.submit();
1.556     raeburn  7690:     }
                   7691: }
                   7692: 
                   7693: $newuserscript
                   7694: 
1.824     bisitz   7695: // ]]>
1.556     raeburn  7696: </script>
1.558     albertel 7697: 
                   7698: $new_user_create
                   7699: 
1.555     raeburn  7700: END_BLOCK
1.558     albertel 7701: 
1.876     raeburn  7702:     $output .= &Apache::lonhtmlcommon::start_pick_box().
                   7703:                &Apache::lonhtmlcommon::row_title($lt{'doma'}).
                   7704:                $domform.
                   7705:                &Apache::lonhtmlcommon::row_closure().
                   7706:                &Apache::lonhtmlcommon::row_title($lt{'usr'}).
                   7707:                $srchbysel.
                   7708:                $srchtypesel. 
                   7709:                '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
                   7710:                $srchinsel.
                   7711:                &Apache::lonhtmlcommon::row_closure(1). 
                   7712:                &Apache::lonhtmlcommon::end_pick_box().
                   7713:                '<br />';
1.555     raeburn  7714:     return $output;
                   7715: }
                   7716: 
1.612     raeburn  7717: sub user_rule_check {
1.615     raeburn  7718:     my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612     raeburn  7719:     my $response;
                   7720:     if (ref($usershash) eq 'HASH') {
                   7721:         foreach my $user (keys(%{$usershash})) {
                   7722:             my ($uname,$udom) = split(/:/,$user);
                   7723:             next if ($udom eq '' || $uname eq '');
1.615     raeburn  7724:             my ($id,$newuser);
1.612     raeburn  7725:             if (ref($usershash->{$user}) eq 'HASH') {
1.615     raeburn  7726:                 $newuser = $usershash->{$user}->{'newuser'};
1.612     raeburn  7727:                 $id = $usershash->{$user}->{'id'};
                   7728:             }
                   7729:             my $inst_response;
                   7730:             if (ref($checks) eq 'HASH') {
                   7731:                 if (defined($checks->{'username'})) {
1.615     raeburn  7732:                     ($inst_response,%{$inst_results->{$user}}) = 
1.612     raeburn  7733:                         &Apache::lonnet::get_instuser($udom,$uname);
                   7734:                 } elsif (defined($checks->{'id'})) {
1.615     raeburn  7735:                     ($inst_response,%{$inst_results->{$user}}) =
1.612     raeburn  7736:                         &Apache::lonnet::get_instuser($udom,undef,$id);
                   7737:                 }
1.615     raeburn  7738:             } else {
                   7739:                 ($inst_response,%{$inst_results->{$user}}) =
                   7740:                     &Apache::lonnet::get_instuser($udom,$uname);
                   7741:                 return;
1.612     raeburn  7742:             }
1.615     raeburn  7743:             if (!$got_rules->{$udom}) {
1.612     raeburn  7744:                 my %domconfig = &Apache::lonnet::get_dom('configuration',
                   7745:                                                   ['usercreation'],$udom);
                   7746:                 if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615     raeburn  7747:                     foreach my $item ('username','id') {
1.612     raeburn  7748:                         if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
                   7749:                             $$curr_rules{$udom}{$item} = 
                   7750:                                 $domconfig{'usercreation'}{$item.'_rule'};
1.585     raeburn  7751:                         }
                   7752:                     }
                   7753:                 }
1.615     raeburn  7754:                 $got_rules->{$udom} = 1;  
1.585     raeburn  7755:             }
1.612     raeburn  7756:             foreach my $item (keys(%{$checks})) {
                   7757:                 if (ref($$curr_rules{$udom}) eq 'HASH') {
                   7758:                     if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
                   7759:                         if (@{$$curr_rules{$udom}{$item}} > 0) {
                   7760:                             my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
                   7761:                             foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
                   7762:                                 if ($rule_check{$rule}) {
                   7763:                                     $$rulematch{$user}{$item} = $rule;
                   7764:                                     if ($inst_response eq 'ok') {
1.615     raeburn  7765:                                         if (ref($inst_results) eq 'HASH') {
                   7766:                                             if (ref($inst_results->{$user}) eq 'HASH') {
                   7767:                                                 if (keys(%{$inst_results->{$user}}) == 0) {
                   7768:                                                     $$alerts{$item}{$udom}{$uname} = 1;
                   7769:                                                 }
1.612     raeburn  7770:                                             }
                   7771:                                         }
1.615     raeburn  7772:                                     }
                   7773:                                     last;
1.585     raeburn  7774:                                 }
                   7775:                             }
                   7776:                         }
                   7777:                     }
                   7778:                 }
                   7779:             }
                   7780:         }
                   7781:     }
1.612     raeburn  7782:     return;
                   7783: }
                   7784: 
                   7785: sub user_rule_formats {
                   7786:     my ($domain,$domdesc,$curr_rules,$check) = @_;
                   7787:     my %text = ( 
                   7788:                  'username' => 'Usernames',
                   7789:                  'id'       => 'IDs',
                   7790:                );
                   7791:     my $output;
                   7792:     my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
                   7793:     if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
                   7794:         if (@{$ruleorder} > 0) {
                   7795:             $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>';
                   7796:             foreach my $rule (@{$ruleorder}) {
                   7797:                 if (ref($curr_rules) eq 'ARRAY') {
                   7798:                     if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
                   7799:                         if (ref($rules->{$rule}) eq 'HASH') {
                   7800:                             $output .= '<li>'.$rules->{$rule}{'name'}.': '.
                   7801:                                         $rules->{$rule}{'desc'}.'</li>';
                   7802:                         }
                   7803:                     }
                   7804:                 }
                   7805:             }
                   7806:             $output .= '</ul>';
                   7807:         }
                   7808:     }
                   7809:     return $output;
                   7810: }
                   7811: 
                   7812: sub instrule_disallow_msg {
1.615     raeburn  7813:     my ($checkitem,$domdesc,$count,$mode) = @_;
1.612     raeburn  7814:     my $response;
                   7815:     my %text = (
                   7816:                   item   => 'username',
                   7817:                   items  => 'usernames',
                   7818:                   match  => 'matches',
                   7819:                   do     => 'does',
                   7820:                   action => 'a username',
                   7821:                   one    => 'one',
                   7822:                );
                   7823:     if ($count > 1) {
                   7824:         $text{'item'} = 'usernames';
                   7825:         $text{'match'} ='match';
                   7826:         $text{'do'} = 'do';
                   7827:         $text{'action'} = 'usernames',
                   7828:         $text{'one'} = 'ones';
                   7829:     }
                   7830:     if ($checkitem eq 'id') {
                   7831:         $text{'items'} = 'IDs';
                   7832:         $text{'item'} = 'ID';
                   7833:         $text{'action'} = 'an ID';
1.615     raeburn  7834:         if ($count > 1) {
                   7835:             $text{'item'} = 'IDs';
                   7836:             $text{'action'} = 'IDs';
                   7837:         }
1.612     raeburn  7838:     }
1.674     bisitz   7839:     $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  7840:     if ($mode eq 'upload') {
                   7841:         if ($checkitem eq 'username') {
                   7842:             $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'}.");
                   7843:         } elsif ($checkitem eq 'id') {
1.674     bisitz   7844:             $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  7845:         }
1.669     raeburn  7846:     } elsif ($mode eq 'selfcreate') {
                   7847:         if ($checkitem eq 'id') {
                   7848:             $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.");
                   7849:         }
1.615     raeburn  7850:     } else {
                   7851:         if ($checkitem eq 'username') {
                   7852:             $response .= &mt("You must choose $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
                   7853:         } elsif ($checkitem eq 'id') {
                   7854:             $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.");
                   7855:         }
1.612     raeburn  7856:     }
                   7857:     return $response;
1.585     raeburn  7858: }
                   7859: 
1.624     raeburn  7860: sub personal_data_fieldtitles {
                   7861:     my %fieldtitles = &Apache::lonlocal::texthash (
                   7862:                         id => 'Student/Employee ID',
                   7863:                         permanentemail => 'E-mail address',
                   7864:                         lastname => 'Last Name',
                   7865:                         firstname => 'First Name',
                   7866:                         middlename => 'Middle Name',
                   7867:                         generation => 'Generation',
                   7868:                         gen => 'Generation',
1.765     raeburn  7869:                         inststatus => 'Affiliation',
1.624     raeburn  7870:                    );
                   7871:     return %fieldtitles;
                   7872: }
                   7873: 
1.642     raeburn  7874: sub sorted_inst_types {
                   7875:     my ($dom) = @_;
                   7876:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
                   7877:     my $othertitle = &mt('All users');
                   7878:     if ($env{'request.course.id'}) {
1.668     raeburn  7879:         $othertitle  = &mt('Any users');
1.642     raeburn  7880:     }
                   7881:     my @types;
                   7882:     if (ref($order) eq 'ARRAY') {
                   7883:         @types = @{$order};
                   7884:     }
                   7885:     if (@types == 0) {
                   7886:         if (ref($usertypes) eq 'HASH') {
                   7887:             @types = sort(keys(%{$usertypes}));
                   7888:         }
                   7889:     }
                   7890:     if (keys(%{$usertypes}) > 0) {
                   7891:         $othertitle = &mt('Other users');
                   7892:     }
                   7893:     return ($othertitle,$usertypes,\@types);
                   7894: }
                   7895: 
1.645     raeburn  7896: sub get_institutional_codes {
                   7897:     my ($settings,$allcourses,$LC_code) = @_;
                   7898: # Get complete list of course sections to update
                   7899:     my @currsections = ();
                   7900:     my @currxlists = ();
                   7901:     my $coursecode = $$settings{'internal.coursecode'};
                   7902: 
                   7903:     if ($$settings{'internal.sectionnums'} ne '') {
                   7904:         @currsections = split(/,/,$$settings{'internal.sectionnums'});
                   7905:     }
                   7906: 
                   7907:     if ($$settings{'internal.crosslistings'} ne '') {
                   7908:         @currxlists = split(/,/,$$settings{'internal.crosslistings'});
                   7909:     }
                   7910: 
                   7911:     if (@currxlists > 0) {
                   7912:         foreach (@currxlists) {
                   7913:             if (m/^([^:]+):(\w*)$/) {
                   7914:                 unless (grep/^$1$/,@{$allcourses}) {
                   7915:                     push @{$allcourses},$1;
                   7916:                     $$LC_code{$1} = $2;
                   7917:                 }
                   7918:             }
                   7919:         }
                   7920:     }
                   7921:  
                   7922:     if (@currsections > 0) {
                   7923:         foreach (@currsections) {
                   7924:             if (m/^(\w+):(\w*)$/) {
                   7925:                 my $sec = $coursecode.$1;
                   7926:                 my $lc_sec = $2;
                   7927:                 unless (grep/^$sec$/,@{$allcourses}) {
                   7928:                     push @{$allcourses},$sec;
                   7929:                     $$LC_code{$sec} = $lc_sec;
                   7930:                 }
                   7931:             }
                   7932:         }
                   7933:     }
                   7934:     return;
                   7935: }
                   7936: 
1.112     bowersj2 7937: =pod
                   7938: 
1.780     raeburn  7939: =head1 Slot Helpers
                   7940: 
                   7941: =over 4
                   7942: 
                   7943: =item * sorted_slots()
                   7944: 
                   7945: Sorts an array of slot names in order of slot start time (earliest first). 
                   7946: 
                   7947: Inputs:
                   7948: 
                   7949: =over 4
                   7950: 
                   7951: slotsarr  - Reference to array of unsorted slot names.
                   7952: 
                   7953: slots     - Reference to hash of hash, where outer hash keys are slot names.
                   7954: 
1.549     albertel 7955: =back
                   7956: 
1.780     raeburn  7957: Returns:
                   7958: 
                   7959: =over 4
                   7960: 
                   7961: sorted   - An array of slot names sorted by the start time of the slot.
                   7962: 
                   7963: =back
                   7964: 
                   7965: =back
                   7966: 
                   7967: =cut
                   7968: 
                   7969: 
                   7970: sub sorted_slots {
                   7971:     my ($slotsarr,$slots) = @_;
                   7972:     my @sorted;
                   7973:     if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
                   7974:         @sorted =
                   7975:             sort {
                   7976:                      if (ref($slots->{$a}) && ref($slots->{$b})) {
                   7977:                          return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
                   7978:                      }
                   7979:                      if (ref($slots->{$a})) { return -1;}
                   7980:                      if (ref($slots->{$b})) { return 1;}
                   7981:                      return 0;
                   7982:                  } @{$slotsarr};
                   7983:     }
                   7984:     return @sorted;
                   7985: }
                   7986: 
                   7987: 
                   7988: =pod
                   7989: 
1.549     albertel 7990: =head1 HTTP Helpers
                   7991: 
                   7992: =over 4
                   7993: 
1.648     raeburn  7994: =item * &get_unprocessed_cgi($query,$possible_names)
1.112     bowersj2 7995: 
1.258     albertel 7996: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112     bowersj2 7997: $query.  The parameters listed in $possible_names (an array reference),
1.258     albertel 7998: will be set in $env{'form.name'} if they do not already exist.
1.112     bowersj2 7999: 
                   8000: Typically called with $ENV{'QUERY_STRING'} as the first parameter.  
                   8001: $possible_names is an ref to an array of form element names.  As an example:
                   8002: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258     albertel 8003: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112     bowersj2 8004: 
                   8005: =cut
1.1       albertel 8006: 
1.6       albertel 8007: sub get_unprocessed_cgi {
1.25      albertel 8008:   my ($query,$possible_names)= @_;
1.26      matthew  8009:   # $Apache::lonxml::debug=1;
1.356     albertel 8010:   foreach my $pair (split(/&/,$query)) {
                   8011:     my ($name, $value) = split(/=/,$pair);
1.369     www      8012:     $name = &unescape($name);
1.25      albertel 8013:     if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
                   8014:       $value =~ tr/+/ /;
                   8015:       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258     albertel 8016:       unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25      albertel 8017:     }
1.16      harris41 8018:   }
1.6       albertel 8019: }
                   8020: 
1.112     bowersj2 8021: =pod
                   8022: 
1.648     raeburn  8023: =item * &cacheheader() 
1.112     bowersj2 8024: 
                   8025: returns cache-controlling header code
                   8026: 
                   8027: =cut
                   8028: 
1.7       albertel 8029: sub cacheheader {
1.258     albertel 8030:     unless ($env{'request.method'} eq 'GET') { return ''; }
1.216     albertel 8031:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
                   8032:     my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7       albertel 8033:                 <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
                   8034:                 <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216     albertel 8035:     return $output;
1.7       albertel 8036: }
                   8037: 
1.112     bowersj2 8038: =pod
                   8039: 
1.648     raeburn  8040: =item * &no_cache($r) 
1.112     bowersj2 8041: 
                   8042: specifies header code to not have cache
                   8043: 
                   8044: =cut
                   8045: 
1.9       albertel 8046: sub no_cache {
1.216     albertel 8047:     my ($r) = @_;
                   8048:     if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258     albertel 8049: 	$env{'request.method'} ne 'GET') { return ''; }
1.216     albertel 8050:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
                   8051:     $r->no_cache(1);
                   8052:     $r->header_out("Expires" => $date);
                   8053:     $r->header_out("Pragma" => "no-cache");
1.123     www      8054: }
                   8055: 
                   8056: sub content_type {
1.181     albertel 8057:     my ($r,$type,$charset) = @_;
1.299     foxr     8058:     if ($r) {
                   8059: 	#  Note that printout.pl calls this with undef for $r.
                   8060: 	&no_cache($r);
                   8061:     }
1.258     albertel 8062:     if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181     albertel 8063:     unless ($charset) {
                   8064: 	$charset=&Apache::lonlocal::current_encoding;
                   8065:     }
                   8066:     if ($charset) { $type.='; charset='.$charset; }
                   8067:     if ($r) {
                   8068: 	$r->content_type($type);
                   8069:     } else {
                   8070: 	print("Content-type: $type\n\n");
                   8071:     }
1.9       albertel 8072: }
1.25      albertel 8073: 
1.112     bowersj2 8074: =pod
                   8075: 
1.648     raeburn  8076: =item * &add_to_env($name,$value) 
1.112     bowersj2 8077: 
1.258     albertel 8078: adds $name to the %env hash with value
1.112     bowersj2 8079: $value, if $name already exists, the entry is converted to an array
                   8080: reference and $value is added to the array.
                   8081: 
                   8082: =cut
                   8083: 
1.25      albertel 8084: sub add_to_env {
                   8085:   my ($name,$value)=@_;
1.258     albertel 8086:   if (defined($env{$name})) {
                   8087:     if (ref($env{$name})) {
1.25      albertel 8088:       #already have multiple values
1.258     albertel 8089:       push(@{ $env{$name} },$value);
1.25      albertel 8090:     } else {
                   8091:       #first time seeing multiple values, convert hash entry to an arrayref
1.258     albertel 8092:       my $first=$env{$name};
                   8093:       undef($env{$name});
                   8094:       push(@{ $env{$name} },$first,$value);
1.25      albertel 8095:     }
                   8096:   } else {
1.258     albertel 8097:     $env{$name}=$value;
1.25      albertel 8098:   }
1.31      albertel 8099: }
1.149     albertel 8100: 
                   8101: =pod
                   8102: 
1.648     raeburn  8103: =item * &get_env_multiple($name) 
1.149     albertel 8104: 
1.258     albertel 8105: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149     albertel 8106: values may be defined and end up as an array ref.
                   8107: 
                   8108: returns an array of values
                   8109: 
                   8110: =cut
                   8111: 
                   8112: sub get_env_multiple {
                   8113:     my ($name) = @_;
                   8114:     my @values;
1.258     albertel 8115:     if (defined($env{$name})) {
1.149     albertel 8116:         # exists is it an array
1.258     albertel 8117:         if (ref($env{$name})) {
                   8118:             @values=@{ $env{$name} };
1.149     albertel 8119:         } else {
1.258     albertel 8120:             $values[0]=$env{$name};
1.149     albertel 8121:         }
                   8122:     }
                   8123:     return(@values);
                   8124: }
                   8125: 
1.660     raeburn  8126: sub ask_for_embedded_content {
                   8127:     my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
                   8128:     my $upload_output = '
                   8129:    <form name="upload_embedded" action="'.$actionurl.'"
                   8130:                   method="post" enctype="multipart/form-data">';
                   8131:     $upload_output .= $state;
1.661     raeburn  8132:     $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660     raeburn  8133: 
                   8134:     my $num = 0;
                   8135:     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
                   8136:         $upload_output .= &start_data_table_row().
                   8137:             '<td>'.$embed_file.'</td><td>';
                   8138:         if ($args->{'ignore_remote_references'}
                   8139:             && $embed_file =~ m{^\w+://}) {
                   8140:             $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
                   8141:         } elsif ($args->{'error_on_invalid_names'}
                   8142:             && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
                   8143: 
                   8144:             $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
                   8145: 
                   8146:         } else {
                   8147:             $upload_output .='
1.661     raeburn  8148:            <input name="embedded_item_'.$num.'" type="file" value="" />
1.660     raeburn  8149:            <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
                   8150:             my $attrib = join(':',@{$$allfiles{$embed_file}});
                   8151:             $upload_output .=
                   8152:                 "\n\t\t".
                   8153:                 '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
                   8154:                 $attrib.'" />';
                   8155:             if (exists($$codebase{$embed_file})) {
                   8156:                 $upload_output .=
                   8157:                     "\n\t\t".
                   8158:                     '<input name="codebase_'.$num.'" type="hidden" value="'.
                   8159:                     &escape($$codebase{$embed_file}).'" />';
                   8160:             }
                   8161:         }
                   8162:         $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
                   8163:         $num++;
                   8164:     }
                   8165:     $upload_output .= &Apache::loncommon::end_data_table().'<br />
                   8166:    <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
                   8167:    <input type ="submit" value="'.&mt('Upload Listed Files').'" />
                   8168:    '.&mt('(only files for which a location has been provided will be uploaded)').'
                   8169:    </form>';
                   8170:     return $upload_output;
                   8171: }
                   8172: 
1.661     raeburn  8173: sub upload_embedded {
                   8174:     my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
                   8175:         $current_disk_usage) = @_;
                   8176:     my $output;
                   8177:     for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
                   8178:         next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
                   8179:         my $orig_uploaded_filename =
                   8180:             $env{'form.embedded_item_'.$i.'.filename'};
                   8181: 
                   8182:         $env{'form.embedded_orig_'.$i} =
                   8183:             &unescape($env{'form.embedded_orig_'.$i});
                   8184:         my ($path,$fname) =
                   8185:             ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
                   8186:         # no path, whole string is fname
                   8187:         if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
                   8188: 
                   8189:         $path = $env{'form.currentpath'}.$path;
                   8190:         $fname = &Apache::lonnet::clean_filename($fname);
                   8191:         # See if there is anything left
                   8192:         next if ($fname eq '');
                   8193: 
                   8194:         # Check if file already exists as a file or directory.
                   8195:         my ($state,$msg);
                   8196:         if ($context eq 'portfolio') {
                   8197:             my $port_path = $dirpath;
                   8198:             if ($group ne '') {
                   8199:                 $port_path = "groups/$group/$port_path";
                   8200:             }
                   8201:             ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
                   8202:                                               $dir_root,$port_path,$disk_quota,
                   8203:                                               $current_disk_usage,$uname,$udom);
                   8204:             if ($state eq 'will_exceed_quota'
                   8205:                 || $state eq 'file_locked'
                   8206:                 || $state eq 'file_exists' ) {
                   8207:                 $output .= $msg;
                   8208:                 next;
                   8209:             }
                   8210:         } elsif (($context eq 'author') || ($context eq 'testbank')) {
                   8211:             ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
                   8212:             if ($state eq 'exists') {
                   8213:                 $output .= $msg;
                   8214:                 next;
                   8215:             }
                   8216:         }
                   8217:         # Check if extension is valid
                   8218:         if (($fname =~ /\.(\w+)$/) &&
                   8219:             (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   8220:             $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
                   8221:             next;
                   8222:         } elsif (($fname =~ /\.(\w+)$/) &&
                   8223:                  (!defined(&Apache::loncommon::fileembstyle($1)))) {
                   8224:             $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   8225:             next;
                   8226:         } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
                   8227:             $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
                   8228:             next;
                   8229:         }
                   8230: 
                   8231:         $env{'form.embedded_item_'.$i.'.filename'}=$fname;
                   8232:         if ($context eq 'portfolio') {
                   8233:             my $result=
                   8234:                 &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
                   8235:                                                 $dirpath.$path);
                   8236:             if ($result !~ m|^/uploaded/|) {
                   8237:                 $output .= '<span class="LC_error">'
                   8238:                       .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
                   8239:                            ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
                   8240:                       .'</span><br />';
                   8241:                 next;
                   8242:             } else {
                   8243:                 $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
                   8244:                            $path.$fname.'</span>').'</p>';     
                   8245:             }
                   8246:         } else {
                   8247: # Save the file
                   8248:             my $target = $env{'form.embedded_item_'.$i};
                   8249:             my $fullpath = $dir_root.$dirpath.'/'.$path;
                   8250:             my $dest = $fullpath.$fname;
                   8251:             my $url = $url_root.$dirpath.'/'.$path.$fname;
                   8252:             my @parts=split(/\//,$fullpath);
                   8253:             my $count;
                   8254:             my $filepath = $dir_root;
                   8255:             for ($count=4;$count<=$#parts;$count++) {
                   8256:                 $filepath .= "/$parts[$count]";
                   8257:                 if ((-e $filepath)!=1) {
                   8258:                     mkdir($filepath,0770);
                   8259:                 }
                   8260:             }
                   8261:             my $fh;
                   8262:             if (!open($fh,'>'.$dest)) {
                   8263:                 &Apache::lonnet::logthis('Failed to create '.$dest);
                   8264:                 $output .= '<span class="LC_error">'.
                   8265:                            &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   8266:                            '</span><br />';
                   8267:             } else {
                   8268:                 if (!print $fh $env{'form.embedded_item_'.$i}) {
                   8269:                     &Apache::lonnet::logthis('Failed to write to '.$dest);
                   8270:                     $output .= '<span class="LC_error">'.
                   8271:                               &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   8272:                               '</span><br />';
                   8273:                 } else {
                   8274:                     if ($context eq 'testbank') {
                   8275:                         $output .= &mt('Embedded file uploaded successfully:').
                   8276:                                    '&nbsp;<a href="'.$url.'">'.
                   8277:                                    $orig_uploaded_filename.'</a><br />';
                   8278:                     } else {
1.705     tempelho 8279:                         $output .= '<span class=\"LC_fontsize_large\">'.
1.661     raeburn  8280:                                    &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705     tempelho 8281:                                    $orig_uploaded_filename.'</a>').'</span><br />';
1.661     raeburn  8282:                     }
                   8283:                 }
                   8284:                 close($fh);
                   8285:             }
                   8286:         }
                   8287:     }
                   8288:     return $output;
                   8289: }
                   8290: 
                   8291: sub check_for_existing {
                   8292:     my ($path,$fname,$element) = @_;
                   8293:     my ($state,$msg);
                   8294:     if (-d $path.'/'.$fname) {
                   8295:         $state = 'exists';
                   8296:         $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   8297:     } elsif (-e $path.'/'.$fname) {
                   8298:         $state = 'exists';
                   8299:         $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   8300:     }
                   8301:     if ($state eq 'exists') {
                   8302:         $msg = '<span class="LC_error">'.$msg.'</span><br />';
                   8303:     }
                   8304:     return ($state,$msg);
                   8305: }
                   8306: 
                   8307: sub check_for_upload {
                   8308:     my ($path,$fname,$group,$element,$portfolio_root,$port_path,
                   8309:         $disk_quota,$current_disk_usage,$uname,$udom) = @_;
                   8310:     my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
                   8311:     my $getpropath = 1;
                   8312:     my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
                   8313:                                             $getpropath);
                   8314:     my $found_file = 0;
                   8315:     my $locked_file = 0;
                   8316:     foreach my $line (@dir_list) {
                   8317:         my ($file_name)=split(/\&/,$line,2);
                   8318:         if ($file_name eq $fname){
                   8319:             $file_name = $path.$file_name;
                   8320:             if ($group ne '') {
                   8321:                 $file_name = $group.$file_name;
                   8322:             }
                   8323:             $found_file = 1;
                   8324:             if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
                   8325:                 $locked_file = 1;
                   8326:             }
                   8327:         }
                   8328:     }
                   8329:     if (($current_disk_usage + $filesize) > $disk_quota){
                   8330:         my $msg = '<span class="LC_error">'.
                   8331:                 &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
                   8332:                   '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
                   8333:         return ('will_exceed_quota',$msg);
                   8334:     } elsif ($found_file) {
                   8335:         if ($locked_file) {
                   8336:             my $msg = '<span class="LC_error">';
                   8337:             $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>');
                   8338:             $msg .= '</span><br />';
                   8339:             $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
                   8340:             return ('file_locked',$msg);
                   8341:         } else {
                   8342:             my $msg = '<span class="LC_error">';
                   8343:             $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'});
                   8344:             $msg .= '</span>';
                   8345:             $msg .= '<br />';
                   8346:             $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
                   8347:             return ('file_exists',$msg);
                   8348:         }
                   8349:     }
                   8350: }
                   8351: 
1.31      albertel 8352: 
1.41      ng       8353: =pod
1.45      matthew  8354: 
1.464     albertel 8355: =back
1.41      ng       8356: 
1.112     bowersj2 8357: =head1 CSV Upload/Handling functions
1.38      albertel 8358: 
1.41      ng       8359: =over 4
                   8360: 
1.648     raeburn  8361: =item * &upfile_store($r)
1.41      ng       8362: 
                   8363: Store uploaded file, $r should be the HTTP Request object,
1.258     albertel 8364: needs $env{'form.upfile'}
1.41      ng       8365: returns $datatoken to be put into hidden field
                   8366: 
                   8367: =cut
1.31      albertel 8368: 
                   8369: sub upfile_store {
                   8370:     my $r=shift;
1.258     albertel 8371:     $env{'form.upfile'}=~s/\r/\n/gs;
                   8372:     $env{'form.upfile'}=~s/\f/\n/gs;
                   8373:     $env{'form.upfile'}=~s/\n+/\n/gs;
                   8374:     $env{'form.upfile'}=~s/\n+$//gs;
1.31      albertel 8375: 
1.258     albertel 8376:     my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
                   8377: 	'_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31      albertel 8378:     {
1.158     raeburn  8379:         my $datafile = $r->dir_config('lonDaemons').
                   8380:                            '/tmp/'.$datatoken.'.tmp';
                   8381:         if ( open(my $fh,">$datafile") ) {
1.258     albertel 8382:             print $fh $env{'form.upfile'};
1.158     raeburn  8383:             close($fh);
                   8384:         }
1.31      albertel 8385:     }
                   8386:     return $datatoken;
                   8387: }
                   8388: 
1.56      matthew  8389: =pod
                   8390: 
1.648     raeburn  8391: =item * &load_tmp_file($r)
1.41      ng       8392: 
                   8393: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258     albertel 8394: needs $env{'form.datatoken'},
                   8395: sets $env{'form.upfile'} to the contents of the file
1.41      ng       8396: 
                   8397: =cut
1.31      albertel 8398: 
                   8399: sub load_tmp_file {
                   8400:     my $r=shift;
                   8401:     my @studentdata=();
                   8402:     {
1.158     raeburn  8403:         my $studentfile = $r->dir_config('lonDaemons').
1.258     albertel 8404:                               '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158     raeburn  8405:         if ( open(my $fh,"<$studentfile") ) {
                   8406:             @studentdata=<$fh>;
                   8407:             close($fh);
                   8408:         }
1.31      albertel 8409:     }
1.258     albertel 8410:     $env{'form.upfile'}=join('',@studentdata);
1.31      albertel 8411: }
                   8412: 
1.56      matthew  8413: =pod
                   8414: 
1.648     raeburn  8415: =item * &upfile_record_sep()
1.41      ng       8416: 
                   8417: Separate uploaded file into records
                   8418: returns array of records,
1.258     albertel 8419: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41      ng       8420: 
                   8421: =cut
1.31      albertel 8422: 
                   8423: sub upfile_record_sep {
1.258     albertel 8424:     if ($env{'form.upfiletype'} eq 'xml') {
1.31      albertel 8425:     } else {
1.248     albertel 8426: 	my @records;
1.258     albertel 8427: 	foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248     albertel 8428: 	    if ($line=~/^\s*$/) { next; }
                   8429: 	    push(@records,$line);
                   8430: 	}
                   8431: 	return @records;
1.31      albertel 8432:     }
                   8433: }
                   8434: 
1.56      matthew  8435: =pod
                   8436: 
1.648     raeburn  8437: =item * &record_sep($record)
1.41      ng       8438: 
1.258     albertel 8439: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41      ng       8440: 
                   8441: =cut
                   8442: 
1.263     www      8443: sub takeleft {
                   8444:     my $index=shift;
                   8445:     return substr('0000'.$index,-4,4);
                   8446: }
                   8447: 
1.31      albertel 8448: sub record_sep {
                   8449:     my $record=shift;
                   8450:     my %components=();
1.258     albertel 8451:     if ($env{'form.upfiletype'} eq 'xml') {
                   8452:     } elsif ($env{'form.upfiletype'} eq 'space') {
1.31      albertel 8453:         my $i=0;
1.356     albertel 8454:         foreach my $field (split(/\s+/,$record)) {
1.31      albertel 8455:             $field=~s/^(\"|\')//;
                   8456:             $field=~s/(\"|\')$//;
1.263     www      8457:             $components{&takeleft($i)}=$field;
1.31      albertel 8458:             $i++;
                   8459:         }
1.258     albertel 8460:     } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31      albertel 8461:         my $i=0;
1.356     albertel 8462:         foreach my $field (split(/\t/,$record)) {
1.31      albertel 8463:             $field=~s/^(\"|\')//;
                   8464:             $field=~s/(\"|\')$//;
1.263     www      8465:             $components{&takeleft($i)}=$field;
1.31      albertel 8466:             $i++;
                   8467:         }
                   8468:     } else {
1.561     www      8469:         my $separator=',';
1.480     banghart 8470:         if ($env{'form.upfiletype'} eq 'semisv') {
1.561     www      8471:             $separator=';';
1.480     banghart 8472:         }
1.31      albertel 8473:         my $i=0;
1.561     www      8474: # the character we are looking for to indicate the end of a quote or a record 
                   8475:         my $looking_for=$separator;
                   8476: # do not add the characters to the fields
                   8477:         my $ignore=0;
                   8478: # we just encountered a separator (or the beginning of the record)
                   8479:         my $just_found_separator=1;
                   8480: # store the field we are working on here
                   8481:         my $field='';
                   8482: # work our way through all characters in record
                   8483:         foreach my $character ($record=~/(.)/g) {
                   8484:             if ($character eq $looking_for) {
                   8485:                if ($character ne $separator) {
                   8486: # Found the end of a quote, again looking for separator
                   8487:                   $looking_for=$separator;
                   8488:                   $ignore=1;
                   8489:                } else {
                   8490: # Found a separator, store away what we got
                   8491:                   $components{&takeleft($i)}=$field;
                   8492: 	          $i++;
                   8493:                   $just_found_separator=1;
                   8494:                   $ignore=0;
                   8495:                   $field='';
                   8496:                }
                   8497:                next;
                   8498:             }
                   8499: # single or double quotation marks after a separator indicate beginning of a quote
                   8500: # we are now looking for the end of the quote and need to ignore separators
                   8501:             if ((($character eq '"') || ($character eq "'")) && ($just_found_separator))  {
                   8502:                $looking_for=$character;
                   8503:                next;
                   8504:             }
                   8505: # ignore would be true after we reached the end of a quote
                   8506:             if ($ignore) { next; }
                   8507:             if (($just_found_separator) && ($character=~/\s/)) { next; }
                   8508:             $field.=$character;
                   8509:             $just_found_separator=0; 
1.31      albertel 8510:         }
1.561     www      8511: # catch the very last entry, since we never encountered the separator
                   8512:         $components{&takeleft($i)}=$field;
1.31      albertel 8513:     }
                   8514:     return %components;
                   8515: }
                   8516: 
1.144     matthew  8517: ######################################################
                   8518: ######################################################
                   8519: 
1.56      matthew  8520: =pod
                   8521: 
1.648     raeburn  8522: =item * &upfile_select_html()
1.41      ng       8523: 
1.144     matthew  8524: Return HTML code to select a file from the users machine and specify 
                   8525: the file type.
1.41      ng       8526: 
                   8527: =cut
                   8528: 
1.144     matthew  8529: ######################################################
                   8530: ######################################################
1.31      albertel 8531: sub upfile_select_html {
1.144     matthew  8532:     my %Types = (
                   8533:                  csv   => &mt('CSV (comma separated values, spreadsheet)'),
1.480     banghart 8534:                  semisv => &mt('Semicolon separated values'),
1.144     matthew  8535:                  space => &mt('Space separated'),
                   8536:                  tab   => &mt('Tabulator separated'),
                   8537: #                 xml   => &mt('HTML/XML'),
                   8538:                  );
                   8539:     my $Str = '<input type="file" name="upfile" size="50" />'.
1.727     riegler  8540:         '<br />'.&mt('Type').': <select name="upfiletype">';
1.144     matthew  8541:     foreach my $type (sort(keys(%Types))) {
                   8542:         $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
                   8543:     }
                   8544:     $Str .= "</select>\n";
                   8545:     return $Str;
1.31      albertel 8546: }
                   8547: 
1.301     albertel 8548: sub get_samples {
                   8549:     my ($records,$toget) = @_;
                   8550:     my @samples=({});
                   8551:     my $got=0;
                   8552:     foreach my $rec (@$records) {
                   8553: 	my %temp = &record_sep($rec);
                   8554: 	if (! grep(/\S/, values(%temp))) { next; }
                   8555: 	if (%temp) {
                   8556: 	    $samples[$got]=\%temp;
                   8557: 	    $got++;
                   8558: 	    if ($got == $toget) { last; }
                   8559: 	}
                   8560:     }
                   8561:     return \@samples;
                   8562: }
                   8563: 
1.144     matthew  8564: ######################################################
                   8565: ######################################################
                   8566: 
1.56      matthew  8567: =pod
                   8568: 
1.648     raeburn  8569: =item * &csv_print_samples($r,$records)
1.41      ng       8570: 
                   8571: Prints a table of sample values from each column uploaded $r is an
                   8572: Apache Request ref, $records is an arrayref from
                   8573: &Apache::loncommon::upfile_record_sep
                   8574: 
                   8575: =cut
                   8576: 
1.144     matthew  8577: ######################################################
                   8578: ######################################################
1.31      albertel 8579: sub csv_print_samples {
                   8580:     my ($r,$records) = @_;
1.662     bisitz   8581:     my $samples = &get_samples($records,5);
1.301     albertel 8582: 
1.594     raeburn  8583:     $r->print(&mt('Samples').'<br />'.&start_data_table().
                   8584:               &start_data_table_header_row());
1.356     albertel 8585:     foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) { 
1.845     bisitz   8586:         $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594     raeburn  8587:     $r->print(&end_data_table_header_row());
1.301     albertel 8588:     foreach my $hash (@$samples) {
1.594     raeburn  8589: 	$r->print(&start_data_table_row());
1.356     albertel 8590: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31      albertel 8591: 	    $r->print('<td>');
1.356     albertel 8592: 	    if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31      albertel 8593: 	    $r->print('</td>');
                   8594: 	}
1.594     raeburn  8595: 	$r->print(&end_data_table_row());
1.31      albertel 8596:     }
1.594     raeburn  8597:     $r->print(&end_data_table().'<br />'."\n");
1.31      albertel 8598: }
                   8599: 
1.144     matthew  8600: ######################################################
                   8601: ######################################################
                   8602: 
1.56      matthew  8603: =pod
                   8604: 
1.648     raeburn  8605: =item * &csv_print_select_table($r,$records,$d)
1.41      ng       8606: 
                   8607: Prints a table to create associations between values and table columns.
1.144     matthew  8608: 
1.41      ng       8609: $r is an Apache Request ref,
                   8610: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174     matthew  8611: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41      ng       8612: 
                   8613: =cut
                   8614: 
1.144     matthew  8615: ######################################################
                   8616: ######################################################
1.31      albertel 8617: sub csv_print_select_table {
                   8618:     my ($r,$records,$d) = @_;
1.301     albertel 8619:     my $i=0;
                   8620:     my $samples = &get_samples($records,1);
1.144     matthew  8621:     $r->print(&mt('Associate columns with student attributes.')."\n".
1.594     raeburn  8622: 	      &start_data_table().&start_data_table_header_row().
1.144     matthew  8623:               '<th>'.&mt('Attribute').'</th>'.
1.594     raeburn  8624:               '<th>'.&mt('Column').'</th>'.
                   8625:               &end_data_table_header_row()."\n");
1.356     albertel 8626:     foreach my $array_ref (@$d) {
                   8627: 	my ($value,$display,$defaultcol)=@{ $array_ref };
1.729     raeburn  8628: 	$r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31      albertel 8629: 
1.875     bisitz   8630: 	$r->print('<td><select name="f'.$i.'"'.
1.32      matthew  8631: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.31      albertel 8632: 	$r->print('<option value="none"></option>');
1.356     albertel 8633: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
                   8634: 	    $r->print('<option value="'.$sample.'"'.
                   8635:                       ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662     bisitz   8636:                       '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31      albertel 8637: 	}
1.594     raeburn  8638: 	$r->print('</select></td>'.&end_data_table_row()."\n");
1.31      albertel 8639: 	$i++;
                   8640:     }
1.594     raeburn  8641:     $r->print(&end_data_table());
1.31      albertel 8642:     $i--;
                   8643:     return $i;
                   8644: }
1.56      matthew  8645: 
1.144     matthew  8646: ######################################################
                   8647: ######################################################
                   8648: 
1.56      matthew  8649: =pod
1.31      albertel 8650: 
1.648     raeburn  8651: =item * &csv_samples_select_table($r,$records,$d)
1.41      ng       8652: 
                   8653: Prints a table of sample values from the upload and can make associate samples to internal names.
                   8654: 
                   8655: $r is an Apache Request ref,
                   8656: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
                   8657: $d is an array of 2 element arrays (internal name, displayed name)
                   8658: 
                   8659: =cut
                   8660: 
1.144     matthew  8661: ######################################################
                   8662: ######################################################
1.31      albertel 8663: sub csv_samples_select_table {
                   8664:     my ($r,$records,$d) = @_;
                   8665:     my $i=0;
1.144     matthew  8666:     #
1.662     bisitz   8667:     my $max_samples = 5;
                   8668:     my $samples = &get_samples($records,$max_samples);
1.594     raeburn  8669:     $r->print(&start_data_table().
                   8670:               &start_data_table_header_row().'<th>'.
                   8671:               &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
                   8672:               &end_data_table_header_row());
1.301     albertel 8673: 
                   8674:     foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594     raeburn  8675: 	$r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32      matthew  8676: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.301     albertel 8677: 	foreach my $option (@$d) {
                   8678: 	    my ($value,$display,$defaultcol)=@{ $option };
1.174     matthew  8679: 	    $r->print('<option value="'.$value.'"'.
1.253     albertel 8680:                       ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174     matthew  8681:                       $display.'</option>');
1.31      albertel 8682: 	}
                   8683: 	$r->print('</select></td><td>');
1.662     bisitz   8684: 	foreach my $line (0..($max_samples-1)) {
1.301     albertel 8685: 	    if (defined($samples->[$line]{$key})) { 
                   8686: 		$r->print($samples->[$line]{$key}."<br />\n"); 
                   8687: 	    }
                   8688: 	}
1.594     raeburn  8689: 	$r->print('</td>'.&end_data_table_row());
1.31      albertel 8690: 	$i++;
                   8691:     }
1.594     raeburn  8692:     $r->print(&end_data_table());
1.31      albertel 8693:     $i--;
                   8694:     return($i);
1.115     matthew  8695: }
                   8696: 
1.144     matthew  8697: ######################################################
                   8698: ######################################################
                   8699: 
1.115     matthew  8700: =pod
                   8701: 
1.648     raeburn  8702: =item * &clean_excel_name($name)
1.115     matthew  8703: 
                   8704: Returns a replacement for $name which does not contain any illegal characters.
                   8705: 
                   8706: =cut
                   8707: 
1.144     matthew  8708: ######################################################
                   8709: ######################################################
1.115     matthew  8710: sub clean_excel_name {
                   8711:     my ($name) = @_;
                   8712:     $name =~ s/[:\*\?\/\\]//g;
                   8713:     if (length($name) > 31) {
                   8714:         $name = substr($name,0,31);
                   8715:     }
                   8716:     return $name;
1.25      albertel 8717: }
1.84      albertel 8718: 
1.85      albertel 8719: =pod
                   8720: 
1.648     raeburn  8721: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85      albertel 8722: 
                   8723: Returns either 1 or undef
                   8724: 
                   8725: 1 if the part is to be hidden, undef if it is to be shown
                   8726: 
                   8727: Arguments are:
                   8728: 
                   8729: $id the id of the part to be checked
                   8730: $symb, optional the symb of the resource to check
                   8731: $udom, optional the domain of the user to check for
                   8732: $uname, optional the username of the user to check for
                   8733: 
                   8734: =cut
1.84      albertel 8735: 
                   8736: sub check_if_partid_hidden {
                   8737:     my ($id,$symb,$udom,$uname) = @_;
1.133     albertel 8738:     my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84      albertel 8739: 					 $symb,$udom,$uname);
1.141     albertel 8740:     my $truth=1;
                   8741:     #if the string starts with !, then the list is the list to show not hide
                   8742:     if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84      albertel 8743:     my @hiddenlist=split(/,/,$hiddenparts);
                   8744:     foreach my $checkid (@hiddenlist) {
1.141     albertel 8745: 	if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84      albertel 8746:     }
1.141     albertel 8747:     return !$truth;
1.84      albertel 8748: }
1.127     matthew  8749: 
1.138     matthew  8750: 
                   8751: ############################################################
                   8752: ############################################################
                   8753: 
                   8754: =pod
                   8755: 
1.157     matthew  8756: =back 
                   8757: 
1.138     matthew  8758: =head1 cgi-bin script and graphing routines
                   8759: 
1.157     matthew  8760: =over 4
                   8761: 
1.648     raeburn  8762: =item * &get_cgi_id()
1.138     matthew  8763: 
                   8764: Inputs: none
                   8765: 
                   8766: Returns an id which can be used to pass environment variables
                   8767: to various cgi-bin scripts.  These environment variables will
                   8768: be removed from the users environment after a given time by
                   8769: the routine &Apache::lonnet::transfer_profile_to_env.
                   8770: 
                   8771: =cut
                   8772: 
                   8773: ############################################################
                   8774: ############################################################
1.152     albertel 8775: my $uniq=0;
1.136     matthew  8776: sub get_cgi_id {
1.154     albertel 8777:     $uniq=($uniq+1)%100000;
1.280     albertel 8778:     return (time.'_'.$$.'_'.$uniq);
1.136     matthew  8779: }
                   8780: 
1.127     matthew  8781: ############################################################
                   8782: ############################################################
                   8783: 
                   8784: =pod
                   8785: 
1.648     raeburn  8786: =item * &DrawBarGraph()
1.127     matthew  8787: 
1.138     matthew  8788: Facilitates the plotting of data in a (stacked) bar graph.
                   8789: Puts plot definition data into the users environment in order for 
                   8790: graph.png to plot it.  Returns an <img> tag for the plot.
                   8791: The bars on the plot are labeled '1','2',...,'n'.
                   8792: 
                   8793: Inputs:
                   8794: 
                   8795: =over 4
                   8796: 
                   8797: =item $Title: string, the title of the plot
                   8798: 
                   8799: =item $xlabel: string, text describing the X-axis of the plot
                   8800: 
                   8801: =item $ylabel: string, text describing the Y-axis of the plot
                   8802: 
                   8803: =item $Max: scalar, the maximum Y value to use in the plot
                   8804: If $Max is < any data point, the graph will not be rendered.
                   8805: 
1.140     matthew  8806: =item $colors: array ref holding the colors to be used for the data sets when
1.138     matthew  8807: they are plotted.  If undefined, default values will be used.
                   8808: 
1.178     matthew  8809: =item $labels: array ref holding the labels to use on the x-axis for the bars.
                   8810: 
1.138     matthew  8811: =item @Values: An array of array references.  Each array reference holds data
                   8812: to be plotted in a stacked bar chart.
                   8813: 
1.239     matthew  8814: =item If the final element of @Values is a hash reference the key/value
                   8815: pairs will be added to the graph definition.
                   8816: 
1.138     matthew  8817: =back
                   8818: 
                   8819: Returns:
                   8820: 
                   8821: An <img> tag which references graph.png and the appropriate identifying
                   8822: information for the plot.
                   8823: 
1.127     matthew  8824: =cut
                   8825: 
                   8826: ############################################################
                   8827: ############################################################
1.134     matthew  8828: sub DrawBarGraph {
1.178     matthew  8829:     my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134     matthew  8830:     #
                   8831:     if (! defined($colors)) {
                   8832:         $colors = ['#33ff00', 
                   8833:                   '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
                   8834:                   '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
                   8835:                   ]; 
                   8836:     }
1.228     matthew  8837:     my $extra_settings = {};
                   8838:     if (ref($Values[-1]) eq 'HASH') {
                   8839:         $extra_settings = pop(@Values);
                   8840:     }
1.127     matthew  8841:     #
1.136     matthew  8842:     my $identifier = &get_cgi_id();
                   8843:     my $id = 'cgi.'.$identifier;        
1.129     matthew  8844:     if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127     matthew  8845:         return '';
                   8846:     }
1.225     matthew  8847:     #
                   8848:     my @Labels;
                   8849:     if (defined($labels)) {
                   8850:         @Labels = @$labels;
                   8851:     } else {
                   8852:         for (my $i=0;$i<@{$Values[0]};$i++) {
                   8853:             push (@Labels,$i+1);
                   8854:         }
                   8855:     }
                   8856:     #
1.129     matthew  8857:     my $NumBars = scalar(@{$Values[0]});
1.225     matthew  8858:     if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129     matthew  8859:     my %ValuesHash;
                   8860:     my $NumSets=1;
                   8861:     foreach my $array (@Values) {
                   8862:         next if (! ref($array));
1.136     matthew  8863:         $ValuesHash{$id.'.data.'.$NumSets++} = 
1.132     matthew  8864:             join(',',@$array);
1.129     matthew  8865:     }
1.127     matthew  8866:     #
1.136     matthew  8867:     my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225     matthew  8868:     if ($NumBars < 3) {
                   8869:         $width = 120+$NumBars*32;
1.220     matthew  8870:         $xskip = 1;
1.225     matthew  8871:         $bar_width = 30;
                   8872:     } elsif ($NumBars < 5) {
                   8873:         $width = 120+$NumBars*20;
                   8874:         $xskip = 1;
                   8875:         $bar_width = 20;
1.220     matthew  8876:     } elsif ($NumBars < 10) {
1.136     matthew  8877:         $width = 120+$NumBars*15;
                   8878:         $xskip = 1;
                   8879:         $bar_width = 15;
                   8880:     } elsif ($NumBars <= 25) {
                   8881:         $width = 120+$NumBars*11;
                   8882:         $xskip = 5;
                   8883:         $bar_width = 8;
                   8884:     } elsif ($NumBars <= 50) {
                   8885:         $width = 120+$NumBars*8;
                   8886:         $xskip = 5;
                   8887:         $bar_width = 4;
                   8888:     } else {
                   8889:         $width = 120+$NumBars*8;
                   8890:         $xskip = 5;
                   8891:         $bar_width = 4;
                   8892:     }
                   8893:     #
1.137     matthew  8894:     $Max = 1 if ($Max < 1);
                   8895:     if ( int($Max) < $Max ) {
                   8896:         $Max++;
                   8897:         $Max = int($Max);
                   8898:     }
1.127     matthew  8899:     $Title  = '' if (! defined($Title));
                   8900:     $xlabel = '' if (! defined($xlabel));
                   8901:     $ylabel = '' if (! defined($ylabel));
1.369     www      8902:     $ValuesHash{$id.'.title'}    = &escape($Title);
                   8903:     $ValuesHash{$id.'.xlabel'}   = &escape($xlabel);
                   8904:     $ValuesHash{$id.'.ylabel'}   = &escape($ylabel);
1.137     matthew  8905:     $ValuesHash{$id.'.y_max_value'} = $Max;
1.136     matthew  8906:     $ValuesHash{$id.'.NumBars'}  = $NumBars;
                   8907:     $ValuesHash{$id.'.NumSets'}  = $NumSets;
                   8908:     $ValuesHash{$id.'.PlotType'} = 'bar';
                   8909:     $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8910:     $ValuesHash{$id.'.height'}   = $height;
                   8911:     $ValuesHash{$id.'.width'}    = $width;
                   8912:     $ValuesHash{$id.'.xskip'}    = $xskip;
                   8913:     $ValuesHash{$id.'.bar_width'} = $bar_width;
                   8914:     $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127     matthew  8915:     #
1.228     matthew  8916:     # Deal with other parameters
                   8917:     while (my ($key,$value) = each(%$extra_settings)) {
                   8918:         $ValuesHash{$id.'.'.$key} = $value;
                   8919:     }
                   8920:     #
1.646     raeburn  8921:     &Apache::lonnet::appenv(\%ValuesHash);
1.137     matthew  8922:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   8923: }
                   8924: 
                   8925: ############################################################
                   8926: ############################################################
                   8927: 
                   8928: =pod
                   8929: 
1.648     raeburn  8930: =item * &DrawXYGraph()
1.137     matthew  8931: 
1.138     matthew  8932: Facilitates the plotting of data in an XY graph.
                   8933: Puts plot definition data into the users environment in order for 
                   8934: graph.png to plot it.  Returns an <img> tag for the plot.
                   8935: 
                   8936: Inputs:
                   8937: 
                   8938: =over 4
                   8939: 
                   8940: =item $Title: string, the title of the plot
                   8941: 
                   8942: =item $xlabel: string, text describing the X-axis of the plot
                   8943: 
                   8944: =item $ylabel: string, text describing the Y-axis of the plot
                   8945: 
                   8946: =item $Max: scalar, the maximum Y value to use in the plot
                   8947: If $Max is < any data point, the graph will not be rendered.
                   8948: 
                   8949: =item $colors: Array ref containing the hex color codes for the data to be 
                   8950: plotted in.  If undefined, default values will be used.
                   8951: 
                   8952: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   8953: 
                   8954: =item $Ydata: Array ref containing Array refs.  
1.185     www      8955: Each of the contained arrays will be plotted as a separate curve.
1.138     matthew  8956: 
                   8957: =item %Values: hash indicating or overriding any default values which are 
                   8958: passed to graph.png.  
                   8959: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   8960: 
                   8961: =back
                   8962: 
                   8963: Returns:
                   8964: 
                   8965: An <img> tag which references graph.png and the appropriate identifying
                   8966: information for the plot.
                   8967: 
1.137     matthew  8968: =cut
                   8969: 
                   8970: ############################################################
                   8971: ############################################################
                   8972: sub DrawXYGraph {
                   8973:     my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
                   8974:     #
                   8975:     # Create the identifier for the graph
                   8976:     my $identifier = &get_cgi_id();
                   8977:     my $id = 'cgi.'.$identifier;
                   8978:     #
                   8979:     $Title  = '' if (! defined($Title));
                   8980:     $xlabel = '' if (! defined($xlabel));
                   8981:     $ylabel = '' if (! defined($ylabel));
                   8982:     my %ValuesHash = 
                   8983:         (
1.369     www      8984:          $id.'.title'  => &escape($Title),
                   8985:          $id.'.xlabel' => &escape($xlabel),
                   8986:          $id.'.ylabel' => &escape($ylabel),
1.137     matthew  8987:          $id.'.y_max_value'=> $Max,
                   8988:          $id.'.labels'     => join(',',@$Xlabels),
                   8989:          $id.'.PlotType'   => 'XY',
                   8990:          );
                   8991:     #
                   8992:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   8993:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8994:     }
                   8995:     #
                   8996:     if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
                   8997:         return '';
                   8998:     }
                   8999:     my $NumSets=1;
1.138     matthew  9000:     foreach my $array (@{$Ydata}){
1.137     matthew  9001:         next if (! ref($array));
                   9002:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
                   9003:     }
1.138     matthew  9004:     $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137     matthew  9005:     #
                   9006:     # Deal with other parameters
                   9007:     while (my ($key,$value) = each(%Values)) {
                   9008:         $ValuesHash{$id.'.'.$key} = $value;
1.127     matthew  9009:     }
                   9010:     #
1.646     raeburn  9011:     &Apache::lonnet::appenv(\%ValuesHash);
1.136     matthew  9012:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   9013: }
                   9014: 
                   9015: ############################################################
                   9016: ############################################################
                   9017: 
                   9018: =pod
                   9019: 
1.648     raeburn  9020: =item * &DrawXYYGraph()
1.138     matthew  9021: 
                   9022: Facilitates the plotting of data in an XY graph with two Y axes.
                   9023: Puts plot definition data into the users environment in order for 
                   9024: graph.png to plot it.  Returns an <img> tag for the plot.
                   9025: 
                   9026: Inputs:
                   9027: 
                   9028: =over 4
                   9029: 
                   9030: =item $Title: string, the title of the plot
                   9031: 
                   9032: =item $xlabel: string, text describing the X-axis of the plot
                   9033: 
                   9034: =item $ylabel: string, text describing the Y-axis of the plot
                   9035: 
                   9036: =item $colors: Array ref containing the hex color codes for the data to be 
                   9037: plotted in.  If undefined, default values will be used.
                   9038: 
                   9039: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   9040: 
                   9041: =item $Ydata1: The first data set
                   9042: 
                   9043: =item $Min1: The minimum value of the left Y-axis
                   9044: 
                   9045: =item $Max1: The maximum value of the left Y-axis
                   9046: 
                   9047: =item $Ydata2: The second data set
                   9048: 
                   9049: =item $Min2: The minimum value of the right Y-axis
                   9050: 
                   9051: =item $Max2: The maximum value of the left Y-axis
                   9052: 
                   9053: =item %Values: hash indicating or overriding any default values which are 
                   9054: passed to graph.png.  
                   9055: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   9056: 
                   9057: =back
                   9058: 
                   9059: Returns:
                   9060: 
                   9061: An <img> tag which references graph.png and the appropriate identifying
                   9062: information for the plot.
1.136     matthew  9063: 
                   9064: =cut
                   9065: 
                   9066: ############################################################
                   9067: ############################################################
1.137     matthew  9068: sub DrawXYYGraph {
                   9069:     my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
                   9070:                                         $Ydata2,$Min2,$Max2,%Values)=@_;
1.136     matthew  9071:     #
                   9072:     # Create the identifier for the graph
                   9073:     my $identifier = &get_cgi_id();
                   9074:     my $id = 'cgi.'.$identifier;
                   9075:     #
                   9076:     $Title  = '' if (! defined($Title));
                   9077:     $xlabel = '' if (! defined($xlabel));
                   9078:     $ylabel = '' if (! defined($ylabel));
                   9079:     my %ValuesHash = 
                   9080:         (
1.369     www      9081:          $id.'.title'  => &escape($Title),
                   9082:          $id.'.xlabel' => &escape($xlabel),
                   9083:          $id.'.ylabel' => &escape($ylabel),
1.136     matthew  9084:          $id.'.labels' => join(',',@$Xlabels),
                   9085:          $id.'.PlotType' => 'XY',
                   9086:          $id.'.NumSets' => 2,
1.137     matthew  9087:          $id.'.two_axes' => 1,
                   9088:          $id.'.y1_max_value' => $Max1,
                   9089:          $id.'.y1_min_value' => $Min1,
                   9090:          $id.'.y2_max_value' => $Max2,
                   9091:          $id.'.y2_min_value' => $Min2,
1.136     matthew  9092:          );
                   9093:     #
1.137     matthew  9094:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   9095:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   9096:     }
                   9097:     #
                   9098:     if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
                   9099:         ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136     matthew  9100:         return '';
                   9101:     }
                   9102:     my $NumSets=1;
1.137     matthew  9103:     foreach my $array ($Ydata1,$Ydata2){
1.136     matthew  9104:         next if (! ref($array));
                   9105:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137     matthew  9106:     }
                   9107:     #
                   9108:     # Deal with other parameters
                   9109:     while (my ($key,$value) = each(%Values)) {
                   9110:         $ValuesHash{$id.'.'.$key} = $value;
1.136     matthew  9111:     }
                   9112:     #
1.646     raeburn  9113:     &Apache::lonnet::appenv(\%ValuesHash);
1.130     albertel 9114:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139     matthew  9115: }
                   9116: 
                   9117: ############################################################
                   9118: ############################################################
                   9119: 
                   9120: =pod
                   9121: 
1.157     matthew  9122: =back 
                   9123: 
1.139     matthew  9124: =head1 Statistics helper routines?  
                   9125: 
                   9126: Bad place for them but what the hell.
                   9127: 
1.157     matthew  9128: =over 4
                   9129: 
1.648     raeburn  9130: =item * &chartlink()
1.139     matthew  9131: 
                   9132: Returns a link to the chart for a specific student.  
                   9133: 
                   9134: Inputs:
                   9135: 
                   9136: =over 4
                   9137: 
                   9138: =item $linktext: The text of the link
                   9139: 
                   9140: =item $sname: The students username
                   9141: 
                   9142: =item $sdomain: The students domain
                   9143: 
                   9144: =back
                   9145: 
1.157     matthew  9146: =back
                   9147: 
1.139     matthew  9148: =cut
                   9149: 
                   9150: ############################################################
                   9151: ############################################################
                   9152: sub chartlink {
                   9153:     my ($linktext, $sname, $sdomain) = @_;
                   9154:     my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369     www      9155:         '&amp;SelectedStudent='.&escape($sname.':'.$sdomain).
1.219     albertel 9156:         '&amp;chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139     matthew  9157:        '">'.$linktext.'</a>';
1.153     matthew  9158: }
                   9159: 
                   9160: #######################################################
                   9161: #######################################################
                   9162: 
                   9163: =pod
                   9164: 
                   9165: =head1 Course Environment Routines
1.157     matthew  9166: 
                   9167: =over 4
1.153     matthew  9168: 
1.648     raeburn  9169: =item * &restore_course_settings()
1.153     matthew  9170: 
1.648     raeburn  9171: =item * &store_course_settings()
1.153     matthew  9172: 
                   9173: Restores/Store indicated form parameters from the course environment.
                   9174: Will not overwrite existing values of the form parameters.
                   9175: 
                   9176: Inputs: 
                   9177: a scalar describing the data (e.g. 'chart', 'problem_analysis')
                   9178: 
                   9179: a hash ref describing the data to be stored.  For example:
                   9180:    
                   9181: %Save_Parameters = ('Status' => 'scalar',
                   9182:     'chartoutputmode' => 'scalar',
                   9183:     'chartoutputdata' => 'scalar',
                   9184:     'Section' => 'array',
1.373     raeburn  9185:     'Group' => 'array',
1.153     matthew  9186:     'StudentData' => 'array',
                   9187:     'Maps' => 'array');
                   9188: 
                   9189: Returns: both routines return nothing
                   9190: 
1.631     raeburn  9191: =back
                   9192: 
1.153     matthew  9193: =cut
                   9194: 
                   9195: #######################################################
                   9196: #######################################################
                   9197: sub store_course_settings {
1.496     albertel 9198:     return &store_settings($env{'request.course.id'},@_);
                   9199: }
                   9200: 
                   9201: sub store_settings {
1.153     matthew  9202:     # save to the environment
                   9203:     # appenv the same items, just to be safe
1.300     albertel 9204:     my $udom  = $env{'user.domain'};
                   9205:     my $uname = $env{'user.name'};
1.496     albertel 9206:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  9207:     my %SaveHash;
                   9208:     my %AppHash;
                   9209:     while (my ($setting,$type) = each(%$Settings)) {
1.496     albertel 9210:         my $basename = join('.','internal',$context,$prefix,$setting);
1.300     albertel 9211:         my $envname = 'environment.'.$basename;
1.258     albertel 9212:         if (exists($env{'form.'.$setting})) {
1.153     matthew  9213:             # Save this value away
                   9214:             if ($type eq 'scalar' &&
1.258     albertel 9215:                 (! exists($env{$envname}) || 
                   9216:                  $env{$envname} ne $env{'form.'.$setting})) {
                   9217:                 $SaveHash{$basename} = $env{'form.'.$setting};
                   9218:                 $AppHash{$envname}   = $env{'form.'.$setting};
1.153     matthew  9219:             } elsif ($type eq 'array') {
                   9220:                 my $stored_form;
1.258     albertel 9221:                 if (ref($env{'form.'.$setting})) {
1.153     matthew  9222:                     $stored_form = join(',',
                   9223:                                         map {
1.369     www      9224:                                             &escape($_);
1.258     albertel 9225:                                         } sort(@{$env{'form.'.$setting}}));
1.153     matthew  9226:                 } else {
                   9227:                     $stored_form = 
1.369     www      9228:                         &escape($env{'form.'.$setting});
1.153     matthew  9229:                 }
                   9230:                 # Determine if the array contents are the same.
1.258     albertel 9231:                 if ($stored_form ne $env{$envname}) {
1.153     matthew  9232:                     $SaveHash{$basename} = $stored_form;
                   9233:                     $AppHash{$envname}   = $stored_form;
                   9234:                 }
                   9235:             }
                   9236:         }
                   9237:     }
                   9238:     my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300     albertel 9239:                                           $udom,$uname);
1.153     matthew  9240:     if ($put_result !~ /^(ok|delayed)/) {
                   9241:         &Apache::lonnet::logthis('unable to save form parameters, '.
                   9242:                                  'got error:'.$put_result);
                   9243:     }
                   9244:     # Make sure these settings stick around in this session, too
1.646     raeburn  9245:     &Apache::lonnet::appenv(\%AppHash);
1.153     matthew  9246:     return;
                   9247: }
                   9248: 
                   9249: sub restore_course_settings {
1.499     albertel 9250:     return &restore_settings($env{'request.course.id'},@_);
1.496     albertel 9251: }
                   9252: 
                   9253: sub restore_settings {
                   9254:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  9255:     while (my ($setting,$type) = each(%$Settings)) {
1.258     albertel 9256:         next if (exists($env{'form.'.$setting}));
1.496     albertel 9257:         my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153     matthew  9258:             '.'.$setting;
1.258     albertel 9259:         if (exists($env{$envname})) {
1.153     matthew  9260:             if ($type eq 'scalar') {
1.258     albertel 9261:                 $env{'form.'.$setting} = $env{$envname};
1.153     matthew  9262:             } elsif ($type eq 'array') {
1.258     albertel 9263:                 $env{'form.'.$setting} = [ 
1.153     matthew  9264:                                            map { 
1.369     www      9265:                                                &unescape($_); 
1.258     albertel 9266:                                            } split(',',$env{$envname})
1.153     matthew  9267:                                            ];
                   9268:             }
                   9269:         }
                   9270:     }
1.127     matthew  9271: }
                   9272: 
1.618     raeburn  9273: #######################################################
                   9274: #######################################################
                   9275: 
                   9276: =pod
                   9277: 
                   9278: =head1 Domain E-mail Routines  
                   9279: 
                   9280: =over 4
                   9281: 
1.648     raeburn  9282: =item * &build_recipient_list()
1.618     raeburn  9283: 
1.766     raeburn  9284: Build recipient lists for four types of e-mail:
                   9285: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
                   9286: (d) Help requests, generated by
                   9287: lonerrorhandler.pm, CHECKRPMS, loncron, and lonsupportreq.pm respectively.
1.618     raeburn  9288: 
                   9289: Inputs:
1.619     raeburn  9290: defmail (scalar - email address of default recipient), 
1.618     raeburn  9291: mailing type (scalar - errormail, packagesmail, or helpdeskmail), 
1.619     raeburn  9292: defdom (domain for which to retrieve configuration settings),
                   9293: origmail (scalar - email address of recipient from loncapa.conf, 
                   9294: i.e., predates configuration by DC via domainprefs.pm 
1.618     raeburn  9295: 
1.655     raeburn  9296: Returns: comma separated list of addresses to which to send e-mail.
                   9297: 
                   9298: =back
1.618     raeburn  9299: 
                   9300: =cut
                   9301: 
                   9302: ############################################################
                   9303: ############################################################
                   9304: sub build_recipient_list {
1.619     raeburn  9305:     my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618     raeburn  9306:     my @recipients;
                   9307:     my $otheremails;
                   9308:     my %domconfig =
                   9309:          &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
                   9310:     if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766     raeburn  9311:         if (exists($domconfig{'contacts'}{$mailing})) {
                   9312:             if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
                   9313:                 my @contacts = ('adminemail','supportemail');
                   9314:                 foreach my $item (@contacts) {
                   9315:                     if ($domconfig{'contacts'}{$mailing}{$item}) {
                   9316:                         my $addr = $domconfig{'contacts'}{$item}; 
                   9317:                         if (!grep(/^\Q$addr\E$/,@recipients)) {
                   9318:                             push(@recipients,$addr);
                   9319:                         }
1.619     raeburn  9320:                     }
1.766     raeburn  9321:                     $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618     raeburn  9322:                 }
                   9323:             }
1.766     raeburn  9324:         } elsif ($origmail ne '') {
                   9325:             push(@recipients,$origmail);
1.618     raeburn  9326:         }
1.619     raeburn  9327:     } elsif ($origmail ne '') {
                   9328:         push(@recipients,$origmail);
1.618     raeburn  9329:     }
1.688     raeburn  9330:     if (defined($defmail)) {
                   9331:         if ($defmail ne '') {
                   9332:             push(@recipients,$defmail);
                   9333:         }
1.618     raeburn  9334:     }
                   9335:     if ($otheremails) {
1.619     raeburn  9336:         my @others;
                   9337:         if ($otheremails =~ /,/) {
                   9338:             @others = split(/,/,$otheremails);
1.618     raeburn  9339:         } else {
1.619     raeburn  9340:             push(@others,$otheremails);
                   9341:         }
                   9342:         foreach my $addr (@others) {
                   9343:             if (!grep(/^\Q$addr\E$/,@recipients)) {
                   9344:                 push(@recipients,$addr);
                   9345:             }
1.618     raeburn  9346:         }
                   9347:     }
1.619     raeburn  9348:     my $recipientlist = join(',',@recipients); 
1.618     raeburn  9349:     return $recipientlist;
                   9350: }
                   9351: 
1.127     matthew  9352: ############################################################
                   9353: ############################################################
1.154     albertel 9354: 
1.655     raeburn  9355: =pod
                   9356: 
                   9357: =head1 Course Catalog Routines
                   9358: 
                   9359: =over 4
                   9360: 
                   9361: =item * &gather_categories()
                   9362: 
                   9363: Converts category definitions - keys of categories hash stored in  
                   9364: coursecategories in configuration.db on the primary library server in a 
                   9365: domain - to an array.  Also generates javascript and idx hash used to 
                   9366: generate Domain Coordinator interface for editing Course Categories.
                   9367: 
                   9368: Inputs:
1.663     raeburn  9369: 
1.655     raeburn  9370: categories (reference to hash of category definitions).
1.663     raeburn  9371: 
1.655     raeburn  9372: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9373:       categories and subcategories).
1.663     raeburn  9374: 
1.655     raeburn  9375: idx (reference to hash of counters used in Domain Coordinator interface for 
                   9376:       editing Course Categories).
1.663     raeburn  9377: 
1.655     raeburn  9378: jsarray (reference to array of categories used to create Javascript arrays for
                   9379:          Domain Coordinator interface for editing Course Categories).
                   9380: 
                   9381: Returns: nothing
                   9382: 
                   9383: Side effects: populates cats, idx and jsarray. 
                   9384: 
                   9385: =cut
                   9386: 
                   9387: sub gather_categories {
                   9388:     my ($categories,$cats,$idx,$jsarray) = @_;
                   9389:     my %counters;
                   9390:     my $num = 0;
                   9391:     foreach my $item (keys(%{$categories})) {
                   9392:         my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   9393:         if ($container eq '' && $depth == 0) {
                   9394:             $cats->[$depth][$categories->{$item}] = $cat;
                   9395:         } else {
                   9396:             $cats->[$depth]{$container}[$categories->{$item}] = $cat;
                   9397:         }
                   9398:         my ($escitem,$tail) = split(/:/,$item,2);
                   9399:         if ($counters{$tail} eq '') {
                   9400:             $counters{$tail} = $num;
                   9401:             $num ++;
                   9402:         }
                   9403:         if (ref($idx) eq 'HASH') {
                   9404:             $idx->{$item} = $counters{$tail};
                   9405:         }
                   9406:         if (ref($jsarray) eq 'ARRAY') {
                   9407:             push(@{$jsarray->[$counters{$tail}]},$item);
                   9408:         }
                   9409:     }
                   9410:     return;
                   9411: }
                   9412: 
                   9413: =pod
                   9414: 
                   9415: =item * &extract_categories()
                   9416: 
                   9417: Used to generate breadcrumb trails for course categories.
                   9418: 
                   9419: Inputs:
1.663     raeburn  9420: 
1.655     raeburn  9421: categories (reference to hash of category definitions).
1.663     raeburn  9422: 
1.655     raeburn  9423: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9424:       categories and subcategories).
1.663     raeburn  9425: 
1.655     raeburn  9426: trails (reference to array of breacrumb trails for each category).
1.663     raeburn  9427: 
1.655     raeburn  9428: allitems (reference to hash - key is category key 
                   9429:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  9430: 
1.655     raeburn  9431: idx (reference to hash of counters used in Domain Coordinator interface for
                   9432:       editing Course Categories).
1.663     raeburn  9433: 
1.655     raeburn  9434: jsarray (reference to array of categories used to create Javascript arrays for
                   9435:          Domain Coordinator interface for editing Course Categories).
                   9436: 
1.665     raeburn  9437: subcats (reference to hash of arrays containing all subcategories within each 
                   9438:          category, -recursive)
                   9439: 
1.655     raeburn  9440: Returns: nothing
                   9441: 
                   9442: Side effects: populates trails and allitems hash references.
                   9443: 
                   9444: =cut
                   9445: 
                   9446: sub extract_categories {
1.665     raeburn  9447:     my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655     raeburn  9448:     if (ref($categories) eq 'HASH') {
                   9449:         &gather_categories($categories,$cats,$idx,$jsarray);
                   9450:         if (ref($cats->[0]) eq 'ARRAY') {
                   9451:             for (my $i=0; $i<@{$cats->[0]}; $i++) {
                   9452:                 my $name = $cats->[0][$i];
                   9453:                 my $item = &escape($name).'::0';
                   9454:                 my $trailstr;
                   9455:                 if ($name eq 'instcode') {
                   9456:                     $trailstr = &mt('Official courses (with institutional codes)');
                   9457:                 } else {
                   9458:                     $trailstr = $name;
                   9459:                 }
                   9460:                 if ($allitems->{$item} eq '') {
                   9461:                     push(@{$trails},$trailstr);
                   9462:                     $allitems->{$item} = scalar(@{$trails})-1;
                   9463:                 }
                   9464:                 my @parents = ($name);
                   9465:                 if (ref($cats->[1]{$name}) eq 'ARRAY') {
                   9466:                     for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
                   9467:                         my $category = $cats->[1]{$name}[$j];
1.665     raeburn  9468:                         if (ref($subcats) eq 'HASH') {
                   9469:                             push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
                   9470:                         }
                   9471:                         &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
                   9472:                     }
                   9473:                 } else {
                   9474:                     if (ref($subcats) eq 'HASH') {
                   9475:                         $subcats->{$item} = [];
1.655     raeburn  9476:                     }
                   9477:                 }
                   9478:             }
                   9479:         }
                   9480:     }
                   9481:     return;
                   9482: }
                   9483: 
                   9484: =pod
                   9485: 
                   9486: =item *&recurse_categories()
                   9487: 
                   9488: Recursively used to generate breadcrumb trails for course categories.
                   9489: 
                   9490: Inputs:
1.663     raeburn  9491: 
1.655     raeburn  9492: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9493:       categories and subcategories).
1.663     raeburn  9494: 
1.655     raeburn  9495: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663     raeburn  9496: 
                   9497: category (current course category, for which breadcrumb trail is being generated).
                   9498: 
                   9499: trails (reference to array of breadcrumb trails for each category).
                   9500: 
1.655     raeburn  9501: allitems (reference to hash - key is category key
                   9502:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  9503: 
1.655     raeburn  9504: parents (array containing containers directories for current category, 
                   9505:          back to top level). 
                   9506: 
                   9507: Returns: nothing
                   9508: 
                   9509: Side effects: populates trails and allitems hash references
                   9510: 
                   9511: =cut
                   9512: 
                   9513: sub recurse_categories {
1.665     raeburn  9514:     my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655     raeburn  9515:     my $shallower = $depth - 1;
                   9516:     if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
                   9517:         for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
                   9518:             my $name = $cats->[$depth]{$category}[$k];
                   9519:             my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   9520:             my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   9521:             if ($allitems->{$item} eq '') {
                   9522:                 push(@{$trails},$trailstr);
                   9523:                 $allitems->{$item} = scalar(@{$trails})-1;
                   9524:             }
                   9525:             my $deeper = $depth+1;
                   9526:             push(@{$parents},$category);
1.665     raeburn  9527:             if (ref($subcats) eq 'HASH') {
                   9528:                 my $subcat = &escape($name).':'.$category.':'.$depth;
                   9529:                 for (my $j=@{$parents}; $j>=0; $j--) {
                   9530:                     my $higher;
                   9531:                     if ($j > 0) {
                   9532:                         $higher = &escape($parents->[$j]).':'.
                   9533:                                   &escape($parents->[$j-1]).':'.$j;
                   9534:                     } else {
                   9535:                         $higher = &escape($parents->[$j]).'::'.$j;
                   9536:                     }
                   9537:                     push(@{$subcats->{$higher}},$subcat);
                   9538:                 }
                   9539:             }
                   9540:             &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
                   9541:                                 $subcats);
1.655     raeburn  9542:             pop(@{$parents});
                   9543:         }
                   9544:     } else {
                   9545:         my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   9546:         my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   9547:         if ($allitems->{$item} eq '') {
                   9548:             push(@{$trails},$trailstr);
                   9549:             $allitems->{$item} = scalar(@{$trails})-1;
                   9550:         }
                   9551:     }
                   9552:     return;
                   9553: }
                   9554: 
1.663     raeburn  9555: =pod
                   9556: 
                   9557: =item *&assign_categories_table()
                   9558: 
                   9559: Create a datatable for display of hierarchical categories in a domain,
                   9560: with checkboxes to allow a course to be categorized. 
                   9561: 
                   9562: Inputs:
                   9563: 
                   9564: cathash - reference to hash of categories defined for the domain (from
                   9565:           configuration.db)
                   9566: 
                   9567: currcat - scalar with an & separated list of categories assigned to a course. 
                   9568: 
                   9569: Returns: $output (markup to be displayed) 
                   9570: 
                   9571: =cut
                   9572: 
                   9573: sub assign_categories_table {
                   9574:     my ($cathash,$currcat) = @_;
                   9575:     my $output;
                   9576:     if (ref($cathash) eq 'HASH') {
                   9577:         my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
                   9578:         &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
                   9579:         $maxdepth = scalar(@cats);
                   9580:         if (@cats > 0) {
                   9581:             my $itemcount = 0;
                   9582:             if (ref($cats[0]) eq 'ARRAY') {
                   9583:                 $output = &Apache::loncommon::start_data_table();
                   9584:                 my @currcategories;
                   9585:                 if ($currcat ne '') {
                   9586:                     @currcategories = split('&',$currcat);
                   9587:                 }
                   9588:                 for (my $i=0; $i<@{$cats[0]}; $i++) {
                   9589:                     my $parent = $cats[0][$i];
                   9590:                     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9591:                     next if ($parent eq 'instcode');
                   9592:                     my $item = &escape($parent).'::0';
                   9593:                     my $checked = '';
                   9594:                     if (@currcategories > 0) {
                   9595:                         if (grep(/^\Q$item\E$/,@currcategories)) {
1.772     bisitz   9596:                             $checked = ' checked="checked"';
1.663     raeburn  9597:                         }
                   9598:                     }
1.675     raeburn  9599:                     $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
                   9600:                                '<input type="checkbox" name="usecategory" value="'.
                   9601:                                $item.'"'.$checked.' />'.$parent.'</span>'.
                   9602:                                '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663     raeburn  9603:                     my $depth = 1;
                   9604:                     push(@path,$parent);
                   9605:                     $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
                   9606:                     pop(@path);
                   9607:                     $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   9608:                     $itemcount ++;
                   9609:                 }
                   9610:                 $output .= &Apache::loncommon::end_data_table();
                   9611:             }
                   9612:         }
                   9613:     }
                   9614:     return $output;
                   9615: }
                   9616: 
                   9617: =pod
                   9618: 
                   9619: =item *&assign_category_rows()
                   9620: 
                   9621: Create a datatable row for display of nested categories in a domain,
                   9622: with checkboxes to allow a course to be categorized,called recursively.
                   9623: 
                   9624: Inputs:
                   9625: 
                   9626: itemcount - track row number for alternating colors
                   9627: 
                   9628: cats - reference to array of arrays/hashes which encapsulates hierarchy of
                   9629:       categories and subcategories.
                   9630: 
                   9631: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
                   9632: 
                   9633: parent - parent of current category item
                   9634: 
                   9635: path - Array containing all categories back up through the hierarchy from the
                   9636:        current category to the top level.
                   9637: 
                   9638: currcategories - reference to array of current categories assigned to the course
                   9639: 
                   9640: Returns: $output (markup to be displayed).
                   9641: 
                   9642: =cut
                   9643: 
                   9644: sub assign_category_rows {
                   9645:     my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
                   9646:     my ($text,$name,$item,$chgstr);
                   9647:     if (ref($cats) eq 'ARRAY') {
                   9648:         my $maxdepth = scalar(@{$cats});
                   9649:         if (ref($cats->[$depth]) eq 'HASH') {
                   9650:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   9651:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   9652:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9653:                 $text .= '<td><table class="LC_datatable">';
                   9654:                 for (my $j=0; $j<$numchildren; $j++) {
                   9655:                     $name = $cats->[$depth]{$parent}[$j];
                   9656:                     $item = &escape($name).':'.&escape($parent).':'.$depth;
                   9657:                     my $deeper = $depth+1;
                   9658:                     my $checked = '';
                   9659:                     if (ref($currcategories) eq 'ARRAY') {
                   9660:                         if (@{$currcategories} > 0) {
                   9661:                             if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772     bisitz   9662:                                 $checked = ' checked="checked"';
1.663     raeburn  9663:                             }
                   9664:                         }
                   9665:                     }
1.664     raeburn  9666:                     $text .= '<tr><td><span class="LC_nobreak"><label>'.
                   9667:                              '<input type="checkbox" name="usecategory" value="'.
1.675     raeburn  9668:                              $item.'"'.$checked.' />'.$name.'</label></span>'.
                   9669:                              '<input type="hidden" name="catname" value="'.$name.'" />'.
                   9670:                              '</td><td>';
1.663     raeburn  9671:                     if (ref($path) eq 'ARRAY') {
                   9672:                         push(@{$path},$name);
                   9673:                         $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
                   9674:                         pop(@{$path});
                   9675:                     }
                   9676:                     $text .= '</td></tr>';
                   9677:                 }
                   9678:                 $text .= '</table></td>';
                   9679:             }
                   9680:         }
                   9681:     }
                   9682:     return $text;
                   9683: }
                   9684: 
1.655     raeburn  9685: ############################################################
                   9686: ############################################################
                   9687: 
                   9688: 
1.443     albertel 9689: sub commit_customrole {
1.664     raeburn  9690:     my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630     raeburn  9691:     my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443     albertel 9692:                          ($start?', '.&mt('starting').' '.localtime($start):'').
                   9693:                          ($end?', ending '.localtime($end):'').': <b>'.
                   9694:               &Apache::lonnet::assigncustomrole(
1.664     raeburn  9695:                  $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443     albertel 9696:                  '</b><br />';
                   9697:     return $output;
                   9698: }
                   9699: 
                   9700: sub commit_standardrole {
1.541     raeburn  9701:     my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
                   9702:     my ($output,$logmsg,$linefeed);
                   9703:     if ($context eq 'auto') {
                   9704:         $linefeed = "\n";
                   9705:     } else {
                   9706:         $linefeed = "<br />\n";
                   9707:     }  
1.443     albertel 9708:     if ($three eq 'st') {
1.541     raeburn  9709:         my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
                   9710:                                          $one,$two,$sec,$context);
                   9711:         if (($result =~ /^error/) || ($result eq 'not_in_class') || 
1.626     raeburn  9712:             ($result eq 'unknown_course') || ($result eq 'refused')) {
                   9713:             $output = $logmsg.' '.&mt('Error: ').$result."\n"; 
1.443     albertel 9714:         } else {
1.541     raeburn  9715:             $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443     albertel 9716:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  9717:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
                   9718:             if ($context eq 'auto') {
                   9719:                 $output .= $result.$linefeed.&mt('Add to classlist').': ok';
                   9720:             } else {
                   9721:                $output .= '<b>'.$result.'</b>'.$linefeed.
                   9722:                &mt('Add to classlist').': <b>ok</b>';
                   9723:             }
                   9724:             $output .= $linefeed;
1.443     albertel 9725:         }
                   9726:     } else {
                   9727:         $output = &mt('Assigning').' '.$three.' in '.$url.
                   9728:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  9729:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652     raeburn  9730:         my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541     raeburn  9731:         if ($context eq 'auto') {
                   9732:             $output .= $result.$linefeed;
                   9733:         } else {
                   9734:             $output .= '<b>'.$result.'</b>'.$linefeed;
                   9735:         }
1.443     albertel 9736:     }
                   9737:     return $output;
                   9738: }
                   9739: 
                   9740: sub commit_studentrole {
1.541     raeburn  9741:     my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626     raeburn  9742:     my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541     raeburn  9743:     if ($context eq 'auto') {
                   9744:         $linefeed = "\n";
                   9745:     } else {
                   9746:         $linefeed = '<br />'."\n";
                   9747:     }
1.443     albertel 9748:     if (defined($one) && defined($two)) {
                   9749:         my $cid=$one.'_'.$two;
                   9750:         my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
                   9751:         my $secchange = 0;
                   9752:         my $expire_role_result;
                   9753:         my $modify_section_result;
1.628     raeburn  9754:         if ($oldsec ne '-1') { 
                   9755:             if ($oldsec ne $sec) {
1.443     albertel 9756:                 $secchange = 1;
1.628     raeburn  9757:                 my $now = time;
1.443     albertel 9758:                 my $uurl='/'.$cid;
                   9759:                 $uurl=~s/\_/\//g;
                   9760:                 if ($oldsec) {
                   9761:                     $uurl.='/'.$oldsec;
                   9762:                 }
1.626     raeburn  9763:                 $oldsecurl = $uurl;
1.628     raeburn  9764:                 $expire_role_result = 
1.652     raeburn  9765:                     &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628     raeburn  9766:                 if ($env{'request.course.sec'} ne '') { 
                   9767:                     if ($expire_role_result eq 'refused') {
                   9768:                         my @roles = ('st');
                   9769:                         my @statuses = ('previous');
                   9770:                         my @roledoms = ($one);
                   9771:                         my $withsec = 1;
                   9772:                         my %roleshash = 
                   9773:                             &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
                   9774:                                               \@statuses,\@roles,\@roledoms,$withsec);
                   9775:                         if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
                   9776:                             my ($oldstart,$oldend) = 
                   9777:                                 split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
                   9778:                             if ($oldend > 0 && $oldend <= $now) {
                   9779:                                 $expire_role_result = 'ok';
                   9780:                             }
                   9781:                         }
                   9782:                     }
                   9783:                 }
1.443     albertel 9784:                 $result = $expire_role_result;
                   9785:             }
                   9786:         }
                   9787:         if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652     raeburn  9788:             $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443     albertel 9789:             if ($modify_section_result =~ /^ok/) {
                   9790:                 if ($secchange == 1) {
1.628     raeburn  9791:                     if ($sec eq '') {
                   9792:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
                   9793:                     } else {
                   9794:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
                   9795:                     }
1.443     albertel 9796:                 } elsif ($oldsec eq '-1') {
1.628     raeburn  9797:                     if ($sec eq '') {
                   9798:                         $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
                   9799:                     } else {
                   9800:                         $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   9801:                     }
1.443     albertel 9802:                 } else {
1.628     raeburn  9803:                     if ($sec eq '') {
                   9804:                         $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
                   9805:                     } else {
                   9806:                         $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   9807:                     }
1.443     albertel 9808:                 }
                   9809:             } else {
1.628     raeburn  9810:                 if ($secchange) {       
                   9811:                     $$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;
                   9812:                 } else {
                   9813:                     $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
                   9814:                 }
1.443     albertel 9815:             }
                   9816:             $result = $modify_section_result;
                   9817:         } elsif ($secchange == 1) {
1.628     raeburn  9818:             if ($oldsec eq '') {
                   9819:                 $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
                   9820:             } else {
                   9821:                 $$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;
                   9822:             }
1.626     raeburn  9823:             if ($expire_role_result eq 'refused') {
                   9824:                 my $newsecurl = '/'.$cid;
                   9825:                 $newsecurl =~ s/\_/\//g;
                   9826:                 if ($sec ne '') {
                   9827:                     $newsecurl.='/'.$sec;
                   9828:                 }
                   9829:                 if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
                   9830:                     if ($sec eq '') {
                   9831:                         $$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;
                   9832:                     } else {
                   9833:                         $$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;
                   9834:                     }
                   9835:                 }
                   9836:             }
1.443     albertel 9837:         }
                   9838:     } else {
1.626     raeburn  9839:         $$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 9840:         $result = "error: incomplete course id\n";
                   9841:     }
                   9842:     return $result;
                   9843: }
                   9844: 
                   9845: ############################################################
                   9846: ############################################################
                   9847: 
1.566     albertel 9848: sub check_clone {
1.578     raeburn  9849:     my ($args,$linefeed) = @_;
1.566     albertel 9850:     my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
                   9851:     my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
                   9852:     my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
                   9853:     my $clonemsg;
                   9854:     my $can_clone = 0;
                   9855: 
                   9856:     if ($clonehome eq 'no_host') {
1.578     raeburn  9857:         $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 9858:     } else {
                   9859: 	my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568     albertel 9860: 	if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566     albertel 9861: 	    $can_clone = 1;
                   9862: 	} else {
                   9863: 	    my %clonehash = &Apache::lonnet::get('environment',['cloners'],
                   9864: 						 $args->{'clonedomain'},$args->{'clonecourse'});
                   9865: 	    my @cloners = split(/,/,$clonehash{'cloners'});
1.578     raeburn  9866:             if (grep(/^\*$/,@cloners)) {
                   9867:                 $can_clone = 1;
                   9868:             } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
                   9869:                 $can_clone = 1;
                   9870:             } else {
                   9871: 	        my %roleshash =
                   9872: 		    &Apache::lonnet::get_my_roles($args->{'ccuname'},
                   9873: 					 $args->{'ccdomain'},
                   9874:                                          'userroles',['active'],['cc'],
                   9875: 					 [$args->{'clonedomain'}]);
                   9876: 	        if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
                   9877: 		    $can_clone = 1;
                   9878: 	        } else {
                   9879:                     $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'});
                   9880: 	        }
1.566     albertel 9881: 	    }
1.578     raeburn  9882:         }
1.566     albertel 9883:     }
                   9884:     return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   9885: }
                   9886: 
1.444     albertel 9887: sub construct_course {
1.541     raeburn  9888:     my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444     albertel 9889:     my $outcome;
1.541     raeburn  9890:     my $linefeed =  '<br />'."\n";
                   9891:     if ($context eq 'auto') {
                   9892:         $linefeed = "\n";
                   9893:     }
1.566     albertel 9894: 
                   9895: #
                   9896: # Are we cloning?
                   9897: #
                   9898:     my ($can_clone, $clonemsg, $cloneid, $clonehome);
                   9899:     if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578     raeburn  9900: 	($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566     albertel 9901: 	if ($context ne 'auto') {
1.578     raeburn  9902:             if ($clonemsg ne '') {
                   9903: 	        $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
                   9904:             }
1.566     albertel 9905: 	}
                   9906: 	$outcome .= $clonemsg.$linefeed;
                   9907: 
                   9908:         if (!$can_clone) {
                   9909: 	    return (0,$outcome);
                   9910: 	}
                   9911:     }
                   9912: 
1.444     albertel 9913: #
                   9914: # Open course
                   9915: #
                   9916:     my $crstype = lc($args->{'crstype'});
                   9917:     my %cenv=();
                   9918:     $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
                   9919:                                              $args->{'cdescr'},
                   9920:                                              $args->{'curl'},
                   9921:                                              $args->{'course_home'},
                   9922:                                              $args->{'nonstandard'},
                   9923:                                              $args->{'crscode'},
                   9924:                                              $args->{'ccuname'}.':'.
                   9925:                                              $args->{'ccdomain'},
                   9926:                                              $args->{'crstype'});
                   9927: 
                   9928:     # Note: The testing routines depend on this being output; see 
                   9929:     # Utils::Course. This needs to at least be output as a comment
                   9930:     # if anyone ever decides to not show this, and Utils::Course::new
                   9931:     # will need to be suitably modified.
1.541     raeburn  9932:     $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444     albertel 9933: #
                   9934: # Check if created correctly
                   9935: #
1.479     albertel 9936:     ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444     albertel 9937:     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541     raeburn  9938:     $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566     albertel 9939: 
1.444     albertel 9940: #
1.566     albertel 9941: # Do the cloning
                   9942: #   
                   9943:     if ($can_clone && $cloneid) {
                   9944: 	$clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
                   9945: 	if ($context ne 'auto') {
                   9946: 	    $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
                   9947: 	}
                   9948: 	$outcome .= $clonemsg.$linefeed;
                   9949: 	my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444     albertel 9950: # Copy all files
1.637     www      9951: 	&Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444     albertel 9952: # Restore URL
1.566     albertel 9953: 	$cenv{'url'}=$oldcenv{'url'};
1.444     albertel 9954: # Restore title
1.566     albertel 9955: 	$cenv{'description'}=$oldcenv{'description'};
1.444     albertel 9956: # Mark as cloned
1.566     albertel 9957: 	$cenv{'clonedfrom'}=$cloneid;
1.638     www      9958: # Need to clone grading mode
                   9959:         my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
                   9960:         $cenv{'grading'}=$newenv{'grading'};
                   9961: # Do not clone these environment entries
                   9962:         &Apache::lonnet::del('environment',
                   9963:                   ['default_enrollment_start_date',
                   9964:                    'default_enrollment_end_date',
                   9965:                    'question.email',
                   9966:                    'policy.email',
                   9967:                    'comment.email',
                   9968:                    'pch.users.denied',
1.725     raeburn  9969:                    'plc.users.denied',
                   9970:                    'hidefromcat',
                   9971:                    'categories'],
1.638     www      9972:                    $$crsudom,$$crsunum);
1.444     albertel 9973:     }
1.566     albertel 9974: 
1.444     albertel 9975: #
                   9976: # Set environment (will override cloned, if existing)
                   9977: #
                   9978:     my @sections = ();
                   9979:     my @xlists = ();
                   9980:     if ($args->{'crstype'}) {
                   9981:         $cenv{'type'}=$args->{'crstype'};
                   9982:     }
                   9983:     if ($args->{'crsid'}) {
                   9984:         $cenv{'courseid'}=$args->{'crsid'};
                   9985:     }
                   9986:     if ($args->{'crscode'}) {
                   9987:         $cenv{'internal.coursecode'}=$args->{'crscode'};
                   9988:     }
                   9989:     if ($args->{'crsquota'} ne '') {
                   9990:         $cenv{'internal.coursequota'}=$args->{'crsquota'};
                   9991:     } else {
                   9992:         $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
                   9993:     }
                   9994:     if ($args->{'ccuname'}) {
                   9995:         $cenv{'internal.courseowner'} = $args->{'ccuname'}.
                   9996:                                         ':'.$args->{'ccdomain'};
                   9997:     } else {
                   9998:         $cenv{'internal.courseowner'} = $args->{'curruser'};
                   9999:     }
                   10000:     my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
                   10001:     if ($args->{'crssections'}) {
                   10002:         $cenv{'internal.sectionnums'} = '';
                   10003:         if ($args->{'crssections'} =~ m/,/) {
                   10004:             @sections = split/,/,$args->{'crssections'};
                   10005:         } else {
                   10006:             $sections[0] = $args->{'crssections'};
                   10007:         }
                   10008:         if (@sections > 0) {
                   10009:             foreach my $item (@sections) {
                   10010:                 my ($sec,$gp) = split/:/,$item;
                   10011:                 my $class = $args->{'crscode'}.$sec;
                   10012:                 my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
                   10013:                 $cenv{'internal.sectionnums'} .= $item.',';
                   10014:                 unless ($addcheck eq 'ok') {
                   10015:                     push @badclasses, $class;
                   10016:                 }
                   10017:             }
                   10018:             $cenv{'internal.sectionnums'} =~ s/,$//;
                   10019:         }
                   10020:     }
                   10021: # do not hide course coordinator from staff listing, 
                   10022: # even if privileged
                   10023:     $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   10024: # add crosslistings
                   10025:     if ($args->{'crsxlist'}) {
                   10026:         $cenv{'internal.crosslistings'}='';
                   10027:         if ($args->{'crsxlist'} =~ m/,/) {
                   10028:             @xlists = split/,/,$args->{'crsxlist'};
                   10029:         } else {
                   10030:             $xlists[0] = $args->{'crsxlist'};
                   10031:         }
                   10032:         if (@xlists > 0) {
                   10033:             foreach my $item (@xlists) {
                   10034:                 my ($xl,$gp) = split/:/,$item;
                   10035:                 my $addcheck =  &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
                   10036:                 $cenv{'internal.crosslistings'} .= $item.',';
                   10037:                 unless ($addcheck eq 'ok') {
                   10038:                     push @badclasses, $xl;
                   10039:                 }
                   10040:             }
                   10041:             $cenv{'internal.crosslistings'} =~ s/,$//;
                   10042:         }
                   10043:     }
                   10044:     if ($args->{'autoadds'}) {
                   10045:         $cenv{'internal.autoadds'}=$args->{'autoadds'};
                   10046:     }
                   10047:     if ($args->{'autodrops'}) {
                   10048:         $cenv{'internal.autodrops'}=$args->{'autodrops'};
                   10049:     }
                   10050: # check for notification of enrollment changes
                   10051:     my @notified = ();
                   10052:     if ($args->{'notify_owner'}) {
                   10053:         if ($args->{'ccuname'} ne '') {
                   10054:             push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
                   10055:         }
                   10056:     }
                   10057:     if ($args->{'notify_dc'}) {
                   10058:         if ($uname ne '') { 
1.630     raeburn  10059:             push(@notified,$uname.':'.$udom);
1.444     albertel 10060:         }
                   10061:     }
                   10062:     if (@notified > 0) {
                   10063:         my $notifylist;
                   10064:         if (@notified > 1) {
                   10065:             $notifylist = join(',',@notified);
                   10066:         } else {
                   10067:             $notifylist = $notified[0];
                   10068:         }
                   10069:         $cenv{'internal.notifylist'} = $notifylist;
                   10070:     }
                   10071:     if (@badclasses > 0) {
                   10072:         my %lt=&Apache::lonlocal::texthash(
                   10073:                 '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',
                   10074:                 'dnhr' => 'does not have rights to access enrollment in these classes',
                   10075:                 'adby' => 'as determined by the policies of your institution on access to official classlists'
                   10076:         );
1.541     raeburn  10077:         my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
                   10078:                            ' ('.$lt{'adby'}.')';
                   10079:         if ($context eq 'auto') {
                   10080:             $outcome .= $badclass_msg.$linefeed;
1.566     albertel 10081:             $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541     raeburn  10082:             foreach my $item (@badclasses) {
                   10083:                 if ($context eq 'auto') {
                   10084:                     $outcome .= " - $item\n";
                   10085:                 } else {
                   10086:                     $outcome .= "<li>$item</li>\n";
                   10087:                 }
                   10088:             }
                   10089:             if ($context eq 'auto') {
                   10090:                 $outcome .= $linefeed;
                   10091:             } else {
1.566     albertel 10092:                 $outcome .= "</ul><br /><br /></div>\n";
1.541     raeburn  10093:             }
                   10094:         } 
1.444     albertel 10095:     }
                   10096:     if ($args->{'no_end_date'}) {
                   10097:         $args->{'endaccess'} = 0;
                   10098:     }
                   10099:     $cenv{'internal.autostart'}=$args->{'enrollstart'};
                   10100:     $cenv{'internal.autoend'}=$args->{'enrollend'};
                   10101:     $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
                   10102:     $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
                   10103:     if ($args->{'showphotos'}) {
                   10104:       $cenv{'internal.showphotos'}=$args->{'showphotos'};
                   10105:     }
                   10106:     $cenv{'internal.authtype'} = $args->{'authtype'};
                   10107:     $cenv{'internal.autharg'} = $args->{'autharg'}; 
                   10108:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
                   10109:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
1.541     raeburn  10110:             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'); 
                   10111:             if ($context eq 'auto') {
                   10112:                 $outcome .= $krb_msg;
                   10113:             } else {
1.566     albertel 10114:                 $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541     raeburn  10115:             }
                   10116:             $outcome .= $linefeed;
1.444     albertel 10117:         }
                   10118:     }
                   10119:     if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
                   10120:        if ($args->{'setpolicy'}) {
                   10121:            $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   10122:        }
                   10123:        if ($args->{'setcontent'}) {
                   10124:            $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   10125:        }
                   10126:     }
                   10127:     if ($args->{'reshome'}) {
                   10128: 	$cenv{'reshome'}=$args->{'reshome'}.'/';
                   10129: 	$cenv{'reshome'}=~s/\/+$/\//;
                   10130:     }
                   10131: #
                   10132: # course has keyed access
                   10133: #
                   10134:     if ($args->{'setkeys'}) {
                   10135:        $cenv{'keyaccess'}='yes';
                   10136:     }
                   10137: # if specified, key authority is not course, but user
                   10138: # only active if keyaccess is yes
                   10139:     if ($args->{'keyauth'}) {
1.487     albertel 10140: 	my ($user,$domain) = split(':',$args->{'keyauth'});
                   10141: 	$user = &LONCAPA::clean_username($user);
                   10142: 	$domain = &LONCAPA::clean_username($domain);
1.488     foxr     10143: 	if ($user ne '' && $domain ne '') {
1.487     albertel 10144: 	    $cenv{'keyauth'}=$user.':'.$domain;
1.444     albertel 10145: 	}
                   10146:     }
                   10147: 
                   10148:     if ($args->{'disresdis'}) {
                   10149:         $cenv{'pch.roles.denied'}='st';
                   10150:     }
                   10151:     if ($args->{'disablechat'}) {
                   10152:         $cenv{'plc.roles.denied'}='st';
                   10153:     }
                   10154: 
                   10155:     # Record we've not yet viewed the Course Initialization Helper for this 
                   10156:     # course
                   10157:     $cenv{'course.helper.not.run'} = 1;
                   10158:     #
                   10159:     # Use new Randomseed
                   10160:     #
                   10161:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
                   10162:     $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
                   10163:     #
                   10164:     # The encryption code and receipt prefix for this course
                   10165:     #
                   10166:     $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
                   10167:     $cenv{'internal.encpref'}=100+int(9*rand(99));
                   10168:     #
                   10169:     # By default, use standard grading
                   10170:     if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
                   10171: 
1.541     raeburn  10172:     $outcome .= $linefeed.&mt('Setting environment').': '.                 
                   10173:           &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 10174: #
                   10175: # Open all assignments
                   10176: #
                   10177:     if ($args->{'openall'}) {
                   10178:        my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
                   10179:        my %storecontent = ($storeunder         => time,
                   10180:                            $storeunder.'.type' => 'date_start');
                   10181:        
                   10182:        $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541     raeburn  10183:                  ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 10184:    }
                   10185: #
                   10186: # Set first page
                   10187: #
                   10188:     unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
                   10189: 	    || ($cloneid)) {
1.445     albertel 10190: 	use LONCAPA::map;
1.444     albertel 10191: 	$outcome .= &mt('Setting first resource').': ';
1.445     albertel 10192: 
                   10193: 	my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
                   10194:         my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
                   10195: 
1.444     albertel 10196:         $outcome .= ($fatal?$errtext:'read ok').' - ';
                   10197:         my $title; my $url;
                   10198:         if ($args->{'firstres'} eq 'syl') {
1.690     bisitz   10199: 	    $title=&mt('Syllabus');
1.444     albertel 10200:             $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
                   10201:         } else {
1.690     bisitz   10202:             $title=&mt('Navigate Contents');
1.444     albertel 10203:             $url='/adm/navmaps';
                   10204:         }
1.445     albertel 10205: 
                   10206:         $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
                   10207: 	(my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
                   10208: 
                   10209: 	if ($errtext) { $fatal=2; }
1.541     raeburn  10210:         $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444     albertel 10211:     }
1.566     albertel 10212: 
                   10213:     return (1,$outcome);
1.444     albertel 10214: }
                   10215: 
                   10216: ############################################################
                   10217: ############################################################
                   10218: 
1.378     raeburn  10219: sub course_type {
                   10220:     my ($cid) = @_;
                   10221:     if (!defined($cid)) {
                   10222:         $cid = $env{'request.course.id'};
                   10223:     }
1.404     albertel 10224:     if (defined($env{'course.'.$cid.'.type'})) {
                   10225:         return $env{'course.'.$cid.'.type'};
1.378     raeburn  10226:     } else {
                   10227:         return 'Course';
1.377     raeburn  10228:     }
                   10229: }
1.156     albertel 10230: 
1.406     raeburn  10231: sub group_term {
                   10232:     my $crstype = &course_type();
                   10233:     my %names = (
                   10234:                   'Course' => 'group',
1.865     raeburn  10235:                   'Community' => 'group',
1.406     raeburn  10236:                 );
                   10237:     return $names{$crstype};
                   10238: }
                   10239: 
1.156     albertel 10240: sub icon {
                   10241:     my ($file)=@_;
1.505     albertel 10242:     my $curfext = lc((split(/\./,$file))[-1]);
1.168     albertel 10243:     my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156     albertel 10244:     my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168     albertel 10245:     if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
                   10246: 	if (-e  $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
                   10247: 	          $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   10248: 	            $curfext.".gif") {
                   10249: 	    $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   10250: 		$curfext.".gif";
                   10251: 	}
                   10252:     }
1.249     albertel 10253:     return &lonhttpdurl($iconname);
1.154     albertel 10254: } 
1.84      albertel 10255: 
1.575     albertel 10256: sub lonhttpdurl {
1.692     www      10257: #
                   10258: # Had been used for "small fry" static images on separate port 8080.
                   10259: # Modify here if lightweight http functionality desired again.
                   10260: # Currently eliminated due to increasing firewall issues.
                   10261: #
1.575     albertel 10262:     my ($url)=@_;
1.692     www      10263:     return $url;
1.215     albertel 10264: }
                   10265: 
1.213     albertel 10266: sub connection_aborted {
                   10267:     my ($r)=@_;
                   10268:     $r->print(" ");$r->rflush();
                   10269:     my $c = $r->connection;
                   10270:     return $c->aborted();
                   10271: }
                   10272: 
1.221     foxr     10273: #    Escapes strings that may have embedded 's that will be put into
1.222     foxr     10274: #    strings as 'strings'.
                   10275: sub escape_single {
1.221     foxr     10276:     my ($input) = @_;
1.223     albertel 10277:     $input =~ s/\\/\\\\/g;	# Escape the \'s..(must be first)>
1.221     foxr     10278:     $input =~ s/\'/\\\'/g;	# Esacpe the 's....
                   10279:     return $input;
                   10280: }
1.223     albertel 10281: 
1.222     foxr     10282: #  Same as escape_single, but escape's "'s  This 
                   10283: #  can be used for  "strings"
                   10284: sub escape_double {
                   10285:     my ($input) = @_;
                   10286:     $input =~ s/\\/\\\\/g;	# Escape the /'s..(must be first)>
                   10287:     $input =~ s/\"/\\\"/g;	# Esacpe the "s....
                   10288:     return $input;
                   10289: }
1.223     albertel 10290:  
1.222     foxr     10291: #   Escapes the last element of a full URL.
                   10292: sub escape_url {
                   10293:     my ($url)   = @_;
1.238     raeburn  10294:     my @urlslices = split(/\//, $url,-1);
1.369     www      10295:     my $lastitem = &escape(pop(@urlslices));
1.223     albertel 10296:     return join('/',@urlslices).'/'.$lastitem;
1.222     foxr     10297: }
1.462     albertel 10298: 
1.820     raeburn  10299: sub compare_arrays {
                   10300:     my ($arrayref1,$arrayref2) = @_;
                   10301:     my (@difference,%count);
                   10302:     @difference = ();
                   10303:     %count = ();
                   10304:     if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
                   10305:         foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
                   10306:         foreach my $element (keys(%count)) {
                   10307:             if ($count{$element} == 1) {
                   10308:                 push(@difference,$element);
                   10309:             }
                   10310:         }
                   10311:     }
                   10312:     return @difference;
                   10313: }
                   10314: 
1.817     bisitz   10315: # -------------------------------------------------------- Initialize user login
1.462     albertel 10316: sub init_user_environment {
1.463     albertel 10317:     my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462     albertel 10318:     my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
                   10319: 
                   10320:     my $public=($username eq 'public' && $domain eq 'public');
                   10321: 
                   10322: # See if old ID present, if so, remove
                   10323: 
                   10324:     my ($filename,$cookie,$userroles);
                   10325:     my $now=time;
                   10326: 
                   10327:     if ($public) {
                   10328: 	my $max_public=100;
                   10329: 	my $oldest;
                   10330: 	my $oldest_time=0;
                   10331: 	for(my $next=1;$next<=$max_public;$next++) {
                   10332: 	    if (-e $lonids."/publicuser_$next.id") {
                   10333: 		my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
                   10334: 		if ($mtime<$oldest_time || !$oldest_time) {
                   10335: 		    $oldest_time=$mtime;
                   10336: 		    $oldest=$next;
                   10337: 		}
                   10338: 	    } else {
                   10339: 		$cookie="publicuser_$next";
                   10340: 		last;
                   10341: 	    }
                   10342: 	}
                   10343: 	if (!$cookie) { $cookie="publicuser_$oldest"; }
                   10344:     } else {
1.463     albertel 10345: 	# if this isn't a robot, kill any existing non-robot sessions
                   10346: 	if (!$args->{'robot'}) {
                   10347: 	    opendir(DIR,$lonids);
                   10348: 	    while ($filename=readdir(DIR)) {
                   10349: 		if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
                   10350: 		    unlink($lonids.'/'.$filename);
                   10351: 		}
1.462     albertel 10352: 	    }
1.463     albertel 10353: 	    closedir(DIR);
1.462     albertel 10354: 	}
                   10355: # Give them a new cookie
1.463     albertel 10356: 	my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684     www      10357: 		                   : $now.$$.int(rand(10000)));
1.463     albertel 10358: 	$cookie="$username\_$id\_$domain\_$authhost";
1.462     albertel 10359:     
                   10360: # Initialize roles
                   10361: 
                   10362: 	$userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
                   10363:     }
                   10364: # ------------------------------------ Check browser type and MathML capability
                   10365: 
                   10366:     my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   10367:         $clientunicode,$clientos) = &decode_user_agent($r);
                   10368: 
                   10369: # ------------------------------------------------------------- Get environment
                   10370: 
                   10371:     my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
                   10372:     my ($tmp) = keys(%userenv);
                   10373:     if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   10374: 	# default remote control to off
                   10375: 	if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
                   10376:     } else {
                   10377: 	undef(%userenv);
                   10378:     }
                   10379:     if (($userenv{'interface'}) && (!$form->{'interface'})) {
                   10380: 	$form->{'interface'}=$userenv{'interface'};
                   10381:     }
                   10382:     $env{'environment.remote'}=$userenv{'remote'};
                   10383:     if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
                   10384: 
                   10385: # --------------- Do not trust query string to be put directly into environment
1.817     bisitz   10386:     foreach my $option ('interface','localpath','localres') {
                   10387:         $form->{$option}=~s/[\n\r\=]//gs;
1.462     albertel 10388:     }
                   10389: # --------------------------------------------------------- Write first profile
                   10390: 
                   10391:     {
                   10392: 	my %initial_env = 
                   10393: 	    ("user.name"          => $username,
                   10394: 	     "user.domain"        => $domain,
                   10395: 	     "user.home"          => $authhost,
                   10396: 	     "browser.type"       => $clientbrowser,
                   10397: 	     "browser.version"    => $clientversion,
                   10398: 	     "browser.mathml"     => $clientmathml,
                   10399: 	     "browser.unicode"    => $clientunicode,
                   10400: 	     "browser.os"         => $clientos,
                   10401: 	     "server.domain"      => $Apache::lonnet::perlvar{'lonDefDomain'},
                   10402: 	     "request.course.fn"  => '',
                   10403: 	     "request.course.uri" => '',
                   10404: 	     "request.course.sec" => '',
                   10405: 	     "request.role"       => 'cm',
                   10406: 	     "request.role.adv"   => $env{'user.adv'},
                   10407: 	     "request.host"       => $ENV{'REMOTE_ADDR'},);
                   10408: 
                   10409:         if ($form->{'localpath'}) {
                   10410: 	    $initial_env{"browser.localpath"}  = $form->{'localpath'};
                   10411: 	    $initial_env{"browser.localres"}   = $form->{'localres'};
                   10412:         }
                   10413: 	
                   10414: 	if ($public) {
                   10415: 	    $initial_env{"environment.remote"} = "off";
                   10416: 	}
                   10417: 	if ($form->{'interface'}) {
                   10418: 	    $form->{'interface'}=~s/\W//gs;
                   10419: 	    $initial_env{"browser.interface"} = $form->{'interface'};
                   10420: 	    $env{'browser.interface'}=$form->{'interface'};
                   10421: 	}
                   10422: 
1.724     raeburn  10423:         foreach my $tool ('aboutme','blog','portfolio') {
                   10424:             $userenv{'availabletools.'.$tool} = 
                   10425:                 &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
                   10426:         }
                   10427: 
1.864     raeburn  10428:         foreach my $crstype ('official','unofficial','community') {
1.765     raeburn  10429:             $userenv{'canrequest.'.$crstype} =
                   10430:                 &Apache::lonnet::usertools_access($username,$domain,$crstype,
                   10431:                                                   'reload','requestcourses');
                   10432:         }
                   10433: 
1.462     albertel 10434: 	$env{'user.environment'} = "$lonids/$cookie.id";
                   10435: 	
                   10436: 	if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
                   10437: 		 &GDBM_WRCREAT(),0640)) {
                   10438: 	    &_add_to_env(\%disk_env,\%initial_env);
                   10439: 	    &_add_to_env(\%disk_env,\%userenv,'environment.');
                   10440: 	    &_add_to_env(\%disk_env,$userroles);
1.463     albertel 10441: 	    if (ref($args->{'extra_env'})) {
                   10442: 		&_add_to_env(\%disk_env,$args->{'extra_env'});
                   10443: 	    }
1.462     albertel 10444: 	    untie(%disk_env);
                   10445: 	} else {
1.705     tempelho 10446: 	    &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
                   10447: 			   'Could not create environment storage in lonauth: '.$!.'</span>');
1.462     albertel 10448: 	    return 'error: '.$!;
                   10449: 	}
                   10450:     }
                   10451:     $env{'request.role'}='cm';
                   10452:     $env{'request.role.adv'}=$env{'user.adv'};
                   10453:     $env{'browser.type'}=$clientbrowser;
                   10454: 
                   10455:     return $cookie;
                   10456: 
                   10457: }
                   10458: 
                   10459: sub _add_to_env {
                   10460:     my ($idf,$env_data,$prefix) = @_;
1.676     raeburn  10461:     if (ref($env_data) eq 'HASH') {
                   10462:         while (my ($key,$value) = each(%$env_data)) {
                   10463: 	    $idf->{$prefix.$key} = $value;
                   10464: 	    $env{$prefix.$key}   = $value;
                   10465:         }
1.462     albertel 10466:     }
                   10467: }
                   10468: 
1.685     tempelho 10469: # --- Get the symbolic name of a problem and the url
                   10470: sub get_symb {
                   10471:     my ($request,$silent) = @_;
1.726     raeburn  10472:     (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685     tempelho 10473:     my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
                   10474:     if ($symb eq '') {
                   10475:         if (!$silent) {
                   10476:             $request->print("Unable to handle ambiguous references:$url:.");
                   10477:             return ();
                   10478:         }
                   10479:     }
                   10480:     &Apache::lonenc::check_decrypt(\$symb);
                   10481:     return ($symb);
                   10482: }
                   10483: 
                   10484: # --------------------------------------------------------------Get annotation
                   10485: 
                   10486: sub get_annotation {
                   10487:     my ($symb,$enc) = @_;
                   10488: 
                   10489:     my $key = $symb;
                   10490:     if (!$enc) {
                   10491:         $key =
                   10492:             &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
                   10493:     }
                   10494:     my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
                   10495:     return $annotation{$key};
                   10496: }
                   10497: 
                   10498: sub clean_symb {
1.731     raeburn  10499:     my ($symb,$delete_enc) = @_;
1.685     tempelho 10500: 
                   10501:     &Apache::lonenc::check_decrypt(\$symb);
                   10502:     my $enc = $env{'request.enc'};
1.731     raeburn  10503:     if ($delete_enc) {
1.730     raeburn  10504:         delete($env{'request.enc'});
                   10505:     }
1.685     tempelho 10506: 
                   10507:     return ($symb,$enc);
                   10508: }
1.462     albertel 10509: 
1.41      ng       10510: =pod
                   10511: 
                   10512: =back
                   10513: 
1.112     bowersj2 10514: =cut
1.41      ng       10515: 
1.112     bowersj2 10516: 1;
                   10517: __END__;
1.41      ng       10518: 

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