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

1.10      albertel    1: # The LearningOnline Network with CAPA
1.1       albertel    2: # a pile of common routines
1.10      albertel    3: #
1.906   ! raeburn     4: # $Id: loncommon.pm,v 1.905 2009/10/30 04:44:56 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.905     raeburn   485:     my ($domainfilter,$sec_element,$formname,$role_element)=@_;
1.886     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.895     raeburn   496:         var formid = getFormIdByName(formname);
1.876     raeburn   497:         var domainfilter = getDomainFromSelectbox(formname,udom);
1.128     albertel  498:         if (domainfilter != null) {
                    499:            if (domainfilter != '') {
                    500:                url += 'domainfilter='+domainfilter+'&';
                    501: 	   }
                    502:         }
1.91      www       503:         url += 'form=' + formname + '&cnumelement='+uname+
1.187     albertel  504: 	                            '&cdomelement='+udom+
                    505:                                     '&cnameelement='+desc;
1.468     raeburn   506:         if (extra_element !=null && extra_element != '') {
1.594     raeburn   507:             if (formname == 'rolechoice' || formname == 'studentform') {
1.468     raeburn   508:                 url += '&roleelement='+extra_element;
                    509:                 if (domainfilter == null || domainfilter == '') {
                    510:                     url += '&domainfilter='+extra_element;
                    511:                 }
1.234     raeburn   512:             }
1.468     raeburn   513:             else {
                    514:                 if (formname == 'portform') {
                    515:                     url += '&setroles='+extra_element;
1.800     raeburn   516:                 } else {
                    517:                     if (formname == 'rules') {
                    518:                         url += '&fixeddom='+extra_element; 
                    519:                     }
1.468     raeburn   520:                 }
                    521:             }     
1.230     raeburn   522:         }
1.872     raeburn   523:         if (formname == 'ccrs') {
                    524:             var ownername = document.forms[formid].ccuname.value;
                    525:             var ownerdom =  document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
                    526:             url += '&cloner='+ownername+':'+ownerdom;
                    527:         }
1.293     raeburn   528:         if (multflag !=null && multflag != '') {
                    529:             url += '&multiple='+multflag;
                    530:         }
1.865     raeburn   531:         if (crstype == 'Course/Community') {
1.377     raeburn   532:             if (formname == 'cu') {
                    533:                 crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value; 
                    534:                 if (crstype == "") {
                    535:                     alert("$crs_or_grp_alert");
                    536:                     return;
                    537:                 }
                    538:             }
                    539:         }
                    540:         if (crstype !=null && crstype != '') {
                    541:             url += '&type='+crstype;
                    542:         }
1.102     www       543:         var title = 'Course_Browser';
1.91      www       544:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    545:         options += ',width=700,height=600';
                    546:         stdeditbrowser = open(url,title,options,'1');
                    547:         stdeditbrowser.focus();
                    548:     }
1.876     raeburn   549: $id_functions
                    550: ENDSTDBRW
1.905     raeburn   551:     if (($sec_element ne '') || ($role_element ne '')) {
                    552:         $output .= &setsec_javascript($sec_element,$formname,$role_element);
1.876     raeburn   553:     }
                    554:     $output .= '
                    555: // ]]>
                    556: </script>';
                    557:     return $output;
                    558: }
                    559: 
                    560: sub javascript_index_functions {
                    561:     return <<"ENDJS";
                    562: 
                    563: function getFormIdByName(formname) {
                    564:     for (var i=0;i<document.forms.length;i++) {
                    565:         if (document.forms[i].name == formname) {
                    566:             return i;
                    567:         }
                    568:     }
                    569:     return -1;
                    570: }
                    571: 
                    572: function getIndexByName(formid,item) {
                    573:     for (var i=0;i<document.forms[formid].elements.length;i++) {
                    574:         if (document.forms[formid].elements[i].name == item) {
                    575:             return i;
                    576:         }
                    577:     }
                    578:     return -1;
                    579: }
1.468     raeburn   580: 
1.876     raeburn   581: function getDomainFromSelectbox(formname,udom) {
                    582:     var userdom;
                    583:     var formid = getFormIdByName(formname);
                    584:     if (formid > -1) {
                    585:         var domid = getIndexByName(formid,udom);
                    586:         if (domid > -1) {
                    587:             if (document.forms[formid].elements[domid].type == 'select-one') {
                    588:                 userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
                    589:             }
                    590:             if (document.forms[formid].elements[domid].type == 'hidden') {
                    591:                 userdom=document.forms[formid].elements[domid].value;
1.468     raeburn   592:             }
                    593:         }
                    594:     }
1.876     raeburn   595:     return userdom;
                    596: }
                    597: 
                    598: ENDJS
1.468     raeburn   599: 
1.876     raeburn   600: }
                    601: 
                    602: sub userbrowser_javascript {
                    603:     my $id_functions = &javascript_index_functions();
                    604:     return <<"ENDUSERBRW";
                    605: 
1.888     raeburn   606: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876     raeburn   607:     var url = '/adm/pickuser?';
                    608:     var userdom = getDomainFromSelectbox(formname,udom);
                    609:     if (userdom != null) {
                    610:        if (userdom != '') {
                    611:            url += 'srchdom='+userdom+'&';
                    612:        }
                    613:     }
                    614:     url += 'form=' + formname + '&unameelement='+uname+
                    615:                                 '&udomelement='+udom+
                    616:                                 '&ulastelement='+ulast+
                    617:                                 '&ufirstelement='+ufirst+
                    618:                                 '&uemailelement='+uemail+
1.881     raeburn   619:                                 '&hideudomelement='+hideudom+
                    620:                                 '&coursedom='+crsdom;
1.888     raeburn   621:     if ((caller != null) && (caller != undefined)) {
                    622:         url += '&caller='+caller;
                    623:     }
1.876     raeburn   624:     var title = 'User_Browser';
                    625:     var options = 'scrollbars=1,resizable=1,menubar=0';
                    626:     options += ',width=700,height=600';
                    627:     var stdeditbrowser = open(url,title,options,'1');
                    628:     stdeditbrowser.focus();
                    629: }
                    630: 
1.888     raeburn   631: function fix_domain (formname,udom,origdom,uname) {
1.876     raeburn   632:     var formid = getFormIdByName(formname);
                    633:     if (formid > -1) {
1.888     raeburn   634:         var unameid = getIndexByName(formid,uname);
1.876     raeburn   635:         var domid = getIndexByName(formid,udom);
                    636:         var hidedomid = getIndexByName(formid,origdom);
                    637:         if (hidedomid > -1) {
                    638:             var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888     raeburn   639:             var unameval = document.forms[formid].elements[unameid].value;
                    640:             if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
                    641:                 if (domid > -1) {
                    642:                     var slct = document.forms[formid].elements[domid];
                    643:                     if (slct.type == 'select-one') {
                    644:                         var i;
                    645:                         for (i=0;i<slct.length;i++) {
                    646:                             if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
                    647:                         }
                    648:                     }
                    649:                     if (slct.type == 'hidden') {
                    650:                         slct.value = fixeddom;
1.876     raeburn   651:                     }
                    652:                 }
1.468     raeburn   653:             }
                    654:         }
                    655:     }
1.876     raeburn   656:     return;
                    657: }
                    658: 
                    659: $id_functions
                    660: ENDUSERBRW
1.468     raeburn   661: }
                    662: 
                    663: sub setsec_javascript {
1.905     raeburn   664:     my ($sec_element,$formname,$role_element) = @_;
                    665:     my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
                    666:         $communityrolestr);
                    667:     if ($role_element ne '') {
                    668:         my @allroles = ('st','ta','ep','in','ad');
                    669:         foreach my $crstype ('Course','Community') {
                    670:             if ($crstype eq 'Community') {
                    671:                 foreach my $role (@allroles) {
                    672:                     push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
                    673:                 }
                    674:                 push(@communityrolenames,&Apache::lonnet::plaintext('co'));
                    675:             } else {
                    676:                 foreach my $role (@allroles) {
                    677:                     push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
                    678:                 }
                    679:                 push(@courserolenames,&Apache::lonnet::plaintext('cc'));
                    680:             }
                    681:         }
                    682:         $rolestr = '"'.join('","',@allroles).'"';
                    683:         $courserolestr = '"'.join('","',@courserolenames).'"';
                    684:         $communityrolestr = '"'.join('","',@communityrolenames).'"';
                    685:     }
1.468     raeburn   686:     my $setsections = qq|
                    687: function setSect(sectionlist) {
1.629     raeburn   688:     var sectionsArray = new Array();
                    689:     if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
                    690:         sectionsArray = sectionlist.split(",");
                    691:     }
1.468     raeburn   692:     var numSections = sectionsArray.length;
                    693:     document.$formname.$sec_element.length = 0;
                    694:     if (numSections == 0) {
                    695:         document.$formname.$sec_element.multiple=false;
                    696:         document.$formname.$sec_element.size=1;
                    697:         document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
                    698:     } else {
                    699:         if (numSections == 1) {
                    700:             document.$formname.$sec_element.multiple=false;
                    701:             document.$formname.$sec_element.size=1;
                    702:             document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
                    703:             document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
                    704:             document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
                    705:         } else {
                    706:             for (var i=0; i<numSections; i++) {
                    707:                 document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
                    708:             }
                    709:             document.$formname.$sec_element.multiple=true
                    710:             if (numSections < 3) {
                    711:                 document.$formname.$sec_element.size=numSections;
                    712:             } else {
                    713:                 document.$formname.$sec_element.size=3;
                    714:             }
                    715:             document.$formname.$sec_element.options[0].selected = false
                    716:         }
                    717:     }
1.91      www       718: }
1.905     raeburn   719: 
                    720: function setRole(crstype) {
1.468     raeburn   721: |;
1.905     raeburn   722:     if ($role_element eq '') {
                    723:         $setsections .= '    return;
                    724: }
                    725: ';
                    726:     } else {
                    727:         $setsections .= qq|
                    728:     var elementLength = document.$formname.$role_element.length;
                    729:     var allroles = Array($rolestr);
                    730:     var courserolenames = Array($courserolestr);
                    731:     var communityrolenames = Array($communityrolestr);
                    732:     if (elementLength != undefined) {
                    733:         if (document.$formname.$role_element.options[5].value == 'cc') {
                    734:             if (crstype == 'Course') {
                    735:                 return;
                    736:             } else {
                    737:                 allroles[5] = 'co';
                    738:                 for (var i=0; i<6; i++) {
                    739:                     document.$formname.$role_element.options[i].value = allroles[i];
                    740:                     document.$formname.$role_element.options[i].text = communityrolenames[i];
                    741:                 }
                    742:             }
                    743:         } else {
                    744:             if (crstype == 'Community') {
                    745:                 return;
                    746:             } else {
                    747:                 allroles[5] = 'cc';
                    748:                 for (var i=0; i<6; i++) {
                    749:                     document.$formname.$role_element.options[i].value = allroles[i];
                    750:                     document.$formname.$role_element.options[i].text = courserolenames[i];
                    751:                 }
                    752:             }
                    753:         }
                    754:     }
                    755:     return;
                    756: }
                    757: |;
                    758:     }
1.468     raeburn   759:     return $setsections;
                    760: }
                    761: 
1.91      www       762: sub selectcourse_link {
1.377     raeburn   763:    my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.871     raeburn   764:    my $linktext = &mt('Select Course');
                    765:    if ($selecttype eq 'Community') {
                    766:        $linktext = &mt('Select Community'); 
1.906   ! raeburn   767:    } elsif ($selecttype eq 'Course/Community') {
        !           768:        $linktext = &mt('Select Course/Community');
        !           769:        $selecttype = 'Course';
1.871     raeburn   770:    }
1.787     bisitz    771:    return '<span class="LC_nobreak">'
                    772:          ."<a href='"
                    773:          .'javascript:opencrsbrowser("'.$form.'","'.$unameele
                    774:          .'","'.$udomele.'","'.$desc.'","'.$extra_element
                    775:          .'","'.$multflag.'","'.$selecttype.'");'
1.871     raeburn   776:          ."'>".$linktext.'</a>'
1.787     bisitz    777:          .'</span>';
1.74      www       778: }
1.42      matthew   779: 
1.653     raeburn   780: sub selectauthor_link {
                    781:    my ($form,$udom)=@_;
                    782:    return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
                    783:           &mt('Select Author').'</a>';
                    784: }
                    785: 
1.876     raeburn   786: sub selectuser_link {
1.881     raeburn   787:     my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888     raeburn   788:         $coursedom,$linktext,$caller) = @_;
1.876     raeburn   789:     return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888     raeburn   790:            "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881     raeburn   791:            ');">'.$linktext.'</a>';
1.876     raeburn   792: }
                    793: 
1.273     raeburn   794: sub check_uncheck_jscript {
                    795:     my $jscript = <<"ENDSCRT";
                    796: function checkAll(field) {
                    797:     if (field.length > 0) {
                    798:         for (i = 0; i < field.length; i++) {
                    799:             field[i].checked = true ;
                    800:         }
                    801:     } else {
                    802:         field.checked = true
                    803:     }
                    804: }
                    805:  
                    806: function uncheckAll(field) {
                    807:     if (field.length > 0) {
                    808:         for (i = 0; i < field.length; i++) {
                    809:             field[i].checked = false ;
1.543     albertel  810:         }
                    811:     } else {
1.273     raeburn   812:         field.checked = false ;
                    813:     }
                    814: }
                    815: ENDSCRT
                    816:     return $jscript;
                    817: }
                    818: 
1.656     www       819: sub select_timezone {
1.659     raeburn   820:    my ($name,$selected,$onchange,$includeempty)=@_;
                    821:    my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    822:    if ($includeempty) {
                    823:        $output .= '<option value=""';
                    824:        if (($selected eq '') || ($selected eq 'local')) {
                    825:            $output .= ' selected="selected" ';
                    826:        }
                    827:        $output .= '> </option>';
                    828:    }
1.657     raeburn   829:    my @timezones = DateTime::TimeZone->all_names;
                    830:    foreach my $tzone (@timezones) {
                    831:        $output.= '<option value="'.$tzone.'"';
                    832:        if ($tzone eq $selected) {
                    833:            $output.=' selected="selected"';
                    834:        }
                    835:        $output.=">$tzone</option>\n";
1.656     www       836:    }
                    837:    $output.="</select>";
                    838:    return $output;
                    839: }
1.273     raeburn   840: 
1.687     raeburn   841: sub select_datelocale {
                    842:     my ($name,$selected,$onchange,$includeempty)=@_;
                    843:     my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    844:     if ($includeempty) {
                    845:         $output .= '<option value=""';
                    846:         if ($selected eq '') {
                    847:             $output .= ' selected="selected" ';
                    848:         }
                    849:         $output .= '> </option>';
                    850:     }
                    851:     my (@possibles,%locale_names);
                    852:     my @locales = DateTime::Locale::Catalog::Locales;
                    853:     foreach my $locale (@locales) {
                    854:         if (ref($locale) eq 'HASH') {
                    855:             my $id = $locale->{'id'};
                    856:             if ($id ne '') {
                    857:                 my $en_terr = $locale->{'en_territory'};
                    858:                 my $native_terr = $locale->{'native_territory'};
1.695     raeburn   859:                 my @languages = &Apache::lonlocal::preferred_languages();
1.687     raeburn   860:                 if (grep(/^en$/,@languages) || !@languages) {
                    861:                     if ($en_terr ne '') {
                    862:                         $locale_names{$id} = '('.$en_terr.')';
                    863:                     } elsif ($native_terr ne '') {
                    864:                         $locale_names{$id} = $native_terr;
                    865:                     }
                    866:                 } else {
                    867:                     if ($native_terr ne '') {
                    868:                         $locale_names{$id} = $native_terr.' ';
                    869:                     } elsif ($en_terr ne '') {
                    870:                         $locale_names{$id} = '('.$en_terr.')';
                    871:                     }
                    872:                 }
                    873:                 push (@possibles,$id);
                    874:             }
                    875:         }
                    876:     }
                    877:     foreach my $item (sort(@possibles)) {
                    878:         $output.= '<option value="'.$item.'"';
                    879:         if ($item eq $selected) {
                    880:             $output.=' selected="selected"';
                    881:         }
                    882:         $output.=">$item";
                    883:         if ($locale_names{$item} ne '') {
                    884:             $output.="  $locale_names{$item}</option>\n";
                    885:         }
                    886:         $output.="</option>\n";
                    887:     }
                    888:     $output.="</select>";
                    889:     return $output;
                    890: }
                    891: 
1.792     raeburn   892: sub select_language {
                    893:     my ($name,$selected,$includeempty) = @_;
                    894:     my %langchoices;
                    895:     if ($includeempty) {
                    896:         %langchoices = ('' => 'No language preference');
                    897:     }
                    898:     foreach my $id (&languageids()) {
                    899:         my $code = &supportedlanguagecode($id);
                    900:         if ($code) {
                    901:             $langchoices{$code} = &plainlanguagedescription($id);
                    902:         }
                    903:     }
                    904:     return &select_form($selected,$name,%langchoices);
                    905: }
                    906: 
1.42      matthew   907: =pod
1.36      matthew   908: 
1.648     raeburn   909: =item * &linked_select_forms(...)
1.36      matthew   910: 
                    911: linked_select_forms returns a string containing a <script></script> block
                    912: and html for two <select> menus.  The select menus will be linked in that
                    913: changing the value of the first menu will result in new values being placed
                    914: in the second menu.  The values in the select menu will appear in alphabetical
1.609     raeburn   915: order unless a defined order is provided.
1.36      matthew   916: 
                    917: linked_select_forms takes the following ordered inputs:
                    918: 
                    919: =over 4
                    920: 
1.112     bowersj2  921: =item * $formname, the name of the <form> tag
1.36      matthew   922: 
1.112     bowersj2  923: =item * $middletext, the text which appears between the <select> tags
1.36      matthew   924: 
1.112     bowersj2  925: =item * $firstdefault, the default value for the first menu
1.36      matthew   926: 
1.112     bowersj2  927: =item * $firstselectname, the name of the first <select> tag
1.36      matthew   928: 
1.112     bowersj2  929: =item * $secondselectname, the name of the second <select> tag
1.36      matthew   930: 
1.112     bowersj2  931: =item * $hashref, a reference to a hash containing the data for the menus.
1.36      matthew   932: 
1.609     raeburn   933: =item * $menuorder, the order of values in the first menu
                    934: 
1.41      ng        935: =back 
                    936: 
1.36      matthew   937: Below is an example of such a hash.  Only the 'text', 'default', and 
                    938: 'select2' keys must appear as stated.  keys(%menu) are the possible 
                    939: values for the first select menu.  The text that coincides with the 
1.41      ng        940: first menu value is given in $menu{$choice1}->{'text'}.  The values 
1.36      matthew   941: and text for the second menu are given in the hash pointed to by 
                    942: $menu{$choice1}->{'select2'}.  
                    943: 
1.112     bowersj2  944:  my %menu = ( A1 => { text =>"Choice A1" ,
                    945:                        default => "B3",
                    946:                        select2 => { 
                    947:                            B1 => "Choice B1",
                    948:                            B2 => "Choice B2",
                    949:                            B3 => "Choice B3",
                    950:                            B4 => "Choice B4"
1.609     raeburn   951:                            },
                    952:                        order => ['B4','B3','B1','B2'],
1.112     bowersj2  953:                    },
                    954:                A2 => { text =>"Choice A2" ,
                    955:                        default => "C2",
                    956:                        select2 => { 
                    957:                            C1 => "Choice C1",
                    958:                            C2 => "Choice C2",
                    959:                            C3 => "Choice C3"
1.609     raeburn   960:                            },
                    961:                        order => ['C2','C1','C3'],
1.112     bowersj2  962:                    },
                    963:                A3 => { text =>"Choice A3" ,
                    964:                        default => "D6",
                    965:                        select2 => { 
                    966:                            D1 => "Choice D1",
                    967:                            D2 => "Choice D2",
                    968:                            D3 => "Choice D3",
                    969:                            D4 => "Choice D4",
                    970:                            D5 => "Choice D5",
                    971:                            D6 => "Choice D6",
                    972:                            D7 => "Choice D7"
1.609     raeburn   973:                            },
                    974:                        order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112     bowersj2  975:                    }
                    976:                );
1.36      matthew   977: 
                    978: =cut
                    979: 
                    980: sub linked_select_forms {
                    981:     my ($formname,
                    982:         $middletext,
                    983:         $firstdefault,
                    984:         $firstselectname,
                    985:         $secondselectname, 
1.609     raeburn   986:         $hashref,
                    987:         $menuorder,
1.36      matthew   988:         ) = @_;
                    989:     my $second = "document.$formname.$secondselectname";
                    990:     my $first = "document.$formname.$firstselectname";
                    991:     # output the javascript to do the changing
                    992:     my $result = '';
1.776     bisitz    993:     $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824     bisitz    994:     $result.="// <![CDATA[\n";
1.36      matthew   995:     $result.="var select2data = new Object();\n";
                    996:     $" = '","';
                    997:     my $debug = '';
                    998:     foreach my $s1 (sort(keys(%$hashref))) {
                    999:         $result.="select2data.d_$s1 = new Object();\n";        
                   1000:         $result.="select2data.d_$s1.def = new String('".
                   1001:             $hashref->{$s1}->{'default'}."');\n";
1.609     raeburn  1002:         $result.="select2data.d_$s1.values = new Array(";
1.36      matthew  1003:         my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609     raeburn  1004:         if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
                   1005:             @s2values = @{$hashref->{$s1}->{'order'}};
                   1006:         }
1.36      matthew  1007:         $result.="\"@s2values\");\n";
                   1008:         $result.="select2data.d_$s1.texts = new Array(";        
                   1009:         my @s2texts;
                   1010:         foreach my $value (@s2values) {
                   1011:             push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
                   1012:         }
                   1013:         $result.="\"@s2texts\");\n";
                   1014:     }
                   1015:     $"=' ';
                   1016:     $result.= <<"END";
                   1017: 
                   1018: function select1_changed() {
                   1019:     // Determine new choice
                   1020:     var newvalue = "d_" + $first.value;
                   1021:     // update select2
                   1022:     var values     = select2data[newvalue].values;
                   1023:     var texts      = select2data[newvalue].texts;
                   1024:     var select2def = select2data[newvalue].def;
                   1025:     var i;
                   1026:     // out with the old
                   1027:     for (i = 0; i < $second.options.length; i++) {
                   1028:         $second.options[i] = null;
                   1029:     }
                   1030:     // in with the nuclear
                   1031:     for (i=0;i<values.length; i++) {
                   1032:         $second.options[i] = new Option(values[i]);
1.143     matthew  1033:         $second.options[i].value = values[i];
1.36      matthew  1034:         $second.options[i].text = texts[i];
                   1035:         if (values[i] == select2def) {
                   1036:             $second.options[i].selected = true;
                   1037:         }
                   1038:     }
                   1039: }
1.824     bisitz   1040: // ]]>
1.36      matthew  1041: </script>
                   1042: END
                   1043:     # output the initial values for the selection lists
                   1044:     $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609     raeburn  1045:     my @order = sort(keys(%{$hashref}));
                   1046:     if (ref($menuorder) eq 'ARRAY') {
                   1047:         @order = @{$menuorder};
                   1048:     }
                   1049:     foreach my $value (@order) {
1.36      matthew  1050:         $result.="    <option value=\"$value\" ";
1.253     albertel 1051:         $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119     www      1052:         $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36      matthew  1053:     }
                   1054:     $result .= "</select>\n";
                   1055:     my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
                   1056:     $result .= $middletext;
                   1057:     $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
                   1058:     my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609     raeburn  1059:     
                   1060:     my @secondorder = sort(keys(%select2));
                   1061:     if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
                   1062:         @secondorder = @{$hashref->{$firstdefault}->{'order'}};
                   1063:     }
                   1064:     foreach my $value (@secondorder) {
1.36      matthew  1065:         $result.="    <option value=\"$value\" ";        
1.253     albertel 1066:         $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119     www      1067:         $result.=">".&mt($select2{$value})."</option>\n";
1.36      matthew  1068:     }
                   1069:     $result .= "</select>\n";
                   1070:     #    return $debug;
                   1071:     return $result;
                   1072: }   #  end of sub linked_select_forms {
                   1073: 
1.45      matthew  1074: =pod
1.44      bowersj2 1075: 
1.648     raeburn  1076: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44      bowersj2 1077: 
1.112     bowersj2 1078: Returns a string corresponding to an HTML link to the given help
                   1079: $topic, where $topic corresponds to the name of a .tex file in
                   1080: /home/httpd/html/adm/help/tex, with underscores replaced by
                   1081: spaces. 
                   1082: 
                   1083: $text will optionally be linked to the same topic, allowing you to
                   1084: link text in addition to the graphic. If you do not want to link
                   1085: text, but wish to specify one of the later parameters, pass an
                   1086: empty string. 
                   1087: 
                   1088: $stayOnPage is a value that will be interpreted as a boolean. If true,
                   1089: the link will not open a new window. If false, the link will open
                   1090: a new window using Javascript. (Default is false.) 
                   1091: 
                   1092: $width and $height are optional numerical parameters that will
                   1093: override the width and height of the popped up window, which may
                   1094: be useful for certain help topics with big pictures included. 
1.44      bowersj2 1095: 
                   1096: =cut
                   1097: 
                   1098: sub help_open_topic {
1.48      bowersj2 1099:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
                   1100:     $text = "" if (not defined $text);
1.44      bowersj2 1101:     $stayOnPage = 0 if (not defined $stayOnPage);
                   1102:     $width = 350 if (not defined $width);
                   1103:     $height = 400 if (not defined $height);
                   1104:     my $filename = $topic;
                   1105:     $filename =~ s/ /_/g;
                   1106: 
1.48      bowersj2 1107:     my $template = "";
                   1108:     my $link;
1.572     banghart 1109:     
1.159     www      1110:     $topic=~s/\W/\_/g;
1.44      bowersj2 1111: 
1.572     banghart 1112:     if (!$stayOnPage) {
1.72      bowersj2 1113: 	$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 1114:     } else {
1.48      bowersj2 1115: 	$link = "/adm/help/${filename}.hlp";
                   1116:     }
                   1117: 
                   1118:     # Add the text
1.755     neumanie 1119:     if ($text ne "") {	
1.763     bisitz   1120: 	$template.='<span class="LC_help_open_topic">'
                   1121:                   .'<a target="_top" href="'.$link.'">'
                   1122:                   .$text.'</a>';
1.48      bowersj2 1123:     }
                   1124: 
1.763     bisitz   1125:     # (Always) Add the graphic
1.179     matthew  1126:     my $title = &mt('Online Help');
1.667     raeburn  1127:     my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.763     bisitz   1128:     $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
                   1129:               .'<img src="'.$helpicon.'" border="0"'
                   1130:               .' alt="'.&mt('Help: [_1]',$topic).'"'
1.783     amueller 1131:               .' title="'.$title.'"' 
1.763     bisitz   1132:               .' /></a>';
                   1133:     if ($text ne "") {	
                   1134:         $template.='</span>';
                   1135:     }
1.44      bowersj2 1136:     return $template;
                   1137: 
1.106     bowersj2 1138: }
                   1139: 
                   1140: # This is a quicky function for Latex cheatsheet editing, since it 
                   1141: # appears in at least four places
                   1142: sub helpLatexCheatsheet {
1.732     raeburn  1143:     my ($topic,$text,$not_author) = @_;
                   1144:     my $out;
1.106     bowersj2 1145:     my $addOther = '';
1.732     raeburn  1146:     if ($topic) {
1.763     bisitz   1147: 	$addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
                   1148: 							       undef, undef, 600).
                   1149: 								   '</span> ';
                   1150:     }
                   1151:     $out = '<span>' # Start cheatsheet
                   1152: 	  .$addOther
                   1153:           .'<span>'
                   1154: 	  .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
                   1155: 					       undef,undef,600)
                   1156: 	  .'</span> <span>'
                   1157: 	  .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
                   1158: 					       undef,undef,600)
                   1159: 	  .'</span>';
1.732     raeburn  1160:     unless ($not_author) {
1.763     bisitz   1161:         $out .= ' <span>'
                   1162: 	       .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
                   1163: 	                                            undef,undef,600)
                   1164: 	       .'</span>';
1.732     raeburn  1165:     }
1.763     bisitz   1166:     $out .= '</span>'; # End cheatsheet
1.732     raeburn  1167:     return $out;
1.172     www      1168: }
                   1169: 
1.430     albertel 1170: sub general_help {
                   1171:     my $helptopic='Student_Intro';
                   1172:     if ($env{'request.role'}=~/^(ca|au)/) {
                   1173: 	$helptopic='Authoring_Intro';
                   1174:     } elsif ($env{'request.role'}=~/^cc/) {
                   1175: 	$helptopic='Course_Coordination_Intro';
1.672     raeburn  1176:     } elsif ($env{'request.role'}=~/^dc/) {
                   1177:         $helptopic='Domain_Coordination_Intro';
1.430     albertel 1178:     }
                   1179:     return $helptopic;
                   1180: }
                   1181: 
                   1182: sub update_help_link {
                   1183:     my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
                   1184:     my $origurl = $ENV{'REQUEST_URI'};
                   1185:     $origurl=~s|^/~|/priv/|;
                   1186:     my $timestamp = time;
                   1187:     foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
                   1188:         $$datum = &escape($$datum);
                   1189:     }
                   1190: 
                   1191:     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";
                   1192:     my $output .= <<"ENDOUTPUT";
                   1193: <script type="text/javascript">
1.824     bisitz   1194: // <![CDATA[
1.430     albertel 1195: banner_link = '$banner_link';
1.824     bisitz   1196: // ]]>
1.430     albertel 1197: </script>
                   1198: ENDOUTPUT
                   1199:     return $output;
                   1200: }
                   1201: 
                   1202: # now just updates the help link and generates a blue icon
1.193     raeburn  1203: sub help_open_menu {
1.430     albertel 1204:     my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text) 
1.552     banghart 1205: 	= @_;    
1.430     albertel 1206:     $stayOnPage = 0 if (not defined $stayOnPage);
1.572     banghart 1207:     # only use pop-up help (stayOnPage == 0)
1.552     banghart 1208:     # if environment.remote is on (using remote control UI)
1.798     tempelho 1209:     if ($env{'environment.remote'} eq 'off' ) {
1.552     banghart 1210:         $stayOnPage=1;
1.430     albertel 1211:     }
                   1212:     my $output;
                   1213:     if ($component_help) {
                   1214: 	if (!$text) {
                   1215: 	    $output=&help_open_topic($component_help,undef,$stayOnPage,
                   1216: 				       $width,$height);
                   1217: 	} else {
                   1218: 	    my $help_text;
                   1219: 	    $help_text=&unescape($topic);
                   1220: 	    $output='<table><tr><td>'.
                   1221: 		&help_open_topic($component_help,$help_text,$stayOnPage,
                   1222: 				 $width,$height).'</td></tr></table>';
                   1223: 	}
                   1224:     }
                   1225:     my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
                   1226:     return $output.$banner_link;
                   1227: }
                   1228: 
                   1229: sub top_nav_help {
                   1230:     my ($text) = @_;
1.436     albertel 1231:     $text = &mt($text);
1.572     banghart 1232:     my $stay_on_page = 
1.798     tempelho 1233: 	($env{'environment.remote'} eq 'off' );
1.572     banghart 1234:     my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436     albertel 1235: 	                     : "javascript:helpMenu('open')";
1.572     banghart 1236:     my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436     albertel 1237: 
1.201     raeburn  1238:     my $title = &mt('Get help');
1.436     albertel 1239: 
                   1240:     return <<"END";
                   1241: $banner_link
                   1242:  <a href="$link" title="$title">$text</a>
                   1243: END
                   1244: }
                   1245: 
                   1246: sub help_menu_js {
                   1247:     my ($text) = @_;
                   1248: 
                   1249:     my $stayOnPage = 
1.798     tempelho 1250: 	($env{'environment.remote'} eq 'off' );
1.436     albertel 1251: 
                   1252:     my $width = 620;
                   1253:     my $height = 600;
1.430     albertel 1254:     my $helptopic=&general_help();
                   1255:     my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261     albertel 1256:     my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331     albertel 1257:     my $start_page =
                   1258:         &Apache::loncommon::start_page('Help Menu', undef,
                   1259: 				       {'frameset'    => 1,
                   1260: 					'js_ready'    => 1,
                   1261: 					'add_entries' => {
                   1262: 					    'border' => '0',
1.579     raeburn  1263: 					    'rows'   => "110,*",},});
1.331     albertel 1264:     my $end_page =
                   1265:         &Apache::loncommon::end_page({'frameset' => 1,
                   1266: 				      'js_ready' => 1,});
                   1267: 
1.436     albertel 1268:     my $template .= <<"ENDTEMPLATE";
                   1269: <script type="text/javascript">
1.877     bisitz   1270: // <![CDATA[
1.253     albertel 1271: // <!-- BEGIN LON-CAPA Internal
1.430     albertel 1272: var banner_link = '';
1.243     raeburn  1273: function helpMenu(target) {
                   1274:     var caller = this;
                   1275:     if (target == 'open') {
                   1276:         var newWindow = null;
                   1277:         try {
1.262     albertel 1278:             newWindow =  window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243     raeburn  1279:         }
                   1280:         catch(error) {
                   1281:             writeHelp(caller);
                   1282:             return;
                   1283:         }
                   1284:         if (newWindow) {
                   1285:             caller = newWindow;
                   1286:         }
1.193     raeburn  1287:     }
1.243     raeburn  1288:     writeHelp(caller);
                   1289:     return;
                   1290: }
                   1291: function writeHelp(caller) {
1.430     albertel 1292:     caller.document.writeln('$start_page<frame name="bannerframe"  src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243     raeburn  1293:     caller.document.close()
                   1294:     caller.focus()
1.193     raeburn  1295: }
1.877     bisitz   1296: // END LON-CAPA Internal -->
1.253     albertel 1297: // ]]>
1.436     albertel 1298: </script>
1.193     raeburn  1299: ENDTEMPLATE
                   1300:     return $template;
                   1301: }
                   1302: 
1.172     www      1303: sub help_open_bug {
                   1304:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1305:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1306:     unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
                   1307:     $text = "" if (not defined $text);
                   1308:     $stayOnPage = 0 if (not defined $stayOnPage);
1.798     tempelho 1309:     if ($env{'environment.remote'} eq 'off' ) {
1.172     www      1310: 	$stayOnPage=1;
                   1311:     }
1.184     albertel 1312:     $width = 600 if (not defined $width);
                   1313:     $height = 600 if (not defined $height);
1.172     www      1314: 
                   1315:     $topic=~s/\W+/\+/g;
                   1316:     my $link='';
                   1317:     my $template='';
1.379     albertel 1318:     my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&amp;bug_file_loc='.
                   1319: 	&escape($ENV{'REQUEST_URI'}).'&amp;component='.$topic;
1.172     www      1320:     if (!$stayOnPage)
                   1321:     {
                   1322: 	$link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1323:     }
                   1324:     else
                   1325:     {
                   1326: 	$link = $url;
                   1327:     }
                   1328:     # Add the text
                   1329:     if ($text ne "")
                   1330:     {
                   1331: 	$template .= 
                   1332:   "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1333:   "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172     www      1334:     }
                   1335: 
                   1336:     # Add the graphic
1.179     matthew  1337:     my $title = &mt('Report a Bug');
1.215     albertel 1338:     my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172     www      1339:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1340:  <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172     www      1341: ENDTEMPLATE
                   1342:     if ($text ne '') { $template.='</td></tr></table>' };
                   1343:     return $template;
                   1344: 
                   1345: }
                   1346: 
                   1347: sub help_open_faq {
                   1348:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1349:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1350:     unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
                   1351:     $text = "" if (not defined $text);
                   1352:     $stayOnPage = 0 if (not defined $stayOnPage);
1.798     tempelho 1353:     if ($env{'environment.remote'} eq 'off' ) {
1.172     www      1354: 	$stayOnPage=1;
                   1355:     }
                   1356:     $width = 350 if (not defined $width);
                   1357:     $height = 400 if (not defined $height);
                   1358: 
                   1359:     $topic=~s/\W+/\+/g;
                   1360:     my $link='';
                   1361:     my $template='';
                   1362:     my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
                   1363:     if (!$stayOnPage)
                   1364:     {
                   1365: 	$link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1366:     }
                   1367:     else
                   1368:     {
                   1369: 	$link = $url;
                   1370:     }
                   1371: 
                   1372:     # Add the text
                   1373:     if ($text ne "")
                   1374:     {
                   1375: 	$template .= 
1.173     www      1376:   "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1377:   "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172     www      1378:     }
                   1379: 
                   1380:     # Add the graphic
1.179     matthew  1381:     my $title = &mt('View the FAQ');
1.215     albertel 1382:     my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172     www      1383:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1384:  <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172     www      1385: ENDTEMPLATE
                   1386:     if ($text ne '') { $template.='</td></tr></table>' };
                   1387:     return $template;
                   1388: 
1.44      bowersj2 1389: }
1.37      matthew  1390: 
1.180     matthew  1391: ###############################################################
                   1392: ###############################################################
                   1393: 
1.45      matthew  1394: =pod
                   1395: 
1.648     raeburn  1396: =item * &change_content_javascript():
1.256     matthew  1397: 
                   1398: This and the next function allow you to create small sections of an
                   1399: otherwise static HTML page that you can update on the fly with
                   1400: Javascript, even in Netscape 4.
                   1401: 
                   1402: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
                   1403: must be written to the HTML page once. It will prove the Javascript
                   1404: function "change(name, content)". Calling the change function with the
                   1405: name of the section 
                   1406: you want to update, matching the name passed to C<changable_area>, and
                   1407: the new content you want to put in there, will put the content into
                   1408: that area.
                   1409: 
                   1410: B<Note>: Netscape 4 only reserves enough space for the changable area
                   1411: to contain room for the original contents. You need to "make space"
                   1412: for whatever changes you wish to make, and be B<sure> to check your
                   1413: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
                   1414: it's adequate for updating a one-line status display, but little more.
                   1415: This script will set the space to 100% width, so you only need to
                   1416: worry about height in Netscape 4.
                   1417: 
                   1418: Modern browsers are much less limiting, and if you can commit to the
                   1419: user not using Netscape 4, this feature may be used freely with
                   1420: pretty much any HTML.
                   1421: 
                   1422: =cut
                   1423: 
                   1424: sub change_content_javascript {
                   1425:     # If we're on Netscape 4, we need to use Layer-based code
1.258     albertel 1426:     if ($env{'browser.type'} eq 'netscape' &&
                   1427: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1428: 	return (<<NETSCAPE4);
                   1429: 	function change(name, content) {
                   1430: 	    doc = document.layers[name+"___escape"].layers[0].document;
                   1431: 	    doc.open();
                   1432: 	    doc.write(content);
                   1433: 	    doc.close();
                   1434: 	}
                   1435: NETSCAPE4
                   1436:     } else {
                   1437: 	# Otherwise, we need to use semi-standards-compliant code
                   1438: 	# (technically, "innerHTML" isn't standard but the equivalent
                   1439: 	# is really scary, and every useful browser supports it
                   1440: 	return (<<DOMBASED);
                   1441: 	function change(name, content) {
                   1442: 	    element = document.getElementById(name);
                   1443: 	    element.innerHTML = content;
                   1444: 	}
                   1445: DOMBASED
                   1446:     }
                   1447: }
                   1448: 
                   1449: =pod
                   1450: 
1.648     raeburn  1451: =item * &changable_area($name,$origContent):
1.256     matthew  1452: 
                   1453: This provides a "changable area" that can be modified on the fly via
                   1454: the Javascript code provided in C<change_content_javascript>. $name is
                   1455: the name you will use to reference the area later; do not repeat the
                   1456: same name on a given HTML page more then once. $origContent is what
                   1457: the area will originally contain, which can be left blank.
                   1458: 
                   1459: =cut
                   1460: 
                   1461: sub changable_area {
                   1462:     my ($name, $origContent) = @_;
                   1463: 
1.258     albertel 1464:     if ($env{'browser.type'} eq 'netscape' &&
                   1465: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1466: 	# If this is netscape 4, we need to use the Layer tag
                   1467: 	return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
                   1468:     } else {
                   1469: 	return "<span id='$name'>$origContent</span>";
                   1470:     }
                   1471: }
                   1472: 
                   1473: =pod
                   1474: 
1.648     raeburn  1475: =item * &viewport_geometry_js 
1.590     raeburn  1476: 
                   1477: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
                   1478: 
                   1479: =cut
                   1480: 
                   1481: 
                   1482: sub viewport_geometry_js { 
                   1483:     return <<"GEOMETRY";
                   1484: var Geometry = {};
                   1485: function init_geometry() {
                   1486:     if (Geometry.init) { return };
                   1487:     Geometry.init=1;
                   1488:     if (window.innerHeight) {
                   1489:         Geometry.getViewportHeight   = function() { return window.innerHeight; };
                   1490:         Geometry.getViewportWidth   = function() { return window.innerWidth; };
                   1491:         Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
                   1492:         Geometry.getVerticalScroll   = function() { return window.pageYOffset; };
                   1493:     }
                   1494:     else if (document.documentElement && document.documentElement.clientHeight) {
                   1495:         Geometry.getViewportHeight =
                   1496:             function() { return document.documentElement.clientHeight; };
                   1497:         Geometry.getViewportWidth =
                   1498:             function() { return document.documentElement.clientWidth; };
                   1499: 
                   1500:         Geometry.getHorizontalScroll =
                   1501:             function() { return document.documentElement.scrollLeft; };
                   1502:         Geometry.getVerticalScroll =
                   1503:             function() { return document.documentElement.scrollTop; };
                   1504:     }
                   1505:     else if (document.body.clientHeight) {
                   1506:         Geometry.getViewportHeight =
                   1507:             function() { return document.body.clientHeight; };
                   1508:         Geometry.getViewportWidth =
                   1509:             function() { return document.body.clientWidth; };
                   1510:         Geometry.getHorizontalScroll =
                   1511:             function() { return document.body.scrollLeft; };
                   1512:         Geometry.getVerticalScroll =
                   1513:             function() { return document.body.scrollTop; };
                   1514:     }
                   1515: }
                   1516: 
                   1517: GEOMETRY
                   1518: }
                   1519: 
                   1520: =pod
                   1521: 
1.648     raeburn  1522: =item * &viewport_size_js()
1.590     raeburn  1523: 
                   1524: 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. 
                   1525: 
                   1526: =cut
                   1527: 
                   1528: sub viewport_size_js {
                   1529:     my $geometry = &viewport_geometry_js();
                   1530:     return <<"DIMS";
                   1531: 
                   1532: $geometry
                   1533: 
                   1534: function getViewportDims(width,height) {
                   1535:     init_geometry();
                   1536:     width.value = Geometry.getViewportWidth();
                   1537:     height.value = Geometry.getViewportHeight();
                   1538:     return;
                   1539: }
                   1540: 
                   1541: DIMS
                   1542: }
                   1543: 
                   1544: =pod
                   1545: 
1.648     raeburn  1546: =item * &resize_textarea_js()
1.565     albertel 1547: 
                   1548: emits the needed javascript to resize a textarea to be as big as possible
                   1549: 
                   1550: creates a function resize_textrea that takes two IDs first should be
                   1551: the id of the element to resize, second should be the id of a div that
                   1552: surrounds everything that comes after the textarea, this routine needs
                   1553: to be attached to the <body> for the onload and onresize events.
                   1554: 
1.648     raeburn  1555: =back
1.565     albertel 1556: 
                   1557: =cut
                   1558: 
                   1559: sub resize_textarea_js {
1.590     raeburn  1560:     my $geometry = &viewport_geometry_js();
1.565     albertel 1561:     return <<"RESIZE";
                   1562:     <script type="text/javascript">
1.824     bisitz   1563: // <![CDATA[
1.590     raeburn  1564: $geometry
1.565     albertel 1565: 
1.588     albertel 1566: function getX(element) {
                   1567:     var x = 0;
                   1568:     while (element) {
                   1569: 	x += element.offsetLeft;
                   1570: 	element = element.offsetParent;
                   1571:     }
                   1572:     return x;
                   1573: }
                   1574: function getY(element) {
                   1575:     var y = 0;
                   1576:     while (element) {
                   1577: 	y += element.offsetTop;
                   1578: 	element = element.offsetParent;
                   1579:     }
                   1580:     return y;
                   1581: }
                   1582: 
                   1583: 
1.565     albertel 1584: function resize_textarea(textarea_id,bottom_id) {
                   1585:     init_geometry();
                   1586:     var textarea        = document.getElementById(textarea_id);
                   1587:     //alert(textarea);
                   1588: 
1.588     albertel 1589:     var textarea_top    = getY(textarea);
1.565     albertel 1590:     var textarea_height = textarea.offsetHeight;
                   1591:     var bottom          = document.getElementById(bottom_id);
1.588     albertel 1592:     var bottom_top      = getY(bottom);
1.565     albertel 1593:     var bottom_height   = bottom.offsetHeight;
                   1594:     var window_height   = Geometry.getViewportHeight();
1.588     albertel 1595:     var fudge           = 23;
1.565     albertel 1596:     var new_height      = window_height-fudge-textarea_top-bottom_height;
                   1597:     if (new_height < 300) {
                   1598: 	new_height = 300;
                   1599:     }
                   1600:     textarea.style.height=new_height+'px';
                   1601: }
1.824     bisitz   1602: // ]]>
1.565     albertel 1603: </script>
                   1604: RESIZE
                   1605: 
                   1606: }
                   1607: 
                   1608: =pod
                   1609: 
1.256     matthew  1610: =head1 Excel and CSV file utility routines
                   1611: 
                   1612: =over 4
                   1613: 
                   1614: =cut
                   1615: 
                   1616: ###############################################################
                   1617: ###############################################################
                   1618: 
                   1619: =pod
                   1620: 
1.648     raeburn  1621: =item * &csv_translate($text) 
1.37      matthew  1622: 
1.185     www      1623: Translate $text to allow it to be output as a 'comma separated values' 
1.37      matthew  1624: format.
                   1625: 
                   1626: =cut
                   1627: 
1.180     matthew  1628: ###############################################################
                   1629: ###############################################################
1.37      matthew  1630: sub csv_translate {
                   1631:     my $text = shift;
                   1632:     $text =~ s/\"/\"\"/g;
1.209     albertel 1633:     $text =~ s/\n/ /g;
1.37      matthew  1634:     return $text;
                   1635: }
1.180     matthew  1636: 
                   1637: ###############################################################
                   1638: ###############################################################
                   1639: 
                   1640: =pod
                   1641: 
1.648     raeburn  1642: =item * &define_excel_formats()
1.180     matthew  1643: 
                   1644: Define some commonly used Excel cell formats.
                   1645: 
                   1646: Currently supported formats:
                   1647: 
                   1648: =over 4
                   1649: 
                   1650: =item header
                   1651: 
                   1652: =item bold
                   1653: 
                   1654: =item h1
                   1655: 
                   1656: =item h2
                   1657: 
                   1658: =item h3
                   1659: 
1.256     matthew  1660: =item h4
                   1661: 
                   1662: =item i
                   1663: 
1.180     matthew  1664: =item date
                   1665: 
                   1666: =back
                   1667: 
                   1668: Inputs: $workbook
                   1669: 
                   1670: Returns: $format, a hash reference.
                   1671: 
                   1672: =cut
                   1673: 
                   1674: ###############################################################
                   1675: ###############################################################
                   1676: sub define_excel_formats {
                   1677:     my ($workbook) = @_;
                   1678:     my $format;
                   1679:     $format->{'header'} = $workbook->add_format(bold      => 1, 
                   1680:                                                 bottom    => 1,
                   1681:                                                 align     => 'center');
                   1682:     $format->{'bold'} = $workbook->add_format(bold=>1);
                   1683:     $format->{'h1'}   = $workbook->add_format(bold=>1, size=>18);
                   1684:     $format->{'h2'}   = $workbook->add_format(bold=>1, size=>16);
                   1685:     $format->{'h3'}   = $workbook->add_format(bold=>1, size=>14);
1.255     matthew  1686:     $format->{'h4'}   = $workbook->add_format(bold=>1, size=>12);
1.246     matthew  1687:     $format->{'i'}    = $workbook->add_format(italic=>1);
1.180     matthew  1688:     $format->{'date'} = $workbook->add_format(num_format=>
1.207     matthew  1689:                                             'mm/dd/yyyy hh:mm:ss');
1.180     matthew  1690:     return $format;
                   1691: }
                   1692: 
                   1693: ###############################################################
                   1694: ###############################################################
1.113     bowersj2 1695: 
                   1696: =pod
                   1697: 
1.648     raeburn  1698: =item * &create_workbook()
1.255     matthew  1699: 
                   1700: Create an Excel worksheet.  If it fails, output message on the
                   1701: request object and return undefs.
                   1702: 
                   1703: Inputs: Apache request object
                   1704: 
                   1705: Returns (undef) on failure, 
                   1706:     Excel worksheet object, scalar with filename, and formats 
                   1707:     from &Apache::loncommon::define_excel_formats on success
                   1708: 
                   1709: =cut
                   1710: 
                   1711: ###############################################################
                   1712: ###############################################################
                   1713: sub create_workbook {
                   1714:     my ($r) = @_;
                   1715:         #
                   1716:     # Create the excel spreadsheet
                   1717:     my $filename = '/prtspool/'.
1.258     albertel 1718:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255     matthew  1719:         time.'_'.rand(1000000000).'.xls';
                   1720:     my $workbook  = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
                   1721:     if (! defined($workbook)) {
                   1722:         $r->log_error("Error creating excel spreadsheet $filename: $!");
                   1723:         $r->print('<p>'.&mt("Unable to create new Excel file.  ".
                   1724:                             "This error has been logged.  ".
                   1725:                             "Please alert your LON-CAPA administrator").
                   1726:                   '</p>');
                   1727:         return (undef);
                   1728:     }
                   1729:     #
                   1730:     $workbook->set_tempdir('/home/httpd/perl/tmp');
                   1731:     #
                   1732:     my $format = &Apache::loncommon::define_excel_formats($workbook);
                   1733:     return ($workbook,$filename,$format);
                   1734: }
                   1735: 
                   1736: ###############################################################
                   1737: ###############################################################
                   1738: 
                   1739: =pod
                   1740: 
1.648     raeburn  1741: =item * &create_text_file()
1.113     bowersj2 1742: 
1.542     raeburn  1743: Create a file to write to and eventually make available to the user.
1.256     matthew  1744: If file creation fails, outputs an error message on the request object and 
                   1745: return undefs.
1.113     bowersj2 1746: 
1.256     matthew  1747: Inputs: Apache request object, and file suffix
1.113     bowersj2 1748: 
1.256     matthew  1749: Returns (undef) on failure, 
                   1750:     Filehandle and filename on success.
1.113     bowersj2 1751: 
                   1752: =cut
                   1753: 
1.256     matthew  1754: ###############################################################
                   1755: ###############################################################
                   1756: sub create_text_file {
                   1757:     my ($r,$suffix) = @_;
                   1758:     if (! defined($suffix)) { $suffix = 'txt'; };
                   1759:     my $fh;
                   1760:     my $filename = '/prtspool/'.
1.258     albertel 1761:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256     matthew  1762:         time.'_'.rand(1000000000).'.'.$suffix;
                   1763:     $fh = Apache::File->new('>/home/httpd'.$filename);
                   1764:     if (! defined($fh)) {
                   1765:         $r->log_error("Couldn't open $filename for output $!");
1.683     bisitz   1766:         $r->print(&mt('Problems occurred in creating the output file. '
                   1767:                      .'This error has been logged. '
                   1768:                      .'Please alert your LON-CAPA administrator.'));
1.113     bowersj2 1769:     }
1.256     matthew  1770:     return ($fh,$filename)
1.113     bowersj2 1771: }
                   1772: 
                   1773: 
1.256     matthew  1774: =pod 
1.113     bowersj2 1775: 
                   1776: =back
                   1777: 
                   1778: =cut
1.37      matthew  1779: 
                   1780: ###############################################################
1.33      matthew  1781: ##        Home server <option> list generating code          ##
                   1782: ###############################################################
1.35      matthew  1783: 
1.169     www      1784: # ------------------------------------------
                   1785: 
                   1786: sub domain_select {
                   1787:     my ($name,$value,$multiple)=@_;
                   1788:     my %domains=map { 
1.514     albertel 1789: 	$_ => $_.' '. &Apache::lonnet::domain($_,'description') 
1.512     albertel 1790:     } &Apache::lonnet::all_domains();
1.169     www      1791:     if ($multiple) {
                   1792: 	$domains{''}=&mt('Any domain');
1.550     albertel 1793: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287     albertel 1794: 	return &multiple_select_form($name,$value,4,\%domains);
1.169     www      1795:     } else {
1.550     albertel 1796: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169     www      1797: 	return &select_form($name,$value,%domains);
                   1798:     }
                   1799: }
                   1800: 
1.282     albertel 1801: #-------------------------------------------
                   1802: 
                   1803: =pod
                   1804: 
1.519     raeburn  1805: =head1 Routines for form select boxes
                   1806: 
                   1807: =over 4
                   1808: 
1.648     raeburn  1809: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282     albertel 1810: 
                   1811: Returns a string containing a <select> element int multiple mode
                   1812: 
                   1813: 
                   1814: Args:
                   1815:   $name - name of the <select> element
1.506     raeburn  1816:   $value - scalar or array ref of values that should already be selected
1.282     albertel 1817:   $size - number of rows long the select element is
1.283     albertel 1818:   $hash - the elements should be 'option' => 'shown text'
1.282     albertel 1819:           (shown text should already have been &mt())
1.506     raeburn  1820:   $order - (optional) array ref of the order to show the elements in
1.283     albertel 1821: 
1.282     albertel 1822: =cut
                   1823: 
                   1824: #-------------------------------------------
1.169     www      1825: sub multiple_select_form {
1.284     albertel 1826:     my ($name,$value,$size,$hash,$order)=@_;
1.169     www      1827:     my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
                   1828:     my $output='';
1.191     matthew  1829:     if (! defined($size)) {
                   1830:         $size = 4;
1.283     albertel 1831:         if (scalar(keys(%$hash))<4) {
                   1832:             $size = scalar(keys(%$hash));
1.191     matthew  1833:         }
                   1834:     }
1.734     bisitz   1835:     $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501     banghart 1836:     my @order;
1.506     raeburn  1837:     if (ref($order) eq 'ARRAY')  {
                   1838:         @order = @{$order};
                   1839:     } else {
                   1840:         @order = sort(keys(%$hash));
1.501     banghart 1841:     }
                   1842:     if (exists($$hash{'select_form_order'})) {
                   1843:         @order = @{$$hash{'select_form_order'}};
                   1844:     }
                   1845:         
1.284     albertel 1846:     foreach my $key (@order) {
1.356     albertel 1847:         $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284     albertel 1848:         $output.='selected="selected" ' if ($selected{$key});
                   1849:         $output.='>'.$hash->{$key}."</option>\n";
1.169     www      1850:     }
                   1851:     $output.="</select>\n";
                   1852:     return $output;
                   1853: }
                   1854: 
1.88      www      1855: #-------------------------------------------
                   1856: 
                   1857: =pod
                   1858: 
1.648     raeburn  1859: =item * &select_form($defdom,$name,%hash)
1.88      www      1860: 
                   1861: Returns a string containing a <select name='$name' size='1'> form to 
                   1862: allow a user to select options from a hash option_name => displayed text.  
                   1863: See lonrights.pm for an example invocation and use.
                   1864: 
                   1865: =cut
                   1866: 
                   1867: #-------------------------------------------
                   1868: sub select_form {
                   1869:     my ($def,$name,%hash) = @_;
                   1870:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128     albertel 1871:     my @keys;
                   1872:     if (exists($hash{'select_form_order'})) {
                   1873: 	@keys=@{$hash{'select_form_order'}};
                   1874:     } else {
                   1875: 	@keys=sort(keys(%hash));
                   1876:     }
1.356     albertel 1877:     foreach my $key (@keys) {
                   1878:         $selectform.=
                   1879: 	    '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
                   1880:             ($key eq $def ? 'selected="selected" ' : '').
                   1881:                 ">".&mt($hash{$key})."</option>\n";
1.88      www      1882:     }
                   1883:     $selectform.="</select>";
                   1884:     return $selectform;
                   1885: }
                   1886: 
1.475     www      1887: # For display filters
                   1888: 
                   1889: sub display_filter {
                   1890:     if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477     www      1891:     if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714     bisitz   1892:     return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475     www      1893: 			       &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
                   1894: 							   (&mt('all'),10,20,50,100,1000,10000))).
1.714     bisitz   1895: 	   '</label></span> <span class="LC_nobreak">'.
1.475     www      1896:            &mt('Filter [_1]',
1.477     www      1897: 	   &select_form($env{'form.displayfilter'},
                   1898: 			'displayfilter',
                   1899: 			('currentfolder' => 'Current folder/page',
                   1900: 			 'containing' => 'Containing phrase',
                   1901: 			 'none' => 'None'))).
1.714     bisitz   1902: 			 '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475     www      1903: }
                   1904: 
1.167     www      1905: sub gradeleveldescription {
                   1906:     my $gradelevel=shift;
                   1907:     my %gradelevels=(0 => 'Not specified',
                   1908: 		     1 => 'Grade 1',
                   1909: 		     2 => 'Grade 2',
                   1910: 		     3 => 'Grade 3',
                   1911: 		     4 => 'Grade 4',
                   1912: 		     5 => 'Grade 5',
                   1913: 		     6 => 'Grade 6',
                   1914: 		     7 => 'Grade 7',
                   1915: 		     8 => 'Grade 8',
                   1916: 		     9 => 'Grade 9',
                   1917: 		     10 => 'Grade 10',
                   1918: 		     11 => 'Grade 11',
                   1919: 		     12 => 'Grade 12',
                   1920: 		     13 => 'Grade 13',
                   1921: 		     14 => '100 Level',
                   1922: 		     15 => '200 Level',
                   1923: 		     16 => '300 Level',
                   1924: 		     17 => '400 Level',
                   1925: 		     18 => 'Graduate Level');
                   1926:     return &mt($gradelevels{$gradelevel});
                   1927: }
                   1928: 
1.163     www      1929: sub select_level_form {
                   1930:     my ($deflevel,$name)=@_;
                   1931:     unless ($deflevel) { $deflevel=0; }
1.167     www      1932:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
                   1933:     for (my $i=0; $i<=18; $i++) {
                   1934:         $selectform.="<option value=\"$i\" ".
1.253     albertel 1935:             ($i==$deflevel ? 'selected="selected" ' : '').
1.167     www      1936:                 ">".&gradeleveldescription($i)."</option>\n";
                   1937:     }
                   1938:     $selectform.="</select>";
                   1939:     return $selectform;
1.163     www      1940: }
1.167     www      1941: 
1.35      matthew  1942: #-------------------------------------------
                   1943: 
1.45      matthew  1944: =pod
                   1945: 
1.873     raeburn  1946: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange)
1.35      matthew  1947: 
                   1948: Returns a string containing a <select name='$name' size='1'> form to 
                   1949: allow a user to select the domain to preform an operation in.  
                   1950: See loncreateuser.pm for an example invocation and use.
                   1951: 
1.90      www      1952: If the $includeempty flag is set, it also includes an empty choice ("no domain
                   1953: selected");
                   1954: 
1.743     raeburn  1955: If the $showdomdesc flag is set, the domain name is followed by the domain description.
                   1956: 
1.872     raeburn  1957: 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  1958: 
1.35      matthew  1959: =cut
                   1960: 
                   1961: #-------------------------------------------
1.34      matthew  1962: sub select_dom_form {
1.872     raeburn  1963:     my ($defdom,$name,$includeempty,$showdomdesc,$onchange) = @_;
                   1964:     if ($onchange) {
1.874     raeburn  1965:         $onchange = ' onchange="'.$onchange.'"';
1.743     raeburn  1966:     }
1.550     albertel 1967:     my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90      www      1968:     if ($includeempty) { @domains=('',@domains); }
1.743     raeburn  1969:     my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356     albertel 1970:     foreach my $dom (@domains) {
                   1971:         $selectdomain.="<option value=\"$dom\" ".
1.563     raeburn  1972:             ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
                   1973:         if ($showdomdesc) {
                   1974:             if ($dom ne '') {
                   1975:                 my $domdesc = &Apache::lonnet::domain($dom,'description');
                   1976:                 if ($domdesc ne '') {
                   1977:                     $selectdomain .= ' ('.$domdesc.')';
                   1978:                 }
                   1979:             } 
                   1980:         }
                   1981:         $selectdomain .= "</option>\n";
1.34      matthew  1982:     }
                   1983:     $selectdomain.="</select>";
                   1984:     return $selectdomain;
                   1985: }
                   1986: 
1.35      matthew  1987: #-------------------------------------------
                   1988: 
1.45      matthew  1989: =pod
                   1990: 
1.648     raeburn  1991: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35      matthew  1992: 
1.586     raeburn  1993: input: 4 arguments (two required, two optional) - 
                   1994:     $domain - domain of new user
                   1995:     $name - name of form element
                   1996:     $default - Value of 'default' causes a default item to be first 
                   1997:                             option, and selected by default. 
                   1998:     $hide - Value of 'hide' causes hiding of the name of the server, 
                   1999:                             if 1 server found, or default, if 0 found.
1.594     raeburn  2000: output: returns 2 items: 
1.586     raeburn  2001: (a) form element which contains either:
                   2002:    (i) <select name="$name">
                   2003:         <option value="$hostid1">$hostid $servers{$hostid}</option>
                   2004:         <option value="$hostid2">$hostid $servers{$hostid}</option>       
                   2005:        </select>
                   2006:        form item if there are multiple library servers in $domain, or
                   2007:    (ii) an <input type="hidden" name="$name" value="$hostid" /> form item 
                   2008:        if there is only one library server in $domain.
                   2009: 
                   2010: (b) number of library servers found.
                   2011: 
                   2012: See loncreateuser.pm for example of use.
1.35      matthew  2013: 
                   2014: =cut
                   2015: 
                   2016: #-------------------------------------------
1.586     raeburn  2017: sub home_server_form_item {
                   2018:     my ($domain,$name,$default,$hide) = @_;
1.513     albertel 2019:     my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586     raeburn  2020:     my $result;
                   2021:     my $numlib = keys(%servers);
                   2022:     if ($numlib > 1) {
                   2023:         $result .= '<select name="'.$name.'" />'."\n";
                   2024:         if ($default) {
1.804     bisitz   2025:             $result .= '<option value="default" selected="selected">'.&mt('default').
1.586     raeburn  2026:                        '</option>'."\n";
                   2027:         }
                   2028:         foreach my $hostid (sort(keys(%servers))) {
                   2029:             $result.= '<option value="'.$hostid.'">'.
                   2030: 	              $hostid.' '.$servers{$hostid}."</option>\n";
                   2031:         }
                   2032:         $result .= '</select>'."\n";
                   2033:     } elsif ($numlib == 1) {
                   2034:         my $hostid;
                   2035:         foreach my $item (keys(%servers)) {
                   2036:             $hostid = $item;
                   2037:         }
                   2038:         $result .= '<input type="hidden" name="'.$name.'" value="'.
                   2039:                    $hostid.'" />';
                   2040:                    if (!$hide) {
                   2041:                        $result .= $hostid.' '.$servers{$hostid};
                   2042:                    }
                   2043:                    $result .= "\n";
                   2044:     } elsif ($default) {
                   2045:         $result .= '<input type="hidden" name="'.$name.
                   2046:                    '" value="default" />';
                   2047:                    if (!$hide) {
                   2048:                        $result .= &mt('default');
                   2049:                    }
                   2050:                    $result .= "\n";
1.33      matthew  2051:     }
1.586     raeburn  2052:     return ($result,$numlib);
1.33      matthew  2053: }
1.112     bowersj2 2054: 
                   2055: =pod
                   2056: 
1.534     albertel 2057: =back 
                   2058: 
1.112     bowersj2 2059: =cut
1.87      matthew  2060: 
                   2061: ###############################################################
1.112     bowersj2 2062: ##                  Decoding User Agent                      ##
1.87      matthew  2063: ###############################################################
                   2064: 
                   2065: =pod
                   2066: 
1.112     bowersj2 2067: =head1 Decoding the User Agent
                   2068: 
                   2069: =over 4
                   2070: 
                   2071: =item * &decode_user_agent()
1.87      matthew  2072: 
                   2073: Inputs: $r
                   2074: 
                   2075: Outputs:
                   2076: 
                   2077: =over 4
                   2078: 
1.112     bowersj2 2079: =item * $httpbrowser
1.87      matthew  2080: 
1.112     bowersj2 2081: =item * $clientbrowser
1.87      matthew  2082: 
1.112     bowersj2 2083: =item * $clientversion
1.87      matthew  2084: 
1.112     bowersj2 2085: =item * $clientmathml
1.87      matthew  2086: 
1.112     bowersj2 2087: =item * $clientunicode
1.87      matthew  2088: 
1.112     bowersj2 2089: =item * $clientos
1.87      matthew  2090: 
                   2091: =back
                   2092: 
1.157     matthew  2093: =back 
                   2094: 
1.87      matthew  2095: =cut
                   2096: 
                   2097: ###############################################################
                   2098: ###############################################################
                   2099: sub decode_user_agent {
1.247     albertel 2100:     my ($r)=@_;
1.87      matthew  2101:     my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
                   2102:     my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
                   2103:     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247     albertel 2104:     if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87      matthew  2105:     my $clientbrowser='unknown';
                   2106:     my $clientversion='0';
                   2107:     my $clientmathml='';
                   2108:     my $clientunicode='0';
                   2109:     for (my $i=0;$i<=$#browsertype;$i++) {
                   2110:         my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
                   2111: 	if (($httpbrowser=~/$match/i)  && ($httpbrowser!~/$notmatch/i)) {
                   2112: 	    $clientbrowser=$bname;
                   2113:             $httpbrowser=~/$vreg/i;
                   2114: 	    $clientversion=$1;
                   2115:             $clientmathml=($clientversion>=$minv);
                   2116:             $clientunicode=($clientversion>=$univ);
                   2117: 	}
                   2118:     }
                   2119:     my $clientos='unknown';
                   2120:     if (($httpbrowser=~/linux/i) ||
                   2121:         ($httpbrowser=~/unix/i) ||
                   2122:         ($httpbrowser=~/ux/i) ||
                   2123:         ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
                   2124:     if (($httpbrowser=~/vax/i) ||
                   2125:         ($httpbrowser=~/vms/i)) { $clientos='vms'; }
                   2126:     if ($httpbrowser=~/next/i) { $clientos='next'; }
                   2127:     if (($httpbrowser=~/mac/i) ||
                   2128:         ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
                   2129:     if ($httpbrowser=~/win/i) { $clientos='win'; }
                   2130:     if ($httpbrowser=~/embed/i) { $clientos='pda'; }
                   2131:     return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   2132:             $clientunicode,$clientos,);
                   2133: }
                   2134: 
1.32      matthew  2135: ###############################################################
                   2136: ##    Authentication changing form generation subroutines    ##
                   2137: ###############################################################
                   2138: ##
                   2139: ## All of the authform_xxxxxxx subroutines take their inputs in a
                   2140: ## hash, and have reasonable default values.
                   2141: ##
                   2142: ##    formname = the name given in the <form> tag.
1.35      matthew  2143: #-------------------------------------------
                   2144: 
1.45      matthew  2145: =pod
                   2146: 
1.112     bowersj2 2147: =head1 Authentication Routines
                   2148: 
                   2149: =over 4
                   2150: 
1.648     raeburn  2151: =item * &authform_xxxxxx()
1.35      matthew  2152: 
                   2153: The authform_xxxxxx subroutines provide javascript and html forms which 
                   2154: handle some of the conveniences required for authentication forms.  
                   2155: This is not an optimal method, but it works.  
                   2156: 
                   2157: =over 4
                   2158: 
1.112     bowersj2 2159: =item * authform_header
1.35      matthew  2160: 
1.112     bowersj2 2161: =item * authform_authorwarning
1.35      matthew  2162: 
1.112     bowersj2 2163: =item * authform_nochange
1.35      matthew  2164: 
1.112     bowersj2 2165: =item * authform_kerberos
1.35      matthew  2166: 
1.112     bowersj2 2167: =item * authform_internal
1.35      matthew  2168: 
1.112     bowersj2 2169: =item * authform_filesystem
1.35      matthew  2170: 
                   2171: =back
                   2172: 
1.648     raeburn  2173: See loncreateuser.pm for invocation and use examples.
1.157     matthew  2174: 
1.35      matthew  2175: =cut
                   2176: 
                   2177: #-------------------------------------------
1.32      matthew  2178: sub authform_header{  
                   2179:     my %in = (
                   2180:         formname => 'cu',
1.80      albertel 2181:         kerb_def_dom => '',
1.32      matthew  2182:         @_,
                   2183:     );
                   2184:     $in{'formname'} = 'document.' . $in{'formname'};
                   2185:     my $result='';
1.80      albertel 2186: 
                   2187: #---------------------------------------------- Code for upper case translation
                   2188:     my $Javascript_toUpperCase;
                   2189:     unless ($in{kerb_def_dom}) {
                   2190:         $Javascript_toUpperCase =<<"END";
                   2191:         switch (choice) {
                   2192:            case 'krb': currentform.elements[choicearg].value =
                   2193:                currentform.elements[choicearg].value.toUpperCase();
                   2194:                break;
                   2195:            default:
                   2196:         }
                   2197: END
                   2198:     } else {
                   2199:         $Javascript_toUpperCase = "";
                   2200:     }
                   2201: 
1.165     raeburn  2202:     my $radioval = "'nochange'";
1.591     raeburn  2203:     if (defined($in{'curr_authtype'})) {
                   2204:         if ($in{'curr_authtype'} ne '') {
                   2205:             $radioval = "'".$in{'curr_authtype'}."arg'";
                   2206:         }
1.174     matthew  2207:     }
1.165     raeburn  2208:     my $argfield = 'null';
1.591     raeburn  2209:     if (defined($in{'mode'})) {
1.165     raeburn  2210:         if ($in{'mode'} eq 'modifycourse')  {
1.591     raeburn  2211:             if (defined($in{'curr_autharg'})) {
                   2212:                 if ($in{'curr_autharg'} ne '') {
1.165     raeburn  2213:                     $argfield = "'$in{'curr_autharg'}'";
                   2214:                 }
                   2215:             }
                   2216:         }
                   2217:     }
                   2218: 
1.32      matthew  2219:     $result.=<<"END";
                   2220: var current = new Object();
1.165     raeburn  2221: current.radiovalue = $radioval;
                   2222: current.argfield = $argfield;
1.32      matthew  2223: 
                   2224: function changed_radio(choice,currentform) {
                   2225:     var choicearg = choice + 'arg';
                   2226:     // If a radio button in changed, we need to change the argfield
                   2227:     if (current.radiovalue != choice) {
                   2228:         current.radiovalue = choice;
                   2229:         if (current.argfield != null) {
                   2230:             currentform.elements[current.argfield].value = '';
                   2231:         }
                   2232:         if (choice == 'nochange') {
                   2233:             current.argfield = null;
                   2234:         } else {
                   2235:             current.argfield = choicearg;
                   2236:             switch(choice) {
                   2237:                 case 'krb': 
                   2238:                     currentform.elements[current.argfield].value = 
                   2239:                         "$in{'kerb_def_dom'}";
                   2240:                 break;
                   2241:               default:
                   2242:                 break;
                   2243:             }
                   2244:         }
                   2245:     }
                   2246:     return;
                   2247: }
1.22      www      2248: 
1.32      matthew  2249: function changed_text(choice,currentform) {
                   2250:     var choicearg = choice + 'arg';
                   2251:     if (currentform.elements[choicearg].value !='') {
1.80      albertel 2252:         $Javascript_toUpperCase
1.32      matthew  2253:         // clear old field
                   2254:         if ((current.argfield != choicearg) && (current.argfield != null)) {
                   2255:             currentform.elements[current.argfield].value = '';
                   2256:         }
                   2257:         current.argfield = choicearg;
                   2258:     }
                   2259:     set_auth_radio_buttons(choice,currentform);
                   2260:     return;
1.20      www      2261: }
1.32      matthew  2262: 
                   2263: function set_auth_radio_buttons(newvalue,currentform) {
                   2264:     var i=0;
                   2265:     while (i < currentform.login.length) {
                   2266:         if (currentform.login[i].value == newvalue) { break; }
                   2267:         i++;
                   2268:     }
                   2269:     if (i == currentform.login.length) {
                   2270:         return;
                   2271:     }
                   2272:     current.radiovalue = newvalue;
                   2273:     currentform.login[i].checked = true;
                   2274:     return;
                   2275: }
                   2276: END
                   2277:     return $result;
                   2278: }
                   2279: 
                   2280: sub authform_authorwarning{
                   2281:     my $result='';
1.144     matthew  2282:     $result='<i>'.
                   2283:         &mt('As a general rule, only authors or co-authors should be '.
                   2284:             'filesystem authenticated '.
                   2285:             '(which allows access to the server filesystem).')."</i>\n";
1.32      matthew  2286:     return $result;
                   2287: }
                   2288: 
                   2289: sub authform_nochange{  
                   2290:     my %in = (
                   2291:               formname => 'document.cu',
                   2292:               kerb_def_dom => 'MSU.EDU',
                   2293:               @_,
                   2294:           );
1.586     raeburn  2295:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'}); 
                   2296:     my $result;
                   2297:     if (keys(%can_assign) == 0) {
                   2298:         $result = &mt('Under you current role you are not permitted to change login settings for this user');  
                   2299:     } else {
                   2300:         $result = '<label>'.&mt('[_1] Do not change login data',
                   2301:                   '<input type="radio" name="login" value="nochange" '.
                   2302:                   'checked="checked" onclick="'.
1.281     albertel 2303:             "javascript:changed_radio('nochange',$in{'formname'});".'" />').
                   2304: 	    '</label>';
1.586     raeburn  2305:     }
1.32      matthew  2306:     return $result;
                   2307: }
                   2308: 
1.591     raeburn  2309: sub authform_kerberos {
1.32      matthew  2310:     my %in = (
                   2311:               formname => 'document.cu',
                   2312:               kerb_def_dom => 'MSU.EDU',
1.80      albertel 2313:               kerb_def_auth => 'krb4',
1.32      matthew  2314:               @_,
                   2315:               );
1.586     raeburn  2316:     my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
                   2317:         $autharg,$jscall);
                   2318:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.80      albertel 2319:     if ($in{'kerb_def_auth'} eq 'krb5') {
1.772     bisitz   2320:        $check5 = ' checked="checked"';
1.80      albertel 2321:     } else {
1.772     bisitz   2322:        $check4 = ' checked="checked"';
1.80      albertel 2323:     }
1.165     raeburn  2324:     $krbarg = $in{'kerb_def_dom'};
1.591     raeburn  2325:     if (defined($in{'curr_authtype'})) {
                   2326:         if ($in{'curr_authtype'} eq 'krb') {
1.772     bisitz   2327:             $krbcheck = ' checked="checked"';
1.623     raeburn  2328:             if (defined($in{'mode'})) {
                   2329:                 if ($in{'mode'} eq 'modifyuser') {
                   2330:                     $krbcheck = '';
                   2331:                 }
                   2332:             }
1.591     raeburn  2333:             if (defined($in{'curr_kerb_ver'})) {
                   2334:                 if ($in{'curr_krb_ver'} eq '5') {
1.772     bisitz   2335:                     $check5 = ' checked="checked"';
1.591     raeburn  2336:                     $check4 = '';
                   2337:                 } else {
1.772     bisitz   2338:                     $check4 = ' checked="checked"';
1.591     raeburn  2339:                     $check5 = '';
                   2340:                 }
1.586     raeburn  2341:             }
1.591     raeburn  2342:             if (defined($in{'curr_autharg'})) {
1.165     raeburn  2343:                 $krbarg = $in{'curr_autharg'};
                   2344:             }
1.586     raeburn  2345:             if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591     raeburn  2346:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2347:                     $result = 
                   2348:     &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
                   2349:         $in{'curr_autharg'},$krbver);
                   2350:                 } else {
                   2351:                     $result =
                   2352:     &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
                   2353:                 }
                   2354:                 return $result; 
                   2355:             }
                   2356:         }
                   2357:     } else {
                   2358:         if ($authnum == 1) {
1.784     bisitz   2359:             $authtype = '<input type="hidden" name="login" value="krb" />';
1.165     raeburn  2360:         }
                   2361:     }
1.586     raeburn  2362:     if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
                   2363:         return;
1.587     raeburn  2364:     } elsif ($authtype eq '') {
1.591     raeburn  2365:         if (defined($in{'mode'})) {
1.587     raeburn  2366:             if ($in{'mode'} eq 'modifycourse') {
                   2367:                 if ($authnum == 1) {
1.784     bisitz   2368:                     $authtype = '<input type="hidden" name="login" value="krb" />';
1.587     raeburn  2369:                 }
                   2370:             }
                   2371:         }
1.586     raeburn  2372:     }
                   2373:     $jscall = "javascript:changed_radio('krb',$in{'formname'});";
                   2374:     if ($authtype eq '') {
                   2375:         $authtype = '<input type="radio" name="login" value="krb" '.
                   2376:                     'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
                   2377:                     $krbcheck.' />';
                   2378:     }
                   2379:     if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
                   2380:         ($can_assign{'krb4'} && !$can_assign{'krb5'} && 
                   2381:          $in{'curr_authtype'} eq 'krb5') ||
                   2382:         (!$can_assign{'krb4'} && $can_assign{'krb5'} && 
                   2383:          $in{'curr_authtype'} eq 'krb4')) {
                   2384:         $result .= &mt
1.144     matthew  2385:         ('[_1] Kerberos authenticated with domain [_2] '.
1.281     albertel 2386:          '[_3] Version 4 [_4] Version 5 [_5]',
1.586     raeburn  2387:          '<label>'.$authtype,
1.281     albertel 2388:          '</label><input type="text" size="10" name="krbarg" '.
1.165     raeburn  2389:              'value="'.$krbarg.'" '.
1.144     matthew  2390:              'onchange="'.$jscall.'" />',
1.281     albertel 2391:          '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
                   2392:          '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
                   2393: 	 '</label>');
1.586     raeburn  2394:     } elsif ($can_assign{'krb4'}) {
                   2395:         $result .= &mt
                   2396:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2397:          '[_3] Version 4 [_4]',
                   2398:          '<label>'.$authtype,
                   2399:          '</label><input type="text" size="10" name="krbarg" '.
                   2400:              'value="'.$krbarg.'" '.
                   2401:              'onchange="'.$jscall.'" />',
                   2402:          '<label><input type="hidden" name="krbver" value="4" />',
                   2403:          '</label>');
                   2404:     } elsif ($can_assign{'krb5'}) {
                   2405:         $result .= &mt
                   2406:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2407:          '[_3] Version 5 [_4]',
                   2408:          '<label>'.$authtype,
                   2409:          '</label><input type="text" size="10" name="krbarg" '.
                   2410:              'value="'.$krbarg.'" '.
                   2411:              'onchange="'.$jscall.'" />',
                   2412:          '<label><input type="hidden" name="krbver" value="5" />',
                   2413:          '</label>');
                   2414:     }
1.32      matthew  2415:     return $result;
                   2416: }
                   2417: 
                   2418: sub authform_internal{  
1.586     raeburn  2419:     my %in = (
1.32      matthew  2420:                 formname => 'document.cu',
                   2421:                 kerb_def_dom => 'MSU.EDU',
                   2422:                 @_,
                   2423:                 );
1.586     raeburn  2424:     my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
                   2425:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2426:     if (defined($in{'curr_authtype'})) {
                   2427:         if ($in{'curr_authtype'} eq 'int') {
1.586     raeburn  2428:             if ($can_assign{'int'}) {
1.772     bisitz   2429:                 $intcheck = 'checked="checked" ';
1.623     raeburn  2430:                 if (defined($in{'mode'})) {
                   2431:                     if ($in{'mode'} eq 'modifyuser') {
                   2432:                         $intcheck = '';
                   2433:                     }
                   2434:                 }
1.591     raeburn  2435:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2436:                     $intarg = $in{'curr_autharg'};
                   2437:                 }
                   2438:             } else {
                   2439:                 $result = &mt('Currently internally authenticated.');
                   2440:                 return $result;
1.165     raeburn  2441:             }
                   2442:         }
1.586     raeburn  2443:     } else {
                   2444:         if ($authnum == 1) {
1.784     bisitz   2445:             $authtype = '<input type="hidden" name="login" value="int" />';
1.586     raeburn  2446:         }
                   2447:     }
                   2448:     if (!$can_assign{'int'}) {
                   2449:         return;
1.587     raeburn  2450:     } elsif ($authtype eq '') {
1.591     raeburn  2451:         if (defined($in{'mode'})) {
1.587     raeburn  2452:             if ($in{'mode'} eq 'modifycourse') {
                   2453:                 if ($authnum == 1) {
1.784     bisitz   2454:                     $authtype = '<input type="hidden" name="login" value="int" />';
1.587     raeburn  2455:                 }
                   2456:             }
                   2457:         }
1.165     raeburn  2458:     }
1.586     raeburn  2459:     $jscall = "javascript:changed_radio('int',$in{'formname'});";
                   2460:     if ($authtype eq '') {
                   2461:         $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
                   2462:                     ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
                   2463:     }
1.605     bisitz   2464:     $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586     raeburn  2465:                $intarg.'" onchange="'.$jscall.'" />';
                   2466:     $result = &mt
1.144     matthew  2467:         ('[_1] Internally authenticated (with initial password [_2])',
1.586     raeburn  2468:          '<label>'.$authtype,'</label>'.$autharg);
1.824     bisitz   2469:     $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  2470:     return $result;
                   2471: }
                   2472: 
                   2473: sub authform_local{  
                   2474:     my %in = (
                   2475:               formname => 'document.cu',
                   2476:               kerb_def_dom => 'MSU.EDU',
                   2477:               @_,
                   2478:               );
1.586     raeburn  2479:     my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
                   2480:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2481:     if (defined($in{'curr_authtype'})) {
                   2482:         if ($in{'curr_authtype'} eq 'loc') {
1.586     raeburn  2483:             if ($can_assign{'loc'}) {
1.772     bisitz   2484:                 $loccheck = 'checked="checked" ';
1.623     raeburn  2485:                 if (defined($in{'mode'})) {
                   2486:                     if ($in{'mode'} eq 'modifyuser') {
                   2487:                         $loccheck = '';
                   2488:                     }
                   2489:                 }
1.591     raeburn  2490:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2491:                     $locarg = $in{'curr_autharg'};
                   2492:                 }
                   2493:             } else {
                   2494:                 $result = &mt('Currently using local (institutional) authentication.');
                   2495:                 return $result;
1.165     raeburn  2496:             }
                   2497:         }
1.586     raeburn  2498:     } else {
                   2499:         if ($authnum == 1) {
1.784     bisitz   2500:             $authtype = '<input type="hidden" name="login" value="loc" />';
1.586     raeburn  2501:         }
                   2502:     }
                   2503:     if (!$can_assign{'loc'}) {
                   2504:         return;
1.587     raeburn  2505:     } elsif ($authtype eq '') {
1.591     raeburn  2506:         if (defined($in{'mode'})) {
1.587     raeburn  2507:             if ($in{'mode'} eq 'modifycourse') {
                   2508:                 if ($authnum == 1) {
1.784     bisitz   2509:                     $authtype = '<input type="hidden" name="login" value="loc" />';
1.587     raeburn  2510:                 }
                   2511:             }
                   2512:         }
1.165     raeburn  2513:     }
1.586     raeburn  2514:     $jscall = "javascript:changed_radio('loc',$in{'formname'});";
                   2515:     if ($authtype eq '') {
                   2516:         $authtype = '<input type="radio" name="login" value="loc" '.
                   2517:                     $loccheck.' onchange="'.$jscall.'" onclick="'.
                   2518:                     $jscall.'" />';
                   2519:     }
                   2520:     $autharg = '<input type="text" size="10" name="locarg" value="'.
                   2521:                $locarg.'" onchange="'.$jscall.'" />';
                   2522:     $result = &mt('[_1] Local Authentication with argument [_2]',
                   2523:                   '<label>'.$authtype,'</label>'.$autharg);
1.32      matthew  2524:     return $result;
                   2525: }
                   2526: 
                   2527: sub authform_filesystem{  
                   2528:     my %in = (
                   2529:               formname => 'document.cu',
                   2530:               kerb_def_dom => 'MSU.EDU',
                   2531:               @_,
                   2532:               );
1.586     raeburn  2533:     my ($fsyscheck,$result,$authtype,$autharg,$jscall);
                   2534:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2535:     if (defined($in{'curr_authtype'})) {
                   2536:         if ($in{'curr_authtype'} eq 'fsys') {
1.586     raeburn  2537:             if ($can_assign{'fsys'}) {
1.772     bisitz   2538:                 $fsyscheck = 'checked="checked" ';
1.623     raeburn  2539:                 if (defined($in{'mode'})) {
                   2540:                     if ($in{'mode'} eq 'modifyuser') {
                   2541:                         $fsyscheck = '';
                   2542:                     }
                   2543:                 }
1.586     raeburn  2544:             } else {
                   2545:                 $result = &mt('Currently Filesystem Authenticated.');
                   2546:                 return $result;
                   2547:             }           
                   2548:         }
                   2549:     } else {
                   2550:         if ($authnum == 1) {
1.784     bisitz   2551:             $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586     raeburn  2552:         }
                   2553:     }
                   2554:     if (!$can_assign{'fsys'}) {
                   2555:         return;
1.587     raeburn  2556:     } elsif ($authtype eq '') {
1.591     raeburn  2557:         if (defined($in{'mode'})) {
1.587     raeburn  2558:             if ($in{'mode'} eq 'modifycourse') {
                   2559:                 if ($authnum == 1) {
1.784     bisitz   2560:                     $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587     raeburn  2561:                 }
                   2562:             }
                   2563:         }
1.586     raeburn  2564:     }
                   2565:     $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
                   2566:     if ($authtype eq '') {
                   2567:         $authtype = '<input type="radio" name="login" value="fsys" '.
                   2568:                     $fsyscheck.' onchange="'.$jscall.'" onclick="'.
                   2569:                     $jscall.'" />';
                   2570:     }
                   2571:     $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
                   2572:                ' onchange="'.$jscall.'" />';
                   2573:     $result = &mt
1.144     matthew  2574:         ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281     albertel 2575:          '<label><input type="radio" name="login" value="fsys" '.
1.586     raeburn  2576:          $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605     bisitz   2577:          '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144     matthew  2578:                   'onchange="'.$jscall.'" />');
1.32      matthew  2579:     return $result;
                   2580: }
                   2581: 
1.586     raeburn  2582: sub get_assignable_auth {
                   2583:     my ($dom) = @_;
                   2584:     if ($dom eq '') {
                   2585:         $dom = $env{'request.role.domain'};
                   2586:     }
                   2587:     my %can_assign = (
                   2588:                           krb4 => 1,
                   2589:                           krb5 => 1,
                   2590:                           int  => 1,
                   2591:                           loc  => 1,
                   2592:                      );
                   2593:     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
                   2594:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   2595:         if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
                   2596:             my $authhash = $domconfig{'usercreation'}{'authtypes'};
                   2597:             my $context;
                   2598:             if ($env{'request.role'} =~ /^au/) {
                   2599:                 $context = 'author';
                   2600:             } elsif ($env{'request.role'} =~ /^dc/) {
                   2601:                 $context = 'domain';
                   2602:             } elsif ($env{'request.course.id'}) {
                   2603:                 $context = 'course';
                   2604:             }
                   2605:             if ($context) {
                   2606:                 if (ref($authhash->{$context}) eq 'HASH') {
                   2607:                    %can_assign = %{$authhash->{$context}}; 
                   2608:                 }
                   2609:             }
                   2610:         }
                   2611:     }
                   2612:     my $authnum = 0;
                   2613:     foreach my $key (keys(%can_assign)) {
                   2614:         if ($can_assign{$key}) {
                   2615:             $authnum ++;
                   2616:         }
                   2617:     }
                   2618:     if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
                   2619:         $authnum --;
                   2620:     }
                   2621:     return ($authnum,%can_assign);
                   2622: }
                   2623: 
1.80      albertel 2624: ###############################################################
                   2625: ##    Get Kerberos Defaults for Domain                 ##
                   2626: ###############################################################
                   2627: ##
                   2628: ## Returns default kerberos version and an associated argument
                   2629: ## as listed in file domain.tab. If not listed, provides
                   2630: ## appropriate default domain and kerberos version.
                   2631: ##
                   2632: #-------------------------------------------
                   2633: 
                   2634: =pod
                   2635: 
1.648     raeburn  2636: =item * &get_kerberos_defaults()
1.80      albertel 2637: 
                   2638: get_kerberos_defaults($target_domain) returns the default kerberos
1.641     raeburn  2639: version and domain. If not found, it defaults to version 4 and the 
                   2640: domain of the server.
1.80      albertel 2641: 
1.648     raeburn  2642: =over 4
                   2643: 
1.80      albertel 2644: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
                   2645: 
1.648     raeburn  2646: =back
                   2647: 
                   2648: =back
                   2649: 
1.80      albertel 2650: =cut
                   2651: 
                   2652: #-------------------------------------------
                   2653: sub get_kerberos_defaults {
                   2654:     my $domain=shift;
1.641     raeburn  2655:     my ($krbdef,$krbdefdom);
                   2656:     my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
                   2657:     if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
                   2658:         $krbdef = $domdefaults{'auth_def'};
                   2659:         $krbdefdom = $domdefaults{'auth_arg_def'};
                   2660:     } else {
1.80      albertel 2661:         $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
                   2662:         my $krbdefdom=$1;
                   2663:         $krbdefdom=~tr/a-z/A-Z/;
                   2664:         $krbdef = "krb4";
                   2665:     }
                   2666:     return ($krbdef,$krbdefdom);
                   2667: }
1.112     bowersj2 2668: 
1.32      matthew  2669: 
1.46      matthew  2670: ###############################################################
                   2671: ##                Thesaurus Functions                        ##
                   2672: ###############################################################
1.20      www      2673: 
1.46      matthew  2674: =pod
1.20      www      2675: 
1.112     bowersj2 2676: =head1 Thesaurus Functions
                   2677: 
                   2678: =over 4
                   2679: 
1.648     raeburn  2680: =item * &initialize_keywords()
1.46      matthew  2681: 
                   2682: Initializes the package variable %Keywords if it is empty.  Uses the
                   2683: package variable $thesaurus_db_file.
                   2684: 
                   2685: =cut
                   2686: 
                   2687: ###################################################
                   2688: 
                   2689: sub initialize_keywords {
                   2690:     return 1 if (scalar keys(%Keywords));
                   2691:     # If we are here, %Keywords is empty, so fill it up
                   2692:     #   Make sure the file we need exists...
                   2693:     if (! -e $thesaurus_db_file) {
                   2694:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
                   2695:                                  " failed because it does not exist");
                   2696:         return 0;
                   2697:     }
                   2698:     #   Set up the hash as a database
                   2699:     my %thesaurus_db;
                   2700:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2701:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2702:         &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
                   2703:                                  $thesaurus_db_file);
                   2704:         return 0;
                   2705:     } 
                   2706:     #  Get the average number of appearances of a word.
                   2707:     my $avecount = $thesaurus_db{'average.count'};
                   2708:     #  Put keywords (those that appear > average) into %Keywords
                   2709:     while (my ($word,$data)=each (%thesaurus_db)) {
                   2710:         my ($count,undef) = split /:/,$data;
                   2711:         $Keywords{$word}++ if ($count > $avecount);
                   2712:     }
                   2713:     untie %thesaurus_db;
                   2714:     # Remove special values from %Keywords.
1.356     albertel 2715:     foreach my $value ('total.count','average.count') {
                   2716:         delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586     raeburn  2717:   }
1.46      matthew  2718:     return 1;
                   2719: }
                   2720: 
                   2721: ###################################################
                   2722: 
                   2723: =pod
                   2724: 
1.648     raeburn  2725: =item * &keyword($word)
1.46      matthew  2726: 
                   2727: Returns true if $word is a keyword.  A keyword is a word that appears more 
                   2728: than the average number of times in the thesaurus database.  Calls 
                   2729: &initialize_keywords
                   2730: 
                   2731: =cut
                   2732: 
                   2733: ###################################################
1.20      www      2734: 
                   2735: sub keyword {
1.46      matthew  2736:     return if (!&initialize_keywords());
                   2737:     my $word=lc(shift());
                   2738:     $word=~s/\W//g;
                   2739:     return exists($Keywords{$word});
1.20      www      2740: }
1.46      matthew  2741: 
                   2742: ###############################################################
                   2743: 
                   2744: =pod 
1.20      www      2745: 
1.648     raeburn  2746: =item * &get_related_words()
1.46      matthew  2747: 
1.160     matthew  2748: Look up a word in the thesaurus.  Takes a scalar argument and returns
1.46      matthew  2749: an array of words.  If the keyword is not in the thesaurus, an empty array
                   2750: will be returned.  The order of the words returned is determined by the
                   2751: database which holds them.
                   2752: 
                   2753: Uses global $thesaurus_db_file.
                   2754: 
                   2755: =cut
                   2756: 
                   2757: ###############################################################
                   2758: sub get_related_words {
                   2759:     my $keyword = shift;
                   2760:     my %thesaurus_db;
                   2761:     if (! -e $thesaurus_db_file) {
                   2762:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
                   2763:                                  "failed because the file does not exist");
                   2764:         return ();
                   2765:     }
                   2766:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2767:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2768:         return ();
                   2769:     } 
                   2770:     my @Words=();
1.429     www      2771:     my $count=0;
1.46      matthew  2772:     if (exists($thesaurus_db{$keyword})) {
1.356     albertel 2773: 	# The first element is the number of times
                   2774: 	# the word appears.  We do not need it now.
1.429     www      2775: 	my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
                   2776: 	my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
                   2777: 	my $threshold=$mostfrequentcount/10;
                   2778:         foreach my $possibleword (@RelatedWords) {
                   2779:             my ($word,$wordcount)=split(/\,/,$possibleword);
                   2780:             if ($wordcount>$threshold) {
                   2781: 		push(@Words,$word);
                   2782:                 $count++;
                   2783:                 if ($count>10) { last; }
                   2784: 	    }
1.20      www      2785:         }
                   2786:     }
1.46      matthew  2787:     untie %thesaurus_db;
                   2788:     return @Words;
1.14      harris41 2789: }
1.46      matthew  2790: 
1.112     bowersj2 2791: =pod
                   2792: 
                   2793: =back
                   2794: 
                   2795: =cut
1.61      www      2796: 
                   2797: # -------------------------------------------------------------- Plaintext name
1.81      albertel 2798: =pod
                   2799: 
1.112     bowersj2 2800: =head1 User Name Functions
                   2801: 
                   2802: =over 4
                   2803: 
1.648     raeburn  2804: =item * &plainname($uname,$udom,$first)
1.81      albertel 2805: 
1.112     bowersj2 2806: Takes a users logon name and returns it as a string in
1.226     albertel 2807: "first middle last generation" form 
                   2808: if $first is set to 'lastname' then it returns it as
                   2809: 'lastname generation, firstname middlename' if their is a lastname
1.81      albertel 2810: 
                   2811: =cut
1.61      www      2812: 
1.295     www      2813: 
1.81      albertel 2814: ###############################################################
1.61      www      2815: sub plainname {
1.226     albertel 2816:     my ($uname,$udom,$first)=@_;
1.537     albertel 2817:     return if (!defined($uname) || !defined($udom));
1.295     www      2818:     my %names=&getnames($uname,$udom);
1.226     albertel 2819:     my $name=&Apache::lonnet::format_name($names{'firstname'},
                   2820: 					  $names{'middlename'},
                   2821: 					  $names{'lastname'},
                   2822: 					  $names{'generation'},$first);
                   2823:     $name=~s/^\s+//;
1.62      www      2824:     $name=~s/\s+$//;
                   2825:     $name=~s/\s+/ /g;
1.353     albertel 2826:     if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62      www      2827:     return $name;
1.61      www      2828: }
1.66      www      2829: 
                   2830: # -------------------------------------------------------------------- Nickname
1.81      albertel 2831: =pod
                   2832: 
1.648     raeburn  2833: =item * &nickname($uname,$udom)
1.81      albertel 2834: 
                   2835: Gets a users name and returns it as a string as
                   2836: 
                   2837: "&quot;nickname&quot;"
1.66      www      2838: 
1.81      albertel 2839: if the user has a nickname or
                   2840: 
                   2841: "first middle last generation"
                   2842: 
                   2843: if the user does not
                   2844: 
                   2845: =cut
1.66      www      2846: 
                   2847: sub nickname {
                   2848:     my ($uname,$udom)=@_;
1.537     albertel 2849:     return if (!defined($uname) || !defined($udom));
1.295     www      2850:     my %names=&getnames($uname,$udom);
1.68      albertel 2851:     my $name=$names{'nickname'};
1.66      www      2852:     if ($name) {
                   2853:        $name='&quot;'.$name.'&quot;'; 
                   2854:     } else {
                   2855:        $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
                   2856: 	     $names{'lastname'}.' '.$names{'generation'};
                   2857:        $name=~s/\s+$//;
                   2858:        $name=~s/\s+/ /g;
                   2859:     }
                   2860:     return $name;
                   2861: }
                   2862: 
1.295     www      2863: sub getnames {
                   2864:     my ($uname,$udom)=@_;
1.537     albertel 2865:     return if (!defined($uname) || !defined($udom));
1.433     albertel 2866:     if ($udom eq 'public' && $uname eq 'public') {
                   2867: 	return ('lastname' => &mt('Public'));
                   2868:     }
1.295     www      2869:     my $id=$uname.':'.$udom;
                   2870:     my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
                   2871:     if ($cached) {
                   2872: 	return %{$names};
                   2873:     } else {
                   2874: 	my %loadnames=&Apache::lonnet::get('environment',
                   2875:                     ['firstname','middlename','lastname','generation','nickname'],
                   2876: 					 $udom,$uname);
                   2877: 	&Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
                   2878: 	return %loadnames;
                   2879:     }
                   2880: }
1.61      www      2881: 
1.542     raeburn  2882: # -------------------------------------------------------------------- getemails
1.648     raeburn  2883: 
1.542     raeburn  2884: =pod
                   2885: 
1.648     raeburn  2886: =item * &getemails($uname,$udom)
1.542     raeburn  2887: 
                   2888: Gets a user's email information and returns it as a hash with keys:
                   2889: notification, critnotification, permanentemail
                   2890: 
                   2891: For notification and critnotification, values are comma-separated lists 
1.648     raeburn  2892: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542     raeburn  2893:  
1.648     raeburn  2894: 
1.542     raeburn  2895: =cut
                   2896: 
1.648     raeburn  2897: 
1.466     albertel 2898: sub getemails {
                   2899:     my ($uname,$udom)=@_;
                   2900:     if ($udom eq 'public' && $uname eq 'public') {
                   2901: 	return;
                   2902:     }
1.467     www      2903:     if (!$udom) { $udom=$env{'user.domain'}; }
                   2904:     if (!$uname) { $uname=$env{'user.name'}; }
1.466     albertel 2905:     my $id=$uname.':'.$udom;
                   2906:     my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
                   2907:     if ($cached) {
                   2908: 	return %{$names};
                   2909:     } else {
                   2910: 	my %loadnames=&Apache::lonnet::get('environment',
                   2911:                     			   ['notification','critnotification',
                   2912: 					    'permanentemail'],
                   2913: 					   $udom,$uname);
                   2914: 	&Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
                   2915: 	return %loadnames;
                   2916:     }
                   2917: }
                   2918: 
1.551     albertel 2919: sub flush_email_cache {
                   2920:     my ($uname,$udom)=@_;
                   2921:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2922:     if (!$uname) { $uname=$env{'user.name'};   }
                   2923:     return if ($udom eq 'public' && $uname eq 'public');
                   2924:     my $id=$uname.':'.$udom;
                   2925:     &Apache::lonnet::devalidate_cache_new('emailscache',$id);
                   2926: }
                   2927: 
1.728     raeburn  2928: # -------------------------------------------------------------------- getlangs
                   2929: 
                   2930: =pod
                   2931: 
                   2932: =item * &getlangs($uname,$udom)
                   2933: 
                   2934: Gets a user's language preference and returns it as a hash with key:
                   2935: language.
                   2936: 
                   2937: =cut
                   2938: 
                   2939: 
                   2940: sub getlangs {
                   2941:     my ($uname,$udom) = @_;
                   2942:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2943:     if (!$uname) { $uname=$env{'user.name'};   }
                   2944:     my $id=$uname.':'.$udom;
                   2945:     my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
                   2946:     if ($cached) {
                   2947:         return %{$langs};
                   2948:     } else {
                   2949:         my %loadlangs=&Apache::lonnet::get('environment',['languages'],
                   2950:                                            $udom,$uname);
                   2951:         &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
                   2952:         return %loadlangs;
                   2953:     }
                   2954: }
                   2955: 
                   2956: sub flush_langs_cache {
                   2957:     my ($uname,$udom)=@_;
                   2958:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2959:     if (!$uname) { $uname=$env{'user.name'};   }
                   2960:     return if ($udom eq 'public' && $uname eq 'public');
                   2961:     my $id=$uname.':'.$udom;
                   2962:     &Apache::lonnet::devalidate_cache_new('userlangs',$id);
                   2963: }
                   2964: 
1.61      www      2965: # ------------------------------------------------------------------ Screenname
1.81      albertel 2966: 
                   2967: =pod
                   2968: 
1.648     raeburn  2969: =item * &screenname($uname,$udom)
1.81      albertel 2970: 
                   2971: Gets a users screenname and returns it as a string
                   2972: 
                   2973: =cut
1.61      www      2974: 
                   2975: sub screenname {
                   2976:     my ($uname,$udom)=@_;
1.258     albertel 2977:     if ($uname eq $env{'user.name'} &&
                   2978: 	$udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212     albertel 2979:     my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68      albertel 2980:     return $names{'screenname'};
1.62      www      2981: }
                   2982: 
1.212     albertel 2983: 
1.802     bisitz   2984: # ------------------------------------------------------------- Confirm Wrapper
                   2985: =pod
                   2986: 
                   2987: =item confirmwrapper
                   2988: 
                   2989: Wrap messages about completion of operation in box
                   2990: 
                   2991: =cut
                   2992: 
                   2993: sub confirmwrapper {
                   2994:     my ($message)=@_;
                   2995:     if ($message) {
                   2996:         return "\n".'<div class="LC_confirm_box">'."\n"
                   2997:                .$message."\n"
                   2998:                .'</div>'."\n";
                   2999:     } else {
                   3000:         return $message;
                   3001:     }
                   3002: }
                   3003: 
1.62      www      3004: # ------------------------------------------------------------- Message Wrapper
                   3005: 
                   3006: sub messagewrapper {
1.369     www      3007:     my ($link,$username,$domain,$subject,$text)=@_;
1.62      www      3008:     return 
1.441     albertel 3009:         '<a href="/adm/email?compose=individual&amp;'.
                   3010:         'recname='.$username.'&amp;recdom='.$domain.
                   3011: 	'&amp;subject='.&escape($subject).'&amp;text='.&escape($text).'" '.
1.200     matthew  3012:         'title="'.&mt('Send message').'">'.$link.'</a>';
1.74      www      3013: }
1.802     bisitz   3014: 
1.74      www      3015: # --------------------------------------------------------------- Notes Wrapper
                   3016: 
                   3017: sub noteswrapper {
                   3018:     my ($link,$un,$do)=@_;
                   3019:     return 
1.896     amueller 3020: "<a href='/adm/email?recordftf=retrieve&amp;recname=$un&amp;recdom=$do'>$link</a>";
1.62      www      3021: }
1.802     bisitz   3022: 
1.62      www      3023: # ------------------------------------------------------------- Aboutme Wrapper
                   3024: 
                   3025: sub aboutmewrapper {
1.166     www      3026:     my ($link,$username,$domain,$target)=@_;
1.447     raeburn  3027:     if (!defined($username)  && !defined($domain)) {
                   3028:         return;
                   3029:     }
1.892     amueller 3030:     return '<a href="/adm/'.$domain.'/'.$username.'/aboutme?forcestudent=1"'.
1.756     weissno  3031: 	($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62      www      3032: }
                   3033: 
                   3034: # ------------------------------------------------------------ Syllabus Wrapper
                   3035: 
                   3036: sub syllabuswrapper {
1.707     bisitz   3037:     my ($linktext,$coursedir,$domain)=@_;
1.208     matthew  3038:     return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61      www      3039: }
1.14      harris41 3040: 
1.802     bisitz   3041: # -----------------------------------------------------------------------------
                   3042: 
1.208     matthew  3043: sub track_student_link {
1.887     raeburn  3044:     my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268     albertel 3045:     my $link ="/adm/trackstudent?";
1.208     matthew  3046:     my $title = 'View recent activity';
                   3047:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   3048:         defined($sdom)  && $sdom  !~ /^\s*$/) {
1.268     albertel 3049:         $link .= "selected_student=$sname:$sdom";
1.208     matthew  3050:         $title .= ' of this student';
1.268     albertel 3051:     } 
1.208     matthew  3052:     if (defined($target) && $target !~ /^\s*$/) {
                   3053:         $target = qq{target="$target"};
                   3054:     } else {
                   3055:         $target = '';
                   3056:     }
1.268     albertel 3057:     if ($start) { $link.='&amp;start='.$start; }
1.887     raeburn  3058:     if ($only_body) { $link .= '&amp;only_body=1'; }
1.554     albertel 3059:     $title = &mt($title);
                   3060:     $linktext = &mt($linktext);
1.448     albertel 3061:     return qq{<a href="$link" title="$title" $target>$linktext</a>}.
                   3062: 	&help_open_topic('View_recent_activity');
1.208     matthew  3063: }
                   3064: 
1.781     raeburn  3065: sub slot_reservations_link {
                   3066:     my ($linktext,$sname,$sdom,$target) = @_;
                   3067:     my $link ="/adm/slotrequest?command=showresv&amp;origin=aboutme";
                   3068:     my $title = 'View slot reservation history';
                   3069:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   3070:         defined($sdom)  && $sdom  !~ /^\s*$/) {
                   3071:         $link .= "&amp;uname=$sname&amp;udom=$sdom";
                   3072:         $title .= ' of this student';
                   3073:     }
                   3074:     if (defined($target) && $target !~ /^\s*$/) {
                   3075:         $target = qq{target="$target"};
                   3076:     } else {
                   3077:         $target = '';
                   3078:     }
                   3079:     $title = &mt($title);
                   3080:     $linktext = &mt($linktext);
                   3081:     return qq{<a href="$link" title="$title" $target>$linktext</a>};
                   3082: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
                   3083: 
                   3084: }
                   3085: 
1.508     www      3086: # ===================================================== Display a student photo
                   3087: 
                   3088: 
1.509     albertel 3089: sub student_image_tag {
1.508     www      3090:     my ($domain,$user)=@_;
                   3091:     my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
                   3092:     if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
                   3093: 	return '<img src="'.$imgsrc.'" align="right" />';
                   3094:     } else {
                   3095: 	return '';
                   3096:     }
                   3097: }
                   3098: 
1.112     bowersj2 3099: =pod
                   3100: 
                   3101: =back
                   3102: 
                   3103: =head1 Access .tab File Data
                   3104: 
                   3105: =over 4
                   3106: 
1.648     raeburn  3107: =item * &languageids() 
1.112     bowersj2 3108: 
                   3109: returns list of all language ids
                   3110: 
                   3111: =cut
                   3112: 
1.14      harris41 3113: sub languageids {
1.16      harris41 3114:     return sort(keys(%language));
1.14      harris41 3115: }
                   3116: 
1.112     bowersj2 3117: =pod
                   3118: 
1.648     raeburn  3119: =item * &languagedescription() 
1.112     bowersj2 3120: 
                   3121: returns description of a specified language id
                   3122: 
                   3123: =cut
                   3124: 
1.14      harris41 3125: sub languagedescription {
1.125     www      3126:     my $code=shift;
                   3127:     return  ($supported_language{$code}?'* ':'').
                   3128:             $language{$code}.
1.126     www      3129: 	    ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145     www      3130: }
                   3131: 
                   3132: sub plainlanguagedescription {
                   3133:     my $code=shift;
                   3134:     return $language{$code};
                   3135: }
                   3136: 
                   3137: sub supportedlanguagecode {
                   3138:     my $code=shift;
                   3139:     return $supported_language{$code};
1.97      www      3140: }
                   3141: 
1.112     bowersj2 3142: =pod
                   3143: 
1.648     raeburn  3144: =item * &copyrightids() 
1.112     bowersj2 3145: 
                   3146: returns list of all copyrights
                   3147: 
                   3148: =cut
                   3149: 
                   3150: sub copyrightids {
                   3151:     return sort(keys(%cprtag));
                   3152: }
                   3153: 
                   3154: =pod
                   3155: 
1.648     raeburn  3156: =item * &copyrightdescription() 
1.112     bowersj2 3157: 
                   3158: returns description of a specified copyright id
                   3159: 
                   3160: =cut
                   3161: 
                   3162: sub copyrightdescription {
1.166     www      3163:     return &mt($cprtag{shift(@_)});
1.112     bowersj2 3164: }
1.197     matthew  3165: 
                   3166: =pod
                   3167: 
1.648     raeburn  3168: =item * &source_copyrightids() 
1.192     taceyjo1 3169: 
                   3170: returns list of all source copyrights
                   3171: 
                   3172: =cut
                   3173: 
                   3174: sub source_copyrightids {
                   3175:     return sort(keys(%scprtag));
                   3176: }
                   3177: 
                   3178: =pod
                   3179: 
1.648     raeburn  3180: =item * &source_copyrightdescription() 
1.192     taceyjo1 3181: 
                   3182: returns description of a specified source copyright id
                   3183: 
                   3184: =cut
                   3185: 
                   3186: sub source_copyrightdescription {
                   3187:     return &mt($scprtag{shift(@_)});
                   3188: }
1.112     bowersj2 3189: 
                   3190: =pod
                   3191: 
1.648     raeburn  3192: =item * &filecategories() 
1.112     bowersj2 3193: 
                   3194: returns list of all file categories
                   3195: 
                   3196: =cut
                   3197: 
                   3198: sub filecategories {
                   3199:     return sort(keys(%category_extensions));
                   3200: }
                   3201: 
                   3202: =pod
                   3203: 
1.648     raeburn  3204: =item * &filecategorytypes() 
1.112     bowersj2 3205: 
                   3206: returns list of file types belonging to a given file
                   3207: category
                   3208: 
                   3209: =cut
                   3210: 
                   3211: sub filecategorytypes {
1.356     albertel 3212:     my ($cat) = @_;
                   3213:     return @{$category_extensions{lc($cat)}};
1.112     bowersj2 3214: }
                   3215: 
                   3216: =pod
                   3217: 
1.648     raeburn  3218: =item * &fileembstyle() 
1.112     bowersj2 3219: 
                   3220: returns embedding style for a specified file type
                   3221: 
                   3222: =cut
                   3223: 
                   3224: sub fileembstyle {
                   3225:     return $fe{lc(shift(@_))};
1.169     www      3226: }
                   3227: 
1.351     www      3228: sub filemimetype {
                   3229:     return $fm{lc(shift(@_))};
                   3230: }
                   3231: 
1.169     www      3232: 
                   3233: sub filecategoryselect {
                   3234:     my ($name,$value)=@_;
1.189     matthew  3235:     return &select_form($value,$name,
1.169     www      3236: 			'' => &mt('Any category'),
                   3237: 			map { $_,$_ } sort(keys(%category_extensions)));
1.112     bowersj2 3238: }
                   3239: 
                   3240: =pod
                   3241: 
1.648     raeburn  3242: =item * &filedescription() 
1.112     bowersj2 3243: 
                   3244: returns description for a specified file type
                   3245: 
                   3246: =cut
                   3247: 
                   3248: sub filedescription {
1.188     matthew  3249:     my $file_description = $fd{lc(shift())};
                   3250:     $file_description =~ s:([\[\]]):~$1:g;
                   3251:     return &mt($file_description);
1.112     bowersj2 3252: }
                   3253: 
                   3254: =pod
                   3255: 
1.648     raeburn  3256: =item * &filedescriptionex() 
1.112     bowersj2 3257: 
                   3258: returns description for a specified file type with
                   3259: extra formatting
                   3260: 
                   3261: =cut
                   3262: 
                   3263: sub filedescriptionex {
                   3264:     my $ex=shift;
1.188     matthew  3265:     my $file_description = $fd{lc($ex)};
                   3266:     $file_description =~ s:([\[\]]):~$1:g;
                   3267:     return '.'.$ex.' '.&mt($file_description);
1.112     bowersj2 3268: }
                   3269: 
                   3270: # End of .tab access
                   3271: =pod
                   3272: 
                   3273: =back
                   3274: 
                   3275: =cut
                   3276: 
                   3277: # ------------------------------------------------------------------ File Types
                   3278: sub fileextensions {
                   3279:     return sort(keys(%fe));
                   3280: }
                   3281: 
1.97      www      3282: # ----------------------------------------------------------- Display Languages
                   3283: # returns a hash with all desired display languages
                   3284: #
                   3285: 
                   3286: sub display_languages {
                   3287:     my %languages=();
1.695     raeburn  3288:     foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356     albertel 3289: 	$languages{$lang}=1;
1.97      www      3290:     }
                   3291:     &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258     albertel 3292:     if ($env{'form.displaylanguage'}) {
1.356     albertel 3293: 	foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
                   3294: 	    $languages{$lang}=1;
1.97      www      3295:         }
                   3296:     }
                   3297:     return %languages;
1.14      harris41 3298: }
                   3299: 
1.582     albertel 3300: sub languages {
                   3301:     my ($possible_langs) = @_;
1.695     raeburn  3302:     my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582     albertel 3303:     if (!ref($possible_langs)) {
                   3304: 	if( wantarray ) {
                   3305: 	    return @preferred_langs;
                   3306: 	} else {
                   3307: 	    return $preferred_langs[0];
                   3308: 	}
                   3309:     }
                   3310:     my %possibilities = map { $_ => 1 } (@$possible_langs);
                   3311:     my @preferred_possibilities;
                   3312:     foreach my $preferred_lang (@preferred_langs) {
                   3313: 	if (exists($possibilities{$preferred_lang})) {
                   3314: 	    push(@preferred_possibilities, $preferred_lang);
                   3315: 	}
                   3316:     }
                   3317:     if( wantarray ) {
                   3318: 	return @preferred_possibilities;
                   3319:     }
                   3320:     return $preferred_possibilities[0];
                   3321: }
                   3322: 
1.742     raeburn  3323: sub user_lang {
                   3324:     my ($touname,$toudom,$fromcid) = @_;
                   3325:     my @userlangs;
                   3326:     if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
                   3327:         @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
                   3328:                     $env{'course.'.$fromcid.'.languages'}));
                   3329:     } else {
                   3330:         my %langhash = &getlangs($touname,$toudom);
                   3331:         if ($langhash{'languages'} ne '') {
                   3332:             @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
                   3333:         } else {
                   3334:             my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
                   3335:             if ($domdefs{'lang_def'} ne '') {
                   3336:                 @userlangs = ($domdefs{'lang_def'});
                   3337:             }
                   3338:         }
                   3339:     }
                   3340:     my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
                   3341:     my $user_lh = Apache::localize->get_handle(@languages);
                   3342:     return $user_lh;
                   3343: }
                   3344: 
                   3345: 
1.112     bowersj2 3346: ###############################################################
                   3347: ##               Student Answer Attempts                     ##
                   3348: ###############################################################
                   3349: 
                   3350: =pod
                   3351: 
                   3352: =head1 Alternate Problem Views
                   3353: 
                   3354: =over 4
                   3355: 
1.648     raeburn  3356: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112     bowersj2 3357:     $getattempt, $regexp, $gradesub)
                   3358: 
                   3359: Return string with previous attempt on problem. Arguments:
                   3360: 
                   3361: =over 4
                   3362: 
                   3363: =item * $symb: Problem, including path
                   3364: 
                   3365: =item * $username: username of the desired student
                   3366: 
                   3367: =item * $domain: domain of the desired student
1.14      harris41 3368: 
1.112     bowersj2 3369: =item * $course: Course ID
1.14      harris41 3370: 
1.112     bowersj2 3371: =item * $getattempt: Leave blank for all attempts, otherwise put
                   3372:     something
1.14      harris41 3373: 
1.112     bowersj2 3374: =item * $regexp: if string matches this regexp, the string will be
                   3375:     sent to $gradesub
1.14      harris41 3376: 
1.112     bowersj2 3377: =item * $gradesub: routine that processes the string if it matches $regexp
1.14      harris41 3378: 
1.112     bowersj2 3379: =back
1.14      harris41 3380: 
1.112     bowersj2 3381: The output string is a table containing all desired attempts, if any.
1.16      harris41 3382: 
1.112     bowersj2 3383: =cut
1.1       albertel 3384: 
                   3385: sub get_previous_attempt {
1.43      ng       3386:   my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1       albertel 3387:   my $prevattempts='';
1.43      ng       3388:   no strict 'refs';
1.1       albertel 3389:   if ($symb) {
1.3       albertel 3390:     my (%returnhash)=
                   3391:       &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1       albertel 3392:     if ($returnhash{'version'}) {
                   3393:       my %lasthash=();
                   3394:       my $version;
                   3395:       for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356     albertel 3396:         foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
                   3397: 	  $lasthash{$key}=$returnhash{$version.':'.$key};
1.19      harris41 3398:         }
1.1       albertel 3399:       }
1.596     albertel 3400:       $prevattempts=&start_data_table().&start_data_table_header_row();
                   3401:       $prevattempts.='<th>'.&mt('History').'</th>';
1.356     albertel 3402:       foreach my $key (sort(keys(%lasthash))) {
                   3403: 	my ($ign,@parts) = split(/\./,$key);
1.41      ng       3404: 	if ($#parts > 0) {
1.31      albertel 3405: 	  my $data=$parts[-1];
                   3406: 	  pop(@parts);
1.596     albertel 3407: 	  $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.'&nbsp;</th>';
1.31      albertel 3408: 	} else {
1.41      ng       3409: 	  if ($#parts == 0) {
                   3410: 	    $prevattempts.='<th>'.$parts[0].'</th>';
                   3411: 	  } else {
                   3412: 	    $prevattempts.='<th>'.$ign.'</th>';
                   3413: 	  }
1.31      albertel 3414: 	}
1.16      harris41 3415:       }
1.596     albertel 3416:       $prevattempts.=&end_data_table_header_row();
1.40      ng       3417:       if ($getattempt eq '') {
                   3418: 	for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596     albertel 3419: 	  $prevattempts.=&start_data_table_row().
                   3420: 	      '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356     albertel 3421: 	    foreach my $key (sort(keys(%lasthash))) {
1.581     albertel 3422: 		my $value = &format_previous_attempt_value($key,
                   3423: 							   $returnhash{$version.':'.$key});
                   3424: 		$prevattempts.='<td>'.$value.'&nbsp;</td>';   
1.40      ng       3425: 	    }
1.596     albertel 3426: 	  $prevattempts.=&end_data_table_row();
1.40      ng       3427: 	 }
1.1       albertel 3428:       }
1.596     albertel 3429:       $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356     albertel 3430:       foreach my $key (sort(keys(%lasthash))) {
1.581     albertel 3431: 	my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356     albertel 3432: 	if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40      ng       3433: 	$prevattempts.='<td>'.$value.'&nbsp;</td>';
1.16      harris41 3434:       }
1.596     albertel 3435:       $prevattempts.= &end_data_table_row().&end_data_table();
1.1       albertel 3436:     } else {
1.596     albertel 3437:       $prevattempts=
                   3438: 	  &start_data_table().&start_data_table_row().
                   3439: 	  '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
                   3440: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3441:     }
                   3442:   } else {
1.596     albertel 3443:     $prevattempts=
                   3444: 	  &start_data_table().&start_data_table_row().
                   3445: 	  '<td>'.&mt('No data.').'</td>'.
                   3446: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3447:   }
1.10      albertel 3448: }
                   3449: 
1.581     albertel 3450: sub format_previous_attempt_value {
                   3451:     my ($key,$value) = @_;
                   3452:     if ($key =~ /timestamp/) {
                   3453: 	$value = &Apache::lonlocal::locallocaltime($value);
                   3454:     } elsif (ref($value) eq 'ARRAY') {
                   3455: 	$value = '('.join(', ', @{ $value }).')';
                   3456:     } else {
                   3457: 	$value = &unescape($value);
                   3458:     }
                   3459:     return $value;
                   3460: }
                   3461: 
                   3462: 
1.107     albertel 3463: sub relative_to_absolute {
                   3464:     my ($url,$output)=@_;
                   3465:     my $parser=HTML::TokeParser->new(\$output);
                   3466:     my $token;
                   3467:     my $thisdir=$url;
                   3468:     my @rlinks=();
                   3469:     while ($token=$parser->get_token) {
                   3470: 	if ($token->[0] eq 'S') {
                   3471: 	    if ($token->[1] eq 'a') {
                   3472: 		if ($token->[2]->{'href'}) {
                   3473: 		    $rlinks[$#rlinks+1]=$token->[2]->{'href'};
                   3474: 		}
                   3475: 	    } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
                   3476: 		$rlinks[$#rlinks+1]=$token->[2]->{'src'};
                   3477: 	    } elsif ($token->[1] eq 'base') {
                   3478: 		$thisdir=$token->[2]->{'href'};
                   3479: 	    }
                   3480: 	}
                   3481:     }
                   3482:     $thisdir=~s-/[^/]*$--;
1.356     albertel 3483:     foreach my $link (@rlinks) {
1.726     raeburn  3484: 	unless (($link=~/^https?\:\/\//i) ||
1.356     albertel 3485: 		($link=~/^\//) ||
                   3486: 		($link=~/^javascript:/i) ||
                   3487: 		($link=~/^mailto:/i) ||
                   3488: 		($link=~/^\#/)) {
                   3489: 	    my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
                   3490: 	    $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107     albertel 3491: 	}
                   3492:     }
                   3493: # -------------------------------------------------- Deal with Applet codebases
                   3494:     $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
                   3495:     return $output;
                   3496: }
                   3497: 
1.112     bowersj2 3498: =pod
                   3499: 
1.648     raeburn  3500: =item * &get_student_view()
1.112     bowersj2 3501: 
                   3502: show a snapshot of what student was looking at
                   3503: 
                   3504: =cut
                   3505: 
1.10      albertel 3506: sub get_student_view {
1.186     albertel 3507:   my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114     www      3508:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3509:   my (%form);
1.10      albertel 3510:   my @elements=('symb','courseid','domain','username');
                   3511:   foreach my $element (@elements) {
1.186     albertel 3512:       $form{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3513:   }
1.186     albertel 3514:   if (defined($moreenv)) {
                   3515:       %form=(%form,%{$moreenv});
                   3516:   }
1.236     albertel 3517:   if (defined($target)) { $form{'grade_target'} = $target; }
1.107     albertel 3518:   $feedurl=&Apache::lonnet::clutter($feedurl);
1.650     www      3519:   my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11      albertel 3520:   $userview=~s/\<body[^\>]*\>//gi;
                   3521:   $userview=~s/\<\/body\>//gi;
                   3522:   $userview=~s/\<html\>//gi;
                   3523:   $userview=~s/\<\/html\>//gi;
                   3524:   $userview=~s/\<head\>//gi;
                   3525:   $userview=~s/\<\/head\>//gi;
                   3526:   $userview=~s/action\s*\=/would_be_action\=/gi;
1.107     albertel 3527:   $userview=&relative_to_absolute($feedurl,$userview);
1.650     www      3528:   if (wantarray) {
                   3529:      return ($userview,$response);
                   3530:   } else {
                   3531:      return $userview;
                   3532:   }
                   3533: }
                   3534: 
                   3535: sub get_student_view_with_retries {
                   3536:   my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
                   3537: 
                   3538:     my $ok = 0;                 # True if we got a good response.
                   3539:     my $content;
                   3540:     my $response;
                   3541: 
                   3542:     # Try to get the student_view done. within the retries count:
                   3543:     
                   3544:     do {
                   3545:          ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
                   3546:          $ok      = $response->is_success;
                   3547:          if (!$ok) {
                   3548:             &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
                   3549:          }
                   3550:          $retries--;
                   3551:     } while (!$ok && ($retries > 0));
                   3552:     
                   3553:     if (!$ok) {
                   3554:        $content = '';          # On error return an empty content.
                   3555:     }
1.651     www      3556:     if (wantarray) {
                   3557:        return ($content, $response);
                   3558:     } else {
                   3559:        return $content;
                   3560:     }
1.11      albertel 3561: }
                   3562: 
1.112     bowersj2 3563: =pod
                   3564: 
1.648     raeburn  3565: =item * &get_student_answers() 
1.112     bowersj2 3566: 
                   3567: show a snapshot of how student was answering problem
                   3568: 
                   3569: =cut
                   3570: 
1.11      albertel 3571: sub get_student_answers {
1.100     sakharuk 3572:   my ($symb,$username,$domain,$courseid,%form) = @_;
1.114     www      3573:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3574:   my (%moreenv);
1.11      albertel 3575:   my @elements=('symb','courseid','domain','username');
                   3576:   foreach my $element (@elements) {
1.186     albertel 3577:     $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3578:   }
1.186     albertel 3579:   $moreenv{'grade_target'}='answer';
                   3580:   %moreenv=(%form,%moreenv);
1.497     raeburn  3581:   $feedurl = &Apache::lonnet::clutter($feedurl);
                   3582:   my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10      albertel 3583:   return $userview;
1.1       albertel 3584: }
1.116     albertel 3585: 
                   3586: =pod
                   3587: 
                   3588: =item * &submlink()
                   3589: 
1.242     albertel 3590: Inputs: $text $uname $udom $symb $target
1.116     albertel 3591: 
                   3592: Returns: A link to grades.pm such as to see the SUBM view of a student
                   3593: 
                   3594: =cut
                   3595: 
                   3596: ###############################################
                   3597: sub submlink {
1.242     albertel 3598:     my ($text,$uname,$udom,$symb,$target)=@_;
1.116     albertel 3599:     if (!($uname && $udom)) {
                   3600: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3601: 	    &Apache::lonnet::whichuser($symb);
1.116     albertel 3602: 	if (!$symb) { $symb=$cursymb; }
                   3603:     }
1.254     matthew  3604:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3605:     $symb=&escape($symb);
1.242     albertel 3606:     if ($target) { $target="target=\"$target\""; }
                   3607:     return '<a href="/adm/grades?&command=submission&'.
                   3608: 	'symb='.$symb.'&student='.$uname.
                   3609: 	'&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
                   3610: }
                   3611: ##############################################
                   3612: 
                   3613: =pod
                   3614: 
                   3615: =item * &pgrdlink()
                   3616: 
                   3617: Inputs: $text $uname $udom $symb $target
                   3618: 
                   3619: Returns: A link to grades.pm such as to see the PGRD view of a student
                   3620: 
                   3621: =cut
                   3622: 
                   3623: ###############################################
                   3624: sub pgrdlink {
                   3625:     my $link=&submlink(@_);
                   3626:     $link=~s/(&command=submission)/$1&showgrading=yes/;
                   3627:     return $link;
                   3628: }
                   3629: ##############################################
                   3630: 
                   3631: =pod
                   3632: 
                   3633: =item * &pprmlink()
                   3634: 
                   3635: Inputs: $text $uname $udom $symb $target
                   3636: 
                   3637: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283     albertel 3638: student and a specific resource
1.242     albertel 3639: 
                   3640: =cut
                   3641: 
                   3642: ###############################################
                   3643: sub pprmlink {
                   3644:     my ($text,$uname,$udom,$symb,$target)=@_;
                   3645:     if (!($uname && $udom)) {
                   3646: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3647: 	    &Apache::lonnet::whichuser($symb);
1.242     albertel 3648: 	if (!$symb) { $symb=$cursymb; }
                   3649:     }
1.254     matthew  3650:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3651:     $symb=&escape($symb);
1.242     albertel 3652:     if ($target) { $target="target=\"$target\""; }
1.595     albertel 3653:     return '<a href="/adm/parmset?command=set&amp;'.
                   3654: 	'symb='.$symb.'&amp;uname='.$uname.
                   3655: 	'&amp;udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116     albertel 3656: }
                   3657: ##############################################
1.37      matthew  3658: 
1.112     bowersj2 3659: =pod
                   3660: 
                   3661: =back
                   3662: 
                   3663: =cut
                   3664: 
1.37      matthew  3665: ###############################################
1.51      www      3666: 
                   3667: 
                   3668: sub timehash {
1.687     raeburn  3669:     my ($thistime) = @_;
                   3670:     my $timezone = &Apache::lonlocal::gettimezone();
                   3671:     my $dt = DateTime->from_epoch(epoch => $thistime)
                   3672:                      ->set_time_zone($timezone);
                   3673:     my $wday = $dt->day_of_week();
                   3674:     if ($wday == 7) { $wday = 0; }
                   3675:     return ( 'second' => $dt->second(),
                   3676:              'minute' => $dt->minute(),
                   3677:              'hour'   => $dt->hour(),
                   3678:              'day'     => $dt->day_of_month(),
                   3679:              'month'   => $dt->month(),
                   3680:              'year'    => $dt->year(),
                   3681:              'weekday' => $wday,
                   3682:              'dayyear' => $dt->day_of_year(),
                   3683:              'dlsav'   => $dt->is_dst() );
1.51      www      3684: }
                   3685: 
1.370     www      3686: sub utc_string {
                   3687:     my ($date)=@_;
1.371     www      3688:     return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370     www      3689: }
                   3690: 
1.51      www      3691: sub maketime {
                   3692:     my %th=@_;
1.687     raeburn  3693:     my ($epoch_time,$timezone,$dt);
                   3694:     $timezone = &Apache::lonlocal::gettimezone();
                   3695:     eval {
                   3696:         $dt = DateTime->new( year   => $th{'year'},
                   3697:                              month  => $th{'month'},
                   3698:                              day    => $th{'day'},
                   3699:                              hour   => $th{'hour'},
                   3700:                              minute => $th{'minute'},
                   3701:                              second => $th{'second'},
                   3702:                              time_zone => $timezone,
                   3703:                          );
                   3704:     };
                   3705:     if (!$@) {
                   3706:         $epoch_time = $dt->epoch;
                   3707:         if ($epoch_time) {
                   3708:             return $epoch_time;
                   3709:         }
                   3710:     }
1.51      www      3711:     return POSIX::mktime(
                   3712:         ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210     www      3713:          $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70      www      3714: }
                   3715: 
                   3716: #########################################
1.51      www      3717: 
                   3718: sub findallcourses {
1.482     raeburn  3719:     my ($roles,$uname,$udom) = @_;
1.355     albertel 3720:     my %roles;
                   3721:     if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348     albertel 3722:     my %courses;
1.51      www      3723:     my $now=time;
1.482     raeburn  3724:     if (!defined($uname)) {
                   3725:         $uname = $env{'user.name'};
                   3726:     }
                   3727:     if (!defined($udom)) {
                   3728:         $udom = $env{'user.domain'};
                   3729:     }
                   3730:     if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
                   3731:         my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
                   3732:         if (!%roles) {
                   3733:             %roles = (
                   3734:                        cc => 1,
                   3735:                        in => 1,
                   3736:                        ep => 1,
                   3737:                        ta => 1,
                   3738:                        cr => 1,
                   3739:                        st => 1,
                   3740:              );
                   3741:         }
                   3742:         foreach my $entry (keys(%roleshash)) {
                   3743:             my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
                   3744:             if ($trole =~ /^cr/) { 
                   3745:                 next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
                   3746:             } else {
                   3747:                 next if (!exists($roles{$trole}));
                   3748:             }
                   3749:             if ($tend) {
                   3750:                 next if ($tend < $now);
                   3751:             }
                   3752:             if ($tstart) {
                   3753:                 next if ($tstart > $now);
                   3754:             }
                   3755:             my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
                   3756:             (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
                   3757:             if ($secpart eq '') {
                   3758:                 ($cnum,$role) = split(/_/,$cnumpart); 
                   3759:                 $sec = 'none';
                   3760:                 $realsec = '';
                   3761:             } else {
                   3762:                 $cnum = $cnumpart;
                   3763:                 ($sec,$role) = split(/_/,$secpart);
                   3764:                 $realsec = $sec;
1.490     raeburn  3765:             }
1.482     raeburn  3766:             $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
                   3767:         }
                   3768:     } else {
                   3769:         foreach my $key (keys(%env)) {
1.483     albertel 3770: 	    if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
                   3771:                  $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482     raeburn  3772: 	        my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
                   3773: 	        next if ($role eq 'ca' || $role eq 'aa');
                   3774: 	        next if (%roles && !exists($roles{$role}));
                   3775: 	        my ($starttime,$endtime)=split(/\./,$env{$key});
                   3776:                 my $active=1;
                   3777:                 if ($starttime) {
                   3778: 		    if ($now<$starttime) { $active=0; }
                   3779:                 }
                   3780:                 if ($endtime) {
                   3781:                     if ($now>$endtime) { $active=0; }
                   3782:                 }
                   3783:                 if ($active) {
                   3784:                     if ($sec eq '') {
                   3785:                         $sec = 'none';
                   3786:                     }
                   3787:                     $courses{$cdom.'_'.$cnum}{$sec} = 
                   3788:                                      $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474     raeburn  3789:                 }
                   3790:             }
1.51      www      3791:         }
                   3792:     }
1.474     raeburn  3793:     return %courses;
1.51      www      3794: }
1.37      matthew  3795: 
1.54      www      3796: ###############################################
1.474     raeburn  3797: 
                   3798: sub blockcheck {
1.482     raeburn  3799:     my ($setters,$activity,$uname,$udom) = @_;
1.490     raeburn  3800: 
                   3801:     if (!defined($udom)) {
                   3802:         $udom = $env{'user.domain'};
                   3803:     }
                   3804:     if (!defined($uname)) {
                   3805:         $uname = $env{'user.name'};
                   3806:     }
                   3807: 
                   3808:     # If uname and udom are for a course, check for blocks in the course.
                   3809: 
                   3810:     if (&Apache::lonnet::is_course($udom,$uname)) {
                   3811:         my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502     raeburn  3812:         my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490     raeburn  3813:         return ($startblock,$endblock);
                   3814:     }
1.474     raeburn  3815: 
1.502     raeburn  3816:     my $startblock = 0;
                   3817:     my $endblock = 0;
1.482     raeburn  3818:     my %live_courses = &findallcourses(undef,$uname,$udom);
1.474     raeburn  3819: 
1.490     raeburn  3820:     # If uname is for a user, and activity is course-specific, i.e.,
                   3821:     # boards, chat or groups, check for blocking in current course only.
1.474     raeburn  3822: 
1.490     raeburn  3823:     if (($activity eq 'boards' || $activity eq 'chat' ||
                   3824:          $activity eq 'groups') && ($env{'request.course.id'})) {
                   3825:         foreach my $key (keys(%live_courses)) {
                   3826:             if ($key ne $env{'request.course.id'}) {
                   3827:                 delete($live_courses{$key});
                   3828:             }
                   3829:         }
                   3830:     }
                   3831: 
                   3832:     my $otheruser = 0;
                   3833:     my %own_courses;
                   3834:     if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
                   3835:         # Resource belongs to user other than current user.
                   3836:         $otheruser = 1;
                   3837:         # Gather courses for current user
                   3838:         %own_courses = 
                   3839:             &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
                   3840:     }
                   3841: 
                   3842:     # Gather active course roles - course coordinator, instructor, 
                   3843:     # exam proctor, ta, student, or custom role.
1.474     raeburn  3844: 
                   3845:     foreach my $course (keys(%live_courses)) {
1.482     raeburn  3846:         my ($cdom,$cnum);
                   3847:         if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
                   3848:             $cdom = $env{'course.'.$course.'.domain'};
                   3849:             $cnum = $env{'course.'.$course.'.num'};
                   3850:         } else {
1.490     raeburn  3851:             ($cdom,$cnum) = split(/_/,$course); 
1.482     raeburn  3852:         }
                   3853:         my $no_ownblock = 0;
                   3854:         my $no_userblock = 0;
1.533     raeburn  3855:         if ($otheruser && $activity ne 'com') {
1.490     raeburn  3856:             # Check if current user has 'evb' priv for this
                   3857:             if (defined($own_courses{$course})) {
                   3858:                 foreach my $sec (keys(%{$own_courses{$course}})) {
                   3859:                     my $checkrole = 'cm./'.$cdom.'/'.$cnum;
                   3860:                     if ($sec ne 'none') {
                   3861:                         $checkrole .= '/'.$sec;
                   3862:                     }
                   3863:                     if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   3864:                         $no_ownblock = 1;
                   3865:                         last;
                   3866:                     }
                   3867:                 }
                   3868:             }
                   3869:             # if they have 'evb' priv and are currently not playing student
                   3870:             next if (($no_ownblock) &&
                   3871:                  ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
                   3872:         }
1.474     raeburn  3873:         foreach my $sec (keys(%{$live_courses{$course}})) {
1.482     raeburn  3874:             my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474     raeburn  3875:             if ($sec ne 'none') {
1.482     raeburn  3876:                 $checkrole .= '/'.$sec;
1.474     raeburn  3877:             }
1.490     raeburn  3878:             if ($otheruser) {
                   3879:                 # Resource belongs to user other than current user.
                   3880:                 # Assemble privs for that user, and check for 'evb' priv.
1.482     raeburn  3881:                 my ($trole,$tdom,$tnum,$tsec);
                   3882:                 my $entry = $live_courses{$course}{$sec};
                   3883:                 if ($entry =~ /^cr/) {
                   3884:                     ($trole,$tdom,$tnum,$tsec) = 
                   3885:                       ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
                   3886:                 } else {
                   3887:                     ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
                   3888:                 }
                   3889:                 my ($spec,$area,$trest,%allroles,%userroles);
                   3890:                 $area = '/'.$tdom.'/'.$tnum;
                   3891:                 $trest = $tnum;
                   3892:                 if ($tsec ne '') {
                   3893:                     $area .= '/'.$tsec;
                   3894:                     $trest .= '/'.$tsec;
                   3895:                 }
                   3896:                 $spec = $trole.'.'.$area;
                   3897:                 if ($trole =~ /^cr/) {
                   3898:                     &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
                   3899:                                                       $tdom,$spec,$trest,$area);
                   3900:                 } else {
                   3901:                     &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
                   3902:                                                        $tdom,$spec,$trest,$area);
                   3903:                 }
                   3904:                 my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486     raeburn  3905:                 if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
                   3906:                     if ($1) {
                   3907:                         $no_userblock = 1;
                   3908:                         last;
                   3909:                     }
                   3910:                 }
1.490     raeburn  3911:             } else {
                   3912:                 # Resource belongs to current user
                   3913:                 # Check for 'evb' priv via lonnet::allowed().
1.482     raeburn  3914:                 if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   3915:                     $no_ownblock = 1;
                   3916:                     last;
                   3917:                 }
1.474     raeburn  3918:             }
                   3919:         }
                   3920:         # if they have the evb priv and are currently not playing student
1.482     raeburn  3921:         next if (($no_ownblock) &&
1.491     albertel 3922:                  ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482     raeburn  3923:         next if ($no_userblock);
1.474     raeburn  3924: 
1.866     kalberla 3925:         # Retrieve blocking times and identity of locker for course
1.490     raeburn  3926:         # of specified user, unless user has 'evb' privilege.
1.502     raeburn  3927:         
                   3928:         my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
                   3929:         if (($start != 0) && 
                   3930:             (($startblock == 0) || ($startblock > $start))) {
                   3931:             $startblock = $start;
                   3932:         }
                   3933:         if (($end != 0)  &&
                   3934:             (($endblock == 0) || ($endblock < $end))) {
                   3935:             $endblock = $end;
                   3936:         }
1.490     raeburn  3937:     }
                   3938:     return ($startblock,$endblock);
                   3939: }
                   3940: 
                   3941: sub get_blocks {
                   3942:     my ($setters,$activity,$cdom,$cnum) = @_;
                   3943:     my $startblock = 0;
                   3944:     my $endblock = 0;
                   3945:     my $course = $cdom.'_'.$cnum;
                   3946:     $setters->{$course} = {};
                   3947:     $setters->{$course}{'staff'} = [];
                   3948:     $setters->{$course}{'times'} = [];
                   3949:     my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
                   3950:     foreach my $record (keys(%records)) {
                   3951:         my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
                   3952:         if ($start <= time && $end >= time) {
                   3953:             my ($staff_name,$staff_dom,$title,$blocks) =
                   3954:                 &parse_block_record($records{$record});
                   3955:             if ($blocks->{$activity} eq 'on') {
                   3956:                 push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
                   3957:                 push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491     albertel 3958:                 if ( ($startblock == 0) || ($startblock > $start) ) {
                   3959:                     $startblock = $start;
1.490     raeburn  3960:                 }
1.491     albertel 3961:                 if ( ($endblock == 0) || ($endblock < $end) ) {
                   3962:                     $endblock = $end;
1.474     raeburn  3963:                 }
                   3964:             }
                   3965:         }
                   3966:     }
                   3967:     return ($startblock,$endblock);
                   3968: }
                   3969: 
                   3970: sub parse_block_record {
                   3971:     my ($record) = @_;
                   3972:     my ($setuname,$setudom,$title,$blocks);
                   3973:     if (ref($record) eq 'HASH') {
                   3974:         ($setuname,$setudom) = split(/:/,$record->{'setter'});
                   3975:         $title = &unescape($record->{'event'});
                   3976:         $blocks = $record->{'blocks'};
                   3977:     } else {
                   3978:         my @data = split(/:/,$record,3);
                   3979:         if (scalar(@data) eq 2) {
                   3980:             $title = $data[1];
                   3981:             ($setuname,$setudom) = split(/@/,$data[0]);
                   3982:         } else {
                   3983:             ($setuname,$setudom,$title) = @data;
                   3984:         }
                   3985:         $blocks = { 'com' => 'on' };
                   3986:     }
                   3987:     return ($setuname,$setudom,$title,$blocks);
                   3988: }
                   3989: 
1.854     kalberla 3990: sub blocking_status {
                   3991:   my ($activity,$uname,$udom) = @_;
1.867     kalberla 3992:   my %setters;
1.890     droeschl 3993: 
                   3994:   # check for active blocking
1.867     kalberla 3995:   my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
1.854     kalberla 3996: 
1.890     droeschl 3997:   my $blocked = $startblock && $endblock ? 1 : 0;
                   3998: 
                   3999:   # caller just wants to know whether a block is active
                   4000:   if (!wantarray) { return $blocked; }
                   4001: 
                   4002:   # build a link to a popup window containing the details
                   4003:   my $querystring  = "?activity=$activity";
                   4004:   # $uname and $udom decide whose portfolio the user is trying to look at
                   4005:      $querystring .= "&amp;udom=$udom"      if $udom;
                   4006:      $querystring .= "&amp;uname=$uname"    if $uname;
                   4007: 
                   4008:   my $output .= <<'END_MYBLOCK';
1.854     kalberla 4009:     function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
                   4010:         var options = "width=" + w + ",height=" + h + ",";
                   4011:         options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
                   4012:         options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
                   4013:         var newWin = window.open(url, wdwName, options);
                   4014:         newWin.focus();
                   4015:     }
1.890     droeschl 4016: END_MYBLOCK
1.854     kalberla 4017: 
1.890     droeschl 4018:   $output = Apache::lonhtmlcommon::scripttag($output);
                   4019:   
1.854     kalberla 4020:   my $popupUrl = "/adm/blockingstatus/$querystring";
1.890     droeschl 4021:   my $text = mt('Communication Blocked');
                   4022: 
1.867     kalberla 4023:   $output .= <<"END_BLOCK";
                   4024: <div class='LC_comblock'>
1.869     kalberla 4025:   <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890     droeschl 4026:   title='$text'>
                   4027:   <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869     kalberla 4028:   <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring' 
1.890     droeschl 4029:   title='$text'>$text</a>
1.867     kalberla 4030: </div>
                   4031: 
                   4032: END_BLOCK
1.474     raeburn  4033: 
1.854     kalberla 4034:   return ($blocked, $output);
                   4035: }
1.490     raeburn  4036: 
1.60      matthew  4037: ###############################################
                   4038: 
1.682     raeburn  4039: sub check_ip_acc {
                   4040:     my ($acc)=@_;
                   4041:     &Apache::lonxml::debug("acc is $acc");
                   4042:     if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
                   4043:         return 1;
                   4044:     }
                   4045:     my $allowed=0;
                   4046:     my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
                   4047: 
                   4048:     my $name;
                   4049:     foreach my $pattern (split(',',$acc)) {
                   4050:         $pattern =~ s/^\s*//;
                   4051:         $pattern =~ s/\s*$//;
                   4052:         if ($pattern =~ /\*$/) {
                   4053:             #35.8.*
                   4054:             $pattern=~s/\*//;
                   4055:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   4056:         } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
                   4057:             #35.8.3.[34-56]
                   4058:             my $low=$2;
                   4059:             my $high=$3;
                   4060:             $pattern=$1;
                   4061:             if ($ip =~ /^\Q$pattern\E/) {
                   4062:                 my $last=(split(/\./,$ip))[3];
                   4063:                 if ($last <=$high && $last >=$low) { $allowed=1; }
                   4064:             }
                   4065:         } elsif ($pattern =~ /^\*/) {
                   4066:             #*.msu.edu
                   4067:             $pattern=~s/\*//;
                   4068:             if (!defined($name)) {
                   4069:                 use Socket;
                   4070:                 my $netaddr=inet_aton($ip);
                   4071:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   4072:             }
                   4073:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   4074:         } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
                   4075:             #127.0.0.1
                   4076:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   4077:         } else {
                   4078:             #some.name.com
                   4079:             if (!defined($name)) {
                   4080:                 use Socket;
                   4081:                 my $netaddr=inet_aton($ip);
                   4082:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   4083:             }
                   4084:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   4085:         }
                   4086:         if ($allowed) { last; }
                   4087:     }
                   4088:     return $allowed;
                   4089: }
                   4090: 
                   4091: ###############################################
                   4092: 
1.60      matthew  4093: =pod
                   4094: 
1.112     bowersj2 4095: =head1 Domain Template Functions
                   4096: 
                   4097: =over 4
                   4098: 
                   4099: =item * &determinedomain()
1.60      matthew  4100: 
                   4101: Inputs: $domain (usually will be undef)
                   4102: 
1.63      www      4103: Returns: Determines which domain should be used for designs
1.60      matthew  4104: 
                   4105: =cut
1.54      www      4106: 
1.60      matthew  4107: ###############################################
1.63      www      4108: sub determinedomain {
                   4109:     my $domain=shift;
1.531     albertel 4110:     if (! $domain) {
1.60      matthew  4111:         # Determine domain if we have not been given one
1.893     raeburn  4112:         $domain = &Apache::lonnet::default_login_domain();
1.258     albertel 4113:         if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
                   4114:         if ($env{'request.role.domain'}) { 
                   4115:             $domain=$env{'request.role.domain'}; 
1.60      matthew  4116:         }
                   4117:     }
1.63      www      4118:     return $domain;
                   4119: }
                   4120: ###############################################
1.517     raeburn  4121: 
1.518     albertel 4122: sub devalidate_domconfig_cache {
                   4123:     my ($udom)=@_;
                   4124:     &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
                   4125: }
                   4126: 
                   4127: # ---------------------- Get domain configuration for a domain
                   4128: sub get_domainconf {
                   4129:     my ($udom) = @_;
                   4130:     my $cachetime=1800;
                   4131:     my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
                   4132:     if (defined($cached)) { return %{$result}; }
                   4133: 
                   4134:     my %domconfig = &Apache::lonnet::get_dom('configuration',
                   4135: 					     ['login','rolecolors'],$udom);
1.632     raeburn  4136:     my (%designhash,%legacy);
1.518     albertel 4137:     if (keys(%domconfig) > 0) {
                   4138:         if (ref($domconfig{'login'}) eq 'HASH') {
1.632     raeburn  4139:             if (keys(%{$domconfig{'login'}})) {
                   4140:                 foreach my $key (keys(%{$domconfig{'login'}})) {
1.699     raeburn  4141:                     if (ref($domconfig{'login'}{$key}) eq 'HASH') {
                   4142:                         foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
                   4143:                             $designhash{$udom.'.login.'.$key.'_'.$img} = 
                   4144:                                 $domconfig{'login'}{$key}{$img};
                   4145:                         }
                   4146:                     } else {
                   4147:                         $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
                   4148:                     }
1.632     raeburn  4149:                 }
                   4150:             } else {
                   4151:                 $legacy{'login'} = 1;
1.518     albertel 4152:             }
1.632     raeburn  4153:         } else {
                   4154:             $legacy{'login'} = 1;
1.518     albertel 4155:         }
                   4156:         if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632     raeburn  4157:             if (keys(%{$domconfig{'rolecolors'}})) {
                   4158:                 foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
                   4159:                     if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
                   4160:                         foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
                   4161:                             $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
                   4162:                         }
1.518     albertel 4163:                     }
                   4164:                 }
1.632     raeburn  4165:             } else {
                   4166:                 $legacy{'rolecolors'} = 1;
1.518     albertel 4167:             }
1.632     raeburn  4168:         } else {
                   4169:             $legacy{'rolecolors'} = 1;
1.518     albertel 4170:         }
1.632     raeburn  4171:         if (keys(%legacy) > 0) {
                   4172:             my %legacyhash = &get_legacy_domconf($udom);
                   4173:             foreach my $item (keys(%legacyhash)) {
                   4174:                 if ($item =~ /^\Q$udom\E\.login/) {
                   4175:                     if ($legacy{'login'}) { 
                   4176:                         $designhash{$item} = $legacyhash{$item};
                   4177:                     }
                   4178:                 } else {
                   4179:                     if ($legacy{'rolecolors'}) {
                   4180:                         $designhash{$item} = $legacyhash{$item};
                   4181:                     }
1.518     albertel 4182:                 }
                   4183:             }
                   4184:         }
1.632     raeburn  4185:     } else {
                   4186:         %designhash = &get_legacy_domconf($udom); 
1.518     albertel 4187:     }
                   4188:     &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
                   4189: 				  $cachetime);
                   4190:     return %designhash;
                   4191: }
                   4192: 
1.632     raeburn  4193: sub get_legacy_domconf {
                   4194:     my ($udom) = @_;
                   4195:     my %legacyhash;
                   4196:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
                   4197:     my $designfile =  $designdir.'/'.$udom.'.tab';
                   4198:     if (-e $designfile) {
                   4199:         if ( open (my $fh,"<$designfile") ) {
                   4200:             while (my $line = <$fh>) {
                   4201:                 next if ($line =~ /^\#/);
                   4202:                 chomp($line);
                   4203:                 my ($key,$val)=(split(/\=/,$line));
                   4204:                 if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
                   4205:             }
                   4206:             close($fh);
                   4207:         }
                   4208:     }
                   4209:     if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
                   4210:         $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
                   4211:     }
                   4212:     return %legacyhash;
                   4213: }
                   4214: 
1.63      www      4215: =pod
                   4216: 
1.112     bowersj2 4217: =item * &domainlogo()
1.63      www      4218: 
                   4219: Inputs: $domain (usually will be undef)
                   4220: 
                   4221: Returns: A link to a domain logo, if the domain logo exists.
                   4222: If the domain logo does not exist, a description of the domain.
                   4223: 
                   4224: =cut
1.112     bowersj2 4225: 
1.63      www      4226: ###############################################
                   4227: sub domainlogo {
1.517     raeburn  4228:     my $domain = &determinedomain(shift);
1.518     albertel 4229:     my %designhash = &get_domainconf($domain);    
1.517     raeburn  4230:     # See if there is a logo
                   4231:     if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519     raeburn  4232:         my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538     albertel 4233:         if ($imgsrc =~ m{^/(adm|res)/}) {
                   4234: 	    if ($imgsrc =~ m{^/res/}) {
                   4235: 		my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
                   4236: 		&Apache::lonnet::repcopy($local_name);
                   4237: 	    }
                   4238: 	   $imgsrc = &lonhttpdurl($imgsrc);
1.519     raeburn  4239:         } 
                   4240:         return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514     albertel 4241:     } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
                   4242:         return &Apache::lonnet::domain($domain,'description');
1.59      www      4243:     } else {
1.60      matthew  4244:         return '';
1.59      www      4245:     }
                   4246: }
1.63      www      4247: ##############################################
                   4248: 
                   4249: =pod
                   4250: 
1.112     bowersj2 4251: =item * &designparm()
1.63      www      4252: 
                   4253: Inputs: $which parameter; $domain (usually will be undef)
                   4254: 
                   4255: Returns: value of designparamter $which
                   4256: 
                   4257: =cut
1.112     bowersj2 4258: 
1.397     albertel 4259: 
1.400     albertel 4260: ##############################################
1.397     albertel 4261: sub designparm {
                   4262:     my ($which,$domain)=@_;
                   4263:     if (exists($env{'environment.color.'.$which})) {
1.817     bisitz   4264:         return $env{'environment.color.'.$which};
1.96      www      4265:     }
1.63      www      4266:     $domain=&determinedomain($domain);
1.518     albertel 4267:     my %domdesign = &get_domainconf($domain);
1.520     raeburn  4268:     my $output;
1.517     raeburn  4269:     if ($domdesign{$domain.'.'.$which} ne '') {
1.817     bisitz   4270:         $output = $domdesign{$domain.'.'.$which};
1.63      www      4271:     } else {
1.520     raeburn  4272:         $output = $defaultdesign{$which};
                   4273:     }
                   4274:     if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635     raeburn  4275:         ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538     albertel 4276:         if ($output =~ m{^/(adm|res)/}) {
1.817     bisitz   4277:             if ($output =~ m{^/res/}) {
                   4278:                 my $local_name = &Apache::lonnet::filelocation('',$output);
                   4279:                 &Apache::lonnet::repcopy($local_name);
                   4280:             }
1.520     raeburn  4281:             $output = &lonhttpdurl($output);
                   4282:         }
1.63      www      4283:     }
1.520     raeburn  4284:     return $output;
1.63      www      4285: }
1.59      www      4286: 
1.822     bisitz   4287: ##############################################
                   4288: =pod
                   4289: 
1.832     bisitz   4290: =item * &authorspace()
                   4291: 
                   4292: Inputs: ./.
                   4293: 
                   4294: Returns: Path to the Construction Space of the current user's
                   4295:          accessed author space
                   4296:          The author space will be that of the current user
                   4297:          when accessing the own author space
                   4298:          and that of the co-author/assistent co-author
                   4299:          when accessing the co-author's/assistent co-author's
                   4300:          space
                   4301: 
                   4302: =cut
                   4303: 
                   4304: sub authorspace {
                   4305:     my $caname = '';
                   4306:     if ($env{'request.role'} =~ /^ca|^aa/) {
                   4307:         (undef,$caname) =
                   4308:             ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
                   4309:     } else {
                   4310:         $caname = $env{'user.name'};
                   4311:     }
                   4312:     return '/priv/'.$caname.'/';
                   4313: }
                   4314: 
                   4315: ##############################################
                   4316: =pod
                   4317: 
1.822     bisitz   4318: =item * &head_subbox()
                   4319: 
                   4320: Inputs: $content (contains HTML code with page functions, etc.)
                   4321: 
                   4322: Returns: HTML div with $content
                   4323:          To be included in page header
                   4324: 
                   4325: =cut
                   4326: 
                   4327: sub head_subbox {
                   4328:     my ($content)=@_;
                   4329:     my $output =
1.844     bisitz   4330:         '<div id="LC_head_subbox">'
1.822     bisitz   4331:        .$content
                   4332:        .'</div>'
                   4333: }
                   4334: 
                   4335: ##############################################
                   4336: =pod
                   4337: 
                   4338: =item * &CSTR_pageheader()
                   4339: 
                   4340: Inputs: ./.
                   4341: 
                   4342: Returns: HTML div with CSTR path and recent box
                   4343:          To be included on Construction Space pages
                   4344: 
                   4345: =cut
                   4346: 
                   4347: sub CSTR_pageheader {
                   4348:     # this is for resources; directories have customtitle, and crumbs
                   4349:             # and select recent are created in lonpubdir.pm  
                   4350:     my ($uname,$thisdisfn)=
                   4351:         ($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
                   4352:     my $formaction='/priv/'.$uname.'/'.$thisdisfn;
                   4353:     $formaction=~s/\/+/\//g;
                   4354: 
                   4355:     my $parentpath = '';
                   4356:     my $lastitem = '';
                   4357:     if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
                   4358:         $parentpath = $1;
                   4359:         $lastitem = $2;
                   4360:     } else {
                   4361:         $lastitem = $thisdisfn;
                   4362:     }
                   4363:     return
                   4364:          '<div>'
                   4365:         .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
                   4366:         .'<b>'.&mt('Construction Space:').'</b> '
                   4367:         .'<form name="dirs" method="post" action="'.$formaction
                   4368:         .'" target="_top"><tt><b>' #FIXME lonpubdir: target="_parent"
                   4369:         .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."$lastitem</b></tt><br />"
                   4370:         #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
                   4371:         .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
                   4372:         .'</form>'
                   4373:         .&Apache::lonmenu::constspaceform()
                   4374:         .'</div>';
                   4375: }
                   4376: 
1.60      matthew  4377: ###############################################
                   4378: ###############################################
                   4379: 
                   4380: =pod
                   4381: 
1.112     bowersj2 4382: =back
                   4383: 
1.549     albertel 4384: =head1 HTML Helpers
1.112     bowersj2 4385: 
                   4386: =over 4
                   4387: 
                   4388: =item * &bodytag()
1.60      matthew  4389: 
                   4390: Returns a uniform header for LON-CAPA web pages.
                   4391: 
                   4392: Inputs: 
                   4393: 
1.112     bowersj2 4394: =over 4
                   4395: 
                   4396: =item * $title, A title to be displayed on the page.
                   4397: 
                   4398: =item * $function, the current role (can be undef).
                   4399: 
                   4400: =item * $addentries, extra parameters for the <body> tag.
                   4401: 
                   4402: =item * $bodyonly, if defined, only return the <body> tag.
                   4403: 
                   4404: =item * $domain, if defined, force a given domain.
                   4405: 
                   4406: =item * $forcereg, if page should register as content page (relevant for 
1.86      www      4407:             text interface only)
1.60      matthew  4408: 
1.814     bisitz   4409: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
                   4410:                      navigational links
1.317     albertel 4411: 
1.338     albertel 4412: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
                   4413: 
1.361     albertel 4414: =item * $no_inline_link, if true and in remote mode, don't show the 
                   4415:          'Switch To Inline Menu' link
                   4416: 
1.460     albertel 4417: =item * $args, optional argument valid values are
                   4418:             no_auto_mt_title -> prevents &mt()ing the title arg
1.562     albertel 4419:             inherit_jsmath -> when creating popup window in a page,
                   4420:                               should it have jsmath forced on by the
                   4421:                               current page
1.460     albertel 4422: 
1.112     bowersj2 4423: =back
                   4424: 
1.60      matthew  4425: Returns: A uniform header for LON-CAPA web pages.  
                   4426: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
                   4427: If $bodyonly is undef or zero, an html string containing a <body> tag and 
                   4428: other decorations will be returned.
                   4429: 
                   4430: =cut
                   4431: 
1.54      www      4432: sub bodytag {
1.831     bisitz   4433:     my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.816     bisitz   4434:         $no_nav_bar,$bgcolor,$no_inline_link,$args)=@_;
1.339     albertel 4435: 
1.460     albertel 4436:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339     albertel 4437: 
1.183     matthew  4438:     $function = &get_users_function() if (!$function);
1.339     albertel 4439:     my $img =    &designparm($function.'.img',$domain);
                   4440:     my $font =   &designparm($function.'.font',$domain);
                   4441:     my $pgbg   = $bgcolor || &designparm($function.'.pgbg',$domain);
                   4442: 
1.803     bisitz   4443:     my %design = ( 'style'   => 'margin-top: 0',
1.535     albertel 4444: 		   'bgcolor' => $pgbg,
1.339     albertel 4445: 		   'text'    => $font,
                   4446:                    'alink'   => &designparm($function.'.alink',$domain),
                   4447: 		   'vlink'   => &designparm($function.'.vlink',$domain),
                   4448: 		   'link'    => &designparm($function.'.link',$domain),);
1.438     albertel 4449:     @design{keys(%$addentries)} = @$addentries{keys(%$addentries)}; 
1.339     albertel 4450: 
1.63      www      4451:  # role and realm
1.378     raeburn  4452:     my ($role,$realm) = split(/\./,$env{'request.role'},2);
                   4453:     if ($role  eq 'ca') {
1.479     albertel 4454:         my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500     albertel 4455:         $realm = &plainname($rname,$rdom);
1.378     raeburn  4456:     } 
1.55      www      4457: # realm
1.258     albertel 4458:     if ($env{'request.course.id'}) {
1.378     raeburn  4459:         if ($env{'request.role'} !~ /^cr/) {
                   4460:             $role = &Apache::lonnet::plaintext($role,&course_type());
                   4461:         }
1.898     raeburn  4462:         if ($env{'request.course.sec'}) {
                   4463:             $role .= ('&nbsp;'x2).'-&nbsp;'.&mt('section:').'&nbsp;'.$env{'request.course.sec'};
                   4464:         }   
1.359     albertel 4465: 	$realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378     raeburn  4466:     } else {
                   4467:         $role = &Apache::lonnet::plaintext($role);
1.54      www      4468:     }
1.433     albertel 4469: 
1.359     albertel 4470:     if (!$realm) { $realm='&nbsp;'; }
1.55      www      4471: # Set messages
1.60      matthew  4472:     my $messages=&domainlogo($domain);
1.330     albertel 4473: 
1.438     albertel 4474:     my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329     albertel 4475: 
1.101     www      4476: # construct main body tag
1.359     albertel 4477:     my $bodytag = "<body $extra_body_attr>".
1.562     albertel 4478: 	&Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252     albertel 4479: 
1.530     albertel 4480:     if ($bodyonly) {
1.60      matthew  4481:         return $bodytag;
1.798     tempelho 4482:     } 
1.359     albertel 4483: 
1.410     albertel 4484:     my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433     albertel 4485:     if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
                   4486: 	undef($role);
1.434     albertel 4487:     } else {
                   4488: 	$name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433     albertel 4489:     }
1.359     albertel 4490:     
1.762     bisitz   4491:     my $titleinfo = '<h1>'.$title.'</h1>';
1.359     albertel 4492:     #
                   4493:     # Extra info if you are the DC
                   4494:     my $dc_info = '';
                   4495:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   4496:                         $env{'course.'.$env{'request.course.id'}.
                   4497:                                  '.domain'}.'/'})) {
                   4498:         my $cid = $env{'request.course.id'};
                   4499:         $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380     www      4500:         $dc_info =~ s/\s+$//;
1.359     albertel 4501:         $dc_info = '('.$dc_info.')';
                   4502:     }
                   4503: 
1.898     raeburn  4504:     $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853     droeschl 4505:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   4506: 
1.837     bisitz   4507:     if ($env{'environment.remote'} eq 'off') {
1.359     albertel 4508:         # No Remote
1.903     droeschl 4509:         if ($no_nav_bar) { return $bodytag; } 
                   4510: 
                   4511:         if ($env{'request.state'} eq 'construct') { $forcereg=1; }
                   4512: 
                   4513:         #    if ($env{'request.state'} eq 'construct') {
                   4514:         #        $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
                   4515:         #    }
                   4516: 
                   4517:         $bodytag .= qq|<div id="LC_nav_bar">$name $role<br />
                   4518:             <em>$realm</em> $dc_info</div>| unless $env{'form.inhibitmenu'};
1.359     albertel 4519: 
1.903     droeschl 4520:         if (   $env{'form.inhibitmenu'} eq 'yes' 
                   4521:             || $ENV{'REQUEST_URI'} eq '/adm/logout'
                   4522:             || $env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.359     albertel 4523: 
1.903     droeschl 4524:             return $bodytag;
                   4525:         }
1.894     droeschl 4526: 
1.903     droeschl 4527:         $bodytag .= Apache::lonhtmlcommon::scripttag(
                   4528:             Apache::lonmenu::utilityfunctions(), 'start');
1.816     bisitz   4529: 
1.903     droeschl 4530:         $bodytag .= Apache::lonmenu::primary_menu();
1.852     droeschl 4531: 
1.903     droeschl 4532:         #don't show menus for public users
                   4533:         if($env{'user.name'} ne 'public' && $env{'user.domain'} ne 'public'){
                   4534:             $bodytag .= Apache::lonmenu::secondary_menu();
                   4535:             $bodytag .= Apache::lonmenu::serverform();
                   4536:             $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end'); 
                   4537:             $bodytag .= Apache::lonmenu::innerregister($forcereg) if $forcereg;
                   4538:         }else{
                   4539:             # this is to seperate menu from content when there's no secondary
                   4540:             # menu. Especially needed for public accessible ressources.
                   4541:             $bodytag .= '<hr style="clear:both" />';
                   4542:             $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end'); 
1.235     raeburn  4543:         }
1.903     droeschl 4544: 
                   4545:         #SD testing
                   4546:         #$bodytag .= Apache::lonmenu::menubuttons($forcereg);
1.235     raeburn  4547:         return $bodytag;
1.94      www      4548:     }
1.95      www      4549: 
1.93      www      4550: #
1.95      www      4551: # Top frame rendering, Remote is up
1.93      www      4552: #
1.359     albertel 4553: 
1.517     raeburn  4554:     my $imgsrc = $img;
                   4555:     if ($img =~ /^\/adm/) {
1.575     albertel 4556:         $imgsrc = &lonhttpdurl($img);
1.517     raeburn  4557:     }
                   4558:     my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359     albertel 4559: 
1.305     www      4560:     # Explicit link to get inline menu
1.361     albertel 4561:     my $menu= ($no_inline_link?''
1.883     droeschl 4562: 	       :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
1.853     droeschl 4563:     $bodytag .= qq|<div id="LC_nav_bar">$name $role
                   4564:             <em>$realm</em> $dc_info </div>
1.897     wenzelju 4565:             <ol class="LC_primary_menu LC_right">
1.853     droeschl 4566:                 <li>$menu</li>
                   4567:             </ol>| unless $env{'form.inhibitmenu'};
1.245     matthew  4568:     #
1.94      www      4569:     return(<<ENDBODY);
1.60      matthew  4570: $bodytag
1.359     albertel 4571: <table id="LC_title_bar" class="LC_with_remote">
1.791     tempelho 4572: <tr><td>$upperleft</td>
                   4573:     <td>$messages&nbsp;</td>
1.54      www      4574: </tr>
1.359     albertel 4575: <tr><td>$titleinfo $dc_info $menu</td>
1.368     albertel 4576: </tr>
1.356     albertel 4577: </table>
1.54      www      4578: ENDBODY
1.182     matthew  4579: }
                   4580: 
1.330     albertel 4581: sub make_attr_string {
                   4582:     my ($register,$attr_ref) = @_;
                   4583: 
                   4584:     if ($attr_ref && !ref($attr_ref)) {
                   4585: 	die("addentries Must be a hash ref ".
                   4586: 	    join(':',caller(1))." ".
                   4587: 	    join(':',caller(0))." ");
                   4588:     }
                   4589: 
                   4590:     if ($register) {
1.339     albertel 4591: 	my ($on_load,$on_unload);
                   4592: 	foreach my $key (keys(%{$attr_ref})) {
                   4593: 	    if      (lc($key) eq 'onload') {
                   4594: 		$on_load.=$attr_ref->{$key}.';';
                   4595: 		delete($attr_ref->{$key});
                   4596: 
                   4597: 	    } elsif (lc($key) eq 'onunload') {
                   4598: 		$on_unload.=$attr_ref->{$key}.';';
                   4599: 		delete($attr_ref->{$key});
                   4600: 	    }
                   4601: 	}
                   4602: 	$attr_ref->{'onload'}  =
                   4603: 	    &Apache::lonmenu::loadevents().  $on_load;
                   4604: 	$attr_ref->{'onunload'}=
                   4605: 	    &Apache::lonmenu::unloadevents().$on_unload;
                   4606:     }
                   4607: 
                   4608: # Accessibility font enhance
                   4609:     if ($env{'browser.fontenhance'} eq 'on') {
                   4610: 	my $style;
                   4611: 	foreach my $key (keys(%{$attr_ref})) {
                   4612: 	    if (lc($key) eq 'style') {
                   4613: 		$style.=$attr_ref->{$key}.';';
                   4614: 		delete($attr_ref->{$key});
                   4615: 	    }
                   4616: 	}
                   4617: 	$attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330     albertel 4618:     }
1.339     albertel 4619: 
1.330     albertel 4620:     my $attr_string;
                   4621:     foreach my $attr (keys(%$attr_ref)) {
                   4622: 	$attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
                   4623:     }
                   4624:     return $attr_string;
                   4625: }
                   4626: 
                   4627: 
1.182     matthew  4628: ###############################################
1.251     albertel 4629: ###############################################
                   4630: 
                   4631: =pod
                   4632: 
                   4633: =item * &endbodytag()
                   4634: 
                   4635: Returns a uniform footer for LON-CAPA web pages.
                   4636: 
1.635     raeburn  4637: Inputs: 1 - optional reference to an args hash
                   4638: If in the hash, key for noredirectlink has a value which evaluates to true,
                   4639: a 'Continue' link is not displayed if the page contains an
                   4640: internal redirect in the <head></head> section,
                   4641: i.e., $env{'internal.head.redirect'} exists   
1.251     albertel 4642: 
                   4643: =cut
                   4644: 
                   4645: sub endbodytag {
1.635     raeburn  4646:     my ($args) = @_;
1.251     albertel 4647:     my $endbodytag='</body>';
1.269     albertel 4648:     $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315     albertel 4649:     if ( exists( $env{'internal.head.redirect'} ) ) {
1.635     raeburn  4650:         if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
                   4651: 	    $endbodytag=
                   4652: 	        "<br /><a href=\"$env{'internal.head.redirect'}\">".
                   4653: 	        &mt('Continue').'</a>'.
                   4654: 	        $endbodytag;
                   4655:         }
1.315     albertel 4656:     }
1.251     albertel 4657:     return $endbodytag;
                   4658: }
                   4659: 
1.352     albertel 4660: =pod
                   4661: 
                   4662: =item * &standard_css()
                   4663: 
                   4664: Returns a style sheet
                   4665: 
                   4666: Inputs: (all optional)
                   4667:             domain         -> force to color decorate a page for a specific
                   4668:                                domain
                   4669:             function       -> force usage of a specific rolish color scheme
                   4670:             bgcolor        -> override the default page bgcolor
                   4671: 
                   4672: =cut
                   4673: 
1.343     albertel 4674: sub standard_css {
1.345     albertel 4675:     my ($function,$domain,$bgcolor) = @_;
1.352     albertel 4676:     $function  = &get_users_function() if (!$function);
                   4677:     my $img    = &designparm($function.'.img',   $domain);
                   4678:     my $tabbg  = &designparm($function.'.tabbg', $domain);
                   4679:     my $font   = &designparm($function.'.font',  $domain);
1.801     tempelho 4680:     my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791     tempelho 4681: #second colour for later usage
1.345     albertel 4682:     my $sidebg = &designparm($function.'.sidebg',$domain);
1.382     albertel 4683:     my $pgbg_or_bgcolor =
                   4684: 	         $bgcolor ||
1.352     albertel 4685: 	         &designparm($function.'.pgbg',  $domain);
1.382     albertel 4686:     my $pgbg   = &designparm($function.'.pgbg',  $domain);
1.352     albertel 4687:     my $alink  = &designparm($function.'.alink', $domain);
                   4688:     my $vlink  = &designparm($function.'.vlink', $domain);
                   4689:     my $link   = &designparm($function.'.link',  $domain);
                   4690: 
1.704     muellerd 4691:     my $loginbg = &designparm('login.sidebg',$domain);
1.712     muellerd 4692:     my $bgcol = &designparm('login.bgcol',$domain);
                   4693:     my $textcol = &designparm('login.textcol',$domain);
1.704     muellerd 4694: 
1.602     albertel 4695:     my $sans                 = 'Verdana,Arial,Helvetica,sans-serif';
1.395     albertel 4696:     my $mono                 = 'monospace';
1.850     bisitz   4697:     my $data_table_head      = $sidebg;
                   4698:     my $data_table_light     = '#FAFAFA';
                   4699:     my $data_table_dark      = '#F0F0F0';
1.470     banghart 4700:     my $data_table_darker    = '#CCCCCC';
1.349     albertel 4701:     my $data_table_highlight = '#FFFF00';
1.352     albertel 4702:     my $mail_new             = '#FFBB77';
                   4703:     my $mail_new_hover       = '#DD9955';
                   4704:     my $mail_read            = '#BBBB77';
                   4705:     my $mail_read_hover      = '#999944';
                   4706:     my $mail_replied         = '#AAAA88';
                   4707:     my $mail_replied_hover   = '#888855';
                   4708:     my $mail_other           = '#99BBBB';
                   4709:     my $mail_other_hover     = '#669999';
1.391     albertel 4710:     my $table_header         = '#DDDDDD';
1.489     raeburn  4711:     my $feedback_link_bg     = '#BBBBBB';
1.701     harmsja  4712:     my $lg_border_color	     = '#C8C8C8';
1.392     albertel 4713: 
1.608     albertel 4714:     my $border = ($env{'browser.type'} eq 'explorer' ||
1.803     bisitz   4715: 		  $env{'browser.type'} eq 'safari'     ) ? '0 2px 0 2px'
                   4716: 	                                                 : '0 3px 0 4px';
1.448     albertel 4717: 
1.523     albertel 4718: 
1.343     albertel 4719:     return <<END;
1.795     www      4720: body {
                   4721:    font-family: $sans;
                   4722:    line-height:130%;
                   4723:    font-size:0.83em;
                   4724:    color:$font;
                   4725: }
                   4726: 
                   4727: a:link, a:visited { 
                   4728:   font-size:100%; 
                   4729: }
                   4730: 
                   4731: a:focus { 
                   4732:   color: red;
                   4733:   background: yellow 
                   4734: }
1.698     harmsja  4735: 
1.795     www      4736: form, .inline { 
                   4737:    display: inline; 
                   4738: }
1.721     harmsja  4739: 
1.795     www      4740: .LC_right {
                   4741:    text-align:right;
                   4742: }
                   4743: 
                   4744: .LC_middle {
                   4745:    vertical-align:middle;
                   4746: }
1.721     harmsja  4747: 
                   4748: /* just for tests */
1.754     droeschl 4749: .LC_400Box {width:400px; }
1.721     harmsja  4750: /* end */
                   4751: 
1.778     bisitz   4752: .LC_filename {
                   4753:   font-family: $mono;
                   4754:   white-space:pre;
                   4755: }
                   4756: 
                   4757: .LC_fileicon {
                   4758:   border: none;
                   4759:   height: 1.3em;
                   4760:   vertical-align: text-bottom;
                   4761:   margin-right: 0.3em;
                   4762:   text-decoration:none;
                   4763: }
                   4764: 
1.350     albertel 4765: .LC_error {
                   4766:   color: red;
                   4767:   font-size: larger;
                   4768: }
1.795     www      4769: 
1.457     albertel 4770: .LC_warning,
                   4771: .LC_diff_removed {
1.733     bisitz   4772:   color: red;
1.394     albertel 4773: }
1.532     albertel 4774: 
                   4775: .LC_info,
1.457     albertel 4776: .LC_success,
                   4777: .LC_diff_added {
1.350     albertel 4778:   color: green;
                   4779: }
1.795     www      4780: 
1.802     bisitz   4781: div.LC_confirm_box {
                   4782:   background-color: #FAFAFA;
                   4783:   border: 1px solid $lg_border_color;
                   4784:   margin-right: 0;
                   4785:   padding: 5px;
                   4786: }
                   4787: 
                   4788: div.LC_confirm_box .LC_error img,
                   4789: div.LC_confirm_box .LC_success img {
                   4790:   vertical-align: middle;
                   4791: }
                   4792: 
1.440     albertel 4793: .LC_icon {
1.771     droeschl 4794:   border: none;
1.790     droeschl 4795:   vertical-align: middle;
1.771     droeschl 4796: }
                   4797: 
1.543     albertel 4798: .LC_docs_spacer {
                   4799:   width: 25px;
                   4800:   height: 1px;
1.771     droeschl 4801:   border: none;
1.543     albertel 4802: }
1.346     albertel 4803: 
1.532     albertel 4804: .LC_internal_info {
1.735     bisitz   4805:   color: #999999;
1.532     albertel 4806: }
                   4807: 
1.794     www      4808: .LC_discussion {
                   4809:    background: $tabbg;
                   4810:    border: 1px solid black;
                   4811:    margin: 2px;
                   4812: }
                   4813: 
                   4814: .LC_disc_action_links_bar {
                   4815:    background: $tabbg;
1.803     bisitz   4816:    border: none;
1.795     www      4817:    margin: 4px;
1.794     www      4818: }
                   4819: 
                   4820: .LC_disc_action_left {
                   4821:    text-align: left;
                   4822: }
                   4823: 
                   4824: .LC_disc_action_right {
                   4825:    text-align: right;
                   4826: }
                   4827: 
                   4828: .LC_disc_new_item {
                   4829:    background: white;
                   4830:    border: 2px solid red;
                   4831:    margin: 2px;
                   4832: }
                   4833: 
                   4834: .LC_disc_old_item {
                   4835:    background: white;
                   4836:    border: 1px solid black;
                   4837:    margin: 2px;
                   4838: }
                   4839: 
1.458     albertel 4840: table.LC_pastsubmission {
                   4841:   border: 1px solid black;
                   4842:   margin: 2px;
                   4843: }
                   4844: 
1.795     www      4845: table#LC_top_nav,
                   4846: table#LC_menubuttons,
                   4847: table#LC_nav_location {
1.345     albertel 4848:   width: 100%;
                   4849:   background: $pgbg;
1.392     albertel 4850:   border: 2px;
1.402     albertel 4851:   border-collapse: separate;
1.803     bisitz   4852:   padding: 0;
1.345     albertel 4853: }
1.392     albertel 4854: 
1.801     tempelho 4855: table#LC_title_bar a {
                   4856:   color: $fontmenu;
                   4857: }
1.836     bisitz   4858: 
1.807     droeschl 4859: table#LC_title_bar {
1.819     tempelho 4860:   clear: both;
1.836     bisitz   4861:   display: none;
1.807     droeschl 4862: }
                   4863: 
1.795     www      4864: table#LC_title_bar,
                   4865: table.LC_breadcrumbs,
1.393     albertel 4866: table#LC_title_bar.LC_with_remote {
1.359     albertel 4867:   width: 100%;
1.392     albertel 4868:   border-color: $pgbg;
                   4869:   border-style: solid;
                   4870:   border-width: $border;
1.379     albertel 4871:   background: $pgbg;
1.801     tempelho 4872:   color: $fontmenu;
1.392     albertel 4873:   border-collapse: collapse;
1.803     bisitz   4874:   padding: 0;
1.819     tempelho 4875:   margin: 0;
1.359     albertel 4876: }
1.795     www      4877: 
1.359     albertel 4878: table#LC_title_bar td {
                   4879:   background: $tabbg;
                   4880: }
1.795     www      4881: 
1.706     harmsja  4882: table#LC_menubuttons img{
1.803     bisitz   4883:   border: none;
1.346     albertel 4884: }
1.795     www      4885: 
1.345     albertel 4886: table#LC_top_nav td {
                   4887:   background: $tabbg;
1.803     bisitz   4888:   border: none;
1.407     albertel 4889:   font-size: small;
1.706     harmsja  4890:   vertical-align:top;
                   4891:   padding:2px 5px 2px 5px;
1.345     albertel 4892: }
1.795     www      4893: 
                   4894: table#LC_top_nav td a,
                   4895: div#LC_top_nav a {
1.345     albertel 4896:   color: $font;
                   4897: }
1.795     www      4898: 
1.364     albertel 4899: table#LC_top_nav td.LC_top_nav_logo {
                   4900:   background: $tabbg;
1.432     albertel 4901:   text-align: left;
1.408     albertel 4902:   white-space: nowrap;
1.432     albertel 4903:   width: 31px;
1.408     albertel 4904: }
1.795     www      4905: 
1.408     albertel 4906: table#LC_top_nav td.LC_top_nav_logo img {
1.803     bisitz   4907:   border: none;
1.408     albertel 4908:   vertical-align: bottom;
1.364     albertel 4909: }
1.795     www      4910: 
1.777     tempelho 4911: table#LC_top_nav td.LC_top_nav_exit,
1.779     bisitz   4912: table#LC_top_nav td.LC_top_nav_help {
1.777     tempelho 4913:   width: 2.0em;
                   4914: }
1.795     www      4915: 
1.442     albertel 4916: table#LC_top_nav td.LC_top_nav_login {
                   4917:   width: 4.0em;
                   4918:   text-align: center;
                   4919: }
1.795     www      4920: 
1.842     droeschl 4921: .LC_breadcrumbs_component {
                   4922:     float: right;
                   4923:     margin: 0 1em;
1.357     albertel 4924: }
1.842     droeschl 4925: .LC_breadcrumbs_component img {
                   4926:     vertical-align: middle;
1.777     tempelho 4927: }
1.795     www      4928: 
1.383     albertel 4929: td.LC_table_cell_checkbox {
                   4930:   text-align: center;
                   4931: }
1.795     www      4932: 
1.779     bisitz   4933: table#LC_mainmenu td.LC_mainmenu_column {
                   4934:     vertical-align: top;
1.777     tempelho 4935: }
1.522     albertel 4936: 
1.795     www      4937: .LC_fontsize_small {
1.705     tempelho 4938:  font-size: 70%;
                   4939: }
                   4940: 
1.844     bisitz   4941: #LC_breadcrumbs {
1.819     tempelho 4942:  clear:both;
                   4943:  background: $sidebg;
1.822     bisitz   4944:  border-bottom: 1px solid $lg_border_color;
1.904     droeschl 4945:  line-height: 2.5em; 
                   4946:  /* SD working here
                   4947:  height: 2.5em;
                   4948:  overflow: hidden; */
1.822     bisitz   4949:  margin: 0;
1.819     tempelho 4950:  padding: 0;
                   4951: }
1.862     bisitz   4952: 
1.839     droeschl 4953: /* Preliminary fix to hide breadcrumbs inside remote control window */
1.844     bisitz   4954: #LC_remote #LC_breadcrumbs {
1.839     droeschl 4955:     display:none;
                   4956: }
1.819     tempelho 4957: 
1.844     bisitz   4958: #LC_head_subbox {
1.822     bisitz   4959:  clear:both;
                   4960:  background: #F8F8F8; /* $sidebg; */
                   4961:  border-bottom: 1px solid $lg_border_color;
                   4962:  margin: 0 0 10px 0;
                   4963:  padding: 5px;
                   4964: }
                   4965: 
1.795     www      4966: .LC_fontsize_medium {
1.705     tempelho 4967:  font-size: 85%;
                   4968: }
                   4969: 
1.795     www      4970: .LC_fontsize_large {
1.705     tempelho 4971:  font-size: 120%;
                   4972: }
                   4973: 
1.346     albertel 4974: .LC_menubuttons_inline_text {
                   4975:   color: $font;
1.698     harmsja  4976:   font-size: 90%;
1.701     harmsja  4977:   padding-left:3px;
1.346     albertel 4978: }
                   4979: 
1.526     www      4980: .LC_menubuttons_link {
                   4981:   text-decoration: none;
                   4982: }
1.795     www      4983: 
1.522     albertel 4984: .LC_menubuttons_category {
1.521     www      4985:   color: $font;
1.526     www      4986:   background: $pgbg;
1.521     www      4987:   font-size: larger;
                   4988:   font-weight: bold;
                   4989: }
                   4990: 
1.346     albertel 4991: td.LC_menubuttons_text {
1.779     bisitz   4992:  	color: $font;
1.346     albertel 4993: }
1.706     harmsja  4994: 
1.346     albertel 4995: .LC_current_location {
                   4996:   background: $tabbg;
                   4997: }
1.795     www      4998: 
1.346     albertel 4999: .LC_new_mail {
1.634     www      5000:   background: $tabbg;
1.346     albertel 5001:   font-weight: bold;
                   5002: }
1.347     albertel 5003: 
1.795     www      5004: table.LC_data_table,
                   5005: table.LC_mail_list {
1.347     albertel 5006:   border: 1px solid #000000;
1.402     albertel 5007:   border-collapse: separate;
1.426     albertel 5008:   border-spacing: 1px;
1.610     albertel 5009:   background: $pgbg;
1.347     albertel 5010: }
1.795     www      5011: 
1.422     albertel 5012: .LC_data_table_dense {
                   5013:   font-size: small;
                   5014: }
1.795     www      5015: 
1.507     raeburn  5016: table.LC_nested_outer {
                   5017:   border: 1px solid #000000;
1.589     raeburn  5018:   border-collapse: collapse;
1.803     bisitz   5019:   border-spacing: 0;
1.507     raeburn  5020:   width: 100%;
                   5021: }
1.795     www      5022: 
1.879     raeburn  5023: table.LC_innerpickbox,
1.507     raeburn  5024: table.LC_nested {
1.803     bisitz   5025:   border: none;
1.589     raeburn  5026:   border-collapse: collapse;
1.803     bisitz   5027:   border-spacing: 0;
1.507     raeburn  5028:   width: 100%;
                   5029: }
1.795     www      5030: 
                   5031: table.LC_data_table tr th, 
                   5032: table.LC_calendar tr th, 
                   5033: table.LC_mail_list tr th,
1.879     raeburn  5034: table.LC_prior_tries tr th,
                   5035: table.LC_innerpickbox tr th {
1.349     albertel 5036:   font-weight: bold;
                   5037:   background-color: $data_table_head;
1.801     tempelho 5038:   color:$fontmenu;
1.701     harmsja  5039:   font-size:90%;
1.347     albertel 5040: }
1.795     www      5041: 
1.879     raeburn  5042: table.LC_innerpickbox tr th,
                   5043: table.LC_innerpickbox tr td {
                   5044:   vertical-align: top;
                   5045: }
                   5046: 
1.711     raeburn  5047: table.LC_data_table tr.LC_info_row > td {
1.735     bisitz   5048:   background-color: #CCCCCC;
1.711     raeburn  5049:   font-weight: bold;
                   5050:   text-align: left;
                   5051: }
1.795     www      5052: 
1.779     bisitz   5053: table.LC_data_table tr.LC_odd_row > td,
1.809     bisitz   5054: table.LC_pick_box tr > td.LC_odd_row {
1.349     albertel 5055:   background-color: $data_table_light;
1.425     albertel 5056:   padding: 2px;
1.900     bisitz   5057:   vertical-align: top;
1.347     albertel 5058: }
1.795     www      5059: 
1.610     albertel 5060: table.LC_data_table tr.LC_even_row > td,
1.809     bisitz   5061: table.LC_pick_box tr > td.LC_even_row {
1.349     albertel 5062:   background-color: $data_table_dark;
1.709     bisitz   5063:   padding: 2px;
1.900     bisitz   5064:   vertical-align: top;
1.347     albertel 5065: }
1.795     www      5066: 
1.425     albertel 5067: table.LC_data_table tr.LC_data_table_highlight td {
                   5068:   background-color: $data_table_darker;
                   5069: }
1.795     www      5070: 
1.639     raeburn  5071: table.LC_data_table tr td.LC_leftcol_header {
                   5072:   background-color: $data_table_head;
                   5073:   font-weight: bold;
                   5074: }
1.795     www      5075: 
1.451     albertel 5076: table.LC_data_table tr.LC_empty_row td,
1.507     raeburn  5077: table.LC_nested tr.LC_empty_row td {
1.347     albertel 5078:   background-color: #FFFFFF;
1.421     albertel 5079:   font-weight: bold;
                   5080:   font-style: italic;
                   5081:   text-align: center;
                   5082:   padding: 8px;
1.347     albertel 5083: }
1.795     www      5084: 
1.890     droeschl 5085: table.LC_caption {
                   5086: }
                   5087: 
1.507     raeburn  5088: table.LC_nested tr.LC_empty_row td {
1.465     albertel 5089:   padding: 4ex
                   5090: }
1.795     www      5091: 
1.507     raeburn  5092: table.LC_nested_outer tr th {
                   5093:   font-weight: bold;
1.801     tempelho 5094:   color:$fontmenu;
1.507     raeburn  5095:   background-color: $data_table_head;
1.701     harmsja  5096:   font-size: small;
1.507     raeburn  5097:   border-bottom: 1px solid #000000;
                   5098: }
1.795     www      5099: 
1.507     raeburn  5100: table.LC_nested_outer tr td.LC_subheader {
                   5101:   background-color: $data_table_head;
                   5102:   font-weight: bold;
                   5103:   font-size: small;
                   5104:   border-bottom: 1px solid #000000;
                   5105:   text-align: right;
1.451     albertel 5106: }
1.795     www      5107: 
1.507     raeburn  5108: table.LC_nested tr.LC_info_row td {
1.735     bisitz   5109:   background-color: #CCCCCC;
1.451     albertel 5110:   font-weight: bold;
                   5111:   font-size: small;
1.507     raeburn  5112:   text-align: center;
                   5113: }
1.795     www      5114: 
1.589     raeburn  5115: table.LC_nested tr.LC_info_row td.LC_left_item,
                   5116: table.LC_nested_outer tr th.LC_left_item {
1.507     raeburn  5117:   text-align: left;
1.451     albertel 5118: }
1.795     www      5119: 
1.507     raeburn  5120: table.LC_nested td {
1.735     bisitz   5121:   background-color: #FFFFFF;
1.451     albertel 5122:   font-size: small;
1.507     raeburn  5123: }
1.795     www      5124: 
1.507     raeburn  5125: table.LC_nested_outer tr th.LC_right_item,
                   5126: table.LC_nested tr.LC_info_row td.LC_right_item,
                   5127: table.LC_nested tr.LC_odd_row td.LC_right_item,
                   5128: table.LC_nested tr td.LC_right_item {
1.451     albertel 5129:   text-align: right;
                   5130: }
                   5131: 
1.507     raeburn  5132: table.LC_nested tr.LC_odd_row td {
1.735     bisitz   5133:   background-color: #EEEEEE;
1.451     albertel 5134: }
                   5135: 
1.473     raeburn  5136: table.LC_createuser {
                   5137: }
                   5138: 
                   5139: table.LC_createuser tr.LC_section_row td {
1.701     harmsja  5140:   font-size: small;
1.473     raeburn  5141: }
                   5142: 
                   5143: table.LC_createuser tr.LC_info_row td  {
1.735     bisitz   5144:   background-color: #CCCCCC;
1.473     raeburn  5145:   font-weight: bold;
                   5146:   text-align: center;
                   5147: }
                   5148: 
1.349     albertel 5149: table.LC_calendar {
                   5150:   border: 1px solid #000000;
                   5151:   border-collapse: collapse;
                   5152: }
1.795     www      5153: 
1.349     albertel 5154: table.LC_calendar_pickdate {
                   5155:   font-size: xx-small;
                   5156: }
1.795     www      5157: 
1.349     albertel 5158: table.LC_calendar tr td {
                   5159:   border: 1px solid #000000;
                   5160:   vertical-align: top;
                   5161: }
1.795     www      5162: 
1.349     albertel 5163: table.LC_calendar tr td.LC_calendar_day_empty {
                   5164:   background-color: $data_table_dark;
                   5165: }
1.795     www      5166: 
1.779     bisitz   5167: table.LC_calendar tr td.LC_calendar_day_current {
                   5168:   background-color: $data_table_highlight;
1.777     tempelho 5169: }
1.795     www      5170: 
1.349     albertel 5171: table.LC_mail_list tr.LC_mail_new {
                   5172:   background-color: $mail_new;
                   5173: }
1.795     www      5174: 
1.349     albertel 5175: table.LC_mail_list tr.LC_mail_new:hover {
                   5176:   background-color: $mail_new_hover;
                   5177: }
1.795     www      5178: 
                   5179: table.LC_mail_list tr.LC_mail_even {
1.777     tempelho 5180: }
1.795     www      5181: 
                   5182: table.LC_mail_list tr.LC_mail_odd {
1.777     tempelho 5183: }
1.795     www      5184: 
1.349     albertel 5185: table.LC_mail_list tr.LC_mail_read {
                   5186:   background-color: $mail_read;
                   5187: }
1.795     www      5188: 
1.349     albertel 5189: table.LC_mail_list tr.LC_mail_read:hover {
                   5190:   background-color: $mail_read_hover;
                   5191: }
1.795     www      5192: 
1.349     albertel 5193: table.LC_mail_list tr.LC_mail_replied {
                   5194:   background-color: $mail_replied;
                   5195: }
1.795     www      5196: 
1.349     albertel 5197: table.LC_mail_list tr.LC_mail_replied:hover {
                   5198:   background-color: $mail_replied_hover;
                   5199: }
1.795     www      5200: 
1.349     albertel 5201: table.LC_mail_list tr.LC_mail_other {
                   5202:   background-color: $mail_other;
                   5203: }
1.795     www      5204: 
1.349     albertel 5205: table.LC_mail_list tr.LC_mail_other:hover {
                   5206:   background-color: $mail_other_hover;
                   5207: }
1.494     raeburn  5208: 
1.777     tempelho 5209: table.LC_data_table tr > td.LC_browser_file,
                   5210: table.LC_data_table tr > td.LC_browser_file_published {
1.899     bisitz   5211:   background: #AAEE77;
1.389     albertel 5212: }
1.795     www      5213: 
1.777     tempelho 5214: table.LC_data_table tr > td.LC_browser_file_locked,
                   5215: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389     albertel 5216:   background: #FFAA99;
1.387     albertel 5217: }
1.795     www      5218: 
1.777     tempelho 5219: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899     bisitz   5220:   background: #888888;
1.779     bisitz   5221: }
1.795     www      5222: 
1.777     tempelho 5223: table.LC_data_table tr > td.LC_browser_file_modified,
1.779     bisitz   5224: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899     bisitz   5225:   background: #F8F866;
1.777     tempelho 5226: }
1.795     www      5227: 
1.696     bisitz   5228: table.LC_data_table tr.LC_browser_folder > td {
1.899     bisitz   5229:   background: #E0E8FF;
1.387     albertel 5230: }
1.696     bisitz   5231: 
1.707     bisitz   5232: table.LC_data_table tr > td.LC_roles_is {
                   5233: /*  background: #77FF77; */
                   5234: }
1.795     www      5235: 
1.707     bisitz   5236: table.LC_data_table tr > td.LC_roles_future {
                   5237:   background: #FFFF77;
                   5238: }
1.795     www      5239: 
1.707     bisitz   5240: table.LC_data_table tr > td.LC_roles_will {
                   5241:   background: #FFAA77;
                   5242: }
1.795     www      5243: 
1.707     bisitz   5244: table.LC_data_table tr > td.LC_roles_expired {
                   5245:   background: #FF7777;
                   5246: }
1.795     www      5247: 
1.707     bisitz   5248: table.LC_data_table tr > td.LC_roles_will_not {
                   5249:   background: #AAFF77;
                   5250: }
1.795     www      5251: 
1.707     bisitz   5252: table.LC_data_table tr > td.LC_roles_selected {
                   5253:   background: #11CC55;
                   5254: }
                   5255: 
1.388     albertel 5256: span.LC_current_location {
1.701     harmsja  5257:   font-size:larger;
1.388     albertel 5258:   background: $pgbg;
                   5259: }
1.387     albertel 5260: 
1.395     albertel 5261: span.LC_parm_menu_item {
                   5262:   font-size: larger;
                   5263: }
1.795     www      5264: 
1.395     albertel 5265: span.LC_parm_scope_all {
                   5266:   color: red;
                   5267: }
1.795     www      5268: 
1.395     albertel 5269: span.LC_parm_scope_folder {
                   5270:   color: green;
                   5271: }
1.795     www      5272: 
1.395     albertel 5273: span.LC_parm_scope_resource {
                   5274:   color: orange;
                   5275: }
1.795     www      5276: 
1.395     albertel 5277: span.LC_parm_part {
                   5278:   color: blue;
                   5279: }
1.795     www      5280: 
1.395     albertel 5281: span.LC_parm_folder, span.LC_parm_symb {
                   5282:   font-size: x-small;
                   5283:   font-family: $mono;
                   5284:   color: #AAAAAA;
                   5285: }
                   5286: 
1.795     www      5287: td.LC_parm_overview_level_menu,
                   5288: td.LC_parm_overview_map_menu,
                   5289: td.LC_parm_overview_parm_selectors,
                   5290: td.LC_parm_overview_restrictions  {
1.396     albertel 5291:   border: 1px solid black;
                   5292:   border-collapse: collapse;
                   5293: }
1.795     www      5294: 
1.396     albertel 5295: table.LC_parm_overview_restrictions td {
                   5296:   border-width: 1px 4px 1px 4px;
                   5297:   border-style: solid;
                   5298:   border-color: $pgbg;
                   5299:   text-align: center;
                   5300: }
1.795     www      5301: 
1.396     albertel 5302: table.LC_parm_overview_restrictions th {
                   5303:   background: $tabbg;
                   5304:   border-width: 1px 4px 1px 4px;
                   5305:   border-style: solid;
                   5306:   border-color: $pgbg;
                   5307: }
1.795     www      5308: 
1.398     albertel 5309: table#LC_helpmenu {
1.803     bisitz   5310:   border: none;
1.398     albertel 5311:   height: 55px;
1.803     bisitz   5312:   border-spacing: 0;
1.398     albertel 5313: }
                   5314: 
                   5315: table#LC_helpmenu fieldset legend {
                   5316:   font-size: larger;
                   5317: }
1.795     www      5318: 
1.397     albertel 5319: table#LC_helpmenu_links {
                   5320:   width: 100%;
                   5321:   border: 1px solid black;
                   5322:   background: $pgbg;
1.803     bisitz   5323:   padding: 0;
1.397     albertel 5324:   border-spacing: 1px;
                   5325: }
1.795     www      5326: 
1.397     albertel 5327: table#LC_helpmenu_links tr td {
                   5328:   padding: 1px;
                   5329:   background: $tabbg;
1.399     albertel 5330:   text-align: center;
                   5331:   font-weight: bold;
1.397     albertel 5332: }
1.396     albertel 5333: 
1.795     www      5334: table#LC_helpmenu_links a:link,
                   5335: table#LC_helpmenu_links a:visited,
1.397     albertel 5336: table#LC_helpmenu_links a:active {
                   5337:   text-decoration: none;
                   5338:   color: $font;
                   5339: }
1.795     www      5340: 
1.397     albertel 5341: table#LC_helpmenu_links a:hover {
                   5342:   text-decoration: underline;
                   5343:   color: $vlink;
                   5344: }
1.396     albertel 5345: 
1.417     albertel 5346: .LC_chrt_popup_exists {
                   5347:   border: 1px solid #339933;
                   5348:   margin: -1px;
                   5349: }
1.795     www      5350: 
1.417     albertel 5351: .LC_chrt_popup_up {
                   5352:   border: 1px solid yellow;
                   5353:   margin: -1px;
                   5354: }
1.795     www      5355: 
1.417     albertel 5356: .LC_chrt_popup {
                   5357:   border: 1px solid #8888FF;
                   5358:   background: #CCCCFF;
                   5359: }
1.795     www      5360: 
1.421     albertel 5361: table.LC_pick_box {
                   5362:   border-collapse: separate;
                   5363:   background: white;
                   5364:   border: 1px solid black;
                   5365:   border-spacing: 1px;
                   5366: }
1.795     www      5367: 
1.421     albertel 5368: table.LC_pick_box td.LC_pick_box_title {
1.850     bisitz   5369:   background: $sidebg;
1.421     albertel 5370:   font-weight: bold;
1.900     bisitz   5371:   text-align: left;
1.740     bisitz   5372:   vertical-align: top;
1.421     albertel 5373:   width: 184px;
                   5374:   padding: 8px;
                   5375: }
1.795     www      5376: 
1.579     raeburn  5377: table.LC_pick_box td.LC_pick_box_value {
                   5378:   text-align: left;
                   5379:   padding: 8px;
                   5380: }
1.795     www      5381: 
1.579     raeburn  5382: table.LC_pick_box td.LC_pick_box_select {
                   5383:   text-align: left;
                   5384:   padding: 8px;
                   5385: }
1.795     www      5386: 
1.424     albertel 5387: table.LC_pick_box td.LC_pick_box_separator {
1.803     bisitz   5388:   padding: 0;
1.421     albertel 5389:   height: 1px;
                   5390:   background: black;
                   5391: }
1.795     www      5392: 
1.421     albertel 5393: table.LC_pick_box td.LC_pick_box_submit {
                   5394:   text-align: right;
                   5395: }
1.795     www      5396: 
1.579     raeburn  5397: table.LC_pick_box td.LC_evenrow_value {
                   5398:   text-align: left;
                   5399:   padding: 8px;
                   5400:   background-color: $data_table_light;
                   5401: }
1.795     www      5402: 
1.579     raeburn  5403: table.LC_pick_box td.LC_oddrow_value {
                   5404:   text-align: left;
                   5405:   padding: 8px;
                   5406:   background-color: $data_table_light;
                   5407: }
1.795     www      5408: 
1.579     raeburn  5409: span.LC_helpform_receipt_cat {
                   5410:   font-weight: bold;
                   5411: }
1.795     www      5412: 
1.424     albertel 5413: table.LC_group_priv_box {
                   5414:   background: white;
                   5415:   border: 1px solid black;
                   5416:   border-spacing: 1px;
                   5417: }
1.795     www      5418: 
1.424     albertel 5419: table.LC_group_priv_box td.LC_pick_box_title {
                   5420:   background: $tabbg;
                   5421:   font-weight: bold;
                   5422:   text-align: right;
                   5423:   width: 184px;
                   5424: }
1.795     www      5425: 
1.424     albertel 5426: table.LC_group_priv_box td.LC_groups_fixed {
                   5427:   background: $data_table_light;
                   5428:   text-align: center;
                   5429: }
1.795     www      5430: 
1.424     albertel 5431: table.LC_group_priv_box td.LC_groups_optional {
                   5432:   background: $data_table_dark;
                   5433:   text-align: center;
                   5434: }
1.795     www      5435: 
1.424     albertel 5436: table.LC_group_priv_box td.LC_groups_functionality {
                   5437:   background: $data_table_darker;
                   5438:   text-align: center;
                   5439:   font-weight: bold;
                   5440: }
1.795     www      5441: 
1.424     albertel 5442: table.LC_group_priv td {
                   5443:   text-align: left;
1.803     bisitz   5444:   padding: 0;
1.424     albertel 5445: }
                   5446: 
1.421     albertel 5447: table.LC_notify_front_page {
                   5448:   background: white;
                   5449:   border: 1px solid black;
                   5450:   padding: 8px;
                   5451: }
1.795     www      5452: 
1.421     albertel 5453: table.LC_notify_front_page td {
                   5454:   padding: 8px;
                   5455: }
1.795     www      5456: 
1.424     albertel 5457: .LC_navbuttons {
                   5458:   margin: 2ex 0ex 2ex 0ex;
                   5459: }
1.795     www      5460: 
1.423     albertel 5461: .LC_topic_bar {
                   5462:   font-weight: bold;
                   5463:   width: 100%;
                   5464:   background: $tabbg;
                   5465:   vertical-align: middle;
                   5466:   margin: 2ex 0ex 2ex 0ex;
1.805     bisitz   5467:   padding: 3px;
1.423     albertel 5468: }
1.795     www      5469: 
1.423     albertel 5470: .LC_topic_bar span {
                   5471:   vertical-align: middle;
                   5472: }
1.795     www      5473: 
1.423     albertel 5474: .LC_topic_bar img {
                   5475:   vertical-align: bottom;
                   5476: }
1.795     www      5477: 
1.423     albertel 5478: table.LC_course_group_status {
                   5479:   margin: 20px;
                   5480: }
1.795     www      5481: 
1.423     albertel 5482: table.LC_status_selector td {
                   5483:   vertical-align: top;
                   5484:   text-align: center;
1.424     albertel 5485:   padding: 4px;
                   5486: }
1.795     www      5487: 
1.599     albertel 5488: div.LC_feedback_link {
1.616     albertel 5489:   clear: both;
1.829     kalberla 5490:   background: $sidebg;
1.779     bisitz   5491:   width: 100%;
1.829     kalberla 5492:   padding-bottom: 10px;
                   5493:   border: 1px $tabbg solid;
1.833     kalberla 5494:   height: 22px;
                   5495:   line-height: 22px;
                   5496:   padding-top: 5px;
                   5497: }
                   5498: 
                   5499: div.LC_feedback_link img {
                   5500:   height: 22px;
1.867     kalberla 5501:   vertical-align:middle;
1.829     kalberla 5502: }
                   5503: 
                   5504: div.LC_feedback_link a{
                   5505:   text-decoration: none;
1.489     raeburn  5506: }
1.795     www      5507: 
1.867     kalberla 5508: div.LC_comblock {
                   5509:   display:inline; 
                   5510:   color:$font;
                   5511:   font-size:90%;
                   5512: }
                   5513: 
                   5514: div.LC_feedback_link div.LC_comblock {
                   5515:   padding-left:5px;
                   5516: }
                   5517: 
                   5518: div.LC_feedback_link div.LC_comblock a {
                   5519:   color:$font;
                   5520: }
                   5521: 
1.489     raeburn  5522: span.LC_feedback_link {
1.858     bisitz   5523:   /* background: $feedback_link_bg; */
1.599     albertel 5524:   font-size: larger;
                   5525: }
1.795     www      5526: 
1.599     albertel 5527: span.LC_message_link {
1.858     bisitz   5528:   /* background: $feedback_link_bg; */
1.599     albertel 5529:   font-size: larger;
                   5530:   position: absolute;
                   5531:   right: 1em;
1.489     raeburn  5532: }
1.421     albertel 5533: 
1.515     albertel 5534: table.LC_prior_tries {
1.524     albertel 5535:   border: 1px solid #000000;
                   5536:   border-collapse: separate;
                   5537:   border-spacing: 1px;
1.515     albertel 5538: }
1.523     albertel 5539: 
1.515     albertel 5540: table.LC_prior_tries td {
1.524     albertel 5541:   padding: 2px;
1.515     albertel 5542: }
1.523     albertel 5543: 
                   5544: .LC_answer_correct {
1.795     www      5545:   background: lightgreen;
                   5546:   color: darkgreen;
                   5547:   padding: 6px;
1.523     albertel 5548: }
1.795     www      5549: 
1.523     albertel 5550: .LC_answer_charged_try {
1.797     www      5551:   background: #FFAAAA;
1.795     www      5552:   color: darkred;
                   5553:   padding: 6px;
1.523     albertel 5554: }
1.795     www      5555: 
1.779     bisitz   5556: .LC_answer_not_charged_try,
1.523     albertel 5557: .LC_answer_no_grade,
                   5558: .LC_answer_late {
1.795     www      5559:   background: lightyellow;
1.523     albertel 5560:   color: black;
1.795     www      5561:   padding: 6px;
1.523     albertel 5562: }
1.795     www      5563: 
1.523     albertel 5564: .LC_answer_previous {
1.795     www      5565:   background: lightblue;
                   5566:   color: darkblue;
                   5567:   padding: 6px;
1.523     albertel 5568: }
1.795     www      5569: 
1.779     bisitz   5570: .LC_answer_no_message {
1.777     tempelho 5571:   background: #FFFFFF;
                   5572:   color: black;
1.795     www      5573:   padding: 6px;
1.779     bisitz   5574: }
1.795     www      5575: 
1.779     bisitz   5576: .LC_answer_unknown {
                   5577:   background: orange;
                   5578:   color: black;
1.795     www      5579:   padding: 6px;
1.777     tempelho 5580: }
1.795     www      5581: 
1.529     albertel 5582: span.LC_prior_numerical,
                   5583: span.LC_prior_string,
                   5584: span.LC_prior_custom,
                   5585: span.LC_prior_reaction,
                   5586: span.LC_prior_math {
1.523     albertel 5587:   font-family: monospace;
                   5588:   white-space: pre;
                   5589: }
                   5590: 
1.525     albertel 5591: span.LC_prior_string {
                   5592:   font-family: monospace;
                   5593:   white-space: pre;
                   5594: }
                   5595: 
1.523     albertel 5596: table.LC_prior_option {
                   5597:   width: 100%;
                   5598:   border-collapse: collapse;
                   5599: }
1.795     www      5600: 
                   5601: table.LC_prior_rank, 
                   5602: table.LC_prior_match {
1.528     albertel 5603:   border-collapse: collapse;
                   5604: }
1.795     www      5605: 
1.528     albertel 5606: table.LC_prior_option tr td,
                   5607: table.LC_prior_rank tr td,
                   5608: table.LC_prior_match tr td {
1.524     albertel 5609:   border: 1px solid #000000;
1.515     albertel 5610: }
                   5611: 
1.855     bisitz   5612: .LC_nobreak {
1.544     albertel 5613:   white-space: nowrap;
1.519     raeburn  5614: }
                   5615: 
1.576     raeburn  5616: span.LC_cusr_emph {
                   5617:   font-style: italic;
                   5618: }
                   5619: 
1.633     raeburn  5620: span.LC_cusr_subheading {
                   5621:   font-weight: normal;
                   5622:   font-size: 85%;
                   5623: }
                   5624: 
1.545     albertel 5625: table.LC_docs_documents {
                   5626:   background: #BBBBBB;
1.803     bisitz   5627:   border-width: 0;
1.545     albertel 5628:   border-collapse: collapse;
                   5629: }
1.795     www      5630: 
1.777     tempelho 5631: table.LC_docs_documents td.LC_docs_document {
1.779     bisitz   5632:   border: 2px solid black;
                   5633:   padding: 4px;
1.777     tempelho 5634: }
1.795     www      5635: 
1.861     bisitz   5636: div.LC_docs_entry_move {
1.859     bisitz   5637:   border: 1px solid #BBBBBB;
1.545     albertel 5638:   background: #DDDDDD;
1.861     bisitz   5639:   width: 22px;
1.859     bisitz   5640:   padding: 1px;
                   5641:   margin: 0;
1.545     albertel 5642: }
                   5643: 
1.861     bisitz   5644: table.LC_data_table tr > td.LC_docs_entry_commands,
                   5645: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545     albertel 5646:   background: #DDDDDD;
                   5647:   font-size: x-small;
                   5648: }
1.795     www      5649: 
1.861     bisitz   5650: .LC_docs_entry_parameter {
                   5651:   white-space: nowrap;
                   5652: }
                   5653: 
1.544     albertel 5654: .LC_docs_copy {
1.545     albertel 5655:   color: #000099;
1.544     albertel 5656: }
1.795     www      5657: 
1.544     albertel 5658: .LC_docs_cut {
1.545     albertel 5659:   color: #550044;
1.544     albertel 5660: }
1.795     www      5661: 
1.544     albertel 5662: .LC_docs_rename {
1.545     albertel 5663:   color: #009900;
1.544     albertel 5664: }
1.795     www      5665: 
1.544     albertel 5666: .LC_docs_remove {
1.545     albertel 5667:   color: #990000;
                   5668: }
                   5669: 
1.547     albertel 5670: .LC_docs_reinit_warn,
                   5671: .LC_docs_ext_edit {
                   5672:   font-size: x-small;
                   5673: }
                   5674: 
1.545     albertel 5675: table.LC_docs_adddocs td,
                   5676: table.LC_docs_adddocs th {
                   5677:   border: 1px solid #BBBBBB;
                   5678:   padding: 4px;
                   5679:   background: #DDDDDD;
1.543     albertel 5680: }
                   5681: 
1.584     albertel 5682: table.LC_sty_begin {
                   5683:   background: #BBFFBB;
                   5684: }
1.795     www      5685: 
1.584     albertel 5686: table.LC_sty_end {
                   5687:   background: #FFBBBB;
                   5688: }
                   5689: 
1.589     raeburn  5690: table.LC_double_column {
1.803     bisitz   5691:   border-width: 0;
1.589     raeburn  5692:   border-collapse: collapse;
                   5693:   width: 100%;
                   5694:   padding: 2px;
                   5695: }
                   5696: 
                   5697: table.LC_double_column tr td.LC_left_col {
1.590     raeburn  5698:   top: 2px;
1.589     raeburn  5699:   left: 2px;
                   5700:   width: 47%;
                   5701:   vertical-align: top;
                   5702: }
                   5703: 
                   5704: table.LC_double_column tr td.LC_right_col {
                   5705:   top: 2px;
1.779     bisitz   5706:   right: 2px;
1.589     raeburn  5707:   width: 47%;
                   5708:   vertical-align: top;
                   5709: }
                   5710: 
1.591     raeburn  5711: div.LC_left_float {
                   5712:   float: left;
                   5713:   padding-right: 5%;
1.597     albertel 5714:   padding-bottom: 4px;
1.591     raeburn  5715: }
                   5716: 
                   5717: div.LC_clear_float_header {
1.597     albertel 5718:   padding-bottom: 2px;
1.591     raeburn  5719: }
                   5720: 
                   5721: div.LC_clear_float_footer {
1.597     albertel 5722:   padding-top: 10px;
1.591     raeburn  5723:   clear: both;
                   5724: }
                   5725: 
1.597     albertel 5726: div.LC_grade_show_user {
                   5727:   margin-top: 20px;
                   5728:   border: 1px solid black;
                   5729: }
1.795     www      5730: 
1.597     albertel 5731: div.LC_grade_user_name {
                   5732:   background: #DDDDEE;
                   5733:   border-bottom: 1px solid black;
1.705     tempelho 5734:   font-weight: bold;
                   5735:   font-size: large;
1.597     albertel 5736: }
1.795     www      5737: 
1.597     albertel 5738: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
                   5739:   background: #DDEEDD;
                   5740: }
                   5741: 
                   5742: div.LC_grade_show_problem,
                   5743: div.LC_grade_submissions,
                   5744: div.LC_grade_message_center,
                   5745: div.LC_grade_info_links,
                   5746: div.LC_grade_assign {
                   5747:   margin: 5px;
                   5748:   width: 99%;
                   5749:   background: #FFFFFF;
                   5750: }
1.795     www      5751: 
1.597     albertel 5752: div.LC_grade_show_problem_header,
                   5753: div.LC_grade_submissions_header,
                   5754: div.LC_grade_message_center_header,
                   5755: div.LC_grade_assign_header {
1.705     tempelho 5756:   font-weight: bold;
                   5757:   font-size: large;
1.597     albertel 5758: }
1.795     www      5759: 
1.597     albertel 5760: div.LC_grade_show_problem_problem,
                   5761: div.LC_grade_submissions_body,
                   5762: div.LC_grade_message_center_body,
                   5763: div.LC_grade_assign_body {
                   5764:   border: 1px solid black;
                   5765:   width: 99%;
                   5766:   background: #FFFFFF;
                   5767: }
1.795     www      5768: 
1.598     albertel 5769: span.LC_grade_check_note {
1.705     tempelho 5770:   font-weight: normal;
                   5771:   font-size: medium;
1.598     albertel 5772:   display: inline;
                   5773:   position: absolute;
                   5774:   right: 1em;
                   5775: }
1.597     albertel 5776: 
1.613     albertel 5777: table.LC_scantron_action {
                   5778:   width: 100%;
                   5779: }
1.795     www      5780: 
1.613     albertel 5781: table.LC_scantron_action tr th {
1.698     harmsja  5782:   font-weight:bold;
                   5783:   font-style:normal;
1.613     albertel 5784: }
1.795     www      5785: 
1.779     bisitz   5786: .LC_edit_problem_header,
1.614     albertel 5787: div.LC_edit_problem_footer {
1.705     tempelho 5788:   font-weight: normal;
                   5789:   font-size:  medium;
1.602     albertel 5790:   margin: 2px;
1.600     albertel 5791: }
1.795     www      5792: 
1.600     albertel 5793: div.LC_edit_problem_header,
1.602     albertel 5794: div.LC_edit_problem_header div,
1.614     albertel 5795: div.LC_edit_problem_footer,
                   5796: div.LC_edit_problem_footer div,
1.602     albertel 5797: div.LC_edit_problem_editxml_header,
                   5798: div.LC_edit_problem_editxml_header div {
1.600     albertel 5799:   margin-top: 5px;
                   5800: }
1.795     www      5801: 
1.600     albertel 5802: div.LC_edit_problem_header_title {
1.705     tempelho 5803:   font-weight: bold;
                   5804:   font-size: larger;
1.602     albertel 5805:   background: $tabbg;
                   5806:   padding: 3px;
                   5807: }
1.795     www      5808: 
1.602     albertel 5809: table.LC_edit_problem_header_title {
1.705     tempelho 5810:   font-size: larger;
                   5811:   font-weight:  bold;
1.602     albertel 5812:   width: 100%;
                   5813:   border-color: $pgbg;
                   5814:   border-style: solid;
                   5815:   border-width: $border;
1.600     albertel 5816:   background: $tabbg;
1.602     albertel 5817:   border-collapse: collapse;
1.803     bisitz   5818:   padding: 0;
1.602     albertel 5819: }
                   5820: 
                   5821: div.LC_edit_problem_discards {
                   5822:   float: left;
                   5823:   padding-bottom: 5px;
                   5824: }
1.795     www      5825: 
1.602     albertel 5826: div.LC_edit_problem_saves {
                   5827:   float: right;
                   5828:   padding-bottom: 5px;
1.600     albertel 5829: }
1.795     www      5830: 
1.679     riegler  5831: img.stift{
1.803     bisitz   5832:   border-width: 0;
                   5833:   vertical-align: middle;
1.677     riegler  5834: }
1.680     riegler  5835: 
1.681     riegler  5836: table#LC_mainmenu{
                   5837:  margin-top:10px;
                   5838:  width:80%;
                   5839: }
                   5840: 
1.680     riegler  5841: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
                   5842:   vertical-align: top;
                   5843:   width: 45%;
                   5844: }
1.795     www      5845: 
1.779     bisitz   5846: .LC_mainmenu_fieldset_category {
                   5847:   color: $font;
                   5848:   background: $pgbg;
                   5849:   font-size: small;
                   5850:   font-weight: bold;
1.777     tempelho 5851: }
1.795     www      5852: 
1.716     raeburn  5853: div.LC_createcourse {
                   5854:     margin: 10px 10px 10px 10px;
                   5855: }
                   5856: 
1.693     droeschl 5857: /* ---- Remove when done ----
                   5858: # The following styles is part of the redesign of LON-CAPA and are
                   5859: # subject to change during this project.
                   5860: # Don't rely on their current functionality as they might be 
                   5861: # changed or removed.
                   5862: # --------------------------*/
                   5863: 
1.698     harmsja  5864: a:hover,
1.897     wenzelju 5865: ol.LC_primary_menu a:hover,
1.721     harmsja  5866: ol#LC_MenuBreadcrumbs a:hover,
                   5867: ol#LC_PathBreadcrumbs a:hover,
1.897     wenzelju 5868: ul#LC_secondary_menu a:hover,
1.721     harmsja  5869: .LC_FormSectionClearButton input:hover
1.795     www      5870: ul.LC_TabContent   li:hover a {
1.698     harmsja  5871: 	color:#BF2317;
1.904     droeschl 5872:     text-decoration:none;
1.693     droeschl 5873: }
                   5874: 
1.779     bisitz   5875: h1 {
1.813     bisitz   5876: 	padding: 0;
1.693     droeschl 5877: 	line-height:130%;
                   5878: }
1.698     harmsja  5879: 
1.795     www      5880: h2,h3,h4,h5,h6 {
1.803     bisitz   5881: 	margin: 5px 0 5px 0;
                   5882: 	padding: 0;
1.721     harmsja  5883: 	line-height:130%;
1.693     droeschl 5884: }
1.795     www      5885: 
                   5886: .LC_hcell {
1.698     harmsja  5887:         padding:3px 15px 3px 15px;
1.803     bisitz   5888:         margin: 0;
1.703     harmsja  5889: 	background-color:$tabbg;
1.801     tempelho 5890: 	color:$fontmenu;
1.779     bisitz   5891: 	border-bottom:solid 1px $lg_border_color;
1.693     droeschl 5892: }
1.795     www      5893: 
1.840     bisitz   5894: .LC_Box > .LC_hcell {
1.847     tempelho 5895:     margin: 0 -10px 10px -10px;
1.835     bisitz   5896: }
                   5897: 
1.721     harmsja  5898: .LC_noBorder {
1.803     bisitz   5899:         border: 0;
1.698     harmsja  5900: }
1.693     droeschl 5901: 
1.761     tempelho 5902: .LC_Right {
                   5903:         float: right;
1.803     bisitz   5904:         margin: 0;
                   5905:         padding: 0;
1.761     tempelho 5906: }
                   5907: 
1.721     harmsja  5908: .LC_FormSectionClearButton input {
1.779     bisitz   5909:         background-color:transparent;
1.803     bisitz   5910:         border: none;
1.698     harmsja  5911:         cursor:pointer;
                   5912:         text-decoration:underline;
1.693     droeschl 5913: }
1.763     bisitz   5914: 
                   5915: .LC_help_open_topic {
                   5916:         color: #FFFFFF;
                   5917:         background-color: #EEEEFF;
                   5918:         margin: 1px;
                   5919:         padding: 4px;
                   5920:         border: 1px solid #000033;
                   5921:         white-space: nowrap;
1.783     amueller 5922: /*		vertical-align: middle; */
1.759     neumanie 5923: }
1.693     droeschl 5924: 
1.698     harmsja  5925: dl,ul,div,fieldset {
1.803     bisitz   5926: 	margin: 10px 10px 10px 0;
1.806     bisitz   5927: /*	overflow: hidden; */
1.693     droeschl 5928: }
1.795     www      5929: 
1.838     bisitz   5930: fieldset > legend {
                   5931:     font-weight: bold;
                   5932:     padding: 0 5px 0 5px;
                   5933: }
                   5934: 
1.813     bisitz   5935: #LC_nav_bar {
1.807     droeschl 5936:     float: left;
1.852     droeschl 5937:     margin: 0.2em 0 0 0;
1.807     droeschl 5938: }
                   5939: 
1.813     bisitz   5940: #LC_nav_bar em{
1.807     droeschl 5941:     font-weight: bold;
                   5942:     font-style: normal;
                   5943: }
                   5944: 
1.897     wenzelju 5945: ol.LC_primary_menu {
1.807     droeschl 5946:     float: right;
1.852     droeschl 5947:     margin: 0.2em 0 0 0;
1.807     droeschl 5948: }
                   5949: 
1.852     droeschl 5950: ol#LC_PathBreadcrumbs {
1.803     bisitz   5951: 	margin: 0;
1.693     droeschl 5952: }
                   5953: 
1.897     wenzelju 5954: ol.LC_primary_menu li {
1.693     droeschl 5955: 	display: inline;
1.803     bisitz   5956: 	padding: 5px 5px 0 10px;
1.693     droeschl 5957: 	vertical-align: top;
                   5958: }
                   5959: 
1.897     wenzelju 5960: ol.LC_primary_menu li img {
1.693     droeschl 5961: 	vertical-align: bottom;
                   5962: }
                   5963: 
1.897     wenzelju 5964: ol.LC_primary_menu a {
1.693     droeschl 5965: 	font-size: 90%;
                   5966: 	color: RGB(80, 80, 80);
                   5967: 	text-decoration: none;
                   5968: }
1.795     www      5969: 
1.897     wenzelju 5970: ul#LC_secondary_menu {
1.807     droeschl 5971:     clear: both;
1.808     droeschl 5972:     color: $fontmenu;
                   5973:     background: $tabbg;
                   5974:     list-style: none;
                   5975:     padding: 0;
                   5976:     margin: 0;
                   5977:     width: 100%;
                   5978: }
                   5979: 
1.897     wenzelju 5980: ul#LC_secondary_menu li {
1.808     droeschl 5981:     font-weight: bold;
                   5982:     line-height: 1.8em;
                   5983:     padding: 0 0.8em; 
                   5984:     border-right: 1px solid black;
                   5985:     display: inline;
                   5986:     vertical-align: middle;
1.807     droeschl 5987: }
                   5988: 
1.847     tempelho 5989: ul.LC_TabContent {
1.721     harmsja  5990: 	display:block;
1.847     tempelho 5991: 	background: $sidebg;
1.858     bisitz   5992: 	border-bottom: solid 1px $lg_border_color;
1.721     harmsja  5993: 	list-style:none;
1.870     tempelho 5994: 	margin: 0 -10px;
1.803     bisitz   5995: 	padding: 0;
1.693     droeschl 5996: }
                   5997: 
1.795     www      5998: ul.LC_TabContent li,
                   5999: ul.LC_TabContentBigger li {
1.741     harmsja  6000: 	float:left;
                   6001: }
1.795     www      6002: 
1.897     wenzelju 6003: ul#LC_secondary_menu li a {
1.808     droeschl 6004:     color: $fontmenu;
1.693     droeschl 6005: 	text-decoration: none;
                   6006: }
1.795     www      6007: 
1.721     harmsja  6008: ul.LC_TabContent {
1.847     tempelho 6009: 	min-height:1.5em;
1.721     harmsja  6010: }
1.795     www      6011: 
                   6012: ul.LC_TabContent li {
1.741     harmsja  6013: 	vertical-align:middle;
1.803     bisitz   6014: 	padding: 0 10px 0 10px;
1.745     ehlerst  6015: 	background-color:$tabbg;
                   6016: 	border-bottom:solid 1px $lg_border_color;
1.721     harmsja  6017: }
1.795     www      6018: 
1.847     tempelho 6019: ul.LC_TabContent .right {
                   6020: 	float:right;
                   6021: }
                   6022: 
1.795     www      6023: ul.LC_TabContent li a, ul.LC_TabContent li {
1.721     harmsja  6024: 	color:rgb(47,47,47);
                   6025: 	text-decoration:none;
                   6026: 	font-size:95%;
                   6027: 	font-weight:bold;
1.761     tempelho 6028: 	padding-right: 16px;
1.721     harmsja  6029: }
1.795     www      6030: 
                   6031: ul.LC_TabContent li:hover, ul.LC_TabContent li.active {
1.761     tempelho 6032:         background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.841     tempelho 6033: 	border-bottom:solid 2px #FFFFFF;
1.761     tempelho 6034: 	padding-right: 16px;
1.744     ehlerst  6035: }
1.795     www      6036: 
1.870     tempelho 6037: #maincoursedoc {
                   6038: 	clear:both;
                   6039: }
                   6040: 
                   6041: ul.LC_TabContentBigger {
                   6042:         display:block;
                   6043:         list-style:none;
                   6044:         padding: 0;
                   6045: }
                   6046: 
1.795     www      6047: ul.LC_TabContentBigger li {
1.870     tempelho 6048:         vertical-align:bottom;
                   6049:         height: 30px;
                   6050:         font-size:110%;
                   6051:         font-weight:bold;
                   6052:         color: #737373;
1.841     tempelho 6053: }
                   6054: 
1.870     tempelho 6055: 
                   6056: ul.LC_TabContentBigger li a {
                   6057:         background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
                   6058: 	height: 30px;
                   6059: 	line-height: 30px;
                   6060: 	text-align: center;
                   6061: 	display: block;
                   6062: 	text-decoration: none;
1.741     harmsja  6063: }
1.795     www      6064: 
1.870     tempelho 6065: ul.LC_TabContentBigger li:hover a, 
                   6066: ul.LC_TabContentBigger li.active a {
                   6067: 	background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
1.857     tempelho 6068: 	color:$font;
1.870     tempelho 6069: 	text-decoration: underline;
1.744     ehlerst  6070: }
1.795     www      6071: 
1.870     tempelho 6072: 
                   6073: ul.LC_TabContentBigger li b {
                   6074: 	background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
                   6075: 	display: block;
                   6076: 	float: left;
                   6077: 	padding: 0 30px;
                   6078: }
                   6079: 
                   6080: ul.LC_TabContentBigger li:hover b,
                   6081: ul.LC_TabContentBigger li.active b {
                   6082:         background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
                   6083:         color:$font;
                   6084: 	border-bottom: 1px solid #FFFFFF;
1.741     harmsja  6085: }
1.693     droeschl 6086: 
1.870     tempelho 6087: 
1.862     bisitz   6088: ul.LC_CourseBreadcrumbs {
                   6089:   background: $sidebg;
                   6090:   line-height: 32px;
                   6091:   padding-left: 10px;
                   6092:   margin: 0 0 10px 0;
                   6093:   list-style-position: inside;
                   6094: 
                   6095: }
                   6096: 
1.795     www      6097: ol#LC_MenuBreadcrumbs, 
1.862     bisitz   6098: ol#LC_PathBreadcrumbs {
1.693     droeschl 6099: 	padding-left: 10px;
1.819     tempelho 6100: 	margin: 0;
1.693     droeschl 6101: 	list-style-position: inside;
1.904     droeschl 6102:     /* SD working here
                   6103:     white-space: nowrap; */
1.693     droeschl 6104: }
                   6105: 
1.795     www      6106: ol#LC_MenuBreadcrumbs li, 
                   6107: ol#LC_PathBreadcrumbs li, 
1.862     bisitz   6108: ul.LC_CourseBreadcrumbs li {
1.842     droeschl 6109:     display: inline;
                   6110:     white-space: nowrap;
1.904     droeschl 6111:     /* SD working here
                   6112:     white-space: normal; */
1.693     droeschl 6113: }
                   6114: 
1.823     bisitz   6115: ol#LC_MenuBreadcrumbs li a,
1.862     bisitz   6116: ul.LC_CourseBreadcrumbs li a {
1.693     droeschl 6117: 	text-decoration: none;
                   6118: 	font-size:90%;
                   6119: }
1.795     www      6120: 
                   6121: ol#LC_PathBreadcrumbs li a {
1.698     harmsja  6122: 	text-decoration:none;
                   6123: 	font-size:100%;
                   6124: 	font-weight:bold;
1.693     droeschl 6125: }
1.795     www      6126: 
1.840     bisitz   6127: .LC_Box {
1.835     bisitz   6128:     border: solid 1px $lg_border_color;
                   6129:     padding: 0 10px 10px 10px;
1.746     neumanie 6130: }
1.795     www      6131: 
                   6132: .LC_AboutMe_Image {
1.747     neumanie 6133: 	float:left;
                   6134: 	margin-right:10px;
                   6135: }
1.795     www      6136: 
                   6137: .LC_Clear_AboutMe_Image {
1.747     neumanie 6138: 	clear:left;
                   6139: }
1.795     www      6140: 
1.721     harmsja  6141: dl.LC_ListStyleClean dt {
1.693     droeschl 6142: 	padding-right: 5px;
                   6143: 	display: table-header-group;
                   6144: }
                   6145: 
1.721     harmsja  6146: dl.LC_ListStyleClean dd {
1.693     droeschl 6147: 	display: table-row;
                   6148: }
                   6149: 
1.721     harmsja  6150: .LC_ListStyleClean,
                   6151: .LC_ListStyleSimple,
                   6152: .LC_ListStyleNormal,
1.777     tempelho 6153: .LC_ListStyle_Border,
1.795     www      6154: .LC_ListStyleSpecial {
1.693     droeschl 6155: 	/*display:block;	*/
                   6156: 	list-style-position: inside;
                   6157: 	list-style-type: none;
                   6158: 	overflow: hidden;
1.803     bisitz   6159: 	padding: 0;
1.693     droeschl 6160: }
                   6161: 
1.721     harmsja  6162: .LC_ListStyleSimple li,
                   6163: .LC_ListStyleSimple dd,
                   6164: .LC_ListStyleNormal li,
                   6165: .LC_ListStyleNormal dd,
                   6166: .LC_ListStyleSpecial li,
1.795     www      6167: .LC_ListStyleSpecial dd {
1.803     bisitz   6168: 	margin: 0;
1.693     droeschl 6169: 	padding: 5px 5px 5px 10px;
                   6170: 	clear: both;
                   6171: }
                   6172: 
1.721     harmsja  6173: .LC_ListStyleClean li,
                   6174: .LC_ListStyleClean dd {
1.803     bisitz   6175: 	padding-top: 0;
                   6176: 	padding-bottom: 0;
1.693     droeschl 6177: }
                   6178: 
1.721     harmsja  6179: .LC_ListStyleSimple dd,
1.795     www      6180: .LC_ListStyleSimple li {
1.698     harmsja  6181: 	border-bottom: solid 1px $lg_border_color;
1.693     droeschl 6182: }
                   6183: 
1.721     harmsja  6184: .LC_ListStyleSpecial li,
                   6185: .LC_ListStyleSpecial dd {
1.693     droeschl 6186: 	list-style-type: none;
                   6187: 	background-color: RGB(220, 220, 220);
                   6188: 	margin-bottom: 4px;
                   6189: }
                   6190: 
1.721     harmsja  6191: table.LC_SimpleTable {
1.698     harmsja  6192: 	margin:5px;
                   6193: 	border:solid 1px $lg_border_color;
1.795     www      6194: }
1.693     droeschl 6195: 
1.721     harmsja  6196: table.LC_SimpleTable tr {
1.803     bisitz   6197: 	padding: 0;
1.698     harmsja  6198: 	border:solid 1px $lg_border_color;
1.693     droeschl 6199: }
1.795     www      6200: 
                   6201: table.LC_SimpleTable thead {
1.698     harmsja  6202: 	 background:rgb(220,220,220);
1.693     droeschl 6203: }
                   6204: 
1.721     harmsja  6205: div.LC_columnSection {
1.693     droeschl 6206: 	display: block;
                   6207: 	clear: both;
                   6208: 	overflow: hidden;
1.803     bisitz   6209: 	margin: 0;
1.693     droeschl 6210: }
                   6211: 
1.721     harmsja  6212: div.LC_columnSection>* {
1.693     droeschl 6213: 	float: left;
1.803     bisitz   6214: 	margin: 10px 20px 10px 0;
1.747     neumanie 6215: 	overflow:hidden;
1.693     droeschl 6216: }
1.721     harmsja  6217: 
1.694     tempelho 6218: .LC_loginpage_container {
                   6219: 	text-align:left;
                   6220: 	margin : 0 auto;
1.785     tempelho 6221: 	width:90%;
1.694     tempelho 6222: 	padding: 10px;
                   6223: 	height: auto;
1.712     muellerd 6224: 	background-color:#FFFFFF;
1.694     tempelho 6225: 	border:1px solid #CCCCCC;
                   6226: }
                   6227: 
                   6228: 
                   6229: .LC_loginpage_loginContainer {
                   6230: 	float:left;
1.712     muellerd 6231: 	width: 182px;
1.785     tempelho 6232: 	padding: 2px;
1.712     muellerd 6233: 	border:1px solid #CCCCCC;
                   6234: 	background-color:$loginbg;
1.694     tempelho 6235: }
                   6236: 
1.795     www      6237: .LC_loginpage_loginContainer h2 {
1.803     bisitz   6238: 	margin-top: 0;
1.712     muellerd 6239: 	display:block;
                   6240: 	background:$bgcol;
                   6241: 	color:$textcol;
                   6242: 	padding-left:5px;
                   6243: }
1.785     tempelho 6244: 
1.694     tempelho 6245: .LC_loginpage_loginInfo {
                   6246: 	float:left;
1.785     tempelho 6247: 	width:182px;
1.694     tempelho 6248: 	border:1px solid #CCCCCC;
1.785     tempelho 6249: 	padding:2px;
1.712     muellerd 6250: }
                   6251: 
1.694     tempelho 6252: .LC_loginpage_space {
1.754     droeschl 6253: 	clear: both;
                   6254: 	margin-bottom: 20px;
1.694     tempelho 6255: 	border-bottom: 1px solid #CCCCCC;
                   6256: }
                   6257: 
1.785     tempelho 6258: .LC_loginpage_floatLeft {
                   6259: 	float: left;
                   6260: 	width: 200px;
                   6261: 	margin: 0;
                   6262: }
                   6263: 
1.795     www      6264: table em {
1.754     droeschl 6265: 	font-weight: bold;
                   6266: 	font-style: normal;
1.748     schulted 6267: }
1.795     www      6268: 
1.779     bisitz   6269: table.LC_tableBrowseRes,
1.795     www      6270: table.LC_tableOfContent {
1.769     schulted 6271:         border:none;
1.858     bisitz   6272: 	border-spacing: 1px;
1.754     droeschl 6273: 	padding: 3px;
                   6274: 	background-color: #FFFFFF;
                   6275: 	font-size: 90%;
1.753     droeschl 6276: }
1.789     droeschl 6277: 
                   6278: table.LC_tableOfContent{
                   6279:     border-collapse: collapse;
                   6280: }
                   6281: 
1.771     droeschl 6282: table.LC_tableBrowseRes a,
1.768     schulted 6283: table.LC_tableOfContent a {
1.771     droeschl 6284:         background-color: transparent;
1.753     droeschl 6285: 	text-decoration: none;
                   6286: }
                   6287: 
1.771     droeschl 6288: table.LC_tableBrowseRes tr.LC_trOdd,
1.768     schulted 6289: table.LC_tableOfContent tr.LC_trOdd{
1.754     droeschl 6290: 	background-color: #EEEEEE;
1.753     droeschl 6291: }
                   6292: 
1.795     www      6293: table.LC_tableOfContent img {
1.753     droeschl 6294: 	border: none;
                   6295: 	height: 1.3em;
                   6296: 	vertical-align: text-bottom;
                   6297: 	margin-right: 0.3em;
                   6298: }
1.757     schulted 6299: 
1.795     www      6300: a#LC_content_toolbar_firsthomework {
1.774     ehlerst  6301: 	background-image:url(/res/adm/pages/open-first-problem.gif);
                   6302: }
                   6303: 
1.795     www      6304: a#LC_content_toolbar_launchnav {
1.774     ehlerst  6305: 	background-image:url(/res/adm/pages/start-navigation.gif);
                   6306: }
                   6307: 
1.795     www      6308: a#LC_content_toolbar_closenav {
1.774     ehlerst  6309: 	background-image:url(/res/adm/pages/close-navigation.gif);
                   6310: }
                   6311: 
1.795     www      6312: a#LC_content_toolbar_everything {
1.774     ehlerst  6313: 	background-image:url(/res/adm/pages/show-all.gif);
                   6314: }
                   6315: 
1.795     www      6316: a#LC_content_toolbar_uncompleted {
1.774     ehlerst  6317: 	background-image:url(/res/adm/pages/show-incomplete-problems.gif);
                   6318: }
                   6319: 
1.795     www      6320: #LC_content_toolbar_clearbubbles {
1.774     ehlerst  6321: 	background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
                   6322: }
                   6323: 
1.795     www      6324: a#LC_content_toolbar_changefolder {
1.757     schulted 6325: 	background : url(/res/adm/pages/close-all-folders.gif) top center ;
                   6326: }
                   6327: 
1.795     www      6328: a#LC_content_toolbar_changefolder_toggled {
1.757     schulted 6329: 	background-image:url(/res/adm/pages/open-all-folders.gif);
                   6330: }
                   6331: 
1.795     www      6332: ul#LC_toolbar li a:hover {
1.757     schulted 6333: 	background-position: bottom center;
                   6334: }
                   6335: 
1.795     www      6336: ul#LC_toolbar {
1.803     bisitz   6337: 	padding: 0;
1.757     schulted 6338: 	margin: 2px;
                   6339: 	list-style:none;
                   6340: 	position:relative;
                   6341: 	background-color:white;
                   6342: }
                   6343: 
1.795     www      6344: ul#LC_toolbar li {
1.757     schulted 6345: 	border:1px solid white;
1.803     bisitz   6346: 	padding: 0;
1.757     schulted 6347: 	margin: 0;
1.795     www      6348:         float: left;
1.767     droeschl 6349: 	display:inline;
1.757     schulted 6350: 	vertical-align:middle;
1.795     www      6351: } 
1.757     schulted 6352: 
1.783     amueller 6353: 
1.795     www      6354: a.LC_toolbarItem {
1.767     droeschl 6355: 	display:block;
1.803     bisitz   6356: 	padding: 0;
                   6357: 	margin: 0;
1.757     schulted 6358: 	height: 32px;
                   6359: 	width: 32px;
1.779     bisitz   6360: 	color:white;
1.803     bisitz   6361: 	border: none;
1.757     schulted 6362: 	background-repeat:no-repeat;
                   6363: 	background-color:transparent;
                   6364: }
                   6365: 
1.843     bisitz   6366: ul.LC_funclist li {
1.782     bisitz   6367:   float: left;
                   6368:   white-space: nowrap;
                   6369:   height: 35px; /* at least as high as heighest list item */
1.803     bisitz   6370:   margin: 0 15px 15px 10px;
1.782     bisitz   6371: }
                   6372: 
1.757     schulted 6373: 
1.343     albertel 6374: END
                   6375: }
                   6376: 
1.306     albertel 6377: =pod
                   6378: 
                   6379: =item * &headtag()
                   6380: 
                   6381: Returns a uniform footer for LON-CAPA web pages.
                   6382: 
1.307     albertel 6383: Inputs: $title - optional title for the head
                   6384:         $head_extra - optional extra HTML to put inside the <head>
1.315     albertel 6385:         $args - optional arguments
1.319     albertel 6386:             force_register - if is true call registerurl so the remote is 
                   6387:                              informed
1.415     albertel 6388:             redirect       -> array ref of
                   6389:                                    1- seconds before redirect occurs
                   6390:                                    2- url to redirect to
                   6391:                                    3- whether the side effect should occur
1.315     albertel 6392:                            (side effect of setting 
                   6393:                                $env{'internal.head.redirect'} to the url 
                   6394:                                redirected too)
1.352     albertel 6395:             domain         -> force to color decorate a page for a specific
                   6396:                                domain
                   6397:             function       -> force usage of a specific rolish color scheme
                   6398:             bgcolor        -> override the default page bgcolor
1.460     albertel 6399:             no_auto_mt_title
                   6400:                            -> prevent &mt()ing the title arg
1.464     albertel 6401: 
1.306     albertel 6402: =cut
                   6403: 
                   6404: sub headtag {
1.313     albertel 6405:     my ($title,$head_extra,$args) = @_;
1.306     albertel 6406:     
1.363     albertel 6407:     my $function = $args->{'function'} || &get_users_function();
                   6408:     my $domain   = $args->{'domain'}   || &determinedomain();
                   6409:     my $bgcolor  = $args->{'bgcolor'}  || &designparm($function.'.pgbg',$domain);
1.418     albertel 6410:     my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458     albertel 6411: 		   $Apache::lonnet::perlvar{'lonVersion'},
1.531     albertel 6412: 		   #time(),
1.418     albertel 6413: 		   $env{'environment.color.timestamp'},
1.363     albertel 6414: 		   $function,$domain,$bgcolor);
                   6415: 
1.369     www      6416:     $url = '/adm/css/'.&escape($url).'.css';
1.363     albertel 6417: 
1.308     albertel 6418:     my $result =
                   6419: 	'<head>'.
1.461     albertel 6420: 	&font_settings();
1.319     albertel 6421: 
1.461     albertel 6422:     if (!$args->{'frameset'}) {
                   6423: 	$result .= &Apache::lonhtmlcommon::htmlareaheaders();
                   6424:     }
1.319     albertel 6425:     if ($args->{'force_register'}) {
                   6426: 	$result .= &Apache::lonmenu::registerurl(1);
                   6427:     }
1.436     albertel 6428:     if (!$args->{'no_nav_bar'} 
                   6429: 	&& !$args->{'only_body'}
                   6430: 	&& !$args->{'frameset'}) {
                   6431: 	$result .= &help_menu_js();
                   6432:     }
1.319     albertel 6433: 
1.314     albertel 6434:     if (ref($args->{'redirect'})) {
1.414     albertel 6435: 	my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315     albertel 6436: 	$url = &Apache::lonenc::check_encrypt($url);
1.414     albertel 6437: 	if (!$inhibit_continue) {
                   6438: 	    $env{'internal.head.redirect'} = $url;
                   6439: 	}
1.313     albertel 6440: 	$result.=<<ADDMETA
                   6441: <meta http-equiv="pragma" content="no-cache" />
1.344     albertel 6442: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313     albertel 6443: ADDMETA
                   6444:     }
1.306     albertel 6445:     if (!defined($title)) {
                   6446: 	$title = 'The LearningOnline Network with CAPA';
                   6447:     }
1.460     albertel 6448:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
                   6449:     $result .= '<title> LON-CAPA '.$title.'</title>'
1.414     albertel 6450: 	.'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
                   6451: 	.$head_extra;
1.306     albertel 6452:     return $result;
                   6453: }
                   6454: 
                   6455: =pod
                   6456: 
1.340     albertel 6457: =item * &font_settings()
                   6458: 
                   6459: Returns neccessary <meta> to set the proper encoding
                   6460: 
                   6461: Inputs: none
                   6462: 
                   6463: =cut
                   6464: 
                   6465: sub font_settings {
                   6466:     my $headerstring='';
1.647     www      6467:     if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340     albertel 6468: 	$headerstring.=
                   6469: 	    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
                   6470:     }
                   6471:     return $headerstring;
                   6472: }
                   6473: 
1.341     albertel 6474: =pod
                   6475: 
                   6476: =item * &xml_begin()
                   6477: 
                   6478: Returns the needed doctype and <html>
                   6479: 
                   6480: Inputs: none
                   6481: 
                   6482: =cut
                   6483: 
                   6484: sub xml_begin {
                   6485:     my $output='';
                   6486: 
1.592     albertel 6487:     if ($env{'internal.start_page'}==1) {
                   6488: 	&Apache::lonhtmlcommon::init_htmlareafields();
                   6489:     }
1.342     albertel 6490: 
1.341     albertel 6491:     if ($env{'browser.mathml'}) {
                   6492: 	$output='<?xml version="1.0"?>'
                   6493:             #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
                   6494: #            .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
                   6495:             
                   6496: #	    .'<!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">] >'
                   6497: 	    .'<!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">'
                   6498:             .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" ' 
                   6499: 	    .'xmlns="http://www.w3.org/1999/xhtml">';
                   6500:     } else {
1.849     bisitz   6501: 	$output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
                   6502:            .'<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">';
1.341     albertel 6503:     }
                   6504:     return $output;
                   6505: }
1.340     albertel 6506: 
                   6507: =pod
                   6508: 
1.306     albertel 6509: =item * &endheadtag()
                   6510: 
                   6511: Returns a uniform </head> for LON-CAPA web pages.
                   6512: 
                   6513: Inputs: none
                   6514: 
                   6515: =cut
                   6516: 
                   6517: sub endheadtag {
                   6518:     return '</head>';
                   6519: }
                   6520: 
                   6521: =pod
                   6522: 
                   6523: =item * &head()
                   6524: 
                   6525: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
                   6526: 
1.648     raeburn  6527: Inputs:
                   6528: 
                   6529: =over 4
                   6530: 
                   6531: $title - optional title for the page
                   6532: 
                   6533: $head_extra - optional extra HTML to put inside the <head>
                   6534: 
                   6535: =back
1.405     albertel 6536: 
1.306     albertel 6537: =cut
                   6538: 
                   6539: sub head {
1.325     albertel 6540:     my ($title,$head_extra,$args) = @_;
                   6541:     return &headtag($title,$head_extra,$args).&endheadtag();
1.306     albertel 6542: }
                   6543: 
                   6544: =pod
                   6545: 
                   6546: =item * &start_page()
                   6547: 
                   6548: Returns a complete <html> .. <body> section for LON-CAPA web pages.
                   6549: 
1.648     raeburn  6550: Inputs:
                   6551: 
                   6552: =over 4
                   6553: 
                   6554: $title - optional title for the page
                   6555: 
                   6556: $head_extra - optional extra HTML to incude inside the <head>
                   6557: 
                   6558: $args - additional optional args supported are:
                   6559: 
                   6560: =over 8
                   6561: 
                   6562:              only_body      -> is true will set &bodytag() onlybodytag
1.317     albertel 6563:                                     arg on
1.814     bisitz   6564:              no_nav_bar     -> is true will set &bodytag() no_nav_bar arg on
1.648     raeburn  6565:              add_entries    -> additional attributes to add to the  <body>
                   6566:              domain         -> force to color decorate a page for a 
1.317     albertel 6567:                                     specific domain
1.648     raeburn  6568:              function       -> force usage of a specific rolish color
1.317     albertel 6569:                                     scheme
1.648     raeburn  6570:              redirect       -> see &headtag()
                   6571:              bgcolor        -> override the default page bg color
                   6572:              js_ready       -> return a string ready for being used in 
1.317     albertel 6573:                                     a javascript writeln
1.648     raeburn  6574:              html_encode    -> return a string ready for being used in 
1.320     albertel 6575:                                     a html attribute
1.648     raeburn  6576:              force_register -> if is true will turn on the &bodytag()
1.317     albertel 6577:                                     $forcereg arg
1.648     raeburn  6578:              frameset       -> if true will start with a <frameset>
1.330     albertel 6579:                                     rather than <body>
1.648     raeburn  6580:              skip_phases    -> hash ref of 
1.338     albertel 6581:                                     head -> skip the <html><head> generation
                   6582:                                     body -> skip all <body> generation
1.648     raeburn  6583:              no_inline_link -> if true and in remote mode, don't show the 
1.361     albertel 6584:                                     'Switch To Inline Menu' link
1.648     raeburn  6585:              no_auto_mt_title -> prevent &mt()ing the title arg
                   6586:              inherit_jsmath -> when creating popup window in a page,
                   6587:                                     should it have jsmath forced on by the
                   6588:                                     current page
1.867     kalberla 6589:              bread_crumbs ->             Array containing breadcrumbs
                   6590:              bread_crumbs_components ->  if exists show it as headline else show only the breadcrumbs
1.361     albertel 6591: 
1.648     raeburn  6592: =back
1.460     albertel 6593: 
1.648     raeburn  6594: =back
1.562     albertel 6595: 
1.306     albertel 6596: =cut
                   6597: 
                   6598: sub start_page {
1.309     albertel 6599:     my ($title,$head_extra,$args) = @_;
1.318     albertel 6600:     #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313     albertel 6601:     my %head_args;
1.352     albertel 6602:     foreach my $arg ('redirect','force_register','domain','function',
1.460     albertel 6603: 		     'bgcolor','frameset','no_nav_bar','only_body',
                   6604: 		     'no_auto_mt_title') {
1.319     albertel 6605: 	if (defined($args->{$arg})) {
1.324     raeburn  6606: 	    $head_args{$arg} = $args->{$arg};
1.319     albertel 6607: 	}
1.313     albertel 6608:     }
1.319     albertel 6609: 
1.315     albertel 6610:     $env{'internal.start_page'}++;
1.338     albertel 6611:     my $result;
                   6612:     if (! exists($args->{'skip_phases'}{'head'}) ) {
                   6613: 	$result.=
1.341     albertel 6614: 	    &xml_begin().
1.338     albertel 6615: 	    &headtag($title,$head_extra,\%head_args).&endheadtag();
                   6616:     }
                   6617:     
                   6618:     if (! exists($args->{'skip_phases'}{'body'}) ) {
                   6619: 	if ($args->{'frameset'}) {
                   6620: 	    my $attr_string = &make_attr_string($args->{'force_register'},
                   6621: 						$args->{'add_entries'});
                   6622: 	    $result .= "\n<frameset $attr_string>\n";
1.831     bisitz   6623:         } else {
                   6624:             $result .=
                   6625:                 &bodytag($title, 
                   6626:                          $args->{'function'},       $args->{'add_entries'},
                   6627:                          $args->{'only_body'},      $args->{'domain'},
                   6628:                          $args->{'force_register'}, $args->{'no_nav_bar'},
                   6629:                          $args->{'bgcolor'},        $args->{'no_inline_link'},
                   6630:                          $args);
                   6631:         }
1.330     albertel 6632:     }
1.338     albertel 6633: 
1.315     albertel 6634:     if ($args->{'js_ready'}) {
1.713     kaisler  6635: 		$result = &js_ready($result);
1.315     albertel 6636:     }
1.320     albertel 6637:     if ($args->{'html_encode'}) {
1.713     kaisler  6638: 		$result = &html_encode($result);
                   6639:     }
                   6640: 
1.813     bisitz   6641:     # Preparation for new and consistent functionlist at top of screen
                   6642:     # if ($args->{'functionlist'}) {
                   6643:     #            $result .= &build_functionlist();
                   6644:     #}
                   6645: 
                   6646:     # Don't add anything more if only_body wanted
                   6647:     return $result if $args->{'only_body'};
                   6648: 
                   6649:     #Breadcrumbs
1.758     kaisler  6650:     if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
                   6651: 		&Apache::lonhtmlcommon::clear_breadcrumbs();
                   6652: 		#if any br links exists, add them to the breadcrumbs
                   6653: 		if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {         
                   6654: 			foreach my $crumb (@{$args->{'bread_crumbs'}}){
                   6655: 				&Apache::lonhtmlcommon::add_breadcrumb($crumb);
                   6656: 			}
                   6657: 		}
                   6658: 
                   6659: 		#if bread_crumbs_component exists show it as headline else show only the breadcrumbs
                   6660: 		if(exists($args->{'bread_crumbs_component'})){
                   6661: 			$result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
                   6662: 		}else{
                   6663: 			$result .= &Apache::lonhtmlcommon::breadcrumbs();
                   6664: 		}
1.320     albertel 6665:     }
1.315     albertel 6666:     return $result;
1.306     albertel 6667: }
                   6668: 
1.330     albertel 6669: 
1.306     albertel 6670: =pod
                   6671: 
                   6672: =item * &head()
                   6673: 
                   6674: Returns a complete </body></html> section for LON-CAPA web pages.
                   6675: 
1.315     albertel 6676: Inputs:         $args - additional optional args supported are:
                   6677:                  js_ready     -> return a string ready for being used in 
                   6678:                                  a javascript writeln
1.320     albertel 6679:                  html_encode  -> return a string ready for being used in 
                   6680:                                  a html attribute
1.330     albertel 6681:                  frameset     -> if true will start with a <frameset>
                   6682:                                  rather than <body>
1.493     albertel 6683:                  dicsussion   -> if true will get discussion from
                   6684:                                   lonxml::xmlend
                   6685:                                  (you can pass the target and parser arguments
                   6686:                                   through optional 'target' and 'parser' args
                   6687:                                   to this routine)
1.306     albertel 6688: 
                   6689: =cut
                   6690: 
                   6691: sub end_page {
1.315     albertel 6692:     my ($args) = @_;
                   6693:     $env{'internal.end_page'}++;
1.330     albertel 6694:     my $result;
1.335     albertel 6695:     if ($args->{'discussion'}) {
                   6696: 	my ($target,$parser);
                   6697: 	if (ref($args->{'discussion'})) {
                   6698: 	    ($target,$parser) =($args->{'discussion'}{'target'},
                   6699: 				$args->{'discussion'}{'parser'});
                   6700: 	}
                   6701: 	$result .= &Apache::lonxml::xmlend($target,$parser);
                   6702:     }
                   6703: 
1.330     albertel 6704:     if ($args->{'frameset'}) {
                   6705: 	$result .= '</frameset>';
                   6706:     } else {
1.635     raeburn  6707: 	$result .= &endbodytag($args);
1.330     albertel 6708:     }
                   6709:     $result .= "\n</html>";
                   6710: 
1.315     albertel 6711:     if ($args->{'js_ready'}) {
1.317     albertel 6712: 	$result = &js_ready($result);
1.315     albertel 6713:     }
1.335     albertel 6714: 
1.320     albertel 6715:     if ($args->{'html_encode'}) {
                   6716: 	$result = &html_encode($result);
                   6717:     }
1.335     albertel 6718: 
1.315     albertel 6719:     return $result;
                   6720: }
                   6721: 
1.320     albertel 6722: sub html_encode {
                   6723:     my ($result) = @_;
                   6724: 
1.322     albertel 6725:     $result = &HTML::Entities::encode($result,'<>&"');
1.320     albertel 6726:     
                   6727:     return $result;
                   6728: }
1.317     albertel 6729: sub js_ready {
                   6730:     my ($result) = @_;
                   6731: 
1.323     albertel 6732:     $result =~ s/[\n\r]/ /xmsg;
                   6733:     $result =~ s/\\/\\\\/xmsg;
                   6734:     $result =~ s/'/\\'/xmsg;
1.372     albertel 6735:     $result =~ s{</}{<\\/}xmsg;
1.317     albertel 6736:     
                   6737:     return $result;
                   6738: }
                   6739: 
1.315     albertel 6740: sub validate_page {
                   6741:     if (  exists($env{'internal.start_page'})
1.316     albertel 6742: 	  &&     $env{'internal.start_page'} > 1) {
                   6743: 	&Apache::lonnet::logthis('start_page called multiple times '.
1.318     albertel 6744: 				 $env{'internal.start_page'}.' '.
1.316     albertel 6745: 				 $ENV{'request.filename'});
1.315     albertel 6746:     }
                   6747:     if (  exists($env{'internal.end_page'})
1.316     albertel 6748: 	  &&     $env{'internal.end_page'} > 1) {
                   6749: 	&Apache::lonnet::logthis('end_page called multiple times '.
1.318     albertel 6750: 				 $env{'internal.end_page'}.' '.
1.316     albertel 6751: 				 $env{'request.filename'});
1.315     albertel 6752:     }
                   6753:     if (     exists($env{'internal.start_page'})
                   6754: 	&& ! exists($env{'internal.end_page'})) {
1.316     albertel 6755: 	&Apache::lonnet::logthis('start_page called without end_page '.
                   6756: 				 $env{'request.filename'});
1.315     albertel 6757:     }
                   6758:     if (   ! exists($env{'internal.start_page'})
                   6759: 	&&   exists($env{'internal.end_page'})) {
1.316     albertel 6760: 	&Apache::lonnet::logthis('end_page called without start_page'.
                   6761: 				 $env{'request.filename'});
1.315     albertel 6762:     }
1.306     albertel 6763: }
1.315     albertel 6764: 
1.318     albertel 6765: sub simple_error_page {
                   6766:     my ($r,$title,$msg) = @_;
                   6767:     my $page =
                   6768: 	&Apache::loncommon::start_page($title).
                   6769: 	&mt($msg).
                   6770: 	&Apache::loncommon::end_page();
                   6771:     if (ref($r)) {
                   6772: 	$r->print($page);
1.327     albertel 6773: 	return;
1.318     albertel 6774:     }
                   6775:     return $page;
                   6776: }
1.347     albertel 6777: 
                   6778: {
1.610     albertel 6779:     my @row_count;
1.347     albertel 6780:     sub start_data_table {
1.422     albertel 6781: 	my ($add_class) = @_;
                   6782: 	my $css_class = (join(' ','LC_data_table',$add_class));
1.610     albertel 6783: 	unshift(@row_count,0);
1.422     albertel 6784: 	return '<table class="'.$css_class.'">'."\n";
1.347     albertel 6785:     }
                   6786: 
                   6787:     sub end_data_table {
1.610     albertel 6788: 	shift(@row_count);
1.389     albertel 6789: 	return '</table>'."\n";;
1.347     albertel 6790:     }
                   6791: 
                   6792:     sub start_data_table_row {
1.422     albertel 6793: 	my ($add_class) = @_;
1.610     albertel 6794: 	$row_count[0]++;
                   6795: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900     bisitz   6796: 	$css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.422     albertel 6797: 	return  '<tr class="'.$css_class.'">'."\n";;
1.347     albertel 6798:     }
1.471     banghart 6799:     
                   6800:     sub continue_data_table_row {
                   6801: 	my ($add_class) = @_;
1.610     albertel 6802: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900     bisitz   6803: 	$css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');;
1.471     banghart 6804: 	return  '<tr class="'.$css_class.'">'."\n";;
                   6805:     }
1.347     albertel 6806: 
                   6807:     sub end_data_table_row {
1.389     albertel 6808: 	return '</tr>'."\n";;
1.347     albertel 6809:     }
1.367     www      6810: 
1.421     albertel 6811:     sub start_data_table_empty_row {
1.707     bisitz   6812: #	$row_count[0]++;
1.421     albertel 6813: 	return  '<tr class="LC_empty_row" >'."\n";;
                   6814:     }
                   6815: 
                   6816:     sub end_data_table_empty_row {
                   6817: 	return '</tr>'."\n";;
                   6818:     }
                   6819: 
1.367     www      6820:     sub start_data_table_header_row {
1.389     albertel 6821: 	return  '<tr class="LC_header_row">'."\n";;
1.367     www      6822:     }
                   6823: 
                   6824:     sub end_data_table_header_row {
1.389     albertel 6825: 	return '</tr>'."\n";;
1.367     www      6826:     }
1.890     droeschl 6827: 
                   6828:     sub data_table_caption {
                   6829:         my $caption = shift;
                   6830:         return "<caption class=\"LC_caption\">$caption</caption>";
                   6831:     }
1.347     albertel 6832: }
                   6833: 
1.548     albertel 6834: =pod
                   6835: 
                   6836: =item * &inhibit_menu_check($arg)
                   6837: 
                   6838: Checks for a inhibitmenu state and generates output to preserve it
                   6839: 
                   6840: Inputs:         $arg - can be any of
                   6841:                      - undef - in which case the return value is a string 
                   6842:                                to add  into arguments list of a uri
                   6843:                      - 'input' - in which case the return value is a HTML
                   6844:                                  <form> <input> field of type hidden to
                   6845:                                  preserve the value
                   6846:                      - a url - in which case the return value is the url with
                   6847:                                the neccesary cgi args added to preserve the
                   6848:                                inhibitmenu state
                   6849:                      - a ref to a url - no return value, but the string is
                   6850:                                         updated to include the neccessary cgi
                   6851:                                         args to preserve the inhibitmenu state
                   6852: 
                   6853: =cut
                   6854: 
                   6855: sub inhibit_menu_check {
                   6856:     my ($arg) = @_;
                   6857:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   6858:     if ($arg eq 'input') {
                   6859: 	if ($env{'form.inhibitmenu'}) {
                   6860: 	    return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
                   6861: 	} else {
                   6862: 	    return
                   6863: 	}
                   6864:     }
                   6865:     if ($env{'form.inhibitmenu'}) {
                   6866: 	if (ref($arg)) {
                   6867: 	    $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   6868: 	} elsif ($arg eq '') {
                   6869: 	    $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
                   6870: 	} else {
                   6871: 	    $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   6872: 	}
                   6873:     }
                   6874:     if (!ref($arg)) {
                   6875: 	return $arg;
                   6876:     }
                   6877: }
                   6878: 
1.251     albertel 6879: ###############################################
1.182     matthew  6880: 
                   6881: =pod
                   6882: 
1.549     albertel 6883: =back
                   6884: 
                   6885: =head1 User Information Routines
                   6886: 
                   6887: =over 4
                   6888: 
1.405     albertel 6889: =item * &get_users_function()
1.182     matthew  6890: 
                   6891: Used by &bodytag to determine the current users primary role.
                   6892: Returns either 'student','coordinator','admin', or 'author'.
                   6893: 
                   6894: =cut
                   6895: 
                   6896: ###############################################
                   6897: sub get_users_function {
1.815     tempelho 6898:     my $function = 'norole';
1.818     tempelho 6899:     if ($env{'request.role'}=~/^(st)/) {
                   6900:         $function='student';
                   6901:     }
1.258     albertel 6902:     if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182     matthew  6903:         $function='coordinator';
                   6904:     }
1.258     albertel 6905:     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182     matthew  6906:         $function='admin';
                   6907:     }
1.826     bisitz   6908:     if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.182     matthew  6909:         ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
                   6910:         $function='author';
                   6911:     }
                   6912:     return $function;
1.54      www      6913: }
1.99      www      6914: 
                   6915: ###############################################
                   6916: 
1.233     raeburn  6917: =pod
                   6918: 
1.821     raeburn  6919: =item * &show_course()
                   6920: 
                   6921: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
                   6922: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
                   6923: 
                   6924: Inputs:
                   6925: None
                   6926: 
                   6927: Outputs:
                   6928: Scalar: 1 if 'Course' to be used, 0 otherwise.
                   6929: 
                   6930: =cut
                   6931: 
                   6932: ###############################################
                   6933: sub show_course {
                   6934:     my $course = !$env{'user.adv'};
                   6935:     if (!$env{'user.adv'}) {
                   6936:         foreach my $env (keys(%env)) {
                   6937:             next if ($env !~ m/^user\.priv\./);
                   6938:             if ($env !~ m/^user\.priv\.(?:st|cm)/) {
                   6939:                 $course = 0;
                   6940:                 last;
                   6941:             }
                   6942:         }
                   6943:     }
                   6944:     return $course;
                   6945: }
                   6946: 
                   6947: ###############################################
                   6948: 
                   6949: =pod
                   6950: 
1.542     raeburn  6951: =item * &check_user_status()
1.274     raeburn  6952: 
                   6953: Determines current status of supplied role for a
                   6954: specific user. Roles can be active, previous or future.
                   6955: 
                   6956: Inputs: 
                   6957: user's domain, user's username, course's domain,
1.375     raeburn  6958: course's number, optional section ID.
1.274     raeburn  6959: 
                   6960: Outputs:
                   6961: role status: active, previous or future. 
                   6962: 
                   6963: =cut
                   6964: 
                   6965: sub check_user_status {
1.412     raeburn  6966:     my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274     raeburn  6967:     my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
                   6968:     my @uroles = keys %userinfo;
                   6969:     my $srchstr;
                   6970:     my $active_chk = 'none';
1.412     raeburn  6971:     my $now = time;
1.274     raeburn  6972:     if (@uroles > 0) {
1.412     raeburn  6973:         if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274     raeburn  6974:             $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
                   6975:         } else {
1.412     raeburn  6976:             $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
                   6977:         }
                   6978:         if (grep/^\Q$srchstr\E$/,@uroles) {
1.274     raeburn  6979:             my $role_end = 0;
                   6980:             my $role_start = 0;
                   6981:             $active_chk = 'active';
1.412     raeburn  6982:             if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
                   6983:                 $role_end = $1;
                   6984:                 if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
                   6985:                     $role_start = $1;
1.274     raeburn  6986:                 }
                   6987:             }
                   6988:             if ($role_start > 0) {
1.412     raeburn  6989:                 if ($now < $role_start) {
1.274     raeburn  6990:                     $active_chk = 'future';
                   6991:                 }
                   6992:             }
                   6993:             if ($role_end > 0) {
1.412     raeburn  6994:                 if ($now > $role_end) {
1.274     raeburn  6995:                     $active_chk = 'previous';
                   6996:                 }
                   6997:             }
                   6998:         }
                   6999:     }
                   7000:     return $active_chk;
                   7001: }
                   7002: 
                   7003: ###############################################
                   7004: 
                   7005: =pod
                   7006: 
1.405     albertel 7007: =item * &get_sections()
1.233     raeburn  7008: 
                   7009: Determines all the sections for a course including
                   7010: sections with students and sections containing other roles.
1.419     raeburn  7011: Incoming parameters: 
                   7012: 
                   7013: 1. domain
                   7014: 2. course number 
                   7015: 3. reference to array containing roles for which sections should 
                   7016: be gathered (optional).
                   7017: 4. reference to array containing status types for which sections 
                   7018: should be gathered (optional).
                   7019: 
                   7020: If the third argument is undefined, sections are gathered for any role. 
                   7021: If the fourth argument is undefined, sections are gathered for any status.
                   7022: Permissible values are 'active' or 'future' or 'previous'.
1.233     raeburn  7023:  
1.374     raeburn  7024: Returns section hash (keys are section IDs, values are
                   7025: number of users in each section), subject to the
1.419     raeburn  7026: optional roles filter, optional status filter 
1.233     raeburn  7027: 
                   7028: =cut
                   7029: 
                   7030: ###############################################
                   7031: sub get_sections {
1.419     raeburn  7032:     my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366     albertel 7033:     if (!defined($cdom) || !defined($cnum)) {
                   7034:         my $cid =  $env{'request.course.id'};
                   7035: 
                   7036: 	return if (!defined($cid));
                   7037: 
                   7038:         $cdom = $env{'course.'.$cid.'.domain'};
                   7039:         $cnum = $env{'course.'.$cid.'.num'};
                   7040:     }
                   7041: 
                   7042:     my %sectioncount;
1.419     raeburn  7043:     my $now = time;
1.240     albertel 7044: 
1.366     albertel 7045:     if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276     albertel 7046: 	my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240     albertel 7047: 	my $sec_index = &Apache::loncoursedata::CL_SECTION();
                   7048: 	my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419     raeburn  7049:         my $start_index = &Apache::loncoursedata::CL_START();
                   7050:         my $end_index = &Apache::loncoursedata::CL_END();
                   7051:         my $status;
1.366     albertel 7052: 	while (my ($student,$data) = each(%$classlist)) {
1.419     raeburn  7053: 	    my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
                   7054: 				                     $data->[$status_index],
                   7055:                                                      $data->[$start_index],
                   7056:                                                      $data->[$end_index]);
                   7057:             if ($stu_status eq 'Active') {
                   7058:                 $status = 'active';
                   7059:             } elsif ($end < $now) {
                   7060:                 $status = 'previous';
                   7061:             } elsif ($start > $now) {
                   7062:                 $status = 'future';
                   7063:             } 
                   7064: 	    if ($section ne '-1' && $section !~ /^\s*$/) {
                   7065:                 if ((!defined($possible_status)) || (($status ne '') && 
                   7066:                     (grep/^\Q$status\E$/,@{$possible_status}))) { 
                   7067: 		    $sectioncount{$section}++;
                   7068:                 }
1.240     albertel 7069: 	    }
                   7070: 	}
                   7071:     }
                   7072:     my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7073:     foreach my $user (sort(keys(%courseroles))) {
                   7074: 	if ($user !~ /^(\w{2})/) { next; }
                   7075: 	my ($role) = ($user =~ /^(\w{2})/);
                   7076: 	if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419     raeburn  7077: 	my ($section,$status);
1.240     albertel 7078: 	if ($role eq 'cr' &&
                   7079: 	    $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
                   7080: 	    $section=$1;
                   7081: 	}
                   7082: 	if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
                   7083: 	if (!defined($section) || $section eq '-1') { next; }
1.419     raeburn  7084:         my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
                   7085:         if ($end == -1 && $start == -1) {
                   7086:             next; #deleted role
                   7087:         }
                   7088:         if (!defined($possible_status)) { 
                   7089:             $sectioncount{$section}++;
                   7090:         } else {
                   7091:             if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
                   7092:                 $status = 'active';
                   7093:             } elsif ($end < $now) {
                   7094:                 $status = 'future';
                   7095:             } elsif ($start > $now) {
                   7096:                 $status = 'previous';
                   7097:             }
                   7098:             if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
                   7099:                 $sectioncount{$section}++;
                   7100:             }
                   7101:         }
1.233     raeburn  7102:     }
1.366     albertel 7103:     return %sectioncount;
1.233     raeburn  7104: }
                   7105: 
1.274     raeburn  7106: ###############################################
1.294     raeburn  7107: 
                   7108: =pod
1.405     albertel 7109: 
                   7110: =item * &get_course_users()
                   7111: 
1.275     raeburn  7112: Retrieves usernames:domains for users in the specified course
                   7113: with specific role(s), and access status. 
                   7114: 
                   7115: Incoming parameters:
1.277     albertel 7116: 1. course domain
                   7117: 2. course number
                   7118: 3. access status: users must have - either active, 
1.275     raeburn  7119: previous, future, or all.
1.277     albertel 7120: 4. reference to array of permissible roles
1.288     raeburn  7121: 5. reference to array of section restrictions (optional)
                   7122: 6. reference to results object (hash of hashes).
                   7123: 7. reference to optional userdata hash
1.609     raeburn  7124: 8. reference to optional statushash
1.630     raeburn  7125: 9. flag if privileged users (except those set to unhide in
                   7126:    course settings) should be excluded    
1.609     raeburn  7127: Keys of top level results hash are roles.
1.275     raeburn  7128: Keys of inner hashes are username:domain, with 
                   7129: values set to access type.
1.288     raeburn  7130: Optional userdata hash returns an array with arguments in the 
                   7131: same order as loncoursedata::get_classlist() for student data.
                   7132: 
1.609     raeburn  7133: Optional statushash returns
                   7134: 
1.288     raeburn  7135: Entries for end, start, section and status are blank because
                   7136: of the possibility of multiple values for non-student roles.
                   7137: 
1.275     raeburn  7138: =cut
1.405     albertel 7139: 
1.275     raeburn  7140: ###############################################
1.405     albertel 7141: 
1.275     raeburn  7142: sub get_course_users {
1.630     raeburn  7143:     my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288     raeburn  7144:     my %idx = ();
1.419     raeburn  7145:     my %seclists;
1.288     raeburn  7146: 
                   7147:     $idx{udom} = &Apache::loncoursedata::CL_SDOM();
                   7148:     $idx{uname} =  &Apache::loncoursedata::CL_SNAME();
                   7149:     $idx{end} = &Apache::loncoursedata::CL_END();
                   7150:     $idx{start} = &Apache::loncoursedata::CL_START();
                   7151:     $idx{id} = &Apache::loncoursedata::CL_ID();
                   7152:     $idx{section} = &Apache::loncoursedata::CL_SECTION();
                   7153:     $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
                   7154:     $idx{status} = &Apache::loncoursedata::CL_STATUS();
                   7155: 
1.290     albertel 7156:     if (grep(/^st$/,@{$roles})) {
1.276     albertel 7157:         my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278     raeburn  7158:         my $now = time;
1.277     albertel 7159:         foreach my $student (keys(%{$classlist})) {
1.288     raeburn  7160:             my $match = 0;
1.412     raeburn  7161:             my $secmatch = 0;
1.419     raeburn  7162:             my $section = $$classlist{$student}[$idx{section}];
1.609     raeburn  7163:             my $status = $$classlist{$student}[$idx{status}];
1.419     raeburn  7164:             if ($section eq '') {
                   7165:                 $section = 'none';
                   7166:             }
1.291     albertel 7167:             if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 7168:                 if (grep(/^all$/,@{$sections})) {
1.412     raeburn  7169:                     $secmatch = 1;
                   7170:                 } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420     albertel 7171:                     if (grep(/^none$/,@{$sections})) {
1.412     raeburn  7172:                         $secmatch = 1;
                   7173:                     }
                   7174:                 } else {  
1.419     raeburn  7175: 		    if (grep(/^\Q$section\E$/,@{$sections})) {
1.412     raeburn  7176: 		        $secmatch = 1;
                   7177:                     }
1.290     albertel 7178: 		}
1.412     raeburn  7179:                 if (!$secmatch) {
                   7180:                     next;
                   7181:                 }
1.419     raeburn  7182:             }
1.275     raeburn  7183:             if (defined($$types{'active'})) {
1.288     raeburn  7184:                 if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275     raeburn  7185:                     push(@{$$users{st}{$student}},'active');
1.288     raeburn  7186:                     $match = 1;
1.275     raeburn  7187:                 }
                   7188:             }
                   7189:             if (defined($$types{'previous'})) {
1.609     raeburn  7190:                 if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275     raeburn  7191:                     push(@{$$users{st}{$student}},'previous');
1.288     raeburn  7192:                     $match = 1;
1.275     raeburn  7193:                 }
                   7194:             }
                   7195:             if (defined($$types{'future'})) {
1.609     raeburn  7196:                 if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275     raeburn  7197:                     push(@{$$users{st}{$student}},'future');
1.288     raeburn  7198:                     $match = 1;
1.275     raeburn  7199:                 }
                   7200:             }
1.609     raeburn  7201:             if ($match) {
                   7202:                 push(@{$seclists{$student}},$section);
                   7203:                 if (ref($userdata) eq 'HASH') {
                   7204:                     $$userdata{$student} = $$classlist{$student};
                   7205:                 }
                   7206:                 if (ref($statushash) eq 'HASH') {
                   7207:                     $statushash->{$student}{'st'}{$section} = $status;
                   7208:                 }
1.288     raeburn  7209:             }
1.275     raeburn  7210:         }
                   7211:     }
1.412     raeburn  7212:     if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439     raeburn  7213:         my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7214:         my $now = time;
1.609     raeburn  7215:         my %displaystatus = ( previous => 'Expired',
                   7216:                               active   => 'Active',
                   7217:                               future   => 'Future',
                   7218:                             );
1.630     raeburn  7219:         my %nothide;
                   7220:         if ($hidepriv) {
                   7221:             my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
                   7222:             foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
                   7223:                 if ($user !~ /:/) {
                   7224:                     $nothide{join(':',split(/[\@]/,$user))}=1;
                   7225:                 } else {
                   7226:                     $nothide{$user} = 1;
                   7227:                 }
                   7228:             }
                   7229:         }
1.439     raeburn  7230:         foreach my $person (sort(keys(%coursepersonnel))) {
1.288     raeburn  7231:             my $match = 0;
1.412     raeburn  7232:             my $secmatch = 0;
1.439     raeburn  7233:             my $status;
1.412     raeburn  7234:             my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275     raeburn  7235:             $user =~ s/:$//;
1.439     raeburn  7236:             my ($end,$start) = split(/:/,$coursepersonnel{$person});
                   7237:             if ($end == -1 || $start == -1) {
                   7238:                 next;
                   7239:             }
                   7240:             if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
                   7241:                 (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412     raeburn  7242:                 my ($uname,$udom) = split(/:/,$user);
                   7243:                 if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 7244:                     if (grep(/^all$/,@{$sections})) {
1.412     raeburn  7245:                         $secmatch = 1;
                   7246:                     } elsif ($usec eq '') {
1.420     albertel 7247:                         if (grep(/^none$/,@{$sections})) {
1.412     raeburn  7248:                             $secmatch = 1;
                   7249:                         }
                   7250:                     } else {
                   7251:                         if (grep(/^\Q$usec\E$/,@{$sections})) {
                   7252:                             $secmatch = 1;
                   7253:                         }
                   7254:                     }
                   7255:                     if (!$secmatch) {
                   7256:                         next;
                   7257:                     }
1.288     raeburn  7258:                 }
1.419     raeburn  7259:                 if ($usec eq '') {
                   7260:                     $usec = 'none';
                   7261:                 }
1.275     raeburn  7262:                 if ($uname ne '' && $udom ne '') {
1.630     raeburn  7263:                     if ($hidepriv) {
                   7264:                         if ((&Apache::lonnet::privileged($uname,$udom)) &&
                   7265:                             (!$nothide{$uname.':'.$udom})) {
                   7266:                             next;
                   7267:                         }
                   7268:                     }
1.503     raeburn  7269:                     if ($end > 0 && $end < $now) {
1.439     raeburn  7270:                         $status = 'previous';
                   7271:                     } elsif ($start > $now) {
                   7272:                         $status = 'future';
                   7273:                     } else {
                   7274:                         $status = 'active';
                   7275:                     }
1.277     albertel 7276:                     foreach my $type (keys(%{$types})) { 
1.275     raeburn  7277:                         if ($status eq $type) {
1.420     albertel 7278:                             if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419     raeburn  7279:                                 push(@{$$users{$role}{$user}},$type);
                   7280:                             }
1.288     raeburn  7281:                             $match = 1;
                   7282:                         }
                   7283:                     }
1.419     raeburn  7284:                     if (($match) && (ref($userdata) eq 'HASH')) {
                   7285:                         if (!exists($$userdata{$uname.':'.$udom})) {
                   7286: 			    &get_user_info($udom,$uname,\%idx,$userdata);
                   7287:                         }
1.420     albertel 7288:                         if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419     raeburn  7289:                             push(@{$seclists{$uname.':'.$udom}},$usec);
                   7290:                         }
1.609     raeburn  7291:                         if (ref($statushash) eq 'HASH') {
                   7292:                             $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
                   7293:                         }
1.275     raeburn  7294:                     }
                   7295:                 }
                   7296:             }
                   7297:         }
1.290     albertel 7298:         if (grep(/^ow$/,@{$roles})) {
1.279     raeburn  7299:             if ((defined($cdom)) && (defined($cnum))) {
                   7300:                 my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
                   7301:                 if ( defined($csettings{'internal.courseowner'}) ) {
                   7302:                     my $owner = $csettings{'internal.courseowner'};
1.609     raeburn  7303:                     next if ($owner eq '');
                   7304:                     my ($ownername,$ownerdom);
                   7305:                     if ($owner =~ /^([^:]+):([^:]+)$/) {
                   7306:                         $ownername = $1;
                   7307:                         $ownerdom = $2;
                   7308:                     } else {
                   7309:                         $ownername = $owner;
                   7310:                         $ownerdom = $cdom;
                   7311:                         $owner = $ownername.':'.$ownerdom;
1.439     raeburn  7312:                     }
                   7313:                     @{$$users{'ow'}{$owner}} = 'any';
1.290     albertel 7314:                     if (defined($userdata) && 
1.609     raeburn  7315: 			!exists($$userdata{$owner})) {
                   7316: 			&get_user_info($ownerdom,$ownername,\%idx,$userdata);
                   7317:                         if (!grep(/^none$/,@{$seclists{$owner}})) {
                   7318:                             push(@{$seclists{$owner}},'none');
                   7319:                         }
                   7320:                         if (ref($statushash) eq 'HASH') {
                   7321:                             $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419     raeburn  7322:                         }
1.290     albertel 7323: 		    }
1.279     raeburn  7324:                 }
                   7325:             }
                   7326:         }
1.419     raeburn  7327:         foreach my $user (keys(%seclists)) {
                   7328:             @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
                   7329:             $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
                   7330:         }
1.275     raeburn  7331:     }
                   7332:     return;
                   7333: }
                   7334: 
1.288     raeburn  7335: sub get_user_info {
                   7336:     my ($udom,$uname,$idx,$userdata) = @_;
1.289     albertel 7337:     $$userdata{$uname.':'.$udom}[$$idx{fullname}] = 
                   7338: 	&plainname($uname,$udom,'lastname');
1.291     albertel 7339:     $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297     raeburn  7340:     $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609     raeburn  7341:     my %idhash =  &Apache::lonnet::idrget($udom,($uname));
                   7342:     $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname}; 
1.288     raeburn  7343:     return;
                   7344: }
1.275     raeburn  7345: 
1.472     raeburn  7346: ###############################################
                   7347: 
                   7348: =pod
                   7349: 
                   7350: =item * &get_user_quota()
                   7351: 
                   7352: Retrieves quota assigned for storage of portfolio files for a user  
                   7353: 
                   7354: Incoming parameters:
                   7355: 1. user's username
                   7356: 2. user's domain
                   7357: 
                   7358: Returns:
1.536     raeburn  7359: 1. Disk quota (in Mb) assigned to student.
                   7360: 2. (Optional) Type of setting: custom or default
                   7361:    (individually assigned or default for user's 
                   7362:    institutional status).
                   7363: 3. (Optional) - User's institutional status (e.g., faculty, staff
                   7364:    or student - types as defined in localenroll::inst_usertypes 
                   7365:    for user's domain, which determines default quota for user.
                   7366: 4. (Optional) - Default quota which would apply to the user.
1.472     raeburn  7367: 
                   7368: If a value has been stored in the user's environment, 
1.536     raeburn  7369: it will return that, otherwise it returns the maximal default
                   7370: defined for the user's instituional status(es) in the domain.
1.472     raeburn  7371: 
                   7372: =cut
                   7373: 
                   7374: ###############################################
                   7375: 
                   7376: 
                   7377: sub get_user_quota {
                   7378:     my ($uname,$udom) = @_;
1.536     raeburn  7379:     my ($quota,$quotatype,$settingstatus,$defquota);
1.472     raeburn  7380:     if (!defined($udom)) {
                   7381:         $udom = $env{'user.domain'};
                   7382:     }
                   7383:     if (!defined($uname)) {
                   7384:         $uname = $env{'user.name'};
                   7385:     }
                   7386:     if (($udom eq '' || $uname eq '') ||
                   7387:         ($udom eq 'public') && ($uname eq 'public')) {
                   7388:         $quota = 0;
1.536     raeburn  7389:         $quotatype = 'default';
                   7390:         $defquota = 0; 
1.472     raeburn  7391:     } else {
1.536     raeburn  7392:         my $inststatus;
1.472     raeburn  7393:         if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
                   7394:             $quota = $env{'environment.portfolioquota'};
1.536     raeburn  7395:             $inststatus = $env{'environment.inststatus'};
1.472     raeburn  7396:         } else {
1.536     raeburn  7397:             my %userenv = 
                   7398:                 &Apache::lonnet::get('environment',['portfolioquota',
                   7399:                                      'inststatus'],$udom,$uname);
1.472     raeburn  7400:             my ($tmp) = keys(%userenv);
                   7401:             if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   7402:                 $quota = $userenv{'portfolioquota'};
1.536     raeburn  7403:                 $inststatus = $userenv{'inststatus'};
1.472     raeburn  7404:             } else {
                   7405:                 undef(%userenv);
                   7406:             }
                   7407:         }
1.536     raeburn  7408:         ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472     raeburn  7409:         if ($quota eq '') {
1.536     raeburn  7410:             $quota = $defquota;
                   7411:             $quotatype = 'default';
                   7412:         } else {
                   7413:             $quotatype = 'custom';
1.472     raeburn  7414:         }
                   7415:     }
1.536     raeburn  7416:     if (wantarray) {
                   7417:         return ($quota,$quotatype,$settingstatus,$defquota);
                   7418:     } else {
                   7419:         return $quota;
                   7420:     }
1.472     raeburn  7421: }
                   7422: 
                   7423: ###############################################
                   7424: 
                   7425: =pod
                   7426: 
                   7427: =item * &default_quota()
                   7428: 
1.536     raeburn  7429: Retrieves default quota assigned for storage of user portfolio files,
                   7430: given an (optional) user's institutional status.
1.472     raeburn  7431: 
                   7432: Incoming parameters:
                   7433: 1. domain
1.536     raeburn  7434: 2. (Optional) institutional status(es).  This is a : separated list of 
                   7435:    status types (e.g., faculty, staff, student etc.)
                   7436:    which apply to the user for whom the default is being retrieved.
                   7437:    If the institutional status string in undefined, the domain
                   7438:    default quota will be returned. 
1.472     raeburn  7439: 
                   7440: Returns:
                   7441: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536     raeburn  7442: 2. (Optional) institutional type which determined the value of the
                   7443:    default quota.
1.472     raeburn  7444: 
                   7445: If a value has been stored in the domain's configuration db,
                   7446: it will return that, otherwise it returns 20 (for backwards 
                   7447: compatibility with domains which have not set up a configuration
                   7448: db file; the original statically defined portfolio quota was 20 Mb). 
                   7449: 
1.536     raeburn  7450: If the user's status includes multiple types (e.g., staff and student),
                   7451: the largest default quota which applies to the user determines the
                   7452: default quota returned.
                   7453: 
1.780     raeburn  7454: =back
                   7455: 
1.472     raeburn  7456: =cut
                   7457: 
                   7458: ###############################################
                   7459: 
                   7460: 
                   7461: sub default_quota {
1.536     raeburn  7462:     my ($udom,$inststatus) = @_;
                   7463:     my ($defquota,$settingstatus);
                   7464:     my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622     raeburn  7465:                                             ['quotas'],$udom);
                   7466:     if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536     raeburn  7467:         if ($inststatus ne '') {
1.765     raeburn  7468:             my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536     raeburn  7469:             foreach my $item (@statuses) {
1.711     raeburn  7470:                 if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7471:                     if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
                   7472:                         if ($defquota eq '') {
                   7473:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7474:                             $settingstatus = $item;
                   7475:                         } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
                   7476:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7477:                             $settingstatus = $item;
                   7478:                         }
                   7479:                     }
                   7480:                 } else {
                   7481:                     if ($quotahash{'quotas'}{$item} ne '') {
                   7482:                         if ($defquota eq '') {
                   7483:                             $defquota = $quotahash{'quotas'}{$item};
                   7484:                             $settingstatus = $item;
                   7485:                         } elsif ($quotahash{'quotas'}{$item} > $defquota) {
                   7486:                             $defquota = $quotahash{'quotas'}{$item};
                   7487:                             $settingstatus = $item;
                   7488:                         }
1.536     raeburn  7489:                     }
                   7490:                 }
                   7491:             }
                   7492:         }
                   7493:         if ($defquota eq '') {
1.711     raeburn  7494:             if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7495:                 $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
                   7496:             } else {
                   7497:                 $defquota = $quotahash{'quotas'}{'default'};
                   7498:             }
1.536     raeburn  7499:             $settingstatus = 'default';
                   7500:         }
                   7501:     } else {
                   7502:         $settingstatus = 'default';
                   7503:         $defquota = 20;
                   7504:     }
                   7505:     if (wantarray) {
                   7506:         return ($defquota,$settingstatus);
1.472     raeburn  7507:     } else {
1.536     raeburn  7508:         return $defquota;
1.472     raeburn  7509:     }
                   7510: }
                   7511: 
1.384     raeburn  7512: sub get_secgrprole_info {
                   7513:     my ($cdom,$cnum,$needroles,$type)  = @_;
                   7514:     my %sections_count = &get_sections($cdom,$cnum);
                   7515:     my @sections =  (sort {$a <=> $b} keys(%sections_count));
                   7516:     my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
                   7517:     my @groups = sort(keys(%curr_groups));
                   7518:     my $allroles = [];
                   7519:     my $rolehash;
                   7520:     my $accesshash = {
                   7521:                      active => 'Currently has access',
                   7522:                      future => 'Will have future access',
                   7523:                      previous => 'Previously had access',
                   7524:                   };
                   7525:     if ($needroles) {
                   7526:         $rolehash = {'all' => 'all'};
1.385     albertel 7527:         my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7528: 	if (&Apache::lonnet::error(%user_roles)) {
                   7529: 	    undef(%user_roles);
                   7530: 	}
                   7531:         foreach my $item (keys(%user_roles)) {
1.384     raeburn  7532:             my ($role)=split(/\:/,$item,2);
                   7533:             if ($role eq 'cr') { next; }
                   7534:             if ($role =~ /^cr/) {
                   7535:                 $$rolehash{$role} = (split('/',$role))[3];
                   7536:             } else {
                   7537:                 $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
                   7538:             }
                   7539:         }
                   7540:         foreach my $key (sort(keys(%{$rolehash}))) {
                   7541:             push(@{$allroles},$key);
                   7542:         }
                   7543:         push (@{$allroles},'st');
                   7544:         $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
                   7545:     }
                   7546:     return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
                   7547: }
                   7548: 
1.555     raeburn  7549: sub user_picker {
1.627     raeburn  7550:     my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555     raeburn  7551:     my $currdom = $dom;
                   7552:     my %curr_selected = (
                   7553:                         srchin => 'dom',
1.580     raeburn  7554:                         srchby => 'lastname',
1.555     raeburn  7555:                       );
                   7556:     my $srchterm;
1.625     raeburn  7557:     if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555     raeburn  7558:         if ($srch->{'srchby'} ne '') {
                   7559:             $curr_selected{'srchby'} = $srch->{'srchby'};
                   7560:         }
                   7561:         if ($srch->{'srchin'} ne '') {
                   7562:             $curr_selected{'srchin'} = $srch->{'srchin'};
                   7563:         }
                   7564:         if ($srch->{'srchtype'} ne '') {
                   7565:             $curr_selected{'srchtype'} = $srch->{'srchtype'};
                   7566:         }
                   7567:         if ($srch->{'srchdomain'} ne '') {
                   7568:             $currdom = $srch->{'srchdomain'};
                   7569:         }
                   7570:         $srchterm = $srch->{'srchterm'};
                   7571:     }
                   7572:     my %lt=&Apache::lonlocal::texthash(
1.573     raeburn  7573:                     'usr'       => 'Search criteria',
1.563     raeburn  7574:                     'doma'      => 'Domain/institution to search',
1.558     albertel 7575:                     'uname'     => 'username',
                   7576:                     'lastname'  => 'last name',
1.555     raeburn  7577:                     'lastfirst' => 'last name, first name',
1.558     albertel 7578:                     'crs'       => 'in this course',
1.576     raeburn  7579:                     'dom'       => 'in selected LON-CAPA domain', 
1.558     albertel 7580:                     'alc'       => 'all LON-CAPA',
1.573     raeburn  7581:                     'instd'     => 'in institutional directory for selected domain',
1.558     albertel 7582:                     'exact'     => 'is',
                   7583:                     'contains'  => 'contains',
1.569     raeburn  7584:                     'begins'    => 'begins with',
1.571     raeburn  7585:                     'youm'      => "You must include some text to search for.",
                   7586:                     'thte'      => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
                   7587:                     'thet'      => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
                   7588:                     'yomc'      => "You must choose a domain when using an institutional directory search.",
                   7589:                     'ymcd'      => "You must choose a domain when using a domain search.",
                   7590:                     'whus'      => "When using searching by last,first you must include a comma as separator between last name and first name.",
                   7591:                     'whse'      => "When searching by last,first you must include at least one character in the first name.",
                   7592:                      'thfo'     => "The following need to be corrected before the search can be run:",
1.555     raeburn  7593:                                        );
1.563     raeburn  7594:     my $domform = &select_dom_form($currdom,'srchdomain',1,1);
                   7595:     my $srchinsel = ' <select name="srchin">';
1.555     raeburn  7596: 
                   7597:     my @srchins = ('crs','dom','alc','instd');
                   7598: 
                   7599:     foreach my $option (@srchins) {
                   7600:         # FIXME 'alc' option unavailable until 
                   7601:         #       loncreateuser::print_user_query_page()
                   7602:         #       has been completed.
                   7603:         next if ($option eq 'alc');
1.880     raeburn  7604:         next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));  
1.555     raeburn  7605:         next if ($option eq 'crs' && !$env{'request.course.id'});
1.563     raeburn  7606:         if ($curr_selected{'srchin'} eq $option) {
                   7607:             $srchinsel .= ' 
                   7608:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7609:         } else {
                   7610:             $srchinsel .= '
                   7611:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7612:         }
1.555     raeburn  7613:     }
1.563     raeburn  7614:     $srchinsel .= "\n  </select>\n";
1.555     raeburn  7615: 
                   7616:     my $srchbysel =  ' <select name="srchby">';
1.580     raeburn  7617:     foreach my $option ('lastname','lastfirst','uname') {
1.555     raeburn  7618:         if ($curr_selected{'srchby'} eq $option) {
                   7619:             $srchbysel .= '
                   7620:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7621:         } else {
                   7622:             $srchbysel .= '
                   7623:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7624:          }
                   7625:     }
                   7626:     $srchbysel .= "\n  </select>\n";
                   7627: 
                   7628:     my $srchtypesel = ' <select name="srchtype">';
1.580     raeburn  7629:     foreach my $option ('begins','contains','exact') {
1.555     raeburn  7630:         if ($curr_selected{'srchtype'} eq $option) {
                   7631:             $srchtypesel .= '
                   7632:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7633:         } else {
                   7634:             $srchtypesel .= '
                   7635:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7636:         }
                   7637:     }
                   7638:     $srchtypesel .= "\n  </select>\n";
                   7639: 
1.558     albertel 7640:     my ($newuserscript,$new_user_create);
1.556     raeburn  7641: 
                   7642:     if ($forcenewuser) {
1.576     raeburn  7643:         if (ref($srch) eq 'HASH') {
                   7644:             if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627     raeburn  7645:                 if ($cancreate) {
                   7646:                     $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>';
                   7647:                 } else {
1.799     bisitz   7648:                     my $helplink = 'javascript:helpMenu('."'display'".')';
1.627     raeburn  7649:                     my %usertypetext = (
                   7650:                         official   => 'institutional',
                   7651:                         unofficial => 'non-institutional',
                   7652:                     );
1.799     bisitz   7653:                     $new_user_create = '<p class="LC_warning">'
                   7654:                                       .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
                   7655:                                       .' '
                   7656:                                       .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
                   7657:                                           ,'<a href="'.$helplink.'">','</a>')
                   7658:                                       .'</p><br />';
1.627     raeburn  7659:                 }
1.576     raeburn  7660:             }
                   7661:         }
                   7662: 
1.556     raeburn  7663:         $newuserscript = <<"ENDSCRIPT";
                   7664: 
1.570     raeburn  7665: function setSearch(createnew,callingForm) {
1.556     raeburn  7666:     if (createnew == 1) {
1.570     raeburn  7667:         for (var i=0; i<callingForm.srchby.length; i++) {
                   7668:             if (callingForm.srchby.options[i].value == 'uname') {
                   7669:                 callingForm.srchby.selectedIndex = i;
1.556     raeburn  7670:             }
                   7671:         }
1.570     raeburn  7672:         for (var i=0; i<callingForm.srchin.length; i++) {
                   7673:             if ( callingForm.srchin.options[i].value == 'dom') {
                   7674: 		callingForm.srchin.selectedIndex = i;
1.556     raeburn  7675:             }
                   7676:         }
1.570     raeburn  7677:         for (var i=0; i<callingForm.srchtype.length; i++) {
                   7678:             if (callingForm.srchtype.options[i].value == 'exact') {
                   7679:                 callingForm.srchtype.selectedIndex = i;
1.556     raeburn  7680:             }
                   7681:         }
1.570     raeburn  7682:         for (var i=0; i<callingForm.srchdomain.length; i++) {
                   7683:             if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
                   7684:                 callingForm.srchdomain.selectedIndex = i;
1.556     raeburn  7685:             }
                   7686:         }
                   7687:     }
                   7688: }
                   7689: ENDSCRIPT
1.558     albertel 7690: 
1.556     raeburn  7691:     }
                   7692: 
1.555     raeburn  7693:     my $output = <<"END_BLOCK";
1.556     raeburn  7694: <script type="text/javascript">
1.824     bisitz   7695: // <![CDATA[
1.570     raeburn  7696: function validateEntry(callingForm) {
1.558     albertel 7697: 
1.556     raeburn  7698:     var checkok = 1;
1.558     albertel 7699:     var srchin;
1.570     raeburn  7700:     for (var i=0; i<callingForm.srchin.length; i++) {
                   7701: 	if ( callingForm.srchin[i].checked ) {
                   7702: 	    srchin = callingForm.srchin[i].value;
1.558     albertel 7703: 	}
                   7704:     }
                   7705: 
1.570     raeburn  7706:     var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
                   7707:     var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
                   7708:     var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
                   7709:     var srchterm =  callingForm.srchterm.value;
                   7710:     var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556     raeburn  7711:     var msg = "";
                   7712: 
                   7713:     if (srchterm == "") {
                   7714:         checkok = 0;
1.571     raeburn  7715:         msg += "$lt{'youm'}\\n";
1.556     raeburn  7716:     }
                   7717: 
1.569     raeburn  7718:     if (srchtype== 'begins') {
                   7719:         if (srchterm.length < 2) {
                   7720:             checkok = 0;
1.571     raeburn  7721:             msg += "$lt{'thte'}\\n";
1.569     raeburn  7722:         }
                   7723:     }
                   7724: 
1.556     raeburn  7725:     if (srchtype== 'contains') {
                   7726:         if (srchterm.length < 3) {
                   7727:             checkok = 0;
1.571     raeburn  7728:             msg += "$lt{'thet'}\\n";
1.556     raeburn  7729:         }
                   7730:     }
                   7731:     if (srchin == 'instd') {
                   7732:         if (srchdomain == '') {
                   7733:             checkok = 0;
1.571     raeburn  7734:             msg += "$lt{'yomc'}\\n";
1.556     raeburn  7735:         }
                   7736:     }
                   7737:     if (srchin == 'dom') {
                   7738:         if (srchdomain == '') {
                   7739:             checkok = 0;
1.571     raeburn  7740:             msg += "$lt{'ymcd'}\\n";
1.556     raeburn  7741:         }
                   7742:     }
                   7743:     if (srchby == 'lastfirst') {
                   7744:         if (srchterm.indexOf(",") == -1) {
                   7745:             checkok = 0;
1.571     raeburn  7746:             msg += "$lt{'whus'}\\n";
1.556     raeburn  7747:         }
                   7748:         if (srchterm.indexOf(",") == srchterm.length -1) {
                   7749:             checkok = 0;
1.571     raeburn  7750:             msg += "$lt{'whse'}\\n";
1.556     raeburn  7751:         }
                   7752:     }
                   7753:     if (checkok == 0) {
1.571     raeburn  7754:         alert("$lt{'thfo'}\\n"+msg);
1.556     raeburn  7755:         return;
                   7756:     }
                   7757:     if (checkok == 1) {
1.570     raeburn  7758:         callingForm.submit();
1.556     raeburn  7759:     }
                   7760: }
                   7761: 
                   7762: $newuserscript
                   7763: 
1.824     bisitz   7764: // ]]>
1.556     raeburn  7765: </script>
1.558     albertel 7766: 
                   7767: $new_user_create
                   7768: 
1.555     raeburn  7769: END_BLOCK
1.558     albertel 7770: 
1.876     raeburn  7771:     $output .= &Apache::lonhtmlcommon::start_pick_box().
                   7772:                &Apache::lonhtmlcommon::row_title($lt{'doma'}).
                   7773:                $domform.
                   7774:                &Apache::lonhtmlcommon::row_closure().
                   7775:                &Apache::lonhtmlcommon::row_title($lt{'usr'}).
                   7776:                $srchbysel.
                   7777:                $srchtypesel. 
                   7778:                '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
                   7779:                $srchinsel.
                   7780:                &Apache::lonhtmlcommon::row_closure(1). 
                   7781:                &Apache::lonhtmlcommon::end_pick_box().
                   7782:                '<br />';
1.555     raeburn  7783:     return $output;
                   7784: }
                   7785: 
1.612     raeburn  7786: sub user_rule_check {
1.615     raeburn  7787:     my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612     raeburn  7788:     my $response;
                   7789:     if (ref($usershash) eq 'HASH') {
                   7790:         foreach my $user (keys(%{$usershash})) {
                   7791:             my ($uname,$udom) = split(/:/,$user);
                   7792:             next if ($udom eq '' || $uname eq '');
1.615     raeburn  7793:             my ($id,$newuser);
1.612     raeburn  7794:             if (ref($usershash->{$user}) eq 'HASH') {
1.615     raeburn  7795:                 $newuser = $usershash->{$user}->{'newuser'};
1.612     raeburn  7796:                 $id = $usershash->{$user}->{'id'};
                   7797:             }
                   7798:             my $inst_response;
                   7799:             if (ref($checks) eq 'HASH') {
                   7800:                 if (defined($checks->{'username'})) {
1.615     raeburn  7801:                     ($inst_response,%{$inst_results->{$user}}) = 
1.612     raeburn  7802:                         &Apache::lonnet::get_instuser($udom,$uname);
                   7803:                 } elsif (defined($checks->{'id'})) {
1.615     raeburn  7804:                     ($inst_response,%{$inst_results->{$user}}) =
1.612     raeburn  7805:                         &Apache::lonnet::get_instuser($udom,undef,$id);
                   7806:                 }
1.615     raeburn  7807:             } else {
                   7808:                 ($inst_response,%{$inst_results->{$user}}) =
                   7809:                     &Apache::lonnet::get_instuser($udom,$uname);
                   7810:                 return;
1.612     raeburn  7811:             }
1.615     raeburn  7812:             if (!$got_rules->{$udom}) {
1.612     raeburn  7813:                 my %domconfig = &Apache::lonnet::get_dom('configuration',
                   7814:                                                   ['usercreation'],$udom);
                   7815:                 if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615     raeburn  7816:                     foreach my $item ('username','id') {
1.612     raeburn  7817:                         if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
                   7818:                             $$curr_rules{$udom}{$item} = 
                   7819:                                 $domconfig{'usercreation'}{$item.'_rule'};
1.585     raeburn  7820:                         }
                   7821:                     }
                   7822:                 }
1.615     raeburn  7823:                 $got_rules->{$udom} = 1;  
1.585     raeburn  7824:             }
1.612     raeburn  7825:             foreach my $item (keys(%{$checks})) {
                   7826:                 if (ref($$curr_rules{$udom}) eq 'HASH') {
                   7827:                     if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
                   7828:                         if (@{$$curr_rules{$udom}{$item}} > 0) {
                   7829:                             my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
                   7830:                             foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
                   7831:                                 if ($rule_check{$rule}) {
                   7832:                                     $$rulematch{$user}{$item} = $rule;
                   7833:                                     if ($inst_response eq 'ok') {
1.615     raeburn  7834:                                         if (ref($inst_results) eq 'HASH') {
                   7835:                                             if (ref($inst_results->{$user}) eq 'HASH') {
                   7836:                                                 if (keys(%{$inst_results->{$user}}) == 0) {
                   7837:                                                     $$alerts{$item}{$udom}{$uname} = 1;
                   7838:                                                 }
1.612     raeburn  7839:                                             }
                   7840:                                         }
1.615     raeburn  7841:                                     }
                   7842:                                     last;
1.585     raeburn  7843:                                 }
                   7844:                             }
                   7845:                         }
                   7846:                     }
                   7847:                 }
                   7848:             }
                   7849:         }
                   7850:     }
1.612     raeburn  7851:     return;
                   7852: }
                   7853: 
                   7854: sub user_rule_formats {
                   7855:     my ($domain,$domdesc,$curr_rules,$check) = @_;
                   7856:     my %text = ( 
                   7857:                  'username' => 'Usernames',
                   7858:                  'id'       => 'IDs',
                   7859:                );
                   7860:     my $output;
                   7861:     my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
                   7862:     if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
                   7863:         if (@{$ruleorder} > 0) {
                   7864:             $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>';
                   7865:             foreach my $rule (@{$ruleorder}) {
                   7866:                 if (ref($curr_rules) eq 'ARRAY') {
                   7867:                     if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
                   7868:                         if (ref($rules->{$rule}) eq 'HASH') {
                   7869:                             $output .= '<li>'.$rules->{$rule}{'name'}.': '.
                   7870:                                         $rules->{$rule}{'desc'}.'</li>';
                   7871:                         }
                   7872:                     }
                   7873:                 }
                   7874:             }
                   7875:             $output .= '</ul>';
                   7876:         }
                   7877:     }
                   7878:     return $output;
                   7879: }
                   7880: 
                   7881: sub instrule_disallow_msg {
1.615     raeburn  7882:     my ($checkitem,$domdesc,$count,$mode) = @_;
1.612     raeburn  7883:     my $response;
                   7884:     my %text = (
                   7885:                   item   => 'username',
                   7886:                   items  => 'usernames',
                   7887:                   match  => 'matches',
                   7888:                   do     => 'does',
                   7889:                   action => 'a username',
                   7890:                   one    => 'one',
                   7891:                );
                   7892:     if ($count > 1) {
                   7893:         $text{'item'} = 'usernames';
                   7894:         $text{'match'} ='match';
                   7895:         $text{'do'} = 'do';
                   7896:         $text{'action'} = 'usernames',
                   7897:         $text{'one'} = 'ones';
                   7898:     }
                   7899:     if ($checkitem eq 'id') {
                   7900:         $text{'items'} = 'IDs';
                   7901:         $text{'item'} = 'ID';
                   7902:         $text{'action'} = 'an ID';
1.615     raeburn  7903:         if ($count > 1) {
                   7904:             $text{'item'} = 'IDs';
                   7905:             $text{'action'} = 'IDs';
                   7906:         }
1.612     raeburn  7907:     }
1.674     bisitz   7908:     $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  7909:     if ($mode eq 'upload') {
                   7910:         if ($checkitem eq 'username') {
                   7911:             $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'}.");
                   7912:         } elsif ($checkitem eq 'id') {
1.674     bisitz   7913:             $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  7914:         }
1.669     raeburn  7915:     } elsif ($mode eq 'selfcreate') {
                   7916:         if ($checkitem eq 'id') {
                   7917:             $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.");
                   7918:         }
1.615     raeburn  7919:     } else {
                   7920:         if ($checkitem eq 'username') {
                   7921:             $response .= &mt("You must choose $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
                   7922:         } elsif ($checkitem eq 'id') {
                   7923:             $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.");
                   7924:         }
1.612     raeburn  7925:     }
                   7926:     return $response;
1.585     raeburn  7927: }
                   7928: 
1.624     raeburn  7929: sub personal_data_fieldtitles {
                   7930:     my %fieldtitles = &Apache::lonlocal::texthash (
                   7931:                         id => 'Student/Employee ID',
                   7932:                         permanentemail => 'E-mail address',
                   7933:                         lastname => 'Last Name',
                   7934:                         firstname => 'First Name',
                   7935:                         middlename => 'Middle Name',
                   7936:                         generation => 'Generation',
                   7937:                         gen => 'Generation',
1.765     raeburn  7938:                         inststatus => 'Affiliation',
1.624     raeburn  7939:                    );
                   7940:     return %fieldtitles;
                   7941: }
                   7942: 
1.642     raeburn  7943: sub sorted_inst_types {
                   7944:     my ($dom) = @_;
                   7945:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
                   7946:     my $othertitle = &mt('All users');
                   7947:     if ($env{'request.course.id'}) {
1.668     raeburn  7948:         $othertitle  = &mt('Any users');
1.642     raeburn  7949:     }
                   7950:     my @types;
                   7951:     if (ref($order) eq 'ARRAY') {
                   7952:         @types = @{$order};
                   7953:     }
                   7954:     if (@types == 0) {
                   7955:         if (ref($usertypes) eq 'HASH') {
                   7956:             @types = sort(keys(%{$usertypes}));
                   7957:         }
                   7958:     }
                   7959:     if (keys(%{$usertypes}) > 0) {
                   7960:         $othertitle = &mt('Other users');
                   7961:     }
                   7962:     return ($othertitle,$usertypes,\@types);
                   7963: }
                   7964: 
1.645     raeburn  7965: sub get_institutional_codes {
                   7966:     my ($settings,$allcourses,$LC_code) = @_;
                   7967: # Get complete list of course sections to update
                   7968:     my @currsections = ();
                   7969:     my @currxlists = ();
                   7970:     my $coursecode = $$settings{'internal.coursecode'};
                   7971: 
                   7972:     if ($$settings{'internal.sectionnums'} ne '') {
                   7973:         @currsections = split(/,/,$$settings{'internal.sectionnums'});
                   7974:     }
                   7975: 
                   7976:     if ($$settings{'internal.crosslistings'} ne '') {
                   7977:         @currxlists = split(/,/,$$settings{'internal.crosslistings'});
                   7978:     }
                   7979: 
                   7980:     if (@currxlists > 0) {
                   7981:         foreach (@currxlists) {
                   7982:             if (m/^([^:]+):(\w*)$/) {
                   7983:                 unless (grep/^$1$/,@{$allcourses}) {
                   7984:                     push @{$allcourses},$1;
                   7985:                     $$LC_code{$1} = $2;
                   7986:                 }
                   7987:             }
                   7988:         }
                   7989:     }
                   7990:  
                   7991:     if (@currsections > 0) {
                   7992:         foreach (@currsections) {
                   7993:             if (m/^(\w+):(\w*)$/) {
                   7994:                 my $sec = $coursecode.$1;
                   7995:                 my $lc_sec = $2;
                   7996:                 unless (grep/^$sec$/,@{$allcourses}) {
                   7997:                     push @{$allcourses},$sec;
                   7998:                     $$LC_code{$sec} = $lc_sec;
                   7999:                 }
                   8000:             }
                   8001:         }
                   8002:     }
                   8003:     return;
                   8004: }
                   8005: 
1.112     bowersj2 8006: =pod
                   8007: 
1.780     raeburn  8008: =head1 Slot Helpers
                   8009: 
                   8010: =over 4
                   8011: 
                   8012: =item * sorted_slots()
                   8013: 
                   8014: Sorts an array of slot names in order of slot start time (earliest first). 
                   8015: 
                   8016: Inputs:
                   8017: 
                   8018: =over 4
                   8019: 
                   8020: slotsarr  - Reference to array of unsorted slot names.
                   8021: 
                   8022: slots     - Reference to hash of hash, where outer hash keys are slot names.
                   8023: 
1.549     albertel 8024: =back
                   8025: 
1.780     raeburn  8026: Returns:
                   8027: 
                   8028: =over 4
                   8029: 
                   8030: sorted   - An array of slot names sorted by the start time of the slot.
                   8031: 
                   8032: =back
                   8033: 
                   8034: =back
                   8035: 
                   8036: =cut
                   8037: 
                   8038: 
                   8039: sub sorted_slots {
                   8040:     my ($slotsarr,$slots) = @_;
                   8041:     my @sorted;
                   8042:     if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
                   8043:         @sorted =
                   8044:             sort {
                   8045:                      if (ref($slots->{$a}) && ref($slots->{$b})) {
                   8046:                          return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
                   8047:                      }
                   8048:                      if (ref($slots->{$a})) { return -1;}
                   8049:                      if (ref($slots->{$b})) { return 1;}
                   8050:                      return 0;
                   8051:                  } @{$slotsarr};
                   8052:     }
                   8053:     return @sorted;
                   8054: }
                   8055: 
                   8056: 
                   8057: =pod
                   8058: 
1.549     albertel 8059: =head1 HTTP Helpers
                   8060: 
                   8061: =over 4
                   8062: 
1.648     raeburn  8063: =item * &get_unprocessed_cgi($query,$possible_names)
1.112     bowersj2 8064: 
1.258     albertel 8065: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112     bowersj2 8066: $query.  The parameters listed in $possible_names (an array reference),
1.258     albertel 8067: will be set in $env{'form.name'} if they do not already exist.
1.112     bowersj2 8068: 
                   8069: Typically called with $ENV{'QUERY_STRING'} as the first parameter.  
                   8070: $possible_names is an ref to an array of form element names.  As an example:
                   8071: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258     albertel 8072: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112     bowersj2 8073: 
                   8074: =cut
1.1       albertel 8075: 
1.6       albertel 8076: sub get_unprocessed_cgi {
1.25      albertel 8077:   my ($query,$possible_names)= @_;
1.26      matthew  8078:   # $Apache::lonxml::debug=1;
1.356     albertel 8079:   foreach my $pair (split(/&/,$query)) {
                   8080:     my ($name, $value) = split(/=/,$pair);
1.369     www      8081:     $name = &unescape($name);
1.25      albertel 8082:     if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
                   8083:       $value =~ tr/+/ /;
                   8084:       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258     albertel 8085:       unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25      albertel 8086:     }
1.16      harris41 8087:   }
1.6       albertel 8088: }
                   8089: 
1.112     bowersj2 8090: =pod
                   8091: 
1.648     raeburn  8092: =item * &cacheheader() 
1.112     bowersj2 8093: 
                   8094: returns cache-controlling header code
                   8095: 
                   8096: =cut
                   8097: 
1.7       albertel 8098: sub cacheheader {
1.258     albertel 8099:     unless ($env{'request.method'} eq 'GET') { return ''; }
1.216     albertel 8100:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
                   8101:     my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7       albertel 8102:                 <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
                   8103:                 <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216     albertel 8104:     return $output;
1.7       albertel 8105: }
                   8106: 
1.112     bowersj2 8107: =pod
                   8108: 
1.648     raeburn  8109: =item * &no_cache($r) 
1.112     bowersj2 8110: 
                   8111: specifies header code to not have cache
                   8112: 
                   8113: =cut
                   8114: 
1.9       albertel 8115: sub no_cache {
1.216     albertel 8116:     my ($r) = @_;
                   8117:     if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258     albertel 8118: 	$env{'request.method'} ne 'GET') { return ''; }
1.216     albertel 8119:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
                   8120:     $r->no_cache(1);
                   8121:     $r->header_out("Expires" => $date);
                   8122:     $r->header_out("Pragma" => "no-cache");
1.123     www      8123: }
                   8124: 
                   8125: sub content_type {
1.181     albertel 8126:     my ($r,$type,$charset) = @_;
1.299     foxr     8127:     if ($r) {
                   8128: 	#  Note that printout.pl calls this with undef for $r.
                   8129: 	&no_cache($r);
                   8130:     }
1.258     albertel 8131:     if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181     albertel 8132:     unless ($charset) {
                   8133: 	$charset=&Apache::lonlocal::current_encoding;
                   8134:     }
                   8135:     if ($charset) { $type.='; charset='.$charset; }
                   8136:     if ($r) {
                   8137: 	$r->content_type($type);
                   8138:     } else {
                   8139: 	print("Content-type: $type\n\n");
                   8140:     }
1.9       albertel 8141: }
1.25      albertel 8142: 
1.112     bowersj2 8143: =pod
                   8144: 
1.648     raeburn  8145: =item * &add_to_env($name,$value) 
1.112     bowersj2 8146: 
1.258     albertel 8147: adds $name to the %env hash with value
1.112     bowersj2 8148: $value, if $name already exists, the entry is converted to an array
                   8149: reference and $value is added to the array.
                   8150: 
                   8151: =cut
                   8152: 
1.25      albertel 8153: sub add_to_env {
                   8154:   my ($name,$value)=@_;
1.258     albertel 8155:   if (defined($env{$name})) {
                   8156:     if (ref($env{$name})) {
1.25      albertel 8157:       #already have multiple values
1.258     albertel 8158:       push(@{ $env{$name} },$value);
1.25      albertel 8159:     } else {
                   8160:       #first time seeing multiple values, convert hash entry to an arrayref
1.258     albertel 8161:       my $first=$env{$name};
                   8162:       undef($env{$name});
                   8163:       push(@{ $env{$name} },$first,$value);
1.25      albertel 8164:     }
                   8165:   } else {
1.258     albertel 8166:     $env{$name}=$value;
1.25      albertel 8167:   }
1.31      albertel 8168: }
1.149     albertel 8169: 
                   8170: =pod
                   8171: 
1.648     raeburn  8172: =item * &get_env_multiple($name) 
1.149     albertel 8173: 
1.258     albertel 8174: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149     albertel 8175: values may be defined and end up as an array ref.
                   8176: 
                   8177: returns an array of values
                   8178: 
                   8179: =cut
                   8180: 
                   8181: sub get_env_multiple {
                   8182:     my ($name) = @_;
                   8183:     my @values;
1.258     albertel 8184:     if (defined($env{$name})) {
1.149     albertel 8185:         # exists is it an array
1.258     albertel 8186:         if (ref($env{$name})) {
                   8187:             @values=@{ $env{$name} };
1.149     albertel 8188:         } else {
1.258     albertel 8189:             $values[0]=$env{$name};
1.149     albertel 8190:         }
                   8191:     }
                   8192:     return(@values);
                   8193: }
                   8194: 
1.660     raeburn  8195: sub ask_for_embedded_content {
                   8196:     my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
                   8197:     my $upload_output = '
                   8198:    <form name="upload_embedded" action="'.$actionurl.'"
                   8199:                   method="post" enctype="multipart/form-data">';
                   8200:     $upload_output .= $state;
1.661     raeburn  8201:     $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660     raeburn  8202: 
                   8203:     my $num = 0;
                   8204:     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
                   8205:         $upload_output .= &start_data_table_row().
                   8206:             '<td>'.$embed_file.'</td><td>';
                   8207:         if ($args->{'ignore_remote_references'}
                   8208:             && $embed_file =~ m{^\w+://}) {
                   8209:             $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
                   8210:         } elsif ($args->{'error_on_invalid_names'}
                   8211:             && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
                   8212: 
                   8213:             $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
                   8214: 
                   8215:         } else {
                   8216:             $upload_output .='
1.661     raeburn  8217:            <input name="embedded_item_'.$num.'" type="file" value="" />
1.660     raeburn  8218:            <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
                   8219:             my $attrib = join(':',@{$$allfiles{$embed_file}});
                   8220:             $upload_output .=
                   8221:                 "\n\t\t".
                   8222:                 '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
                   8223:                 $attrib.'" />';
                   8224:             if (exists($$codebase{$embed_file})) {
                   8225:                 $upload_output .=
                   8226:                     "\n\t\t".
                   8227:                     '<input name="codebase_'.$num.'" type="hidden" value="'.
                   8228:                     &escape($$codebase{$embed_file}).'" />';
                   8229:             }
                   8230:         }
                   8231:         $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
                   8232:         $num++;
                   8233:     }
                   8234:     $upload_output .= &Apache::loncommon::end_data_table().'<br />
                   8235:    <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
                   8236:    <input type ="submit" value="'.&mt('Upload Listed Files').'" />
                   8237:    '.&mt('(only files for which a location has been provided will be uploaded)').'
                   8238:    </form>';
                   8239:     return $upload_output;
                   8240: }
                   8241: 
1.661     raeburn  8242: sub upload_embedded {
                   8243:     my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
                   8244:         $current_disk_usage) = @_;
                   8245:     my $output;
                   8246:     for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
                   8247:         next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
                   8248:         my $orig_uploaded_filename =
                   8249:             $env{'form.embedded_item_'.$i.'.filename'};
                   8250: 
                   8251:         $env{'form.embedded_orig_'.$i} =
                   8252:             &unescape($env{'form.embedded_orig_'.$i});
                   8253:         my ($path,$fname) =
                   8254:             ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
                   8255:         # no path, whole string is fname
                   8256:         if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
                   8257: 
                   8258:         $path = $env{'form.currentpath'}.$path;
                   8259:         $fname = &Apache::lonnet::clean_filename($fname);
                   8260:         # See if there is anything left
                   8261:         next if ($fname eq '');
                   8262: 
                   8263:         # Check if file already exists as a file or directory.
                   8264:         my ($state,$msg);
                   8265:         if ($context eq 'portfolio') {
                   8266:             my $port_path = $dirpath;
                   8267:             if ($group ne '') {
                   8268:                 $port_path = "groups/$group/$port_path";
                   8269:             }
                   8270:             ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
                   8271:                                               $dir_root,$port_path,$disk_quota,
                   8272:                                               $current_disk_usage,$uname,$udom);
                   8273:             if ($state eq 'will_exceed_quota'
                   8274:                 || $state eq 'file_locked'
                   8275:                 || $state eq 'file_exists' ) {
                   8276:                 $output .= $msg;
                   8277:                 next;
                   8278:             }
                   8279:         } elsif (($context eq 'author') || ($context eq 'testbank')) {
                   8280:             ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
                   8281:             if ($state eq 'exists') {
                   8282:                 $output .= $msg;
                   8283:                 next;
                   8284:             }
                   8285:         }
                   8286:         # Check if extension is valid
                   8287:         if (($fname =~ /\.(\w+)$/) &&
                   8288:             (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   8289:             $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
                   8290:             next;
                   8291:         } elsif (($fname =~ /\.(\w+)$/) &&
                   8292:                  (!defined(&Apache::loncommon::fileembstyle($1)))) {
                   8293:             $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   8294:             next;
                   8295:         } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
                   8296:             $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
                   8297:             next;
                   8298:         }
                   8299: 
                   8300:         $env{'form.embedded_item_'.$i.'.filename'}=$fname;
                   8301:         if ($context eq 'portfolio') {
                   8302:             my $result=
                   8303:                 &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
                   8304:                                                 $dirpath.$path);
                   8305:             if ($result !~ m|^/uploaded/|) {
                   8306:                 $output .= '<span class="LC_error">'
                   8307:                       .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
                   8308:                            ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
                   8309:                       .'</span><br />';
                   8310:                 next;
                   8311:             } else {
                   8312:                 $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
                   8313:                            $path.$fname.'</span>').'</p>';     
                   8314:             }
                   8315:         } else {
                   8316: # Save the file
                   8317:             my $target = $env{'form.embedded_item_'.$i};
                   8318:             my $fullpath = $dir_root.$dirpath.'/'.$path;
                   8319:             my $dest = $fullpath.$fname;
                   8320:             my $url = $url_root.$dirpath.'/'.$path.$fname;
                   8321:             my @parts=split(/\//,$fullpath);
                   8322:             my $count;
                   8323:             my $filepath = $dir_root;
                   8324:             for ($count=4;$count<=$#parts;$count++) {
                   8325:                 $filepath .= "/$parts[$count]";
                   8326:                 if ((-e $filepath)!=1) {
                   8327:                     mkdir($filepath,0770);
                   8328:                 }
                   8329:             }
                   8330:             my $fh;
                   8331:             if (!open($fh,'>'.$dest)) {
                   8332:                 &Apache::lonnet::logthis('Failed to create '.$dest);
                   8333:                 $output .= '<span class="LC_error">'.
                   8334:                            &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   8335:                            '</span><br />';
                   8336:             } else {
                   8337:                 if (!print $fh $env{'form.embedded_item_'.$i}) {
                   8338:                     &Apache::lonnet::logthis('Failed to write to '.$dest);
                   8339:                     $output .= '<span class="LC_error">'.
                   8340:                               &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   8341:                               '</span><br />';
                   8342:                 } else {
                   8343:                     if ($context eq 'testbank') {
                   8344:                         $output .= &mt('Embedded file uploaded successfully:').
                   8345:                                    '&nbsp;<a href="'.$url.'">'.
                   8346:                                    $orig_uploaded_filename.'</a><br />';
                   8347:                     } else {
1.705     tempelho 8348:                         $output .= '<span class=\"LC_fontsize_large\">'.
1.661     raeburn  8349:                                    &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705     tempelho 8350:                                    $orig_uploaded_filename.'</a>').'</span><br />';
1.661     raeburn  8351:                     }
                   8352:                 }
                   8353:                 close($fh);
                   8354:             }
                   8355:         }
                   8356:     }
                   8357:     return $output;
                   8358: }
                   8359: 
                   8360: sub check_for_existing {
                   8361:     my ($path,$fname,$element) = @_;
                   8362:     my ($state,$msg);
                   8363:     if (-d $path.'/'.$fname) {
                   8364:         $state = 'exists';
                   8365:         $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   8366:     } elsif (-e $path.'/'.$fname) {
                   8367:         $state = 'exists';
                   8368:         $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   8369:     }
                   8370:     if ($state eq 'exists') {
                   8371:         $msg = '<span class="LC_error">'.$msg.'</span><br />';
                   8372:     }
                   8373:     return ($state,$msg);
                   8374: }
                   8375: 
                   8376: sub check_for_upload {
                   8377:     my ($path,$fname,$group,$element,$portfolio_root,$port_path,
                   8378:         $disk_quota,$current_disk_usage,$uname,$udom) = @_;
                   8379:     my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
                   8380:     my $getpropath = 1;
                   8381:     my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
                   8382:                                             $getpropath);
                   8383:     my $found_file = 0;
                   8384:     my $locked_file = 0;
                   8385:     foreach my $line (@dir_list) {
                   8386:         my ($file_name)=split(/\&/,$line,2);
                   8387:         if ($file_name eq $fname){
                   8388:             $file_name = $path.$file_name;
                   8389:             if ($group ne '') {
                   8390:                 $file_name = $group.$file_name;
                   8391:             }
                   8392:             $found_file = 1;
                   8393:             if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
                   8394:                 $locked_file = 1;
                   8395:             }
                   8396:         }
                   8397:     }
                   8398:     if (($current_disk_usage + $filesize) > $disk_quota){
                   8399:         my $msg = '<span class="LC_error">'.
                   8400:                 &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
                   8401:                   '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
                   8402:         return ('will_exceed_quota',$msg);
                   8403:     } elsif ($found_file) {
                   8404:         if ($locked_file) {
                   8405:             my $msg = '<span class="LC_error">';
                   8406:             $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>');
                   8407:             $msg .= '</span><br />';
                   8408:             $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
                   8409:             return ('file_locked',$msg);
                   8410:         } else {
                   8411:             my $msg = '<span class="LC_error">';
                   8412:             $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'});
                   8413:             $msg .= '</span>';
                   8414:             $msg .= '<br />';
                   8415:             $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
                   8416:             return ('file_exists',$msg);
                   8417:         }
                   8418:     }
                   8419: }
                   8420: 
1.31      albertel 8421: 
1.41      ng       8422: =pod
1.45      matthew  8423: 
1.464     albertel 8424: =back
1.41      ng       8425: 
1.112     bowersj2 8426: =head1 CSV Upload/Handling functions
1.38      albertel 8427: 
1.41      ng       8428: =over 4
                   8429: 
1.648     raeburn  8430: =item * &upfile_store($r)
1.41      ng       8431: 
                   8432: Store uploaded file, $r should be the HTTP Request object,
1.258     albertel 8433: needs $env{'form.upfile'}
1.41      ng       8434: returns $datatoken to be put into hidden field
                   8435: 
                   8436: =cut
1.31      albertel 8437: 
                   8438: sub upfile_store {
                   8439:     my $r=shift;
1.258     albertel 8440:     $env{'form.upfile'}=~s/\r/\n/gs;
                   8441:     $env{'form.upfile'}=~s/\f/\n/gs;
                   8442:     $env{'form.upfile'}=~s/\n+/\n/gs;
                   8443:     $env{'form.upfile'}=~s/\n+$//gs;
1.31      albertel 8444: 
1.258     albertel 8445:     my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
                   8446: 	'_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31      albertel 8447:     {
1.158     raeburn  8448:         my $datafile = $r->dir_config('lonDaemons').
                   8449:                            '/tmp/'.$datatoken.'.tmp';
                   8450:         if ( open(my $fh,">$datafile") ) {
1.258     albertel 8451:             print $fh $env{'form.upfile'};
1.158     raeburn  8452:             close($fh);
                   8453:         }
1.31      albertel 8454:     }
                   8455:     return $datatoken;
                   8456: }
                   8457: 
1.56      matthew  8458: =pod
                   8459: 
1.648     raeburn  8460: =item * &load_tmp_file($r)
1.41      ng       8461: 
                   8462: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258     albertel 8463: needs $env{'form.datatoken'},
                   8464: sets $env{'form.upfile'} to the contents of the file
1.41      ng       8465: 
                   8466: =cut
1.31      albertel 8467: 
                   8468: sub load_tmp_file {
                   8469:     my $r=shift;
                   8470:     my @studentdata=();
                   8471:     {
1.158     raeburn  8472:         my $studentfile = $r->dir_config('lonDaemons').
1.258     albertel 8473:                               '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158     raeburn  8474:         if ( open(my $fh,"<$studentfile") ) {
                   8475:             @studentdata=<$fh>;
                   8476:             close($fh);
                   8477:         }
1.31      albertel 8478:     }
1.258     albertel 8479:     $env{'form.upfile'}=join('',@studentdata);
1.31      albertel 8480: }
                   8481: 
1.56      matthew  8482: =pod
                   8483: 
1.648     raeburn  8484: =item * &upfile_record_sep()
1.41      ng       8485: 
                   8486: Separate uploaded file into records
                   8487: returns array of records,
1.258     albertel 8488: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41      ng       8489: 
                   8490: =cut
1.31      albertel 8491: 
                   8492: sub upfile_record_sep {
1.258     albertel 8493:     if ($env{'form.upfiletype'} eq 'xml') {
1.31      albertel 8494:     } else {
1.248     albertel 8495: 	my @records;
1.258     albertel 8496: 	foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248     albertel 8497: 	    if ($line=~/^\s*$/) { next; }
                   8498: 	    push(@records,$line);
                   8499: 	}
                   8500: 	return @records;
1.31      albertel 8501:     }
                   8502: }
                   8503: 
1.56      matthew  8504: =pod
                   8505: 
1.648     raeburn  8506: =item * &record_sep($record)
1.41      ng       8507: 
1.258     albertel 8508: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41      ng       8509: 
                   8510: =cut
                   8511: 
1.263     www      8512: sub takeleft {
                   8513:     my $index=shift;
                   8514:     return substr('0000'.$index,-4,4);
                   8515: }
                   8516: 
1.31      albertel 8517: sub record_sep {
                   8518:     my $record=shift;
                   8519:     my %components=();
1.258     albertel 8520:     if ($env{'form.upfiletype'} eq 'xml') {
                   8521:     } elsif ($env{'form.upfiletype'} eq 'space') {
1.31      albertel 8522:         my $i=0;
1.356     albertel 8523:         foreach my $field (split(/\s+/,$record)) {
1.31      albertel 8524:             $field=~s/^(\"|\')//;
                   8525:             $field=~s/(\"|\')$//;
1.263     www      8526:             $components{&takeleft($i)}=$field;
1.31      albertel 8527:             $i++;
                   8528:         }
1.258     albertel 8529:     } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31      albertel 8530:         my $i=0;
1.356     albertel 8531:         foreach my $field (split(/\t/,$record)) {
1.31      albertel 8532:             $field=~s/^(\"|\')//;
                   8533:             $field=~s/(\"|\')$//;
1.263     www      8534:             $components{&takeleft($i)}=$field;
1.31      albertel 8535:             $i++;
                   8536:         }
                   8537:     } else {
1.561     www      8538:         my $separator=',';
1.480     banghart 8539:         if ($env{'form.upfiletype'} eq 'semisv') {
1.561     www      8540:             $separator=';';
1.480     banghart 8541:         }
1.31      albertel 8542:         my $i=0;
1.561     www      8543: # the character we are looking for to indicate the end of a quote or a record 
                   8544:         my $looking_for=$separator;
                   8545: # do not add the characters to the fields
                   8546:         my $ignore=0;
                   8547: # we just encountered a separator (or the beginning of the record)
                   8548:         my $just_found_separator=1;
                   8549: # store the field we are working on here
                   8550:         my $field='';
                   8551: # work our way through all characters in record
                   8552:         foreach my $character ($record=~/(.)/g) {
                   8553:             if ($character eq $looking_for) {
                   8554:                if ($character ne $separator) {
                   8555: # Found the end of a quote, again looking for separator
                   8556:                   $looking_for=$separator;
                   8557:                   $ignore=1;
                   8558:                } else {
                   8559: # Found a separator, store away what we got
                   8560:                   $components{&takeleft($i)}=$field;
                   8561: 	          $i++;
                   8562:                   $just_found_separator=1;
                   8563:                   $ignore=0;
                   8564:                   $field='';
                   8565:                }
                   8566:                next;
                   8567:             }
                   8568: # single or double quotation marks after a separator indicate beginning of a quote
                   8569: # we are now looking for the end of the quote and need to ignore separators
                   8570:             if ((($character eq '"') || ($character eq "'")) && ($just_found_separator))  {
                   8571:                $looking_for=$character;
                   8572:                next;
                   8573:             }
                   8574: # ignore would be true after we reached the end of a quote
                   8575:             if ($ignore) { next; }
                   8576:             if (($just_found_separator) && ($character=~/\s/)) { next; }
                   8577:             $field.=$character;
                   8578:             $just_found_separator=0; 
1.31      albertel 8579:         }
1.561     www      8580: # catch the very last entry, since we never encountered the separator
                   8581:         $components{&takeleft($i)}=$field;
1.31      albertel 8582:     }
                   8583:     return %components;
                   8584: }
                   8585: 
1.144     matthew  8586: ######################################################
                   8587: ######################################################
                   8588: 
1.56      matthew  8589: =pod
                   8590: 
1.648     raeburn  8591: =item * &upfile_select_html()
1.41      ng       8592: 
1.144     matthew  8593: Return HTML code to select a file from the users machine and specify 
                   8594: the file type.
1.41      ng       8595: 
                   8596: =cut
                   8597: 
1.144     matthew  8598: ######################################################
                   8599: ######################################################
1.31      albertel 8600: sub upfile_select_html {
1.144     matthew  8601:     my %Types = (
                   8602:                  csv   => &mt('CSV (comma separated values, spreadsheet)'),
1.480     banghart 8603:                  semisv => &mt('Semicolon separated values'),
1.144     matthew  8604:                  space => &mt('Space separated'),
                   8605:                  tab   => &mt('Tabulator separated'),
                   8606: #                 xml   => &mt('HTML/XML'),
                   8607:                  );
                   8608:     my $Str = '<input type="file" name="upfile" size="50" />'.
1.727     riegler  8609:         '<br />'.&mt('Type').': <select name="upfiletype">';
1.144     matthew  8610:     foreach my $type (sort(keys(%Types))) {
                   8611:         $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
                   8612:     }
                   8613:     $Str .= "</select>\n";
                   8614:     return $Str;
1.31      albertel 8615: }
                   8616: 
1.301     albertel 8617: sub get_samples {
                   8618:     my ($records,$toget) = @_;
                   8619:     my @samples=({});
                   8620:     my $got=0;
                   8621:     foreach my $rec (@$records) {
                   8622: 	my %temp = &record_sep($rec);
                   8623: 	if (! grep(/\S/, values(%temp))) { next; }
                   8624: 	if (%temp) {
                   8625: 	    $samples[$got]=\%temp;
                   8626: 	    $got++;
                   8627: 	    if ($got == $toget) { last; }
                   8628: 	}
                   8629:     }
                   8630:     return \@samples;
                   8631: }
                   8632: 
1.144     matthew  8633: ######################################################
                   8634: ######################################################
                   8635: 
1.56      matthew  8636: =pod
                   8637: 
1.648     raeburn  8638: =item * &csv_print_samples($r,$records)
1.41      ng       8639: 
                   8640: Prints a table of sample values from each column uploaded $r is an
                   8641: Apache Request ref, $records is an arrayref from
                   8642: &Apache::loncommon::upfile_record_sep
                   8643: 
                   8644: =cut
                   8645: 
1.144     matthew  8646: ######################################################
                   8647: ######################################################
1.31      albertel 8648: sub csv_print_samples {
                   8649:     my ($r,$records) = @_;
1.662     bisitz   8650:     my $samples = &get_samples($records,5);
1.301     albertel 8651: 
1.594     raeburn  8652:     $r->print(&mt('Samples').'<br />'.&start_data_table().
                   8653:               &start_data_table_header_row());
1.356     albertel 8654:     foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) { 
1.845     bisitz   8655:         $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594     raeburn  8656:     $r->print(&end_data_table_header_row());
1.301     albertel 8657:     foreach my $hash (@$samples) {
1.594     raeburn  8658: 	$r->print(&start_data_table_row());
1.356     albertel 8659: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31      albertel 8660: 	    $r->print('<td>');
1.356     albertel 8661: 	    if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31      albertel 8662: 	    $r->print('</td>');
                   8663: 	}
1.594     raeburn  8664: 	$r->print(&end_data_table_row());
1.31      albertel 8665:     }
1.594     raeburn  8666:     $r->print(&end_data_table().'<br />'."\n");
1.31      albertel 8667: }
                   8668: 
1.144     matthew  8669: ######################################################
                   8670: ######################################################
                   8671: 
1.56      matthew  8672: =pod
                   8673: 
1.648     raeburn  8674: =item * &csv_print_select_table($r,$records,$d)
1.41      ng       8675: 
                   8676: Prints a table to create associations between values and table columns.
1.144     matthew  8677: 
1.41      ng       8678: $r is an Apache Request ref,
                   8679: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174     matthew  8680: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41      ng       8681: 
                   8682: =cut
                   8683: 
1.144     matthew  8684: ######################################################
                   8685: ######################################################
1.31      albertel 8686: sub csv_print_select_table {
                   8687:     my ($r,$records,$d) = @_;
1.301     albertel 8688:     my $i=0;
                   8689:     my $samples = &get_samples($records,1);
1.144     matthew  8690:     $r->print(&mt('Associate columns with student attributes.')."\n".
1.594     raeburn  8691: 	      &start_data_table().&start_data_table_header_row().
1.144     matthew  8692:               '<th>'.&mt('Attribute').'</th>'.
1.594     raeburn  8693:               '<th>'.&mt('Column').'</th>'.
                   8694:               &end_data_table_header_row()."\n");
1.356     albertel 8695:     foreach my $array_ref (@$d) {
                   8696: 	my ($value,$display,$defaultcol)=@{ $array_ref };
1.729     raeburn  8697: 	$r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31      albertel 8698: 
1.875     bisitz   8699: 	$r->print('<td><select name="f'.$i.'"'.
1.32      matthew  8700: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.31      albertel 8701: 	$r->print('<option value="none"></option>');
1.356     albertel 8702: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
                   8703: 	    $r->print('<option value="'.$sample.'"'.
                   8704:                       ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662     bisitz   8705:                       '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31      albertel 8706: 	}
1.594     raeburn  8707: 	$r->print('</select></td>'.&end_data_table_row()."\n");
1.31      albertel 8708: 	$i++;
                   8709:     }
1.594     raeburn  8710:     $r->print(&end_data_table());
1.31      albertel 8711:     $i--;
                   8712:     return $i;
                   8713: }
1.56      matthew  8714: 
1.144     matthew  8715: ######################################################
                   8716: ######################################################
                   8717: 
1.56      matthew  8718: =pod
1.31      albertel 8719: 
1.648     raeburn  8720: =item * &csv_samples_select_table($r,$records,$d)
1.41      ng       8721: 
                   8722: Prints a table of sample values from the upload and can make associate samples to internal names.
                   8723: 
                   8724: $r is an Apache Request ref,
                   8725: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
                   8726: $d is an array of 2 element arrays (internal name, displayed name)
                   8727: 
                   8728: =cut
                   8729: 
1.144     matthew  8730: ######################################################
                   8731: ######################################################
1.31      albertel 8732: sub csv_samples_select_table {
                   8733:     my ($r,$records,$d) = @_;
                   8734:     my $i=0;
1.144     matthew  8735:     #
1.662     bisitz   8736:     my $max_samples = 5;
                   8737:     my $samples = &get_samples($records,$max_samples);
1.594     raeburn  8738:     $r->print(&start_data_table().
                   8739:               &start_data_table_header_row().'<th>'.
                   8740:               &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
                   8741:               &end_data_table_header_row());
1.301     albertel 8742: 
                   8743:     foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594     raeburn  8744: 	$r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32      matthew  8745: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.301     albertel 8746: 	foreach my $option (@$d) {
                   8747: 	    my ($value,$display,$defaultcol)=@{ $option };
1.174     matthew  8748: 	    $r->print('<option value="'.$value.'"'.
1.253     albertel 8749:                       ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174     matthew  8750:                       $display.'</option>');
1.31      albertel 8751: 	}
                   8752: 	$r->print('</select></td><td>');
1.662     bisitz   8753: 	foreach my $line (0..($max_samples-1)) {
1.301     albertel 8754: 	    if (defined($samples->[$line]{$key})) { 
                   8755: 		$r->print($samples->[$line]{$key}."<br />\n"); 
                   8756: 	    }
                   8757: 	}
1.594     raeburn  8758: 	$r->print('</td>'.&end_data_table_row());
1.31      albertel 8759: 	$i++;
                   8760:     }
1.594     raeburn  8761:     $r->print(&end_data_table());
1.31      albertel 8762:     $i--;
                   8763:     return($i);
1.115     matthew  8764: }
                   8765: 
1.144     matthew  8766: ######################################################
                   8767: ######################################################
                   8768: 
1.115     matthew  8769: =pod
                   8770: 
1.648     raeburn  8771: =item * &clean_excel_name($name)
1.115     matthew  8772: 
                   8773: Returns a replacement for $name which does not contain any illegal characters.
                   8774: 
                   8775: =cut
                   8776: 
1.144     matthew  8777: ######################################################
                   8778: ######################################################
1.115     matthew  8779: sub clean_excel_name {
                   8780:     my ($name) = @_;
                   8781:     $name =~ s/[:\*\?\/\\]//g;
                   8782:     if (length($name) > 31) {
                   8783:         $name = substr($name,0,31);
                   8784:     }
                   8785:     return $name;
1.25      albertel 8786: }
1.84      albertel 8787: 
1.85      albertel 8788: =pod
                   8789: 
1.648     raeburn  8790: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85      albertel 8791: 
                   8792: Returns either 1 or undef
                   8793: 
                   8794: 1 if the part is to be hidden, undef if it is to be shown
                   8795: 
                   8796: Arguments are:
                   8797: 
                   8798: $id the id of the part to be checked
                   8799: $symb, optional the symb of the resource to check
                   8800: $udom, optional the domain of the user to check for
                   8801: $uname, optional the username of the user to check for
                   8802: 
                   8803: =cut
1.84      albertel 8804: 
                   8805: sub check_if_partid_hidden {
                   8806:     my ($id,$symb,$udom,$uname) = @_;
1.133     albertel 8807:     my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84      albertel 8808: 					 $symb,$udom,$uname);
1.141     albertel 8809:     my $truth=1;
                   8810:     #if the string starts with !, then the list is the list to show not hide
                   8811:     if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84      albertel 8812:     my @hiddenlist=split(/,/,$hiddenparts);
                   8813:     foreach my $checkid (@hiddenlist) {
1.141     albertel 8814: 	if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84      albertel 8815:     }
1.141     albertel 8816:     return !$truth;
1.84      albertel 8817: }
1.127     matthew  8818: 
1.138     matthew  8819: 
                   8820: ############################################################
                   8821: ############################################################
                   8822: 
                   8823: =pod
                   8824: 
1.157     matthew  8825: =back 
                   8826: 
1.138     matthew  8827: =head1 cgi-bin script and graphing routines
                   8828: 
1.157     matthew  8829: =over 4
                   8830: 
1.648     raeburn  8831: =item * &get_cgi_id()
1.138     matthew  8832: 
                   8833: Inputs: none
                   8834: 
                   8835: Returns an id which can be used to pass environment variables
                   8836: to various cgi-bin scripts.  These environment variables will
                   8837: be removed from the users environment after a given time by
                   8838: the routine &Apache::lonnet::transfer_profile_to_env.
                   8839: 
                   8840: =cut
                   8841: 
                   8842: ############################################################
                   8843: ############################################################
1.152     albertel 8844: my $uniq=0;
1.136     matthew  8845: sub get_cgi_id {
1.154     albertel 8846:     $uniq=($uniq+1)%100000;
1.280     albertel 8847:     return (time.'_'.$$.'_'.$uniq);
1.136     matthew  8848: }
                   8849: 
1.127     matthew  8850: ############################################################
                   8851: ############################################################
                   8852: 
                   8853: =pod
                   8854: 
1.648     raeburn  8855: =item * &DrawBarGraph()
1.127     matthew  8856: 
1.138     matthew  8857: Facilitates the plotting of data in a (stacked) bar graph.
                   8858: Puts plot definition data into the users environment in order for 
                   8859: graph.png to plot it.  Returns an <img> tag for the plot.
                   8860: The bars on the plot are labeled '1','2',...,'n'.
                   8861: 
                   8862: Inputs:
                   8863: 
                   8864: =over 4
                   8865: 
                   8866: =item $Title: string, the title of the plot
                   8867: 
                   8868: =item $xlabel: string, text describing the X-axis of the plot
                   8869: 
                   8870: =item $ylabel: string, text describing the Y-axis of the plot
                   8871: 
                   8872: =item $Max: scalar, the maximum Y value to use in the plot
                   8873: If $Max is < any data point, the graph will not be rendered.
                   8874: 
1.140     matthew  8875: =item $colors: array ref holding the colors to be used for the data sets when
1.138     matthew  8876: they are plotted.  If undefined, default values will be used.
                   8877: 
1.178     matthew  8878: =item $labels: array ref holding the labels to use on the x-axis for the bars.
                   8879: 
1.138     matthew  8880: =item @Values: An array of array references.  Each array reference holds data
                   8881: to be plotted in a stacked bar chart.
                   8882: 
1.239     matthew  8883: =item If the final element of @Values is a hash reference the key/value
                   8884: pairs will be added to the graph definition.
                   8885: 
1.138     matthew  8886: =back
                   8887: 
                   8888: Returns:
                   8889: 
                   8890: An <img> tag which references graph.png and the appropriate identifying
                   8891: information for the plot.
                   8892: 
1.127     matthew  8893: =cut
                   8894: 
                   8895: ############################################################
                   8896: ############################################################
1.134     matthew  8897: sub DrawBarGraph {
1.178     matthew  8898:     my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134     matthew  8899:     #
                   8900:     if (! defined($colors)) {
                   8901:         $colors = ['#33ff00', 
                   8902:                   '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
                   8903:                   '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
                   8904:                   ]; 
                   8905:     }
1.228     matthew  8906:     my $extra_settings = {};
                   8907:     if (ref($Values[-1]) eq 'HASH') {
                   8908:         $extra_settings = pop(@Values);
                   8909:     }
1.127     matthew  8910:     #
1.136     matthew  8911:     my $identifier = &get_cgi_id();
                   8912:     my $id = 'cgi.'.$identifier;        
1.129     matthew  8913:     if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127     matthew  8914:         return '';
                   8915:     }
1.225     matthew  8916:     #
                   8917:     my @Labels;
                   8918:     if (defined($labels)) {
                   8919:         @Labels = @$labels;
                   8920:     } else {
                   8921:         for (my $i=0;$i<@{$Values[0]};$i++) {
                   8922:             push (@Labels,$i+1);
                   8923:         }
                   8924:     }
                   8925:     #
1.129     matthew  8926:     my $NumBars = scalar(@{$Values[0]});
1.225     matthew  8927:     if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129     matthew  8928:     my %ValuesHash;
                   8929:     my $NumSets=1;
                   8930:     foreach my $array (@Values) {
                   8931:         next if (! ref($array));
1.136     matthew  8932:         $ValuesHash{$id.'.data.'.$NumSets++} = 
1.132     matthew  8933:             join(',',@$array);
1.129     matthew  8934:     }
1.127     matthew  8935:     #
1.136     matthew  8936:     my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225     matthew  8937:     if ($NumBars < 3) {
                   8938:         $width = 120+$NumBars*32;
1.220     matthew  8939:         $xskip = 1;
1.225     matthew  8940:         $bar_width = 30;
                   8941:     } elsif ($NumBars < 5) {
                   8942:         $width = 120+$NumBars*20;
                   8943:         $xskip = 1;
                   8944:         $bar_width = 20;
1.220     matthew  8945:     } elsif ($NumBars < 10) {
1.136     matthew  8946:         $width = 120+$NumBars*15;
                   8947:         $xskip = 1;
                   8948:         $bar_width = 15;
                   8949:     } elsif ($NumBars <= 25) {
                   8950:         $width = 120+$NumBars*11;
                   8951:         $xskip = 5;
                   8952:         $bar_width = 8;
                   8953:     } elsif ($NumBars <= 50) {
                   8954:         $width = 120+$NumBars*8;
                   8955:         $xskip = 5;
                   8956:         $bar_width = 4;
                   8957:     } else {
                   8958:         $width = 120+$NumBars*8;
                   8959:         $xskip = 5;
                   8960:         $bar_width = 4;
                   8961:     }
                   8962:     #
1.137     matthew  8963:     $Max = 1 if ($Max < 1);
                   8964:     if ( int($Max) < $Max ) {
                   8965:         $Max++;
                   8966:         $Max = int($Max);
                   8967:     }
1.127     matthew  8968:     $Title  = '' if (! defined($Title));
                   8969:     $xlabel = '' if (! defined($xlabel));
                   8970:     $ylabel = '' if (! defined($ylabel));
1.369     www      8971:     $ValuesHash{$id.'.title'}    = &escape($Title);
                   8972:     $ValuesHash{$id.'.xlabel'}   = &escape($xlabel);
                   8973:     $ValuesHash{$id.'.ylabel'}   = &escape($ylabel);
1.137     matthew  8974:     $ValuesHash{$id.'.y_max_value'} = $Max;
1.136     matthew  8975:     $ValuesHash{$id.'.NumBars'}  = $NumBars;
                   8976:     $ValuesHash{$id.'.NumSets'}  = $NumSets;
                   8977:     $ValuesHash{$id.'.PlotType'} = 'bar';
                   8978:     $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8979:     $ValuesHash{$id.'.height'}   = $height;
                   8980:     $ValuesHash{$id.'.width'}    = $width;
                   8981:     $ValuesHash{$id.'.xskip'}    = $xskip;
                   8982:     $ValuesHash{$id.'.bar_width'} = $bar_width;
                   8983:     $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127     matthew  8984:     #
1.228     matthew  8985:     # Deal with other parameters
                   8986:     while (my ($key,$value) = each(%$extra_settings)) {
                   8987:         $ValuesHash{$id.'.'.$key} = $value;
                   8988:     }
                   8989:     #
1.646     raeburn  8990:     &Apache::lonnet::appenv(\%ValuesHash);
1.137     matthew  8991:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   8992: }
                   8993: 
                   8994: ############################################################
                   8995: ############################################################
                   8996: 
                   8997: =pod
                   8998: 
1.648     raeburn  8999: =item * &DrawXYGraph()
1.137     matthew  9000: 
1.138     matthew  9001: Facilitates the plotting of data in an XY graph.
                   9002: Puts plot definition data into the users environment in order for 
                   9003: graph.png to plot it.  Returns an <img> tag for the plot.
                   9004: 
                   9005: Inputs:
                   9006: 
                   9007: =over 4
                   9008: 
                   9009: =item $Title: string, the title of the plot
                   9010: 
                   9011: =item $xlabel: string, text describing the X-axis of the plot
                   9012: 
                   9013: =item $ylabel: string, text describing the Y-axis of the plot
                   9014: 
                   9015: =item $Max: scalar, the maximum Y value to use in the plot
                   9016: If $Max is < any data point, the graph will not be rendered.
                   9017: 
                   9018: =item $colors: Array ref containing the hex color codes for the data to be 
                   9019: plotted in.  If undefined, default values will be used.
                   9020: 
                   9021: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   9022: 
                   9023: =item $Ydata: Array ref containing Array refs.  
1.185     www      9024: Each of the contained arrays will be plotted as a separate curve.
1.138     matthew  9025: 
                   9026: =item %Values: hash indicating or overriding any default values which are 
                   9027: passed to graph.png.  
                   9028: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   9029: 
                   9030: =back
                   9031: 
                   9032: Returns:
                   9033: 
                   9034: An <img> tag which references graph.png and the appropriate identifying
                   9035: information for the plot.
                   9036: 
1.137     matthew  9037: =cut
                   9038: 
                   9039: ############################################################
                   9040: ############################################################
                   9041: sub DrawXYGraph {
                   9042:     my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
                   9043:     #
                   9044:     # Create the identifier for the graph
                   9045:     my $identifier = &get_cgi_id();
                   9046:     my $id = 'cgi.'.$identifier;
                   9047:     #
                   9048:     $Title  = '' if (! defined($Title));
                   9049:     $xlabel = '' if (! defined($xlabel));
                   9050:     $ylabel = '' if (! defined($ylabel));
                   9051:     my %ValuesHash = 
                   9052:         (
1.369     www      9053:          $id.'.title'  => &escape($Title),
                   9054:          $id.'.xlabel' => &escape($xlabel),
                   9055:          $id.'.ylabel' => &escape($ylabel),
1.137     matthew  9056:          $id.'.y_max_value'=> $Max,
                   9057:          $id.'.labels'     => join(',',@$Xlabels),
                   9058:          $id.'.PlotType'   => 'XY',
                   9059:          );
                   9060:     #
                   9061:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   9062:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   9063:     }
                   9064:     #
                   9065:     if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
                   9066:         return '';
                   9067:     }
                   9068:     my $NumSets=1;
1.138     matthew  9069:     foreach my $array (@{$Ydata}){
1.137     matthew  9070:         next if (! ref($array));
                   9071:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
                   9072:     }
1.138     matthew  9073:     $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137     matthew  9074:     #
                   9075:     # Deal with other parameters
                   9076:     while (my ($key,$value) = each(%Values)) {
                   9077:         $ValuesHash{$id.'.'.$key} = $value;
1.127     matthew  9078:     }
                   9079:     #
1.646     raeburn  9080:     &Apache::lonnet::appenv(\%ValuesHash);
1.136     matthew  9081:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   9082: }
                   9083: 
                   9084: ############################################################
                   9085: ############################################################
                   9086: 
                   9087: =pod
                   9088: 
1.648     raeburn  9089: =item * &DrawXYYGraph()
1.138     matthew  9090: 
                   9091: Facilitates the plotting of data in an XY graph with two Y axes.
                   9092: Puts plot definition data into the users environment in order for 
                   9093: graph.png to plot it.  Returns an <img> tag for the plot.
                   9094: 
                   9095: Inputs:
                   9096: 
                   9097: =over 4
                   9098: 
                   9099: =item $Title: string, the title of the plot
                   9100: 
                   9101: =item $xlabel: string, text describing the X-axis of the plot
                   9102: 
                   9103: =item $ylabel: string, text describing the Y-axis of the plot
                   9104: 
                   9105: =item $colors: Array ref containing the hex color codes for the data to be 
                   9106: plotted in.  If undefined, default values will be used.
                   9107: 
                   9108: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   9109: 
                   9110: =item $Ydata1: The first data set
                   9111: 
                   9112: =item $Min1: The minimum value of the left Y-axis
                   9113: 
                   9114: =item $Max1: The maximum value of the left Y-axis
                   9115: 
                   9116: =item $Ydata2: The second data set
                   9117: 
                   9118: =item $Min2: The minimum value of the right Y-axis
                   9119: 
                   9120: =item $Max2: The maximum value of the left Y-axis
                   9121: 
                   9122: =item %Values: hash indicating or overriding any default values which are 
                   9123: passed to graph.png.  
                   9124: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   9125: 
                   9126: =back
                   9127: 
                   9128: Returns:
                   9129: 
                   9130: An <img> tag which references graph.png and the appropriate identifying
                   9131: information for the plot.
1.136     matthew  9132: 
                   9133: =cut
                   9134: 
                   9135: ############################################################
                   9136: ############################################################
1.137     matthew  9137: sub DrawXYYGraph {
                   9138:     my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
                   9139:                                         $Ydata2,$Min2,$Max2,%Values)=@_;
1.136     matthew  9140:     #
                   9141:     # Create the identifier for the graph
                   9142:     my $identifier = &get_cgi_id();
                   9143:     my $id = 'cgi.'.$identifier;
                   9144:     #
                   9145:     $Title  = '' if (! defined($Title));
                   9146:     $xlabel = '' if (! defined($xlabel));
                   9147:     $ylabel = '' if (! defined($ylabel));
                   9148:     my %ValuesHash = 
                   9149:         (
1.369     www      9150:          $id.'.title'  => &escape($Title),
                   9151:          $id.'.xlabel' => &escape($xlabel),
                   9152:          $id.'.ylabel' => &escape($ylabel),
1.136     matthew  9153:          $id.'.labels' => join(',',@$Xlabels),
                   9154:          $id.'.PlotType' => 'XY',
                   9155:          $id.'.NumSets' => 2,
1.137     matthew  9156:          $id.'.two_axes' => 1,
                   9157:          $id.'.y1_max_value' => $Max1,
                   9158:          $id.'.y1_min_value' => $Min1,
                   9159:          $id.'.y2_max_value' => $Max2,
                   9160:          $id.'.y2_min_value' => $Min2,
1.136     matthew  9161:          );
                   9162:     #
1.137     matthew  9163:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   9164:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   9165:     }
                   9166:     #
                   9167:     if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
                   9168:         ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136     matthew  9169:         return '';
                   9170:     }
                   9171:     my $NumSets=1;
1.137     matthew  9172:     foreach my $array ($Ydata1,$Ydata2){
1.136     matthew  9173:         next if (! ref($array));
                   9174:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137     matthew  9175:     }
                   9176:     #
                   9177:     # Deal with other parameters
                   9178:     while (my ($key,$value) = each(%Values)) {
                   9179:         $ValuesHash{$id.'.'.$key} = $value;
1.136     matthew  9180:     }
                   9181:     #
1.646     raeburn  9182:     &Apache::lonnet::appenv(\%ValuesHash);
1.130     albertel 9183:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139     matthew  9184: }
                   9185: 
                   9186: ############################################################
                   9187: ############################################################
                   9188: 
                   9189: =pod
                   9190: 
1.157     matthew  9191: =back 
                   9192: 
1.139     matthew  9193: =head1 Statistics helper routines?  
                   9194: 
                   9195: Bad place for them but what the hell.
                   9196: 
1.157     matthew  9197: =over 4
                   9198: 
1.648     raeburn  9199: =item * &chartlink()
1.139     matthew  9200: 
                   9201: Returns a link to the chart for a specific student.  
                   9202: 
                   9203: Inputs:
                   9204: 
                   9205: =over 4
                   9206: 
                   9207: =item $linktext: The text of the link
                   9208: 
                   9209: =item $sname: The students username
                   9210: 
                   9211: =item $sdomain: The students domain
                   9212: 
                   9213: =back
                   9214: 
1.157     matthew  9215: =back
                   9216: 
1.139     matthew  9217: =cut
                   9218: 
                   9219: ############################################################
                   9220: ############################################################
                   9221: sub chartlink {
                   9222:     my ($linktext, $sname, $sdomain) = @_;
                   9223:     my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369     www      9224:         '&amp;SelectedStudent='.&escape($sname.':'.$sdomain).
1.219     albertel 9225:         '&amp;chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139     matthew  9226:        '">'.$linktext.'</a>';
1.153     matthew  9227: }
                   9228: 
                   9229: #######################################################
                   9230: #######################################################
                   9231: 
                   9232: =pod
                   9233: 
                   9234: =head1 Course Environment Routines
1.157     matthew  9235: 
                   9236: =over 4
1.153     matthew  9237: 
1.648     raeburn  9238: =item * &restore_course_settings()
1.153     matthew  9239: 
1.648     raeburn  9240: =item * &store_course_settings()
1.153     matthew  9241: 
                   9242: Restores/Store indicated form parameters from the course environment.
                   9243: Will not overwrite existing values of the form parameters.
                   9244: 
                   9245: Inputs: 
                   9246: a scalar describing the data (e.g. 'chart', 'problem_analysis')
                   9247: 
                   9248: a hash ref describing the data to be stored.  For example:
                   9249:    
                   9250: %Save_Parameters = ('Status' => 'scalar',
                   9251:     'chartoutputmode' => 'scalar',
                   9252:     'chartoutputdata' => 'scalar',
                   9253:     'Section' => 'array',
1.373     raeburn  9254:     'Group' => 'array',
1.153     matthew  9255:     'StudentData' => 'array',
                   9256:     'Maps' => 'array');
                   9257: 
                   9258: Returns: both routines return nothing
                   9259: 
1.631     raeburn  9260: =back
                   9261: 
1.153     matthew  9262: =cut
                   9263: 
                   9264: #######################################################
                   9265: #######################################################
                   9266: sub store_course_settings {
1.496     albertel 9267:     return &store_settings($env{'request.course.id'},@_);
                   9268: }
                   9269: 
                   9270: sub store_settings {
1.153     matthew  9271:     # save to the environment
                   9272:     # appenv the same items, just to be safe
1.300     albertel 9273:     my $udom  = $env{'user.domain'};
                   9274:     my $uname = $env{'user.name'};
1.496     albertel 9275:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  9276:     my %SaveHash;
                   9277:     my %AppHash;
                   9278:     while (my ($setting,$type) = each(%$Settings)) {
1.496     albertel 9279:         my $basename = join('.','internal',$context,$prefix,$setting);
1.300     albertel 9280:         my $envname = 'environment.'.$basename;
1.258     albertel 9281:         if (exists($env{'form.'.$setting})) {
1.153     matthew  9282:             # Save this value away
                   9283:             if ($type eq 'scalar' &&
1.258     albertel 9284:                 (! exists($env{$envname}) || 
                   9285:                  $env{$envname} ne $env{'form.'.$setting})) {
                   9286:                 $SaveHash{$basename} = $env{'form.'.$setting};
                   9287:                 $AppHash{$envname}   = $env{'form.'.$setting};
1.153     matthew  9288:             } elsif ($type eq 'array') {
                   9289:                 my $stored_form;
1.258     albertel 9290:                 if (ref($env{'form.'.$setting})) {
1.153     matthew  9291:                     $stored_form = join(',',
                   9292:                                         map {
1.369     www      9293:                                             &escape($_);
1.258     albertel 9294:                                         } sort(@{$env{'form.'.$setting}}));
1.153     matthew  9295:                 } else {
                   9296:                     $stored_form = 
1.369     www      9297:                         &escape($env{'form.'.$setting});
1.153     matthew  9298:                 }
                   9299:                 # Determine if the array contents are the same.
1.258     albertel 9300:                 if ($stored_form ne $env{$envname}) {
1.153     matthew  9301:                     $SaveHash{$basename} = $stored_form;
                   9302:                     $AppHash{$envname}   = $stored_form;
                   9303:                 }
                   9304:             }
                   9305:         }
                   9306:     }
                   9307:     my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300     albertel 9308:                                           $udom,$uname);
1.153     matthew  9309:     if ($put_result !~ /^(ok|delayed)/) {
                   9310:         &Apache::lonnet::logthis('unable to save form parameters, '.
                   9311:                                  'got error:'.$put_result);
                   9312:     }
                   9313:     # Make sure these settings stick around in this session, too
1.646     raeburn  9314:     &Apache::lonnet::appenv(\%AppHash);
1.153     matthew  9315:     return;
                   9316: }
                   9317: 
                   9318: sub restore_course_settings {
1.499     albertel 9319:     return &restore_settings($env{'request.course.id'},@_);
1.496     albertel 9320: }
                   9321: 
                   9322: sub restore_settings {
                   9323:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  9324:     while (my ($setting,$type) = each(%$Settings)) {
1.258     albertel 9325:         next if (exists($env{'form.'.$setting}));
1.496     albertel 9326:         my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153     matthew  9327:             '.'.$setting;
1.258     albertel 9328:         if (exists($env{$envname})) {
1.153     matthew  9329:             if ($type eq 'scalar') {
1.258     albertel 9330:                 $env{'form.'.$setting} = $env{$envname};
1.153     matthew  9331:             } elsif ($type eq 'array') {
1.258     albertel 9332:                 $env{'form.'.$setting} = [ 
1.153     matthew  9333:                                            map { 
1.369     www      9334:                                                &unescape($_); 
1.258     albertel 9335:                                            } split(',',$env{$envname})
1.153     matthew  9336:                                            ];
                   9337:             }
                   9338:         }
                   9339:     }
1.127     matthew  9340: }
                   9341: 
1.618     raeburn  9342: #######################################################
                   9343: #######################################################
                   9344: 
                   9345: =pod
                   9346: 
                   9347: =head1 Domain E-mail Routines  
                   9348: 
                   9349: =over 4
                   9350: 
1.648     raeburn  9351: =item * &build_recipient_list()
1.618     raeburn  9352: 
1.884     raeburn  9353: Build recipient lists for five types of e-mail:
1.766     raeburn  9354: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.884     raeburn  9355: (d) Help requests, (e) Course requests needing approval,  generated by
                   9356: lonerrorhandler.pm, CHECKRPMS, loncron, lonsupportreq.pm and
                   9357: loncoursequeueadmin.pm respectively.
1.618     raeburn  9358: 
                   9359: Inputs:
1.619     raeburn  9360: defmail (scalar - email address of default recipient), 
1.618     raeburn  9361: mailing type (scalar - errormail, packagesmail, or helpdeskmail), 
1.619     raeburn  9362: defdom (domain for which to retrieve configuration settings),
                   9363: origmail (scalar - email address of recipient from loncapa.conf, 
                   9364: i.e., predates configuration by DC via domainprefs.pm 
1.618     raeburn  9365: 
1.655     raeburn  9366: Returns: comma separated list of addresses to which to send e-mail.
                   9367: 
                   9368: =back
1.618     raeburn  9369: 
                   9370: =cut
                   9371: 
                   9372: ############################################################
                   9373: ############################################################
                   9374: sub build_recipient_list {
1.619     raeburn  9375:     my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618     raeburn  9376:     my @recipients;
                   9377:     my $otheremails;
                   9378:     my %domconfig =
                   9379:          &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
                   9380:     if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766     raeburn  9381:         if (exists($domconfig{'contacts'}{$mailing})) {
                   9382:             if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
                   9383:                 my @contacts = ('adminemail','supportemail');
                   9384:                 foreach my $item (@contacts) {
                   9385:                     if ($domconfig{'contacts'}{$mailing}{$item}) {
                   9386:                         my $addr = $domconfig{'contacts'}{$item}; 
                   9387:                         if (!grep(/^\Q$addr\E$/,@recipients)) {
                   9388:                             push(@recipients,$addr);
                   9389:                         }
1.619     raeburn  9390:                     }
1.766     raeburn  9391:                     $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618     raeburn  9392:                 }
                   9393:             }
1.766     raeburn  9394:         } elsif ($origmail ne '') {
                   9395:             push(@recipients,$origmail);
1.618     raeburn  9396:         }
1.619     raeburn  9397:     } elsif ($origmail ne '') {
                   9398:         push(@recipients,$origmail);
1.618     raeburn  9399:     }
1.688     raeburn  9400:     if (defined($defmail)) {
                   9401:         if ($defmail ne '') {
                   9402:             push(@recipients,$defmail);
                   9403:         }
1.618     raeburn  9404:     }
                   9405:     if ($otheremails) {
1.619     raeburn  9406:         my @others;
                   9407:         if ($otheremails =~ /,/) {
                   9408:             @others = split(/,/,$otheremails);
1.618     raeburn  9409:         } else {
1.619     raeburn  9410:             push(@others,$otheremails);
                   9411:         }
                   9412:         foreach my $addr (@others) {
                   9413:             if (!grep(/^\Q$addr\E$/,@recipients)) {
                   9414:                 push(@recipients,$addr);
                   9415:             }
1.618     raeburn  9416:         }
                   9417:     }
1.619     raeburn  9418:     my $recipientlist = join(',',@recipients); 
1.618     raeburn  9419:     return $recipientlist;
                   9420: }
                   9421: 
1.127     matthew  9422: ############################################################
                   9423: ############################################################
1.154     albertel 9424: 
1.655     raeburn  9425: =pod
                   9426: 
                   9427: =head1 Course Catalog Routines
                   9428: 
                   9429: =over 4
                   9430: 
                   9431: =item * &gather_categories()
                   9432: 
                   9433: Converts category definitions - keys of categories hash stored in  
                   9434: coursecategories in configuration.db on the primary library server in a 
                   9435: domain - to an array.  Also generates javascript and idx hash used to 
                   9436: generate Domain Coordinator interface for editing Course Categories.
                   9437: 
                   9438: Inputs:
1.663     raeburn  9439: 
1.655     raeburn  9440: categories (reference to hash of category definitions).
1.663     raeburn  9441: 
1.655     raeburn  9442: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9443:       categories and subcategories).
1.663     raeburn  9444: 
1.655     raeburn  9445: idx (reference to hash of counters used in Domain Coordinator interface for 
                   9446:       editing Course Categories).
1.663     raeburn  9447: 
1.655     raeburn  9448: jsarray (reference to array of categories used to create Javascript arrays for
                   9449:          Domain Coordinator interface for editing Course Categories).
                   9450: 
                   9451: Returns: nothing
                   9452: 
                   9453: Side effects: populates cats, idx and jsarray. 
                   9454: 
                   9455: =cut
                   9456: 
                   9457: sub gather_categories {
                   9458:     my ($categories,$cats,$idx,$jsarray) = @_;
                   9459:     my %counters;
                   9460:     my $num = 0;
                   9461:     foreach my $item (keys(%{$categories})) {
                   9462:         my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   9463:         if ($container eq '' && $depth == 0) {
                   9464:             $cats->[$depth][$categories->{$item}] = $cat;
                   9465:         } else {
                   9466:             $cats->[$depth]{$container}[$categories->{$item}] = $cat;
                   9467:         }
                   9468:         my ($escitem,$tail) = split(/:/,$item,2);
                   9469:         if ($counters{$tail} eq '') {
                   9470:             $counters{$tail} = $num;
                   9471:             $num ++;
                   9472:         }
                   9473:         if (ref($idx) eq 'HASH') {
                   9474:             $idx->{$item} = $counters{$tail};
                   9475:         }
                   9476:         if (ref($jsarray) eq 'ARRAY') {
                   9477:             push(@{$jsarray->[$counters{$tail}]},$item);
                   9478:         }
                   9479:     }
                   9480:     return;
                   9481: }
                   9482: 
                   9483: =pod
                   9484: 
                   9485: =item * &extract_categories()
                   9486: 
                   9487: Used to generate breadcrumb trails for course categories.
                   9488: 
                   9489: Inputs:
1.663     raeburn  9490: 
1.655     raeburn  9491: categories (reference to hash of category definitions).
1.663     raeburn  9492: 
1.655     raeburn  9493: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9494:       categories and subcategories).
1.663     raeburn  9495: 
1.655     raeburn  9496: trails (reference to array of breacrumb trails for each category).
1.663     raeburn  9497: 
1.655     raeburn  9498: allitems (reference to hash - key is category key 
                   9499:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  9500: 
1.655     raeburn  9501: idx (reference to hash of counters used in Domain Coordinator interface for
                   9502:       editing Course Categories).
1.663     raeburn  9503: 
1.655     raeburn  9504: jsarray (reference to array of categories used to create Javascript arrays for
                   9505:          Domain Coordinator interface for editing Course Categories).
                   9506: 
1.665     raeburn  9507: subcats (reference to hash of arrays containing all subcategories within each 
                   9508:          category, -recursive)
                   9509: 
1.655     raeburn  9510: Returns: nothing
                   9511: 
                   9512: Side effects: populates trails and allitems hash references.
                   9513: 
                   9514: =cut
                   9515: 
                   9516: sub extract_categories {
1.665     raeburn  9517:     my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655     raeburn  9518:     if (ref($categories) eq 'HASH') {
                   9519:         &gather_categories($categories,$cats,$idx,$jsarray);
                   9520:         if (ref($cats->[0]) eq 'ARRAY') {
                   9521:             for (my $i=0; $i<@{$cats->[0]}; $i++) {
                   9522:                 my $name = $cats->[0][$i];
                   9523:                 my $item = &escape($name).'::0';
                   9524:                 my $trailstr;
                   9525:                 if ($name eq 'instcode') {
                   9526:                     $trailstr = &mt('Official courses (with institutional codes)');
                   9527:                 } else {
                   9528:                     $trailstr = $name;
                   9529:                 }
                   9530:                 if ($allitems->{$item} eq '') {
                   9531:                     push(@{$trails},$trailstr);
                   9532:                     $allitems->{$item} = scalar(@{$trails})-1;
                   9533:                 }
                   9534:                 my @parents = ($name);
                   9535:                 if (ref($cats->[1]{$name}) eq 'ARRAY') {
                   9536:                     for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
                   9537:                         my $category = $cats->[1]{$name}[$j];
1.665     raeburn  9538:                         if (ref($subcats) eq 'HASH') {
                   9539:                             push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
                   9540:                         }
                   9541:                         &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
                   9542:                     }
                   9543:                 } else {
                   9544:                     if (ref($subcats) eq 'HASH') {
                   9545:                         $subcats->{$item} = [];
1.655     raeburn  9546:                     }
                   9547:                 }
                   9548:             }
                   9549:         }
                   9550:     }
                   9551:     return;
                   9552: }
                   9553: 
                   9554: =pod
                   9555: 
                   9556: =item *&recurse_categories()
                   9557: 
                   9558: Recursively used to generate breadcrumb trails for course categories.
                   9559: 
                   9560: Inputs:
1.663     raeburn  9561: 
1.655     raeburn  9562: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9563:       categories and subcategories).
1.663     raeburn  9564: 
1.655     raeburn  9565: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663     raeburn  9566: 
                   9567: category (current course category, for which breadcrumb trail is being generated).
                   9568: 
                   9569: trails (reference to array of breadcrumb trails for each category).
                   9570: 
1.655     raeburn  9571: allitems (reference to hash - key is category key
                   9572:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  9573: 
1.655     raeburn  9574: parents (array containing containers directories for current category, 
                   9575:          back to top level). 
                   9576: 
                   9577: Returns: nothing
                   9578: 
                   9579: Side effects: populates trails and allitems hash references
                   9580: 
                   9581: =cut
                   9582: 
                   9583: sub recurse_categories {
1.665     raeburn  9584:     my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655     raeburn  9585:     my $shallower = $depth - 1;
                   9586:     if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
                   9587:         for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
                   9588:             my $name = $cats->[$depth]{$category}[$k];
                   9589:             my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   9590:             my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   9591:             if ($allitems->{$item} eq '') {
                   9592:                 push(@{$trails},$trailstr);
                   9593:                 $allitems->{$item} = scalar(@{$trails})-1;
                   9594:             }
                   9595:             my $deeper = $depth+1;
                   9596:             push(@{$parents},$category);
1.665     raeburn  9597:             if (ref($subcats) eq 'HASH') {
                   9598:                 my $subcat = &escape($name).':'.$category.':'.$depth;
                   9599:                 for (my $j=@{$parents}; $j>=0; $j--) {
                   9600:                     my $higher;
                   9601:                     if ($j > 0) {
                   9602:                         $higher = &escape($parents->[$j]).':'.
                   9603:                                   &escape($parents->[$j-1]).':'.$j;
                   9604:                     } else {
                   9605:                         $higher = &escape($parents->[$j]).'::'.$j;
                   9606:                     }
                   9607:                     push(@{$subcats->{$higher}},$subcat);
                   9608:                 }
                   9609:             }
                   9610:             &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
                   9611:                                 $subcats);
1.655     raeburn  9612:             pop(@{$parents});
                   9613:         }
                   9614:     } else {
                   9615:         my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   9616:         my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   9617:         if ($allitems->{$item} eq '') {
                   9618:             push(@{$trails},$trailstr);
                   9619:             $allitems->{$item} = scalar(@{$trails})-1;
                   9620:         }
                   9621:     }
                   9622:     return;
                   9623: }
                   9624: 
1.663     raeburn  9625: =pod
                   9626: 
                   9627: =item *&assign_categories_table()
                   9628: 
                   9629: Create a datatable for display of hierarchical categories in a domain,
                   9630: with checkboxes to allow a course to be categorized. 
                   9631: 
                   9632: Inputs:
                   9633: 
                   9634: cathash - reference to hash of categories defined for the domain (from
                   9635:           configuration.db)
                   9636: 
                   9637: currcat - scalar with an & separated list of categories assigned to a course. 
                   9638: 
                   9639: Returns: $output (markup to be displayed) 
                   9640: 
                   9641: =cut
                   9642: 
                   9643: sub assign_categories_table {
                   9644:     my ($cathash,$currcat) = @_;
                   9645:     my $output;
                   9646:     if (ref($cathash) eq 'HASH') {
                   9647:         my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
                   9648:         &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
                   9649:         $maxdepth = scalar(@cats);
                   9650:         if (@cats > 0) {
                   9651:             my $itemcount = 0;
                   9652:             if (ref($cats[0]) eq 'ARRAY') {
                   9653:                 $output = &Apache::loncommon::start_data_table();
                   9654:                 my @currcategories;
                   9655:                 if ($currcat ne '') {
                   9656:                     @currcategories = split('&',$currcat);
                   9657:                 }
                   9658:                 for (my $i=0; $i<@{$cats[0]}; $i++) {
                   9659:                     my $parent = $cats[0][$i];
                   9660:                     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9661:                     next if ($parent eq 'instcode');
                   9662:                     my $item = &escape($parent).'::0';
                   9663:                     my $checked = '';
                   9664:                     if (@currcategories > 0) {
                   9665:                         if (grep(/^\Q$item\E$/,@currcategories)) {
1.772     bisitz   9666:                             $checked = ' checked="checked"';
1.663     raeburn  9667:                         }
                   9668:                     }
1.675     raeburn  9669:                     $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
                   9670:                                '<input type="checkbox" name="usecategory" value="'.
                   9671:                                $item.'"'.$checked.' />'.$parent.'</span>'.
                   9672:                                '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663     raeburn  9673:                     my $depth = 1;
                   9674:                     push(@path,$parent);
                   9675:                     $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
                   9676:                     pop(@path);
                   9677:                     $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   9678:                     $itemcount ++;
                   9679:                 }
                   9680:                 $output .= &Apache::loncommon::end_data_table();
                   9681:             }
                   9682:         }
                   9683:     }
                   9684:     return $output;
                   9685: }
                   9686: 
                   9687: =pod
                   9688: 
                   9689: =item *&assign_category_rows()
                   9690: 
                   9691: Create a datatable row for display of nested categories in a domain,
                   9692: with checkboxes to allow a course to be categorized,called recursively.
                   9693: 
                   9694: Inputs:
                   9695: 
                   9696: itemcount - track row number for alternating colors
                   9697: 
                   9698: cats - reference to array of arrays/hashes which encapsulates hierarchy of
                   9699:       categories and subcategories.
                   9700: 
                   9701: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
                   9702: 
                   9703: parent - parent of current category item
                   9704: 
                   9705: path - Array containing all categories back up through the hierarchy from the
                   9706:        current category to the top level.
                   9707: 
                   9708: currcategories - reference to array of current categories assigned to the course
                   9709: 
                   9710: Returns: $output (markup to be displayed).
                   9711: 
                   9712: =cut
                   9713: 
                   9714: sub assign_category_rows {
                   9715:     my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
                   9716:     my ($text,$name,$item,$chgstr);
                   9717:     if (ref($cats) eq 'ARRAY') {
                   9718:         my $maxdepth = scalar(@{$cats});
                   9719:         if (ref($cats->[$depth]) eq 'HASH') {
                   9720:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   9721:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   9722:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9723:                 $text .= '<td><table class="LC_datatable">';
                   9724:                 for (my $j=0; $j<$numchildren; $j++) {
                   9725:                     $name = $cats->[$depth]{$parent}[$j];
                   9726:                     $item = &escape($name).':'.&escape($parent).':'.$depth;
                   9727:                     my $deeper = $depth+1;
                   9728:                     my $checked = '';
                   9729:                     if (ref($currcategories) eq 'ARRAY') {
                   9730:                         if (@{$currcategories} > 0) {
                   9731:                             if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772     bisitz   9732:                                 $checked = ' checked="checked"';
1.663     raeburn  9733:                             }
                   9734:                         }
                   9735:                     }
1.664     raeburn  9736:                     $text .= '<tr><td><span class="LC_nobreak"><label>'.
                   9737:                              '<input type="checkbox" name="usecategory" value="'.
1.675     raeburn  9738:                              $item.'"'.$checked.' />'.$name.'</label></span>'.
                   9739:                              '<input type="hidden" name="catname" value="'.$name.'" />'.
                   9740:                              '</td><td>';
1.663     raeburn  9741:                     if (ref($path) eq 'ARRAY') {
                   9742:                         push(@{$path},$name);
                   9743:                         $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
                   9744:                         pop(@{$path});
                   9745:                     }
                   9746:                     $text .= '</td></tr>';
                   9747:                 }
                   9748:                 $text .= '</table></td>';
                   9749:             }
                   9750:         }
                   9751:     }
                   9752:     return $text;
                   9753: }
                   9754: 
1.655     raeburn  9755: ############################################################
                   9756: ############################################################
                   9757: 
                   9758: 
1.443     albertel 9759: sub commit_customrole {
1.664     raeburn  9760:     my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630     raeburn  9761:     my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443     albertel 9762:                          ($start?', '.&mt('starting').' '.localtime($start):'').
                   9763:                          ($end?', ending '.localtime($end):'').': <b>'.
                   9764:               &Apache::lonnet::assigncustomrole(
1.664     raeburn  9765:                  $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443     albertel 9766:                  '</b><br />';
                   9767:     return $output;
                   9768: }
                   9769: 
                   9770: sub commit_standardrole {
1.541     raeburn  9771:     my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
                   9772:     my ($output,$logmsg,$linefeed);
                   9773:     if ($context eq 'auto') {
                   9774:         $linefeed = "\n";
                   9775:     } else {
                   9776:         $linefeed = "<br />\n";
                   9777:     }  
1.443     albertel 9778:     if ($three eq 'st') {
1.541     raeburn  9779:         my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
                   9780:                                          $one,$two,$sec,$context);
                   9781:         if (($result =~ /^error/) || ($result eq 'not_in_class') || 
1.626     raeburn  9782:             ($result eq 'unknown_course') || ($result eq 'refused')) {
                   9783:             $output = $logmsg.' '.&mt('Error: ').$result."\n"; 
1.443     albertel 9784:         } else {
1.541     raeburn  9785:             $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443     albertel 9786:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  9787:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
                   9788:             if ($context eq 'auto') {
                   9789:                 $output .= $result.$linefeed.&mt('Add to classlist').': ok';
                   9790:             } else {
                   9791:                $output .= '<b>'.$result.'</b>'.$linefeed.
                   9792:                &mt('Add to classlist').': <b>ok</b>';
                   9793:             }
                   9794:             $output .= $linefeed;
1.443     albertel 9795:         }
                   9796:     } else {
                   9797:         $output = &mt('Assigning').' '.$three.' in '.$url.
                   9798:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  9799:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652     raeburn  9800:         my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541     raeburn  9801:         if ($context eq 'auto') {
                   9802:             $output .= $result.$linefeed;
                   9803:         } else {
                   9804:             $output .= '<b>'.$result.'</b>'.$linefeed;
                   9805:         }
1.443     albertel 9806:     }
                   9807:     return $output;
                   9808: }
                   9809: 
                   9810: sub commit_studentrole {
1.541     raeburn  9811:     my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626     raeburn  9812:     my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541     raeburn  9813:     if ($context eq 'auto') {
                   9814:         $linefeed = "\n";
                   9815:     } else {
                   9816:         $linefeed = '<br />'."\n";
                   9817:     }
1.443     albertel 9818:     if (defined($one) && defined($two)) {
                   9819:         my $cid=$one.'_'.$two;
                   9820:         my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
                   9821:         my $secchange = 0;
                   9822:         my $expire_role_result;
                   9823:         my $modify_section_result;
1.628     raeburn  9824:         if ($oldsec ne '-1') { 
                   9825:             if ($oldsec ne $sec) {
1.443     albertel 9826:                 $secchange = 1;
1.628     raeburn  9827:                 my $now = time;
1.443     albertel 9828:                 my $uurl='/'.$cid;
                   9829:                 $uurl=~s/\_/\//g;
                   9830:                 if ($oldsec) {
                   9831:                     $uurl.='/'.$oldsec;
                   9832:                 }
1.626     raeburn  9833:                 $oldsecurl = $uurl;
1.628     raeburn  9834:                 $expire_role_result = 
1.652     raeburn  9835:                     &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628     raeburn  9836:                 if ($env{'request.course.sec'} ne '') { 
                   9837:                     if ($expire_role_result eq 'refused') {
                   9838:                         my @roles = ('st');
                   9839:                         my @statuses = ('previous');
                   9840:                         my @roledoms = ($one);
                   9841:                         my $withsec = 1;
                   9842:                         my %roleshash = 
                   9843:                             &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
                   9844:                                               \@statuses,\@roles,\@roledoms,$withsec);
                   9845:                         if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
                   9846:                             my ($oldstart,$oldend) = 
                   9847:                                 split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
                   9848:                             if ($oldend > 0 && $oldend <= $now) {
                   9849:                                 $expire_role_result = 'ok';
                   9850:                             }
                   9851:                         }
                   9852:                     }
                   9853:                 }
1.443     albertel 9854:                 $result = $expire_role_result;
                   9855:             }
                   9856:         }
                   9857:         if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652     raeburn  9858:             $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443     albertel 9859:             if ($modify_section_result =~ /^ok/) {
                   9860:                 if ($secchange == 1) {
1.628     raeburn  9861:                     if ($sec eq '') {
                   9862:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
                   9863:                     } else {
                   9864:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
                   9865:                     }
1.443     albertel 9866:                 } elsif ($oldsec eq '-1') {
1.628     raeburn  9867:                     if ($sec eq '') {
                   9868:                         $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
                   9869:                     } else {
                   9870:                         $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   9871:                     }
1.443     albertel 9872:                 } else {
1.628     raeburn  9873:                     if ($sec eq '') {
                   9874:                         $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
                   9875:                     } else {
                   9876:                         $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   9877:                     }
1.443     albertel 9878:                 }
                   9879:             } else {
1.628     raeburn  9880:                 if ($secchange) {       
                   9881:                     $$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;
                   9882:                 } else {
                   9883:                     $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
                   9884:                 }
1.443     albertel 9885:             }
                   9886:             $result = $modify_section_result;
                   9887:         } elsif ($secchange == 1) {
1.628     raeburn  9888:             if ($oldsec eq '') {
                   9889:                 $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
                   9890:             } else {
                   9891:                 $$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;
                   9892:             }
1.626     raeburn  9893:             if ($expire_role_result eq 'refused') {
                   9894:                 my $newsecurl = '/'.$cid;
                   9895:                 $newsecurl =~ s/\_/\//g;
                   9896:                 if ($sec ne '') {
                   9897:                     $newsecurl.='/'.$sec;
                   9898:                 }
                   9899:                 if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
                   9900:                     if ($sec eq '') {
                   9901:                         $$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;
                   9902:                     } else {
                   9903:                         $$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;
                   9904:                     }
                   9905:                 }
                   9906:             }
1.443     albertel 9907:         }
                   9908:     } else {
1.626     raeburn  9909:         $$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 9910:         $result = "error: incomplete course id\n";
                   9911:     }
                   9912:     return $result;
                   9913: }
                   9914: 
                   9915: ############################################################
                   9916: ############################################################
                   9917: 
1.566     albertel 9918: sub check_clone {
1.578     raeburn  9919:     my ($args,$linefeed) = @_;
1.566     albertel 9920:     my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
                   9921:     my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
                   9922:     my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
                   9923:     my $clonemsg;
                   9924:     my $can_clone = 0;
                   9925: 
                   9926:     if ($clonehome eq 'no_host') {
1.578     raeburn  9927:         $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 9928:     } else {
                   9929: 	my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.882     raeburn  9930: 	if (($env{'request.role.domain'} eq $args->{'clonedomain'}) && 
                   9931:             (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566     albertel 9932: 	    $can_clone = 1;
                   9933: 	} else {
                   9934: 	    my %clonehash = &Apache::lonnet::get('environment',['cloners'],
                   9935: 						 $args->{'clonedomain'},$args->{'clonecourse'});
                   9936: 	    my @cloners = split(/,/,$clonehash{'cloners'});
1.578     raeburn  9937:             if (grep(/^\*$/,@cloners)) {
                   9938:                 $can_clone = 1;
                   9939:             } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
                   9940:                 $can_clone = 1;
                   9941:             } else {
                   9942: 	        my %roleshash =
                   9943: 		    &Apache::lonnet::get_my_roles($args->{'ccuname'},
                   9944: 					 $args->{'ccdomain'},
                   9945:                                          'userroles',['active'],['cc'],
                   9946: 					 [$args->{'clonedomain'}]);
                   9947: 	        if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
                   9948: 		    $can_clone = 1;
                   9949: 	        } else {
                   9950:                     $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'});
                   9951: 	        }
1.566     albertel 9952: 	    }
1.578     raeburn  9953:         }
1.566     albertel 9954:     }
                   9955:     return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   9956: }
                   9957: 
1.444     albertel 9958: sub construct_course {
1.885     raeburn  9959:     my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category) = @_;
1.444     albertel 9960:     my $outcome;
1.541     raeburn  9961:     my $linefeed =  '<br />'."\n";
                   9962:     if ($context eq 'auto') {
                   9963:         $linefeed = "\n";
                   9964:     }
1.566     albertel 9965: 
                   9966: #
                   9967: # Are we cloning?
                   9968: #
                   9969:     my ($can_clone, $clonemsg, $cloneid, $clonehome);
                   9970:     if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578     raeburn  9971: 	($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566     albertel 9972: 	if ($context ne 'auto') {
1.578     raeburn  9973:             if ($clonemsg ne '') {
                   9974: 	        $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
                   9975:             }
1.566     albertel 9976: 	}
                   9977: 	$outcome .= $clonemsg.$linefeed;
                   9978: 
                   9979:         if (!$can_clone) {
                   9980: 	    return (0,$outcome);
                   9981: 	}
                   9982:     }
                   9983: 
1.444     albertel 9984: #
                   9985: # Open course
                   9986: #
                   9987:     my $crstype = lc($args->{'crstype'});
                   9988:     my %cenv=();
                   9989:     $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
                   9990:                                              $args->{'cdescr'},
                   9991:                                              $args->{'curl'},
                   9992:                                              $args->{'course_home'},
                   9993:                                              $args->{'nonstandard'},
                   9994:                                              $args->{'crscode'},
                   9995:                                              $args->{'ccuname'}.':'.
                   9996:                                              $args->{'ccdomain'},
1.882     raeburn  9997:                                              $args->{'crstype'},
1.885     raeburn  9998:                                              $cnum,$context,$category);
1.444     albertel 9999: 
                   10000:     # Note: The testing routines depend on this being output; see 
                   10001:     # Utils::Course. This needs to at least be output as a comment
                   10002:     # if anyone ever decides to not show this, and Utils::Course::new
                   10003:     # will need to be suitably modified.
1.541     raeburn  10004:     $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444     albertel 10005: #
                   10006: # Check if created correctly
                   10007: #
1.479     albertel 10008:     ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444     albertel 10009:     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541     raeburn  10010:     $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566     albertel 10011: 
1.444     albertel 10012: #
1.566     albertel 10013: # Do the cloning
                   10014: #   
                   10015:     if ($can_clone && $cloneid) {
                   10016: 	$clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
                   10017: 	if ($context ne 'auto') {
                   10018: 	    $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
                   10019: 	}
                   10020: 	$outcome .= $clonemsg.$linefeed;
                   10021: 	my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444     albertel 10022: # Copy all files
1.637     www      10023: 	&Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444     albertel 10024: # Restore URL
1.566     albertel 10025: 	$cenv{'url'}=$oldcenv{'url'};
1.444     albertel 10026: # Restore title
1.566     albertel 10027: 	$cenv{'description'}=$oldcenv{'description'};
1.444     albertel 10028: # Mark as cloned
1.566     albertel 10029: 	$cenv{'clonedfrom'}=$cloneid;
1.638     www      10030: # Need to clone grading mode
                   10031:         my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
                   10032:         $cenv{'grading'}=$newenv{'grading'};
                   10033: # Do not clone these environment entries
                   10034:         &Apache::lonnet::del('environment',
                   10035:                   ['default_enrollment_start_date',
                   10036:                    'default_enrollment_end_date',
                   10037:                    'question.email',
                   10038:                    'policy.email',
                   10039:                    'comment.email',
                   10040:                    'pch.users.denied',
1.725     raeburn  10041:                    'plc.users.denied',
                   10042:                    'hidefromcat',
                   10043:                    'categories'],
1.638     www      10044:                    $$crsudom,$$crsunum);
1.444     albertel 10045:     }
1.566     albertel 10046: 
1.444     albertel 10047: #
                   10048: # Set environment (will override cloned, if existing)
                   10049: #
                   10050:     my @sections = ();
                   10051:     my @xlists = ();
                   10052:     if ($args->{'crstype'}) {
                   10053:         $cenv{'type'}=$args->{'crstype'};
                   10054:     }
                   10055:     if ($args->{'crsid'}) {
                   10056:         $cenv{'courseid'}=$args->{'crsid'};
                   10057:     }
                   10058:     if ($args->{'crscode'}) {
                   10059:         $cenv{'internal.coursecode'}=$args->{'crscode'};
                   10060:     }
                   10061:     if ($args->{'crsquota'} ne '') {
                   10062:         $cenv{'internal.coursequota'}=$args->{'crsquota'};
                   10063:     } else {
                   10064:         $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
                   10065:     }
                   10066:     if ($args->{'ccuname'}) {
                   10067:         $cenv{'internal.courseowner'} = $args->{'ccuname'}.
                   10068:                                         ':'.$args->{'ccdomain'};
                   10069:     } else {
                   10070:         $cenv{'internal.courseowner'} = $args->{'curruser'};
                   10071:     }
                   10072:     my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
                   10073:     if ($args->{'crssections'}) {
                   10074:         $cenv{'internal.sectionnums'} = '';
                   10075:         if ($args->{'crssections'} =~ m/,/) {
                   10076:             @sections = split/,/,$args->{'crssections'};
                   10077:         } else {
                   10078:             $sections[0] = $args->{'crssections'};
                   10079:         }
                   10080:         if (@sections > 0) {
                   10081:             foreach my $item (@sections) {
                   10082:                 my ($sec,$gp) = split/:/,$item;
                   10083:                 my $class = $args->{'crscode'}.$sec;
                   10084:                 my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
                   10085:                 $cenv{'internal.sectionnums'} .= $item.',';
                   10086:                 unless ($addcheck eq 'ok') {
                   10087:                     push @badclasses, $class;
                   10088:                 }
                   10089:             }
                   10090:             $cenv{'internal.sectionnums'} =~ s/,$//;
                   10091:         }
                   10092:     }
                   10093: # do not hide course coordinator from staff listing, 
                   10094: # even if privileged
                   10095:     $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   10096: # add crosslistings
                   10097:     if ($args->{'crsxlist'}) {
                   10098:         $cenv{'internal.crosslistings'}='';
                   10099:         if ($args->{'crsxlist'} =~ m/,/) {
                   10100:             @xlists = split/,/,$args->{'crsxlist'};
                   10101:         } else {
                   10102:             $xlists[0] = $args->{'crsxlist'};
                   10103:         }
                   10104:         if (@xlists > 0) {
                   10105:             foreach my $item (@xlists) {
                   10106:                 my ($xl,$gp) = split/:/,$item;
                   10107:                 my $addcheck =  &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
                   10108:                 $cenv{'internal.crosslistings'} .= $item.',';
                   10109:                 unless ($addcheck eq 'ok') {
                   10110:                     push @badclasses, $xl;
                   10111:                 }
                   10112:             }
                   10113:             $cenv{'internal.crosslistings'} =~ s/,$//;
                   10114:         }
                   10115:     }
                   10116:     if ($args->{'autoadds'}) {
                   10117:         $cenv{'internal.autoadds'}=$args->{'autoadds'};
                   10118:     }
                   10119:     if ($args->{'autodrops'}) {
                   10120:         $cenv{'internal.autodrops'}=$args->{'autodrops'};
                   10121:     }
                   10122: # check for notification of enrollment changes
                   10123:     my @notified = ();
                   10124:     if ($args->{'notify_owner'}) {
                   10125:         if ($args->{'ccuname'} ne '') {
                   10126:             push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
                   10127:         }
                   10128:     }
                   10129:     if ($args->{'notify_dc'}) {
                   10130:         if ($uname ne '') { 
1.630     raeburn  10131:             push(@notified,$uname.':'.$udom);
1.444     albertel 10132:         }
                   10133:     }
                   10134:     if (@notified > 0) {
                   10135:         my $notifylist;
                   10136:         if (@notified > 1) {
                   10137:             $notifylist = join(',',@notified);
                   10138:         } else {
                   10139:             $notifylist = $notified[0];
                   10140:         }
                   10141:         $cenv{'internal.notifylist'} = $notifylist;
                   10142:     }
                   10143:     if (@badclasses > 0) {
                   10144:         my %lt=&Apache::lonlocal::texthash(
                   10145:                 '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',
                   10146:                 'dnhr' => 'does not have rights to access enrollment in these classes',
                   10147:                 'adby' => 'as determined by the policies of your institution on access to official classlists'
                   10148:         );
1.541     raeburn  10149:         my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
                   10150:                            ' ('.$lt{'adby'}.')';
                   10151:         if ($context eq 'auto') {
                   10152:             $outcome .= $badclass_msg.$linefeed;
1.566     albertel 10153:             $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541     raeburn  10154:             foreach my $item (@badclasses) {
                   10155:                 if ($context eq 'auto') {
                   10156:                     $outcome .= " - $item\n";
                   10157:                 } else {
                   10158:                     $outcome .= "<li>$item</li>\n";
                   10159:                 }
                   10160:             }
                   10161:             if ($context eq 'auto') {
                   10162:                 $outcome .= $linefeed;
                   10163:             } else {
1.566     albertel 10164:                 $outcome .= "</ul><br /><br /></div>\n";
1.541     raeburn  10165:             }
                   10166:         } 
1.444     albertel 10167:     }
                   10168:     if ($args->{'no_end_date'}) {
                   10169:         $args->{'endaccess'} = 0;
                   10170:     }
                   10171:     $cenv{'internal.autostart'}=$args->{'enrollstart'};
                   10172:     $cenv{'internal.autoend'}=$args->{'enrollend'};
                   10173:     $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
                   10174:     $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
                   10175:     if ($args->{'showphotos'}) {
                   10176:       $cenv{'internal.showphotos'}=$args->{'showphotos'};
                   10177:     }
                   10178:     $cenv{'internal.authtype'} = $args->{'authtype'};
                   10179:     $cenv{'internal.autharg'} = $args->{'autharg'}; 
                   10180:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
                   10181:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
1.541     raeburn  10182:             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'); 
                   10183:             if ($context eq 'auto') {
                   10184:                 $outcome .= $krb_msg;
                   10185:             } else {
1.566     albertel 10186:                 $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541     raeburn  10187:             }
                   10188:             $outcome .= $linefeed;
1.444     albertel 10189:         }
                   10190:     }
                   10191:     if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
                   10192:        if ($args->{'setpolicy'}) {
                   10193:            $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   10194:        }
                   10195:        if ($args->{'setcontent'}) {
                   10196:            $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   10197:        }
                   10198:     }
                   10199:     if ($args->{'reshome'}) {
                   10200: 	$cenv{'reshome'}=$args->{'reshome'}.'/';
                   10201: 	$cenv{'reshome'}=~s/\/+$/\//;
                   10202:     }
                   10203: #
                   10204: # course has keyed access
                   10205: #
                   10206:     if ($args->{'setkeys'}) {
                   10207:        $cenv{'keyaccess'}='yes';
                   10208:     }
                   10209: # if specified, key authority is not course, but user
                   10210: # only active if keyaccess is yes
                   10211:     if ($args->{'keyauth'}) {
1.487     albertel 10212: 	my ($user,$domain) = split(':',$args->{'keyauth'});
                   10213: 	$user = &LONCAPA::clean_username($user);
                   10214: 	$domain = &LONCAPA::clean_username($domain);
1.488     foxr     10215: 	if ($user ne '' && $domain ne '') {
1.487     albertel 10216: 	    $cenv{'keyauth'}=$user.':'.$domain;
1.444     albertel 10217: 	}
                   10218:     }
                   10219: 
                   10220:     if ($args->{'disresdis'}) {
                   10221:         $cenv{'pch.roles.denied'}='st';
                   10222:     }
                   10223:     if ($args->{'disablechat'}) {
                   10224:         $cenv{'plc.roles.denied'}='st';
                   10225:     }
                   10226: 
                   10227:     # Record we've not yet viewed the Course Initialization Helper for this 
                   10228:     # course
                   10229:     $cenv{'course.helper.not.run'} = 1;
                   10230:     #
                   10231:     # Use new Randomseed
                   10232:     #
                   10233:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
                   10234:     $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
                   10235:     #
                   10236:     # The encryption code and receipt prefix for this course
                   10237:     #
                   10238:     $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
                   10239:     $cenv{'internal.encpref'}=100+int(9*rand(99));
                   10240:     #
                   10241:     # By default, use standard grading
                   10242:     if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
                   10243: 
1.541     raeburn  10244:     $outcome .= $linefeed.&mt('Setting environment').': '.                 
                   10245:           &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 10246: #
                   10247: # Open all assignments
                   10248: #
                   10249:     if ($args->{'openall'}) {
                   10250:        my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
                   10251:        my %storecontent = ($storeunder         => time,
                   10252:                            $storeunder.'.type' => 'date_start');
                   10253:        
                   10254:        $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541     raeburn  10255:                  ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 10256:    }
                   10257: #
                   10258: # Set first page
                   10259: #
                   10260:     unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
                   10261: 	    || ($cloneid)) {
1.445     albertel 10262: 	use LONCAPA::map;
1.444     albertel 10263: 	$outcome .= &mt('Setting first resource').': ';
1.445     albertel 10264: 
                   10265: 	my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
                   10266:         my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
                   10267: 
1.444     albertel 10268:         $outcome .= ($fatal?$errtext:'read ok').' - ';
                   10269:         my $title; my $url;
                   10270:         if ($args->{'firstres'} eq 'syl') {
1.690     bisitz   10271: 	    $title=&mt('Syllabus');
1.444     albertel 10272:             $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
                   10273:         } else {
1.690     bisitz   10274:             $title=&mt('Navigate Contents');
1.444     albertel 10275:             $url='/adm/navmaps';
                   10276:         }
1.445     albertel 10277: 
                   10278:         $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
                   10279: 	(my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
                   10280: 
                   10281: 	if ($errtext) { $fatal=2; }
1.541     raeburn  10282:         $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444     albertel 10283:     }
1.566     albertel 10284: 
                   10285:     return (1,$outcome);
1.444     albertel 10286: }
                   10287: 
                   10288: ############################################################
                   10289: ############################################################
                   10290: 
1.378     raeburn  10291: sub course_type {
                   10292:     my ($cid) = @_;
                   10293:     if (!defined($cid)) {
                   10294:         $cid = $env{'request.course.id'};
                   10295:     }
1.404     albertel 10296:     if (defined($env{'course.'.$cid.'.type'})) {
                   10297:         return $env{'course.'.$cid.'.type'};
1.378     raeburn  10298:     } else {
                   10299:         return 'Course';
1.377     raeburn  10300:     }
                   10301: }
1.156     albertel 10302: 
1.406     raeburn  10303: sub group_term {
                   10304:     my $crstype = &course_type();
                   10305:     my %names = (
                   10306:                   'Course' => 'group',
1.865     raeburn  10307:                   'Community' => 'group',
1.406     raeburn  10308:                 );
                   10309:     return $names{$crstype};
                   10310: }
                   10311: 
1.902     raeburn  10312: sub course_types {
                   10313:     my @types = ('official','unofficial','community');
                   10314:     my %typename = (
                   10315:                          official   => 'Official course',
                   10316:                          unofficial => 'Unofficial course',
                   10317:                          community  => 'Community',
                   10318:                    );
                   10319:     return (\@types,\%typename);
                   10320: }
                   10321: 
1.156     albertel 10322: sub icon {
                   10323:     my ($file)=@_;
1.505     albertel 10324:     my $curfext = lc((split(/\./,$file))[-1]);
1.168     albertel 10325:     my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156     albertel 10326:     my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168     albertel 10327:     if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
                   10328: 	if (-e  $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
                   10329: 	          $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   10330: 	            $curfext.".gif") {
                   10331: 	    $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   10332: 		$curfext.".gif";
                   10333: 	}
                   10334:     }
1.249     albertel 10335:     return &lonhttpdurl($iconname);
1.154     albertel 10336: } 
1.84      albertel 10337: 
1.575     albertel 10338: sub lonhttpdurl {
1.692     www      10339: #
                   10340: # Had been used for "small fry" static images on separate port 8080.
                   10341: # Modify here if lightweight http functionality desired again.
                   10342: # Currently eliminated due to increasing firewall issues.
                   10343: #
1.575     albertel 10344:     my ($url)=@_;
1.692     www      10345:     return $url;
1.215     albertel 10346: }
                   10347: 
1.213     albertel 10348: sub connection_aborted {
                   10349:     my ($r)=@_;
                   10350:     $r->print(" ");$r->rflush();
                   10351:     my $c = $r->connection;
                   10352:     return $c->aborted();
                   10353: }
                   10354: 
1.221     foxr     10355: #    Escapes strings that may have embedded 's that will be put into
1.222     foxr     10356: #    strings as 'strings'.
                   10357: sub escape_single {
1.221     foxr     10358:     my ($input) = @_;
1.223     albertel 10359:     $input =~ s/\\/\\\\/g;	# Escape the \'s..(must be first)>
1.221     foxr     10360:     $input =~ s/\'/\\\'/g;	# Esacpe the 's....
                   10361:     return $input;
                   10362: }
1.223     albertel 10363: 
1.222     foxr     10364: #  Same as escape_single, but escape's "'s  This 
                   10365: #  can be used for  "strings"
                   10366: sub escape_double {
                   10367:     my ($input) = @_;
                   10368:     $input =~ s/\\/\\\\/g;	# Escape the /'s..(must be first)>
                   10369:     $input =~ s/\"/\\\"/g;	# Esacpe the "s....
                   10370:     return $input;
                   10371: }
1.223     albertel 10372:  
1.222     foxr     10373: #   Escapes the last element of a full URL.
                   10374: sub escape_url {
                   10375:     my ($url)   = @_;
1.238     raeburn  10376:     my @urlslices = split(/\//, $url,-1);
1.369     www      10377:     my $lastitem = &escape(pop(@urlslices));
1.223     albertel 10378:     return join('/',@urlslices).'/'.$lastitem;
1.222     foxr     10379: }
1.462     albertel 10380: 
1.820     raeburn  10381: sub compare_arrays {
                   10382:     my ($arrayref1,$arrayref2) = @_;
                   10383:     my (@difference,%count);
                   10384:     @difference = ();
                   10385:     %count = ();
                   10386:     if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
                   10387:         foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
                   10388:         foreach my $element (keys(%count)) {
                   10389:             if ($count{$element} == 1) {
                   10390:                 push(@difference,$element);
                   10391:             }
                   10392:         }
                   10393:     }
                   10394:     return @difference;
                   10395: }
                   10396: 
1.817     bisitz   10397: # -------------------------------------------------------- Initialize user login
1.462     albertel 10398: sub init_user_environment {
1.463     albertel 10399:     my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462     albertel 10400:     my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
                   10401: 
                   10402:     my $public=($username eq 'public' && $domain eq 'public');
                   10403: 
                   10404: # See if old ID present, if so, remove
                   10405: 
                   10406:     my ($filename,$cookie,$userroles);
                   10407:     my $now=time;
                   10408: 
                   10409:     if ($public) {
                   10410: 	my $max_public=100;
                   10411: 	my $oldest;
                   10412: 	my $oldest_time=0;
                   10413: 	for(my $next=1;$next<=$max_public;$next++) {
                   10414: 	    if (-e $lonids."/publicuser_$next.id") {
                   10415: 		my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
                   10416: 		if ($mtime<$oldest_time || !$oldest_time) {
                   10417: 		    $oldest_time=$mtime;
                   10418: 		    $oldest=$next;
                   10419: 		}
                   10420: 	    } else {
                   10421: 		$cookie="publicuser_$next";
                   10422: 		last;
                   10423: 	    }
                   10424: 	}
                   10425: 	if (!$cookie) { $cookie="publicuser_$oldest"; }
                   10426:     } else {
1.463     albertel 10427: 	# if this isn't a robot, kill any existing non-robot sessions
                   10428: 	if (!$args->{'robot'}) {
                   10429: 	    opendir(DIR,$lonids);
                   10430: 	    while ($filename=readdir(DIR)) {
                   10431: 		if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
                   10432: 		    unlink($lonids.'/'.$filename);
                   10433: 		}
1.462     albertel 10434: 	    }
1.463     albertel 10435: 	    closedir(DIR);
1.462     albertel 10436: 	}
                   10437: # Give them a new cookie
1.463     albertel 10438: 	my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684     www      10439: 		                   : $now.$$.int(rand(10000)));
1.463     albertel 10440: 	$cookie="$username\_$id\_$domain\_$authhost";
1.462     albertel 10441:     
                   10442: # Initialize roles
                   10443: 
                   10444: 	$userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
                   10445:     }
                   10446: # ------------------------------------ Check browser type and MathML capability
                   10447: 
                   10448:     my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   10449:         $clientunicode,$clientos) = &decode_user_agent($r);
                   10450: 
                   10451: # ------------------------------------------------------------- Get environment
                   10452: 
                   10453:     my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
                   10454:     my ($tmp) = keys(%userenv);
                   10455:     if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   10456: 	# default remote control to off
                   10457: 	if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
                   10458:     } else {
                   10459: 	undef(%userenv);
                   10460:     }
                   10461:     if (($userenv{'interface'}) && (!$form->{'interface'})) {
                   10462: 	$form->{'interface'}=$userenv{'interface'};
                   10463:     }
                   10464:     $env{'environment.remote'}=$userenv{'remote'};
                   10465:     if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
                   10466: 
                   10467: # --------------- Do not trust query string to be put directly into environment
1.817     bisitz   10468:     foreach my $option ('interface','localpath','localres') {
                   10469:         $form->{$option}=~s/[\n\r\=]//gs;
1.462     albertel 10470:     }
                   10471: # --------------------------------------------------------- Write first profile
                   10472: 
                   10473:     {
                   10474: 	my %initial_env = 
                   10475: 	    ("user.name"          => $username,
                   10476: 	     "user.domain"        => $domain,
                   10477: 	     "user.home"          => $authhost,
                   10478: 	     "browser.type"       => $clientbrowser,
                   10479: 	     "browser.version"    => $clientversion,
                   10480: 	     "browser.mathml"     => $clientmathml,
                   10481: 	     "browser.unicode"    => $clientunicode,
                   10482: 	     "browser.os"         => $clientos,
                   10483: 	     "server.domain"      => $Apache::lonnet::perlvar{'lonDefDomain'},
                   10484: 	     "request.course.fn"  => '',
                   10485: 	     "request.course.uri" => '',
                   10486: 	     "request.course.sec" => '',
                   10487: 	     "request.role"       => 'cm',
                   10488: 	     "request.role.adv"   => $env{'user.adv'},
                   10489: 	     "request.host"       => $ENV{'REMOTE_ADDR'},);
                   10490: 
                   10491:         if ($form->{'localpath'}) {
                   10492: 	    $initial_env{"browser.localpath"}  = $form->{'localpath'};
                   10493: 	    $initial_env{"browser.localres"}   = $form->{'localres'};
                   10494:         }
                   10495: 	
                   10496: 	if ($public) {
                   10497: 	    $initial_env{"environment.remote"} = "off";
                   10498: 	}
                   10499: 	if ($form->{'interface'}) {
                   10500: 	    $form->{'interface'}=~s/\W//gs;
                   10501: 	    $initial_env{"browser.interface"} = $form->{'interface'};
                   10502: 	    $env{'browser.interface'}=$form->{'interface'};
                   10503: 	}
                   10504: 
1.724     raeburn  10505:         foreach my $tool ('aboutme','blog','portfolio') {
                   10506:             $userenv{'availabletools.'.$tool} = 
                   10507:                 &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
                   10508:         }
                   10509: 
1.864     raeburn  10510:         foreach my $crstype ('official','unofficial','community') {
1.765     raeburn  10511:             $userenv{'canrequest.'.$crstype} =
                   10512:                 &Apache::lonnet::usertools_access($username,$domain,$crstype,
                   10513:                                                   'reload','requestcourses');
                   10514:         }
                   10515: 
1.462     albertel 10516: 	$env{'user.environment'} = "$lonids/$cookie.id";
                   10517: 	
                   10518: 	if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
                   10519: 		 &GDBM_WRCREAT(),0640)) {
                   10520: 	    &_add_to_env(\%disk_env,\%initial_env);
                   10521: 	    &_add_to_env(\%disk_env,\%userenv,'environment.');
                   10522: 	    &_add_to_env(\%disk_env,$userroles);
1.463     albertel 10523: 	    if (ref($args->{'extra_env'})) {
                   10524: 		&_add_to_env(\%disk_env,$args->{'extra_env'});
                   10525: 	    }
1.462     albertel 10526: 	    untie(%disk_env);
                   10527: 	} else {
1.705     tempelho 10528: 	    &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
                   10529: 			   'Could not create environment storage in lonauth: '.$!.'</span>');
1.462     albertel 10530: 	    return 'error: '.$!;
                   10531: 	}
                   10532:     }
                   10533:     $env{'request.role'}='cm';
                   10534:     $env{'request.role.adv'}=$env{'user.adv'};
                   10535:     $env{'browser.type'}=$clientbrowser;
                   10536: 
                   10537:     return $cookie;
                   10538: 
                   10539: }
                   10540: 
                   10541: sub _add_to_env {
                   10542:     my ($idf,$env_data,$prefix) = @_;
1.676     raeburn  10543:     if (ref($env_data) eq 'HASH') {
                   10544:         while (my ($key,$value) = each(%$env_data)) {
                   10545: 	    $idf->{$prefix.$key} = $value;
                   10546: 	    $env{$prefix.$key}   = $value;
                   10547:         }
1.462     albertel 10548:     }
                   10549: }
                   10550: 
1.685     tempelho 10551: # --- Get the symbolic name of a problem and the url
                   10552: sub get_symb {
                   10553:     my ($request,$silent) = @_;
1.726     raeburn  10554:     (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685     tempelho 10555:     my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
                   10556:     if ($symb eq '') {
                   10557:         if (!$silent) {
                   10558:             $request->print("Unable to handle ambiguous references:$url:.");
                   10559:             return ();
                   10560:         }
                   10561:     }
                   10562:     &Apache::lonenc::check_decrypt(\$symb);
                   10563:     return ($symb);
                   10564: }
                   10565: 
                   10566: # --------------------------------------------------------------Get annotation
                   10567: 
                   10568: sub get_annotation {
                   10569:     my ($symb,$enc) = @_;
                   10570: 
                   10571:     my $key = $symb;
                   10572:     if (!$enc) {
                   10573:         $key =
                   10574:             &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
                   10575:     }
                   10576:     my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
                   10577:     return $annotation{$key};
                   10578: }
                   10579: 
                   10580: sub clean_symb {
1.731     raeburn  10581:     my ($symb,$delete_enc) = @_;
1.685     tempelho 10582: 
                   10583:     &Apache::lonenc::check_decrypt(\$symb);
                   10584:     my $enc = $env{'request.enc'};
1.731     raeburn  10585:     if ($delete_enc) {
1.730     raeburn  10586:         delete($env{'request.enc'});
                   10587:     }
1.685     tempelho 10588: 
                   10589:     return ($symb,$enc);
                   10590: }
1.462     albertel 10591: 
1.41      ng       10592: =pod
                   10593: 
                   10594: =back
                   10595: 
1.112     bowersj2 10596: =cut
1.41      ng       10597: 
1.112     bowersj2 10598: 1;
                   10599: __END__;
1.41      ng       10600: 

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