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

1.10      albertel    1: # The LearningOnline Network with CAPA
1.1       albertel    2: # a pile of common routines
1.10      albertel    3: #
1.795   ! www         4: # $Id: loncommon.pm,v 1.794 2009/04/24 13:02:09 www Exp $
1.10      albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
1.1       albertel   28: 
                     29: # Makes a table out of the previous attempts
1.2       albertel   30: # Inputs result_from_symbread, user, domain, course_id
1.16      harris41   31: # Reads in non-network-related .tab files
1.1       albertel   32: 
1.35      matthew    33: # POD header:
                     34: 
1.45      matthew    35: =pod
                     36: 
1.35      matthew    37: =head1 NAME
                     38: 
                     39: Apache::loncommon - pile of common routines
                     40: 
                     41: =head1 SYNOPSIS
                     42: 
1.112     bowersj2   43: Common routines for manipulating connections, student answers,
                     44:     domains, common Javascript fragments, etc.
1.35      matthew    45: 
1.112     bowersj2   46: =head1 OVERVIEW
1.35      matthew    47: 
1.112     bowersj2   48: A collection of commonly used subroutines that don't have a natural
                     49: home anywhere else. This collection helps remove
1.35      matthew    50: redundancy from other modules and increase efficiency of memory usage.
                     51: 
                     52: =cut 
                     53: 
                     54: # End of POD header
1.1       albertel   55: package Apache::loncommon;
                     56: 
                     57: use strict;
1.258     albertel   58: use Apache::lonnet;
1.46      matthew    59: use GDBM_File;
1.51      www        60: use POSIX qw(strftime mktime);
1.82      www        61: use Apache::lonmenu();
1.498     albertel   62: use Apache::lonenc();
1.117     www        63: use Apache::lonlocal;
1.685     tempelho   64: use Apache::lonnet();
1.139     matthew    65: use HTML::Entities;
1.334     albertel   66: use Apache::lonhtmlcommon();
                     67: use Apache::loncoursedata();
1.344     albertel   68: use Apache::lontexconvert();
1.444     albertel   69: use Apache::lonclonecourse();
1.479     albertel   70: use LONCAPA qw(:DEFAULT :match);
1.657     raeburn    71: use DateTime::TimeZone;
1.687     raeburn    72: use DateTime::Locale::Catalog;
1.117     www        73: 
1.517     raeburn    74: # ---------------------------------------------- Designs
                     75: use vars qw(%defaultdesign);
                     76: 
1.22      www        77: my $readit;
                     78: 
1.517     raeburn    79: 
1.157     matthew    80: ##
                     81: ## Global Variables
                     82: ##
1.46      matthew    83: 
1.643     foxr       84: 
                     85: # ----------------------------------------------- SSI with retries:
                     86: #
                     87: 
                     88: =pod
                     89: 
1.648     raeburn    90: =head1 Server Side include with retries:
1.643     foxr       91: 
                     92: =over 4
                     93: 
1.648     raeburn    94: =item * &ssi_with_retries(resource,retries form)
1.643     foxr       95: 
                     96: Performs an ssi with some number of retries.  Retries continue either
                     97: until the result is ok or until the retry count supplied by the
                     98: caller is exhausted.  
                     99: 
                    100: Inputs:
1.648     raeburn   101: 
                    102: =over 4
                    103: 
1.643     foxr      104: resource   - Identifies the resource to insert.
1.648     raeburn   105: 
1.643     foxr      106: retries    - Count of the number of retries allowed.
1.648     raeburn   107: 
1.643     foxr      108: form       - Hash that identifies the rendering options.
                    109: 
1.648     raeburn   110: =back
                    111: 
                    112: Returns:
                    113: 
                    114: =over 4
                    115: 
1.643     foxr      116: content    - The content of the response.  If retries were exhausted this is empty.
1.648     raeburn   117: 
1.643     foxr      118: response   - The response from the last attempt (which may or may not have been successful.
                    119: 
1.648     raeburn   120: =back
                    121: 
                    122: =back
                    123: 
1.643     foxr      124: =cut
                    125: 
                    126: sub ssi_with_retries {
                    127:     my ($resource, $retries, %form) = @_;
                    128: 
                    129: 
                    130:     my $ok = 0;			# True if we got a good response.
                    131:     my $content;
                    132:     my $response;
                    133: 
                    134:     # Try to get the ssi done. within the retries count:
                    135: 
                    136:     do {
                    137: 	($content, $response) = &Apache::lonnet::ssi($resource, %form);
                    138: 	$ok      = $response->is_success;
1.650     www       139:         if (!$ok) {
                    140:             &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
                    141:         }
1.643     foxr      142: 	$retries--;
                    143:     } while (!$ok && ($retries > 0));
                    144: 
                    145:     if (!$ok) {
                    146: 	$content = '';		# On error return an empty content.
                    147:     }
                    148:     return ($content, $response);
                    149: 
                    150: }
                    151: 
                    152: 
                    153: 
1.20      www       154: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12      harris41  155: my %language;
1.124     www       156: my %supported_language;
1.12      harris41  157: my %cprtag;
1.192     taceyjo1  158: my %scprtag;
1.351     www       159: my %fe; my %fd; my %fm;
1.41      ng        160: my %category_extensions;
1.12      harris41  161: 
1.46      matthew   162: # ---------------------------------------------- Thesaurus variables
1.144     matthew   163: #
                    164: # %Keywords:
                    165: #      A hash used by &keyword to determine if a word is considered a keyword.
                    166: # $thesaurus_db_file 
                    167: #      Scalar containing the full path to the thesaurus database.
1.46      matthew   168: 
                    169: my %Keywords;
                    170: my $thesaurus_db_file;
                    171: 
1.144     matthew   172: #
                    173: # Initialize values from language.tab, copyright.tab, filetypes.tab,
                    174: # thesaurus.tab, and filecategories.tab.
                    175: #
1.18      www       176: BEGIN {
1.46      matthew   177:     # Variable initialization
                    178:     $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
                    179:     #
1.22      www       180:     unless ($readit) {
1.12      harris41  181: # ------------------------------------------------------------------- languages
                    182:     {
1.158     raeburn   183:         my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    184:                                    '/language.tab';
                    185:         if ( open(my $fh,"<$langtabfile") ) {
1.356     albertel  186:             while (my $line = <$fh>) {
                    187:                 next if ($line=~/^\#/);
                    188:                 chomp($line);
                    189:                 my ($key,$two,$country,$three,$enc,$val,$sup)=(split(/\t/,$line));
1.158     raeburn   190:                 $language{$key}=$val.' - '.$enc;
                    191:                 if ($sup) {
                    192:                     $supported_language{$key}=$sup;
                    193:                 }
                    194:             }
                    195:             close($fh);
                    196:         }
1.12      harris41  197:     }
                    198: # ------------------------------------------------------------------ copyrights
                    199:     {
1.158     raeburn   200:         my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
                    201:                                   '/copyright.tab';
                    202:         if ( open (my $fh,"<$copyrightfile") ) {
1.356     albertel  203:             while (my $line = <$fh>) {
                    204:                 next if ($line=~/^\#/);
                    205:                 chomp($line);
                    206:                 my ($key,$val)=(split(/\s+/,$line,2));
1.158     raeburn   207:                 $cprtag{$key}=$val;
                    208:             }
                    209:             close($fh);
                    210:         }
1.12      harris41  211:     }
1.351     www       212: # ----------------------------------------------------------- source copyrights
1.192     taceyjo1  213:     {
                    214:         my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
                    215:                                   '/source_copyright.tab';
                    216:         if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356     albertel  217:             while (my $line = <$fh>) {
                    218:                 next if ($line =~ /^\#/);
                    219:                 chomp($line);
                    220:                 my ($key,$val)=(split(/\s+/,$line,2));
1.192     taceyjo1  221:                 $scprtag{$key}=$val;
                    222:             }
                    223:             close($fh);
                    224:         }
                    225:     }
1.63      www       226: 
1.517     raeburn   227: # -------------------------------------------------------------- default domain designs
1.63      www       228:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517     raeburn   229:     my $designfile = $designdir.'/default.tab';
                    230:     if ( open (my $fh,"<$designfile") ) {
                    231:         while (my $line = <$fh>) {
                    232:             next if ($line =~ /^\#/);
                    233:             chomp($line);
                    234:             my ($key,$val)=(split(/\=/,$line));
                    235:             if ($val) { $defaultdesign{$key}=$val; }
                    236:         }
                    237:         close($fh);
1.63      www       238:     }
                    239: 
1.15      harris41  240: # ------------------------------------------------------------- file categories
                    241:     {
1.158     raeburn   242:         my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    243:                                   '/filecategories.tab';
                    244:         if ( open (my $fh,"<$categoryfile") ) {
1.356     albertel  245: 	    while (my $line = <$fh>) {
                    246: 		next if ($line =~ /^\#/);
                    247: 		chomp($line);
                    248:                 my ($extension,$category)=(split(/\s+/,$line,2));
1.158     raeburn   249:                 push @{$category_extensions{lc($category)}},$extension;
                    250:             }
                    251:             close($fh);
                    252:         }
                    253: 
1.15      harris41  254:     }
1.12      harris41  255: # ------------------------------------------------------------------ file types
                    256:     {
1.158     raeburn   257:         my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
                    258:                '/filetypes.tab';
                    259:         if ( open (my $fh,"<$typesfile") ) {
1.356     albertel  260:             while (my $line = <$fh>) {
                    261: 		next if ($line =~ /^\#/);
                    262: 		chomp($line);
                    263:                 my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158     raeburn   264:                 if ($descr ne '') {
                    265:                     $fe{$ending}=lc($emb);
                    266:                     $fd{$ending}=$descr;
1.351     www       267:                     if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158     raeburn   268:                 }
                    269:             }
                    270:             close($fh);
                    271:         }
1.12      harris41  272:     }
1.22      www       273:     &Apache::lonnet::logthis(
1.705     tempelho  274:              "<span style='color:yellow;'>INFO: Read file types</span>");
1.22      www       275:     $readit=1;
1.46      matthew   276:     }  # end of unless($readit) 
1.32      matthew   277:     
                    278: }
1.112     bowersj2  279: 
1.42      matthew   280: ###############################################################
                    281: ##           HTML and Javascript Helper Functions            ##
                    282: ###############################################################
                    283: 
                    284: =pod 
                    285: 
1.112     bowersj2  286: =head1 HTML and Javascript Functions
1.42      matthew   287: 
1.112     bowersj2  288: =over 4
                    289: 
1.648     raeburn   290: =item * &browser_and_searcher_javascript()
1.112     bowersj2  291: 
                    292: X<browsing, javascript>X<searching, javascript>Returns a string
                    293: containing javascript with two functions, C<openbrowser> and
                    294: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
                    295: tags.
1.42      matthew   296: 
1.648     raeburn   297: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42      matthew   298: 
                    299: inputs: formname, elementname, only, omit
                    300: 
                    301: formname and elementname indicate the name of the html form and name of
                    302: the element that the results of the browsing selection are to be placed in. 
                    303: 
                    304: Specifying 'only' will restrict the browser to displaying only files
1.185     www       305: with the given extension.  Can be a comma separated list.
1.42      matthew   306: 
                    307: Specifying 'omit' will restrict the browser to NOT displaying files
1.185     www       308: with the given extension.  Can be a comma separated list.
1.42      matthew   309: 
1.648     raeburn   310: =item * &opensearcher(formname,elementname) [javascript]
1.42      matthew   311: 
                    312: Inputs: formname, elementname
                    313: 
                    314: formname and elementname specify the name of the html form and the name
                    315: of the element the selection from the search results will be placed in.
1.542     raeburn   316: 
1.42      matthew   317: =cut
                    318: 
                    319: sub browser_and_searcher_javascript {
1.199     albertel  320:     my ($mode)=@_;
                    321:     if (!defined($mode)) { $mode='edit'; }
1.453     albertel  322:     my $resurl=&escape_single(&lastresurl());
1.42      matthew   323:     return <<END;
1.219     albertel  324: // <!-- BEGIN LON-CAPA Internal
1.50      matthew   325:     var editbrowser = null;
1.135     albertel  326:     function openbrowser(formname,elementname,only,omit,titleelement) {
1.170     www       327:         var url = '$resurl/?';
1.42      matthew   328:         if (editbrowser == null) {
                    329:             url += 'launch=1&';
                    330:         }
                    331:         url += 'catalogmode=interactive&';
1.199     albertel  332:         url += 'mode=$mode&';
1.611     albertel  333:         url += 'inhibitmenu=yes&';
1.42      matthew   334:         url += 'form=' + formname + '&';
                    335:         if (only != null) {
                    336:             url += 'only=' + only + '&';
1.217     albertel  337:         } else {
                    338:             url += 'only=&';
                    339: 	}
1.42      matthew   340:         if (omit != null) {
                    341:             url += 'omit=' + omit + '&';
1.217     albertel  342:         } else {
                    343:             url += 'omit=&';
                    344: 	}
1.135     albertel  345:         if (titleelement != null) {
                    346:             url += 'titleelement=' + titleelement + '&';
1.217     albertel  347:         } else {
                    348: 	    url += 'titleelement=&';
                    349: 	}
1.42      matthew   350:         url += 'element=' + elementname + '';
                    351:         var title = 'Browser';
1.435     albertel  352:         var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42      matthew   353:         options += ',width=700,height=600';
                    354:         editbrowser = open(url,title,options,'1');
                    355:         editbrowser.focus();
                    356:     }
                    357:     var editsearcher;
1.135     albertel  358:     function opensearcher(formname,elementname,titleelement) {
1.42      matthew   359:         var url = '/adm/searchcat?';
                    360:         if (editsearcher == null) {
                    361:             url += 'launch=1&';
                    362:         }
                    363:         url += 'catalogmode=interactive&';
1.199     albertel  364:         url += 'mode=$mode&';
1.42      matthew   365:         url += 'form=' + formname + '&';
1.135     albertel  366:         if (titleelement != null) {
                    367:             url += 'titleelement=' + titleelement + '&';
1.217     albertel  368:         } else {
                    369: 	    url += 'titleelement=&';
                    370: 	}
1.42      matthew   371:         url += 'element=' + elementname + '';
                    372:         var title = 'Search';
1.435     albertel  373:         var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42      matthew   374:         options += ',width=700,height=600';
                    375:         editsearcher = open(url,title,options,'1');
                    376:         editsearcher.focus();
                    377:     }
1.219     albertel  378: // END LON-CAPA Internal -->
1.42      matthew   379: END
1.170     www       380: }
                    381: 
                    382: sub lastresurl {
1.258     albertel  383:     if ($env{'environment.lastresurl'}) {
                    384: 	return $env{'environment.lastresurl'}
1.170     www       385:     } else {
                    386: 	return '/res';
                    387:     }
                    388: }
                    389: 
                    390: sub storeresurl {
                    391:     my $resurl=&Apache::lonnet::clutter(shift);
                    392:     unless ($resurl=~/^\/res/) { return 0; }
                    393:     $resurl=~s/\/$//;
                    394:     &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646     raeburn   395:     &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170     www       396:     return 1;
1.42      matthew   397: }
                    398: 
1.74      www       399: sub studentbrowser_javascript {
1.111     www       400:    unless (
1.258     albertel  401:             (($env{'request.course.id'}) && 
1.302     albertel  402:              (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    403: 	      || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                    404: 					  '/'.$env{'request.course.sec'})
                    405: 	      ))
1.258     albertel  406:          || ($env{'request.role'}=~/^(au|dc|su)/)
1.111     www       407:           ) { return ''; }  
1.74      www       408:    return (<<'ENDSTDBRW');
1.776     bisitz    409: <script type="text/javascript" language="Javascript">
1.74      www       410:     var stdeditbrowser;
1.793     raeburn   411:     function openstdbrowser(formname,uname,udom,roleflag,ignorefilter,courseadvonly) {
1.74      www       412:         var url = '/adm/pickstudent?';
                    413:         var filter;
1.558     albertel  414: 	if (!ignorefilter) {
                    415: 	    eval('filter=document.'+formname+'.'+uname+'.value;');
                    416: 	}
1.74      www       417:         if (filter != null) {
                    418:            if (filter != '') {
                    419:                url += 'filter='+filter+'&';
                    420: 	   }
                    421:         }
                    422:         url += 'form=' + formname + '&unameelement='+uname+
                    423:                                     '&udomelement='+udom;
1.111     www       424: 	if (roleflag) { url+="&roles=1"; }
1.793     raeburn   425:         if (courseadvonly) { url+="&courseadvonly=1"; }
1.102     www       426:         var title = 'Student_Browser';
1.74      www       427:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    428:         options += ',width=700,height=600';
                    429:         stdeditbrowser = open(url,title,options,'1');
                    430:         stdeditbrowser.focus();
                    431:     }
                    432: </script>
                    433: ENDSTDBRW
                    434: }
1.42      matthew   435: 
1.74      www       436: sub selectstudent_link {
1.793     raeburn   437:    my ($form,$unameele,$udomele,$courseadvonly)=@_;
                    438:    my $callargs = "'".$form."','".$unameele."','".$udomele."'";
1.258     albertel  439:    if ($env{'request.course.id'}) {  
1.302     albertel  440:        if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    441: 	   && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                    442: 					'/'.$env{'request.course.sec'})) {
1.111     www       443: 	   return '';
                    444:        }
1.793     raeburn   445:        if ($courseadvonly)  {
                    446:            $callargs .= ",'',1,1";
                    447:        }
                    448:        return '<span class="LC_nobreak">'.
                    449:               '<a href="javascript:openstdbrowser('.$callargs.');">'.
                    450:               &mt('Select User').'</a></span>';
1.74      www       451:    }
1.258     albertel  452:    if ($env{'request.role'}=~/^(au|dc|su)/) {
1.793     raeburn   453:        $callargs .= ",1"; 
                    454:        return '<span class="LC_nobreak">'.
                    455:               '<a href="javascript:openstdbrowser('.$callargs.');">'.
                    456:               &mt('Select User').'</a></span>';
1.111     www       457:    }
                    458:    return '';
1.91      www       459: }
                    460: 
1.653     raeburn   461: sub authorbrowser_javascript {
                    462:     return <<"ENDAUTHORBRW";
1.776     bisitz    463: <script type="text/javascript" language="JavaScript">
1.653     raeburn   464: var stdeditbrowser;
                    465: 
                    466: function openauthorbrowser(formname,udom) {
                    467:     var url = '/adm/pickauthor?';
                    468:     url += 'form='+formname+'&roledom='+udom;
                    469:     var title = 'Author_Browser';
                    470:     var options = 'scrollbars=1,resizable=1,menubar=0';
                    471:     options += ',width=700,height=600';
                    472:     stdeditbrowser = open(url,title,options,'1');
                    473:     stdeditbrowser.focus();
                    474: }
                    475: 
                    476: </script>
                    477: ENDAUTHORBRW
                    478: }
                    479: 
1.91      www       480: sub coursebrowser_javascript {
1.468     raeburn   481:     my ($domainfilter,$sec_element,$formname)=@_;
1.377     raeburn   482:     my $crs_or_grp_alert = &mt('Please select the type of LON-CAPA entity - Course or Group - for which you wish to add/modify a user role');
1.468     raeburn   483:    my $output = '
1.776     bisitz    484: <script type="text/javascript" language="JavaScript">
1.468     raeburn   485:     var stdeditbrowser;'."\n";
                    486:    $output .= <<"ENDSTDBRW";
1.377     raeburn   487:     function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
1.91      www       488:         var url = '/adm/pickcourse?';
1.468     raeburn   489:         var domainfilter = '';
                    490:         var formid = getFormIdByName(formname);
                    491:         if (formid > -1) {
                    492:             var domid = getIndexByName(formid,udom);
                    493:             if (domid > -1) {
                    494:                 if (document.forms[formid].elements[domid].type == 'select-one') {
                    495:                     domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
                    496:                 }
                    497:                 if (document.forms[formid].elements[domid].type == 'hidden') {
                    498:                     domainfilter=document.forms[formid].elements[domid].value;
                    499:                 }
                    500:             }
1.91      www       501:         }
1.128     albertel  502:         if (domainfilter != null) {
                    503:            if (domainfilter != '') {
                    504:                url += 'domainfilter='+domainfilter+'&';
                    505: 	   }
                    506:         }
1.91      www       507:         url += 'form=' + formname + '&cnumelement='+uname+
1.187     albertel  508: 	                            '&cdomelement='+udom+
                    509:                                     '&cnameelement='+desc;
1.468     raeburn   510:         if (extra_element !=null && extra_element != '') {
1.594     raeburn   511:             if (formname == 'rolechoice' || formname == 'studentform') {
1.468     raeburn   512:                 url += '&roleelement='+extra_element;
                    513:                 if (domainfilter == null || domainfilter == '') {
                    514:                     url += '&domainfilter='+extra_element;
                    515:                 }
1.234     raeburn   516:             }
1.468     raeburn   517:             else {
                    518:                 if (formname == 'portform') {
                    519:                     url += '&setroles='+extra_element;
                    520:                 }
                    521:             }     
1.230     raeburn   522:         }
1.293     raeburn   523:         if (multflag !=null && multflag != '') {
                    524:             url += '&multiple='+multflag;
                    525:         }
1.377     raeburn   526:         if (crstype == 'Course/Group') {
                    527:             if (formname == 'cu') {
                    528:                 crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value; 
                    529:                 if (crstype == "") {
                    530:                     alert("$crs_or_grp_alert");
                    531:                     return;
                    532:                 }
                    533:             }
                    534:         }
                    535:         if (crstype !=null && crstype != '') {
                    536:             url += '&type='+crstype;
                    537:         }
1.102     www       538:         var title = 'Course_Browser';
1.91      www       539:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    540:         options += ',width=700,height=600';
                    541:         stdeditbrowser = open(url,title,options,'1');
                    542:         stdeditbrowser.focus();
                    543:     }
1.468     raeburn   544: 
                    545:     function getFormIdByName(formname) {
                    546:         for (var i=0;i<document.forms.length;i++) {
                    547:             if (document.forms[i].name == formname) {
                    548:                 return i;
                    549:             }
                    550:         }
                    551:         return -1; 
                    552:     }
                    553: 
                    554:     function getIndexByName(formid,item) {
                    555:         for (var i=0;i<document.forms[formid].elements.length;i++) {
                    556:             if (document.forms[formid].elements[i].name == item) {
                    557:                 return i;
                    558:             }
                    559:         }
                    560:         return -1;
                    561:     }
1.91      www       562: ENDSTDBRW
1.468     raeburn   563:     if ($sec_element ne '') {
                    564:         $output .= &setsec_javascript($sec_element,$formname);
                    565:     }
                    566:     $output .= '
                    567: </script>';
                    568:     return $output;
                    569: }
                    570: 
                    571: sub setsec_javascript {
                    572:     my ($sec_element,$formname) = @_;
                    573:     my $setsections = qq|
                    574: function setSect(sectionlist) {
1.629     raeburn   575:     var sectionsArray = new Array();
                    576:     if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
                    577:         sectionsArray = sectionlist.split(",");
                    578:     }
1.468     raeburn   579:     var numSections = sectionsArray.length;
                    580:     document.$formname.$sec_element.length = 0;
                    581:     if (numSections == 0) {
                    582:         document.$formname.$sec_element.multiple=false;
                    583:         document.$formname.$sec_element.size=1;
                    584:         document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
                    585:     } else {
                    586:         if (numSections == 1) {
                    587:             document.$formname.$sec_element.multiple=false;
                    588:             document.$formname.$sec_element.size=1;
                    589:             document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
                    590:             document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
                    591:             document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
                    592:         } else {
                    593:             for (var i=0; i<numSections; i++) {
                    594:                 document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
                    595:             }
                    596:             document.$formname.$sec_element.multiple=true
                    597:             if (numSections < 3) {
                    598:                 document.$formname.$sec_element.size=numSections;
                    599:             } else {
                    600:                 document.$formname.$sec_element.size=3;
                    601:             }
                    602:             document.$formname.$sec_element.options[0].selected = false
                    603:         }
                    604:     }
1.91      www       605: }
1.468     raeburn   606: |;
                    607:     return $setsections;
                    608: }
                    609: 
1.91      www       610: 
                    611: sub selectcourse_link {
1.377     raeburn   612:    my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.787     bisitz    613:    return '<span class="LC_nobreak">'
                    614:          ."<a href='"
                    615:          .'javascript:opencrsbrowser("'.$form.'","'.$unameele
                    616:          .'","'.$udomele.'","'.$desc.'","'.$extra_element
                    617:          .'","'.$multflag.'","'.$selecttype.'");'
                    618:          ."'>".&mt('Select Course').'</a>'
                    619:          .'</span>';
1.74      www       620: }
1.42      matthew   621: 
1.653     raeburn   622: sub selectauthor_link {
                    623:    my ($form,$udom)=@_;
                    624:    return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
                    625:           &mt('Select Author').'</a>';
                    626: }
                    627: 
1.273     raeburn   628: sub check_uncheck_jscript {
                    629:     my $jscript = <<"ENDSCRT";
                    630: function checkAll(field) {
                    631:     if (field.length > 0) {
                    632:         for (i = 0; i < field.length; i++) {
                    633:             field[i].checked = true ;
                    634:         }
                    635:     } else {
                    636:         field.checked = true
                    637:     }
                    638: }
                    639:  
                    640: function uncheckAll(field) {
                    641:     if (field.length > 0) {
                    642:         for (i = 0; i < field.length; i++) {
                    643:             field[i].checked = false ;
1.543     albertel  644:         }
                    645:     } else {
1.273     raeburn   646:         field.checked = false ;
                    647:     }
                    648: }
                    649: ENDSCRT
                    650:     return $jscript;
                    651: }
                    652: 
1.656     www       653: sub select_timezone {
1.659     raeburn   654:    my ($name,$selected,$onchange,$includeempty)=@_;
                    655:    my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    656:    if ($includeempty) {
                    657:        $output .= '<option value=""';
                    658:        if (($selected eq '') || ($selected eq 'local')) {
                    659:            $output .= ' selected="selected" ';
                    660:        }
                    661:        $output .= '> </option>';
                    662:    }
1.657     raeburn   663:    my @timezones = DateTime::TimeZone->all_names;
                    664:    foreach my $tzone (@timezones) {
                    665:        $output.= '<option value="'.$tzone.'"';
                    666:        if ($tzone eq $selected) {
                    667:            $output.=' selected="selected"';
                    668:        }
                    669:        $output.=">$tzone</option>\n";
1.656     www       670:    }
                    671:    $output.="</select>";
                    672:    return $output;
                    673: }
1.273     raeburn   674: 
1.687     raeburn   675: sub select_datelocale {
                    676:     my ($name,$selected,$onchange,$includeempty)=@_;
                    677:     my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    678:     if ($includeempty) {
                    679:         $output .= '<option value=""';
                    680:         if ($selected eq '') {
                    681:             $output .= ' selected="selected" ';
                    682:         }
                    683:         $output .= '> </option>';
                    684:     }
                    685:     my (@possibles,%locale_names);
                    686:     my @locales = DateTime::Locale::Catalog::Locales;
                    687:     foreach my $locale (@locales) {
                    688:         if (ref($locale) eq 'HASH') {
                    689:             my $id = $locale->{'id'};
                    690:             if ($id ne '') {
                    691:                 my $en_terr = $locale->{'en_territory'};
                    692:                 my $native_terr = $locale->{'native_territory'};
1.695     raeburn   693:                 my @languages = &Apache::lonlocal::preferred_languages();
1.687     raeburn   694:                 if (grep(/^en$/,@languages) || !@languages) {
                    695:                     if ($en_terr ne '') {
                    696:                         $locale_names{$id} = '('.$en_terr.')';
                    697:                     } elsif ($native_terr ne '') {
                    698:                         $locale_names{$id} = $native_terr;
                    699:                     }
                    700:                 } else {
                    701:                     if ($native_terr ne '') {
                    702:                         $locale_names{$id} = $native_terr.' ';
                    703:                     } elsif ($en_terr ne '') {
                    704:                         $locale_names{$id} = '('.$en_terr.')';
                    705:                     }
                    706:                 }
                    707:                 push (@possibles,$id);
                    708:             }
                    709:         }
                    710:     }
                    711:     foreach my $item (sort(@possibles)) {
                    712:         $output.= '<option value="'.$item.'"';
                    713:         if ($item eq $selected) {
                    714:             $output.=' selected="selected"';
                    715:         }
                    716:         $output.=">$item";
                    717:         if ($locale_names{$item} ne '') {
                    718:             $output.="  $locale_names{$item}</option>\n";
                    719:         }
                    720:         $output.="</option>\n";
                    721:     }
                    722:     $output.="</select>";
                    723:     return $output;
                    724: }
                    725: 
1.792     raeburn   726: sub select_language {
                    727:     my ($name,$selected,$includeempty) = @_;
                    728:     my %langchoices;
                    729:     if ($includeempty) {
                    730:         %langchoices = ('' => 'No language preference');
                    731:     }
                    732:     foreach my $id (&languageids()) {
                    733:         my $code = &supportedlanguagecode($id);
                    734:         if ($code) {
                    735:             $langchoices{$code} = &plainlanguagedescription($id);
                    736:         }
                    737:     }
                    738:     return &select_form($selected,$name,%langchoices);
                    739: }
                    740: 
1.42      matthew   741: =pod
1.36      matthew   742: 
1.648     raeburn   743: =item * &linked_select_forms(...)
1.36      matthew   744: 
                    745: linked_select_forms returns a string containing a <script></script> block
                    746: and html for two <select> menus.  The select menus will be linked in that
                    747: changing the value of the first menu will result in new values being placed
                    748: in the second menu.  The values in the select menu will appear in alphabetical
1.609     raeburn   749: order unless a defined order is provided.
1.36      matthew   750: 
                    751: linked_select_forms takes the following ordered inputs:
                    752: 
                    753: =over 4
                    754: 
1.112     bowersj2  755: =item * $formname, the name of the <form> tag
1.36      matthew   756: 
1.112     bowersj2  757: =item * $middletext, the text which appears between the <select> tags
1.36      matthew   758: 
1.112     bowersj2  759: =item * $firstdefault, the default value for the first menu
1.36      matthew   760: 
1.112     bowersj2  761: =item * $firstselectname, the name of the first <select> tag
1.36      matthew   762: 
1.112     bowersj2  763: =item * $secondselectname, the name of the second <select> tag
1.36      matthew   764: 
1.112     bowersj2  765: =item * $hashref, a reference to a hash containing the data for the menus.
1.36      matthew   766: 
1.609     raeburn   767: =item * $menuorder, the order of values in the first menu
                    768: 
1.41      ng        769: =back 
                    770: 
1.36      matthew   771: Below is an example of such a hash.  Only the 'text', 'default', and 
                    772: 'select2' keys must appear as stated.  keys(%menu) are the possible 
                    773: values for the first select menu.  The text that coincides with the 
1.41      ng        774: first menu value is given in $menu{$choice1}->{'text'}.  The values 
1.36      matthew   775: and text for the second menu are given in the hash pointed to by 
                    776: $menu{$choice1}->{'select2'}.  
                    777: 
1.112     bowersj2  778:  my %menu = ( A1 => { text =>"Choice A1" ,
                    779:                        default => "B3",
                    780:                        select2 => { 
                    781:                            B1 => "Choice B1",
                    782:                            B2 => "Choice B2",
                    783:                            B3 => "Choice B3",
                    784:                            B4 => "Choice B4"
1.609     raeburn   785:                            },
                    786:                        order => ['B4','B3','B1','B2'],
1.112     bowersj2  787:                    },
                    788:                A2 => { text =>"Choice A2" ,
                    789:                        default => "C2",
                    790:                        select2 => { 
                    791:                            C1 => "Choice C1",
                    792:                            C2 => "Choice C2",
                    793:                            C3 => "Choice C3"
1.609     raeburn   794:                            },
                    795:                        order => ['C2','C1','C3'],
1.112     bowersj2  796:                    },
                    797:                A3 => { text =>"Choice A3" ,
                    798:                        default => "D6",
                    799:                        select2 => { 
                    800:                            D1 => "Choice D1",
                    801:                            D2 => "Choice D2",
                    802:                            D3 => "Choice D3",
                    803:                            D4 => "Choice D4",
                    804:                            D5 => "Choice D5",
                    805:                            D6 => "Choice D6",
                    806:                            D7 => "Choice D7"
1.609     raeburn   807:                            },
                    808:                        order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112     bowersj2  809:                    }
                    810:                );
1.36      matthew   811: 
                    812: =cut
                    813: 
                    814: sub linked_select_forms {
                    815:     my ($formname,
                    816:         $middletext,
                    817:         $firstdefault,
                    818:         $firstselectname,
                    819:         $secondselectname, 
1.609     raeburn   820:         $hashref,
                    821:         $menuorder,
1.36      matthew   822:         ) = @_;
                    823:     my $second = "document.$formname.$secondselectname";
                    824:     my $first = "document.$formname.$firstselectname";
                    825:     # output the javascript to do the changing
                    826:     my $result = '';
1.776     bisitz    827:     $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.36      matthew   828:     $result.="var select2data = new Object();\n";
                    829:     $" = '","';
                    830:     my $debug = '';
                    831:     foreach my $s1 (sort(keys(%$hashref))) {
                    832:         $result.="select2data.d_$s1 = new Object();\n";        
                    833:         $result.="select2data.d_$s1.def = new String('".
                    834:             $hashref->{$s1}->{'default'}."');\n";
1.609     raeburn   835:         $result.="select2data.d_$s1.values = new Array(";
1.36      matthew   836:         my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609     raeburn   837:         if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
                    838:             @s2values = @{$hashref->{$s1}->{'order'}};
                    839:         }
1.36      matthew   840:         $result.="\"@s2values\");\n";
                    841:         $result.="select2data.d_$s1.texts = new Array(";        
                    842:         my @s2texts;
                    843:         foreach my $value (@s2values) {
                    844:             push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
                    845:         }
                    846:         $result.="\"@s2texts\");\n";
                    847:     }
                    848:     $"=' ';
                    849:     $result.= <<"END";
                    850: 
                    851: function select1_changed() {
                    852:     // Determine new choice
                    853:     var newvalue = "d_" + $first.value;
                    854:     // update select2
                    855:     var values     = select2data[newvalue].values;
                    856:     var texts      = select2data[newvalue].texts;
                    857:     var select2def = select2data[newvalue].def;
                    858:     var i;
                    859:     // out with the old
                    860:     for (i = 0; i < $second.options.length; i++) {
                    861:         $second.options[i] = null;
                    862:     }
                    863:     // in with the nuclear
                    864:     for (i=0;i<values.length; i++) {
                    865:         $second.options[i] = new Option(values[i]);
1.143     matthew   866:         $second.options[i].value = values[i];
1.36      matthew   867:         $second.options[i].text = texts[i];
                    868:         if (values[i] == select2def) {
                    869:             $second.options[i].selected = true;
                    870:         }
                    871:     }
                    872: }
                    873: </script>
                    874: END
                    875:     # output the initial values for the selection lists
                    876:     $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609     raeburn   877:     my @order = sort(keys(%{$hashref}));
                    878:     if (ref($menuorder) eq 'ARRAY') {
                    879:         @order = @{$menuorder};
                    880:     }
                    881:     foreach my $value (@order) {
1.36      matthew   882:         $result.="    <option value=\"$value\" ";
1.253     albertel  883:         $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119     www       884:         $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36      matthew   885:     }
                    886:     $result .= "</select>\n";
                    887:     my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
                    888:     $result .= $middletext;
                    889:     $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
                    890:     my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609     raeburn   891:     
                    892:     my @secondorder = sort(keys(%select2));
                    893:     if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
                    894:         @secondorder = @{$hashref->{$firstdefault}->{'order'}};
                    895:     }
                    896:     foreach my $value (@secondorder) {
1.36      matthew   897:         $result.="    <option value=\"$value\" ";        
1.253     albertel  898:         $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119     www       899:         $result.=">".&mt($select2{$value})."</option>\n";
1.36      matthew   900:     }
                    901:     $result .= "</select>\n";
                    902:     #    return $debug;
                    903:     return $result;
                    904: }   #  end of sub linked_select_forms {
                    905: 
1.45      matthew   906: =pod
1.44      bowersj2  907: 
1.648     raeburn   908: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44      bowersj2  909: 
1.112     bowersj2  910: Returns a string corresponding to an HTML link to the given help
                    911: $topic, where $topic corresponds to the name of a .tex file in
                    912: /home/httpd/html/adm/help/tex, with underscores replaced by
                    913: spaces. 
                    914: 
                    915: $text will optionally be linked to the same topic, allowing you to
                    916: link text in addition to the graphic. If you do not want to link
                    917: text, but wish to specify one of the later parameters, pass an
                    918: empty string. 
                    919: 
                    920: $stayOnPage is a value that will be interpreted as a boolean. If true,
                    921: the link will not open a new window. If false, the link will open
                    922: a new window using Javascript. (Default is false.) 
                    923: 
                    924: $width and $height are optional numerical parameters that will
                    925: override the width and height of the popped up window, which may
                    926: be useful for certain help topics with big pictures included. 
1.44      bowersj2  927: 
                    928: =cut
                    929: 
                    930: sub help_open_topic {
1.48      bowersj2  931:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
                    932:     $text = "" if (not defined $text);
1.44      bowersj2  933:     $stayOnPage = 0 if (not defined $stayOnPage);
1.552     banghart  934:     if ($env{'browser.interface'} eq 'textual') {
1.79      www       935: 	$stayOnPage=1;
                    936:     }
1.44      bowersj2  937:     $width = 350 if (not defined $width);
                    938:     $height = 400 if (not defined $height);
                    939:     my $filename = $topic;
                    940:     $filename =~ s/ /_/g;
                    941: 
1.48      bowersj2  942:     my $template = "";
                    943:     my $link;
1.572     banghart  944:     
1.159     www       945:     $topic=~s/\W/\_/g;
1.44      bowersj2  946: 
1.572     banghart  947:     if (!$stayOnPage) {
1.72      bowersj2  948: 	$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  949:     } else {
1.48      bowersj2  950: 	$link = "/adm/help/${filename}.hlp";
                    951:     }
                    952: 
                    953:     # Add the text
1.755     neumanie  954:     if ($text ne "") {	
1.763     bisitz    955: 	$template.='<span class="LC_help_open_topic">'
                    956:                   .'<a target="_top" href="'.$link.'">'
                    957:                   .$text.'</a>';
1.48      bowersj2  958:     }
                    959: 
1.763     bisitz    960:     # (Always) Add the graphic
1.179     matthew   961:     my $title = &mt('Online Help');
1.667     raeburn   962:     my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.763     bisitz    963:     $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
                    964:               .'<img src="'.$helpicon.'" border="0"'
                    965:               .' alt="'.&mt('Help: [_1]',$topic).'"'
1.783     amueller  966:               .' title="'.$title.'"' 
1.763     bisitz    967:               .' /></a>';
                    968:     if ($text ne "") {	
                    969:         $template.='</span>';
                    970:     }
1.44      bowersj2  971:     return $template;
                    972: 
1.106     bowersj2  973: }
                    974: 
                    975: # This is a quicky function for Latex cheatsheet editing, since it 
                    976: # appears in at least four places
                    977: sub helpLatexCheatsheet {
1.732     raeburn   978:     my ($topic,$text,$not_author) = @_;
                    979:     my $out;
1.106     bowersj2  980:     my $addOther = '';
1.732     raeburn   981:     if ($topic) {
1.763     bisitz    982: 	$addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
                    983: 							       undef, undef, 600).
                    984: 								   '</span> ';
                    985:     }
                    986:     $out = '<span>' # Start cheatsheet
                    987: 	  .$addOther
                    988:           .'<span>'
                    989: 	  .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
                    990: 					       undef,undef,600)
                    991: 	  .'</span> <span>'
                    992: 	  .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
                    993: 					       undef,undef,600)
                    994: 	  .'</span>';
1.732     raeburn   995:     unless ($not_author) {
1.763     bisitz    996:         $out .= ' <span>'
                    997: 	       .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
                    998: 	                                            undef,undef,600)
                    999: 	       .'</span>';
1.732     raeburn  1000:     }
1.763     bisitz   1001:     $out .= '</span>'; # End cheatsheet
1.732     raeburn  1002:     return $out;
1.172     www      1003: }
                   1004: 
1.430     albertel 1005: sub general_help {
                   1006:     my $helptopic='Student_Intro';
                   1007:     if ($env{'request.role'}=~/^(ca|au)/) {
                   1008: 	$helptopic='Authoring_Intro';
                   1009:     } elsif ($env{'request.role'}=~/^cc/) {
                   1010: 	$helptopic='Course_Coordination_Intro';
1.672     raeburn  1011:     } elsif ($env{'request.role'}=~/^dc/) {
                   1012:         $helptopic='Domain_Coordination_Intro';
1.430     albertel 1013:     }
                   1014:     return $helptopic;
                   1015: }
                   1016: 
                   1017: sub update_help_link {
                   1018:     my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
                   1019:     my $origurl = $ENV{'REQUEST_URI'};
                   1020:     $origurl=~s|^/~|/priv/|;
                   1021:     my $timestamp = time;
                   1022:     foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
                   1023:         $$datum = &escape($$datum);
                   1024:     }
                   1025: 
                   1026:     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";
                   1027:     my $output .= <<"ENDOUTPUT";
                   1028: <script type="text/javascript">
                   1029: banner_link = '$banner_link';
                   1030: </script>
                   1031: ENDOUTPUT
                   1032:     return $output;
                   1033: }
                   1034: 
                   1035: # now just updates the help link and generates a blue icon
1.193     raeburn  1036: sub help_open_menu {
1.430     albertel 1037:     my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text) 
1.552     banghart 1038: 	= @_;    
1.430     albertel 1039:     $stayOnPage = 0 if (not defined $stayOnPage);
1.572     banghart 1040:     # only use pop-up help (stayOnPage == 0)
1.552     banghart 1041:     # if environment.remote is on (using remote control UI)
1.572     banghart 1042:     if ($env{'browser.interface'} eq 'textual' ||
                   1043:     	$env{'environment.remote'} eq 'off' ) {
1.552     banghart 1044:         $stayOnPage=1;
1.430     albertel 1045:     }
                   1046:     my $output;
                   1047:     if ($component_help) {
                   1048: 	if (!$text) {
                   1049: 	    $output=&help_open_topic($component_help,undef,$stayOnPage,
                   1050: 				       $width,$height);
                   1051: 	} else {
                   1052: 	    my $help_text;
                   1053: 	    $help_text=&unescape($topic);
                   1054: 	    $output='<table><tr><td>'.
                   1055: 		&help_open_topic($component_help,$help_text,$stayOnPage,
                   1056: 				 $width,$height).'</td></tr></table>';
                   1057: 	}
                   1058:     }
                   1059:     my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
                   1060:     return $output.$banner_link;
                   1061: }
                   1062: 
                   1063: sub top_nav_help {
                   1064:     my ($text) = @_;
1.436     albertel 1065:     $text = &mt($text);
1.572     banghart 1066:     my $stay_on_page = 
1.436     albertel 1067: 	($env{'browser.interface'}  eq 'textual' ||
                   1068: 	 $env{'environment.remote'} eq 'off' );
1.572     banghart 1069:     my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436     albertel 1070: 	                     : "javascript:helpMenu('open')";
1.572     banghart 1071:     my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436     albertel 1072: 
1.201     raeburn  1073:     my $title = &mt('Get help');
1.436     albertel 1074: 
                   1075:     return <<"END";
                   1076: $banner_link
                   1077:  <a href="$link" title="$title">$text</a>
                   1078: END
                   1079: }
                   1080: 
                   1081: sub help_menu_js {
                   1082:     my ($text) = @_;
                   1083: 
                   1084:     my $stayOnPage = 
                   1085: 	($env{'browser.interface'}  eq 'textual' ||
                   1086: 	 $env{'environment.remote'} eq 'off' );
                   1087: 
                   1088:     my $width = 620;
                   1089:     my $height = 600;
1.430     albertel 1090:     my $helptopic=&general_help();
                   1091:     my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261     albertel 1092:     my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331     albertel 1093:     my $start_page =
                   1094:         &Apache::loncommon::start_page('Help Menu', undef,
                   1095: 				       {'frameset'    => 1,
                   1096: 					'js_ready'    => 1,
                   1097: 					'add_entries' => {
                   1098: 					    'border' => '0',
1.579     raeburn  1099: 					    'rows'   => "110,*",},});
1.331     albertel 1100:     my $end_page =
                   1101:         &Apache::loncommon::end_page({'frameset' => 1,
                   1102: 				      'js_ready' => 1,});
                   1103: 
1.436     albertel 1104:     my $template .= <<"ENDTEMPLATE";
                   1105: <script type="text/javascript">
1.253     albertel 1106: // <!-- BEGIN LON-CAPA Internal
                   1107: // <![CDATA[
1.430     albertel 1108: var banner_link = '';
1.243     raeburn  1109: function helpMenu(target) {
                   1110:     var caller = this;
                   1111:     if (target == 'open') {
                   1112:         var newWindow = null;
                   1113:         try {
1.262     albertel 1114:             newWindow =  window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243     raeburn  1115:         }
                   1116:         catch(error) {
                   1117:             writeHelp(caller);
                   1118:             return;
                   1119:         }
                   1120:         if (newWindow) {
                   1121:             caller = newWindow;
                   1122:         }
1.193     raeburn  1123:     }
1.243     raeburn  1124:     writeHelp(caller);
                   1125:     return;
                   1126: }
                   1127: function writeHelp(caller) {
1.430     albertel 1128:     caller.document.writeln('$start_page<frame name="bannerframe"  src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243     raeburn  1129:     caller.document.close()
                   1130:     caller.focus()
1.193     raeburn  1131: }
1.253     albertel 1132: // ]]>
1.219     albertel 1133: // END LON-CAPA Internal -->
1.436     albertel 1134: </script>
1.193     raeburn  1135: ENDTEMPLATE
                   1136:     return $template;
                   1137: }
                   1138: 
1.172     www      1139: sub help_open_bug {
                   1140:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1141:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1142:     unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
                   1143:     $text = "" if (not defined $text);
                   1144:     $stayOnPage = 0 if (not defined $stayOnPage);
1.258     albertel 1145:     if ($env{'browser.interface'} eq 'textual' ||
                   1146: 	$env{'environment.remote'} eq 'off' ) {
1.172     www      1147: 	$stayOnPage=1;
                   1148:     }
1.184     albertel 1149:     $width = 600 if (not defined $width);
                   1150:     $height = 600 if (not defined $height);
1.172     www      1151: 
                   1152:     $topic=~s/\W+/\+/g;
                   1153:     my $link='';
                   1154:     my $template='';
1.379     albertel 1155:     my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&amp;bug_file_loc='.
                   1156: 	&escape($ENV{'REQUEST_URI'}).'&amp;component='.$topic;
1.172     www      1157:     if (!$stayOnPage)
                   1158:     {
                   1159: 	$link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1160:     }
                   1161:     else
                   1162:     {
                   1163: 	$link = $url;
                   1164:     }
                   1165:     # Add the text
                   1166:     if ($text ne "")
                   1167:     {
                   1168: 	$template .= 
                   1169:   "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1170:   "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172     www      1171:     }
                   1172: 
                   1173:     # Add the graphic
1.179     matthew  1174:     my $title = &mt('Report a Bug');
1.215     albertel 1175:     my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172     www      1176:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1177:  <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172     www      1178: ENDTEMPLATE
                   1179:     if ($text ne '') { $template.='</td></tr></table>' };
                   1180:     return $template;
                   1181: 
                   1182: }
                   1183: 
                   1184: sub help_open_faq {
                   1185:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1186:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1187:     unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
                   1188:     $text = "" if (not defined $text);
                   1189:     $stayOnPage = 0 if (not defined $stayOnPage);
1.258     albertel 1190:     if ($env{'browser.interface'} eq 'textual' ||
                   1191: 	$env{'environment.remote'} eq 'off' ) {
1.172     www      1192: 	$stayOnPage=1;
                   1193:     }
                   1194:     $width = 350 if (not defined $width);
                   1195:     $height = 400 if (not defined $height);
                   1196: 
                   1197:     $topic=~s/\W+/\+/g;
                   1198:     my $link='';
                   1199:     my $template='';
                   1200:     my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
                   1201:     if (!$stayOnPage)
                   1202:     {
                   1203: 	$link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1204:     }
                   1205:     else
                   1206:     {
                   1207: 	$link = $url;
                   1208:     }
                   1209: 
                   1210:     # Add the text
                   1211:     if ($text ne "")
                   1212:     {
                   1213: 	$template .= 
1.173     www      1214:   "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1215:   "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172     www      1216:     }
                   1217: 
                   1218:     # Add the graphic
1.179     matthew  1219:     my $title = &mt('View the FAQ');
1.215     albertel 1220:     my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172     www      1221:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1222:  <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172     www      1223: ENDTEMPLATE
                   1224:     if ($text ne '') { $template.='</td></tr></table>' };
                   1225:     return $template;
                   1226: 
1.44      bowersj2 1227: }
1.37      matthew  1228: 
1.180     matthew  1229: ###############################################################
                   1230: ###############################################################
                   1231: 
1.45      matthew  1232: =pod
                   1233: 
1.648     raeburn  1234: =item * &change_content_javascript():
1.256     matthew  1235: 
                   1236: This and the next function allow you to create small sections of an
                   1237: otherwise static HTML page that you can update on the fly with
                   1238: Javascript, even in Netscape 4.
                   1239: 
                   1240: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
                   1241: must be written to the HTML page once. It will prove the Javascript
                   1242: function "change(name, content)". Calling the change function with the
                   1243: name of the section 
                   1244: you want to update, matching the name passed to C<changable_area>, and
                   1245: the new content you want to put in there, will put the content into
                   1246: that area.
                   1247: 
                   1248: B<Note>: Netscape 4 only reserves enough space for the changable area
                   1249: to contain room for the original contents. You need to "make space"
                   1250: for whatever changes you wish to make, and be B<sure> to check your
                   1251: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
                   1252: it's adequate for updating a one-line status display, but little more.
                   1253: This script will set the space to 100% width, so you only need to
                   1254: worry about height in Netscape 4.
                   1255: 
                   1256: Modern browsers are much less limiting, and if you can commit to the
                   1257: user not using Netscape 4, this feature may be used freely with
                   1258: pretty much any HTML.
                   1259: 
                   1260: =cut
                   1261: 
                   1262: sub change_content_javascript {
                   1263:     # If we're on Netscape 4, we need to use Layer-based code
1.258     albertel 1264:     if ($env{'browser.type'} eq 'netscape' &&
                   1265: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1266: 	return (<<NETSCAPE4);
                   1267: 	function change(name, content) {
                   1268: 	    doc = document.layers[name+"___escape"].layers[0].document;
                   1269: 	    doc.open();
                   1270: 	    doc.write(content);
                   1271: 	    doc.close();
                   1272: 	}
                   1273: NETSCAPE4
                   1274:     } else {
                   1275: 	# Otherwise, we need to use semi-standards-compliant code
                   1276: 	# (technically, "innerHTML" isn't standard but the equivalent
                   1277: 	# is really scary, and every useful browser supports it
                   1278: 	return (<<DOMBASED);
                   1279: 	function change(name, content) {
                   1280: 	    element = document.getElementById(name);
                   1281: 	    element.innerHTML = content;
                   1282: 	}
                   1283: DOMBASED
                   1284:     }
                   1285: }
                   1286: 
                   1287: =pod
                   1288: 
1.648     raeburn  1289: =item * &changable_area($name,$origContent):
1.256     matthew  1290: 
                   1291: This provides a "changable area" that can be modified on the fly via
                   1292: the Javascript code provided in C<change_content_javascript>. $name is
                   1293: the name you will use to reference the area later; do not repeat the
                   1294: same name on a given HTML page more then once. $origContent is what
                   1295: the area will originally contain, which can be left blank.
                   1296: 
                   1297: =cut
                   1298: 
                   1299: sub changable_area {
                   1300:     my ($name, $origContent) = @_;
                   1301: 
1.258     albertel 1302:     if ($env{'browser.type'} eq 'netscape' &&
                   1303: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1304: 	# If this is netscape 4, we need to use the Layer tag
                   1305: 	return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
                   1306:     } else {
                   1307: 	return "<span id='$name'>$origContent</span>";
                   1308:     }
                   1309: }
                   1310: 
                   1311: =pod
                   1312: 
1.648     raeburn  1313: =item * &viewport_geometry_js 
1.590     raeburn  1314: 
                   1315: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
                   1316: 
                   1317: =cut
                   1318: 
                   1319: 
                   1320: sub viewport_geometry_js { 
                   1321:     return <<"GEOMETRY";
                   1322: var Geometry = {};
                   1323: function init_geometry() {
                   1324:     if (Geometry.init) { return };
                   1325:     Geometry.init=1;
                   1326:     if (window.innerHeight) {
                   1327:         Geometry.getViewportHeight   = function() { return window.innerHeight; };
                   1328:         Geometry.getViewportWidth   = function() { return window.innerWidth; };
                   1329:         Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
                   1330:         Geometry.getVerticalScroll   = function() { return window.pageYOffset; };
                   1331:     }
                   1332:     else if (document.documentElement && document.documentElement.clientHeight) {
                   1333:         Geometry.getViewportHeight =
                   1334:             function() { return document.documentElement.clientHeight; };
                   1335:         Geometry.getViewportWidth =
                   1336:             function() { return document.documentElement.clientWidth; };
                   1337: 
                   1338:         Geometry.getHorizontalScroll =
                   1339:             function() { return document.documentElement.scrollLeft; };
                   1340:         Geometry.getVerticalScroll =
                   1341:             function() { return document.documentElement.scrollTop; };
                   1342:     }
                   1343:     else if (document.body.clientHeight) {
                   1344:         Geometry.getViewportHeight =
                   1345:             function() { return document.body.clientHeight; };
                   1346:         Geometry.getViewportWidth =
                   1347:             function() { return document.body.clientWidth; };
                   1348:         Geometry.getHorizontalScroll =
                   1349:             function() { return document.body.scrollLeft; };
                   1350:         Geometry.getVerticalScroll =
                   1351:             function() { return document.body.scrollTop; };
                   1352:     }
                   1353: }
                   1354: 
                   1355: GEOMETRY
                   1356: }
                   1357: 
                   1358: =pod
                   1359: 
1.648     raeburn  1360: =item * &viewport_size_js()
1.590     raeburn  1361: 
                   1362: 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. 
                   1363: 
                   1364: =cut
                   1365: 
                   1366: sub viewport_size_js {
                   1367:     my $geometry = &viewport_geometry_js();
                   1368:     return <<"DIMS";
                   1369: 
                   1370: $geometry
                   1371: 
                   1372: function getViewportDims(width,height) {
                   1373:     init_geometry();
                   1374:     width.value = Geometry.getViewportWidth();
                   1375:     height.value = Geometry.getViewportHeight();
                   1376:     return;
                   1377: }
                   1378: 
                   1379: DIMS
                   1380: }
                   1381: 
                   1382: =pod
                   1383: 
1.648     raeburn  1384: =item * &resize_textarea_js()
1.565     albertel 1385: 
                   1386: emits the needed javascript to resize a textarea to be as big as possible
                   1387: 
                   1388: creates a function resize_textrea that takes two IDs first should be
                   1389: the id of the element to resize, second should be the id of a div that
                   1390: surrounds everything that comes after the textarea, this routine needs
                   1391: to be attached to the <body> for the onload and onresize events.
                   1392: 
1.648     raeburn  1393: =back
1.565     albertel 1394: 
                   1395: =cut
                   1396: 
                   1397: sub resize_textarea_js {
1.590     raeburn  1398:     my $geometry = &viewport_geometry_js();
1.565     albertel 1399:     return <<"RESIZE";
                   1400:     <script type="text/javascript">
1.590     raeburn  1401: $geometry
1.565     albertel 1402: 
1.588     albertel 1403: function getX(element) {
                   1404:     var x = 0;
                   1405:     while (element) {
                   1406: 	x += element.offsetLeft;
                   1407: 	element = element.offsetParent;
                   1408:     }
                   1409:     return x;
                   1410: }
                   1411: function getY(element) {
                   1412:     var y = 0;
                   1413:     while (element) {
                   1414: 	y += element.offsetTop;
                   1415: 	element = element.offsetParent;
                   1416:     }
                   1417:     return y;
                   1418: }
                   1419: 
                   1420: 
1.565     albertel 1421: function resize_textarea(textarea_id,bottom_id) {
                   1422:     init_geometry();
                   1423:     var textarea        = document.getElementById(textarea_id);
                   1424:     //alert(textarea);
                   1425: 
1.588     albertel 1426:     var textarea_top    = getY(textarea);
1.565     albertel 1427:     var textarea_height = textarea.offsetHeight;
                   1428:     var bottom          = document.getElementById(bottom_id);
1.588     albertel 1429:     var bottom_top      = getY(bottom);
1.565     albertel 1430:     var bottom_height   = bottom.offsetHeight;
                   1431:     var window_height   = Geometry.getViewportHeight();
1.588     albertel 1432:     var fudge           = 23;
1.565     albertel 1433:     var new_height      = window_height-fudge-textarea_top-bottom_height;
                   1434:     if (new_height < 300) {
                   1435: 	new_height = 300;
                   1436:     }
                   1437:     textarea.style.height=new_height+'px';
                   1438: }
                   1439: </script>
                   1440: RESIZE
                   1441: 
                   1442: }
                   1443: 
                   1444: =pod
                   1445: 
1.256     matthew  1446: =head1 Excel and CSV file utility routines
                   1447: 
                   1448: =over 4
                   1449: 
                   1450: =cut
                   1451: 
                   1452: ###############################################################
                   1453: ###############################################################
                   1454: 
                   1455: =pod
                   1456: 
1.648     raeburn  1457: =item * &csv_translate($text) 
1.37      matthew  1458: 
1.185     www      1459: Translate $text to allow it to be output as a 'comma separated values' 
1.37      matthew  1460: format.
                   1461: 
                   1462: =cut
                   1463: 
1.180     matthew  1464: ###############################################################
                   1465: ###############################################################
1.37      matthew  1466: sub csv_translate {
                   1467:     my $text = shift;
                   1468:     $text =~ s/\"/\"\"/g;
1.209     albertel 1469:     $text =~ s/\n/ /g;
1.37      matthew  1470:     return $text;
                   1471: }
1.180     matthew  1472: 
                   1473: ###############################################################
                   1474: ###############################################################
                   1475: 
                   1476: =pod
                   1477: 
1.648     raeburn  1478: =item * &define_excel_formats()
1.180     matthew  1479: 
                   1480: Define some commonly used Excel cell formats.
                   1481: 
                   1482: Currently supported formats:
                   1483: 
                   1484: =over 4
                   1485: 
                   1486: =item header
                   1487: 
                   1488: =item bold
                   1489: 
                   1490: =item h1
                   1491: 
                   1492: =item h2
                   1493: 
                   1494: =item h3
                   1495: 
1.256     matthew  1496: =item h4
                   1497: 
                   1498: =item i
                   1499: 
1.180     matthew  1500: =item date
                   1501: 
                   1502: =back
                   1503: 
                   1504: Inputs: $workbook
                   1505: 
                   1506: Returns: $format, a hash reference.
                   1507: 
                   1508: =cut
                   1509: 
                   1510: ###############################################################
                   1511: ###############################################################
                   1512: sub define_excel_formats {
                   1513:     my ($workbook) = @_;
                   1514:     my $format;
                   1515:     $format->{'header'} = $workbook->add_format(bold      => 1, 
                   1516:                                                 bottom    => 1,
                   1517:                                                 align     => 'center');
                   1518:     $format->{'bold'} = $workbook->add_format(bold=>1);
                   1519:     $format->{'h1'}   = $workbook->add_format(bold=>1, size=>18);
                   1520:     $format->{'h2'}   = $workbook->add_format(bold=>1, size=>16);
                   1521:     $format->{'h3'}   = $workbook->add_format(bold=>1, size=>14);
1.255     matthew  1522:     $format->{'h4'}   = $workbook->add_format(bold=>1, size=>12);
1.246     matthew  1523:     $format->{'i'}    = $workbook->add_format(italic=>1);
1.180     matthew  1524:     $format->{'date'} = $workbook->add_format(num_format=>
1.207     matthew  1525:                                             'mm/dd/yyyy hh:mm:ss');
1.180     matthew  1526:     return $format;
                   1527: }
                   1528: 
                   1529: ###############################################################
                   1530: ###############################################################
1.113     bowersj2 1531: 
                   1532: =pod
                   1533: 
1.648     raeburn  1534: =item * &create_workbook()
1.255     matthew  1535: 
                   1536: Create an Excel worksheet.  If it fails, output message on the
                   1537: request object and return undefs.
                   1538: 
                   1539: Inputs: Apache request object
                   1540: 
                   1541: Returns (undef) on failure, 
                   1542:     Excel worksheet object, scalar with filename, and formats 
                   1543:     from &Apache::loncommon::define_excel_formats on success
                   1544: 
                   1545: =cut
                   1546: 
                   1547: ###############################################################
                   1548: ###############################################################
                   1549: sub create_workbook {
                   1550:     my ($r) = @_;
                   1551:         #
                   1552:     # Create the excel spreadsheet
                   1553:     my $filename = '/prtspool/'.
1.258     albertel 1554:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255     matthew  1555:         time.'_'.rand(1000000000).'.xls';
                   1556:     my $workbook  = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
                   1557:     if (! defined($workbook)) {
                   1558:         $r->log_error("Error creating excel spreadsheet $filename: $!");
                   1559:         $r->print('<p>'.&mt("Unable to create new Excel file.  ".
                   1560:                             "This error has been logged.  ".
                   1561:                             "Please alert your LON-CAPA administrator").
                   1562:                   '</p>');
                   1563:         return (undef);
                   1564:     }
                   1565:     #
                   1566:     $workbook->set_tempdir('/home/httpd/perl/tmp');
                   1567:     #
                   1568:     my $format = &Apache::loncommon::define_excel_formats($workbook);
                   1569:     return ($workbook,$filename,$format);
                   1570: }
                   1571: 
                   1572: ###############################################################
                   1573: ###############################################################
                   1574: 
                   1575: =pod
                   1576: 
1.648     raeburn  1577: =item * &create_text_file()
1.113     bowersj2 1578: 
1.542     raeburn  1579: Create a file to write to and eventually make available to the user.
1.256     matthew  1580: If file creation fails, outputs an error message on the request object and 
                   1581: return undefs.
1.113     bowersj2 1582: 
1.256     matthew  1583: Inputs: Apache request object, and file suffix
1.113     bowersj2 1584: 
1.256     matthew  1585: Returns (undef) on failure, 
                   1586:     Filehandle and filename on success.
1.113     bowersj2 1587: 
                   1588: =cut
                   1589: 
1.256     matthew  1590: ###############################################################
                   1591: ###############################################################
                   1592: sub create_text_file {
                   1593:     my ($r,$suffix) = @_;
                   1594:     if (! defined($suffix)) { $suffix = 'txt'; };
                   1595:     my $fh;
                   1596:     my $filename = '/prtspool/'.
1.258     albertel 1597:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256     matthew  1598:         time.'_'.rand(1000000000).'.'.$suffix;
                   1599:     $fh = Apache::File->new('>/home/httpd'.$filename);
                   1600:     if (! defined($fh)) {
                   1601:         $r->log_error("Couldn't open $filename for output $!");
1.683     bisitz   1602:         $r->print(&mt('Problems occurred in creating the output file. '
                   1603:                      .'This error has been logged. '
                   1604:                      .'Please alert your LON-CAPA administrator.'));
1.113     bowersj2 1605:     }
1.256     matthew  1606:     return ($fh,$filename)
1.113     bowersj2 1607: }
                   1608: 
                   1609: 
1.256     matthew  1610: =pod 
1.113     bowersj2 1611: 
                   1612: =back
                   1613: 
                   1614: =cut
1.37      matthew  1615: 
                   1616: ###############################################################
1.33      matthew  1617: ##        Home server <option> list generating code          ##
                   1618: ###############################################################
1.35      matthew  1619: 
1.169     www      1620: # ------------------------------------------
                   1621: 
                   1622: sub domain_select {
                   1623:     my ($name,$value,$multiple)=@_;
                   1624:     my %domains=map { 
1.514     albertel 1625: 	$_ => $_.' '. &Apache::lonnet::domain($_,'description') 
1.512     albertel 1626:     } &Apache::lonnet::all_domains();
1.169     www      1627:     if ($multiple) {
                   1628: 	$domains{''}=&mt('Any domain');
1.550     albertel 1629: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287     albertel 1630: 	return &multiple_select_form($name,$value,4,\%domains);
1.169     www      1631:     } else {
1.550     albertel 1632: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169     www      1633: 	return &select_form($name,$value,%domains);
                   1634:     }
                   1635: }
                   1636: 
1.282     albertel 1637: #-------------------------------------------
                   1638: 
                   1639: =pod
                   1640: 
1.519     raeburn  1641: =head1 Routines for form select boxes
                   1642: 
                   1643: =over 4
                   1644: 
1.648     raeburn  1645: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282     albertel 1646: 
                   1647: Returns a string containing a <select> element int multiple mode
                   1648: 
                   1649: 
                   1650: Args:
                   1651:   $name - name of the <select> element
1.506     raeburn  1652:   $value - scalar or array ref of values that should already be selected
1.282     albertel 1653:   $size - number of rows long the select element is
1.283     albertel 1654:   $hash - the elements should be 'option' => 'shown text'
1.282     albertel 1655:           (shown text should already have been &mt())
1.506     raeburn  1656:   $order - (optional) array ref of the order to show the elements in
1.283     albertel 1657: 
1.282     albertel 1658: =cut
                   1659: 
                   1660: #-------------------------------------------
1.169     www      1661: sub multiple_select_form {
1.284     albertel 1662:     my ($name,$value,$size,$hash,$order)=@_;
1.169     www      1663:     my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
                   1664:     my $output='';
1.191     matthew  1665:     if (! defined($size)) {
                   1666:         $size = 4;
1.283     albertel 1667:         if (scalar(keys(%$hash))<4) {
                   1668:             $size = scalar(keys(%$hash));
1.191     matthew  1669:         }
                   1670:     }
1.734     bisitz   1671:     $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501     banghart 1672:     my @order;
1.506     raeburn  1673:     if (ref($order) eq 'ARRAY')  {
                   1674:         @order = @{$order};
                   1675:     } else {
                   1676:         @order = sort(keys(%$hash));
1.501     banghart 1677:     }
                   1678:     if (exists($$hash{'select_form_order'})) {
                   1679:         @order = @{$$hash{'select_form_order'}};
                   1680:     }
                   1681:         
1.284     albertel 1682:     foreach my $key (@order) {
1.356     albertel 1683:         $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284     albertel 1684:         $output.='selected="selected" ' if ($selected{$key});
                   1685:         $output.='>'.$hash->{$key}."</option>\n";
1.169     www      1686:     }
                   1687:     $output.="</select>\n";
                   1688:     return $output;
                   1689: }
                   1690: 
1.88      www      1691: #-------------------------------------------
                   1692: 
                   1693: =pod
                   1694: 
1.648     raeburn  1695: =item * &select_form($defdom,$name,%hash)
1.88      www      1696: 
                   1697: Returns a string containing a <select name='$name' size='1'> form to 
                   1698: allow a user to select options from a hash option_name => displayed text.  
                   1699: See lonrights.pm for an example invocation and use.
                   1700: 
                   1701: =cut
                   1702: 
                   1703: #-------------------------------------------
                   1704: sub select_form {
                   1705:     my ($def,$name,%hash) = @_;
                   1706:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128     albertel 1707:     my @keys;
                   1708:     if (exists($hash{'select_form_order'})) {
                   1709: 	@keys=@{$hash{'select_form_order'}};
                   1710:     } else {
                   1711: 	@keys=sort(keys(%hash));
                   1712:     }
1.356     albertel 1713:     foreach my $key (@keys) {
                   1714:         $selectform.=
                   1715: 	    '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
                   1716:             ($key eq $def ? 'selected="selected" ' : '').
                   1717:                 ">".&mt($hash{$key})."</option>\n";
1.88      www      1718:     }
                   1719:     $selectform.="</select>";
                   1720:     return $selectform;
                   1721: }
                   1722: 
1.475     www      1723: # For display filters
                   1724: 
                   1725: sub display_filter {
                   1726:     if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477     www      1727:     if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714     bisitz   1728:     return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475     www      1729: 			       &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
                   1730: 							   (&mt('all'),10,20,50,100,1000,10000))).
1.714     bisitz   1731: 	   '</label></span> <span class="LC_nobreak">'.
1.475     www      1732:            &mt('Filter [_1]',
1.477     www      1733: 	   &select_form($env{'form.displayfilter'},
                   1734: 			'displayfilter',
                   1735: 			('currentfolder' => 'Current folder/page',
                   1736: 			 'containing' => 'Containing phrase',
                   1737: 			 'none' => 'None'))).
1.714     bisitz   1738: 			 '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475     www      1739: }
                   1740: 
1.167     www      1741: sub gradeleveldescription {
                   1742:     my $gradelevel=shift;
                   1743:     my %gradelevels=(0 => 'Not specified',
                   1744: 		     1 => 'Grade 1',
                   1745: 		     2 => 'Grade 2',
                   1746: 		     3 => 'Grade 3',
                   1747: 		     4 => 'Grade 4',
                   1748: 		     5 => 'Grade 5',
                   1749: 		     6 => 'Grade 6',
                   1750: 		     7 => 'Grade 7',
                   1751: 		     8 => 'Grade 8',
                   1752: 		     9 => 'Grade 9',
                   1753: 		     10 => 'Grade 10',
                   1754: 		     11 => 'Grade 11',
                   1755: 		     12 => 'Grade 12',
                   1756: 		     13 => 'Grade 13',
                   1757: 		     14 => '100 Level',
                   1758: 		     15 => '200 Level',
                   1759: 		     16 => '300 Level',
                   1760: 		     17 => '400 Level',
                   1761: 		     18 => 'Graduate Level');
                   1762:     return &mt($gradelevels{$gradelevel});
                   1763: }
                   1764: 
1.163     www      1765: sub select_level_form {
                   1766:     my ($deflevel,$name)=@_;
                   1767:     unless ($deflevel) { $deflevel=0; }
1.167     www      1768:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
                   1769:     for (my $i=0; $i<=18; $i++) {
                   1770:         $selectform.="<option value=\"$i\" ".
1.253     albertel 1771:             ($i==$deflevel ? 'selected="selected" ' : '').
1.167     www      1772:                 ">".&gradeleveldescription($i)."</option>\n";
                   1773:     }
                   1774:     $selectform.="</select>";
                   1775:     return $selectform;
1.163     www      1776: }
1.167     www      1777: 
1.35      matthew  1778: #-------------------------------------------
                   1779: 
1.45      matthew  1780: =pod
                   1781: 
1.743     raeburn  1782: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$autosubmit)
1.35      matthew  1783: 
                   1784: Returns a string containing a <select name='$name' size='1'> form to 
                   1785: allow a user to select the domain to preform an operation in.  
                   1786: See loncreateuser.pm for an example invocation and use.
                   1787: 
1.90      www      1788: If the $includeempty flag is set, it also includes an empty choice ("no domain
                   1789: selected");
                   1790: 
1.743     raeburn  1791: If the $showdomdesc flag is set, the domain name is followed by the domain description.
                   1792: 
                   1793: If the $autosubmit flag is set, the form containing the domain selector will be auto-submitted by an onchange action.  
1.563     raeburn  1794: 
1.35      matthew  1795: =cut
                   1796: 
                   1797: #-------------------------------------------
1.34      matthew  1798: sub select_dom_form {
1.743     raeburn  1799:     my ($defdom,$name,$includeempty,$showdomdesc,$autosubmit) = @_;
                   1800:     my $onchange;
                   1801:     if ($autosubmit) {
                   1802:         $onchange = ' onchange="this.form.submit()"';
                   1803:     }
1.550     albertel 1804:     my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90      www      1805:     if ($includeempty) { @domains=('',@domains); }
1.743     raeburn  1806:     my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356     albertel 1807:     foreach my $dom (@domains) {
                   1808:         $selectdomain.="<option value=\"$dom\" ".
1.563     raeburn  1809:             ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
                   1810:         if ($showdomdesc) {
                   1811:             if ($dom ne '') {
                   1812:                 my $domdesc = &Apache::lonnet::domain($dom,'description');
                   1813:                 if ($domdesc ne '') {
                   1814:                     $selectdomain .= ' ('.$domdesc.')';
                   1815:                 }
                   1816:             } 
                   1817:         }
                   1818:         $selectdomain .= "</option>\n";
1.34      matthew  1819:     }
                   1820:     $selectdomain.="</select>";
                   1821:     return $selectdomain;
                   1822: }
                   1823: 
1.35      matthew  1824: #-------------------------------------------
                   1825: 
1.45      matthew  1826: =pod
                   1827: 
1.648     raeburn  1828: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35      matthew  1829: 
1.586     raeburn  1830: input: 4 arguments (two required, two optional) - 
                   1831:     $domain - domain of new user
                   1832:     $name - name of form element
                   1833:     $default - Value of 'default' causes a default item to be first 
                   1834:                             option, and selected by default. 
                   1835:     $hide - Value of 'hide' causes hiding of the name of the server, 
                   1836:                             if 1 server found, or default, if 0 found.
1.594     raeburn  1837: output: returns 2 items: 
1.586     raeburn  1838: (a) form element which contains either:
                   1839:    (i) <select name="$name">
                   1840:         <option value="$hostid1">$hostid $servers{$hostid}</option>
                   1841:         <option value="$hostid2">$hostid $servers{$hostid}</option>       
                   1842:        </select>
                   1843:        form item if there are multiple library servers in $domain, or
                   1844:    (ii) an <input type="hidden" name="$name" value="$hostid" /> form item 
                   1845:        if there is only one library server in $domain.
                   1846: 
                   1847: (b) number of library servers found.
                   1848: 
                   1849: See loncreateuser.pm for example of use.
1.35      matthew  1850: 
                   1851: =cut
                   1852: 
                   1853: #-------------------------------------------
1.586     raeburn  1854: sub home_server_form_item {
                   1855:     my ($domain,$name,$default,$hide) = @_;
1.513     albertel 1856:     my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586     raeburn  1857:     my $result;
                   1858:     my $numlib = keys(%servers);
                   1859:     if ($numlib > 1) {
                   1860:         $result .= '<select name="'.$name.'" />'."\n";
                   1861:         if ($default) {
                   1862:             $result .= '<option value="default" selected>'.&mt('default').
                   1863:                        '</option>'."\n";
                   1864:         }
                   1865:         foreach my $hostid (sort(keys(%servers))) {
                   1866:             $result.= '<option value="'.$hostid.'">'.
                   1867: 	              $hostid.' '.$servers{$hostid}."</option>\n";
                   1868:         }
                   1869:         $result .= '</select>'."\n";
                   1870:     } elsif ($numlib == 1) {
                   1871:         my $hostid;
                   1872:         foreach my $item (keys(%servers)) {
                   1873:             $hostid = $item;
                   1874:         }
                   1875:         $result .= '<input type="hidden" name="'.$name.'" value="'.
                   1876:                    $hostid.'" />';
                   1877:                    if (!$hide) {
                   1878:                        $result .= $hostid.' '.$servers{$hostid};
                   1879:                    }
                   1880:                    $result .= "\n";
                   1881:     } elsif ($default) {
                   1882:         $result .= '<input type="hidden" name="'.$name.
                   1883:                    '" value="default" />';
                   1884:                    if (!$hide) {
                   1885:                        $result .= &mt('default');
                   1886:                    }
                   1887:                    $result .= "\n";
1.33      matthew  1888:     }
1.586     raeburn  1889:     return ($result,$numlib);
1.33      matthew  1890: }
1.112     bowersj2 1891: 
                   1892: =pod
                   1893: 
1.534     albertel 1894: =back 
                   1895: 
1.112     bowersj2 1896: =cut
1.87      matthew  1897: 
                   1898: ###############################################################
1.112     bowersj2 1899: ##                  Decoding User Agent                      ##
1.87      matthew  1900: ###############################################################
                   1901: 
                   1902: =pod
                   1903: 
1.112     bowersj2 1904: =head1 Decoding the User Agent
                   1905: 
                   1906: =over 4
                   1907: 
                   1908: =item * &decode_user_agent()
1.87      matthew  1909: 
                   1910: Inputs: $r
                   1911: 
                   1912: Outputs:
                   1913: 
                   1914: =over 4
                   1915: 
1.112     bowersj2 1916: =item * $httpbrowser
1.87      matthew  1917: 
1.112     bowersj2 1918: =item * $clientbrowser
1.87      matthew  1919: 
1.112     bowersj2 1920: =item * $clientversion
1.87      matthew  1921: 
1.112     bowersj2 1922: =item * $clientmathml
1.87      matthew  1923: 
1.112     bowersj2 1924: =item * $clientunicode
1.87      matthew  1925: 
1.112     bowersj2 1926: =item * $clientos
1.87      matthew  1927: 
                   1928: =back
                   1929: 
1.157     matthew  1930: =back 
                   1931: 
1.87      matthew  1932: =cut
                   1933: 
                   1934: ###############################################################
                   1935: ###############################################################
                   1936: sub decode_user_agent {
1.247     albertel 1937:     my ($r)=@_;
1.87      matthew  1938:     my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
                   1939:     my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
                   1940:     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247     albertel 1941:     if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87      matthew  1942:     my $clientbrowser='unknown';
                   1943:     my $clientversion='0';
                   1944:     my $clientmathml='';
                   1945:     my $clientunicode='0';
                   1946:     for (my $i=0;$i<=$#browsertype;$i++) {
                   1947:         my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
                   1948: 	if (($httpbrowser=~/$match/i)  && ($httpbrowser!~/$notmatch/i)) {
                   1949: 	    $clientbrowser=$bname;
                   1950:             $httpbrowser=~/$vreg/i;
                   1951: 	    $clientversion=$1;
                   1952:             $clientmathml=($clientversion>=$minv);
                   1953:             $clientunicode=($clientversion>=$univ);
                   1954: 	}
                   1955:     }
                   1956:     my $clientos='unknown';
                   1957:     if (($httpbrowser=~/linux/i) ||
                   1958:         ($httpbrowser=~/unix/i) ||
                   1959:         ($httpbrowser=~/ux/i) ||
                   1960:         ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
                   1961:     if (($httpbrowser=~/vax/i) ||
                   1962:         ($httpbrowser=~/vms/i)) { $clientos='vms'; }
                   1963:     if ($httpbrowser=~/next/i) { $clientos='next'; }
                   1964:     if (($httpbrowser=~/mac/i) ||
                   1965:         ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
                   1966:     if ($httpbrowser=~/win/i) { $clientos='win'; }
                   1967:     if ($httpbrowser=~/embed/i) { $clientos='pda'; }
                   1968:     return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   1969:             $clientunicode,$clientos,);
                   1970: }
                   1971: 
1.32      matthew  1972: ###############################################################
                   1973: ##    Authentication changing form generation subroutines    ##
                   1974: ###############################################################
                   1975: ##
                   1976: ## All of the authform_xxxxxxx subroutines take their inputs in a
                   1977: ## hash, and have reasonable default values.
                   1978: ##
                   1979: ##    formname = the name given in the <form> tag.
1.35      matthew  1980: #-------------------------------------------
                   1981: 
1.45      matthew  1982: =pod
                   1983: 
1.112     bowersj2 1984: =head1 Authentication Routines
                   1985: 
                   1986: =over 4
                   1987: 
1.648     raeburn  1988: =item * &authform_xxxxxx()
1.35      matthew  1989: 
                   1990: The authform_xxxxxx subroutines provide javascript and html forms which 
                   1991: handle some of the conveniences required for authentication forms.  
                   1992: This is not an optimal method, but it works.  
                   1993: 
                   1994: =over 4
                   1995: 
1.112     bowersj2 1996: =item * authform_header
1.35      matthew  1997: 
1.112     bowersj2 1998: =item * authform_authorwarning
1.35      matthew  1999: 
1.112     bowersj2 2000: =item * authform_nochange
1.35      matthew  2001: 
1.112     bowersj2 2002: =item * authform_kerberos
1.35      matthew  2003: 
1.112     bowersj2 2004: =item * authform_internal
1.35      matthew  2005: 
1.112     bowersj2 2006: =item * authform_filesystem
1.35      matthew  2007: 
                   2008: =back
                   2009: 
1.648     raeburn  2010: See loncreateuser.pm for invocation and use examples.
1.157     matthew  2011: 
1.35      matthew  2012: =cut
                   2013: 
                   2014: #-------------------------------------------
1.32      matthew  2015: sub authform_header{  
                   2016:     my %in = (
                   2017:         formname => 'cu',
1.80      albertel 2018:         kerb_def_dom => '',
1.32      matthew  2019:         @_,
                   2020:     );
                   2021:     $in{'formname'} = 'document.' . $in{'formname'};
                   2022:     my $result='';
1.80      albertel 2023: 
                   2024: #---------------------------------------------- Code for upper case translation
                   2025:     my $Javascript_toUpperCase;
                   2026:     unless ($in{kerb_def_dom}) {
                   2027:         $Javascript_toUpperCase =<<"END";
                   2028:         switch (choice) {
                   2029:            case 'krb': currentform.elements[choicearg].value =
                   2030:                currentform.elements[choicearg].value.toUpperCase();
                   2031:                break;
                   2032:            default:
                   2033:         }
                   2034: END
                   2035:     } else {
                   2036:         $Javascript_toUpperCase = "";
                   2037:     }
                   2038: 
1.165     raeburn  2039:     my $radioval = "'nochange'";
1.591     raeburn  2040:     if (defined($in{'curr_authtype'})) {
                   2041:         if ($in{'curr_authtype'} ne '') {
                   2042:             $radioval = "'".$in{'curr_authtype'}."arg'";
                   2043:         }
1.174     matthew  2044:     }
1.165     raeburn  2045:     my $argfield = 'null';
1.591     raeburn  2046:     if (defined($in{'mode'})) {
1.165     raeburn  2047:         if ($in{'mode'} eq 'modifycourse')  {
1.591     raeburn  2048:             if (defined($in{'curr_autharg'})) {
                   2049:                 if ($in{'curr_autharg'} ne '') {
1.165     raeburn  2050:                     $argfield = "'$in{'curr_autharg'}'";
                   2051:                 }
                   2052:             }
                   2053:         }
                   2054:     }
                   2055: 
1.32      matthew  2056:     $result.=<<"END";
                   2057: var current = new Object();
1.165     raeburn  2058: current.radiovalue = $radioval;
                   2059: current.argfield = $argfield;
1.32      matthew  2060: 
                   2061: function changed_radio(choice,currentform) {
                   2062:     var choicearg = choice + 'arg';
                   2063:     // If a radio button in changed, we need to change the argfield
                   2064:     if (current.radiovalue != choice) {
                   2065:         current.radiovalue = choice;
                   2066:         if (current.argfield != null) {
                   2067:             currentform.elements[current.argfield].value = '';
                   2068:         }
                   2069:         if (choice == 'nochange') {
                   2070:             current.argfield = null;
                   2071:         } else {
                   2072:             current.argfield = choicearg;
                   2073:             switch(choice) {
                   2074:                 case 'krb': 
                   2075:                     currentform.elements[current.argfield].value = 
                   2076:                         "$in{'kerb_def_dom'}";
                   2077:                 break;
                   2078:               default:
                   2079:                 break;
                   2080:             }
                   2081:         }
                   2082:     }
                   2083:     return;
                   2084: }
1.22      www      2085: 
1.32      matthew  2086: function changed_text(choice,currentform) {
                   2087:     var choicearg = choice + 'arg';
                   2088:     if (currentform.elements[choicearg].value !='') {
1.80      albertel 2089:         $Javascript_toUpperCase
1.32      matthew  2090:         // clear old field
                   2091:         if ((current.argfield != choicearg) && (current.argfield != null)) {
                   2092:             currentform.elements[current.argfield].value = '';
                   2093:         }
                   2094:         current.argfield = choicearg;
                   2095:     }
                   2096:     set_auth_radio_buttons(choice,currentform);
                   2097:     return;
1.20      www      2098: }
1.32      matthew  2099: 
                   2100: function set_auth_radio_buttons(newvalue,currentform) {
                   2101:     var i=0;
                   2102:     while (i < currentform.login.length) {
                   2103:         if (currentform.login[i].value == newvalue) { break; }
                   2104:         i++;
                   2105:     }
                   2106:     if (i == currentform.login.length) {
                   2107:         return;
                   2108:     }
                   2109:     current.radiovalue = newvalue;
                   2110:     currentform.login[i].checked = true;
                   2111:     return;
                   2112: }
                   2113: END
                   2114:     return $result;
                   2115: }
                   2116: 
                   2117: sub authform_authorwarning{
                   2118:     my $result='';
1.144     matthew  2119:     $result='<i>'.
                   2120:         &mt('As a general rule, only authors or co-authors should be '.
                   2121:             'filesystem authenticated '.
                   2122:             '(which allows access to the server filesystem).')."</i>\n";
1.32      matthew  2123:     return $result;
                   2124: }
                   2125: 
                   2126: sub authform_nochange{  
                   2127:     my %in = (
                   2128:               formname => 'document.cu',
                   2129:               kerb_def_dom => 'MSU.EDU',
                   2130:               @_,
                   2131:           );
1.586     raeburn  2132:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'}); 
                   2133:     my $result;
                   2134:     if (keys(%can_assign) == 0) {
                   2135:         $result = &mt('Under you current role you are not permitted to change login settings for this user');  
                   2136:     } else {
                   2137:         $result = '<label>'.&mt('[_1] Do not change login data',
                   2138:                   '<input type="radio" name="login" value="nochange" '.
                   2139:                   'checked="checked" onclick="'.
1.281     albertel 2140:             "javascript:changed_radio('nochange',$in{'formname'});".'" />').
                   2141: 	    '</label>';
1.586     raeburn  2142:     }
1.32      matthew  2143:     return $result;
                   2144: }
                   2145: 
1.591     raeburn  2146: sub authform_kerberos {
1.32      matthew  2147:     my %in = (
                   2148:               formname => 'document.cu',
                   2149:               kerb_def_dom => 'MSU.EDU',
1.80      albertel 2150:               kerb_def_auth => 'krb4',
1.32      matthew  2151:               @_,
                   2152:               );
1.586     raeburn  2153:     my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
                   2154:         $autharg,$jscall);
                   2155:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.80      albertel 2156:     if ($in{'kerb_def_auth'} eq 'krb5') {
1.772     bisitz   2157:        $check5 = ' checked="checked"';
1.80      albertel 2158:     } else {
1.772     bisitz   2159:        $check4 = ' checked="checked"';
1.80      albertel 2160:     }
1.165     raeburn  2161:     $krbarg = $in{'kerb_def_dom'};
1.591     raeburn  2162:     if (defined($in{'curr_authtype'})) {
                   2163:         if ($in{'curr_authtype'} eq 'krb') {
1.772     bisitz   2164:             $krbcheck = ' checked="checked"';
1.623     raeburn  2165:             if (defined($in{'mode'})) {
                   2166:                 if ($in{'mode'} eq 'modifyuser') {
                   2167:                     $krbcheck = '';
                   2168:                 }
                   2169:             }
1.591     raeburn  2170:             if (defined($in{'curr_kerb_ver'})) {
                   2171:                 if ($in{'curr_krb_ver'} eq '5') {
1.772     bisitz   2172:                     $check5 = ' checked="checked"';
1.591     raeburn  2173:                     $check4 = '';
                   2174:                 } else {
1.772     bisitz   2175:                     $check4 = ' checked="checked"';
1.591     raeburn  2176:                     $check5 = '';
                   2177:                 }
1.586     raeburn  2178:             }
1.591     raeburn  2179:             if (defined($in{'curr_autharg'})) {
1.165     raeburn  2180:                 $krbarg = $in{'curr_autharg'};
                   2181:             }
1.586     raeburn  2182:             if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591     raeburn  2183:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2184:                     $result = 
                   2185:     &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
                   2186:         $in{'curr_autharg'},$krbver);
                   2187:                 } else {
                   2188:                     $result =
                   2189:     &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
                   2190:                 }
                   2191:                 return $result; 
                   2192:             }
                   2193:         }
                   2194:     } else {
                   2195:         if ($authnum == 1) {
1.784     bisitz   2196:             $authtype = '<input type="hidden" name="login" value="krb" />';
1.165     raeburn  2197:         }
                   2198:     }
1.586     raeburn  2199:     if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
                   2200:         return;
1.587     raeburn  2201:     } elsif ($authtype eq '') {
1.591     raeburn  2202:         if (defined($in{'mode'})) {
1.587     raeburn  2203:             if ($in{'mode'} eq 'modifycourse') {
                   2204:                 if ($authnum == 1) {
1.784     bisitz   2205:                     $authtype = '<input type="hidden" name="login" value="krb" />';
1.587     raeburn  2206:                 }
                   2207:             }
                   2208:         }
1.586     raeburn  2209:     }
                   2210:     $jscall = "javascript:changed_radio('krb',$in{'formname'});";
                   2211:     if ($authtype eq '') {
                   2212:         $authtype = '<input type="radio" name="login" value="krb" '.
                   2213:                     'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
                   2214:                     $krbcheck.' />';
                   2215:     }
                   2216:     if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
                   2217:         ($can_assign{'krb4'} && !$can_assign{'krb5'} && 
                   2218:          $in{'curr_authtype'} eq 'krb5') ||
                   2219:         (!$can_assign{'krb4'} && $can_assign{'krb5'} && 
                   2220:          $in{'curr_authtype'} eq 'krb4')) {
                   2221:         $result .= &mt
1.144     matthew  2222:         ('[_1] Kerberos authenticated with domain [_2] '.
1.281     albertel 2223:          '[_3] Version 4 [_4] Version 5 [_5]',
1.586     raeburn  2224:          '<label>'.$authtype,
1.281     albertel 2225:          '</label><input type="text" size="10" name="krbarg" '.
1.165     raeburn  2226:              'value="'.$krbarg.'" '.
1.144     matthew  2227:              'onchange="'.$jscall.'" />',
1.281     albertel 2228:          '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
                   2229:          '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
                   2230: 	 '</label>');
1.586     raeburn  2231:     } elsif ($can_assign{'krb4'}) {
                   2232:         $result .= &mt
                   2233:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2234:          '[_3] Version 4 [_4]',
                   2235:          '<label>'.$authtype,
                   2236:          '</label><input type="text" size="10" name="krbarg" '.
                   2237:              'value="'.$krbarg.'" '.
                   2238:              'onchange="'.$jscall.'" />',
                   2239:          '<label><input type="hidden" name="krbver" value="4" />',
                   2240:          '</label>');
                   2241:     } elsif ($can_assign{'krb5'}) {
                   2242:         $result .= &mt
                   2243:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2244:          '[_3] Version 5 [_4]',
                   2245:          '<label>'.$authtype,
                   2246:          '</label><input type="text" size="10" name="krbarg" '.
                   2247:              'value="'.$krbarg.'" '.
                   2248:              'onchange="'.$jscall.'" />',
                   2249:          '<label><input type="hidden" name="krbver" value="5" />',
                   2250:          '</label>');
                   2251:     }
1.32      matthew  2252:     return $result;
                   2253: }
                   2254: 
                   2255: sub authform_internal{  
1.586     raeburn  2256:     my %in = (
1.32      matthew  2257:                 formname => 'document.cu',
                   2258:                 kerb_def_dom => 'MSU.EDU',
                   2259:                 @_,
                   2260:                 );
1.586     raeburn  2261:     my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
                   2262:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2263:     if (defined($in{'curr_authtype'})) {
                   2264:         if ($in{'curr_authtype'} eq 'int') {
1.586     raeburn  2265:             if ($can_assign{'int'}) {
1.772     bisitz   2266:                 $intcheck = 'checked="checked" ';
1.623     raeburn  2267:                 if (defined($in{'mode'})) {
                   2268:                     if ($in{'mode'} eq 'modifyuser') {
                   2269:                         $intcheck = '';
                   2270:                     }
                   2271:                 }
1.591     raeburn  2272:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2273:                     $intarg = $in{'curr_autharg'};
                   2274:                 }
                   2275:             } else {
                   2276:                 $result = &mt('Currently internally authenticated.');
                   2277:                 return $result;
1.165     raeburn  2278:             }
                   2279:         }
1.586     raeburn  2280:     } else {
                   2281:         if ($authnum == 1) {
1.784     bisitz   2282:             $authtype = '<input type="hidden" name="login" value="int" />';
1.586     raeburn  2283:         }
                   2284:     }
                   2285:     if (!$can_assign{'int'}) {
                   2286:         return;
1.587     raeburn  2287:     } elsif ($authtype eq '') {
1.591     raeburn  2288:         if (defined($in{'mode'})) {
1.587     raeburn  2289:             if ($in{'mode'} eq 'modifycourse') {
                   2290:                 if ($authnum == 1) {
1.784     bisitz   2291:                     $authtype = '<input type="hidden" name="login" value="int" />';
1.587     raeburn  2292:                 }
                   2293:             }
                   2294:         }
1.165     raeburn  2295:     }
1.586     raeburn  2296:     $jscall = "javascript:changed_radio('int',$in{'formname'});";
                   2297:     if ($authtype eq '') {
                   2298:         $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
                   2299:                     ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
                   2300:     }
1.605     bisitz   2301:     $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586     raeburn  2302:                $intarg.'" onchange="'.$jscall.'" />';
                   2303:     $result = &mt
1.144     matthew  2304:         ('[_1] Internally authenticated (with initial password [_2])',
1.586     raeburn  2305:          '<label>'.$authtype,'</label>'.$autharg);
1.620     www      2306:     $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  2307:     return $result;
                   2308: }
                   2309: 
                   2310: sub authform_local{  
                   2311:     my %in = (
                   2312:               formname => 'document.cu',
                   2313:               kerb_def_dom => 'MSU.EDU',
                   2314:               @_,
                   2315:               );
1.586     raeburn  2316:     my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
                   2317:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2318:     if (defined($in{'curr_authtype'})) {
                   2319:         if ($in{'curr_authtype'} eq 'loc') {
1.586     raeburn  2320:             if ($can_assign{'loc'}) {
1.772     bisitz   2321:                 $loccheck = 'checked="checked" ';
1.623     raeburn  2322:                 if (defined($in{'mode'})) {
                   2323:                     if ($in{'mode'} eq 'modifyuser') {
                   2324:                         $loccheck = '';
                   2325:                     }
                   2326:                 }
1.591     raeburn  2327:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2328:                     $locarg = $in{'curr_autharg'};
                   2329:                 }
                   2330:             } else {
                   2331:                 $result = &mt('Currently using local (institutional) authentication.');
                   2332:                 return $result;
1.165     raeburn  2333:             }
                   2334:         }
1.586     raeburn  2335:     } else {
                   2336:         if ($authnum == 1) {
1.784     bisitz   2337:             $authtype = '<input type="hidden" name="login" value="loc" />';
1.586     raeburn  2338:         }
                   2339:     }
                   2340:     if (!$can_assign{'loc'}) {
                   2341:         return;
1.587     raeburn  2342:     } elsif ($authtype eq '') {
1.591     raeburn  2343:         if (defined($in{'mode'})) {
1.587     raeburn  2344:             if ($in{'mode'} eq 'modifycourse') {
                   2345:                 if ($authnum == 1) {
1.784     bisitz   2346:                     $authtype = '<input type="hidden" name="login" value="loc" />';
1.587     raeburn  2347:                 }
                   2348:             }
                   2349:         }
1.165     raeburn  2350:     }
1.586     raeburn  2351:     $jscall = "javascript:changed_radio('loc',$in{'formname'});";
                   2352:     if ($authtype eq '') {
                   2353:         $authtype = '<input type="radio" name="login" value="loc" '.
                   2354:                     $loccheck.' onchange="'.$jscall.'" onclick="'.
                   2355:                     $jscall.'" />';
                   2356:     }
                   2357:     $autharg = '<input type="text" size="10" name="locarg" value="'.
                   2358:                $locarg.'" onchange="'.$jscall.'" />';
                   2359:     $result = &mt('[_1] Local Authentication with argument [_2]',
                   2360:                   '<label>'.$authtype,'</label>'.$autharg);
1.32      matthew  2361:     return $result;
                   2362: }
                   2363: 
                   2364: sub authform_filesystem{  
                   2365:     my %in = (
                   2366:               formname => 'document.cu',
                   2367:               kerb_def_dom => 'MSU.EDU',
                   2368:               @_,
                   2369:               );
1.586     raeburn  2370:     my ($fsyscheck,$result,$authtype,$autharg,$jscall);
                   2371:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2372:     if (defined($in{'curr_authtype'})) {
                   2373:         if ($in{'curr_authtype'} eq 'fsys') {
1.586     raeburn  2374:             if ($can_assign{'fsys'}) {
1.772     bisitz   2375:                 $fsyscheck = 'checked="checked" ';
1.623     raeburn  2376:                 if (defined($in{'mode'})) {
                   2377:                     if ($in{'mode'} eq 'modifyuser') {
                   2378:                         $fsyscheck = '';
                   2379:                     }
                   2380:                 }
1.586     raeburn  2381:             } else {
                   2382:                 $result = &mt('Currently Filesystem Authenticated.');
                   2383:                 return $result;
                   2384:             }           
                   2385:         }
                   2386:     } else {
                   2387:         if ($authnum == 1) {
1.784     bisitz   2388:             $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586     raeburn  2389:         }
                   2390:     }
                   2391:     if (!$can_assign{'fsys'}) {
                   2392:         return;
1.587     raeburn  2393:     } elsif ($authtype eq '') {
1.591     raeburn  2394:         if (defined($in{'mode'})) {
1.587     raeburn  2395:             if ($in{'mode'} eq 'modifycourse') {
                   2396:                 if ($authnum == 1) {
1.784     bisitz   2397:                     $authtype = '<input type="hidden" name="login" value="fsys" />';
1.587     raeburn  2398:                 }
                   2399:             }
                   2400:         }
1.586     raeburn  2401:     }
                   2402:     $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
                   2403:     if ($authtype eq '') {
                   2404:         $authtype = '<input type="radio" name="login" value="fsys" '.
                   2405:                     $fsyscheck.' onchange="'.$jscall.'" onclick="'.
                   2406:                     $jscall.'" />';
                   2407:     }
                   2408:     $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
                   2409:                ' onchange="'.$jscall.'" />';
                   2410:     $result = &mt
1.144     matthew  2411:         ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281     albertel 2412:          '<label><input type="radio" name="login" value="fsys" '.
1.586     raeburn  2413:          $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605     bisitz   2414:          '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144     matthew  2415:                   'onchange="'.$jscall.'" />');
1.32      matthew  2416:     return $result;
                   2417: }
                   2418: 
1.586     raeburn  2419: sub get_assignable_auth {
                   2420:     my ($dom) = @_;
                   2421:     if ($dom eq '') {
                   2422:         $dom = $env{'request.role.domain'};
                   2423:     }
                   2424:     my %can_assign = (
                   2425:                           krb4 => 1,
                   2426:                           krb5 => 1,
                   2427:                           int  => 1,
                   2428:                           loc  => 1,
                   2429:                      );
                   2430:     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
                   2431:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   2432:         if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
                   2433:             my $authhash = $domconfig{'usercreation'}{'authtypes'};
                   2434:             my $context;
                   2435:             if ($env{'request.role'} =~ /^au/) {
                   2436:                 $context = 'author';
                   2437:             } elsif ($env{'request.role'} =~ /^dc/) {
                   2438:                 $context = 'domain';
                   2439:             } elsif ($env{'request.course.id'}) {
                   2440:                 $context = 'course';
                   2441:             }
                   2442:             if ($context) {
                   2443:                 if (ref($authhash->{$context}) eq 'HASH') {
                   2444:                    %can_assign = %{$authhash->{$context}}; 
                   2445:                 }
                   2446:             }
                   2447:         }
                   2448:     }
                   2449:     my $authnum = 0;
                   2450:     foreach my $key (keys(%can_assign)) {
                   2451:         if ($can_assign{$key}) {
                   2452:             $authnum ++;
                   2453:         }
                   2454:     }
                   2455:     if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
                   2456:         $authnum --;
                   2457:     }
                   2458:     return ($authnum,%can_assign);
                   2459: }
                   2460: 
1.80      albertel 2461: ###############################################################
                   2462: ##    Get Kerberos Defaults for Domain                 ##
                   2463: ###############################################################
                   2464: ##
                   2465: ## Returns default kerberos version and an associated argument
                   2466: ## as listed in file domain.tab. If not listed, provides
                   2467: ## appropriate default domain and kerberos version.
                   2468: ##
                   2469: #-------------------------------------------
                   2470: 
                   2471: =pod
                   2472: 
1.648     raeburn  2473: =item * &get_kerberos_defaults()
1.80      albertel 2474: 
                   2475: get_kerberos_defaults($target_domain) returns the default kerberos
1.641     raeburn  2476: version and domain. If not found, it defaults to version 4 and the 
                   2477: domain of the server.
1.80      albertel 2478: 
1.648     raeburn  2479: =over 4
                   2480: 
1.80      albertel 2481: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
                   2482: 
1.648     raeburn  2483: =back
                   2484: 
                   2485: =back
                   2486: 
1.80      albertel 2487: =cut
                   2488: 
                   2489: #-------------------------------------------
                   2490: sub get_kerberos_defaults {
                   2491:     my $domain=shift;
1.641     raeburn  2492:     my ($krbdef,$krbdefdom);
                   2493:     my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
                   2494:     if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
                   2495:         $krbdef = $domdefaults{'auth_def'};
                   2496:         $krbdefdom = $domdefaults{'auth_arg_def'};
                   2497:     } else {
1.80      albertel 2498:         $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
                   2499:         my $krbdefdom=$1;
                   2500:         $krbdefdom=~tr/a-z/A-Z/;
                   2501:         $krbdef = "krb4";
                   2502:     }
                   2503:     return ($krbdef,$krbdefdom);
                   2504: }
1.112     bowersj2 2505: 
1.32      matthew  2506: 
1.46      matthew  2507: ###############################################################
                   2508: ##                Thesaurus Functions                        ##
                   2509: ###############################################################
1.20      www      2510: 
1.46      matthew  2511: =pod
1.20      www      2512: 
1.112     bowersj2 2513: =head1 Thesaurus Functions
                   2514: 
                   2515: =over 4
                   2516: 
1.648     raeburn  2517: =item * &initialize_keywords()
1.46      matthew  2518: 
                   2519: Initializes the package variable %Keywords if it is empty.  Uses the
                   2520: package variable $thesaurus_db_file.
                   2521: 
                   2522: =cut
                   2523: 
                   2524: ###################################################
                   2525: 
                   2526: sub initialize_keywords {
                   2527:     return 1 if (scalar keys(%Keywords));
                   2528:     # If we are here, %Keywords is empty, so fill it up
                   2529:     #   Make sure the file we need exists...
                   2530:     if (! -e $thesaurus_db_file) {
                   2531:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
                   2532:                                  " failed because it does not exist");
                   2533:         return 0;
                   2534:     }
                   2535:     #   Set up the hash as a database
                   2536:     my %thesaurus_db;
                   2537:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2538:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2539:         &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
                   2540:                                  $thesaurus_db_file);
                   2541:         return 0;
                   2542:     } 
                   2543:     #  Get the average number of appearances of a word.
                   2544:     my $avecount = $thesaurus_db{'average.count'};
                   2545:     #  Put keywords (those that appear > average) into %Keywords
                   2546:     while (my ($word,$data)=each (%thesaurus_db)) {
                   2547:         my ($count,undef) = split /:/,$data;
                   2548:         $Keywords{$word}++ if ($count > $avecount);
                   2549:     }
                   2550:     untie %thesaurus_db;
                   2551:     # Remove special values from %Keywords.
1.356     albertel 2552:     foreach my $value ('total.count','average.count') {
                   2553:         delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586     raeburn  2554:   }
1.46      matthew  2555:     return 1;
                   2556: }
                   2557: 
                   2558: ###################################################
                   2559: 
                   2560: =pod
                   2561: 
1.648     raeburn  2562: =item * &keyword($word)
1.46      matthew  2563: 
                   2564: Returns true if $word is a keyword.  A keyword is a word that appears more 
                   2565: than the average number of times in the thesaurus database.  Calls 
                   2566: &initialize_keywords
                   2567: 
                   2568: =cut
                   2569: 
                   2570: ###################################################
1.20      www      2571: 
                   2572: sub keyword {
1.46      matthew  2573:     return if (!&initialize_keywords());
                   2574:     my $word=lc(shift());
                   2575:     $word=~s/\W//g;
                   2576:     return exists($Keywords{$word});
1.20      www      2577: }
1.46      matthew  2578: 
                   2579: ###############################################################
                   2580: 
                   2581: =pod 
1.20      www      2582: 
1.648     raeburn  2583: =item * &get_related_words()
1.46      matthew  2584: 
1.160     matthew  2585: Look up a word in the thesaurus.  Takes a scalar argument and returns
1.46      matthew  2586: an array of words.  If the keyword is not in the thesaurus, an empty array
                   2587: will be returned.  The order of the words returned is determined by the
                   2588: database which holds them.
                   2589: 
                   2590: Uses global $thesaurus_db_file.
                   2591: 
                   2592: =cut
                   2593: 
                   2594: ###############################################################
                   2595: sub get_related_words {
                   2596:     my $keyword = shift;
                   2597:     my %thesaurus_db;
                   2598:     if (! -e $thesaurus_db_file) {
                   2599:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
                   2600:                                  "failed because the file does not exist");
                   2601:         return ();
                   2602:     }
                   2603:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2604:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2605:         return ();
                   2606:     } 
                   2607:     my @Words=();
1.429     www      2608:     my $count=0;
1.46      matthew  2609:     if (exists($thesaurus_db{$keyword})) {
1.356     albertel 2610: 	# The first element is the number of times
                   2611: 	# the word appears.  We do not need it now.
1.429     www      2612: 	my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
                   2613: 	my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
                   2614: 	my $threshold=$mostfrequentcount/10;
                   2615:         foreach my $possibleword (@RelatedWords) {
                   2616:             my ($word,$wordcount)=split(/\,/,$possibleword);
                   2617:             if ($wordcount>$threshold) {
                   2618: 		push(@Words,$word);
                   2619:                 $count++;
                   2620:                 if ($count>10) { last; }
                   2621: 	    }
1.20      www      2622:         }
                   2623:     }
1.46      matthew  2624:     untie %thesaurus_db;
                   2625:     return @Words;
1.14      harris41 2626: }
1.46      matthew  2627: 
1.112     bowersj2 2628: =pod
                   2629: 
                   2630: =back
                   2631: 
                   2632: =cut
1.61      www      2633: 
                   2634: # -------------------------------------------------------------- Plaintext name
1.81      albertel 2635: =pod
                   2636: 
1.112     bowersj2 2637: =head1 User Name Functions
                   2638: 
                   2639: =over 4
                   2640: 
1.648     raeburn  2641: =item * &plainname($uname,$udom,$first)
1.81      albertel 2642: 
1.112     bowersj2 2643: Takes a users logon name and returns it as a string in
1.226     albertel 2644: "first middle last generation" form 
                   2645: if $first is set to 'lastname' then it returns it as
                   2646: 'lastname generation, firstname middlename' if their is a lastname
1.81      albertel 2647: 
                   2648: =cut
1.61      www      2649: 
1.295     www      2650: 
1.81      albertel 2651: ###############################################################
1.61      www      2652: sub plainname {
1.226     albertel 2653:     my ($uname,$udom,$first)=@_;
1.537     albertel 2654:     return if (!defined($uname) || !defined($udom));
1.295     www      2655:     my %names=&getnames($uname,$udom);
1.226     albertel 2656:     my $name=&Apache::lonnet::format_name($names{'firstname'},
                   2657: 					  $names{'middlename'},
                   2658: 					  $names{'lastname'},
                   2659: 					  $names{'generation'},$first);
                   2660:     $name=~s/^\s+//;
1.62      www      2661:     $name=~s/\s+$//;
                   2662:     $name=~s/\s+/ /g;
1.353     albertel 2663:     if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62      www      2664:     return $name;
1.61      www      2665: }
1.66      www      2666: 
                   2667: # -------------------------------------------------------------------- Nickname
1.81      albertel 2668: =pod
                   2669: 
1.648     raeburn  2670: =item * &nickname($uname,$udom)
1.81      albertel 2671: 
                   2672: Gets a users name and returns it as a string as
                   2673: 
                   2674: "&quot;nickname&quot;"
1.66      www      2675: 
1.81      albertel 2676: if the user has a nickname or
                   2677: 
                   2678: "first middle last generation"
                   2679: 
                   2680: if the user does not
                   2681: 
                   2682: =cut
1.66      www      2683: 
                   2684: sub nickname {
                   2685:     my ($uname,$udom)=@_;
1.537     albertel 2686:     return if (!defined($uname) || !defined($udom));
1.295     www      2687:     my %names=&getnames($uname,$udom);
1.68      albertel 2688:     my $name=$names{'nickname'};
1.66      www      2689:     if ($name) {
                   2690:        $name='&quot;'.$name.'&quot;'; 
                   2691:     } else {
                   2692:        $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
                   2693: 	     $names{'lastname'}.' '.$names{'generation'};
                   2694:        $name=~s/\s+$//;
                   2695:        $name=~s/\s+/ /g;
                   2696:     }
                   2697:     return $name;
                   2698: }
                   2699: 
1.295     www      2700: sub getnames {
                   2701:     my ($uname,$udom)=@_;
1.537     albertel 2702:     return if (!defined($uname) || !defined($udom));
1.433     albertel 2703:     if ($udom eq 'public' && $uname eq 'public') {
                   2704: 	return ('lastname' => &mt('Public'));
                   2705:     }
1.295     www      2706:     my $id=$uname.':'.$udom;
                   2707:     my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
                   2708:     if ($cached) {
                   2709: 	return %{$names};
                   2710:     } else {
                   2711: 	my %loadnames=&Apache::lonnet::get('environment',
                   2712:                     ['firstname','middlename','lastname','generation','nickname'],
                   2713: 					 $udom,$uname);
                   2714: 	&Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
                   2715: 	return %loadnames;
                   2716:     }
                   2717: }
1.61      www      2718: 
1.542     raeburn  2719: # -------------------------------------------------------------------- getemails
1.648     raeburn  2720: 
1.542     raeburn  2721: =pod
                   2722: 
1.648     raeburn  2723: =item * &getemails($uname,$udom)
1.542     raeburn  2724: 
                   2725: Gets a user's email information and returns it as a hash with keys:
                   2726: notification, critnotification, permanentemail
                   2727: 
                   2728: For notification and critnotification, values are comma-separated lists 
1.648     raeburn  2729: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542     raeburn  2730:  
1.648     raeburn  2731: 
1.542     raeburn  2732: =cut
                   2733: 
1.648     raeburn  2734: 
1.466     albertel 2735: sub getemails {
                   2736:     my ($uname,$udom)=@_;
                   2737:     if ($udom eq 'public' && $uname eq 'public') {
                   2738: 	return;
                   2739:     }
1.467     www      2740:     if (!$udom) { $udom=$env{'user.domain'}; }
                   2741:     if (!$uname) { $uname=$env{'user.name'}; }
1.466     albertel 2742:     my $id=$uname.':'.$udom;
                   2743:     my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
                   2744:     if ($cached) {
                   2745: 	return %{$names};
                   2746:     } else {
                   2747: 	my %loadnames=&Apache::lonnet::get('environment',
                   2748:                     			   ['notification','critnotification',
                   2749: 					    'permanentemail'],
                   2750: 					   $udom,$uname);
                   2751: 	&Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
                   2752: 	return %loadnames;
                   2753:     }
                   2754: }
                   2755: 
1.551     albertel 2756: sub flush_email_cache {
                   2757:     my ($uname,$udom)=@_;
                   2758:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2759:     if (!$uname) { $uname=$env{'user.name'};   }
                   2760:     return if ($udom eq 'public' && $uname eq 'public');
                   2761:     my $id=$uname.':'.$udom;
                   2762:     &Apache::lonnet::devalidate_cache_new('emailscache',$id);
                   2763: }
                   2764: 
1.728     raeburn  2765: # -------------------------------------------------------------------- getlangs
                   2766: 
                   2767: =pod
                   2768: 
                   2769: =item * &getlangs($uname,$udom)
                   2770: 
                   2771: Gets a user's language preference and returns it as a hash with key:
                   2772: language.
                   2773: 
                   2774: =cut
                   2775: 
                   2776: 
                   2777: sub getlangs {
                   2778:     my ($uname,$udom) = @_;
                   2779:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2780:     if (!$uname) { $uname=$env{'user.name'};   }
                   2781:     my $id=$uname.':'.$udom;
                   2782:     my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
                   2783:     if ($cached) {
                   2784:         return %{$langs};
                   2785:     } else {
                   2786:         my %loadlangs=&Apache::lonnet::get('environment',['languages'],
                   2787:                                            $udom,$uname);
                   2788:         &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
                   2789:         return %loadlangs;
                   2790:     }
                   2791: }
                   2792: 
                   2793: sub flush_langs_cache {
                   2794:     my ($uname,$udom)=@_;
                   2795:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2796:     if (!$uname) { $uname=$env{'user.name'};   }
                   2797:     return if ($udom eq 'public' && $uname eq 'public');
                   2798:     my $id=$uname.':'.$udom;
                   2799:     &Apache::lonnet::devalidate_cache_new('userlangs',$id);
                   2800: }
                   2801: 
1.61      www      2802: # ------------------------------------------------------------------ Screenname
1.81      albertel 2803: 
                   2804: =pod
                   2805: 
1.648     raeburn  2806: =item * &screenname($uname,$udom)
1.81      albertel 2807: 
                   2808: Gets a users screenname and returns it as a string
                   2809: 
                   2810: =cut
1.61      www      2811: 
                   2812: sub screenname {
                   2813:     my ($uname,$udom)=@_;
1.258     albertel 2814:     if ($uname eq $env{'user.name'} &&
                   2815: 	$udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212     albertel 2816:     my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68      albertel 2817:     return $names{'screenname'};
1.62      www      2818: }
                   2819: 
1.212     albertel 2820: 
1.62      www      2821: # ------------------------------------------------------------- Message Wrapper
                   2822: 
                   2823: sub messagewrapper {
1.369     www      2824:     my ($link,$username,$domain,$subject,$text)=@_;
1.62      www      2825:     return 
1.441     albertel 2826:         '<a href="/adm/email?compose=individual&amp;'.
                   2827:         'recname='.$username.'&amp;recdom='.$domain.
                   2828: 	'&amp;subject='.&escape($subject).'&amp;text='.&escape($text).'" '.
1.200     matthew  2829:         'title="'.&mt('Send message').'">'.$link.'</a>';
1.74      www      2830: }
                   2831: # --------------------------------------------------------------- Notes Wrapper
                   2832: 
                   2833: sub noteswrapper {
                   2834:     my ($link,$un,$do)=@_;
                   2835:     return 
                   2836: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62      www      2837: }
                   2838: # ------------------------------------------------------------- Aboutme Wrapper
                   2839: 
                   2840: sub aboutmewrapper {
1.166     www      2841:     my ($link,$username,$domain,$target)=@_;
1.447     raeburn  2842:     if (!defined($username)  && !defined($domain)) {
                   2843:         return;
                   2844:     }
1.205     www      2845:     return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.756     weissno  2846: 	($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62      www      2847: }
                   2848: 
                   2849: # ------------------------------------------------------------ Syllabus Wrapper
                   2850: 
                   2851: 
                   2852: sub syllabuswrapper {
1.707     bisitz   2853:     my ($linktext,$coursedir,$domain)=@_;
1.208     matthew  2854:     return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61      www      2855: }
1.14      harris41 2856: 
1.208     matthew  2857: sub track_student_link {
1.268     albertel 2858:     my ($linktext,$sname,$sdom,$target,$start) = @_;
                   2859:     my $link ="/adm/trackstudent?";
1.208     matthew  2860:     my $title = 'View recent activity';
                   2861:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   2862:         defined($sdom)  && $sdom  !~ /^\s*$/) {
1.268     albertel 2863:         $link .= "selected_student=$sname:$sdom";
1.208     matthew  2864:         $title .= ' of this student';
1.268     albertel 2865:     } 
1.208     matthew  2866:     if (defined($target) && $target !~ /^\s*$/) {
                   2867:         $target = qq{target="$target"};
                   2868:     } else {
                   2869:         $target = '';
                   2870:     }
1.268     albertel 2871:     if ($start) { $link.='&amp;start='.$start; }
1.554     albertel 2872:     $title = &mt($title);
                   2873:     $linktext = &mt($linktext);
1.448     albertel 2874:     return qq{<a href="$link" title="$title" $target>$linktext</a>}.
                   2875: 	&help_open_topic('View_recent_activity');
1.208     matthew  2876: }
                   2877: 
1.781     raeburn  2878: sub slot_reservations_link {
                   2879:     my ($linktext,$sname,$sdom,$target) = @_;
                   2880:     my $link ="/adm/slotrequest?command=showresv&amp;origin=aboutme";
                   2881:     my $title = 'View slot reservation history';
                   2882:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   2883:         defined($sdom)  && $sdom  !~ /^\s*$/) {
                   2884:         $link .= "&amp;uname=$sname&amp;udom=$sdom";
                   2885:         $title .= ' of this student';
                   2886:     }
                   2887:     if (defined($target) && $target !~ /^\s*$/) {
                   2888:         $target = qq{target="$target"};
                   2889:     } else {
                   2890:         $target = '';
                   2891:     }
                   2892:     $title = &mt($title);
                   2893:     $linktext = &mt($linktext);
                   2894:     return qq{<a href="$link" title="$title" $target>$linktext</a>};
                   2895: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
                   2896: 
                   2897: }
                   2898: 
1.508     www      2899: # ===================================================== Display a student photo
                   2900: 
                   2901: 
1.509     albertel 2902: sub student_image_tag {
1.508     www      2903:     my ($domain,$user)=@_;
                   2904:     my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
                   2905:     if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
                   2906: 	return '<img src="'.$imgsrc.'" align="right" />';
                   2907:     } else {
                   2908: 	return '';
                   2909:     }
                   2910: }
                   2911: 
1.112     bowersj2 2912: =pod
                   2913: 
                   2914: =back
                   2915: 
                   2916: =head1 Access .tab File Data
                   2917: 
                   2918: =over 4
                   2919: 
1.648     raeburn  2920: =item * &languageids() 
1.112     bowersj2 2921: 
                   2922: returns list of all language ids
                   2923: 
                   2924: =cut
                   2925: 
1.14      harris41 2926: sub languageids {
1.16      harris41 2927:     return sort(keys(%language));
1.14      harris41 2928: }
                   2929: 
1.112     bowersj2 2930: =pod
                   2931: 
1.648     raeburn  2932: =item * &languagedescription() 
1.112     bowersj2 2933: 
                   2934: returns description of a specified language id
                   2935: 
                   2936: =cut
                   2937: 
1.14      harris41 2938: sub languagedescription {
1.125     www      2939:     my $code=shift;
                   2940:     return  ($supported_language{$code}?'* ':'').
                   2941:             $language{$code}.
1.126     www      2942: 	    ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145     www      2943: }
                   2944: 
                   2945: sub plainlanguagedescription {
                   2946:     my $code=shift;
                   2947:     return $language{$code};
                   2948: }
                   2949: 
                   2950: sub supportedlanguagecode {
                   2951:     my $code=shift;
                   2952:     return $supported_language{$code};
1.97      www      2953: }
                   2954: 
1.112     bowersj2 2955: =pod
                   2956: 
1.648     raeburn  2957: =item * &copyrightids() 
1.112     bowersj2 2958: 
                   2959: returns list of all copyrights
                   2960: 
                   2961: =cut
                   2962: 
                   2963: sub copyrightids {
                   2964:     return sort(keys(%cprtag));
                   2965: }
                   2966: 
                   2967: =pod
                   2968: 
1.648     raeburn  2969: =item * &copyrightdescription() 
1.112     bowersj2 2970: 
                   2971: returns description of a specified copyright id
                   2972: 
                   2973: =cut
                   2974: 
                   2975: sub copyrightdescription {
1.166     www      2976:     return &mt($cprtag{shift(@_)});
1.112     bowersj2 2977: }
1.197     matthew  2978: 
                   2979: =pod
                   2980: 
1.648     raeburn  2981: =item * &source_copyrightids() 
1.192     taceyjo1 2982: 
                   2983: returns list of all source copyrights
                   2984: 
                   2985: =cut
                   2986: 
                   2987: sub source_copyrightids {
                   2988:     return sort(keys(%scprtag));
                   2989: }
                   2990: 
                   2991: =pod
                   2992: 
1.648     raeburn  2993: =item * &source_copyrightdescription() 
1.192     taceyjo1 2994: 
                   2995: returns description of a specified source copyright id
                   2996: 
                   2997: =cut
                   2998: 
                   2999: sub source_copyrightdescription {
                   3000:     return &mt($scprtag{shift(@_)});
                   3001: }
1.112     bowersj2 3002: 
                   3003: =pod
                   3004: 
1.648     raeburn  3005: =item * &filecategories() 
1.112     bowersj2 3006: 
                   3007: returns list of all file categories
                   3008: 
                   3009: =cut
                   3010: 
                   3011: sub filecategories {
                   3012:     return sort(keys(%category_extensions));
                   3013: }
                   3014: 
                   3015: =pod
                   3016: 
1.648     raeburn  3017: =item * &filecategorytypes() 
1.112     bowersj2 3018: 
                   3019: returns list of file types belonging to a given file
                   3020: category
                   3021: 
                   3022: =cut
                   3023: 
                   3024: sub filecategorytypes {
1.356     albertel 3025:     my ($cat) = @_;
                   3026:     return @{$category_extensions{lc($cat)}};
1.112     bowersj2 3027: }
                   3028: 
                   3029: =pod
                   3030: 
1.648     raeburn  3031: =item * &fileembstyle() 
1.112     bowersj2 3032: 
                   3033: returns embedding style for a specified file type
                   3034: 
                   3035: =cut
                   3036: 
                   3037: sub fileembstyle {
                   3038:     return $fe{lc(shift(@_))};
1.169     www      3039: }
                   3040: 
1.351     www      3041: sub filemimetype {
                   3042:     return $fm{lc(shift(@_))};
                   3043: }
                   3044: 
1.169     www      3045: 
                   3046: sub filecategoryselect {
                   3047:     my ($name,$value)=@_;
1.189     matthew  3048:     return &select_form($value,$name,
1.169     www      3049: 			'' => &mt('Any category'),
                   3050: 			map { $_,$_ } sort(keys(%category_extensions)));
1.112     bowersj2 3051: }
                   3052: 
                   3053: =pod
                   3054: 
1.648     raeburn  3055: =item * &filedescription() 
1.112     bowersj2 3056: 
                   3057: returns description for a specified file type
                   3058: 
                   3059: =cut
                   3060: 
                   3061: sub filedescription {
1.188     matthew  3062:     my $file_description = $fd{lc(shift())};
                   3063:     $file_description =~ s:([\[\]]):~$1:g;
                   3064:     return &mt($file_description);
1.112     bowersj2 3065: }
                   3066: 
                   3067: =pod
                   3068: 
1.648     raeburn  3069: =item * &filedescriptionex() 
1.112     bowersj2 3070: 
                   3071: returns description for a specified file type with
                   3072: extra formatting
                   3073: 
                   3074: =cut
                   3075: 
                   3076: sub filedescriptionex {
                   3077:     my $ex=shift;
1.188     matthew  3078:     my $file_description = $fd{lc($ex)};
                   3079:     $file_description =~ s:([\[\]]):~$1:g;
                   3080:     return '.'.$ex.' '.&mt($file_description);
1.112     bowersj2 3081: }
                   3082: 
                   3083: # End of .tab access
                   3084: =pod
                   3085: 
                   3086: =back
                   3087: 
                   3088: =cut
                   3089: 
                   3090: # ------------------------------------------------------------------ File Types
                   3091: sub fileextensions {
                   3092:     return sort(keys(%fe));
                   3093: }
                   3094: 
1.97      www      3095: # ----------------------------------------------------------- Display Languages
                   3096: # returns a hash with all desired display languages
                   3097: #
                   3098: 
                   3099: sub display_languages {
                   3100:     my %languages=();
1.695     raeburn  3101:     foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356     albertel 3102: 	$languages{$lang}=1;
1.97      www      3103:     }
                   3104:     &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258     albertel 3105:     if ($env{'form.displaylanguage'}) {
1.356     albertel 3106: 	foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
                   3107: 	    $languages{$lang}=1;
1.97      www      3108:         }
                   3109:     }
                   3110:     return %languages;
1.14      harris41 3111: }
                   3112: 
1.582     albertel 3113: sub languages {
                   3114:     my ($possible_langs) = @_;
1.695     raeburn  3115:     my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582     albertel 3116:     if (!ref($possible_langs)) {
                   3117: 	if( wantarray ) {
                   3118: 	    return @preferred_langs;
                   3119: 	} else {
                   3120: 	    return $preferred_langs[0];
                   3121: 	}
                   3122:     }
                   3123:     my %possibilities = map { $_ => 1 } (@$possible_langs);
                   3124:     my @preferred_possibilities;
                   3125:     foreach my $preferred_lang (@preferred_langs) {
                   3126: 	if (exists($possibilities{$preferred_lang})) {
                   3127: 	    push(@preferred_possibilities, $preferred_lang);
                   3128: 	}
                   3129:     }
                   3130:     if( wantarray ) {
                   3131: 	return @preferred_possibilities;
                   3132:     }
                   3133:     return $preferred_possibilities[0];
                   3134: }
                   3135: 
1.742     raeburn  3136: sub user_lang {
                   3137:     my ($touname,$toudom,$fromcid) = @_;
                   3138:     my @userlangs;
                   3139:     if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
                   3140:         @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
                   3141:                     $env{'course.'.$fromcid.'.languages'}));
                   3142:     } else {
                   3143:         my %langhash = &getlangs($touname,$toudom);
                   3144:         if ($langhash{'languages'} ne '') {
                   3145:             @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
                   3146:         } else {
                   3147:             my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
                   3148:             if ($domdefs{'lang_def'} ne '') {
                   3149:                 @userlangs = ($domdefs{'lang_def'});
                   3150:             }
                   3151:         }
                   3152:     }
                   3153:     my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
                   3154:     my $user_lh = Apache::localize->get_handle(@languages);
                   3155:     return $user_lh;
                   3156: }
                   3157: 
                   3158: 
1.112     bowersj2 3159: ###############################################################
                   3160: ##               Student Answer Attempts                     ##
                   3161: ###############################################################
                   3162: 
                   3163: =pod
                   3164: 
                   3165: =head1 Alternate Problem Views
                   3166: 
                   3167: =over 4
                   3168: 
1.648     raeburn  3169: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112     bowersj2 3170:     $getattempt, $regexp, $gradesub)
                   3171: 
                   3172: Return string with previous attempt on problem. Arguments:
                   3173: 
                   3174: =over 4
                   3175: 
                   3176: =item * $symb: Problem, including path
                   3177: 
                   3178: =item * $username: username of the desired student
                   3179: 
                   3180: =item * $domain: domain of the desired student
1.14      harris41 3181: 
1.112     bowersj2 3182: =item * $course: Course ID
1.14      harris41 3183: 
1.112     bowersj2 3184: =item * $getattempt: Leave blank for all attempts, otherwise put
                   3185:     something
1.14      harris41 3186: 
1.112     bowersj2 3187: =item * $regexp: if string matches this regexp, the string will be
                   3188:     sent to $gradesub
1.14      harris41 3189: 
1.112     bowersj2 3190: =item * $gradesub: routine that processes the string if it matches $regexp
1.14      harris41 3191: 
1.112     bowersj2 3192: =back
1.14      harris41 3193: 
1.112     bowersj2 3194: The output string is a table containing all desired attempts, if any.
1.16      harris41 3195: 
1.112     bowersj2 3196: =cut
1.1       albertel 3197: 
                   3198: sub get_previous_attempt {
1.43      ng       3199:   my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1       albertel 3200:   my $prevattempts='';
1.43      ng       3201:   no strict 'refs';
1.1       albertel 3202:   if ($symb) {
1.3       albertel 3203:     my (%returnhash)=
                   3204:       &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1       albertel 3205:     if ($returnhash{'version'}) {
                   3206:       my %lasthash=();
                   3207:       my $version;
                   3208:       for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356     albertel 3209:         foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
                   3210: 	  $lasthash{$key}=$returnhash{$version.':'.$key};
1.19      harris41 3211:         }
1.1       albertel 3212:       }
1.596     albertel 3213:       $prevattempts=&start_data_table().&start_data_table_header_row();
                   3214:       $prevattempts.='<th>'.&mt('History').'</th>';
1.356     albertel 3215:       foreach my $key (sort(keys(%lasthash))) {
                   3216: 	my ($ign,@parts) = split(/\./,$key);
1.41      ng       3217: 	if ($#parts > 0) {
1.31      albertel 3218: 	  my $data=$parts[-1];
                   3219: 	  pop(@parts);
1.596     albertel 3220: 	  $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.'&nbsp;</th>';
1.31      albertel 3221: 	} else {
1.41      ng       3222: 	  if ($#parts == 0) {
                   3223: 	    $prevattempts.='<th>'.$parts[0].'</th>';
                   3224: 	  } else {
                   3225: 	    $prevattempts.='<th>'.$ign.'</th>';
                   3226: 	  }
1.31      albertel 3227: 	}
1.16      harris41 3228:       }
1.596     albertel 3229:       $prevattempts.=&end_data_table_header_row();
1.40      ng       3230:       if ($getattempt eq '') {
                   3231: 	for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596     albertel 3232: 	  $prevattempts.=&start_data_table_row().
                   3233: 	      '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356     albertel 3234: 	    foreach my $key (sort(keys(%lasthash))) {
1.581     albertel 3235: 		my $value = &format_previous_attempt_value($key,
                   3236: 							   $returnhash{$version.':'.$key});
                   3237: 		$prevattempts.='<td>'.$value.'&nbsp;</td>';   
1.40      ng       3238: 	    }
1.596     albertel 3239: 	  $prevattempts.=&end_data_table_row();
1.40      ng       3240: 	 }
1.1       albertel 3241:       }
1.596     albertel 3242:       $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356     albertel 3243:       foreach my $key (sort(keys(%lasthash))) {
1.581     albertel 3244: 	my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356     albertel 3245: 	if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40      ng       3246: 	$prevattempts.='<td>'.$value.'&nbsp;</td>';
1.16      harris41 3247:       }
1.596     albertel 3248:       $prevattempts.= &end_data_table_row().&end_data_table();
1.1       albertel 3249:     } else {
1.596     albertel 3250:       $prevattempts=
                   3251: 	  &start_data_table().&start_data_table_row().
                   3252: 	  '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
                   3253: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3254:     }
                   3255:   } else {
1.596     albertel 3256:     $prevattempts=
                   3257: 	  &start_data_table().&start_data_table_row().
                   3258: 	  '<td>'.&mt('No data.').'</td>'.
                   3259: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3260:   }
1.10      albertel 3261: }
                   3262: 
1.581     albertel 3263: sub format_previous_attempt_value {
                   3264:     my ($key,$value) = @_;
                   3265:     if ($key =~ /timestamp/) {
                   3266: 	$value = &Apache::lonlocal::locallocaltime($value);
                   3267:     } elsif (ref($value) eq 'ARRAY') {
                   3268: 	$value = '('.join(', ', @{ $value }).')';
                   3269:     } else {
                   3270: 	$value = &unescape($value);
                   3271:     }
                   3272:     return $value;
                   3273: }
                   3274: 
                   3275: 
1.107     albertel 3276: sub relative_to_absolute {
                   3277:     my ($url,$output)=@_;
                   3278:     my $parser=HTML::TokeParser->new(\$output);
                   3279:     my $token;
                   3280:     my $thisdir=$url;
                   3281:     my @rlinks=();
                   3282:     while ($token=$parser->get_token) {
                   3283: 	if ($token->[0] eq 'S') {
                   3284: 	    if ($token->[1] eq 'a') {
                   3285: 		if ($token->[2]->{'href'}) {
                   3286: 		    $rlinks[$#rlinks+1]=$token->[2]->{'href'};
                   3287: 		}
                   3288: 	    } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
                   3289: 		$rlinks[$#rlinks+1]=$token->[2]->{'src'};
                   3290: 	    } elsif ($token->[1] eq 'base') {
                   3291: 		$thisdir=$token->[2]->{'href'};
                   3292: 	    }
                   3293: 	}
                   3294:     }
                   3295:     $thisdir=~s-/[^/]*$--;
1.356     albertel 3296:     foreach my $link (@rlinks) {
1.726     raeburn  3297: 	unless (($link=~/^https?\:\/\//i) ||
1.356     albertel 3298: 		($link=~/^\//) ||
                   3299: 		($link=~/^javascript:/i) ||
                   3300: 		($link=~/^mailto:/i) ||
                   3301: 		($link=~/^\#/)) {
                   3302: 	    my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
                   3303: 	    $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107     albertel 3304: 	}
                   3305:     }
                   3306: # -------------------------------------------------- Deal with Applet codebases
                   3307:     $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
                   3308:     return $output;
                   3309: }
                   3310: 
1.112     bowersj2 3311: =pod
                   3312: 
1.648     raeburn  3313: =item * &get_student_view()
1.112     bowersj2 3314: 
                   3315: show a snapshot of what student was looking at
                   3316: 
                   3317: =cut
                   3318: 
1.10      albertel 3319: sub get_student_view {
1.186     albertel 3320:   my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114     www      3321:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3322:   my (%form);
1.10      albertel 3323:   my @elements=('symb','courseid','domain','username');
                   3324:   foreach my $element (@elements) {
1.186     albertel 3325:       $form{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3326:   }
1.186     albertel 3327:   if (defined($moreenv)) {
                   3328:       %form=(%form,%{$moreenv});
                   3329:   }
1.236     albertel 3330:   if (defined($target)) { $form{'grade_target'} = $target; }
1.107     albertel 3331:   $feedurl=&Apache::lonnet::clutter($feedurl);
1.650     www      3332:   my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11      albertel 3333:   $userview=~s/\<body[^\>]*\>//gi;
                   3334:   $userview=~s/\<\/body\>//gi;
                   3335:   $userview=~s/\<html\>//gi;
                   3336:   $userview=~s/\<\/html\>//gi;
                   3337:   $userview=~s/\<head\>//gi;
                   3338:   $userview=~s/\<\/head\>//gi;
                   3339:   $userview=~s/action\s*\=/would_be_action\=/gi;
1.107     albertel 3340:   $userview=&relative_to_absolute($feedurl,$userview);
1.650     www      3341:   if (wantarray) {
                   3342:      return ($userview,$response);
                   3343:   } else {
                   3344:      return $userview;
                   3345:   }
                   3346: }
                   3347: 
                   3348: sub get_student_view_with_retries {
                   3349:   my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
                   3350: 
                   3351:     my $ok = 0;                 # True if we got a good response.
                   3352:     my $content;
                   3353:     my $response;
                   3354: 
                   3355:     # Try to get the student_view done. within the retries count:
                   3356:     
                   3357:     do {
                   3358:          ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
                   3359:          $ok      = $response->is_success;
                   3360:          if (!$ok) {
                   3361:             &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
                   3362:          }
                   3363:          $retries--;
                   3364:     } while (!$ok && ($retries > 0));
                   3365:     
                   3366:     if (!$ok) {
                   3367:        $content = '';          # On error return an empty content.
                   3368:     }
1.651     www      3369:     if (wantarray) {
                   3370:        return ($content, $response);
                   3371:     } else {
                   3372:        return $content;
                   3373:     }
1.11      albertel 3374: }
                   3375: 
1.112     bowersj2 3376: =pod
                   3377: 
1.648     raeburn  3378: =item * &get_student_answers() 
1.112     bowersj2 3379: 
                   3380: show a snapshot of how student was answering problem
                   3381: 
                   3382: =cut
                   3383: 
1.11      albertel 3384: sub get_student_answers {
1.100     sakharuk 3385:   my ($symb,$username,$domain,$courseid,%form) = @_;
1.114     www      3386:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3387:   my (%moreenv);
1.11      albertel 3388:   my @elements=('symb','courseid','domain','username');
                   3389:   foreach my $element (@elements) {
1.186     albertel 3390:     $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3391:   }
1.186     albertel 3392:   $moreenv{'grade_target'}='answer';
                   3393:   %moreenv=(%form,%moreenv);
1.497     raeburn  3394:   $feedurl = &Apache::lonnet::clutter($feedurl);
                   3395:   my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10      albertel 3396:   return $userview;
1.1       albertel 3397: }
1.116     albertel 3398: 
                   3399: =pod
                   3400: 
                   3401: =item * &submlink()
                   3402: 
1.242     albertel 3403: Inputs: $text $uname $udom $symb $target
1.116     albertel 3404: 
                   3405: Returns: A link to grades.pm such as to see the SUBM view of a student
                   3406: 
                   3407: =cut
                   3408: 
                   3409: ###############################################
                   3410: sub submlink {
1.242     albertel 3411:     my ($text,$uname,$udom,$symb,$target)=@_;
1.116     albertel 3412:     if (!($uname && $udom)) {
                   3413: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3414: 	    &Apache::lonnet::whichuser($symb);
1.116     albertel 3415: 	if (!$symb) { $symb=$cursymb; }
                   3416:     }
1.254     matthew  3417:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3418:     $symb=&escape($symb);
1.242     albertel 3419:     if ($target) { $target="target=\"$target\""; }
                   3420:     return '<a href="/adm/grades?&command=submission&'.
                   3421: 	'symb='.$symb.'&student='.$uname.
                   3422: 	'&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
                   3423: }
                   3424: ##############################################
                   3425: 
                   3426: =pod
                   3427: 
                   3428: =item * &pgrdlink()
                   3429: 
                   3430: Inputs: $text $uname $udom $symb $target
                   3431: 
                   3432: Returns: A link to grades.pm such as to see the PGRD view of a student
                   3433: 
                   3434: =cut
                   3435: 
                   3436: ###############################################
                   3437: sub pgrdlink {
                   3438:     my $link=&submlink(@_);
                   3439:     $link=~s/(&command=submission)/$1&showgrading=yes/;
                   3440:     return $link;
                   3441: }
                   3442: ##############################################
                   3443: 
                   3444: =pod
                   3445: 
                   3446: =item * &pprmlink()
                   3447: 
                   3448: Inputs: $text $uname $udom $symb $target
                   3449: 
                   3450: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283     albertel 3451: student and a specific resource
1.242     albertel 3452: 
                   3453: =cut
                   3454: 
                   3455: ###############################################
                   3456: sub pprmlink {
                   3457:     my ($text,$uname,$udom,$symb,$target)=@_;
                   3458:     if (!($uname && $udom)) {
                   3459: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3460: 	    &Apache::lonnet::whichuser($symb);
1.242     albertel 3461: 	if (!$symb) { $symb=$cursymb; }
                   3462:     }
1.254     matthew  3463:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3464:     $symb=&escape($symb);
1.242     albertel 3465:     if ($target) { $target="target=\"$target\""; }
1.595     albertel 3466:     return '<a href="/adm/parmset?command=set&amp;'.
                   3467: 	'symb='.$symb.'&amp;uname='.$uname.
                   3468: 	'&amp;udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116     albertel 3469: }
                   3470: ##############################################
1.37      matthew  3471: 
1.112     bowersj2 3472: =pod
                   3473: 
                   3474: =back
                   3475: 
                   3476: =cut
                   3477: 
1.37      matthew  3478: ###############################################
1.51      www      3479: 
                   3480: 
                   3481: sub timehash {
1.687     raeburn  3482:     my ($thistime) = @_;
                   3483:     my $timezone = &Apache::lonlocal::gettimezone();
                   3484:     my $dt = DateTime->from_epoch(epoch => $thistime)
                   3485:                      ->set_time_zone($timezone);
                   3486:     my $wday = $dt->day_of_week();
                   3487:     if ($wday == 7) { $wday = 0; }
                   3488:     return ( 'second' => $dt->second(),
                   3489:              'minute' => $dt->minute(),
                   3490:              'hour'   => $dt->hour(),
                   3491:              'day'     => $dt->day_of_month(),
                   3492:              'month'   => $dt->month(),
                   3493:              'year'    => $dt->year(),
                   3494:              'weekday' => $wday,
                   3495:              'dayyear' => $dt->day_of_year(),
                   3496:              'dlsav'   => $dt->is_dst() );
1.51      www      3497: }
                   3498: 
1.370     www      3499: sub utc_string {
                   3500:     my ($date)=@_;
1.371     www      3501:     return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370     www      3502: }
                   3503: 
1.51      www      3504: sub maketime {
                   3505:     my %th=@_;
1.687     raeburn  3506:     my ($epoch_time,$timezone,$dt);
                   3507:     $timezone = &Apache::lonlocal::gettimezone();
                   3508:     eval {
                   3509:         $dt = DateTime->new( year   => $th{'year'},
                   3510:                              month  => $th{'month'},
                   3511:                              day    => $th{'day'},
                   3512:                              hour   => $th{'hour'},
                   3513:                              minute => $th{'minute'},
                   3514:                              second => $th{'second'},
                   3515:                              time_zone => $timezone,
                   3516:                          );
                   3517:     };
                   3518:     if (!$@) {
                   3519:         $epoch_time = $dt->epoch;
                   3520:         if ($epoch_time) {
                   3521:             return $epoch_time;
                   3522:         }
                   3523:     }
1.51      www      3524:     return POSIX::mktime(
                   3525:         ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210     www      3526:          $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70      www      3527: }
                   3528: 
                   3529: #########################################
1.51      www      3530: 
                   3531: sub findallcourses {
1.482     raeburn  3532:     my ($roles,$uname,$udom) = @_;
1.355     albertel 3533:     my %roles;
                   3534:     if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348     albertel 3535:     my %courses;
1.51      www      3536:     my $now=time;
1.482     raeburn  3537:     if (!defined($uname)) {
                   3538:         $uname = $env{'user.name'};
                   3539:     }
                   3540:     if (!defined($udom)) {
                   3541:         $udom = $env{'user.domain'};
                   3542:     }
                   3543:     if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
                   3544:         my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
                   3545:         if (!%roles) {
                   3546:             %roles = (
                   3547:                        cc => 1,
                   3548:                        in => 1,
                   3549:                        ep => 1,
                   3550:                        ta => 1,
                   3551:                        cr => 1,
                   3552:                        st => 1,
                   3553:              );
                   3554:         }
                   3555:         foreach my $entry (keys(%roleshash)) {
                   3556:             my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
                   3557:             if ($trole =~ /^cr/) { 
                   3558:                 next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
                   3559:             } else {
                   3560:                 next if (!exists($roles{$trole}));
                   3561:             }
                   3562:             if ($tend) {
                   3563:                 next if ($tend < $now);
                   3564:             }
                   3565:             if ($tstart) {
                   3566:                 next if ($tstart > $now);
                   3567:             }
                   3568:             my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
                   3569:             (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
                   3570:             if ($secpart eq '') {
                   3571:                 ($cnum,$role) = split(/_/,$cnumpart); 
                   3572:                 $sec = 'none';
                   3573:                 $realsec = '';
                   3574:             } else {
                   3575:                 $cnum = $cnumpart;
                   3576:                 ($sec,$role) = split(/_/,$secpart);
                   3577:                 $realsec = $sec;
1.490     raeburn  3578:             }
1.482     raeburn  3579:             $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
                   3580:         }
                   3581:     } else {
                   3582:         foreach my $key (keys(%env)) {
1.483     albertel 3583: 	    if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
                   3584:                  $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482     raeburn  3585: 	        my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
                   3586: 	        next if ($role eq 'ca' || $role eq 'aa');
                   3587: 	        next if (%roles && !exists($roles{$role}));
                   3588: 	        my ($starttime,$endtime)=split(/\./,$env{$key});
                   3589:                 my $active=1;
                   3590:                 if ($starttime) {
                   3591: 		    if ($now<$starttime) { $active=0; }
                   3592:                 }
                   3593:                 if ($endtime) {
                   3594:                     if ($now>$endtime) { $active=0; }
                   3595:                 }
                   3596:                 if ($active) {
                   3597:                     if ($sec eq '') {
                   3598:                         $sec = 'none';
                   3599:                     }
                   3600:                     $courses{$cdom.'_'.$cnum}{$sec} = 
                   3601:                                      $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474     raeburn  3602:                 }
                   3603:             }
1.51      www      3604:         }
                   3605:     }
1.474     raeburn  3606:     return %courses;
1.51      www      3607: }
1.37      matthew  3608: 
1.54      www      3609: ###############################################
1.474     raeburn  3610: 
                   3611: sub blockcheck {
1.482     raeburn  3612:     my ($setters,$activity,$uname,$udom) = @_;
1.490     raeburn  3613: 
                   3614:     if (!defined($udom)) {
                   3615:         $udom = $env{'user.domain'};
                   3616:     }
                   3617:     if (!defined($uname)) {
                   3618:         $uname = $env{'user.name'};
                   3619:     }
                   3620: 
                   3621:     # If uname and udom are for a course, check for blocks in the course.
                   3622: 
                   3623:     if (&Apache::lonnet::is_course($udom,$uname)) {
                   3624:         my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502     raeburn  3625:         my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490     raeburn  3626:         return ($startblock,$endblock);
                   3627:     }
1.474     raeburn  3628: 
1.502     raeburn  3629:     my $startblock = 0;
                   3630:     my $endblock = 0;
1.482     raeburn  3631:     my %live_courses = &findallcourses(undef,$uname,$udom);
1.474     raeburn  3632: 
1.490     raeburn  3633:     # If uname is for a user, and activity is course-specific, i.e.,
                   3634:     # boards, chat or groups, check for blocking in current course only.
1.474     raeburn  3635: 
1.490     raeburn  3636:     if (($activity eq 'boards' || $activity eq 'chat' ||
                   3637:          $activity eq 'groups') && ($env{'request.course.id'})) {
                   3638:         foreach my $key (keys(%live_courses)) {
                   3639:             if ($key ne $env{'request.course.id'}) {
                   3640:                 delete($live_courses{$key});
                   3641:             }
                   3642:         }
                   3643:     }
                   3644: 
                   3645:     my $otheruser = 0;
                   3646:     my %own_courses;
                   3647:     if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
                   3648:         # Resource belongs to user other than current user.
                   3649:         $otheruser = 1;
                   3650:         # Gather courses for current user
                   3651:         %own_courses = 
                   3652:             &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
                   3653:     }
                   3654: 
                   3655:     # Gather active course roles - course coordinator, instructor, 
                   3656:     # exam proctor, ta, student, or custom role.
1.474     raeburn  3657: 
                   3658:     foreach my $course (keys(%live_courses)) {
1.482     raeburn  3659:         my ($cdom,$cnum);
                   3660:         if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
                   3661:             $cdom = $env{'course.'.$course.'.domain'};
                   3662:             $cnum = $env{'course.'.$course.'.num'};
                   3663:         } else {
1.490     raeburn  3664:             ($cdom,$cnum) = split(/_/,$course); 
1.482     raeburn  3665:         }
                   3666:         my $no_ownblock = 0;
                   3667:         my $no_userblock = 0;
1.533     raeburn  3668:         if ($otheruser && $activity ne 'com') {
1.490     raeburn  3669:             # Check if current user has 'evb' priv for this
                   3670:             if (defined($own_courses{$course})) {
                   3671:                 foreach my $sec (keys(%{$own_courses{$course}})) {
                   3672:                     my $checkrole = 'cm./'.$cdom.'/'.$cnum;
                   3673:                     if ($sec ne 'none') {
                   3674:                         $checkrole .= '/'.$sec;
                   3675:                     }
                   3676:                     if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   3677:                         $no_ownblock = 1;
                   3678:                         last;
                   3679:                     }
                   3680:                 }
                   3681:             }
                   3682:             # if they have 'evb' priv and are currently not playing student
                   3683:             next if (($no_ownblock) &&
                   3684:                  ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
                   3685:         }
1.474     raeburn  3686:         foreach my $sec (keys(%{$live_courses{$course}})) {
1.482     raeburn  3687:             my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474     raeburn  3688:             if ($sec ne 'none') {
1.482     raeburn  3689:                 $checkrole .= '/'.$sec;
1.474     raeburn  3690:             }
1.490     raeburn  3691:             if ($otheruser) {
                   3692:                 # Resource belongs to user other than current user.
                   3693:                 # Assemble privs for that user, and check for 'evb' priv.
1.482     raeburn  3694:                 my ($trole,$tdom,$tnum,$tsec);
                   3695:                 my $entry = $live_courses{$course}{$sec};
                   3696:                 if ($entry =~ /^cr/) {
                   3697:                     ($trole,$tdom,$tnum,$tsec) = 
                   3698:                       ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
                   3699:                 } else {
                   3700:                     ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
                   3701:                 }
                   3702:                 my ($spec,$area,$trest,%allroles,%userroles);
                   3703:                 $area = '/'.$tdom.'/'.$tnum;
                   3704:                 $trest = $tnum;
                   3705:                 if ($tsec ne '') {
                   3706:                     $area .= '/'.$tsec;
                   3707:                     $trest .= '/'.$tsec;
                   3708:                 }
                   3709:                 $spec = $trole.'.'.$area;
                   3710:                 if ($trole =~ /^cr/) {
                   3711:                     &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
                   3712:                                                       $tdom,$spec,$trest,$area);
                   3713:                 } else {
                   3714:                     &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
                   3715:                                                        $tdom,$spec,$trest,$area);
                   3716:                 }
                   3717:                 my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486     raeburn  3718:                 if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
                   3719:                     if ($1) {
                   3720:                         $no_userblock = 1;
                   3721:                         last;
                   3722:                     }
                   3723:                 }
1.490     raeburn  3724:             } else {
                   3725:                 # Resource belongs to current user
                   3726:                 # Check for 'evb' priv via lonnet::allowed().
1.482     raeburn  3727:                 if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   3728:                     $no_ownblock = 1;
                   3729:                     last;
                   3730:                 }
1.474     raeburn  3731:             }
                   3732:         }
                   3733:         # if they have the evb priv and are currently not playing student
1.482     raeburn  3734:         next if (($no_ownblock) &&
1.491     albertel 3735:                  ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482     raeburn  3736:         next if ($no_userblock);
1.474     raeburn  3737: 
1.490     raeburn  3738:         # Retrieve blocking times and identity of blocker for course
                   3739:         # of specified user, unless user has 'evb' privilege.
1.502     raeburn  3740:         
                   3741:         my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
                   3742:         if (($start != 0) && 
                   3743:             (($startblock == 0) || ($startblock > $start))) {
                   3744:             $startblock = $start;
                   3745:         }
                   3746:         if (($end != 0)  &&
                   3747:             (($endblock == 0) || ($endblock < $end))) {
                   3748:             $endblock = $end;
                   3749:         }
1.490     raeburn  3750:     }
                   3751:     return ($startblock,$endblock);
                   3752: }
                   3753: 
                   3754: sub get_blocks {
                   3755:     my ($setters,$activity,$cdom,$cnum) = @_;
                   3756:     my $startblock = 0;
                   3757:     my $endblock = 0;
                   3758:     my $course = $cdom.'_'.$cnum;
                   3759:     $setters->{$course} = {};
                   3760:     $setters->{$course}{'staff'} = [];
                   3761:     $setters->{$course}{'times'} = [];
                   3762:     my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
                   3763:     foreach my $record (keys(%records)) {
                   3764:         my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
                   3765:         if ($start <= time && $end >= time) {
                   3766:             my ($staff_name,$staff_dom,$title,$blocks) =
                   3767:                 &parse_block_record($records{$record});
                   3768:             if ($blocks->{$activity} eq 'on') {
                   3769:                 push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
                   3770:                 push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491     albertel 3771:                 if ( ($startblock == 0) || ($startblock > $start) ) {
                   3772:                     $startblock = $start;
1.490     raeburn  3773:                 }
1.491     albertel 3774:                 if ( ($endblock == 0) || ($endblock < $end) ) {
                   3775:                     $endblock = $end;
1.474     raeburn  3776:                 }
                   3777:             }
                   3778:         }
                   3779:     }
                   3780:     return ($startblock,$endblock);
                   3781: }
                   3782: 
                   3783: sub parse_block_record {
                   3784:     my ($record) = @_;
                   3785:     my ($setuname,$setudom,$title,$blocks);
                   3786:     if (ref($record) eq 'HASH') {
                   3787:         ($setuname,$setudom) = split(/:/,$record->{'setter'});
                   3788:         $title = &unescape($record->{'event'});
                   3789:         $blocks = $record->{'blocks'};
                   3790:     } else {
                   3791:         my @data = split(/:/,$record,3);
                   3792:         if (scalar(@data) eq 2) {
                   3793:             $title = $data[1];
                   3794:             ($setuname,$setudom) = split(/@/,$data[0]);
                   3795:         } else {
                   3796:             ($setuname,$setudom,$title) = @data;
                   3797:         }
                   3798:         $blocks = { 'com' => 'on' };
                   3799:     }
                   3800:     return ($setuname,$setudom,$title,$blocks);
                   3801: }
                   3802: 
                   3803: sub build_block_table {
                   3804:     my ($startblock,$endblock,$setters) = @_;
                   3805:     my %lt = &Apache::lonlocal::texthash(
                   3806:         'cacb' => 'Currently active communication blocks',
                   3807:         'cour' => 'Course',
                   3808:         'dura' => 'Duration',
                   3809:         'blse' => 'Block set by'
                   3810:     );
                   3811:     my $output;
1.476     raeburn  3812:     $output = '<br />'.$lt{'cacb'}.':<br />';
1.474     raeburn  3813:     $output .= &start_data_table();
                   3814:     $output .= '
                   3815: <tr>
                   3816:  <th>'.$lt{'cour'}.'</th>
                   3817:  <th>'.$lt{'dura'}.'</th>
                   3818:  <th>'.$lt{'blse'}.'</th>
                   3819: </tr>
                   3820: ';
                   3821:     foreach my $course (keys(%{$setters})) {
                   3822:         my %courseinfo=&Apache::lonnet::coursedescription($course);
                   3823:         for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
                   3824:             my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490     raeburn  3825:             my $fullname = &plainname($uname,$udom);
                   3826:             if (defined($env{'user.name'}) && defined($env{'user.domain'})
                   3827:                 && $env{'user.name'} ne 'public' 
                   3828:                 && $env{'user.domain'} ne 'public') {
                   3829:                 $fullname = &aboutmewrapper($fullname,$uname,$udom);
                   3830:             }
1.474     raeburn  3831:             my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
                   3832:             $openblock = &Apache::lonlocal::locallocaltime($openblock);
                   3833:             $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
                   3834:             $output .= &Apache::loncommon::start_data_table_row().
                   3835:                        '<td>'.$courseinfo{'description'}.'</td>'.
                   3836:                        '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490     raeburn  3837:                        '<td>'.$fullname.'</td>'.
1.474     raeburn  3838:                         &Apache::loncommon::end_data_table_row();
                   3839:         }
                   3840:     }
                   3841:     $output .= &end_data_table();
                   3842: }
                   3843: 
1.490     raeburn  3844: sub blocking_status {
                   3845:     my ($activity,$uname,$udom) = @_;
                   3846:     my %setters;
                   3847:     my ($blocked,$output,$ownitem,$is_course);
                   3848:     my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
                   3849:     if ($startblock && $endblock) {
                   3850:         $blocked = 1;
                   3851:         if (wantarray) {
                   3852:             my $category;
                   3853:             if ($activity eq 'boards') {
                   3854:                 $category = 'Discussion posts in this course';
                   3855:             } elsif ($activity eq 'blogs') {
                   3856:                 $category = 'Blogs';
                   3857:             } elsif ($activity eq 'port') {
                   3858:                 if (defined($uname) && defined($udom)) {
                   3859:                     if ($uname eq $env{'user.name'} &&
                   3860:                         $udom eq $env{'user.domain'}) {
                   3861:                         $ownitem = 1;
                   3862:                     }
                   3863:                 }
                   3864:                 $is_course = &Apache::lonnet::is_course($udom,$uname);
                   3865:                 if ($ownitem) { 
                   3866:                     $category = 'Your portfolio files';  
                   3867:                 } elsif ($is_course) {
                   3868:                     my $coursedesc;
                   3869:                     foreach my $course (keys(%setters)) {
                   3870:                         my %courseinfo =
                   3871:                              &Apache::lonnet::coursedescription($course);
                   3872:                         $coursedesc = $courseinfo{'description'};
                   3873:                     }
1.764     weissno  3874:                     $category = "Group portfolio in the course '$coursedesc'";
1.490     raeburn  3875:                 } else {
                   3876:                     $category = 'Portfolio files belonging to ';
                   3877:                     if ($env{'user.name'} eq 'public' && 
                   3878:                         $env{'user.domain'} eq 'public') {
                   3879:                         $category .= &plainname($uname,$udom);
                   3880:                     } else {
                   3881:                         $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);  
                   3882:                     }
                   3883:                 }
                   3884:             } elsif ($activity eq 'groups') {
                   3885:                 $category = 'Groups in this course';
                   3886:             }
                   3887:             my $showstart = &Apache::lonlocal::locallocaltime($startblock);
                   3888:             my $showend = &Apache::lonlocal::locallocaltime($endblock);
                   3889:             $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
                   3890:             if (!($activity eq 'port' && !($ownitem) && !($is_course))) { 
                   3891:                 $output .= &build_block_table($startblock,$endblock,\%setters);
                   3892:             }
                   3893:         }
                   3894:     }
                   3895:     if (wantarray) {
                   3896:         return ($blocked,$output);
                   3897:     } else {
                   3898:         return $blocked;
                   3899:     }
                   3900: }
                   3901: 
1.60      matthew  3902: ###############################################
                   3903: 
1.682     raeburn  3904: sub check_ip_acc {
                   3905:     my ($acc)=@_;
                   3906:     &Apache::lonxml::debug("acc is $acc");
                   3907:     if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
                   3908:         return 1;
                   3909:     }
                   3910:     my $allowed=0;
                   3911:     my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
                   3912: 
                   3913:     my $name;
                   3914:     foreach my $pattern (split(',',$acc)) {
                   3915:         $pattern =~ s/^\s*//;
                   3916:         $pattern =~ s/\s*$//;
                   3917:         if ($pattern =~ /\*$/) {
                   3918:             #35.8.*
                   3919:             $pattern=~s/\*//;
                   3920:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   3921:         } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
                   3922:             #35.8.3.[34-56]
                   3923:             my $low=$2;
                   3924:             my $high=$3;
                   3925:             $pattern=$1;
                   3926:             if ($ip =~ /^\Q$pattern\E/) {
                   3927:                 my $last=(split(/\./,$ip))[3];
                   3928:                 if ($last <=$high && $last >=$low) { $allowed=1; }
                   3929:             }
                   3930:         } elsif ($pattern =~ /^\*/) {
                   3931:             #*.msu.edu
                   3932:             $pattern=~s/\*//;
                   3933:             if (!defined($name)) {
                   3934:                 use Socket;
                   3935:                 my $netaddr=inet_aton($ip);
                   3936:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   3937:             }
                   3938:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   3939:         } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
                   3940:             #127.0.0.1
                   3941:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   3942:         } else {
                   3943:             #some.name.com
                   3944:             if (!defined($name)) {
                   3945:                 use Socket;
                   3946:                 my $netaddr=inet_aton($ip);
                   3947:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   3948:             }
                   3949:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   3950:         }
                   3951:         if ($allowed) { last; }
                   3952:     }
                   3953:     return $allowed;
                   3954: }
                   3955: 
                   3956: ###############################################
                   3957: 
1.60      matthew  3958: =pod
                   3959: 
1.112     bowersj2 3960: =head1 Domain Template Functions
                   3961: 
                   3962: =over 4
                   3963: 
                   3964: =item * &determinedomain()
1.60      matthew  3965: 
                   3966: Inputs: $domain (usually will be undef)
                   3967: 
1.63      www      3968: Returns: Determines which domain should be used for designs
1.60      matthew  3969: 
                   3970: =cut
1.54      www      3971: 
1.60      matthew  3972: ###############################################
1.63      www      3973: sub determinedomain {
                   3974:     my $domain=shift;
1.531     albertel 3975:     if (! $domain) {
1.60      matthew  3976:         # Determine domain if we have not been given one
                   3977:         $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258     albertel 3978:         if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
                   3979:         if ($env{'request.role.domain'}) { 
                   3980:             $domain=$env{'request.role.domain'}; 
1.60      matthew  3981:         }
                   3982:     }
1.63      www      3983:     return $domain;
                   3984: }
                   3985: ###############################################
1.517     raeburn  3986: 
1.518     albertel 3987: sub devalidate_domconfig_cache {
                   3988:     my ($udom)=@_;
                   3989:     &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
                   3990: }
                   3991: 
                   3992: # ---------------------- Get domain configuration for a domain
                   3993: sub get_domainconf {
                   3994:     my ($udom) = @_;
                   3995:     my $cachetime=1800;
                   3996:     my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
                   3997:     if (defined($cached)) { return %{$result}; }
                   3998: 
                   3999:     my %domconfig = &Apache::lonnet::get_dom('configuration',
                   4000: 					     ['login','rolecolors'],$udom);
1.632     raeburn  4001:     my (%designhash,%legacy);
1.518     albertel 4002:     if (keys(%domconfig) > 0) {
                   4003:         if (ref($domconfig{'login'}) eq 'HASH') {
1.632     raeburn  4004:             if (keys(%{$domconfig{'login'}})) {
                   4005:                 foreach my $key (keys(%{$domconfig{'login'}})) {
1.699     raeburn  4006:                     if (ref($domconfig{'login'}{$key}) eq 'HASH') {
                   4007:                         foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
                   4008:                             $designhash{$udom.'.login.'.$key.'_'.$img} = 
                   4009:                                 $domconfig{'login'}{$key}{$img};
                   4010:                         }
                   4011:                     } else {
                   4012:                         $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
                   4013:                     }
1.632     raeburn  4014:                 }
                   4015:             } else {
                   4016:                 $legacy{'login'} = 1;
1.518     albertel 4017:             }
1.632     raeburn  4018:         } else {
                   4019:             $legacy{'login'} = 1;
1.518     albertel 4020:         }
                   4021:         if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632     raeburn  4022:             if (keys(%{$domconfig{'rolecolors'}})) {
                   4023:                 foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
                   4024:                     if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
                   4025:                         foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
                   4026:                             $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
                   4027:                         }
1.518     albertel 4028:                     }
                   4029:                 }
1.632     raeburn  4030:             } else {
                   4031:                 $legacy{'rolecolors'} = 1;
1.518     albertel 4032:             }
1.632     raeburn  4033:         } else {
                   4034:             $legacy{'rolecolors'} = 1;
1.518     albertel 4035:         }
1.632     raeburn  4036:         if (keys(%legacy) > 0) {
                   4037:             my %legacyhash = &get_legacy_domconf($udom);
                   4038:             foreach my $item (keys(%legacyhash)) {
                   4039:                 if ($item =~ /^\Q$udom\E\.login/) {
                   4040:                     if ($legacy{'login'}) { 
                   4041:                         $designhash{$item} = $legacyhash{$item};
                   4042:                     }
                   4043:                 } else {
                   4044:                     if ($legacy{'rolecolors'}) {
                   4045:                         $designhash{$item} = $legacyhash{$item};
                   4046:                     }
1.518     albertel 4047:                 }
                   4048:             }
                   4049:         }
1.632     raeburn  4050:     } else {
                   4051:         %designhash = &get_legacy_domconf($udom); 
1.518     albertel 4052:     }
                   4053:     &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
                   4054: 				  $cachetime);
                   4055:     return %designhash;
                   4056: }
                   4057: 
1.632     raeburn  4058: sub get_legacy_domconf {
                   4059:     my ($udom) = @_;
                   4060:     my %legacyhash;
                   4061:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
                   4062:     my $designfile =  $designdir.'/'.$udom.'.tab';
                   4063:     if (-e $designfile) {
                   4064:         if ( open (my $fh,"<$designfile") ) {
                   4065:             while (my $line = <$fh>) {
                   4066:                 next if ($line =~ /^\#/);
                   4067:                 chomp($line);
                   4068:                 my ($key,$val)=(split(/\=/,$line));
                   4069:                 if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
                   4070:             }
                   4071:             close($fh);
                   4072:         }
                   4073:     }
                   4074:     if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
                   4075:         $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
                   4076:     }
                   4077:     return %legacyhash;
                   4078: }
                   4079: 
1.63      www      4080: =pod
                   4081: 
1.112     bowersj2 4082: =item * &domainlogo()
1.63      www      4083: 
                   4084: Inputs: $domain (usually will be undef)
                   4085: 
                   4086: Returns: A link to a domain logo, if the domain logo exists.
                   4087: If the domain logo does not exist, a description of the domain.
                   4088: 
                   4089: =cut
1.112     bowersj2 4090: 
1.63      www      4091: ###############################################
                   4092: sub domainlogo {
1.517     raeburn  4093:     my $domain = &determinedomain(shift);
1.518     albertel 4094:     my %designhash = &get_domainconf($domain);    
1.517     raeburn  4095:     # See if there is a logo
                   4096:     if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519     raeburn  4097:         my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538     albertel 4098:         if ($imgsrc =~ m{^/(adm|res)/}) {
                   4099: 	    if ($imgsrc =~ m{^/res/}) {
                   4100: 		my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
                   4101: 		&Apache::lonnet::repcopy($local_name);
                   4102: 	    }
                   4103: 	   $imgsrc = &lonhttpdurl($imgsrc);
1.519     raeburn  4104:         } 
                   4105:         return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514     albertel 4106:     } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
                   4107:         return &Apache::lonnet::domain($domain,'description');
1.59      www      4108:     } else {
1.60      matthew  4109:         return '';
1.59      www      4110:     }
                   4111: }
1.63      www      4112: ##############################################
                   4113: 
                   4114: =pod
                   4115: 
1.112     bowersj2 4116: =item * &designparm()
1.63      www      4117: 
                   4118: Inputs: $which parameter; $domain (usually will be undef)
                   4119: 
                   4120: Returns: value of designparamter $which
                   4121: 
                   4122: =cut
1.112     bowersj2 4123: 
1.397     albertel 4124: 
1.400     albertel 4125: ##############################################
1.397     albertel 4126: sub designparm {
                   4127:     my ($which,$domain)=@_;
1.258     albertel 4128:     if ($env{'browser.blackwhite'} eq 'on') {
1.635     raeburn  4129: 	if ($which=~/\.(font|alink|vlink|link|textcol)$/) {
1.110     www      4130: 	    return '#000000';
                   4131: 	}
1.635     raeburn  4132: 	if ($which=~/\.(pgbg|sidebg|bgcol)$/) {
1.110     www      4133: 	    return '#FFFFFF';
                   4134: 	}
                   4135: 	if ($which=~/\.tabbg$/) {
                   4136: 	    return '#CCCCCC';
                   4137: 	}
                   4138:     }
1.397     albertel 4139:     if (exists($env{'environment.color.'.$which})) {
1.258     albertel 4140: 	return $env{'environment.color.'.$which};
1.96      www      4141:     }
1.63      www      4142:     $domain=&determinedomain($domain);
1.518     albertel 4143:     my %domdesign = &get_domainconf($domain);
1.520     raeburn  4144:     my $output;
1.517     raeburn  4145:     if ($domdesign{$domain.'.'.$which} ne '') {
1.520     raeburn  4146: 	$output = $domdesign{$domain.'.'.$which};
1.63      www      4147:     } else {
1.520     raeburn  4148:         $output = $defaultdesign{$which};
                   4149:     }
                   4150:     if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635     raeburn  4151:         ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538     albertel 4152:         if ($output =~ m{^/(adm|res)/}) {
                   4153: 	    if ($output =~ m{^/res/}) {
                   4154: 		my $local_name = &Apache::lonnet::filelocation('',$output);
                   4155: 		&Apache::lonnet::repcopy($local_name);
                   4156: 	    }
1.520     raeburn  4157:             $output = &lonhttpdurl($output);
                   4158:         }
1.63      www      4159:     }
1.520     raeburn  4160:     return $output;
1.63      www      4161: }
1.59      www      4162: 
1.60      matthew  4163: ###############################################
                   4164: ###############################################
                   4165: 
                   4166: =pod
                   4167: 
1.112     bowersj2 4168: =back
                   4169: 
1.549     albertel 4170: =head1 HTML Helpers
1.112     bowersj2 4171: 
                   4172: =over 4
                   4173: 
                   4174: =item * &bodytag()
1.60      matthew  4175: 
                   4176: Returns a uniform header for LON-CAPA web pages.
                   4177: 
                   4178: Inputs: 
                   4179: 
1.112     bowersj2 4180: =over 4
                   4181: 
                   4182: =item * $title, A title to be displayed on the page.
                   4183: 
                   4184: =item * $function, the current role (can be undef).
                   4185: 
                   4186: =item * $addentries, extra parameters for the <body> tag.
                   4187: 
                   4188: =item * $bodyonly, if defined, only return the <body> tag.
                   4189: 
                   4190: =item * $domain, if defined, force a given domain.
                   4191: 
                   4192: =item * $forcereg, if page should register as content page (relevant for 
1.86      www      4193:             text interface only)
1.60      matthew  4194: 
1.326     albertel 4195: =item * $customtitle, alternate text to use instead of $title
                   4196:                       in the title box that appears, this text
                   4197:                       is not auto translated like the $title is
1.309     albertel 4198: 
                   4199: =item * $notopbar, if true, keep the 'what is this' info but remove the
                   4200:                    navigational links
1.317     albertel 4201: 
1.338     albertel 4202: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
                   4203: 
                   4204: =item * $notitle, if true keep the nav controls, but remove the title bar
                   4205: 
1.361     albertel 4206: =item * $no_inline_link, if true and in remote mode, don't show the 
                   4207:          'Switch To Inline Menu' link
                   4208: 
1.460     albertel 4209: =item * $args, optional argument valid values are
                   4210:             no_auto_mt_title -> prevents &mt()ing the title arg
1.562     albertel 4211:             inherit_jsmath -> when creating popup window in a page,
                   4212:                               should it have jsmath forced on by the
                   4213:                               current page
1.460     albertel 4214: 
1.112     bowersj2 4215: =back
                   4216: 
1.60      matthew  4217: Returns: A uniform header for LON-CAPA web pages.  
                   4218: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
                   4219: If $bodyonly is undef or zero, an html string containing a <body> tag and 
                   4220: other decorations will be returned.
                   4221: 
                   4222: =cut
                   4223: 
1.54      www      4224: sub bodytag {
1.309     albertel 4225:     my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
1.460     albertel 4226: 	$notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
1.339     albertel 4227: 
1.460     albertel 4228:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339     albertel 4229: 
1.183     matthew  4230:     $function = &get_users_function() if (!$function);
1.339     albertel 4231:     my $img =    &designparm($function.'.img',$domain);
                   4232:     my $font =   &designparm($function.'.font',$domain);
                   4233:     my $pgbg   = $bgcolor || &designparm($function.'.pgbg',$domain);
                   4234: 
                   4235:     my %design = ( 'style'   => 'margin-top: 0px',
1.535     albertel 4236: 		   'bgcolor' => $pgbg,
1.339     albertel 4237: 		   'text'    => $font,
                   4238:                    'alink'   => &designparm($function.'.alink',$domain),
                   4239: 		   'vlink'   => &designparm($function.'.vlink',$domain),
                   4240: 		   'link'    => &designparm($function.'.link',$domain),);
1.438     albertel 4241:     @design{keys(%$addentries)} = @$addentries{keys(%$addentries)}; 
1.339     albertel 4242: 
1.63      www      4243:  # role and realm
1.378     raeburn  4244:     my ($role,$realm) = split(/\./,$env{'request.role'},2);
                   4245:     if ($role  eq 'ca') {
1.479     albertel 4246:         my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500     albertel 4247:         $realm = &plainname($rname,$rdom);
1.378     raeburn  4248:     } 
1.55      www      4249: # realm
1.258     albertel 4250:     if ($env{'request.course.id'}) {
1.378     raeburn  4251:         if ($env{'request.role'} !~ /^cr/) {
                   4252:             $role = &Apache::lonnet::plaintext($role,&course_type());
                   4253:         }
1.359     albertel 4254: 	$realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378     raeburn  4255:     } else {
                   4256:         $role = &Apache::lonnet::plaintext($role);
1.54      www      4257:     }
1.433     albertel 4258: 
1.359     albertel 4259:     if (!$realm) { $realm='&nbsp;'; }
1.55      www      4260: # Set messages
1.60      matthew  4261:     my $messages=&domainlogo($domain);
1.330     albertel 4262: 
1.438     albertel 4263:     my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329     albertel 4264: 
1.101     www      4265: # construct main body tag
1.359     albertel 4266:     my $bodytag = "<body $extra_body_attr>".
1.562     albertel 4267: 	&Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252     albertel 4268: 
1.530     albertel 4269:     if ($bodyonly) {
1.60      matthew  4270:         return $bodytag;
1.258     albertel 4271:     } elsif ($env{'browser.interface'} eq 'textual') {
1.95      www      4272: # Accessibility
1.224     raeburn  4273:           
1.337     albertel 4274: 	$bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg);
1.338     albertel 4275: 	if (!$notitle) {
1.337     albertel 4276: 	    $bodytag.='<h1>LON-CAPA: '.$title.'</h1>';
                   4277: 	}
                   4278: 	return $bodytag;
1.359     albertel 4279:     }
                   4280: 
1.410     albertel 4281:     my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433     albertel 4282:     if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
                   4283: 	undef($role);
1.434     albertel 4284:     } else {
                   4285: 	$name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433     albertel 4286:     }
1.359     albertel 4287:     
                   4288:     my $roleinfo=(<<ENDROLE);
                   4289: <td class="LC_title_bar_who">
                   4290: <div class="LC_title_bar_name">
1.410     albertel 4291:     $name
1.361     albertel 4292:     &nbsp;
1.359     albertel 4293: </div>
                   4294: <div class="LC_title_bar_role">
1.361     albertel 4295: $role&nbsp;
1.359     albertel 4296: </div>
                   4297: <div class="LC_title_bar_realm">
1.361     albertel 4298: $realm&nbsp;
1.359     albertel 4299: </div>
1.206     albertel 4300: </td>
                   4301: ENDROLE
1.235     raeburn  4302: 
1.762     bisitz   4303:     my $titleinfo = '<h1>'.$title.'</h1>';
1.359     albertel 4304:     if ($customtitle) {
                   4305:         $titleinfo = $customtitle;
                   4306:     }
                   4307:     #
                   4308:     # Extra info if you are the DC
                   4309:     my $dc_info = '';
                   4310:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   4311:                         $env{'course.'.$env{'request.course.id'}.
                   4312:                                  '.domain'}.'/'})) {
                   4313:         my $cid = $env{'request.course.id'};
                   4314:         $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380     www      4315:         $dc_info =~ s/\s+$//;
1.359     albertel 4316:         $dc_info = '('.$dc_info.')';
                   4317:     }
                   4318: 
1.644     www      4319:     if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) {
1.359     albertel 4320:         # No Remote
1.258     albertel 4321: 	if ($env{'request.state'} eq 'construct') {
1.359     albertel 4322: 	    $forcereg=1;
                   4323: 	}
                   4324: 
                   4325: 	if (!$customtitle && $env{'request.state'} eq 'construct') {
                   4326: 	    # this is for resources; directories have customtitle, and crumbs
                   4327:             # and select recent are created in lonpubdir.pm  
1.229     albertel 4328: 	    my ($uname,$thisdisfn)=
1.258     albertel 4329: 		($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
1.229     albertel 4330: 	    my $formaction='/priv/'.$uname.'/'.$thisdisfn;
                   4331: 	    $formaction=~s/\/+/\//g;
                   4332: 
1.359     albertel 4333: 	    my $parentpath = '';
                   4334: 	    my $lastitem = '';
                   4335: 	    if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
                   4336: 		$parentpath = $1;
                   4337: 		$lastitem = $2;
                   4338: 	    } else {
                   4339: 		$lastitem = $thisdisfn;
                   4340: 	    }
                   4341: 	    $titleinfo = 
1.640     bisitz   4342: 		&Apache::loncommon::help_open_menu('','',3,'Authoring')
                   4343: 		.'<b>'.&mt('Construction Space').'</b>:&nbsp;'
                   4344: 		.'<form name="dirs" method="post" action="'.$formaction
1.359     albertel 4345: 		.'" target="_top"><tt><b>'
1.705     tempelho 4346: 		.&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<span class=\"LC_fontsize_big\">$lastitem</span></b></tt><br />"
1.359     albertel 4347: 		.&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
                   4348: 		.'</form>'
                   4349: 		.&Apache::lonmenu::constspaceform();
1.235     raeburn  4350:         }
1.359     albertel 4351: 
1.337     albertel 4352:         my $titletable;
1.338     albertel 4353: 	if (!$notitle) {
1.337     albertel 4354: 	    $titletable =
1.359     albertel 4355: 		'<table id="LC_title_bar">'.
                   4356:                          "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
                   4357: 			 '</tr></table>';
1.337     albertel 4358: 	}
1.359     albertel 4359: 	if ($notopbar) {
                   4360: 	    $bodytag .= $titletable;
                   4361: 	} else {
                   4362: 	    if ($env{'request.state'} eq 'construct') {
1.337     albertel 4363:                 $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
                   4364: 							  $titletable);
1.272     raeburn  4365:             } else {
1.336     albertel 4366:                 $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
1.359     albertel 4367: 		    $titletable;
1.272     raeburn  4368:             }
1.235     raeburn  4369:         }
                   4370:         return $bodytag;
1.94      www      4371:     }
1.95      www      4372: 
1.93      www      4373: #
1.95      www      4374: # Top frame rendering, Remote is up
1.93      www      4375: #
1.359     albertel 4376: 
1.517     raeburn  4377:     my $imgsrc = $img;
                   4378:     if ($img =~ /^\/adm/) {
1.575     albertel 4379:         $imgsrc = &lonhttpdurl($img);
1.517     raeburn  4380:     }
                   4381:     my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359     albertel 4382: 
1.305     www      4383:     # Explicit link to get inline menu
1.361     albertel 4384:     my $menu= ($no_inline_link?''
                   4385: 	       :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
1.245     matthew  4386:     #
1.338     albertel 4387:     if ($notitle) {
1.337     albertel 4388: 	return $bodytag;
                   4389:     }
1.94      www      4390:     return(<<ENDBODY);
1.60      matthew  4391: $bodytag
1.359     albertel 4392: <table id="LC_title_bar" class="LC_with_remote">
1.791     tempelho 4393: <tr><td>$upperleft</td>
                   4394:     <td>$messages&nbsp;</td>
1.54      www      4395: </tr>
1.359     albertel 4396: <tr><td>$titleinfo $dc_info $menu</td>
                   4397: $roleinfo
1.368     albertel 4398: </tr>
1.356     albertel 4399: </table>
1.54      www      4400: ENDBODY
1.182     matthew  4401: }
                   4402: 
1.330     albertel 4403: sub make_attr_string {
                   4404:     my ($register,$attr_ref) = @_;
                   4405: 
                   4406:     if ($attr_ref && !ref($attr_ref)) {
                   4407: 	die("addentries Must be a hash ref ".
                   4408: 	    join(':',caller(1))." ".
                   4409: 	    join(':',caller(0))." ");
                   4410:     }
                   4411: 
                   4412:     if ($register) {
1.339     albertel 4413: 	my ($on_load,$on_unload);
                   4414: 	foreach my $key (keys(%{$attr_ref})) {
                   4415: 	    if      (lc($key) eq 'onload') {
                   4416: 		$on_load.=$attr_ref->{$key}.';';
                   4417: 		delete($attr_ref->{$key});
                   4418: 
                   4419: 	    } elsif (lc($key) eq 'onunload') {
                   4420: 		$on_unload.=$attr_ref->{$key}.';';
                   4421: 		delete($attr_ref->{$key});
                   4422: 	    }
                   4423: 	}
                   4424: 	$attr_ref->{'onload'}  =
                   4425: 	    &Apache::lonmenu::loadevents().  $on_load;
                   4426: 	$attr_ref->{'onunload'}=
                   4427: 	    &Apache::lonmenu::unloadevents().$on_unload;
                   4428:     }
                   4429: 
                   4430: # Accessibility font enhance
                   4431:     if ($env{'browser.fontenhance'} eq 'on') {
                   4432: 	my $style;
                   4433: 	foreach my $key (keys(%{$attr_ref})) {
                   4434: 	    if (lc($key) eq 'style') {
                   4435: 		$style.=$attr_ref->{$key}.';';
                   4436: 		delete($attr_ref->{$key});
                   4437: 	    }
                   4438: 	}
                   4439: 	$attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330     albertel 4440:     }
1.339     albertel 4441: 
                   4442:     if ($env{'browser.blackwhite'} eq 'on') {
                   4443: 	delete($attr_ref->{'font'});
                   4444: 	delete($attr_ref->{'link'});
                   4445: 	delete($attr_ref->{'alink'});
                   4446: 	delete($attr_ref->{'vlink'});
                   4447: 	delete($attr_ref->{'bgcolor'});
                   4448: 	delete($attr_ref->{'background'});
                   4449:     }
                   4450: 
1.330     albertel 4451:     my $attr_string;
                   4452:     foreach my $attr (keys(%$attr_ref)) {
                   4453: 	$attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
                   4454:     }
                   4455:     return $attr_string;
                   4456: }
                   4457: 
                   4458: 
1.182     matthew  4459: ###############################################
1.251     albertel 4460: ###############################################
                   4461: 
                   4462: =pod
                   4463: 
                   4464: =item * &endbodytag()
                   4465: 
                   4466: Returns a uniform footer for LON-CAPA web pages.
                   4467: 
1.635     raeburn  4468: Inputs: 1 - optional reference to an args hash
                   4469: If in the hash, key for noredirectlink has a value which evaluates to true,
                   4470: a 'Continue' link is not displayed if the page contains an
                   4471: internal redirect in the <head></head> section,
                   4472: i.e., $env{'internal.head.redirect'} exists   
1.251     albertel 4473: 
                   4474: =cut
                   4475: 
                   4476: sub endbodytag {
1.635     raeburn  4477:     my ($args) = @_;
1.251     albertel 4478:     my $endbodytag='</body>';
1.269     albertel 4479:     $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315     albertel 4480:     if ( exists( $env{'internal.head.redirect'} ) ) {
1.635     raeburn  4481:         if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
                   4482: 	    $endbodytag=
                   4483: 	        "<br /><a href=\"$env{'internal.head.redirect'}\">".
                   4484: 	        &mt('Continue').'</a>'.
                   4485: 	        $endbodytag;
                   4486:         }
1.315     albertel 4487:     }
1.251     albertel 4488:     return $endbodytag;
                   4489: }
                   4490: 
1.352     albertel 4491: =pod
                   4492: 
                   4493: =item * &standard_css()
                   4494: 
                   4495: Returns a style sheet
                   4496: 
                   4497: Inputs: (all optional)
                   4498:             domain         -> force to color decorate a page for a specific
                   4499:                                domain
                   4500:             function       -> force usage of a specific rolish color scheme
                   4501:             bgcolor        -> override the default page bgcolor
                   4502: 
                   4503: =cut
                   4504: 
1.343     albertel 4505: sub standard_css {
1.345     albertel 4506:     my ($function,$domain,$bgcolor) = @_;
1.352     albertel 4507:     $function  = &get_users_function() if (!$function);
                   4508:     my $img    = &designparm($function.'.img',   $domain);
                   4509:     my $tabbg  = &designparm($function.'.tabbg', $domain);
                   4510:     my $font   = &designparm($function.'.font',  $domain);
1.791     tempelho 4511: #second colour for later usage
1.345     albertel 4512:     my $sidebg = &designparm($function.'.sidebg',$domain);
1.382     albertel 4513:     my $pgbg_or_bgcolor =
                   4514: 	         $bgcolor ||
1.352     albertel 4515: 	         &designparm($function.'.pgbg',  $domain);
1.382     albertel 4516:     my $pgbg   = &designparm($function.'.pgbg',  $domain);
1.352     albertel 4517:     my $alink  = &designparm($function.'.alink', $domain);
                   4518:     my $vlink  = &designparm($function.'.vlink', $domain);
                   4519:     my $link   = &designparm($function.'.link',  $domain);
                   4520: 
1.704     muellerd 4521:     my $loginbg = &designparm('login.sidebg',$domain);
1.712     muellerd 4522:     my $bgcol = &designparm('login.bgcol',$domain);
                   4523:     my $textcol = &designparm('login.textcol',$domain);
1.704     muellerd 4524: 
1.602     albertel 4525:     my $sans                 = 'Verdana,Arial,Helvetica,sans-serif';
1.395     albertel 4526:     my $mono                 = 'monospace';
1.352     albertel 4527:     my $data_table_head      = $tabbg;
                   4528:     my $data_table_light     = '#EEEEEE';
1.470     banghart 4529:     my $data_table_dark      = '#DDDDDD';
                   4530:     my $data_table_darker    = '#CCCCCC';
1.349     albertel 4531:     my $data_table_highlight = '#FFFF00';
1.352     albertel 4532:     my $mail_new             = '#FFBB77';
                   4533:     my $mail_new_hover       = '#DD9955';
                   4534:     my $mail_read            = '#BBBB77';
                   4535:     my $mail_read_hover      = '#999944';
                   4536:     my $mail_replied         = '#AAAA88';
                   4537:     my $mail_replied_hover   = '#888855';
                   4538:     my $mail_other           = '#99BBBB';
                   4539:     my $mail_other_hover     = '#669999';
1.391     albertel 4540:     my $table_header         = '#DDDDDD';
1.489     raeburn  4541:     my $feedback_link_bg     = '#BBBBBB';
1.701     harmsja  4542:     my $lg_border_color	     = '#C8C8C8';
1.392     albertel 4543: 
1.608     albertel 4544:     my $border = ($env{'browser.type'} eq 'explorer' ||
                   4545: 		  $env{'browser.type'} eq 'safari'     ) ? '0px 2px 0px 2px'
                   4546: 	                                                 : '0px 3px 0px 4px';
1.448     albertel 4547: 
1.523     albertel 4548: 
1.343     albertel 4549:     return <<END;
1.795   ! www      4550: body {
        !          4551:    font-family: $sans;
        !          4552:    line-height:130%;
        !          4553:    font-size:0.83em;
        !          4554:    color:$font;
        !          4555: }
        !          4556: 
        !          4557: a:link, a:visited { 
        !          4558:   font-size:100%; 
        !          4559: }
        !          4560: 
        !          4561: a:focus { 
        !          4562:   color: red;
        !          4563:   background: yellow 
        !          4564: }
1.698     harmsja  4565: 
1.510     albertel 4566: table.thinborder,
                   4567: table.thinborder tr th {
                   4568:   border-style: solid;
                   4569:   border-width: 1px;
1.698     harmsja  4570:   border-color: $lg_border_color;
1.510     albertel 4571:   background: $tabbg;
                   4572: }
1.795   ! www      4573: 
1.523     albertel 4574: table.thinborder tr td {
1.510     albertel 4575:   border-style: solid;
1.698     harmsja  4576:   border-width: 1px;
                   4577:   border-color: $lg_border_color;
1.510     albertel 4578: }
1.426     albertel 4579: 
1.795   ! www      4580: form, .inline { 
        !          4581:    display: inline; 
        !          4582: }
1.721     harmsja  4583: 
1.795   ! www      4584: .LC_right {
        !          4585:    text-align:right;
        !          4586: }
        !          4587: 
        !          4588: .LC_middle {
        !          4589:    vertical-align:middle;
        !          4590: }
1.721     harmsja  4591: 
                   4592: /* just for tests */
1.754     droeschl 4593: .LC_400Box {width:400px; }
1.721     harmsja  4594: /* end */
                   4595: 
1.778     bisitz   4596: .LC_filename {
                   4597:   font-family: $mono;
                   4598:   white-space:pre;
                   4599: }
                   4600: 
                   4601: .LC_fileicon {
                   4602:   border: none;
                   4603:   height: 1.3em;
                   4604:   vertical-align: text-bottom;
                   4605:   margin-right: 0.3em;
                   4606:   text-decoration:none;
                   4607: }
                   4608: 
1.350     albertel 4609: .LC_error {
                   4610:   color: red;
                   4611:   font-size: larger;
                   4612: }
1.795   ! www      4613: 
1.457     albertel 4614: .LC_warning,
                   4615: .LC_diff_removed {
1.733     bisitz   4616:   color: red;
1.394     albertel 4617: }
1.532     albertel 4618: 
                   4619: .LC_info,
1.457     albertel 4620: .LC_success,
                   4621: .LC_diff_added {
1.350     albertel 4622:   color: green;
                   4623: }
1.795   ! www      4624: 
1.543     albertel 4625: .LC_unknown {
                   4626:   color: yellow;
                   4627: }
                   4628: 
1.440     albertel 4629: .LC_icon {
1.771     droeschl 4630:   border: none;
1.790     droeschl 4631:   vertical-align: middle;
1.771     droeschl 4632: }
                   4633: 
1.539     albertel 4634: .LC_indexer_icon {
                   4635:   border: 0px;
                   4636:   height: 22px;
                   4637: }
1.795   ! www      4638: 
1.543     albertel 4639: .LC_docs_spacer {
                   4640:   width: 25px;
                   4641:   height: 1px;
1.771     droeschl 4642:   border: none;
1.543     albertel 4643: }
1.346     albertel 4644: 
1.532     albertel 4645: .LC_internal_info {
1.735     bisitz   4646:   color: #999999;
1.532     albertel 4647: }
                   4648: 
1.794     www      4649: .LC_discussion {
                   4650:    background: $tabbg;
                   4651:    border: 1px solid black;
                   4652:    margin: 2px;
                   4653: }
                   4654: 
                   4655: .LC_disc_action_links_bar {
                   4656:    background: $tabbg;
                   4657:    font-family: $sans;
                   4658:    border: 0px;
1.795   ! www      4659:    margin: 4px;
1.794     www      4660: }
                   4661: 
                   4662: .LC_disc_action_left {
                   4663:    text-align: left;
                   4664: }
                   4665: 
                   4666: .LC_disc_action_right {
                   4667:    text-align: right;
                   4668: }
                   4669: 
                   4670: .LC_disc_new_item {
                   4671:    background: white;
                   4672:    border: 2px solid red;
                   4673:    margin: 2px;
                   4674: }
                   4675: 
                   4676: .LC_disc_old_item {
                   4677:    background: white;
                   4678:    border: 1px solid black;
                   4679:    margin: 2px;
                   4680: }
                   4681: 
1.795   ! www      4682: .LC_success_confirm {
        !          4683:    font-family: $sans;
        !          4684:    color: darkgreen;
        !          4685: } 
        !          4686: 
1.458     albertel 4687: table.LC_pastsubmission {
                   4688:   border: 1px solid black;
                   4689:   margin: 2px;
                   4690: }
                   4691: 
1.795   ! www      4692: table#LC_top_nav,
        !          4693: table#LC_menubuttons,
        !          4694: table#LC_nav_location {
1.345     albertel 4695:   width: 100%;
                   4696:   background: $pgbg;
1.392     albertel 4697:   border: 2px;
1.402     albertel 4698:   border-collapse: separate;
1.403     albertel 4699:   padding: 0px;
1.345     albertel 4700: }
1.392     albertel 4701: 
1.795   ! www      4702: table#LC_title_bar,
        !          4703: table.LC_breadcrumbs,
1.393     albertel 4704: table#LC_title_bar.LC_with_remote {
1.359     albertel 4705:   width: 100%;
1.392     albertel 4706:   border-color: $pgbg;
                   4707:   border-style: solid;
                   4708:   border-width: $border;
1.379     albertel 4709:   background: $pgbg;
                   4710:   font-family: $sans;
1.392     albertel 4711:   border-collapse: collapse;
1.403     albertel 4712:   padding: 0px;
1.359     albertel 4713: }
1.795   ! www      4714: 
1.409     albertel 4715: table.LC_docs_path {
                   4716:   width: 100%;
                   4717:   border: 0;
                   4718:   background: $pgbg;
                   4719:   font-family: $sans;
                   4720:   border-collapse: collapse;
                   4721:   padding: 0px;
                   4722: }
                   4723: 
1.359     albertel 4724: table#LC_title_bar td {
                   4725:   background: $tabbg;
                   4726: }
1.795   ! www      4727: 
1.773     ehlerst  4728: table#LC_title_bar .LC_title_bar_who {
1.359     albertel 4729:   background: $tabbg;
                   4730:   color: $font;
1.427     albertel 4731:   font: small $sans;
1.359     albertel 4732:   text-align: right;
1.773     ehlerst  4733:   margin: 0px;
                   4734: }
1.795   ! www      4735: 
1.773     ehlerst  4736: table#LC_title_bar .LC_title_bar_name {
                   4737:   margin: 0px;
                   4738: }
1.795   ! www      4739: 
1.773     ehlerst  4740: table#LC_title_bar .LC_title_bar_role {
                   4741:   margin: 0px;
                   4742: }
1.795   ! www      4743: 
1.775     bisitz   4744: table#LC_title_bar .LC_title_bar_realm {
1.773     ehlerst  4745:   margin: 0px;
1.359     albertel 4746: }
1.795   ! www      4747: 
1.469     banghart 4748: span.LC_metadata {
1.795   ! www      4749:   font-family: $sans;
1.469     banghart 4750: }
1.359     albertel 4751: 
1.706     harmsja  4752: table#LC_menubuttons img{
1.346     albertel 4753:   border: 0px;
                   4754: }
1.795   ! www      4755: 
1.345     albertel 4756: table#LC_top_nav td {
                   4757:   background: $tabbg;
1.392     albertel 4758:   border: 0px;
1.407     albertel 4759:   font-size: small;
1.706     harmsja  4760:   vertical-align:top;
                   4761:   padding:2px 5px 2px 5px;
1.345     albertel 4762: }
1.795   ! www      4763: 
        !          4764: table#LC_top_nav td a,
        !          4765: div#LC_top_nav a {
1.345     albertel 4766:   color: $font;
                   4767:   font-family: $sans;
                   4768: }
1.795   ! www      4769: 
1.364     albertel 4770: table#LC_top_nav td.LC_top_nav_logo {
                   4771:   background: $tabbg;
1.432     albertel 4772:   text-align: left;
1.408     albertel 4773:   white-space: nowrap;
1.432     albertel 4774:   width: 31px;
1.408     albertel 4775: }
1.795   ! www      4776: 
1.408     albertel 4777: table#LC_top_nav td.LC_top_nav_logo img {
1.432     albertel 4778:   border: 0px;
1.408     albertel 4779:   vertical-align: bottom;
1.364     albertel 4780: }
1.795   ! www      4781: 
1.777     tempelho 4782: table#LC_top_nav td.LC_top_nav_exit,
1.779     bisitz   4783: table#LC_top_nav td.LC_top_nav_help {
1.777     tempelho 4784:   width: 2.0em;
                   4785: }
1.795   ! www      4786: 
1.442     albertel 4787: table#LC_top_nav td.LC_top_nav_login {
                   4788:   width: 4.0em;
                   4789:   text-align: center;
                   4790: }
1.795   ! www      4791: 
        !          4792: table.LC_breadcrumbs td,
        !          4793: table.LC_docs_path td  {
1.357     albertel 4794:   background: $tabbg;
                   4795:   color: $font;
                   4796:   font-family: $sans;
1.358     albertel 4797:   font-size: smaller;
1.357     albertel 4798: }
1.795   ! www      4799: 
1.777     tempelho 4800: table.LC_breadcrumbs td.LC_breadcrumbs_component,
                   4801: table.LC_docs_path td.LC_docs_path_component {
1.779     bisitz   4802:   background: $tabbg;
1.777     tempelho 4803:   color: $font;
                   4804:   font-family: $sans;
1.779     bisitz   4805:   font-size: larger;
                   4806:   text-align: right;
1.777     tempelho 4807: }
1.795   ! www      4808: 
1.383     albertel 4809: td.LC_table_cell_checkbox {
                   4810:   text-align: center;
                   4811: }
1.795   ! www      4812: 
1.779     bisitz   4813: table#LC_mainmenu td.LC_mainmenu_column {
                   4814:     vertical-align: top;
1.777     tempelho 4815: }
1.522     albertel 4816: 
1.795   ! www      4817: .LC_fontsize_small {
1.705     tempelho 4818:  font-size: 70%;
                   4819: }
                   4820: 
1.795   ! www      4821: .LC_fontsize_medium {
1.705     tempelho 4822:  font-size: 85%;
                   4823: }
                   4824: 
1.795   ! www      4825: .LC_fontsize_large {
1.705     tempelho 4826:  font-size: 120%;
                   4827: }
                   4828: 
1.346     albertel 4829: .LC_menubuttons_inline_text {
                   4830:   color: $font;
                   4831:   font-family: $sans;
1.698     harmsja  4832:   font-size: 90%;
1.701     harmsja  4833:   padding-left:3px;
1.346     albertel 4834: }
                   4835: 
1.526     www      4836: .LC_menubuttons_link {
                   4837:   text-decoration: none;
                   4838: }
1.795   ! www      4839: 
1.522     albertel 4840: .LC_menubuttons_category {
1.521     www      4841:   color: $font;
1.526     www      4842:   background: $pgbg;
1.521     www      4843:   font-family: $sans;
                   4844:   font-size: larger;
                   4845:   font-weight: bold;
                   4846: }
                   4847: 
1.346     albertel 4848: td.LC_menubuttons_text {
1.779     bisitz   4849:  	color: $font;
1.346     albertel 4850: }
1.706     harmsja  4851: 
1.346     albertel 4852: .LC_current_location {
                   4853:   font-family: $sans;
                   4854:   background: $tabbg;
                   4855: }
1.795   ! www      4856: 
1.346     albertel 4857: .LC_new_mail {
                   4858:   font-family: $sans;
1.634     www      4859:   background: $tabbg;
1.346     albertel 4860:   font-weight: bold;
                   4861: }
1.347     albertel 4862: 
1.527     www      4863: .LC_dropadd_labeltext {
                   4864:   font-family: $sans;
                   4865:   text-align: right;
                   4866: }
                   4867: 
                   4868: .LC_preferences_labeltext {
                   4869:   font-family: $sans;
                   4870:   text-align: right;
                   4871: }
                   4872: 
1.666     raeburn  4873: .LC_roleslog_note {
1.701     harmsja  4874:   font-size: small;
1.666     raeburn  4875: }
                   4876: 
1.715     raeburn  4877: .LC_mail_functions {
                   4878:     font-weight: bold;
                   4879: }
                   4880: 
1.440     albertel 4881: table.LC_aboutme_port {
                   4882:   border: 0px;
                   4883:   border-collapse: collapse;
                   4884:   border-spacing: 0px;
                   4885: }
1.795   ! www      4886: 
        !          4887: table.LC_data_table,
        !          4888: table.LC_mail_list {
1.347     albertel 4889:   border: 1px solid #000000;
1.402     albertel 4890:   border-collapse: separate;
1.426     albertel 4891:   border-spacing: 1px;
1.610     albertel 4892:   background: $pgbg;
1.347     albertel 4893: }
1.795   ! www      4894: 
1.422     albertel 4895: .LC_data_table_dense {
                   4896:   font-size: small;
                   4897: }
1.795   ! www      4898: 
1.507     raeburn  4899: table.LC_nested_outer {
                   4900:   border: 1px solid #000000;
1.589     raeburn  4901:   border-collapse: collapse;
1.507     raeburn  4902:   border-spacing: 0px;
                   4903:   width: 100%;
                   4904: }
1.795   ! www      4905: 
1.507     raeburn  4906: table.LC_nested {
                   4907:   border: 0px;
1.589     raeburn  4908:   border-collapse: collapse;
1.507     raeburn  4909:   border-spacing: 0px;
                   4910:   width: 100%;
                   4911: }
1.795   ! www      4912: 
        !          4913: table.LC_data_table tr th, 
        !          4914: table.LC_calendar tr th, 
        !          4915: table.LC_mail_list tr th,
1.523     albertel 4916: table.LC_prior_tries tr th {
1.349     albertel 4917:   font-weight: bold;
                   4918:   background-color: $data_table_head;
1.701     harmsja  4919:   font-size:90%;
1.347     albertel 4920: }
1.795   ! www      4921: 
1.711     raeburn  4922: table.LC_data_table tr.LC_info_row > td {
1.735     bisitz   4923:   background-color: #CCCCCC;
1.711     raeburn  4924:   font-weight: bold;
                   4925:   text-align: left;
                   4926: }
1.795   ! www      4927: 
1.779     bisitz   4928: table.LC_data_table tr.LC_odd_row > td,
1.709     bisitz   4929: table.LC_pick_box tr > td.LC_odd_row,
1.440     albertel 4930: table.LC_aboutme_port tr td {
1.349     albertel 4931:   background-color: $data_table_light;
1.425     albertel 4932:   padding: 2px;
1.347     albertel 4933: }
1.795   ! www      4934: 
1.610     albertel 4935: table.LC_data_table tr.LC_even_row > td,
1.709     bisitz   4936: table.LC_pick_box tr > td.LC_even_row,
1.440     albertel 4937: table.LC_aboutme_port tr.LC_even_row td {
1.349     albertel 4938:   background-color: $data_table_dark;
1.709     bisitz   4939:   padding: 2px;
1.347     albertel 4940: }
1.795   ! www      4941: 
1.425     albertel 4942: table.LC_data_table tr.LC_data_table_highlight td {
                   4943:   background-color: $data_table_darker;
                   4944: }
1.795   ! www      4945: 
1.639     raeburn  4946: table.LC_data_table tr td.LC_leftcol_header {
                   4947:   background-color: $data_table_head;
                   4948:   font-weight: bold;
                   4949: }
1.795   ! www      4950: 
1.451     albertel 4951: table.LC_data_table tr.LC_empty_row td,
1.507     raeburn  4952: table.LC_nested tr.LC_empty_row td {
1.347     albertel 4953:   background-color: #FFFFFF;
1.421     albertel 4954:   font-weight: bold;
                   4955:   font-style: italic;
                   4956:   text-align: center;
                   4957:   padding: 8px;
1.347     albertel 4958: }
1.795   ! www      4959: 
1.507     raeburn  4960: table.LC_nested tr.LC_empty_row td {
1.465     albertel 4961:   padding: 4ex
                   4962: }
1.795   ! www      4963: 
1.507     raeburn  4964: table.LC_nested_outer tr th {
                   4965:   font-weight: bold;
                   4966:   background-color: $data_table_head;
1.701     harmsja  4967:   font-size: small;
1.507     raeburn  4968:   border-bottom: 1px solid #000000;
                   4969: }
1.795   ! www      4970: 
1.507     raeburn  4971: table.LC_nested_outer tr td.LC_subheader {
                   4972:   background-color: $data_table_head;
                   4973:   font-weight: bold;
                   4974:   font-size: small;
                   4975:   border-bottom: 1px solid #000000;
                   4976:   text-align: right;
1.451     albertel 4977: }
1.795   ! www      4978: 
1.507     raeburn  4979: table.LC_nested tr.LC_info_row td {
1.735     bisitz   4980:   background-color: #CCCCCC;
1.451     albertel 4981:   font-weight: bold;
                   4982:   font-size: small;
1.507     raeburn  4983:   text-align: center;
                   4984: }
1.795   ! www      4985: 
1.589     raeburn  4986: table.LC_nested tr.LC_info_row td.LC_left_item,
                   4987: table.LC_nested_outer tr th.LC_left_item {
1.507     raeburn  4988:   text-align: left;
1.451     albertel 4989: }
1.795   ! www      4990: 
1.507     raeburn  4991: table.LC_nested td {
1.735     bisitz   4992:   background-color: #FFFFFF;
1.451     albertel 4993:   font-size: small;
1.507     raeburn  4994: }
1.795   ! www      4995: 
1.507     raeburn  4996: table.LC_nested_outer tr th.LC_right_item,
                   4997: table.LC_nested tr.LC_info_row td.LC_right_item,
                   4998: table.LC_nested tr.LC_odd_row td.LC_right_item,
                   4999: table.LC_nested tr td.LC_right_item {
1.451     albertel 5000:   text-align: right;
                   5001: }
                   5002: 
1.507     raeburn  5003: table.LC_nested tr.LC_odd_row td {
1.735     bisitz   5004:   background-color: #EEEEEE;
1.451     albertel 5005: }
                   5006: 
1.473     raeburn  5007: table.LC_createuser {
                   5008: }
                   5009: 
                   5010: table.LC_createuser tr.LC_section_row td {
1.701     harmsja  5011:   font-size: small;
1.473     raeburn  5012: }
                   5013: 
                   5014: table.LC_createuser tr.LC_info_row td  {
1.735     bisitz   5015:   background-color: #CCCCCC;
1.473     raeburn  5016:   font-weight: bold;
                   5017:   text-align: center;
                   5018: }
                   5019: 
1.349     albertel 5020: table.LC_calendar {
                   5021:   border: 1px solid #000000;
                   5022:   border-collapse: collapse;
                   5023: }
1.795   ! www      5024: 
1.349     albertel 5025: table.LC_calendar_pickdate {
                   5026:   font-size: xx-small;
                   5027: }
1.795   ! www      5028: 
1.349     albertel 5029: table.LC_calendar tr td {
                   5030:   border: 1px solid #000000;
                   5031:   vertical-align: top;
                   5032: }
1.795   ! www      5033: 
1.349     albertel 5034: table.LC_calendar tr td.LC_calendar_day_empty {
                   5035:   background-color: $data_table_dark;
                   5036: }
1.795   ! www      5037: 
1.779     bisitz   5038: table.LC_calendar tr td.LC_calendar_day_current {
                   5039:   background-color: $data_table_highlight;
1.777     tempelho 5040: }
1.795   ! www      5041: 
1.349     albertel 5042: table.LC_mail_list tr.LC_mail_new {
                   5043:   background-color: $mail_new;
                   5044: }
1.795   ! www      5045: 
1.349     albertel 5046: table.LC_mail_list tr.LC_mail_new:hover {
                   5047:   background-color: $mail_new_hover;
                   5048: }
1.795   ! www      5049: 
        !          5050: table.LC_mail_list tr.LC_mail_even {
1.777     tempelho 5051: }
1.795   ! www      5052: 
        !          5053: table.LC_mail_list tr.LC_mail_odd {
1.777     tempelho 5054: }
1.795   ! www      5055: 
1.349     albertel 5056: table.LC_mail_list tr.LC_mail_read {
                   5057:   background-color: $mail_read;
                   5058: }
1.795   ! www      5059: 
1.349     albertel 5060: table.LC_mail_list tr.LC_mail_read:hover {
                   5061:   background-color: $mail_read_hover;
                   5062: }
1.795   ! www      5063: 
1.349     albertel 5064: table.LC_mail_list tr.LC_mail_replied {
                   5065:   background-color: $mail_replied;
                   5066: }
1.795   ! www      5067: 
1.349     albertel 5068: table.LC_mail_list tr.LC_mail_replied:hover {
                   5069:   background-color: $mail_replied_hover;
                   5070: }
1.795   ! www      5071: 
1.349     albertel 5072: table.LC_mail_list tr.LC_mail_other {
                   5073:   background-color: $mail_other;
                   5074: }
1.795   ! www      5075: 
1.349     albertel 5076: table.LC_mail_list tr.LC_mail_other:hover {
                   5077:   background-color: $mail_other_hover;
                   5078: }
1.494     raeburn  5079: 
1.777     tempelho 5080: table.LC_data_table tr > td.LC_browser_file,
                   5081: table.LC_data_table tr > td.LC_browser_file_published {
1.389     albertel 5082:   background: #CCFF88;
                   5083: }
1.795   ! www      5084: 
1.777     tempelho 5085: table.LC_data_table tr > td.LC_browser_file_locked,
                   5086: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389     albertel 5087:   background: #FFAA99;
1.387     albertel 5088: }
1.795   ! www      5089: 
1.777     tempelho 5090: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.779     bisitz   5091:   background: #AAAAAA;
                   5092: }
1.795   ! www      5093: 
1.777     tempelho 5094: table.LC_data_table tr > td.LC_browser_file_modified,
1.779     bisitz   5095: table.LC_data_table tr > td.LC_browser_file_metamodified {
                   5096:   background: #FFFF77;
1.777     tempelho 5097: }
1.795   ! www      5098: 
1.696     bisitz   5099: table.LC_data_table tr.LC_browser_folder > td {
1.389     albertel 5100:   background: #CCCCFF;
1.387     albertel 5101: }
1.696     bisitz   5102: 
1.707     bisitz   5103: table.LC_data_table tr > td.LC_roles_is {
                   5104: /*  background: #77FF77; */
                   5105: }
1.795   ! www      5106: 
1.707     bisitz   5107: table.LC_data_table tr > td.LC_roles_future {
                   5108:   background: #FFFF77;
                   5109: }
1.795   ! www      5110: 
1.707     bisitz   5111: table.LC_data_table tr > td.LC_roles_will {
                   5112:   background: #FFAA77;
                   5113: }
1.795   ! www      5114: 
1.707     bisitz   5115: table.LC_data_table tr > td.LC_roles_expired {
                   5116:   background: #FF7777;
                   5117: }
1.795   ! www      5118: 
1.707     bisitz   5119: table.LC_data_table tr > td.LC_roles_will_not {
                   5120:   background: #AAFF77;
                   5121: }
1.795   ! www      5122: 
1.707     bisitz   5123: table.LC_data_table tr > td.LC_roles_selected {
                   5124:   background: #11CC55;
                   5125: }
                   5126: 
1.388     albertel 5127: span.LC_current_location {
1.701     harmsja  5128:   font-size:larger;
1.388     albertel 5129:   background: $pgbg;
                   5130: }
1.387     albertel 5131: 
1.395     albertel 5132: span.LC_parm_menu_item {
                   5133:   font-size: larger;
                   5134:   font-family: $sans;
                   5135: }
1.795   ! www      5136: 
1.395     albertel 5137: span.LC_parm_scope_all {
                   5138:   color: red;
                   5139: }
1.795   ! www      5140: 
1.395     albertel 5141: span.LC_parm_scope_folder {
                   5142:   color: green;
                   5143: }
1.795   ! www      5144: 
1.395     albertel 5145: span.LC_parm_scope_resource {
                   5146:   color: orange;
                   5147: }
1.795   ! www      5148: 
1.395     albertel 5149: span.LC_parm_part {
                   5150:   color: blue;
                   5151: }
1.795   ! www      5152: 
1.395     albertel 5153: span.LC_parm_folder, span.LC_parm_symb {
                   5154:   font-size: x-small;
                   5155:   font-family: $mono;
                   5156:   color: #AAAAAA;
                   5157: }
                   5158: 
1.795   ! www      5159: td.LC_parm_overview_level_menu,
        !          5160: td.LC_parm_overview_map_menu,
        !          5161: td.LC_parm_overview_parm_selectors,
        !          5162: td.LC_parm_overview_restrictions  {
1.396     albertel 5163:   border: 1px solid black;
                   5164:   border-collapse: collapse;
                   5165: }
1.795   ! www      5166: 
1.396     albertel 5167: table.LC_parm_overview_restrictions td {
                   5168:   border-width: 1px 4px 1px 4px;
                   5169:   border-style: solid;
                   5170:   border-color: $pgbg;
                   5171:   text-align: center;
                   5172: }
1.795   ! www      5173: 
1.396     albertel 5174: table.LC_parm_overview_restrictions th {
                   5175:   background: $tabbg;
                   5176:   border-width: 1px 4px 1px 4px;
                   5177:   border-style: solid;
                   5178:   border-color: $pgbg;
                   5179: }
1.795   ! www      5180: 
1.398     albertel 5181: table#LC_helpmenu {
                   5182:   border: 0px;
                   5183:   height: 55px;
                   5184:   border-spacing: 0px;
                   5185: }
                   5186: 
                   5187: table#LC_helpmenu fieldset legend {
                   5188:   font-size: larger;
                   5189:   font-weight: bold;
                   5190: }
1.795   ! www      5191: 
1.397     albertel 5192: table#LC_helpmenu_links {
                   5193:   width: 100%;
                   5194:   border: 1px solid black;
                   5195:   background: $pgbg;
                   5196:   padding: 0px;
                   5197:   border-spacing: 1px;
                   5198: }
1.795   ! www      5199: 
1.397     albertel 5200: table#LC_helpmenu_links tr td {
                   5201:   padding: 1px;
                   5202:   background: $tabbg;
1.399     albertel 5203:   text-align: center;
                   5204:   font-weight: bold;
1.397     albertel 5205: }
1.396     albertel 5206: 
1.795   ! www      5207: table#LC_helpmenu_links a:link,
        !          5208: table#LC_helpmenu_links a:visited,
1.397     albertel 5209: table#LC_helpmenu_links a:active {
                   5210:   text-decoration: none;
                   5211:   color: $font;
                   5212: }
1.795   ! www      5213: 
1.397     albertel 5214: table#LC_helpmenu_links a:hover {
                   5215:   text-decoration: underline;
                   5216:   color: $vlink;
                   5217: }
1.396     albertel 5218: 
1.417     albertel 5219: .LC_chrt_popup_exists {
                   5220:   border: 1px solid #339933;
                   5221:   margin: -1px;
                   5222: }
1.795   ! www      5223: 
1.417     albertel 5224: .LC_chrt_popup_up {
                   5225:   border: 1px solid yellow;
                   5226:   margin: -1px;
                   5227: }
1.795   ! www      5228: 
1.417     albertel 5229: .LC_chrt_popup {
                   5230:   border: 1px solid #8888FF;
                   5231:   background: #CCCCFF;
                   5232: }
1.795   ! www      5233: 
1.421     albertel 5234: table.LC_pick_box {
                   5235:   border-collapse: separate;
                   5236:   background: white;
                   5237:   border: 1px solid black;
                   5238:   border-spacing: 1px;
                   5239: }
1.795   ! www      5240: 
1.421     albertel 5241: table.LC_pick_box td.LC_pick_box_title {
                   5242:   background: $tabbg;
                   5243:   font-weight: bold;
                   5244:   text-align: right;
1.740     bisitz   5245:   vertical-align: top;
1.421     albertel 5246:   width: 184px;
                   5247:   padding: 8px;
                   5248: }
1.795   ! www      5249: 
1.645     raeburn  5250: table.LC_pick_box td.LC_selfenroll_pick_box_title {
                   5251:   background: $tabbg;
                   5252:   font-weight: bold;
                   5253:   text-align: right;
                   5254:   width: 350px;
                   5255:   padding: 8px;
                   5256: }
                   5257: 
1.579     raeburn  5258: table.LC_pick_box td.LC_pick_box_value {
                   5259:   text-align: left;
                   5260:   padding: 8px;
                   5261: }
1.795   ! www      5262: 
1.579     raeburn  5263: table.LC_pick_box td.LC_pick_box_select {
                   5264:   text-align: left;
                   5265:   padding: 8px;
                   5266: }
1.795   ! www      5267: 
1.424     albertel 5268: table.LC_pick_box td.LC_pick_box_separator {
1.421     albertel 5269:   padding: 0px;
                   5270:   height: 1px;
                   5271:   background: black;
                   5272: }
1.795   ! www      5273: 
1.421     albertel 5274: table.LC_pick_box td.LC_pick_box_submit {
                   5275:   text-align: right;
                   5276: }
1.795   ! www      5277: 
1.579     raeburn  5278: table.LC_pick_box td.LC_evenrow_value {
                   5279:   text-align: left;
                   5280:   padding: 8px;
                   5281:   background-color: $data_table_light;
                   5282: }
1.795   ! www      5283: 
1.579     raeburn  5284: table.LC_pick_box td.LC_oddrow_value {
                   5285:   text-align: left;
                   5286:   padding: 8px;
                   5287:   background-color: $data_table_light;
                   5288: }
1.795   ! www      5289: 
1.579     raeburn  5290: table.LC_helpform_receipt {
                   5291:   width: 620px;
                   5292:   border-collapse: separate;
                   5293:   background: white;
                   5294:   border: 1px solid black;
                   5295:   border-spacing: 1px;
                   5296: }
1.795   ! www      5297: 
1.579     raeburn  5298: table.LC_helpform_receipt td.LC_pick_box_title {
                   5299:   background: $tabbg;
                   5300:   font-weight: bold;
                   5301:   text-align: right;
                   5302:   width: 184px;
                   5303:   padding: 8px;
                   5304: }
1.795   ! www      5305: 
1.579     raeburn  5306: table.LC_helpform_receipt td.LC_evenrow_value {
                   5307:   text-align: left;
                   5308:   padding: 8px;
                   5309:   background-color: $data_table_light;
                   5310: }
1.795   ! www      5311: 
1.579     raeburn  5312: table.LC_helpform_receipt td.LC_oddrow_value {
                   5313:   text-align: left;
                   5314:   padding: 8px;
                   5315:   background-color: $data_table_light;
                   5316: }
1.795   ! www      5317: 
1.579     raeburn  5318: table.LC_helpform_receipt td.LC_pick_box_separator {
                   5319:   padding: 0px;
                   5320:   height: 1px;
                   5321:   background: black;
                   5322: }
1.795   ! www      5323: 
1.579     raeburn  5324: span.LC_helpform_receipt_cat {
                   5325:   font-weight: bold;
                   5326: }
1.795   ! www      5327: 
1.424     albertel 5328: table.LC_group_priv_box {
                   5329:   background: white;
                   5330:   border: 1px solid black;
                   5331:   border-spacing: 1px;
                   5332: }
1.795   ! www      5333: 
1.424     albertel 5334: table.LC_group_priv_box td.LC_pick_box_title {
                   5335:   background: $tabbg;
                   5336:   font-weight: bold;
                   5337:   text-align: right;
                   5338:   width: 184px;
                   5339: }
1.795   ! www      5340: 
1.424     albertel 5341: table.LC_group_priv_box td.LC_groups_fixed {
                   5342:   background: $data_table_light;
                   5343:   text-align: center;
                   5344: }
1.795   ! www      5345: 
1.424     albertel 5346: table.LC_group_priv_box td.LC_groups_optional {
                   5347:   background: $data_table_dark;
                   5348:   text-align: center;
                   5349: }
1.795   ! www      5350: 
1.424     albertel 5351: table.LC_group_priv_box td.LC_groups_functionality {
                   5352:   background: $data_table_darker;
                   5353:   text-align: center;
                   5354:   font-weight: bold;
                   5355: }
1.795   ! www      5356: 
1.424     albertel 5357: table.LC_group_priv td {
                   5358:   text-align: left;
                   5359:   padding: 0px;
                   5360: }
                   5361: 
1.421     albertel 5362: table.LC_notify_front_page {
                   5363:   background: white;
                   5364:   border: 1px solid black;
                   5365:   padding: 8px;
                   5366: }
1.795   ! www      5367: 
1.421     albertel 5368: table.LC_notify_front_page td {
                   5369:   padding: 8px;
                   5370: }
1.795   ! www      5371: 
1.424     albertel 5372: .LC_navbuttons {
                   5373:   margin: 2ex 0ex 2ex 0ex;
                   5374: }
1.795   ! www      5375: 
1.423     albertel 5376: .LC_topic_bar {
                   5377:   font-family: $sans;
                   5378:   font-weight: bold;
                   5379:   width: 100%;
                   5380:   background: $tabbg;
                   5381:   vertical-align: middle;
                   5382:   margin: 2ex 0ex 2ex 0ex;
                   5383: }
1.795   ! www      5384: 
1.423     albertel 5385: .LC_topic_bar span {
                   5386:   vertical-align: middle;
                   5387: }
1.795   ! www      5388: 
1.423     albertel 5389: .LC_topic_bar img {
                   5390:   vertical-align: bottom;
                   5391: }
1.795   ! www      5392: 
1.423     albertel 5393: table.LC_course_group_status {
                   5394:   margin: 20px;
                   5395: }
1.795   ! www      5396: 
1.423     albertel 5397: table.LC_status_selector td {
                   5398:   vertical-align: top;
                   5399:   text-align: center;
1.424     albertel 5400:   padding: 4px;
                   5401: }
1.795   ! www      5402: 
1.424     albertel 5403: table.LC_descriptive_input td.LC_description {
                   5404:   vertical-align: top;
                   5405:   text-align: right;
                   5406:   font-weight: bold;
1.423     albertel 5407: }
1.795   ! www      5408: 
1.599     albertel 5409: div.LC_feedback_link {
1.616     albertel 5410:   clear: both;
1.599     albertel 5411:   background: white;
1.779     bisitz   5412:   width: 100%;
1.489     raeburn  5413: }
1.795   ! www      5414: 
1.489     raeburn  5415: span.LC_feedback_link {
1.599     albertel 5416:   background: $feedback_link_bg;
                   5417:   font-size: larger;
                   5418: }
1.795   ! www      5419: 
1.599     albertel 5420: span.LC_message_link {
                   5421:   background: $feedback_link_bg;
                   5422:   font-size: larger;
                   5423:   position: absolute;
                   5424:   right: 1em;
1.489     raeburn  5425: }
1.421     albertel 5426: 
1.515     albertel 5427: table.LC_prior_tries {
1.524     albertel 5428:   border: 1px solid #000000;
                   5429:   border-collapse: separate;
                   5430:   border-spacing: 1px;
1.515     albertel 5431: }
1.523     albertel 5432: 
1.515     albertel 5433: table.LC_prior_tries td {
1.524     albertel 5434:   padding: 2px;
1.515     albertel 5435: }
1.523     albertel 5436: 
                   5437: .LC_answer_correct {
1.795   ! www      5438:   background: lightgreen;
        !          5439:   font-family: $sans;
        !          5440:   color: darkgreen;
        !          5441:   padding: 6px;
1.523     albertel 5442: }
1.795   ! www      5443: 
1.523     albertel 5444: .LC_answer_charged_try {
1.795   ! www      5445:   background: lightred;
        !          5446:   font-family: $sans;
        !          5447:   color: darkred;
        !          5448:   padding: 6px;
1.523     albertel 5449: }
1.795   ! www      5450: 
1.779     bisitz   5451: .LC_answer_not_charged_try,
1.523     albertel 5452: .LC_answer_no_grade,
                   5453: .LC_answer_late {
1.795   ! www      5454:   background: lightyellow;
        !          5455:   font-family: $sans;
1.523     albertel 5456:   color: black;
1.795   ! www      5457:   padding: 6px;
1.523     albertel 5458: }
1.795   ! www      5459: 
1.523     albertel 5460: .LC_answer_previous {
1.795   ! www      5461:   background: lightblue;
        !          5462:   font-family: $sans;
        !          5463:   color: darkblue;
        !          5464:   padding: 6px;
1.523     albertel 5465: }
1.795   ! www      5466: 
1.779     bisitz   5467: .LC_answer_no_message {
1.777     tempelho 5468:   background: #FFFFFF;
1.795   ! www      5469:   font-family: $sans;
1.777     tempelho 5470:   color: black;
1.795   ! www      5471:   padding: 6px;
1.779     bisitz   5472: }
1.795   ! www      5473: 
1.779     bisitz   5474: .LC_answer_unknown {
                   5475:   background: orange;
1.795   ! www      5476:   font-family: $sans;
1.779     bisitz   5477:   color: black;
1.795   ! www      5478:   padding: 6px;
1.777     tempelho 5479: }
1.795   ! www      5480: 
1.529     albertel 5481: span.LC_prior_numerical,
                   5482: span.LC_prior_string,
                   5483: span.LC_prior_custom,
                   5484: span.LC_prior_reaction,
                   5485: span.LC_prior_math {
1.523     albertel 5486:   font-family: monospace;
                   5487:   white-space: pre;
                   5488: }
                   5489: 
1.525     albertel 5490: span.LC_prior_string {
                   5491:   font-family: monospace;
                   5492:   white-space: pre;
                   5493: }
                   5494: 
1.523     albertel 5495: table.LC_prior_option {
                   5496:   width: 100%;
                   5497:   border-collapse: collapse;
                   5498: }
1.795   ! www      5499: 
        !          5500: table.LC_prior_rank, 
        !          5501: table.LC_prior_match {
1.528     albertel 5502:   border-collapse: collapse;
                   5503: }
1.795   ! www      5504: 
1.528     albertel 5505: table.LC_prior_option tr td,
                   5506: table.LC_prior_rank tr td,
                   5507: table.LC_prior_match tr td {
1.524     albertel 5508:   border: 1px solid #000000;
1.515     albertel 5509: }
                   5510: 
1.770     droeschl 5511: td.LC_nobreak,
1.519     raeburn  5512: span.LC_nobreak {
1.544     albertel 5513:   white-space: nowrap;
1.519     raeburn  5514: }
                   5515: 
1.576     raeburn  5516: span.LC_cusr_emph {
                   5517:   font-style: italic;
                   5518: }
                   5519: 
1.633     raeburn  5520: span.LC_cusr_subheading {
                   5521:   font-weight: normal;
                   5522:   font-size: 85%;
                   5523: }
                   5524: 
1.545     albertel 5525: table.LC_docs_documents {
                   5526:   background: #BBBBBB;
1.547     albertel 5527:   border-width: 0px;
1.545     albertel 5528:   border-collapse: collapse;
                   5529: }
1.795   ! www      5530: 
1.777     tempelho 5531: table.LC_docs_documents td.LC_docs_document {
1.779     bisitz   5532:   border: 2px solid black;
                   5533:   padding: 4px;
1.777     tempelho 5534: }
1.795   ! www      5535: 
1.545     albertel 5536: .LC_docs_entry_move {
                   5537:   border: 0px;
                   5538:   border-collapse: collapse;
1.544     albertel 5539: }
                   5540: 
1.545     albertel 5541: .LC_docs_entry_move td {
                   5542:   border: 2px solid #BBBBBB;
                   5543:   background: #DDDDDD;
                   5544: }
                   5545: 
                   5546: .LC_docs_editor td.LC_docs_entry_commands {
                   5547:   background: #DDDDDD;
                   5548:   font-size: x-small;
                   5549: }
1.795   ! www      5550: 
1.544     albertel 5551: .LC_docs_copy {
1.545     albertel 5552:   color: #000099;
1.544     albertel 5553: }
1.795   ! www      5554: 
1.544     albertel 5555: .LC_docs_cut {
1.545     albertel 5556:   color: #550044;
1.544     albertel 5557: }
1.795   ! www      5558: 
1.544     albertel 5559: .LC_docs_rename {
1.545     albertel 5560:   color: #009900;
1.544     albertel 5561: }
1.795   ! www      5562: 
1.544     albertel 5563: .LC_docs_remove {
1.545     albertel 5564:   color: #990000;
                   5565: }
                   5566: 
1.547     albertel 5567: .LC_docs_reinit_warn,
                   5568: .LC_docs_ext_edit {
                   5569:   font-size: x-small;
                   5570: }
                   5571: 
1.545     albertel 5572: .LC_docs_editor td.LC_docs_entry_title,
                   5573: .LC_docs_editor td.LC_docs_entry_icon {
                   5574:   background: #FFFFBB;
                   5575: }
1.795   ! www      5576: 
1.545     albertel 5577: .LC_docs_editor td.LC_docs_entry_parameter {
                   5578:   background: #BBBBFF;
                   5579:   font-size: x-small;
                   5580:   white-space: nowrap;
                   5581: }
                   5582: 
                   5583: table.LC_docs_adddocs td,
                   5584: table.LC_docs_adddocs th {
                   5585:   border: 1px solid #BBBBBB;
                   5586:   padding: 4px;
                   5587:   background: #DDDDDD;
1.543     albertel 5588: }
                   5589: 
1.584     albertel 5590: table.LC_sty_begin {
                   5591:   background: #BBFFBB;
                   5592: }
1.795   ! www      5593: 
1.584     albertel 5594: table.LC_sty_end {
                   5595:   background: #FFBBBB;
                   5596: }
                   5597: 
1.589     raeburn  5598: table.LC_double_column {
                   5599:   border-width: 0px;
                   5600:   border-collapse: collapse;
                   5601:   width: 100%;
                   5602:   padding: 2px;
                   5603: }
                   5604: 
                   5605: table.LC_double_column tr td.LC_left_col {
1.590     raeburn  5606:   top: 2px;
1.589     raeburn  5607:   left: 2px;
                   5608:   width: 47%;
                   5609:   vertical-align: top;
                   5610: }
                   5611: 
                   5612: table.LC_double_column tr td.LC_right_col {
                   5613:   top: 2px;
1.779     bisitz   5614:   right: 2px;
1.589     raeburn  5615:   width: 47%;
                   5616:   vertical-align: top;
                   5617: }
                   5618: 
1.594     raeburn  5619: span.LC_role_level {
                   5620:   font-weight: bold;
                   5621: }
                   5622: 
1.591     raeburn  5623: div.LC_left_float {
                   5624:   float: left;
                   5625:   padding-right: 5%;
1.597     albertel 5626:   padding-bottom: 4px;
1.591     raeburn  5627: }
                   5628: 
                   5629: div.LC_clear_float_header {
1.597     albertel 5630:   padding-bottom: 2px;
1.591     raeburn  5631: }
                   5632: 
                   5633: div.LC_clear_float_footer {
1.597     albertel 5634:   padding-top: 10px;
1.591     raeburn  5635:   clear: both;
                   5636: }
                   5637: 
1.597     albertel 5638: div.LC_grade_show_user {
                   5639:   margin-top: 20px;
                   5640:   border: 1px solid black;
                   5641: }
1.795   ! www      5642: 
1.597     albertel 5643: div.LC_grade_user_name {
                   5644:   background: #DDDDEE;
                   5645:   border-bottom: 1px solid black;
1.705     tempelho 5646:   font-weight: bold;
                   5647:   font-size: large;
1.597     albertel 5648: }
1.795   ! www      5649: 
1.597     albertel 5650: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
                   5651:   background: #DDEEDD;
                   5652: }
                   5653: 
                   5654: div.LC_grade_show_problem,
                   5655: div.LC_grade_submissions,
                   5656: div.LC_grade_message_center,
                   5657: div.LC_grade_info_links,
                   5658: div.LC_grade_assign {
                   5659:   margin: 5px;
                   5660:   width: 99%;
                   5661:   background: #FFFFFF;
                   5662: }
1.795   ! www      5663: 
1.597     albertel 5664: div.LC_grade_show_problem_header,
                   5665: div.LC_grade_submissions_header,
                   5666: div.LC_grade_message_center_header,
                   5667: div.LC_grade_assign_header {
1.705     tempelho 5668:   font-weight: bold;
                   5669:   font-size: large;
1.597     albertel 5670: }
1.795   ! www      5671: 
1.597     albertel 5672: div.LC_grade_show_problem_problem,
                   5673: div.LC_grade_submissions_body,
                   5674: div.LC_grade_message_center_body,
                   5675: div.LC_grade_assign_body {
                   5676:   border: 1px solid black;
                   5677:   width: 99%;
                   5678:   background: #FFFFFF;
                   5679: }
1.795   ! www      5680: 
1.598     albertel 5681: span.LC_grade_check_note {
1.705     tempelho 5682:   font-weight: normal;
                   5683:   font-size: medium;
1.598     albertel 5684:   display: inline;
                   5685:   position: absolute;
                   5686:   right: 1em;
                   5687: }
1.597     albertel 5688: 
1.613     albertel 5689: table.LC_scantron_action {
                   5690:   width: 100%;
                   5691: }
1.795   ! www      5692: 
1.613     albertel 5693: table.LC_scantron_action tr th {
1.698     harmsja  5694:   font-weight:bold;
                   5695:   font-style:normal;
1.613     albertel 5696: }
1.795   ! www      5697: 
1.779     bisitz   5698: .LC_edit_problem_header,
1.614     albertel 5699: div.LC_edit_problem_footer {
1.705     tempelho 5700:   font-weight: normal;
                   5701:   font-size:  medium;
1.602     albertel 5702:   margin: 2px;
1.600     albertel 5703: }
1.795   ! www      5704: 
1.600     albertel 5705: div.LC_edit_problem_header,
1.602     albertel 5706: div.LC_edit_problem_header div,
1.614     albertel 5707: div.LC_edit_problem_footer,
                   5708: div.LC_edit_problem_footer div,
1.602     albertel 5709: div.LC_edit_problem_editxml_header,
                   5710: div.LC_edit_problem_editxml_header div {
1.600     albertel 5711:   margin-top: 5px;
                   5712: }
1.795   ! www      5713: 
1.602     albertel 5714: div.LC_edit_problem_header_edit_row {
                   5715:   background: $tabbg;
                   5716:   padding: 3px;
                   5717:   margin-bottom: 5px;
                   5718: }
1.795   ! www      5719: 
1.600     albertel 5720: div.LC_edit_problem_header_title {
1.705     tempelho 5721:   font-weight: bold;
                   5722:   font-size: larger;
1.602     albertel 5723:   background: $tabbg;
                   5724:   padding: 3px;
                   5725: }
1.795   ! www      5726: 
1.602     albertel 5727: table.LC_edit_problem_header_title {
1.705     tempelho 5728:   font-size: larger;
                   5729:   font-weight:  bold;
1.602     albertel 5730:   width: 100%;
                   5731:   border-color: $pgbg;
                   5732:   border-style: solid;
                   5733:   border-width: $border;
1.600     albertel 5734:   background: $tabbg;
1.602     albertel 5735:   border-collapse: collapse;
                   5736:   padding: 0px
                   5737: }
                   5738: 
                   5739: div.LC_edit_problem_discards {
                   5740:   float: left;
                   5741:   padding-bottom: 5px;
                   5742: }
1.795   ! www      5743: 
1.602     albertel 5744: div.LC_edit_problem_saves {
                   5745:   float: right;
                   5746:   padding-bottom: 5px;
1.600     albertel 5747: }
1.795   ! www      5748: 
1.600     albertel 5749: hr.LC_edit_problem_divide {
1.602     albertel 5750:   clear: both;
1.600     albertel 5751:   color: $tabbg;
                   5752:   background-color: $tabbg;
                   5753:   height: 3px;
                   5754:   border: 0px;
                   5755: }
1.795   ! www      5756: 
1.679     riegler  5757: img.stift{
1.678     riegler  5758:   border-width:0;
1.679     riegler  5759:   vertical-align:middle;
1.677     riegler  5760: }
1.680     riegler  5761: 
1.681     riegler  5762: table#LC_mainmenu{
                   5763:  margin-top:10px;
                   5764:  width:80%;
                   5765: }
                   5766: 
1.680     riegler  5767: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
                   5768:   vertical-align: top;
                   5769:   width: 45%;
                   5770: }
1.795   ! www      5771: 
1.779     bisitz   5772: .LC_mainmenu_fieldset_category {
                   5773:   color: $font;
                   5774:   background: $pgbg;
                   5775:   font-family: $sans;
                   5776:   font-size: small;
                   5777:   font-weight: bold;
1.777     tempelho 5778: }
1.795   ! www      5779: 
1.716     raeburn  5780: div.LC_createcourse {
                   5781:     margin: 10px 10px 10px 10px;
                   5782: }
                   5783: 
1.693     droeschl 5784: /* ---- Remove when done ----
                   5785: # The following styles is part of the redesign of LON-CAPA and are
                   5786: # subject to change during this project.
                   5787: # Don't rely on their current functionality as they might be 
                   5788: # changed or removed.
                   5789: # --------------------------*/
                   5790: 
1.698     harmsja  5791: a:hover,
1.721     harmsja  5792: ol.LC_smallMenu a:hover,
                   5793: ol#LC_MenuBreadcrumbs a:hover,
                   5794: ol#LC_PathBreadcrumbs a:hover,
                   5795: ul#LC_TabMainMenuContent a:hover,
                   5796: .LC_FormSectionClearButton input:hover
1.795   ! www      5797: ul.LC_TabContent   li:hover a {
1.698     harmsja  5798: 	color:#BF2317;
                   5799:         text-decoration:none;
1.693     droeschl 5800: }
                   5801: 
1.779     bisitz   5802: h1 {
1.721     harmsja  5803: 	padding:5px 10px 5px 20px;
1.693     droeschl 5804: 	line-height:130%;
                   5805: }
1.698     harmsja  5806: 
1.795   ! www      5807: h2,h3,h4,h5,h6 {
1.721     harmsja  5808: 	margin:5px 0px 5px 0px;
                   5809: 	padding:0px;
                   5810: 	line-height:130%;
1.693     droeschl 5811: }
1.795   ! www      5812: 
        !          5813: .LC_hcell {
1.698     harmsja  5814:         padding:3px 15px 3px 15px;
                   5815:         margin:0px;
1.703     harmsja  5816: 	background-color:$tabbg;
1.779     bisitz   5817: 	border-bottom:solid 1px $lg_border_color;
1.693     droeschl 5818: }
1.795   ! www      5819: 
1.721     harmsja  5820: .LC_noBorder {
1.698     harmsja  5821:         border:0px;
                   5822: }
1.693     droeschl 5823: 
                   5824: 
1.698     harmsja  5825: /* Main Header with discription of Person, Course, etc. */
1.693     droeschl 5826: 
1.761     tempelho 5827: .LC_Right {
                   5828:         float: right;
                   5829:         margin: 0px;
                   5830:         padding: 0px;
                   5831: }
                   5832: 
1.721     harmsja  5833: .LC_FormSectionClearButton input {
1.779     bisitz   5834:         background-color:transparent;
1.698     harmsja  5835:         border:0px;
                   5836:         cursor:pointer;
                   5837:         text-decoration:underline;
1.693     droeschl 5838: }
1.763     bisitz   5839: 
                   5840: .LC_help_open_topic {
                   5841:         color: #FFFFFF;
                   5842:         background-color: #EEEEFF;
                   5843:         margin: 1px;
                   5844:         padding: 4px;
                   5845:         border: 1px solid #000033;
                   5846:         white-space: nowrap;
1.783     amueller 5847: /*		vertical-align: middle; */
1.759     neumanie 5848: }
1.693     droeschl 5849: 
1.698     harmsja  5850: dl,ul,div,fieldset {
                   5851: 	margin: 10px 10px 10px 0px;
1.693     droeschl 5852: 	overflow:hidden;
                   5853: }
1.795   ! www      5854: 
1.721     harmsja  5855: ol.LC_smallMenu, ol#LC_PathBreadcrumbs {
1.698     harmsja  5856: 	margin: 0px;
1.693     droeschl 5857: }
                   5858: 
1.721     harmsja  5859: ol.LC_smallMenu li {
1.693     droeschl 5860: 	display: inline;
                   5861: 	padding: 5px 5px 0px 10px;
                   5862: 	vertical-align: top;
                   5863: }
                   5864: 
1.721     harmsja  5865: ol.LC_smallMenu li img {
1.693     droeschl 5866: 	vertical-align: bottom;
                   5867: }
                   5868: 
1.721     harmsja  5869: ol.LC_smallMenu a {
1.693     droeschl 5870: 	font-size: 90%;
                   5871: 	color: RGB(80, 80, 80);
                   5872: 	text-decoration: none;
                   5873: }
1.795   ! www      5874: 
        !          5875: ol#LC_TabMainMenuContent, 
        !          5876: ul.LC_TabContent ,
1.741     harmsja  5877: ul.LC_TabContentBigger {
1.721     harmsja  5878: 	display:block;
                   5879: 	list-style:none;
1.741     harmsja  5880: 	margin: 0px;
1.693     droeschl 5881: 	padding: 0px;
                   5882: }
                   5883: 
1.795   ! www      5884: ol#LC_TabMainMenuContent li,
        !          5885: ul.LC_TabContent li,
        !          5886: ul.LC_TabContentBigger li {
1.693     droeschl 5887: 	display: inline;
1.741     harmsja  5888: 	border-right: solid 1px $lg_border_color;
                   5889: 	float:left;
                   5890: 	line-height:140%;
                   5891: 	white-space:nowrap;
                   5892: }
1.795   ! www      5893: 
        !          5894: ol#LC_TabMainMenuContent li {
1.693     droeschl 5895: 	vertical-align: bottom;
                   5896: 	border-bottom: solid 1px RGB(175, 175, 175);
1.721     harmsja  5897: 	padding: 5px 10px 5px 10px;
1.741     harmsja  5898: 	margin-right:5px;
                   5899: 	margin-bottom:3px;
1.693     droeschl 5900: 	font-weight: bold;
1.723     riegler  5901: 	background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693     droeschl 5902: }
                   5903: 
1.795   ! www      5904: ol#LC_TabMainMenuContent li a {
1.693     droeschl 5905: 	color: RGB(47, 47, 47);
                   5906: 	text-decoration: none;
                   5907: }
1.795   ! www      5908: 
1.721     harmsja  5909: ul.LC_TabContent {
1.741     harmsja  5910: 	min-height:1.6em;
1.721     harmsja  5911: }
1.795   ! www      5912: 
        !          5913: ul.LC_TabContent li {
1.741     harmsja  5914: 	vertical-align:middle;
                   5915: 	padding:0px 10px 0px 10px;
1.745     ehlerst  5916: 	background-color:$tabbg;
                   5917: 	border-bottom:solid 1px $lg_border_color;
1.721     harmsja  5918: }
1.795   ! www      5919: 
        !          5920: ul.LC_TabContent li a, ul.LC_TabContent li {
1.721     harmsja  5921: 	color:rgb(47,47,47);
                   5922: 	text-decoration:none;
                   5923: 	font-size:95%;
                   5924: 	font-weight:bold;
1.761     tempelho 5925: 	padding-right: 16px;
1.721     harmsja  5926: }
1.795   ! www      5927: 
        !          5928: ul.LC_TabContent li:hover, ul.LC_TabContent li.active {
1.761     tempelho 5929:         background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.745     ehlerst  5930: 	border-bottom:solid 1px #FFFFFF;
1.761     tempelho 5931: 	padding-right: 16px;
1.744     ehlerst  5932: }
1.795   ! www      5933: 
        !          5934: ul.LC_TabContentBigger li {
1.741     harmsja  5935: 	vertical-align:bottom;
                   5936: 	border-top:solid 1px $lg_border_color;
                   5937: 	border-left:solid 1px $lg_border_color;
                   5938: 	padding:5px 10px 5px 10px;
                   5939: 	margin-left:2px;
                   5940: 	background:url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
                   5941: }
1.795   ! www      5942: 
        !          5943: ul.LC_TabContentBigger li:hover, 
        !          5944: ul.LC_TabContentBigger li.active {
1.744     ehlerst  5945: 	background:url(/adm/lonIcons/lightGreyBG.png) repeat-x right bottom;
                   5946: }
1.795   ! www      5947: 
        !          5948: ul.LC_TabContentBigger li, 
        !          5949: ul.LC_TabContentBigger li a {
1.741     harmsja  5950: 	font-size:110%;
                   5951: 	font-weight:bold;
                   5952: }
1.693     droeschl 5953: 
1.795   ! www      5954: ol#LC_MenuBreadcrumbs, 
        !          5955: ol#LC_PathBreadcrumbs, 
        !          5956: ul.LC_CourseBreadcrumbs {
1.693     droeschl 5957: 	border-top: solid 1px RGB(255, 255, 255);
                   5958: 	height: 20px;
                   5959: 	line-height: 20px;
                   5960: 	vertical-align: bottom;
                   5961: 	margin: 0px 0px 30px 0px;
                   5962: 	padding-left: 10px;
                   5963: 	list-style-position: inside;
1.723     riegler  5964: 	background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693     droeschl 5965: }
                   5966: 
1.795   ! www      5967: ol#LC_MenuBreadcrumbs li, 
        !          5968: ol#LC_PathBreadcrumbs li, 
        !          5969: ul.LC_CourseBreadcrumbs li {
1.741     harmsja  5970: /*
1.723     riegler  5971: 	background: url(/adm/lonIcons/arrow_white.png) no-repeat left center;
1.779     bisitz   5972: */
1.693     droeschl 5973: 	display: inline;
                   5974: 	padding: 0px 0px 0px 10px;
1.783     amueller 5975: /*	vertical-align: bottom; */
1.693     droeschl 5976: 	overflow:hidden;
                   5977: }
                   5978: 
1.783     amueller 5979: ol#LC_MenuBreadcrumbs li a, ul.LC_CourseBreadcrumbs li a {
1.693     droeschl 5980: 	text-decoration: none;
                   5981: 	font-size:90%;
                   5982: }
1.795   ! www      5983: 
        !          5984: ol#LC_PathBreadcrumbs li a {
1.698     harmsja  5985: 	text-decoration:none;
                   5986: 	font-size:100%;
                   5987: 	font-weight:bold;
1.693     droeschl 5988: }
1.795   ! www      5989: 
        !          5990: .LC_BoxPadding {
1.786     neumanie 5991: 	padding: 10px;
                   5992: }
1.795   ! www      5993: 
        !          5994: .LC_ContentBoxSpecial {
1.701     harmsja  5995: 	border: solid 1px $lg_border_color;
1.746     neumanie 5996: }
1.795   ! www      5997: 
        !          5998: .LC_ContentBoxSpecialContactInfo {
1.746     neumanie 5999: 	border: solid 1px $lg_border_color;
                   6000: 	max-width:25%;
                   6001: 	min-width:25%;
1.698     harmsja  6002: }
1.795   ! www      6003: 
        !          6004: .LC_AboutMe_Image {
1.747     neumanie 6005: 	float:left;
                   6006: 	margin-right:10px;
                   6007: }
1.795   ! www      6008: 
        !          6009: .LC_Clear_AboutMe_Image {
1.747     neumanie 6010: 	clear:left;
                   6011: }
1.795   ! www      6012: 
1.721     harmsja  6013: dl.LC_ListStyleClean dt {
1.693     droeschl 6014: 	padding-right: 5px;
                   6015: 	display: table-header-group;
                   6016: }
                   6017: 
1.721     harmsja  6018: dl.LC_ListStyleClean dd {
1.693     droeschl 6019: 	display: table-row;
                   6020: }
                   6021: 
1.721     harmsja  6022: .LC_ListStyleClean,
                   6023: .LC_ListStyleSimple,
                   6024: .LC_ListStyleNormal,
1.777     tempelho 6025: .LC_ListStyle_Border,
1.795   ! www      6026: .LC_ListStyleSpecial {
1.693     droeschl 6027: 	/*display:block;	*/
                   6028: 	list-style-position: inside;
                   6029: 	list-style-type: none;
                   6030: 	overflow: hidden;
                   6031: 	padding: 0px;
                   6032: }
                   6033: 
1.721     harmsja  6034: .LC_ListStyleSimple li,
                   6035: .LC_ListStyleSimple dd,
                   6036: .LC_ListStyleNormal li,
                   6037: .LC_ListStyleNormal dd,
                   6038: .LC_ListStyleSpecial li,
1.795   ! www      6039: .LC_ListStyleSpecial dd {
1.693     droeschl 6040: 	margin: 0px;
                   6041: 	padding: 5px 5px 5px 10px;
                   6042: 	clear: both;
                   6043: }
                   6044: 
1.721     harmsja  6045: .LC_ListStyleClean li,
                   6046: .LC_ListStyleClean dd {
1.693     droeschl 6047: 	padding-top: 0px;
                   6048: 	padding-bottom: 0px;
                   6049: }
                   6050: 
1.721     harmsja  6051: .LC_ListStyleSimple dd,
1.795   ! www      6052: .LC_ListStyleSimple li {
1.698     harmsja  6053: 	border-bottom: solid 1px $lg_border_color;
1.693     droeschl 6054: }
                   6055: 
1.721     harmsja  6056: .LC_ListStyleSpecial li,
                   6057: .LC_ListStyleSpecial dd {
1.693     droeschl 6058: 	list-style-type: none;
                   6059: 	background-color: RGB(220, 220, 220);
                   6060: 	margin-bottom: 4px;
                   6061: }
                   6062: 
1.721     harmsja  6063: table.LC_SimpleTable {
1.698     harmsja  6064: 	margin:5px;
                   6065: 	border:solid 1px $lg_border_color;
1.795   ! www      6066: }
1.693     droeschl 6067: 
1.721     harmsja  6068: table.LC_SimpleTable tr {
1.698     harmsja  6069: 	padding:0px;
                   6070: 	border:solid 1px $lg_border_color;
1.693     droeschl 6071: }
1.795   ! www      6072: 
        !          6073: table.LC_SimpleTable thead {
1.698     harmsja  6074: 	 background:rgb(220,220,220);
1.693     droeschl 6075: }
                   6076: 
1.721     harmsja  6077: div.LC_columnSection {
1.693     droeschl 6078: 	display: block;
                   6079: 	clear: both;
                   6080: 	overflow: hidden;
                   6081: 	margin:0px;
                   6082: }
                   6083: 
1.721     harmsja  6084: div.LC_columnSection>* {
1.693     droeschl 6085: 	float: left;
                   6086: 	margin: 10px 20px 10px 0px;
1.747     neumanie 6087: 	overflow:hidden;
1.693     droeschl 6088: }
1.721     harmsja  6089: 
1.795   ! www      6090: .ContentBoxSpecialTemplate {
1.747     neumanie 6091:         border: solid 1px $lg_border_color;
1.719     ehlerst  6092: }
1.795   ! www      6093: 
1.719     ehlerst  6094: .ContentBoxTemplate {
                   6095:         padding:10px;
                   6096: }
                   6097: 
1.721     harmsja  6098: div.LC_columnSection > .ContentBoxTemplate,
1.795   ! www      6099: div.LC_columnSection > .ContentBoxSpecialTemplate {
1.719     ehlerst  6100:         width: 600px;
                   6101: }
1.753     droeschl 6102: 
1.795   ! www      6103: .clear {
1.720     ehlerst  6104: 	clear: both;
                   6105: 	line-height: 0px;
                   6106: 	font-size: 0px;
                   6107: 	height: 0px;
                   6108: }
1.693     droeschl 6109: 
1.694     tempelho 6110: .LC_loginpage_container {
                   6111: 	text-align:left;
                   6112: 	margin : 0 auto;
1.785     tempelho 6113: 	width:90%;
1.694     tempelho 6114: 	padding: 10px;
                   6115: 	height: auto;
1.712     muellerd 6116: 	background-color:#FFFFFF;
1.694     tempelho 6117: 	border:1px solid #CCCCCC;
                   6118: }
                   6119: 
                   6120: 
                   6121: .LC_loginpage_loginContainer {
                   6122: 	float:left;
1.712     muellerd 6123: 	width: 182px;
1.785     tempelho 6124: 	padding: 2px;
1.712     muellerd 6125: 	border:1px solid #CCCCCC;
                   6126: 	background-color:$loginbg;
1.694     tempelho 6127: }
                   6128: 
1.795   ! www      6129: .LC_loginpage_loginContainer h2 {
1.712     muellerd 6130: 	margin-top:0;
                   6131: 	display:block;
                   6132: 	background:$bgcol;
                   6133: 	color:$textcol;
                   6134: 	padding-left:5px;
                   6135: }
1.785     tempelho 6136: 
1.694     tempelho 6137: .LC_loginpage_loginInfo {
                   6138: 	float:left;
1.785     tempelho 6139: 	width:182px;
1.694     tempelho 6140: 	border:1px solid #CCCCCC;
1.785     tempelho 6141: 	padding:2px;
1.712     muellerd 6142: }
                   6143: 
1.694     tempelho 6144: .LC_loginpage_space {
1.754     droeschl 6145: 	clear: both;
                   6146: 	margin-bottom: 20px;
1.694     tempelho 6147: 	border-bottom: 1px solid #CCCCCC;
                   6148: }
                   6149: 
1.785     tempelho 6150: .LC_loginpage_floatLeft {
                   6151: 	float: left;
                   6152: 	width: 200px;
                   6153: 	margin: 0;
                   6154: }
                   6155: 
1.795   ! www      6156: table em {
1.754     droeschl 6157: 	font-weight: bold;
                   6158: 	font-style: normal;
1.748     schulted 6159: }
1.795   ! www      6160: 
1.779     bisitz   6161: table.LC_tableBrowseRes,
1.795   ! www      6162: table.LC_tableOfContent {
1.769     schulted 6163:         border:none;
                   6164: 	border-spacing: 1;
1.754     droeschl 6165: 	padding: 3px;
                   6166: 	background-color: #FFFFFF;
                   6167: 	font-size: 90%;
1.753     droeschl 6168: }
1.789     droeschl 6169: 
                   6170: table.LC_tableOfContent{
                   6171:     border-collapse: collapse;
                   6172: }
                   6173: 
1.771     droeschl 6174: table.LC_tableBrowseRes a,
1.768     schulted 6175: table.LC_tableOfContent a {
1.771     droeschl 6176:         background-color: transparent;
1.753     droeschl 6177: 	text-decoration: none;
                   6178: }
                   6179: 
1.771     droeschl 6180: table.LC_tableBrowseRes tr.LC_trOdd,
1.768     schulted 6181: table.LC_tableOfContent tr.LC_trOdd{
1.754     droeschl 6182: 	background-color: #EEEEEE;
1.753     droeschl 6183: }
                   6184: 
1.795   ! www      6185: table.LC_tableOfContent img {
1.753     droeschl 6186: 	border: none;
                   6187: 	height: 1.3em;
                   6188: 	vertical-align: text-bottom;
                   6189: 	margin-right: 0.3em;
                   6190: }
1.757     schulted 6191: 
1.795   ! www      6192: a#LC_content_toolbar_firsthomework {
1.774     ehlerst  6193: 	background-image:url(/res/adm/pages/open-first-problem.gif);
                   6194: }
                   6195: 
1.795   ! www      6196: a#LC_content_toolbar_launchnav {
1.774     ehlerst  6197: 	background-image:url(/res/adm/pages/start-navigation.gif);
                   6198: }
                   6199: 
1.795   ! www      6200: a#LC_content_toolbar_closenav {
1.774     ehlerst  6201: 	background-image:url(/res/adm/pages/close-navigation.gif);
                   6202: }
                   6203: 
1.795   ! www      6204: a#LC_content_toolbar_everything {
1.774     ehlerst  6205: 	background-image:url(/res/adm/pages/show-all.gif);
                   6206: }
                   6207: 
1.795   ! www      6208: a#LC_content_toolbar_uncompleted {
1.774     ehlerst  6209: 	background-image:url(/res/adm/pages/show-incomplete-problems.gif);
                   6210: }
                   6211: 
1.795   ! www      6212: #LC_content_toolbar_clearbubbles {
1.774     ehlerst  6213: 	background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
                   6214: }
                   6215: 
1.795   ! www      6216: a#LC_content_toolbar_changefolder {
1.757     schulted 6217: 	background : url(/res/adm/pages/close-all-folders.gif) top center ;
                   6218: }
                   6219: 
1.795   ! www      6220: a#LC_content_toolbar_changefolder_toggled {
1.757     schulted 6221: 	background-image:url(/res/adm/pages/open-all-folders.gif);
                   6222: }
                   6223: 
1.795   ! www      6224: ul#LC_toolbar li a:hover {
1.757     schulted 6225: 	background-position: bottom center;
                   6226: }
                   6227: 
1.795   ! www      6228: ul#LC_toolbar {
1.779     bisitz   6229: 	padding:0;
1.757     schulted 6230: 	margin: 2px;
                   6231: 	list-style:none;
                   6232: 	position:relative;
                   6233: 	background-color:white;
                   6234: }
                   6235: 
1.795   ! www      6236: ul#LC_toolbar li {
1.757     schulted 6237: 	border:1px solid white;
                   6238: 	padding:0;
                   6239: 	margin: 0;
1.795   ! www      6240:         float: left;
1.767     droeschl 6241: 	display:inline;
1.757     schulted 6242: 	vertical-align:middle;
1.795   ! www      6243: } 
1.757     schulted 6244: 
1.783     amueller 6245: 
1.795   ! www      6246: a.LC_toolbarItem {
1.767     droeschl 6247: 	display:block;
1.757     schulted 6248: 	padding:0;
                   6249: 	margin:0;
                   6250: 	height: 32px;
                   6251: 	width: 32px;
1.779     bisitz   6252: 	color:white;
                   6253: 	border:0 none;
1.757     schulted 6254: 	background-repeat:no-repeat;
                   6255: 	background-color:transparent;
                   6256: }
                   6257: 
1.782     bisitz   6258: ul.LC_functionslist li {
                   6259:   float: left;
                   6260:   white-space: nowrap;
                   6261:   height: 35px; /* at least as high as heighest list item */
                   6262:   margin: 0px 15px 15px 10px;
                   6263: }
                   6264: 
1.757     schulted 6265: 
1.343     albertel 6266: END
                   6267: }
                   6268: 
1.306     albertel 6269: =pod
                   6270: 
                   6271: =item * &headtag()
                   6272: 
                   6273: Returns a uniform footer for LON-CAPA web pages.
                   6274: 
1.307     albertel 6275: Inputs: $title - optional title for the head
                   6276:         $head_extra - optional extra HTML to put inside the <head>
1.315     albertel 6277:         $args - optional arguments
1.319     albertel 6278:             force_register - if is true call registerurl so the remote is 
                   6279:                              informed
1.415     albertel 6280:             redirect       -> array ref of
                   6281:                                    1- seconds before redirect occurs
                   6282:                                    2- url to redirect to
                   6283:                                    3- whether the side effect should occur
1.315     albertel 6284:                            (side effect of setting 
                   6285:                                $env{'internal.head.redirect'} to the url 
                   6286:                                redirected too)
1.352     albertel 6287:             domain         -> force to color decorate a page for a specific
                   6288:                                domain
                   6289:             function       -> force usage of a specific rolish color scheme
                   6290:             bgcolor        -> override the default page bgcolor
1.460     albertel 6291:             no_auto_mt_title
                   6292:                            -> prevent &mt()ing the title arg
1.464     albertel 6293: 
1.306     albertel 6294: =cut
                   6295: 
                   6296: sub headtag {
1.313     albertel 6297:     my ($title,$head_extra,$args) = @_;
1.306     albertel 6298:     
1.363     albertel 6299:     my $function = $args->{'function'} || &get_users_function();
                   6300:     my $domain   = $args->{'domain'}   || &determinedomain();
                   6301:     my $bgcolor  = $args->{'bgcolor'}  || &designparm($function.'.pgbg',$domain);
1.418     albertel 6302:     my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458     albertel 6303: 		   $Apache::lonnet::perlvar{'lonVersion'},
1.531     albertel 6304: 		   #time(),
1.418     albertel 6305: 		   $env{'environment.color.timestamp'},
1.363     albertel 6306: 		   $function,$domain,$bgcolor);
                   6307: 
1.369     www      6308:     $url = '/adm/css/'.&escape($url).'.css';
1.363     albertel 6309: 
1.308     albertel 6310:     my $result =
                   6311: 	'<head>'.
1.461     albertel 6312: 	&font_settings();
1.319     albertel 6313: 
1.461     albertel 6314:     if (!$args->{'frameset'}) {
                   6315: 	$result .= &Apache::lonhtmlcommon::htmlareaheaders();
                   6316:     }
1.319     albertel 6317:     if ($args->{'force_register'}) {
                   6318: 	$result .= &Apache::lonmenu::registerurl(1);
                   6319:     }
1.436     albertel 6320:     if (!$args->{'no_nav_bar'} 
                   6321: 	&& !$args->{'only_body'}
                   6322: 	&& !$args->{'frameset'}) {
                   6323: 	$result .= &help_menu_js();
                   6324:     }
1.319     albertel 6325: 
1.314     albertel 6326:     if (ref($args->{'redirect'})) {
1.414     albertel 6327: 	my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315     albertel 6328: 	$url = &Apache::lonenc::check_encrypt($url);
1.414     albertel 6329: 	if (!$inhibit_continue) {
                   6330: 	    $env{'internal.head.redirect'} = $url;
                   6331: 	}
1.313     albertel 6332: 	$result.=<<ADDMETA
                   6333: <meta http-equiv="pragma" content="no-cache" />
1.344     albertel 6334: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313     albertel 6335: ADDMETA
                   6336:     }
1.306     albertel 6337:     if (!defined($title)) {
                   6338: 	$title = 'The LearningOnline Network with CAPA';
                   6339:     }
1.460     albertel 6340:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
                   6341:     $result .= '<title> LON-CAPA '.$title.'</title>'
1.414     albertel 6342: 	.'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
                   6343: 	.$head_extra;
1.306     albertel 6344:     return $result;
                   6345: }
                   6346: 
                   6347: =pod
                   6348: 
1.340     albertel 6349: =item * &font_settings()
                   6350: 
                   6351: Returns neccessary <meta> to set the proper encoding
                   6352: 
                   6353: Inputs: none
                   6354: 
                   6355: =cut
                   6356: 
                   6357: sub font_settings {
                   6358:     my $headerstring='';
1.647     www      6359:     if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340     albertel 6360: 	$headerstring.=
                   6361: 	    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
                   6362:     }
                   6363:     return $headerstring;
                   6364: }
                   6365: 
1.341     albertel 6366: =pod
                   6367: 
                   6368: =item * &xml_begin()
                   6369: 
                   6370: Returns the needed doctype and <html>
                   6371: 
                   6372: Inputs: none
                   6373: 
                   6374: =cut
                   6375: 
                   6376: sub xml_begin {
                   6377:     my $output='';
                   6378: 
1.592     albertel 6379:     if ($env{'internal.start_page'}==1) {
                   6380: 	&Apache::lonhtmlcommon::init_htmlareafields();
                   6381:     }
1.342     albertel 6382: 
1.341     albertel 6383:     if ($env{'browser.mathml'}) {
                   6384: 	$output='<?xml version="1.0"?>'
                   6385:             #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
                   6386: #            .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
                   6387:             
                   6388: #	    .'<!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">] >'
                   6389: 	    .'<!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">'
                   6390:             .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" ' 
                   6391: 	    .'xmlns="http://www.w3.org/1999/xhtml">';
                   6392:     } else {
                   6393: 	$output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
                   6394:     }
                   6395:     return $output;
                   6396: }
1.340     albertel 6397: 
                   6398: =pod
                   6399: 
1.306     albertel 6400: =item * &endheadtag()
                   6401: 
                   6402: Returns a uniform </head> for LON-CAPA web pages.
                   6403: 
                   6404: Inputs: none
                   6405: 
                   6406: =cut
                   6407: 
                   6408: sub endheadtag {
                   6409:     return '</head>';
                   6410: }
                   6411: 
                   6412: =pod
                   6413: 
                   6414: =item * &head()
                   6415: 
                   6416: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
                   6417: 
1.648     raeburn  6418: Inputs:
                   6419: 
                   6420: =over 4
                   6421: 
                   6422: $title - optional title for the page
                   6423: 
                   6424: $head_extra - optional extra HTML to put inside the <head>
                   6425: 
                   6426: =back
1.405     albertel 6427: 
1.306     albertel 6428: =cut
                   6429: 
                   6430: sub head {
1.325     albertel 6431:     my ($title,$head_extra,$args) = @_;
                   6432:     return &headtag($title,$head_extra,$args).&endheadtag();
1.306     albertel 6433: }
                   6434: 
                   6435: =pod
                   6436: 
                   6437: =item * &start_page()
                   6438: 
                   6439: Returns a complete <html> .. <body> section for LON-CAPA web pages.
                   6440: 
1.648     raeburn  6441: Inputs:
                   6442: 
                   6443: =over 4
                   6444: 
                   6445: $title - optional title for the page
                   6446: 
                   6447: $head_extra - optional extra HTML to incude inside the <head>
                   6448: 
                   6449: $args - additional optional args supported are:
                   6450: 
                   6451: =over 8
                   6452: 
                   6453:              only_body      -> is true will set &bodytag() onlybodytag
1.317     albertel 6454:                                     arg on
1.648     raeburn  6455:              no_nav_bar     -> is true will set &bodytag() notopbar arg on
                   6456:              add_entries    -> additional attributes to add to the  <body>
                   6457:              domain         -> force to color decorate a page for a 
1.317     albertel 6458:                                     specific domain
1.648     raeburn  6459:              function       -> force usage of a specific rolish color
1.317     albertel 6460:                                     scheme
1.648     raeburn  6461:              redirect       -> see &headtag()
                   6462:              bgcolor        -> override the default page bg color
                   6463:              js_ready       -> return a string ready for being used in 
1.317     albertel 6464:                                     a javascript writeln
1.648     raeburn  6465:              html_encode    -> return a string ready for being used in 
1.320     albertel 6466:                                     a html attribute
1.648     raeburn  6467:              force_register -> if is true will turn on the &bodytag()
1.317     albertel 6468:                                     $forcereg arg
1.648     raeburn  6469:              body_title     -> alternate text to use instead of $title
1.326     albertel 6470:                                     in the title box that appears, this text
                   6471:                                     is not auto translated like the $title is
1.648     raeburn  6472:              frameset       -> if true will start with a <frameset>
1.330     albertel 6473:                                     rather than <body>
1.648     raeburn  6474:              no_title       -> if true the title bar won't be shown
                   6475:              skip_phases    -> hash ref of 
1.338     albertel 6476:                                     head -> skip the <html><head> generation
                   6477:                                     body -> skip all <body> generation
1.648     raeburn  6478:              no_inline_link -> if true and in remote mode, don't show the 
1.361     albertel 6479:                                     'Switch To Inline Menu' link
1.648     raeburn  6480:              no_auto_mt_title -> prevent &mt()ing the title arg
                   6481:              inherit_jsmath -> when creating popup window in a page,
                   6482:                                     should it have jsmath forced on by the
                   6483:                                     current page
1.361     albertel 6484: 
1.648     raeburn  6485: =back
1.460     albertel 6486: 
1.648     raeburn  6487: =back
1.562     albertel 6488: 
1.306     albertel 6489: =cut
                   6490: 
                   6491: sub start_page {
1.309     albertel 6492:     my ($title,$head_extra,$args) = @_;
1.318     albertel 6493:     #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313     albertel 6494:     my %head_args;
1.352     albertel 6495:     foreach my $arg ('redirect','force_register','domain','function',
1.460     albertel 6496: 		     'bgcolor','frameset','no_nav_bar','only_body',
                   6497: 		     'no_auto_mt_title') {
1.319     albertel 6498: 	if (defined($args->{$arg})) {
1.324     raeburn  6499: 	    $head_args{$arg} = $args->{$arg};
1.319     albertel 6500: 	}
1.313     albertel 6501:     }
1.319     albertel 6502: 
1.315     albertel 6503:     $env{'internal.start_page'}++;
1.338     albertel 6504:     my $result;
                   6505:     if (! exists($args->{'skip_phases'}{'head'}) ) {
                   6506: 	$result.=
1.341     albertel 6507: 	    &xml_begin().
1.338     albertel 6508: 	    &headtag($title,$head_extra,\%head_args).&endheadtag();
                   6509:     }
                   6510:     
                   6511:     if (! exists($args->{'skip_phases'}{'body'}) ) {
                   6512: 	if ($args->{'frameset'}) {
                   6513: 	    my $attr_string = &make_attr_string($args->{'force_register'},
                   6514: 						$args->{'add_entries'});
                   6515: 	    $result .= "\n<frameset $attr_string>\n";
                   6516: 	} else {
                   6517: 	    $result .=
                   6518: 		&bodytag($title, 
                   6519: 			 $args->{'function'},       $args->{'add_entries'},
                   6520: 			 $args->{'only_body'},      $args->{'domain'},
                   6521: 			 $args->{'force_register'}, $args->{'body_title'},
                   6522: 			 $args->{'no_nav_bar'},     $args->{'bgcolor'},
1.460     albertel 6523: 			 $args->{'no_title'},       $args->{'no_inline_link'},
                   6524: 			 $args);
1.338     albertel 6525: 	}
1.330     albertel 6526:     }
1.338     albertel 6527: 
1.315     albertel 6528:     if ($args->{'js_ready'}) {
1.713     kaisler  6529: 		$result = &js_ready($result);
1.315     albertel 6530:     }
1.320     albertel 6531:     if ($args->{'html_encode'}) {
1.713     kaisler  6532: 		$result = &html_encode($result);
                   6533:     }
                   6534: 
1.758     kaisler  6535: 	#Breadcrumbs
                   6536:     if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
                   6537: 		&Apache::lonhtmlcommon::clear_breadcrumbs();
                   6538: 		#if any br links exists, add them to the breadcrumbs
                   6539: 		if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {         
                   6540: 			foreach my $crumb (@{$args->{'bread_crumbs'}}){
                   6541: 				&Apache::lonhtmlcommon::add_breadcrumb($crumb);
                   6542: 			}
                   6543: 		}
                   6544: 
                   6545: 		#if bread_crumbs_component exists show it as headline else show only the breadcrumbs
                   6546: 		if(exists($args->{'bread_crumbs_component'})){
                   6547: 			$result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
                   6548: 		}else{
                   6549: 			$result .= &Apache::lonhtmlcommon::breadcrumbs();
                   6550: 		}
1.320     albertel 6551:     }
1.315     albertel 6552:     return $result;
1.306     albertel 6553: }
                   6554: 
1.330     albertel 6555: 
1.306     albertel 6556: =pod
                   6557: 
                   6558: =item * &head()
                   6559: 
                   6560: Returns a complete </body></html> section for LON-CAPA web pages.
                   6561: 
1.315     albertel 6562: Inputs:         $args - additional optional args supported are:
                   6563:                  js_ready     -> return a string ready for being used in 
                   6564:                                  a javascript writeln
1.320     albertel 6565:                  html_encode  -> return a string ready for being used in 
                   6566:                                  a html attribute
1.330     albertel 6567:                  frameset     -> if true will start with a <frameset>
                   6568:                                  rather than <body>
1.493     albertel 6569:                  dicsussion   -> if true will get discussion from
                   6570:                                   lonxml::xmlend
                   6571:                                  (you can pass the target and parser arguments
                   6572:                                   through optional 'target' and 'parser' args
                   6573:                                   to this routine)
1.306     albertel 6574: 
                   6575: =cut
                   6576: 
                   6577: sub end_page {
1.315     albertel 6578:     my ($args) = @_;
                   6579:     $env{'internal.end_page'}++;
1.330     albertel 6580:     my $result;
1.335     albertel 6581:     if ($args->{'discussion'}) {
                   6582: 	my ($target,$parser);
                   6583: 	if (ref($args->{'discussion'})) {
                   6584: 	    ($target,$parser) =($args->{'discussion'}{'target'},
                   6585: 				$args->{'discussion'}{'parser'});
                   6586: 	}
                   6587: 	$result .= &Apache::lonxml::xmlend($target,$parser);
                   6588:     }
                   6589: 
1.330     albertel 6590:     if ($args->{'frameset'}) {
                   6591: 	$result .= '</frameset>';
                   6592:     } else {
1.635     raeburn  6593: 	$result .= &endbodytag($args);
1.330     albertel 6594:     }
                   6595:     $result .= "\n</html>";
                   6596: 
1.315     albertel 6597:     if ($args->{'js_ready'}) {
1.317     albertel 6598: 	$result = &js_ready($result);
1.315     albertel 6599:     }
1.335     albertel 6600: 
1.320     albertel 6601:     if ($args->{'html_encode'}) {
                   6602: 	$result = &html_encode($result);
                   6603:     }
1.335     albertel 6604: 
1.315     albertel 6605:     return $result;
                   6606: }
                   6607: 
1.320     albertel 6608: sub html_encode {
                   6609:     my ($result) = @_;
                   6610: 
1.322     albertel 6611:     $result = &HTML::Entities::encode($result,'<>&"');
1.320     albertel 6612:     
                   6613:     return $result;
                   6614: }
1.317     albertel 6615: sub js_ready {
                   6616:     my ($result) = @_;
                   6617: 
1.323     albertel 6618:     $result =~ s/[\n\r]/ /xmsg;
                   6619:     $result =~ s/\\/\\\\/xmsg;
                   6620:     $result =~ s/'/\\'/xmsg;
1.372     albertel 6621:     $result =~ s{</}{<\\/}xmsg;
1.317     albertel 6622:     
                   6623:     return $result;
                   6624: }
                   6625: 
1.315     albertel 6626: sub validate_page {
                   6627:     if (  exists($env{'internal.start_page'})
1.316     albertel 6628: 	  &&     $env{'internal.start_page'} > 1) {
                   6629: 	&Apache::lonnet::logthis('start_page called multiple times '.
1.318     albertel 6630: 				 $env{'internal.start_page'}.' '.
1.316     albertel 6631: 				 $ENV{'request.filename'});
1.315     albertel 6632:     }
                   6633:     if (  exists($env{'internal.end_page'})
1.316     albertel 6634: 	  &&     $env{'internal.end_page'} > 1) {
                   6635: 	&Apache::lonnet::logthis('end_page called multiple times '.
1.318     albertel 6636: 				 $env{'internal.end_page'}.' '.
1.316     albertel 6637: 				 $env{'request.filename'});
1.315     albertel 6638:     }
                   6639:     if (     exists($env{'internal.start_page'})
                   6640: 	&& ! exists($env{'internal.end_page'})) {
1.316     albertel 6641: 	&Apache::lonnet::logthis('start_page called without end_page '.
                   6642: 				 $env{'request.filename'});
1.315     albertel 6643:     }
                   6644:     if (   ! exists($env{'internal.start_page'})
                   6645: 	&&   exists($env{'internal.end_page'})) {
1.316     albertel 6646: 	&Apache::lonnet::logthis('end_page called without start_page'.
                   6647: 				 $env{'request.filename'});
1.315     albertel 6648:     }
1.306     albertel 6649: }
1.315     albertel 6650: 
1.318     albertel 6651: sub simple_error_page {
                   6652:     my ($r,$title,$msg) = @_;
                   6653:     my $page =
                   6654: 	&Apache::loncommon::start_page($title).
                   6655: 	&mt($msg).
                   6656: 	&Apache::loncommon::end_page();
                   6657:     if (ref($r)) {
                   6658: 	$r->print($page);
1.327     albertel 6659: 	return;
1.318     albertel 6660:     }
                   6661:     return $page;
                   6662: }
1.347     albertel 6663: 
                   6664: {
1.610     albertel 6665:     my @row_count;
1.347     albertel 6666:     sub start_data_table {
1.422     albertel 6667: 	my ($add_class) = @_;
                   6668: 	my $css_class = (join(' ','LC_data_table',$add_class));
1.610     albertel 6669: 	unshift(@row_count,0);
1.422     albertel 6670: 	return '<table class="'.$css_class.'">'."\n";
1.347     albertel 6671:     }
                   6672: 
                   6673:     sub end_data_table {
1.610     albertel 6674: 	shift(@row_count);
1.389     albertel 6675: 	return '</table>'."\n";;
1.347     albertel 6676:     }
                   6677: 
                   6678:     sub start_data_table_row {
1.422     albertel 6679: 	my ($add_class) = @_;
1.610     albertel 6680: 	$row_count[0]++;
                   6681: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428     albertel 6682: 	$css_class = (join(' ',$css_class,$add_class));
1.422     albertel 6683: 	return  '<tr class="'.$css_class.'">'."\n";;
1.347     albertel 6684:     }
1.471     banghart 6685:     
                   6686:     sub continue_data_table_row {
                   6687: 	my ($add_class) = @_;
1.610     albertel 6688: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471     banghart 6689: 	$css_class = (join(' ',$css_class,$add_class));
                   6690: 	return  '<tr class="'.$css_class.'">'."\n";;
                   6691:     }
1.347     albertel 6692: 
                   6693:     sub end_data_table_row {
1.389     albertel 6694: 	return '</tr>'."\n";;
1.347     albertel 6695:     }
1.367     www      6696: 
1.421     albertel 6697:     sub start_data_table_empty_row {
1.707     bisitz   6698: #	$row_count[0]++;
1.421     albertel 6699: 	return  '<tr class="LC_empty_row" >'."\n";;
                   6700:     }
                   6701: 
                   6702:     sub end_data_table_empty_row {
                   6703: 	return '</tr>'."\n";;
                   6704:     }
                   6705: 
1.367     www      6706:     sub start_data_table_header_row {
1.389     albertel 6707: 	return  '<tr class="LC_header_row">'."\n";;
1.367     www      6708:     }
                   6709: 
                   6710:     sub end_data_table_header_row {
1.389     albertel 6711: 	return '</tr>'."\n";;
1.367     www      6712:     }
1.347     albertel 6713: }
                   6714: 
1.548     albertel 6715: =pod
                   6716: 
                   6717: =item * &inhibit_menu_check($arg)
                   6718: 
                   6719: Checks for a inhibitmenu state and generates output to preserve it
                   6720: 
                   6721: Inputs:         $arg - can be any of
                   6722:                      - undef - in which case the return value is a string 
                   6723:                                to add  into arguments list of a uri
                   6724:                      - 'input' - in which case the return value is a HTML
                   6725:                                  <form> <input> field of type hidden to
                   6726:                                  preserve the value
                   6727:                      - a url - in which case the return value is the url with
                   6728:                                the neccesary cgi args added to preserve the
                   6729:                                inhibitmenu state
                   6730:                      - a ref to a url - no return value, but the string is
                   6731:                                         updated to include the neccessary cgi
                   6732:                                         args to preserve the inhibitmenu state
                   6733: 
                   6734: =cut
                   6735: 
                   6736: sub inhibit_menu_check {
                   6737:     my ($arg) = @_;
                   6738:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   6739:     if ($arg eq 'input') {
                   6740: 	if ($env{'form.inhibitmenu'}) {
                   6741: 	    return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
                   6742: 	} else {
                   6743: 	    return
                   6744: 	}
                   6745:     }
                   6746:     if ($env{'form.inhibitmenu'}) {
                   6747: 	if (ref($arg)) {
                   6748: 	    $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   6749: 	} elsif ($arg eq '') {
                   6750: 	    $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
                   6751: 	} else {
                   6752: 	    $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   6753: 	}
                   6754:     }
                   6755:     if (!ref($arg)) {
                   6756: 	return $arg;
                   6757:     }
                   6758: }
                   6759: 
1.251     albertel 6760: ###############################################
1.182     matthew  6761: 
                   6762: =pod
                   6763: 
1.549     albertel 6764: =back
                   6765: 
                   6766: =head1 User Information Routines
                   6767: 
                   6768: =over 4
                   6769: 
1.405     albertel 6770: =item * &get_users_function()
1.182     matthew  6771: 
                   6772: Used by &bodytag to determine the current users primary role.
                   6773: Returns either 'student','coordinator','admin', or 'author'.
                   6774: 
                   6775: =cut
                   6776: 
                   6777: ###############################################
                   6778: sub get_users_function {
                   6779:     my $function = 'student';
1.258     albertel 6780:     if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182     matthew  6781:         $function='coordinator';
                   6782:     }
1.258     albertel 6783:     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182     matthew  6784:         $function='admin';
                   6785:     }
1.258     albertel 6786:     if (($env{'request.role'}=~/^(au|ca)/) ||
1.182     matthew  6787:         ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
                   6788:         $function='author';
                   6789:     }
                   6790:     return $function;
1.54      www      6791: }
1.99      www      6792: 
                   6793: ###############################################
                   6794: 
1.233     raeburn  6795: =pod
                   6796: 
1.542     raeburn  6797: =item * &check_user_status()
1.274     raeburn  6798: 
                   6799: Determines current status of supplied role for a
                   6800: specific user. Roles can be active, previous or future.
                   6801: 
                   6802: Inputs: 
                   6803: user's domain, user's username, course's domain,
1.375     raeburn  6804: course's number, optional section ID.
1.274     raeburn  6805: 
                   6806: Outputs:
                   6807: role status: active, previous or future. 
                   6808: 
                   6809: =cut
                   6810: 
                   6811: sub check_user_status {
1.412     raeburn  6812:     my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274     raeburn  6813:     my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
                   6814:     my @uroles = keys %userinfo;
                   6815:     my $srchstr;
                   6816:     my $active_chk = 'none';
1.412     raeburn  6817:     my $now = time;
1.274     raeburn  6818:     if (@uroles > 0) {
1.412     raeburn  6819:         if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274     raeburn  6820:             $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
                   6821:         } else {
1.412     raeburn  6822:             $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
                   6823:         }
                   6824:         if (grep/^\Q$srchstr\E$/,@uroles) {
1.274     raeburn  6825:             my $role_end = 0;
                   6826:             my $role_start = 0;
                   6827:             $active_chk = 'active';
1.412     raeburn  6828:             if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
                   6829:                 $role_end = $1;
                   6830:                 if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
                   6831:                     $role_start = $1;
1.274     raeburn  6832:                 }
                   6833:             }
                   6834:             if ($role_start > 0) {
1.412     raeburn  6835:                 if ($now < $role_start) {
1.274     raeburn  6836:                     $active_chk = 'future';
                   6837:                 }
                   6838:             }
                   6839:             if ($role_end > 0) {
1.412     raeburn  6840:                 if ($now > $role_end) {
1.274     raeburn  6841:                     $active_chk = 'previous';
                   6842:                 }
                   6843:             }
                   6844:         }
                   6845:     }
                   6846:     return $active_chk;
                   6847: }
                   6848: 
                   6849: ###############################################
                   6850: 
                   6851: =pod
                   6852: 
1.405     albertel 6853: =item * &get_sections()
1.233     raeburn  6854: 
                   6855: Determines all the sections for a course including
                   6856: sections with students and sections containing other roles.
1.419     raeburn  6857: Incoming parameters: 
                   6858: 
                   6859: 1. domain
                   6860: 2. course number 
                   6861: 3. reference to array containing roles for which sections should 
                   6862: be gathered (optional).
                   6863: 4. reference to array containing status types for which sections 
                   6864: should be gathered (optional).
                   6865: 
                   6866: If the third argument is undefined, sections are gathered for any role. 
                   6867: If the fourth argument is undefined, sections are gathered for any status.
                   6868: Permissible values are 'active' or 'future' or 'previous'.
1.233     raeburn  6869:  
1.374     raeburn  6870: Returns section hash (keys are section IDs, values are
                   6871: number of users in each section), subject to the
1.419     raeburn  6872: optional roles filter, optional status filter 
1.233     raeburn  6873: 
                   6874: =cut
                   6875: 
                   6876: ###############################################
                   6877: sub get_sections {
1.419     raeburn  6878:     my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366     albertel 6879:     if (!defined($cdom) || !defined($cnum)) {
                   6880:         my $cid =  $env{'request.course.id'};
                   6881: 
                   6882: 	return if (!defined($cid));
                   6883: 
                   6884:         $cdom = $env{'course.'.$cid.'.domain'};
                   6885:         $cnum = $env{'course.'.$cid.'.num'};
                   6886:     }
                   6887: 
                   6888:     my %sectioncount;
1.419     raeburn  6889:     my $now = time;
1.240     albertel 6890: 
1.366     albertel 6891:     if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276     albertel 6892: 	my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240     albertel 6893: 	my $sec_index = &Apache::loncoursedata::CL_SECTION();
                   6894: 	my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419     raeburn  6895:         my $start_index = &Apache::loncoursedata::CL_START();
                   6896:         my $end_index = &Apache::loncoursedata::CL_END();
                   6897:         my $status;
1.366     albertel 6898: 	while (my ($student,$data) = each(%$classlist)) {
1.419     raeburn  6899: 	    my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
                   6900: 				                     $data->[$status_index],
                   6901:                                                      $data->[$start_index],
                   6902:                                                      $data->[$end_index]);
                   6903:             if ($stu_status eq 'Active') {
                   6904:                 $status = 'active';
                   6905:             } elsif ($end < $now) {
                   6906:                 $status = 'previous';
                   6907:             } elsif ($start > $now) {
                   6908:                 $status = 'future';
                   6909:             } 
                   6910: 	    if ($section ne '-1' && $section !~ /^\s*$/) {
                   6911:                 if ((!defined($possible_status)) || (($status ne '') && 
                   6912:                     (grep/^\Q$status\E$/,@{$possible_status}))) { 
                   6913: 		    $sectioncount{$section}++;
                   6914:                 }
1.240     albertel 6915: 	    }
                   6916: 	}
                   6917:     }
                   6918:     my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   6919:     foreach my $user (sort(keys(%courseroles))) {
                   6920: 	if ($user !~ /^(\w{2})/) { next; }
                   6921: 	my ($role) = ($user =~ /^(\w{2})/);
                   6922: 	if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419     raeburn  6923: 	my ($section,$status);
1.240     albertel 6924: 	if ($role eq 'cr' &&
                   6925: 	    $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
                   6926: 	    $section=$1;
                   6927: 	}
                   6928: 	if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
                   6929: 	if (!defined($section) || $section eq '-1') { next; }
1.419     raeburn  6930:         my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
                   6931:         if ($end == -1 && $start == -1) {
                   6932:             next; #deleted role
                   6933:         }
                   6934:         if (!defined($possible_status)) { 
                   6935:             $sectioncount{$section}++;
                   6936:         } else {
                   6937:             if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
                   6938:                 $status = 'active';
                   6939:             } elsif ($end < $now) {
                   6940:                 $status = 'future';
                   6941:             } elsif ($start > $now) {
                   6942:                 $status = 'previous';
                   6943:             }
                   6944:             if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
                   6945:                 $sectioncount{$section}++;
                   6946:             }
                   6947:         }
1.233     raeburn  6948:     }
1.366     albertel 6949:     return %sectioncount;
1.233     raeburn  6950: }
                   6951: 
1.274     raeburn  6952: ###############################################
1.294     raeburn  6953: 
                   6954: =pod
1.405     albertel 6955: 
                   6956: =item * &get_course_users()
                   6957: 
1.275     raeburn  6958: Retrieves usernames:domains for users in the specified course
                   6959: with specific role(s), and access status. 
                   6960: 
                   6961: Incoming parameters:
1.277     albertel 6962: 1. course domain
                   6963: 2. course number
                   6964: 3. access status: users must have - either active, 
1.275     raeburn  6965: previous, future, or all.
1.277     albertel 6966: 4. reference to array of permissible roles
1.288     raeburn  6967: 5. reference to array of section restrictions (optional)
                   6968: 6. reference to results object (hash of hashes).
                   6969: 7. reference to optional userdata hash
1.609     raeburn  6970: 8. reference to optional statushash
1.630     raeburn  6971: 9. flag if privileged users (except those set to unhide in
                   6972:    course settings) should be excluded    
1.609     raeburn  6973: Keys of top level results hash are roles.
1.275     raeburn  6974: Keys of inner hashes are username:domain, with 
                   6975: values set to access type.
1.288     raeburn  6976: Optional userdata hash returns an array with arguments in the 
                   6977: same order as loncoursedata::get_classlist() for student data.
                   6978: 
1.609     raeburn  6979: Optional statushash returns
                   6980: 
1.288     raeburn  6981: Entries for end, start, section and status are blank because
                   6982: of the possibility of multiple values for non-student roles.
                   6983: 
1.275     raeburn  6984: =cut
1.405     albertel 6985: 
1.275     raeburn  6986: ###############################################
1.405     albertel 6987: 
1.275     raeburn  6988: sub get_course_users {
1.630     raeburn  6989:     my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288     raeburn  6990:     my %idx = ();
1.419     raeburn  6991:     my %seclists;
1.288     raeburn  6992: 
                   6993:     $idx{udom} = &Apache::loncoursedata::CL_SDOM();
                   6994:     $idx{uname} =  &Apache::loncoursedata::CL_SNAME();
                   6995:     $idx{end} = &Apache::loncoursedata::CL_END();
                   6996:     $idx{start} = &Apache::loncoursedata::CL_START();
                   6997:     $idx{id} = &Apache::loncoursedata::CL_ID();
                   6998:     $idx{section} = &Apache::loncoursedata::CL_SECTION();
                   6999:     $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
                   7000:     $idx{status} = &Apache::loncoursedata::CL_STATUS();
                   7001: 
1.290     albertel 7002:     if (grep(/^st$/,@{$roles})) {
1.276     albertel 7003:         my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278     raeburn  7004:         my $now = time;
1.277     albertel 7005:         foreach my $student (keys(%{$classlist})) {
1.288     raeburn  7006:             my $match = 0;
1.412     raeburn  7007:             my $secmatch = 0;
1.419     raeburn  7008:             my $section = $$classlist{$student}[$idx{section}];
1.609     raeburn  7009:             my $status = $$classlist{$student}[$idx{status}];
1.419     raeburn  7010:             if ($section eq '') {
                   7011:                 $section = 'none';
                   7012:             }
1.291     albertel 7013:             if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 7014:                 if (grep(/^all$/,@{$sections})) {
1.412     raeburn  7015:                     $secmatch = 1;
                   7016:                 } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420     albertel 7017:                     if (grep(/^none$/,@{$sections})) {
1.412     raeburn  7018:                         $secmatch = 1;
                   7019:                     }
                   7020:                 } else {  
1.419     raeburn  7021: 		    if (grep(/^\Q$section\E$/,@{$sections})) {
1.412     raeburn  7022: 		        $secmatch = 1;
                   7023:                     }
1.290     albertel 7024: 		}
1.412     raeburn  7025:                 if (!$secmatch) {
                   7026:                     next;
                   7027:                 }
1.419     raeburn  7028:             }
1.275     raeburn  7029:             if (defined($$types{'active'})) {
1.288     raeburn  7030:                 if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275     raeburn  7031:                     push(@{$$users{st}{$student}},'active');
1.288     raeburn  7032:                     $match = 1;
1.275     raeburn  7033:                 }
                   7034:             }
                   7035:             if (defined($$types{'previous'})) {
1.609     raeburn  7036:                 if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275     raeburn  7037:                     push(@{$$users{st}{$student}},'previous');
1.288     raeburn  7038:                     $match = 1;
1.275     raeburn  7039:                 }
                   7040:             }
                   7041:             if (defined($$types{'future'})) {
1.609     raeburn  7042:                 if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275     raeburn  7043:                     push(@{$$users{st}{$student}},'future');
1.288     raeburn  7044:                     $match = 1;
1.275     raeburn  7045:                 }
                   7046:             }
1.609     raeburn  7047:             if ($match) {
                   7048:                 push(@{$seclists{$student}},$section);
                   7049:                 if (ref($userdata) eq 'HASH') {
                   7050:                     $$userdata{$student} = $$classlist{$student};
                   7051:                 }
                   7052:                 if (ref($statushash) eq 'HASH') {
                   7053:                     $statushash->{$student}{'st'}{$section} = $status;
                   7054:                 }
1.288     raeburn  7055:             }
1.275     raeburn  7056:         }
                   7057:     }
1.412     raeburn  7058:     if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439     raeburn  7059:         my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7060:         my $now = time;
1.609     raeburn  7061:         my %displaystatus = ( previous => 'Expired',
                   7062:                               active   => 'Active',
                   7063:                               future   => 'Future',
                   7064:                             );
1.630     raeburn  7065:         my %nothide;
                   7066:         if ($hidepriv) {
                   7067:             my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
                   7068:             foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
                   7069:                 if ($user !~ /:/) {
                   7070:                     $nothide{join(':',split(/[\@]/,$user))}=1;
                   7071:                 } else {
                   7072:                     $nothide{$user} = 1;
                   7073:                 }
                   7074:             }
                   7075:         }
1.439     raeburn  7076:         foreach my $person (sort(keys(%coursepersonnel))) {
1.288     raeburn  7077:             my $match = 0;
1.412     raeburn  7078:             my $secmatch = 0;
1.439     raeburn  7079:             my $status;
1.412     raeburn  7080:             my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275     raeburn  7081:             $user =~ s/:$//;
1.439     raeburn  7082:             my ($end,$start) = split(/:/,$coursepersonnel{$person});
                   7083:             if ($end == -1 || $start == -1) {
                   7084:                 next;
                   7085:             }
                   7086:             if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
                   7087:                 (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412     raeburn  7088:                 my ($uname,$udom) = split(/:/,$user);
                   7089:                 if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 7090:                     if (grep(/^all$/,@{$sections})) {
1.412     raeburn  7091:                         $secmatch = 1;
                   7092:                     } elsif ($usec eq '') {
1.420     albertel 7093:                         if (grep(/^none$/,@{$sections})) {
1.412     raeburn  7094:                             $secmatch = 1;
                   7095:                         }
                   7096:                     } else {
                   7097:                         if (grep(/^\Q$usec\E$/,@{$sections})) {
                   7098:                             $secmatch = 1;
                   7099:                         }
                   7100:                     }
                   7101:                     if (!$secmatch) {
                   7102:                         next;
                   7103:                     }
1.288     raeburn  7104:                 }
1.419     raeburn  7105:                 if ($usec eq '') {
                   7106:                     $usec = 'none';
                   7107:                 }
1.275     raeburn  7108:                 if ($uname ne '' && $udom ne '') {
1.630     raeburn  7109:                     if ($hidepriv) {
                   7110:                         if ((&Apache::lonnet::privileged($uname,$udom)) &&
                   7111:                             (!$nothide{$uname.':'.$udom})) {
                   7112:                             next;
                   7113:                         }
                   7114:                     }
1.503     raeburn  7115:                     if ($end > 0 && $end < $now) {
1.439     raeburn  7116:                         $status = 'previous';
                   7117:                     } elsif ($start > $now) {
                   7118:                         $status = 'future';
                   7119:                     } else {
                   7120:                         $status = 'active';
                   7121:                     }
1.277     albertel 7122:                     foreach my $type (keys(%{$types})) { 
1.275     raeburn  7123:                         if ($status eq $type) {
1.420     albertel 7124:                             if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419     raeburn  7125:                                 push(@{$$users{$role}{$user}},$type);
                   7126:                             }
1.288     raeburn  7127:                             $match = 1;
                   7128:                         }
                   7129:                     }
1.419     raeburn  7130:                     if (($match) && (ref($userdata) eq 'HASH')) {
                   7131:                         if (!exists($$userdata{$uname.':'.$udom})) {
                   7132: 			    &get_user_info($udom,$uname,\%idx,$userdata);
                   7133:                         }
1.420     albertel 7134:                         if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419     raeburn  7135:                             push(@{$seclists{$uname.':'.$udom}},$usec);
                   7136:                         }
1.609     raeburn  7137:                         if (ref($statushash) eq 'HASH') {
                   7138:                             $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
                   7139:                         }
1.275     raeburn  7140:                     }
                   7141:                 }
                   7142:             }
                   7143:         }
1.290     albertel 7144:         if (grep(/^ow$/,@{$roles})) {
1.279     raeburn  7145:             if ((defined($cdom)) && (defined($cnum))) {
                   7146:                 my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
                   7147:                 if ( defined($csettings{'internal.courseowner'}) ) {
                   7148:                     my $owner = $csettings{'internal.courseowner'};
1.609     raeburn  7149:                     next if ($owner eq '');
                   7150:                     my ($ownername,$ownerdom);
                   7151:                     if ($owner =~ /^([^:]+):([^:]+)$/) {
                   7152:                         $ownername = $1;
                   7153:                         $ownerdom = $2;
                   7154:                     } else {
                   7155:                         $ownername = $owner;
                   7156:                         $ownerdom = $cdom;
                   7157:                         $owner = $ownername.':'.$ownerdom;
1.439     raeburn  7158:                     }
                   7159:                     @{$$users{'ow'}{$owner}} = 'any';
1.290     albertel 7160:                     if (defined($userdata) && 
1.609     raeburn  7161: 			!exists($$userdata{$owner})) {
                   7162: 			&get_user_info($ownerdom,$ownername,\%idx,$userdata);
                   7163:                         if (!grep(/^none$/,@{$seclists{$owner}})) {
                   7164:                             push(@{$seclists{$owner}},'none');
                   7165:                         }
                   7166:                         if (ref($statushash) eq 'HASH') {
                   7167:                             $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419     raeburn  7168:                         }
1.290     albertel 7169: 		    }
1.279     raeburn  7170:                 }
                   7171:             }
                   7172:         }
1.419     raeburn  7173:         foreach my $user (keys(%seclists)) {
                   7174:             @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
                   7175:             $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
                   7176:         }
1.275     raeburn  7177:     }
                   7178:     return;
                   7179: }
                   7180: 
1.288     raeburn  7181: sub get_user_info {
                   7182:     my ($udom,$uname,$idx,$userdata) = @_;
1.289     albertel 7183:     $$userdata{$uname.':'.$udom}[$$idx{fullname}] = 
                   7184: 	&plainname($uname,$udom,'lastname');
1.291     albertel 7185:     $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297     raeburn  7186:     $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609     raeburn  7187:     my %idhash =  &Apache::lonnet::idrget($udom,($uname));
                   7188:     $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname}; 
1.288     raeburn  7189:     return;
                   7190: }
1.275     raeburn  7191: 
1.472     raeburn  7192: ###############################################
                   7193: 
                   7194: =pod
                   7195: 
                   7196: =item * &get_user_quota()
                   7197: 
                   7198: Retrieves quota assigned for storage of portfolio files for a user  
                   7199: 
                   7200: Incoming parameters:
                   7201: 1. user's username
                   7202: 2. user's domain
                   7203: 
                   7204: Returns:
1.536     raeburn  7205: 1. Disk quota (in Mb) assigned to student.
                   7206: 2. (Optional) Type of setting: custom or default
                   7207:    (individually assigned or default for user's 
                   7208:    institutional status).
                   7209: 3. (Optional) - User's institutional status (e.g., faculty, staff
                   7210:    or student - types as defined in localenroll::inst_usertypes 
                   7211:    for user's domain, which determines default quota for user.
                   7212: 4. (Optional) - Default quota which would apply to the user.
1.472     raeburn  7213: 
                   7214: If a value has been stored in the user's environment, 
1.536     raeburn  7215: it will return that, otherwise it returns the maximal default
                   7216: defined for the user's instituional status(es) in the domain.
1.472     raeburn  7217: 
                   7218: =cut
                   7219: 
                   7220: ###############################################
                   7221: 
                   7222: 
                   7223: sub get_user_quota {
                   7224:     my ($uname,$udom) = @_;
1.536     raeburn  7225:     my ($quota,$quotatype,$settingstatus,$defquota);
1.472     raeburn  7226:     if (!defined($udom)) {
                   7227:         $udom = $env{'user.domain'};
                   7228:     }
                   7229:     if (!defined($uname)) {
                   7230:         $uname = $env{'user.name'};
                   7231:     }
                   7232:     if (($udom eq '' || $uname eq '') ||
                   7233:         ($udom eq 'public') && ($uname eq 'public')) {
                   7234:         $quota = 0;
1.536     raeburn  7235:         $quotatype = 'default';
                   7236:         $defquota = 0; 
1.472     raeburn  7237:     } else {
1.536     raeburn  7238:         my $inststatus;
1.472     raeburn  7239:         if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
                   7240:             $quota = $env{'environment.portfolioquota'};
1.536     raeburn  7241:             $inststatus = $env{'environment.inststatus'};
1.472     raeburn  7242:         } else {
1.536     raeburn  7243:             my %userenv = 
                   7244:                 &Apache::lonnet::get('environment',['portfolioquota',
                   7245:                                      'inststatus'],$udom,$uname);
1.472     raeburn  7246:             my ($tmp) = keys(%userenv);
                   7247:             if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   7248:                 $quota = $userenv{'portfolioquota'};
1.536     raeburn  7249:                 $inststatus = $userenv{'inststatus'};
1.472     raeburn  7250:             } else {
                   7251:                 undef(%userenv);
                   7252:             }
                   7253:         }
1.536     raeburn  7254:         ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472     raeburn  7255:         if ($quota eq '') {
1.536     raeburn  7256:             $quota = $defquota;
                   7257:             $quotatype = 'default';
                   7258:         } else {
                   7259:             $quotatype = 'custom';
1.472     raeburn  7260:         }
                   7261:     }
1.536     raeburn  7262:     if (wantarray) {
                   7263:         return ($quota,$quotatype,$settingstatus,$defquota);
                   7264:     } else {
                   7265:         return $quota;
                   7266:     }
1.472     raeburn  7267: }
                   7268: 
                   7269: ###############################################
                   7270: 
                   7271: =pod
                   7272: 
                   7273: =item * &default_quota()
                   7274: 
1.536     raeburn  7275: Retrieves default quota assigned for storage of user portfolio files,
                   7276: given an (optional) user's institutional status.
1.472     raeburn  7277: 
                   7278: Incoming parameters:
                   7279: 1. domain
1.536     raeburn  7280: 2. (Optional) institutional status(es).  This is a : separated list of 
                   7281:    status types (e.g., faculty, staff, student etc.)
                   7282:    which apply to the user for whom the default is being retrieved.
                   7283:    If the institutional status string in undefined, the domain
                   7284:    default quota will be returned. 
1.472     raeburn  7285: 
                   7286: Returns:
                   7287: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536     raeburn  7288: 2. (Optional) institutional type which determined the value of the
                   7289:    default quota.
1.472     raeburn  7290: 
                   7291: If a value has been stored in the domain's configuration db,
                   7292: it will return that, otherwise it returns 20 (for backwards 
                   7293: compatibility with domains which have not set up a configuration
                   7294: db file; the original statically defined portfolio quota was 20 Mb). 
                   7295: 
1.536     raeburn  7296: If the user's status includes multiple types (e.g., staff and student),
                   7297: the largest default quota which applies to the user determines the
                   7298: default quota returned.
                   7299: 
1.780     raeburn  7300: =back
                   7301: 
1.472     raeburn  7302: =cut
                   7303: 
                   7304: ###############################################
                   7305: 
                   7306: 
                   7307: sub default_quota {
1.536     raeburn  7308:     my ($udom,$inststatus) = @_;
                   7309:     my ($defquota,$settingstatus);
                   7310:     my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622     raeburn  7311:                                             ['quotas'],$udom);
                   7312:     if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536     raeburn  7313:         if ($inststatus ne '') {
1.765     raeburn  7314:             my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536     raeburn  7315:             foreach my $item (@statuses) {
1.711     raeburn  7316:                 if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7317:                     if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
                   7318:                         if ($defquota eq '') {
                   7319:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7320:                             $settingstatus = $item;
                   7321:                         } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
                   7322:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7323:                             $settingstatus = $item;
                   7324:                         }
                   7325:                     }
                   7326:                 } else {
                   7327:                     if ($quotahash{'quotas'}{$item} ne '') {
                   7328:                         if ($defquota eq '') {
                   7329:                             $defquota = $quotahash{'quotas'}{$item};
                   7330:                             $settingstatus = $item;
                   7331:                         } elsif ($quotahash{'quotas'}{$item} > $defquota) {
                   7332:                             $defquota = $quotahash{'quotas'}{$item};
                   7333:                             $settingstatus = $item;
                   7334:                         }
1.536     raeburn  7335:                     }
                   7336:                 }
                   7337:             }
                   7338:         }
                   7339:         if ($defquota eq '') {
1.711     raeburn  7340:             if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7341:                 $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
                   7342:             } else {
                   7343:                 $defquota = $quotahash{'quotas'}{'default'};
                   7344:             }
1.536     raeburn  7345:             $settingstatus = 'default';
                   7346:         }
                   7347:     } else {
                   7348:         $settingstatus = 'default';
                   7349:         $defquota = 20;
                   7350:     }
                   7351:     if (wantarray) {
                   7352:         return ($defquota,$settingstatus);
1.472     raeburn  7353:     } else {
1.536     raeburn  7354:         return $defquota;
1.472     raeburn  7355:     }
                   7356: }
                   7357: 
1.384     raeburn  7358: sub get_secgrprole_info {
                   7359:     my ($cdom,$cnum,$needroles,$type)  = @_;
                   7360:     my %sections_count = &get_sections($cdom,$cnum);
                   7361:     my @sections =  (sort {$a <=> $b} keys(%sections_count));
                   7362:     my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
                   7363:     my @groups = sort(keys(%curr_groups));
                   7364:     my $allroles = [];
                   7365:     my $rolehash;
                   7366:     my $accesshash = {
                   7367:                      active => 'Currently has access',
                   7368:                      future => 'Will have future access',
                   7369:                      previous => 'Previously had access',
                   7370:                   };
                   7371:     if ($needroles) {
                   7372:         $rolehash = {'all' => 'all'};
1.385     albertel 7373:         my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7374: 	if (&Apache::lonnet::error(%user_roles)) {
                   7375: 	    undef(%user_roles);
                   7376: 	}
                   7377:         foreach my $item (keys(%user_roles)) {
1.384     raeburn  7378:             my ($role)=split(/\:/,$item,2);
                   7379:             if ($role eq 'cr') { next; }
                   7380:             if ($role =~ /^cr/) {
                   7381:                 $$rolehash{$role} = (split('/',$role))[3];
                   7382:             } else {
                   7383:                 $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
                   7384:             }
                   7385:         }
                   7386:         foreach my $key (sort(keys(%{$rolehash}))) {
                   7387:             push(@{$allroles},$key);
                   7388:         }
                   7389:         push (@{$allroles},'st');
                   7390:         $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
                   7391:     }
                   7392:     return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
                   7393: }
                   7394: 
1.555     raeburn  7395: sub user_picker {
1.627     raeburn  7396:     my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555     raeburn  7397:     my $currdom = $dom;
                   7398:     my %curr_selected = (
                   7399:                         srchin => 'dom',
1.580     raeburn  7400:                         srchby => 'lastname',
1.555     raeburn  7401:                       );
                   7402:     my $srchterm;
1.625     raeburn  7403:     if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555     raeburn  7404:         if ($srch->{'srchby'} ne '') {
                   7405:             $curr_selected{'srchby'} = $srch->{'srchby'};
                   7406:         }
                   7407:         if ($srch->{'srchin'} ne '') {
                   7408:             $curr_selected{'srchin'} = $srch->{'srchin'};
                   7409:         }
                   7410:         if ($srch->{'srchtype'} ne '') {
                   7411:             $curr_selected{'srchtype'} = $srch->{'srchtype'};
                   7412:         }
                   7413:         if ($srch->{'srchdomain'} ne '') {
                   7414:             $currdom = $srch->{'srchdomain'};
                   7415:         }
                   7416:         $srchterm = $srch->{'srchterm'};
                   7417:     }
                   7418:     my %lt=&Apache::lonlocal::texthash(
1.573     raeburn  7419:                     'usr'       => 'Search criteria',
1.563     raeburn  7420:                     'doma'      => 'Domain/institution to search',
1.558     albertel 7421:                     'uname'     => 'username',
                   7422:                     'lastname'  => 'last name',
1.555     raeburn  7423:                     'lastfirst' => 'last name, first name',
1.558     albertel 7424:                     'crs'       => 'in this course',
1.576     raeburn  7425:                     'dom'       => 'in selected LON-CAPA domain', 
1.558     albertel 7426:                     'alc'       => 'all LON-CAPA',
1.573     raeburn  7427:                     'instd'     => 'in institutional directory for selected domain',
1.558     albertel 7428:                     'exact'     => 'is',
                   7429:                     'contains'  => 'contains',
1.569     raeburn  7430:                     'begins'    => 'begins with',
1.571     raeburn  7431:                     'youm'      => "You must include some text to search for.",
                   7432:                     'thte'      => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
                   7433:                     'thet'      => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
                   7434:                     'yomc'      => "You must choose a domain when using an institutional directory search.",
                   7435:                     'ymcd'      => "You must choose a domain when using a domain search.",
                   7436:                     'whus'      => "When using searching by last,first you must include a comma as separator between last name and first name.",
                   7437:                     'whse'      => "When searching by last,first you must include at least one character in the first name.",
                   7438:                      'thfo'     => "The following need to be corrected before the search can be run:",
1.555     raeburn  7439:                                        );
1.563     raeburn  7440:     my $domform = &select_dom_form($currdom,'srchdomain',1,1);
                   7441:     my $srchinsel = ' <select name="srchin">';
1.555     raeburn  7442: 
                   7443:     my @srchins = ('crs','dom','alc','instd');
                   7444: 
                   7445:     foreach my $option (@srchins) {
                   7446:         # FIXME 'alc' option unavailable until 
                   7447:         #       loncreateuser::print_user_query_page()
                   7448:         #       has been completed.
                   7449:         next if ($option eq 'alc');
                   7450:         next if ($option eq 'crs' && !$env{'request.course.id'});
1.563     raeburn  7451:         if ($curr_selected{'srchin'} eq $option) {
                   7452:             $srchinsel .= ' 
                   7453:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7454:         } else {
                   7455:             $srchinsel .= '
                   7456:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7457:         }
1.555     raeburn  7458:     }
1.563     raeburn  7459:     $srchinsel .= "\n  </select>\n";
1.555     raeburn  7460: 
                   7461:     my $srchbysel =  ' <select name="srchby">';
1.580     raeburn  7462:     foreach my $option ('lastname','lastfirst','uname') {
1.555     raeburn  7463:         if ($curr_selected{'srchby'} eq $option) {
                   7464:             $srchbysel .= '
                   7465:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7466:         } else {
                   7467:             $srchbysel .= '
                   7468:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7469:          }
                   7470:     }
                   7471:     $srchbysel .= "\n  </select>\n";
                   7472: 
                   7473:     my $srchtypesel = ' <select name="srchtype">';
1.580     raeburn  7474:     foreach my $option ('begins','contains','exact') {
1.555     raeburn  7475:         if ($curr_selected{'srchtype'} eq $option) {
                   7476:             $srchtypesel .= '
                   7477:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7478:         } else {
                   7479:             $srchtypesel .= '
                   7480:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7481:         }
                   7482:     }
                   7483:     $srchtypesel .= "\n  </select>\n";
                   7484: 
1.558     albertel 7485:     my ($newuserscript,$new_user_create);
1.556     raeburn  7486: 
                   7487:     if ($forcenewuser) {
1.576     raeburn  7488:         if (ref($srch) eq 'HASH') {
                   7489:             if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627     raeburn  7490:                 if ($cancreate) {
                   7491:                     $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>';
                   7492:                 } else {
                   7493:                     my $helplink = ' href="javascript:helpMenu('."'display'".')"';
                   7494:                     my %usertypetext = (
                   7495:                         official   => 'institutional',
                   7496:                         unofficial => 'non-institutional',
                   7497:                     );
                   7498:                     $new_user_create = '<br /><span class="LC_warning">'.&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.").' '.&mt('Contact the <a[_1]>helpdesk</a> for assistance.',$helplink).'</span><br /><br />';
                   7499:                 }
1.576     raeburn  7500:             }
                   7501:         }
                   7502: 
1.556     raeburn  7503:         $newuserscript = <<"ENDSCRIPT";
                   7504: 
1.570     raeburn  7505: function setSearch(createnew,callingForm) {
1.556     raeburn  7506:     if (createnew == 1) {
1.570     raeburn  7507:         for (var i=0; i<callingForm.srchby.length; i++) {
                   7508:             if (callingForm.srchby.options[i].value == 'uname') {
                   7509:                 callingForm.srchby.selectedIndex = i;
1.556     raeburn  7510:             }
                   7511:         }
1.570     raeburn  7512:         for (var i=0; i<callingForm.srchin.length; i++) {
                   7513:             if ( callingForm.srchin.options[i].value == 'dom') {
                   7514: 		callingForm.srchin.selectedIndex = i;
1.556     raeburn  7515:             }
                   7516:         }
1.570     raeburn  7517:         for (var i=0; i<callingForm.srchtype.length; i++) {
                   7518:             if (callingForm.srchtype.options[i].value == 'exact') {
                   7519:                 callingForm.srchtype.selectedIndex = i;
1.556     raeburn  7520:             }
                   7521:         }
1.570     raeburn  7522:         for (var i=0; i<callingForm.srchdomain.length; i++) {
                   7523:             if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
                   7524:                 callingForm.srchdomain.selectedIndex = i;
1.556     raeburn  7525:             }
                   7526:         }
                   7527:     }
                   7528: }
                   7529: ENDSCRIPT
1.558     albertel 7530: 
1.556     raeburn  7531:     }
                   7532: 
1.555     raeburn  7533:     my $output = <<"END_BLOCK";
1.556     raeburn  7534: <script type="text/javascript">
1.570     raeburn  7535: function validateEntry(callingForm) {
1.558     albertel 7536: 
1.556     raeburn  7537:     var checkok = 1;
1.558     albertel 7538:     var srchin;
1.570     raeburn  7539:     for (var i=0; i<callingForm.srchin.length; i++) {
                   7540: 	if ( callingForm.srchin[i].checked ) {
                   7541: 	    srchin = callingForm.srchin[i].value;
1.558     albertel 7542: 	}
                   7543:     }
                   7544: 
1.570     raeburn  7545:     var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
                   7546:     var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
                   7547:     var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
                   7548:     var srchterm =  callingForm.srchterm.value;
                   7549:     var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556     raeburn  7550:     var msg = "";
                   7551: 
                   7552:     if (srchterm == "") {
                   7553:         checkok = 0;
1.571     raeburn  7554:         msg += "$lt{'youm'}\\n";
1.556     raeburn  7555:     }
                   7556: 
1.569     raeburn  7557:     if (srchtype== 'begins') {
                   7558:         if (srchterm.length < 2) {
                   7559:             checkok = 0;
1.571     raeburn  7560:             msg += "$lt{'thte'}\\n";
1.569     raeburn  7561:         }
                   7562:     }
                   7563: 
1.556     raeburn  7564:     if (srchtype== 'contains') {
                   7565:         if (srchterm.length < 3) {
                   7566:             checkok = 0;
1.571     raeburn  7567:             msg += "$lt{'thet'}\\n";
1.556     raeburn  7568:         }
                   7569:     }
                   7570:     if (srchin == 'instd') {
                   7571:         if (srchdomain == '') {
                   7572:             checkok = 0;
1.571     raeburn  7573:             msg += "$lt{'yomc'}\\n";
1.556     raeburn  7574:         }
                   7575:     }
                   7576:     if (srchin == 'dom') {
                   7577:         if (srchdomain == '') {
                   7578:             checkok = 0;
1.571     raeburn  7579:             msg += "$lt{'ymcd'}\\n";
1.556     raeburn  7580:         }
                   7581:     }
                   7582:     if (srchby == 'lastfirst') {
                   7583:         if (srchterm.indexOf(",") == -1) {
                   7584:             checkok = 0;
1.571     raeburn  7585:             msg += "$lt{'whus'}\\n";
1.556     raeburn  7586:         }
                   7587:         if (srchterm.indexOf(",") == srchterm.length -1) {
                   7588:             checkok = 0;
1.571     raeburn  7589:             msg += "$lt{'whse'}\\n";
1.556     raeburn  7590:         }
                   7591:     }
                   7592:     if (checkok == 0) {
1.571     raeburn  7593:         alert("$lt{'thfo'}\\n"+msg);
1.556     raeburn  7594:         return;
                   7595:     }
                   7596:     if (checkok == 1) {
1.570     raeburn  7597:         callingForm.submit();
1.556     raeburn  7598:     }
                   7599: }
                   7600: 
                   7601: $newuserscript
                   7602: 
                   7603: </script>
1.558     albertel 7604: 
                   7605: $new_user_create
                   7606: 
1.555     raeburn  7607: <table>
1.558     albertel 7608:  <tr>
1.573     raeburn  7609:   <td>$lt{'doma'}:</td>
                   7610:   <td>$domform</td>
                   7611:   </td>
                   7612:  </tr>
                   7613:  <tr>
                   7614:   <td>$lt{'usr'}:</td>
1.563     raeburn  7615:   <td>$srchbysel
                   7616:       $srchtypesel 
                   7617:       <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564     albertel 7618:       $srchinsel 
1.563     raeburn  7619:   </td>
                   7620:  </tr>
1.555     raeburn  7621: </table>
                   7622: <br />
                   7623: END_BLOCK
1.558     albertel 7624: 
1.555     raeburn  7625:     return $output;
                   7626: }
                   7627: 
1.612     raeburn  7628: sub user_rule_check {
1.615     raeburn  7629:     my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612     raeburn  7630:     my $response;
                   7631:     if (ref($usershash) eq 'HASH') {
                   7632:         foreach my $user (keys(%{$usershash})) {
                   7633:             my ($uname,$udom) = split(/:/,$user);
                   7634:             next if ($udom eq '' || $uname eq '');
1.615     raeburn  7635:             my ($id,$newuser);
1.612     raeburn  7636:             if (ref($usershash->{$user}) eq 'HASH') {
1.615     raeburn  7637:                 $newuser = $usershash->{$user}->{'newuser'};
1.612     raeburn  7638:                 $id = $usershash->{$user}->{'id'};
                   7639:             }
                   7640:             my $inst_response;
                   7641:             if (ref($checks) eq 'HASH') {
                   7642:                 if (defined($checks->{'username'})) {
1.615     raeburn  7643:                     ($inst_response,%{$inst_results->{$user}}) = 
1.612     raeburn  7644:                         &Apache::lonnet::get_instuser($udom,$uname);
                   7645:                 } elsif (defined($checks->{'id'})) {
1.615     raeburn  7646:                     ($inst_response,%{$inst_results->{$user}}) =
1.612     raeburn  7647:                         &Apache::lonnet::get_instuser($udom,undef,$id);
                   7648:                 }
1.615     raeburn  7649:             } else {
                   7650:                 ($inst_response,%{$inst_results->{$user}}) =
                   7651:                     &Apache::lonnet::get_instuser($udom,$uname);
                   7652:                 return;
1.612     raeburn  7653:             }
1.615     raeburn  7654:             if (!$got_rules->{$udom}) {
1.612     raeburn  7655:                 my %domconfig = &Apache::lonnet::get_dom('configuration',
                   7656:                                                   ['usercreation'],$udom);
                   7657:                 if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615     raeburn  7658:                     foreach my $item ('username','id') {
1.612     raeburn  7659:                         if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
                   7660:                             $$curr_rules{$udom}{$item} = 
                   7661:                                 $domconfig{'usercreation'}{$item.'_rule'};
1.585     raeburn  7662:                         }
                   7663:                     }
                   7664:                 }
1.615     raeburn  7665:                 $got_rules->{$udom} = 1;  
1.585     raeburn  7666:             }
1.612     raeburn  7667:             foreach my $item (keys(%{$checks})) {
                   7668:                 if (ref($$curr_rules{$udom}) eq 'HASH') {
                   7669:                     if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
                   7670:                         if (@{$$curr_rules{$udom}{$item}} > 0) {
                   7671:                             my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
                   7672:                             foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
                   7673:                                 if ($rule_check{$rule}) {
                   7674:                                     $$rulematch{$user}{$item} = $rule;
                   7675:                                     if ($inst_response eq 'ok') {
1.615     raeburn  7676:                                         if (ref($inst_results) eq 'HASH') {
                   7677:                                             if (ref($inst_results->{$user}) eq 'HASH') {
                   7678:                                                 if (keys(%{$inst_results->{$user}}) == 0) {
                   7679:                                                     $$alerts{$item}{$udom}{$uname} = 1;
                   7680:                                                 }
1.612     raeburn  7681:                                             }
                   7682:                                         }
1.615     raeburn  7683:                                     }
                   7684:                                     last;
1.585     raeburn  7685:                                 }
                   7686:                             }
                   7687:                         }
                   7688:                     }
                   7689:                 }
                   7690:             }
                   7691:         }
                   7692:     }
1.612     raeburn  7693:     return;
                   7694: }
                   7695: 
                   7696: sub user_rule_formats {
                   7697:     my ($domain,$domdesc,$curr_rules,$check) = @_;
                   7698:     my %text = ( 
                   7699:                  'username' => 'Usernames',
                   7700:                  'id'       => 'IDs',
                   7701:                );
                   7702:     my $output;
                   7703:     my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
                   7704:     if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
                   7705:         if (@{$ruleorder} > 0) {
                   7706:             $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>';
                   7707:             foreach my $rule (@{$ruleorder}) {
                   7708:                 if (ref($curr_rules) eq 'ARRAY') {
                   7709:                     if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
                   7710:                         if (ref($rules->{$rule}) eq 'HASH') {
                   7711:                             $output .= '<li>'.$rules->{$rule}{'name'}.': '.
                   7712:                                         $rules->{$rule}{'desc'}.'</li>';
                   7713:                         }
                   7714:                     }
                   7715:                 }
                   7716:             }
                   7717:             $output .= '</ul>';
                   7718:         }
                   7719:     }
                   7720:     return $output;
                   7721: }
                   7722: 
                   7723: sub instrule_disallow_msg {
1.615     raeburn  7724:     my ($checkitem,$domdesc,$count,$mode) = @_;
1.612     raeburn  7725:     my $response;
                   7726:     my %text = (
                   7727:                   item   => 'username',
                   7728:                   items  => 'usernames',
                   7729:                   match  => 'matches',
                   7730:                   do     => 'does',
                   7731:                   action => 'a username',
                   7732:                   one    => 'one',
                   7733:                );
                   7734:     if ($count > 1) {
                   7735:         $text{'item'} = 'usernames';
                   7736:         $text{'match'} ='match';
                   7737:         $text{'do'} = 'do';
                   7738:         $text{'action'} = 'usernames',
                   7739:         $text{'one'} = 'ones';
                   7740:     }
                   7741:     if ($checkitem eq 'id') {
                   7742:         $text{'items'} = 'IDs';
                   7743:         $text{'item'} = 'ID';
                   7744:         $text{'action'} = 'an ID';
1.615     raeburn  7745:         if ($count > 1) {
                   7746:             $text{'item'} = 'IDs';
                   7747:             $text{'action'} = 'IDs';
                   7748:         }
1.612     raeburn  7749:     }
1.674     bisitz   7750:     $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  7751:     if ($mode eq 'upload') {
                   7752:         if ($checkitem eq 'username') {
                   7753:             $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'}.");
                   7754:         } elsif ($checkitem eq 'id') {
1.674     bisitz   7755:             $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  7756:         }
1.669     raeburn  7757:     } elsif ($mode eq 'selfcreate') {
                   7758:         if ($checkitem eq 'id') {
                   7759:             $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.");
                   7760:         }
1.615     raeburn  7761:     } else {
                   7762:         if ($checkitem eq 'username') {
                   7763:             $response .= &mt("You must choose $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
                   7764:         } elsif ($checkitem eq 'id') {
                   7765:             $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.");
                   7766:         }
1.612     raeburn  7767:     }
                   7768:     return $response;
1.585     raeburn  7769: }
                   7770: 
1.624     raeburn  7771: sub personal_data_fieldtitles {
                   7772:     my %fieldtitles = &Apache::lonlocal::texthash (
                   7773:                         id => 'Student/Employee ID',
                   7774:                         permanentemail => 'E-mail address',
                   7775:                         lastname => 'Last Name',
                   7776:                         firstname => 'First Name',
                   7777:                         middlename => 'Middle Name',
                   7778:                         generation => 'Generation',
                   7779:                         gen => 'Generation',
1.765     raeburn  7780:                         inststatus => 'Affiliation',
1.624     raeburn  7781:                    );
                   7782:     return %fieldtitles;
                   7783: }
                   7784: 
1.642     raeburn  7785: sub sorted_inst_types {
                   7786:     my ($dom) = @_;
                   7787:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
                   7788:     my $othertitle = &mt('All users');
                   7789:     if ($env{'request.course.id'}) {
1.668     raeburn  7790:         $othertitle  = &mt('Any users');
1.642     raeburn  7791:     }
                   7792:     my @types;
                   7793:     if (ref($order) eq 'ARRAY') {
                   7794:         @types = @{$order};
                   7795:     }
                   7796:     if (@types == 0) {
                   7797:         if (ref($usertypes) eq 'HASH') {
                   7798:             @types = sort(keys(%{$usertypes}));
                   7799:         }
                   7800:     }
                   7801:     if (keys(%{$usertypes}) > 0) {
                   7802:         $othertitle = &mt('Other users');
                   7803:     }
                   7804:     return ($othertitle,$usertypes,\@types);
                   7805: }
                   7806: 
1.645     raeburn  7807: sub get_institutional_codes {
                   7808:     my ($settings,$allcourses,$LC_code) = @_;
                   7809: # Get complete list of course sections to update
                   7810:     my @currsections = ();
                   7811:     my @currxlists = ();
                   7812:     my $coursecode = $$settings{'internal.coursecode'};
                   7813: 
                   7814:     if ($$settings{'internal.sectionnums'} ne '') {
                   7815:         @currsections = split(/,/,$$settings{'internal.sectionnums'});
                   7816:     }
                   7817: 
                   7818:     if ($$settings{'internal.crosslistings'} ne '') {
                   7819:         @currxlists = split(/,/,$$settings{'internal.crosslistings'});
                   7820:     }
                   7821: 
                   7822:     if (@currxlists > 0) {
                   7823:         foreach (@currxlists) {
                   7824:             if (m/^([^:]+):(\w*)$/) {
                   7825:                 unless (grep/^$1$/,@{$allcourses}) {
                   7826:                     push @{$allcourses},$1;
                   7827:                     $$LC_code{$1} = $2;
                   7828:                 }
                   7829:             }
                   7830:         }
                   7831:     }
                   7832:  
                   7833:     if (@currsections > 0) {
                   7834:         foreach (@currsections) {
                   7835:             if (m/^(\w+):(\w*)$/) {
                   7836:                 my $sec = $coursecode.$1;
                   7837:                 my $lc_sec = $2;
                   7838:                 unless (grep/^$sec$/,@{$allcourses}) {
                   7839:                     push @{$allcourses},$sec;
                   7840:                     $$LC_code{$sec} = $lc_sec;
                   7841:                 }
                   7842:             }
                   7843:         }
                   7844:     }
                   7845:     return;
                   7846: }
                   7847: 
1.112     bowersj2 7848: =pod
                   7849: 
1.780     raeburn  7850: =head1 Slot Helpers
                   7851: 
                   7852: =over 4
                   7853: 
                   7854: =item * sorted_slots()
                   7855: 
                   7856: Sorts an array of slot names in order of slot start time (earliest first). 
                   7857: 
                   7858: Inputs:
                   7859: 
                   7860: =over 4
                   7861: 
                   7862: slotsarr  - Reference to array of unsorted slot names.
                   7863: 
                   7864: slots     - Reference to hash of hash, where outer hash keys are slot names.
                   7865: 
1.549     albertel 7866: =back
                   7867: 
1.780     raeburn  7868: Returns:
                   7869: 
                   7870: =over 4
                   7871: 
                   7872: sorted   - An array of slot names sorted by the start time of the slot.
                   7873: 
                   7874: =back
                   7875: 
                   7876: =back
                   7877: 
                   7878: =cut
                   7879: 
                   7880: 
                   7881: sub sorted_slots {
                   7882:     my ($slotsarr,$slots) = @_;
                   7883:     my @sorted;
                   7884:     if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
                   7885:         @sorted =
                   7886:             sort {
                   7887:                      if (ref($slots->{$a}) && ref($slots->{$b})) {
                   7888:                          return $slots->{$a}{'starttime'} <=> $slots->{$b}{'starttime'}
                   7889:                      }
                   7890:                      if (ref($slots->{$a})) { return -1;}
                   7891:                      if (ref($slots->{$b})) { return 1;}
                   7892:                      return 0;
                   7893:                  } @{$slotsarr};
                   7894:     }
                   7895:     return @sorted;
                   7896: }
                   7897: 
                   7898: 
                   7899: =pod
                   7900: 
1.549     albertel 7901: =head1 HTTP Helpers
                   7902: 
                   7903: =over 4
                   7904: 
1.648     raeburn  7905: =item * &get_unprocessed_cgi($query,$possible_names)
1.112     bowersj2 7906: 
1.258     albertel 7907: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112     bowersj2 7908: $query.  The parameters listed in $possible_names (an array reference),
1.258     albertel 7909: will be set in $env{'form.name'} if they do not already exist.
1.112     bowersj2 7910: 
                   7911: Typically called with $ENV{'QUERY_STRING'} as the first parameter.  
                   7912: $possible_names is an ref to an array of form element names.  As an example:
                   7913: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258     albertel 7914: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112     bowersj2 7915: 
                   7916: =cut
1.1       albertel 7917: 
1.6       albertel 7918: sub get_unprocessed_cgi {
1.25      albertel 7919:   my ($query,$possible_names)= @_;
1.26      matthew  7920:   # $Apache::lonxml::debug=1;
1.356     albertel 7921:   foreach my $pair (split(/&/,$query)) {
                   7922:     my ($name, $value) = split(/=/,$pair);
1.369     www      7923:     $name = &unescape($name);
1.25      albertel 7924:     if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
                   7925:       $value =~ tr/+/ /;
                   7926:       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258     albertel 7927:       unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25      albertel 7928:     }
1.16      harris41 7929:   }
1.6       albertel 7930: }
                   7931: 
1.112     bowersj2 7932: =pod
                   7933: 
1.648     raeburn  7934: =item * &cacheheader() 
1.112     bowersj2 7935: 
                   7936: returns cache-controlling header code
                   7937: 
                   7938: =cut
                   7939: 
1.7       albertel 7940: sub cacheheader {
1.258     albertel 7941:     unless ($env{'request.method'} eq 'GET') { return ''; }
1.216     albertel 7942:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
                   7943:     my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7       albertel 7944:                 <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
                   7945:                 <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216     albertel 7946:     return $output;
1.7       albertel 7947: }
                   7948: 
1.112     bowersj2 7949: =pod
                   7950: 
1.648     raeburn  7951: =item * &no_cache($r) 
1.112     bowersj2 7952: 
                   7953: specifies header code to not have cache
                   7954: 
                   7955: =cut
                   7956: 
1.9       albertel 7957: sub no_cache {
1.216     albertel 7958:     my ($r) = @_;
                   7959:     if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258     albertel 7960: 	$env{'request.method'} ne 'GET') { return ''; }
1.216     albertel 7961:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
                   7962:     $r->no_cache(1);
                   7963:     $r->header_out("Expires" => $date);
                   7964:     $r->header_out("Pragma" => "no-cache");
1.123     www      7965: }
                   7966: 
                   7967: sub content_type {
1.181     albertel 7968:     my ($r,$type,$charset) = @_;
1.299     foxr     7969:     if ($r) {
                   7970: 	#  Note that printout.pl calls this with undef for $r.
                   7971: 	&no_cache($r);
                   7972:     }
1.258     albertel 7973:     if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181     albertel 7974:     unless ($charset) {
                   7975: 	$charset=&Apache::lonlocal::current_encoding;
                   7976:     }
                   7977:     if ($charset) { $type.='; charset='.$charset; }
                   7978:     if ($r) {
                   7979: 	$r->content_type($type);
                   7980:     } else {
                   7981: 	print("Content-type: $type\n\n");
                   7982:     }
1.9       albertel 7983: }
1.25      albertel 7984: 
1.112     bowersj2 7985: =pod
                   7986: 
1.648     raeburn  7987: =item * &add_to_env($name,$value) 
1.112     bowersj2 7988: 
1.258     albertel 7989: adds $name to the %env hash with value
1.112     bowersj2 7990: $value, if $name already exists, the entry is converted to an array
                   7991: reference and $value is added to the array.
                   7992: 
                   7993: =cut
                   7994: 
1.25      albertel 7995: sub add_to_env {
                   7996:   my ($name,$value)=@_;
1.258     albertel 7997:   if (defined($env{$name})) {
                   7998:     if (ref($env{$name})) {
1.25      albertel 7999:       #already have multiple values
1.258     albertel 8000:       push(@{ $env{$name} },$value);
1.25      albertel 8001:     } else {
                   8002:       #first time seeing multiple values, convert hash entry to an arrayref
1.258     albertel 8003:       my $first=$env{$name};
                   8004:       undef($env{$name});
                   8005:       push(@{ $env{$name} },$first,$value);
1.25      albertel 8006:     }
                   8007:   } else {
1.258     albertel 8008:     $env{$name}=$value;
1.25      albertel 8009:   }
1.31      albertel 8010: }
1.149     albertel 8011: 
                   8012: =pod
                   8013: 
1.648     raeburn  8014: =item * &get_env_multiple($name) 
1.149     albertel 8015: 
1.258     albertel 8016: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149     albertel 8017: values may be defined and end up as an array ref.
                   8018: 
                   8019: returns an array of values
                   8020: 
                   8021: =cut
                   8022: 
                   8023: sub get_env_multiple {
                   8024:     my ($name) = @_;
                   8025:     my @values;
1.258     albertel 8026:     if (defined($env{$name})) {
1.149     albertel 8027:         # exists is it an array
1.258     albertel 8028:         if (ref($env{$name})) {
                   8029:             @values=@{ $env{$name} };
1.149     albertel 8030:         } else {
1.258     albertel 8031:             $values[0]=$env{$name};
1.149     albertel 8032:         }
                   8033:     }
                   8034:     return(@values);
                   8035: }
                   8036: 
1.660     raeburn  8037: sub ask_for_embedded_content {
                   8038:     my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
                   8039:     my $upload_output = '
                   8040:    <form name="upload_embedded" action="'.$actionurl.'"
                   8041:                   method="post" enctype="multipart/form-data">';
                   8042:     $upload_output .= $state;
1.661     raeburn  8043:     $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660     raeburn  8044: 
                   8045:     my $num = 0;
                   8046:     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
                   8047:         $upload_output .= &start_data_table_row().
                   8048:             '<td>'.$embed_file.'</td><td>';
                   8049:         if ($args->{'ignore_remote_references'}
                   8050:             && $embed_file =~ m{^\w+://}) {
                   8051:             $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
                   8052:         } elsif ($args->{'error_on_invalid_names'}
                   8053:             && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
                   8054: 
                   8055:             $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
                   8056: 
                   8057:         } else {
                   8058:             $upload_output .='
1.661     raeburn  8059:            <input name="embedded_item_'.$num.'" type="file" value="" />
1.660     raeburn  8060:            <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
                   8061:             my $attrib = join(':',@{$$allfiles{$embed_file}});
                   8062:             $upload_output .=
                   8063:                 "\n\t\t".
                   8064:                 '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
                   8065:                 $attrib.'" />';
                   8066:             if (exists($$codebase{$embed_file})) {
                   8067:                 $upload_output .=
                   8068:                     "\n\t\t".
                   8069:                     '<input name="codebase_'.$num.'" type="hidden" value="'.
                   8070:                     &escape($$codebase{$embed_file}).'" />';
                   8071:             }
                   8072:         }
                   8073:         $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
                   8074:         $num++;
                   8075:     }
                   8076:     $upload_output .= &Apache::loncommon::end_data_table().'<br />
                   8077:    <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
                   8078:    <input type ="submit" value="'.&mt('Upload Listed Files').'" />
                   8079:    '.&mt('(only files for which a location has been provided will be uploaded)').'
                   8080:    </form>';
                   8081:     return $upload_output;
                   8082: }
                   8083: 
1.661     raeburn  8084: sub upload_embedded {
                   8085:     my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
                   8086:         $current_disk_usage) = @_;
                   8087:     my $output;
                   8088:     for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
                   8089:         next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
                   8090:         my $orig_uploaded_filename =
                   8091:             $env{'form.embedded_item_'.$i.'.filename'};
                   8092: 
                   8093:         $env{'form.embedded_orig_'.$i} =
                   8094:             &unescape($env{'form.embedded_orig_'.$i});
                   8095:         my ($path,$fname) =
                   8096:             ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
                   8097:         # no path, whole string is fname
                   8098:         if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
                   8099: 
                   8100:         $path = $env{'form.currentpath'}.$path;
                   8101:         $fname = &Apache::lonnet::clean_filename($fname);
                   8102:         # See if there is anything left
                   8103:         next if ($fname eq '');
                   8104: 
                   8105:         # Check if file already exists as a file or directory.
                   8106:         my ($state,$msg);
                   8107:         if ($context eq 'portfolio') {
                   8108:             my $port_path = $dirpath;
                   8109:             if ($group ne '') {
                   8110:                 $port_path = "groups/$group/$port_path";
                   8111:             }
                   8112:             ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
                   8113:                                               $dir_root,$port_path,$disk_quota,
                   8114:                                               $current_disk_usage,$uname,$udom);
                   8115:             if ($state eq 'will_exceed_quota'
                   8116:                 || $state eq 'file_locked'
                   8117:                 || $state eq 'file_exists' ) {
                   8118:                 $output .= $msg;
                   8119:                 next;
                   8120:             }
                   8121:         } elsif (($context eq 'author') || ($context eq 'testbank')) {
                   8122:             ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
                   8123:             if ($state eq 'exists') {
                   8124:                 $output .= $msg;
                   8125:                 next;
                   8126:             }
                   8127:         }
                   8128:         # Check if extension is valid
                   8129:         if (($fname =~ /\.(\w+)$/) &&
                   8130:             (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   8131:             $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
                   8132:             next;
                   8133:         } elsif (($fname =~ /\.(\w+)$/) &&
                   8134:                  (!defined(&Apache::loncommon::fileembstyle($1)))) {
                   8135:             $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   8136:             next;
                   8137:         } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
                   8138:             $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
                   8139:             next;
                   8140:         }
                   8141: 
                   8142:         $env{'form.embedded_item_'.$i.'.filename'}=$fname;
                   8143:         if ($context eq 'portfolio') {
                   8144:             my $result=
                   8145:                 &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
                   8146:                                                 $dirpath.$path);
                   8147:             if ($result !~ m|^/uploaded/|) {
                   8148:                 $output .= '<span class="LC_error">'
                   8149:                       .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
                   8150:                            ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
                   8151:                       .'</span><br />';
                   8152:                 next;
                   8153:             } else {
                   8154:                 $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
                   8155:                            $path.$fname.'</span>').'</p>';     
                   8156:             }
                   8157:         } else {
                   8158: # Save the file
                   8159:             my $target = $env{'form.embedded_item_'.$i};
                   8160:             my $fullpath = $dir_root.$dirpath.'/'.$path;
                   8161:             my $dest = $fullpath.$fname;
                   8162:             my $url = $url_root.$dirpath.'/'.$path.$fname;
                   8163:             my @parts=split(/\//,$fullpath);
                   8164:             my $count;
                   8165:             my $filepath = $dir_root;
                   8166:             for ($count=4;$count<=$#parts;$count++) {
                   8167:                 $filepath .= "/$parts[$count]";
                   8168:                 if ((-e $filepath)!=1) {
                   8169:                     mkdir($filepath,0770);
                   8170:                 }
                   8171:             }
                   8172:             my $fh;
                   8173:             if (!open($fh,'>'.$dest)) {
                   8174:                 &Apache::lonnet::logthis('Failed to create '.$dest);
                   8175:                 $output .= '<span class="LC_error">'.
                   8176:                            &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   8177:                            '</span><br />';
                   8178:             } else {
                   8179:                 if (!print $fh $env{'form.embedded_item_'.$i}) {
                   8180:                     &Apache::lonnet::logthis('Failed to write to '.$dest);
                   8181:                     $output .= '<span class="LC_error">'.
                   8182:                               &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   8183:                               '</span><br />';
                   8184:                 } else {
                   8185:                     if ($context eq 'testbank') {
                   8186:                         $output .= &mt('Embedded file uploaded successfully:').
                   8187:                                    '&nbsp;<a href="'.$url.'">'.
                   8188:                                    $orig_uploaded_filename.'</a><br />';
                   8189:                     } else {
1.705     tempelho 8190:                         $output .= '<span class=\"LC_fontsize_large\">'.
1.661     raeburn  8191:                                    &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705     tempelho 8192:                                    $orig_uploaded_filename.'</a>').'</span><br />';
1.661     raeburn  8193:                     }
                   8194:                 }
                   8195:                 close($fh);
                   8196:             }
                   8197:         }
                   8198:     }
                   8199:     return $output;
                   8200: }
                   8201: 
                   8202: sub check_for_existing {
                   8203:     my ($path,$fname,$element) = @_;
                   8204:     my ($state,$msg);
                   8205:     if (-d $path.'/'.$fname) {
                   8206:         $state = 'exists';
                   8207:         $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   8208:     } elsif (-e $path.'/'.$fname) {
                   8209:         $state = 'exists';
                   8210:         $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   8211:     }
                   8212:     if ($state eq 'exists') {
                   8213:         $msg = '<span class="LC_error">'.$msg.'</span><br />';
                   8214:     }
                   8215:     return ($state,$msg);
                   8216: }
                   8217: 
                   8218: sub check_for_upload {
                   8219:     my ($path,$fname,$group,$element,$portfolio_root,$port_path,
                   8220:         $disk_quota,$current_disk_usage,$uname,$udom) = @_;
                   8221:     my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
                   8222:     my $getpropath = 1;
                   8223:     my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
                   8224:                                             $getpropath);
                   8225:     my $found_file = 0;
                   8226:     my $locked_file = 0;
                   8227:     foreach my $line (@dir_list) {
                   8228:         my ($file_name)=split(/\&/,$line,2);
                   8229:         if ($file_name eq $fname){
                   8230:             $file_name = $path.$file_name;
                   8231:             if ($group ne '') {
                   8232:                 $file_name = $group.$file_name;
                   8233:             }
                   8234:             $found_file = 1;
                   8235:             if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
                   8236:                 $locked_file = 1;
                   8237:             }
                   8238:         }
                   8239:     }
                   8240:     if (($current_disk_usage + $filesize) > $disk_quota){
                   8241:         my $msg = '<span class="LC_error">'.
                   8242:                 &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
                   8243:                   '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
                   8244:         return ('will_exceed_quota',$msg);
                   8245:     } elsif ($found_file) {
                   8246:         if ($locked_file) {
                   8247:             my $msg = '<span class="LC_error">';
                   8248:             $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>');
                   8249:             $msg .= '</span><br />';
                   8250:             $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
                   8251:             return ('file_locked',$msg);
                   8252:         } else {
                   8253:             my $msg = '<span class="LC_error">';
                   8254:             $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'});
                   8255:             $msg .= '</span>';
                   8256:             $msg .= '<br />';
                   8257:             $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
                   8258:             return ('file_exists',$msg);
                   8259:         }
                   8260:     }
                   8261: }
                   8262: 
1.31      albertel 8263: 
1.41      ng       8264: =pod
1.45      matthew  8265: 
1.464     albertel 8266: =back
1.41      ng       8267: 
1.112     bowersj2 8268: =head1 CSV Upload/Handling functions
1.38      albertel 8269: 
1.41      ng       8270: =over 4
                   8271: 
1.648     raeburn  8272: =item * &upfile_store($r)
1.41      ng       8273: 
                   8274: Store uploaded file, $r should be the HTTP Request object,
1.258     albertel 8275: needs $env{'form.upfile'}
1.41      ng       8276: returns $datatoken to be put into hidden field
                   8277: 
                   8278: =cut
1.31      albertel 8279: 
                   8280: sub upfile_store {
                   8281:     my $r=shift;
1.258     albertel 8282:     $env{'form.upfile'}=~s/\r/\n/gs;
                   8283:     $env{'form.upfile'}=~s/\f/\n/gs;
                   8284:     $env{'form.upfile'}=~s/\n+/\n/gs;
                   8285:     $env{'form.upfile'}=~s/\n+$//gs;
1.31      albertel 8286: 
1.258     albertel 8287:     my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
                   8288: 	'_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31      albertel 8289:     {
1.158     raeburn  8290:         my $datafile = $r->dir_config('lonDaemons').
                   8291:                            '/tmp/'.$datatoken.'.tmp';
                   8292:         if ( open(my $fh,">$datafile") ) {
1.258     albertel 8293:             print $fh $env{'form.upfile'};
1.158     raeburn  8294:             close($fh);
                   8295:         }
1.31      albertel 8296:     }
                   8297:     return $datatoken;
                   8298: }
                   8299: 
1.56      matthew  8300: =pod
                   8301: 
1.648     raeburn  8302: =item * &load_tmp_file($r)
1.41      ng       8303: 
                   8304: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258     albertel 8305: needs $env{'form.datatoken'},
                   8306: sets $env{'form.upfile'} to the contents of the file
1.41      ng       8307: 
                   8308: =cut
1.31      albertel 8309: 
                   8310: sub load_tmp_file {
                   8311:     my $r=shift;
                   8312:     my @studentdata=();
                   8313:     {
1.158     raeburn  8314:         my $studentfile = $r->dir_config('lonDaemons').
1.258     albertel 8315:                               '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158     raeburn  8316:         if ( open(my $fh,"<$studentfile") ) {
                   8317:             @studentdata=<$fh>;
                   8318:             close($fh);
                   8319:         }
1.31      albertel 8320:     }
1.258     albertel 8321:     $env{'form.upfile'}=join('',@studentdata);
1.31      albertel 8322: }
                   8323: 
1.56      matthew  8324: =pod
                   8325: 
1.648     raeburn  8326: =item * &upfile_record_sep()
1.41      ng       8327: 
                   8328: Separate uploaded file into records
                   8329: returns array of records,
1.258     albertel 8330: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41      ng       8331: 
                   8332: =cut
1.31      albertel 8333: 
                   8334: sub upfile_record_sep {
1.258     albertel 8335:     if ($env{'form.upfiletype'} eq 'xml') {
1.31      albertel 8336:     } else {
1.248     albertel 8337: 	my @records;
1.258     albertel 8338: 	foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248     albertel 8339: 	    if ($line=~/^\s*$/) { next; }
                   8340: 	    push(@records,$line);
                   8341: 	}
                   8342: 	return @records;
1.31      albertel 8343:     }
                   8344: }
                   8345: 
1.56      matthew  8346: =pod
                   8347: 
1.648     raeburn  8348: =item * &record_sep($record)
1.41      ng       8349: 
1.258     albertel 8350: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41      ng       8351: 
                   8352: =cut
                   8353: 
1.263     www      8354: sub takeleft {
                   8355:     my $index=shift;
                   8356:     return substr('0000'.$index,-4,4);
                   8357: }
                   8358: 
1.31      albertel 8359: sub record_sep {
                   8360:     my $record=shift;
                   8361:     my %components=();
1.258     albertel 8362:     if ($env{'form.upfiletype'} eq 'xml') {
                   8363:     } elsif ($env{'form.upfiletype'} eq 'space') {
1.31      albertel 8364:         my $i=0;
1.356     albertel 8365:         foreach my $field (split(/\s+/,$record)) {
1.31      albertel 8366:             $field=~s/^(\"|\')//;
                   8367:             $field=~s/(\"|\')$//;
1.263     www      8368:             $components{&takeleft($i)}=$field;
1.31      albertel 8369:             $i++;
                   8370:         }
1.258     albertel 8371:     } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31      albertel 8372:         my $i=0;
1.356     albertel 8373:         foreach my $field (split(/\t/,$record)) {
1.31      albertel 8374:             $field=~s/^(\"|\')//;
                   8375:             $field=~s/(\"|\')$//;
1.263     www      8376:             $components{&takeleft($i)}=$field;
1.31      albertel 8377:             $i++;
                   8378:         }
                   8379:     } else {
1.561     www      8380:         my $separator=',';
1.480     banghart 8381:         if ($env{'form.upfiletype'} eq 'semisv') {
1.561     www      8382:             $separator=';';
1.480     banghart 8383:         }
1.31      albertel 8384:         my $i=0;
1.561     www      8385: # the character we are looking for to indicate the end of a quote or a record 
                   8386:         my $looking_for=$separator;
                   8387: # do not add the characters to the fields
                   8388:         my $ignore=0;
                   8389: # we just encountered a separator (or the beginning of the record)
                   8390:         my $just_found_separator=1;
                   8391: # store the field we are working on here
                   8392:         my $field='';
                   8393: # work our way through all characters in record
                   8394:         foreach my $character ($record=~/(.)/g) {
                   8395:             if ($character eq $looking_for) {
                   8396:                if ($character ne $separator) {
                   8397: # Found the end of a quote, again looking for separator
                   8398:                   $looking_for=$separator;
                   8399:                   $ignore=1;
                   8400:                } else {
                   8401: # Found a separator, store away what we got
                   8402:                   $components{&takeleft($i)}=$field;
                   8403: 	          $i++;
                   8404:                   $just_found_separator=1;
                   8405:                   $ignore=0;
                   8406:                   $field='';
                   8407:                }
                   8408:                next;
                   8409:             }
                   8410: # single or double quotation marks after a separator indicate beginning of a quote
                   8411: # we are now looking for the end of the quote and need to ignore separators
                   8412:             if ((($character eq '"') || ($character eq "'")) && ($just_found_separator))  {
                   8413:                $looking_for=$character;
                   8414:                next;
                   8415:             }
                   8416: # ignore would be true after we reached the end of a quote
                   8417:             if ($ignore) { next; }
                   8418:             if (($just_found_separator) && ($character=~/\s/)) { next; }
                   8419:             $field.=$character;
                   8420:             $just_found_separator=0; 
1.31      albertel 8421:         }
1.561     www      8422: # catch the very last entry, since we never encountered the separator
                   8423:         $components{&takeleft($i)}=$field;
1.31      albertel 8424:     }
                   8425:     return %components;
                   8426: }
                   8427: 
1.144     matthew  8428: ######################################################
                   8429: ######################################################
                   8430: 
1.56      matthew  8431: =pod
                   8432: 
1.648     raeburn  8433: =item * &upfile_select_html()
1.41      ng       8434: 
1.144     matthew  8435: Return HTML code to select a file from the users machine and specify 
                   8436: the file type.
1.41      ng       8437: 
                   8438: =cut
                   8439: 
1.144     matthew  8440: ######################################################
                   8441: ######################################################
1.31      albertel 8442: sub upfile_select_html {
1.144     matthew  8443:     my %Types = (
                   8444:                  csv   => &mt('CSV (comma separated values, spreadsheet)'),
1.480     banghart 8445:                  semisv => &mt('Semicolon separated values'),
1.144     matthew  8446:                  space => &mt('Space separated'),
                   8447:                  tab   => &mt('Tabulator separated'),
                   8448: #                 xml   => &mt('HTML/XML'),
                   8449:                  );
                   8450:     my $Str = '<input type="file" name="upfile" size="50" />'.
1.727     riegler  8451:         '<br />'.&mt('Type').': <select name="upfiletype">';
1.144     matthew  8452:     foreach my $type (sort(keys(%Types))) {
                   8453:         $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
                   8454:     }
                   8455:     $Str .= "</select>\n";
                   8456:     return $Str;
1.31      albertel 8457: }
                   8458: 
1.301     albertel 8459: sub get_samples {
                   8460:     my ($records,$toget) = @_;
                   8461:     my @samples=({});
                   8462:     my $got=0;
                   8463:     foreach my $rec (@$records) {
                   8464: 	my %temp = &record_sep($rec);
                   8465: 	if (! grep(/\S/, values(%temp))) { next; }
                   8466: 	if (%temp) {
                   8467: 	    $samples[$got]=\%temp;
                   8468: 	    $got++;
                   8469: 	    if ($got == $toget) { last; }
                   8470: 	}
                   8471:     }
                   8472:     return \@samples;
                   8473: }
                   8474: 
1.144     matthew  8475: ######################################################
                   8476: ######################################################
                   8477: 
1.56      matthew  8478: =pod
                   8479: 
1.648     raeburn  8480: =item * &csv_print_samples($r,$records)
1.41      ng       8481: 
                   8482: Prints a table of sample values from each column uploaded $r is an
                   8483: Apache Request ref, $records is an arrayref from
                   8484: &Apache::loncommon::upfile_record_sep
                   8485: 
                   8486: =cut
                   8487: 
1.144     matthew  8488: ######################################################
                   8489: ######################################################
1.31      albertel 8490: sub csv_print_samples {
                   8491:     my ($r,$records) = @_;
1.662     bisitz   8492:     my $samples = &get_samples($records,5);
1.301     albertel 8493: 
1.594     raeburn  8494:     $r->print(&mt('Samples').'<br />'.&start_data_table().
                   8495:               &start_data_table_header_row());
1.356     albertel 8496:     foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) { 
                   8497:         $r->print('<th>'.&mt('Column&nbsp;[_1]',($sample+1)).'</th>'); }
1.594     raeburn  8498:     $r->print(&end_data_table_header_row());
1.301     albertel 8499:     foreach my $hash (@$samples) {
1.594     raeburn  8500: 	$r->print(&start_data_table_row());
1.356     albertel 8501: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31      albertel 8502: 	    $r->print('<td>');
1.356     albertel 8503: 	    if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31      albertel 8504: 	    $r->print('</td>');
                   8505: 	}
1.594     raeburn  8506: 	$r->print(&end_data_table_row());
1.31      albertel 8507:     }
1.594     raeburn  8508:     $r->print(&end_data_table().'<br />'."\n");
1.31      albertel 8509: }
                   8510: 
1.144     matthew  8511: ######################################################
                   8512: ######################################################
                   8513: 
1.56      matthew  8514: =pod
                   8515: 
1.648     raeburn  8516: =item * &csv_print_select_table($r,$records,$d)
1.41      ng       8517: 
                   8518: Prints a table to create associations between values and table columns.
1.144     matthew  8519: 
1.41      ng       8520: $r is an Apache Request ref,
                   8521: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174     matthew  8522: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41      ng       8523: 
                   8524: =cut
                   8525: 
1.144     matthew  8526: ######################################################
                   8527: ######################################################
1.31      albertel 8528: sub csv_print_select_table {
                   8529:     my ($r,$records,$d) = @_;
1.301     albertel 8530:     my $i=0;
                   8531:     my $samples = &get_samples($records,1);
1.144     matthew  8532:     $r->print(&mt('Associate columns with student attributes.')."\n".
1.594     raeburn  8533: 	      &start_data_table().&start_data_table_header_row().
1.144     matthew  8534:               '<th>'.&mt('Attribute').'</th>'.
1.594     raeburn  8535:               '<th>'.&mt('Column').'</th>'.
                   8536:               &end_data_table_header_row()."\n");
1.356     albertel 8537:     foreach my $array_ref (@$d) {
                   8538: 	my ($value,$display,$defaultcol)=@{ $array_ref };
1.729     raeburn  8539: 	$r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31      albertel 8540: 
                   8541: 	$r->print('<td><select name=f'.$i.
1.32      matthew  8542: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.31      albertel 8543: 	$r->print('<option value="none"></option>');
1.356     albertel 8544: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
                   8545: 	    $r->print('<option value="'.$sample.'"'.
                   8546:                       ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662     bisitz   8547:                       '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31      albertel 8548: 	}
1.594     raeburn  8549: 	$r->print('</select></td>'.&end_data_table_row()."\n");
1.31      albertel 8550: 	$i++;
                   8551:     }
1.594     raeburn  8552:     $r->print(&end_data_table());
1.31      albertel 8553:     $i--;
                   8554:     return $i;
                   8555: }
1.56      matthew  8556: 
1.144     matthew  8557: ######################################################
                   8558: ######################################################
                   8559: 
1.56      matthew  8560: =pod
1.31      albertel 8561: 
1.648     raeburn  8562: =item * &csv_samples_select_table($r,$records,$d)
1.41      ng       8563: 
                   8564: Prints a table of sample values from the upload and can make associate samples to internal names.
                   8565: 
                   8566: $r is an Apache Request ref,
                   8567: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
                   8568: $d is an array of 2 element arrays (internal name, displayed name)
                   8569: 
                   8570: =cut
                   8571: 
1.144     matthew  8572: ######################################################
                   8573: ######################################################
1.31      albertel 8574: sub csv_samples_select_table {
                   8575:     my ($r,$records,$d) = @_;
                   8576:     my $i=0;
1.144     matthew  8577:     #
1.662     bisitz   8578:     my $max_samples = 5;
                   8579:     my $samples = &get_samples($records,$max_samples);
1.594     raeburn  8580:     $r->print(&start_data_table().
                   8581:               &start_data_table_header_row().'<th>'.
                   8582:               &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
                   8583:               &end_data_table_header_row());
1.301     albertel 8584: 
                   8585:     foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594     raeburn  8586: 	$r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32      matthew  8587: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.301     albertel 8588: 	foreach my $option (@$d) {
                   8589: 	    my ($value,$display,$defaultcol)=@{ $option };
1.174     matthew  8590: 	    $r->print('<option value="'.$value.'"'.
1.253     albertel 8591:                       ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174     matthew  8592:                       $display.'</option>');
1.31      albertel 8593: 	}
                   8594: 	$r->print('</select></td><td>');
1.662     bisitz   8595: 	foreach my $line (0..($max_samples-1)) {
1.301     albertel 8596: 	    if (defined($samples->[$line]{$key})) { 
                   8597: 		$r->print($samples->[$line]{$key}."<br />\n"); 
                   8598: 	    }
                   8599: 	}
1.594     raeburn  8600: 	$r->print('</td>'.&end_data_table_row());
1.31      albertel 8601: 	$i++;
                   8602:     }
1.594     raeburn  8603:     $r->print(&end_data_table());
1.31      albertel 8604:     $i--;
                   8605:     return($i);
1.115     matthew  8606: }
                   8607: 
1.144     matthew  8608: ######################################################
                   8609: ######################################################
                   8610: 
1.115     matthew  8611: =pod
                   8612: 
1.648     raeburn  8613: =item * &clean_excel_name($name)
1.115     matthew  8614: 
                   8615: Returns a replacement for $name which does not contain any illegal characters.
                   8616: 
                   8617: =cut
                   8618: 
1.144     matthew  8619: ######################################################
                   8620: ######################################################
1.115     matthew  8621: sub clean_excel_name {
                   8622:     my ($name) = @_;
                   8623:     $name =~ s/[:\*\?\/\\]//g;
                   8624:     if (length($name) > 31) {
                   8625:         $name = substr($name,0,31);
                   8626:     }
                   8627:     return $name;
1.25      albertel 8628: }
1.84      albertel 8629: 
1.85      albertel 8630: =pod
                   8631: 
1.648     raeburn  8632: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85      albertel 8633: 
                   8634: Returns either 1 or undef
                   8635: 
                   8636: 1 if the part is to be hidden, undef if it is to be shown
                   8637: 
                   8638: Arguments are:
                   8639: 
                   8640: $id the id of the part to be checked
                   8641: $symb, optional the symb of the resource to check
                   8642: $udom, optional the domain of the user to check for
                   8643: $uname, optional the username of the user to check for
                   8644: 
                   8645: =cut
1.84      albertel 8646: 
                   8647: sub check_if_partid_hidden {
                   8648:     my ($id,$symb,$udom,$uname) = @_;
1.133     albertel 8649:     my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84      albertel 8650: 					 $symb,$udom,$uname);
1.141     albertel 8651:     my $truth=1;
                   8652:     #if the string starts with !, then the list is the list to show not hide
                   8653:     if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84      albertel 8654:     my @hiddenlist=split(/,/,$hiddenparts);
                   8655:     foreach my $checkid (@hiddenlist) {
1.141     albertel 8656: 	if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84      albertel 8657:     }
1.141     albertel 8658:     return !$truth;
1.84      albertel 8659: }
1.127     matthew  8660: 
1.138     matthew  8661: 
                   8662: ############################################################
                   8663: ############################################################
                   8664: 
                   8665: =pod
                   8666: 
1.157     matthew  8667: =back 
                   8668: 
1.138     matthew  8669: =head1 cgi-bin script and graphing routines
                   8670: 
1.157     matthew  8671: =over 4
                   8672: 
1.648     raeburn  8673: =item * &get_cgi_id()
1.138     matthew  8674: 
                   8675: Inputs: none
                   8676: 
                   8677: Returns an id which can be used to pass environment variables
                   8678: to various cgi-bin scripts.  These environment variables will
                   8679: be removed from the users environment after a given time by
                   8680: the routine &Apache::lonnet::transfer_profile_to_env.
                   8681: 
                   8682: =cut
                   8683: 
                   8684: ############################################################
                   8685: ############################################################
1.152     albertel 8686: my $uniq=0;
1.136     matthew  8687: sub get_cgi_id {
1.154     albertel 8688:     $uniq=($uniq+1)%100000;
1.280     albertel 8689:     return (time.'_'.$$.'_'.$uniq);
1.136     matthew  8690: }
                   8691: 
1.127     matthew  8692: ############################################################
                   8693: ############################################################
                   8694: 
                   8695: =pod
                   8696: 
1.648     raeburn  8697: =item * &DrawBarGraph()
1.127     matthew  8698: 
1.138     matthew  8699: Facilitates the plotting of data in a (stacked) bar graph.
                   8700: Puts plot definition data into the users environment in order for 
                   8701: graph.png to plot it.  Returns an <img> tag for the plot.
                   8702: The bars on the plot are labeled '1','2',...,'n'.
                   8703: 
                   8704: Inputs:
                   8705: 
                   8706: =over 4
                   8707: 
                   8708: =item $Title: string, the title of the plot
                   8709: 
                   8710: =item $xlabel: string, text describing the X-axis of the plot
                   8711: 
                   8712: =item $ylabel: string, text describing the Y-axis of the plot
                   8713: 
                   8714: =item $Max: scalar, the maximum Y value to use in the plot
                   8715: If $Max is < any data point, the graph will not be rendered.
                   8716: 
1.140     matthew  8717: =item $colors: array ref holding the colors to be used for the data sets when
1.138     matthew  8718: they are plotted.  If undefined, default values will be used.
                   8719: 
1.178     matthew  8720: =item $labels: array ref holding the labels to use on the x-axis for the bars.
                   8721: 
1.138     matthew  8722: =item @Values: An array of array references.  Each array reference holds data
                   8723: to be plotted in a stacked bar chart.
                   8724: 
1.239     matthew  8725: =item If the final element of @Values is a hash reference the key/value
                   8726: pairs will be added to the graph definition.
                   8727: 
1.138     matthew  8728: =back
                   8729: 
                   8730: Returns:
                   8731: 
                   8732: An <img> tag which references graph.png and the appropriate identifying
                   8733: information for the plot.
                   8734: 
1.127     matthew  8735: =cut
                   8736: 
                   8737: ############################################################
                   8738: ############################################################
1.134     matthew  8739: sub DrawBarGraph {
1.178     matthew  8740:     my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134     matthew  8741:     #
                   8742:     if (! defined($colors)) {
                   8743:         $colors = ['#33ff00', 
                   8744:                   '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
                   8745:                   '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
                   8746:                   ]; 
                   8747:     }
1.228     matthew  8748:     my $extra_settings = {};
                   8749:     if (ref($Values[-1]) eq 'HASH') {
                   8750:         $extra_settings = pop(@Values);
                   8751:     }
1.127     matthew  8752:     #
1.136     matthew  8753:     my $identifier = &get_cgi_id();
                   8754:     my $id = 'cgi.'.$identifier;        
1.129     matthew  8755:     if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127     matthew  8756:         return '';
                   8757:     }
1.225     matthew  8758:     #
                   8759:     my @Labels;
                   8760:     if (defined($labels)) {
                   8761:         @Labels = @$labels;
                   8762:     } else {
                   8763:         for (my $i=0;$i<@{$Values[0]};$i++) {
                   8764:             push (@Labels,$i+1);
                   8765:         }
                   8766:     }
                   8767:     #
1.129     matthew  8768:     my $NumBars = scalar(@{$Values[0]});
1.225     matthew  8769:     if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129     matthew  8770:     my %ValuesHash;
                   8771:     my $NumSets=1;
                   8772:     foreach my $array (@Values) {
                   8773:         next if (! ref($array));
1.136     matthew  8774:         $ValuesHash{$id.'.data.'.$NumSets++} = 
1.132     matthew  8775:             join(',',@$array);
1.129     matthew  8776:     }
1.127     matthew  8777:     #
1.136     matthew  8778:     my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225     matthew  8779:     if ($NumBars < 3) {
                   8780:         $width = 120+$NumBars*32;
1.220     matthew  8781:         $xskip = 1;
1.225     matthew  8782:         $bar_width = 30;
                   8783:     } elsif ($NumBars < 5) {
                   8784:         $width = 120+$NumBars*20;
                   8785:         $xskip = 1;
                   8786:         $bar_width = 20;
1.220     matthew  8787:     } elsif ($NumBars < 10) {
1.136     matthew  8788:         $width = 120+$NumBars*15;
                   8789:         $xskip = 1;
                   8790:         $bar_width = 15;
                   8791:     } elsif ($NumBars <= 25) {
                   8792:         $width = 120+$NumBars*11;
                   8793:         $xskip = 5;
                   8794:         $bar_width = 8;
                   8795:     } elsif ($NumBars <= 50) {
                   8796:         $width = 120+$NumBars*8;
                   8797:         $xskip = 5;
                   8798:         $bar_width = 4;
                   8799:     } else {
                   8800:         $width = 120+$NumBars*8;
                   8801:         $xskip = 5;
                   8802:         $bar_width = 4;
                   8803:     }
                   8804:     #
1.137     matthew  8805:     $Max = 1 if ($Max < 1);
                   8806:     if ( int($Max) < $Max ) {
                   8807:         $Max++;
                   8808:         $Max = int($Max);
                   8809:     }
1.127     matthew  8810:     $Title  = '' if (! defined($Title));
                   8811:     $xlabel = '' if (! defined($xlabel));
                   8812:     $ylabel = '' if (! defined($ylabel));
1.369     www      8813:     $ValuesHash{$id.'.title'}    = &escape($Title);
                   8814:     $ValuesHash{$id.'.xlabel'}   = &escape($xlabel);
                   8815:     $ValuesHash{$id.'.ylabel'}   = &escape($ylabel);
1.137     matthew  8816:     $ValuesHash{$id.'.y_max_value'} = $Max;
1.136     matthew  8817:     $ValuesHash{$id.'.NumBars'}  = $NumBars;
                   8818:     $ValuesHash{$id.'.NumSets'}  = $NumSets;
                   8819:     $ValuesHash{$id.'.PlotType'} = 'bar';
                   8820:     $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8821:     $ValuesHash{$id.'.height'}   = $height;
                   8822:     $ValuesHash{$id.'.width'}    = $width;
                   8823:     $ValuesHash{$id.'.xskip'}    = $xskip;
                   8824:     $ValuesHash{$id.'.bar_width'} = $bar_width;
                   8825:     $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127     matthew  8826:     #
1.228     matthew  8827:     # Deal with other parameters
                   8828:     while (my ($key,$value) = each(%$extra_settings)) {
                   8829:         $ValuesHash{$id.'.'.$key} = $value;
                   8830:     }
                   8831:     #
1.646     raeburn  8832:     &Apache::lonnet::appenv(\%ValuesHash);
1.137     matthew  8833:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   8834: }
                   8835: 
                   8836: ############################################################
                   8837: ############################################################
                   8838: 
                   8839: =pod
                   8840: 
1.648     raeburn  8841: =item * &DrawXYGraph()
1.137     matthew  8842: 
1.138     matthew  8843: Facilitates the plotting of data in an XY graph.
                   8844: Puts plot definition data into the users environment in order for 
                   8845: graph.png to plot it.  Returns an <img> tag for the plot.
                   8846: 
                   8847: Inputs:
                   8848: 
                   8849: =over 4
                   8850: 
                   8851: =item $Title: string, the title of the plot
                   8852: 
                   8853: =item $xlabel: string, text describing the X-axis of the plot
                   8854: 
                   8855: =item $ylabel: string, text describing the Y-axis of the plot
                   8856: 
                   8857: =item $Max: scalar, the maximum Y value to use in the plot
                   8858: If $Max is < any data point, the graph will not be rendered.
                   8859: 
                   8860: =item $colors: Array ref containing the hex color codes for the data to be 
                   8861: plotted in.  If undefined, default values will be used.
                   8862: 
                   8863: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   8864: 
                   8865: =item $Ydata: Array ref containing Array refs.  
1.185     www      8866: Each of the contained arrays will be plotted as a separate curve.
1.138     matthew  8867: 
                   8868: =item %Values: hash indicating or overriding any default values which are 
                   8869: passed to graph.png.  
                   8870: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   8871: 
                   8872: =back
                   8873: 
                   8874: Returns:
                   8875: 
                   8876: An <img> tag which references graph.png and the appropriate identifying
                   8877: information for the plot.
                   8878: 
1.137     matthew  8879: =cut
                   8880: 
                   8881: ############################################################
                   8882: ############################################################
                   8883: sub DrawXYGraph {
                   8884:     my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
                   8885:     #
                   8886:     # Create the identifier for the graph
                   8887:     my $identifier = &get_cgi_id();
                   8888:     my $id = 'cgi.'.$identifier;
                   8889:     #
                   8890:     $Title  = '' if (! defined($Title));
                   8891:     $xlabel = '' if (! defined($xlabel));
                   8892:     $ylabel = '' if (! defined($ylabel));
                   8893:     my %ValuesHash = 
                   8894:         (
1.369     www      8895:          $id.'.title'  => &escape($Title),
                   8896:          $id.'.xlabel' => &escape($xlabel),
                   8897:          $id.'.ylabel' => &escape($ylabel),
1.137     matthew  8898:          $id.'.y_max_value'=> $Max,
                   8899:          $id.'.labels'     => join(',',@$Xlabels),
                   8900:          $id.'.PlotType'   => 'XY',
                   8901:          );
                   8902:     #
                   8903:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   8904:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8905:     }
                   8906:     #
                   8907:     if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
                   8908:         return '';
                   8909:     }
                   8910:     my $NumSets=1;
1.138     matthew  8911:     foreach my $array (@{$Ydata}){
1.137     matthew  8912:         next if (! ref($array));
                   8913:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
                   8914:     }
1.138     matthew  8915:     $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137     matthew  8916:     #
                   8917:     # Deal with other parameters
                   8918:     while (my ($key,$value) = each(%Values)) {
                   8919:         $ValuesHash{$id.'.'.$key} = $value;
1.127     matthew  8920:     }
                   8921:     #
1.646     raeburn  8922:     &Apache::lonnet::appenv(\%ValuesHash);
1.136     matthew  8923:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   8924: }
                   8925: 
                   8926: ############################################################
                   8927: ############################################################
                   8928: 
                   8929: =pod
                   8930: 
1.648     raeburn  8931: =item * &DrawXYYGraph()
1.138     matthew  8932: 
                   8933: Facilitates the plotting of data in an XY graph with two Y axes.
                   8934: Puts plot definition data into the users environment in order for 
                   8935: graph.png to plot it.  Returns an <img> tag for the plot.
                   8936: 
                   8937: Inputs:
                   8938: 
                   8939: =over 4
                   8940: 
                   8941: =item $Title: string, the title of the plot
                   8942: 
                   8943: =item $xlabel: string, text describing the X-axis of the plot
                   8944: 
                   8945: =item $ylabel: string, text describing the Y-axis of the plot
                   8946: 
                   8947: =item $colors: Array ref containing the hex color codes for the data to be 
                   8948: plotted in.  If undefined, default values will be used.
                   8949: 
                   8950: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   8951: 
                   8952: =item $Ydata1: The first data set
                   8953: 
                   8954: =item $Min1: The minimum value of the left Y-axis
                   8955: 
                   8956: =item $Max1: The maximum value of the left Y-axis
                   8957: 
                   8958: =item $Ydata2: The second data set
                   8959: 
                   8960: =item $Min2: The minimum value of the right Y-axis
                   8961: 
                   8962: =item $Max2: The maximum value of the left Y-axis
                   8963: 
                   8964: =item %Values: hash indicating or overriding any default values which are 
                   8965: passed to graph.png.  
                   8966: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   8967: 
                   8968: =back
                   8969: 
                   8970: Returns:
                   8971: 
                   8972: An <img> tag which references graph.png and the appropriate identifying
                   8973: information for the plot.
1.136     matthew  8974: 
                   8975: =cut
                   8976: 
                   8977: ############################################################
                   8978: ############################################################
1.137     matthew  8979: sub DrawXYYGraph {
                   8980:     my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
                   8981:                                         $Ydata2,$Min2,$Max2,%Values)=@_;
1.136     matthew  8982:     #
                   8983:     # Create the identifier for the graph
                   8984:     my $identifier = &get_cgi_id();
                   8985:     my $id = 'cgi.'.$identifier;
                   8986:     #
                   8987:     $Title  = '' if (! defined($Title));
                   8988:     $xlabel = '' if (! defined($xlabel));
                   8989:     $ylabel = '' if (! defined($ylabel));
                   8990:     my %ValuesHash = 
                   8991:         (
1.369     www      8992:          $id.'.title'  => &escape($Title),
                   8993:          $id.'.xlabel' => &escape($xlabel),
                   8994:          $id.'.ylabel' => &escape($ylabel),
1.136     matthew  8995:          $id.'.labels' => join(',',@$Xlabels),
                   8996:          $id.'.PlotType' => 'XY',
                   8997:          $id.'.NumSets' => 2,
1.137     matthew  8998:          $id.'.two_axes' => 1,
                   8999:          $id.'.y1_max_value' => $Max1,
                   9000:          $id.'.y1_min_value' => $Min1,
                   9001:          $id.'.y2_max_value' => $Max2,
                   9002:          $id.'.y2_min_value' => $Min2,
1.136     matthew  9003:          );
                   9004:     #
1.137     matthew  9005:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   9006:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   9007:     }
                   9008:     #
                   9009:     if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
                   9010:         ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136     matthew  9011:         return '';
                   9012:     }
                   9013:     my $NumSets=1;
1.137     matthew  9014:     foreach my $array ($Ydata1,$Ydata2){
1.136     matthew  9015:         next if (! ref($array));
                   9016:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137     matthew  9017:     }
                   9018:     #
                   9019:     # Deal with other parameters
                   9020:     while (my ($key,$value) = each(%Values)) {
                   9021:         $ValuesHash{$id.'.'.$key} = $value;
1.136     matthew  9022:     }
                   9023:     #
1.646     raeburn  9024:     &Apache::lonnet::appenv(\%ValuesHash);
1.130     albertel 9025:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139     matthew  9026: }
                   9027: 
                   9028: ############################################################
                   9029: ############################################################
                   9030: 
                   9031: =pod
                   9032: 
1.157     matthew  9033: =back 
                   9034: 
1.139     matthew  9035: =head1 Statistics helper routines?  
                   9036: 
                   9037: Bad place for them but what the hell.
                   9038: 
1.157     matthew  9039: =over 4
                   9040: 
1.648     raeburn  9041: =item * &chartlink()
1.139     matthew  9042: 
                   9043: Returns a link to the chart for a specific student.  
                   9044: 
                   9045: Inputs:
                   9046: 
                   9047: =over 4
                   9048: 
                   9049: =item $linktext: The text of the link
                   9050: 
                   9051: =item $sname: The students username
                   9052: 
                   9053: =item $sdomain: The students domain
                   9054: 
                   9055: =back
                   9056: 
1.157     matthew  9057: =back
                   9058: 
1.139     matthew  9059: =cut
                   9060: 
                   9061: ############################################################
                   9062: ############################################################
                   9063: sub chartlink {
                   9064:     my ($linktext, $sname, $sdomain) = @_;
                   9065:     my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369     www      9066:         '&amp;SelectedStudent='.&escape($sname.':'.$sdomain).
1.219     albertel 9067:         '&amp;chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139     matthew  9068:        '">'.$linktext.'</a>';
1.153     matthew  9069: }
                   9070: 
                   9071: #######################################################
                   9072: #######################################################
                   9073: 
                   9074: =pod
                   9075: 
                   9076: =head1 Course Environment Routines
1.157     matthew  9077: 
                   9078: =over 4
1.153     matthew  9079: 
1.648     raeburn  9080: =item * &restore_course_settings()
1.153     matthew  9081: 
1.648     raeburn  9082: =item * &store_course_settings()
1.153     matthew  9083: 
                   9084: Restores/Store indicated form parameters from the course environment.
                   9085: Will not overwrite existing values of the form parameters.
                   9086: 
                   9087: Inputs: 
                   9088: a scalar describing the data (e.g. 'chart', 'problem_analysis')
                   9089: 
                   9090: a hash ref describing the data to be stored.  For example:
                   9091:    
                   9092: %Save_Parameters = ('Status' => 'scalar',
                   9093:     'chartoutputmode' => 'scalar',
                   9094:     'chartoutputdata' => 'scalar',
                   9095:     'Section' => 'array',
1.373     raeburn  9096:     'Group' => 'array',
1.153     matthew  9097:     'StudentData' => 'array',
                   9098:     'Maps' => 'array');
                   9099: 
                   9100: Returns: both routines return nothing
                   9101: 
1.631     raeburn  9102: =back
                   9103: 
1.153     matthew  9104: =cut
                   9105: 
                   9106: #######################################################
                   9107: #######################################################
                   9108: sub store_course_settings {
1.496     albertel 9109:     return &store_settings($env{'request.course.id'},@_);
                   9110: }
                   9111: 
                   9112: sub store_settings {
1.153     matthew  9113:     # save to the environment
                   9114:     # appenv the same items, just to be safe
1.300     albertel 9115:     my $udom  = $env{'user.domain'};
                   9116:     my $uname = $env{'user.name'};
1.496     albertel 9117:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  9118:     my %SaveHash;
                   9119:     my %AppHash;
                   9120:     while (my ($setting,$type) = each(%$Settings)) {
1.496     albertel 9121:         my $basename = join('.','internal',$context,$prefix,$setting);
1.300     albertel 9122:         my $envname = 'environment.'.$basename;
1.258     albertel 9123:         if (exists($env{'form.'.$setting})) {
1.153     matthew  9124:             # Save this value away
                   9125:             if ($type eq 'scalar' &&
1.258     albertel 9126:                 (! exists($env{$envname}) || 
                   9127:                  $env{$envname} ne $env{'form.'.$setting})) {
                   9128:                 $SaveHash{$basename} = $env{'form.'.$setting};
                   9129:                 $AppHash{$envname}   = $env{'form.'.$setting};
1.153     matthew  9130:             } elsif ($type eq 'array') {
                   9131:                 my $stored_form;
1.258     albertel 9132:                 if (ref($env{'form.'.$setting})) {
1.153     matthew  9133:                     $stored_form = join(',',
                   9134:                                         map {
1.369     www      9135:                                             &escape($_);
1.258     albertel 9136:                                         } sort(@{$env{'form.'.$setting}}));
1.153     matthew  9137:                 } else {
                   9138:                     $stored_form = 
1.369     www      9139:                         &escape($env{'form.'.$setting});
1.153     matthew  9140:                 }
                   9141:                 # Determine if the array contents are the same.
1.258     albertel 9142:                 if ($stored_form ne $env{$envname}) {
1.153     matthew  9143:                     $SaveHash{$basename} = $stored_form;
                   9144:                     $AppHash{$envname}   = $stored_form;
                   9145:                 }
                   9146:             }
                   9147:         }
                   9148:     }
                   9149:     my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300     albertel 9150:                                           $udom,$uname);
1.153     matthew  9151:     if ($put_result !~ /^(ok|delayed)/) {
                   9152:         &Apache::lonnet::logthis('unable to save form parameters, '.
                   9153:                                  'got error:'.$put_result);
                   9154:     }
                   9155:     # Make sure these settings stick around in this session, too
1.646     raeburn  9156:     &Apache::lonnet::appenv(\%AppHash);
1.153     matthew  9157:     return;
                   9158: }
                   9159: 
                   9160: sub restore_course_settings {
1.499     albertel 9161:     return &restore_settings($env{'request.course.id'},@_);
1.496     albertel 9162: }
                   9163: 
                   9164: sub restore_settings {
                   9165:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  9166:     while (my ($setting,$type) = each(%$Settings)) {
1.258     albertel 9167:         next if (exists($env{'form.'.$setting}));
1.496     albertel 9168:         my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153     matthew  9169:             '.'.$setting;
1.258     albertel 9170:         if (exists($env{$envname})) {
1.153     matthew  9171:             if ($type eq 'scalar') {
1.258     albertel 9172:                 $env{'form.'.$setting} = $env{$envname};
1.153     matthew  9173:             } elsif ($type eq 'array') {
1.258     albertel 9174:                 $env{'form.'.$setting} = [ 
1.153     matthew  9175:                                            map { 
1.369     www      9176:                                                &unescape($_); 
1.258     albertel 9177:                                            } split(',',$env{$envname})
1.153     matthew  9178:                                            ];
                   9179:             }
                   9180:         }
                   9181:     }
1.127     matthew  9182: }
                   9183: 
1.618     raeburn  9184: #######################################################
                   9185: #######################################################
                   9186: 
                   9187: =pod
                   9188: 
                   9189: =head1 Domain E-mail Routines  
                   9190: 
                   9191: =over 4
                   9192: 
1.648     raeburn  9193: =item * &build_recipient_list()
1.618     raeburn  9194: 
1.766     raeburn  9195: Build recipient lists for four types of e-mail:
                   9196: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
                   9197: (d) Help requests, generated by
                   9198: lonerrorhandler.pm, CHECKRPMS, loncron, and lonsupportreq.pm respectively.
1.618     raeburn  9199: 
                   9200: Inputs:
1.619     raeburn  9201: defmail (scalar - email address of default recipient), 
1.618     raeburn  9202: mailing type (scalar - errormail, packagesmail, or helpdeskmail), 
1.619     raeburn  9203: defdom (domain for which to retrieve configuration settings),
                   9204: origmail (scalar - email address of recipient from loncapa.conf, 
                   9205: i.e., predates configuration by DC via domainprefs.pm 
1.618     raeburn  9206: 
1.655     raeburn  9207: Returns: comma separated list of addresses to which to send e-mail.
                   9208: 
                   9209: =back
1.618     raeburn  9210: 
                   9211: =cut
                   9212: 
                   9213: ############################################################
                   9214: ############################################################
                   9215: sub build_recipient_list {
1.619     raeburn  9216:     my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618     raeburn  9217:     my @recipients;
                   9218:     my $otheremails;
                   9219:     my %domconfig =
                   9220:          &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
                   9221:     if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766     raeburn  9222:         if (exists($domconfig{'contacts'}{$mailing})) {
                   9223:             if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
                   9224:                 my @contacts = ('adminemail','supportemail');
                   9225:                 foreach my $item (@contacts) {
                   9226:                     if ($domconfig{'contacts'}{$mailing}{$item}) {
                   9227:                         my $addr = $domconfig{'contacts'}{$item}; 
                   9228:                         if (!grep(/^\Q$addr\E$/,@recipients)) {
                   9229:                             push(@recipients,$addr);
                   9230:                         }
1.619     raeburn  9231:                     }
1.766     raeburn  9232:                     $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618     raeburn  9233:                 }
                   9234:             }
1.766     raeburn  9235:         } elsif ($origmail ne '') {
                   9236:             push(@recipients,$origmail);
1.618     raeburn  9237:         }
1.619     raeburn  9238:     } elsif ($origmail ne '') {
                   9239:         push(@recipients,$origmail);
1.618     raeburn  9240:     }
1.688     raeburn  9241:     if (defined($defmail)) {
                   9242:         if ($defmail ne '') {
                   9243:             push(@recipients,$defmail);
                   9244:         }
1.618     raeburn  9245:     }
                   9246:     if ($otheremails) {
1.619     raeburn  9247:         my @others;
                   9248:         if ($otheremails =~ /,/) {
                   9249:             @others = split(/,/,$otheremails);
1.618     raeburn  9250:         } else {
1.619     raeburn  9251:             push(@others,$otheremails);
                   9252:         }
                   9253:         foreach my $addr (@others) {
                   9254:             if (!grep(/^\Q$addr\E$/,@recipients)) {
                   9255:                 push(@recipients,$addr);
                   9256:             }
1.618     raeburn  9257:         }
                   9258:     }
1.619     raeburn  9259:     my $recipientlist = join(',',@recipients); 
1.618     raeburn  9260:     return $recipientlist;
                   9261: }
                   9262: 
1.127     matthew  9263: ############################################################
                   9264: ############################################################
1.154     albertel 9265: 
1.655     raeburn  9266: =pod
                   9267: 
                   9268: =head1 Course Catalog Routines
                   9269: 
                   9270: =over 4
                   9271: 
                   9272: =item * &gather_categories()
                   9273: 
                   9274: Converts category definitions - keys of categories hash stored in  
                   9275: coursecategories in configuration.db on the primary library server in a 
                   9276: domain - to an array.  Also generates javascript and idx hash used to 
                   9277: generate Domain Coordinator interface for editing Course Categories.
                   9278: 
                   9279: Inputs:
1.663     raeburn  9280: 
1.655     raeburn  9281: categories (reference to hash of category definitions).
1.663     raeburn  9282: 
1.655     raeburn  9283: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9284:       categories and subcategories).
1.663     raeburn  9285: 
1.655     raeburn  9286: idx (reference to hash of counters used in Domain Coordinator interface for 
                   9287:       editing Course Categories).
1.663     raeburn  9288: 
1.655     raeburn  9289: jsarray (reference to array of categories used to create Javascript arrays for
                   9290:          Domain Coordinator interface for editing Course Categories).
                   9291: 
                   9292: Returns: nothing
                   9293: 
                   9294: Side effects: populates cats, idx and jsarray. 
                   9295: 
                   9296: =cut
                   9297: 
                   9298: sub gather_categories {
                   9299:     my ($categories,$cats,$idx,$jsarray) = @_;
                   9300:     my %counters;
                   9301:     my $num = 0;
                   9302:     foreach my $item (keys(%{$categories})) {
                   9303:         my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   9304:         if ($container eq '' && $depth == 0) {
                   9305:             $cats->[$depth][$categories->{$item}] = $cat;
                   9306:         } else {
                   9307:             $cats->[$depth]{$container}[$categories->{$item}] = $cat;
                   9308:         }
                   9309:         my ($escitem,$tail) = split(/:/,$item,2);
                   9310:         if ($counters{$tail} eq '') {
                   9311:             $counters{$tail} = $num;
                   9312:             $num ++;
                   9313:         }
                   9314:         if (ref($idx) eq 'HASH') {
                   9315:             $idx->{$item} = $counters{$tail};
                   9316:         }
                   9317:         if (ref($jsarray) eq 'ARRAY') {
                   9318:             push(@{$jsarray->[$counters{$tail}]},$item);
                   9319:         }
                   9320:     }
                   9321:     return;
                   9322: }
                   9323: 
                   9324: =pod
                   9325: 
                   9326: =item * &extract_categories()
                   9327: 
                   9328: Used to generate breadcrumb trails for course categories.
                   9329: 
                   9330: Inputs:
1.663     raeburn  9331: 
1.655     raeburn  9332: categories (reference to hash of category definitions).
1.663     raeburn  9333: 
1.655     raeburn  9334: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9335:       categories and subcategories).
1.663     raeburn  9336: 
1.655     raeburn  9337: trails (reference to array of breacrumb trails for each category).
1.663     raeburn  9338: 
1.655     raeburn  9339: allitems (reference to hash - key is category key 
                   9340:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  9341: 
1.655     raeburn  9342: idx (reference to hash of counters used in Domain Coordinator interface for
                   9343:       editing Course Categories).
1.663     raeburn  9344: 
1.655     raeburn  9345: jsarray (reference to array of categories used to create Javascript arrays for
                   9346:          Domain Coordinator interface for editing Course Categories).
                   9347: 
1.665     raeburn  9348: subcats (reference to hash of arrays containing all subcategories within each 
                   9349:          category, -recursive)
                   9350: 
1.655     raeburn  9351: Returns: nothing
                   9352: 
                   9353: Side effects: populates trails and allitems hash references.
                   9354: 
                   9355: =cut
                   9356: 
                   9357: sub extract_categories {
1.665     raeburn  9358:     my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655     raeburn  9359:     if (ref($categories) eq 'HASH') {
                   9360:         &gather_categories($categories,$cats,$idx,$jsarray);
                   9361:         if (ref($cats->[0]) eq 'ARRAY') {
                   9362:             for (my $i=0; $i<@{$cats->[0]}; $i++) {
                   9363:                 my $name = $cats->[0][$i];
                   9364:                 my $item = &escape($name).'::0';
                   9365:                 my $trailstr;
                   9366:                 if ($name eq 'instcode') {
                   9367:                     $trailstr = &mt('Official courses (with institutional codes)');
                   9368:                 } else {
                   9369:                     $trailstr = $name;
                   9370:                 }
                   9371:                 if ($allitems->{$item} eq '') {
                   9372:                     push(@{$trails},$trailstr);
                   9373:                     $allitems->{$item} = scalar(@{$trails})-1;
                   9374:                 }
                   9375:                 my @parents = ($name);
                   9376:                 if (ref($cats->[1]{$name}) eq 'ARRAY') {
                   9377:                     for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
                   9378:                         my $category = $cats->[1]{$name}[$j];
1.665     raeburn  9379:                         if (ref($subcats) eq 'HASH') {
                   9380:                             push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
                   9381:                         }
                   9382:                         &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
                   9383:                     }
                   9384:                 } else {
                   9385:                     if (ref($subcats) eq 'HASH') {
                   9386:                         $subcats->{$item} = [];
1.655     raeburn  9387:                     }
                   9388:                 }
                   9389:             }
                   9390:         }
                   9391:     }
                   9392:     return;
                   9393: }
                   9394: 
                   9395: =pod
                   9396: 
                   9397: =item *&recurse_categories()
                   9398: 
                   9399: Recursively used to generate breadcrumb trails for course categories.
                   9400: 
                   9401: Inputs:
1.663     raeburn  9402: 
1.655     raeburn  9403: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9404:       categories and subcategories).
1.663     raeburn  9405: 
1.655     raeburn  9406: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663     raeburn  9407: 
                   9408: category (current course category, for which breadcrumb trail is being generated).
                   9409: 
                   9410: trails (reference to array of breadcrumb trails for each category).
                   9411: 
1.655     raeburn  9412: allitems (reference to hash - key is category key
                   9413:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  9414: 
1.655     raeburn  9415: parents (array containing containers directories for current category, 
                   9416:          back to top level). 
                   9417: 
                   9418: Returns: nothing
                   9419: 
                   9420: Side effects: populates trails and allitems hash references
                   9421: 
                   9422: =cut
                   9423: 
                   9424: sub recurse_categories {
1.665     raeburn  9425:     my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655     raeburn  9426:     my $shallower = $depth - 1;
                   9427:     if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
                   9428:         for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
                   9429:             my $name = $cats->[$depth]{$category}[$k];
                   9430:             my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   9431:             my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   9432:             if ($allitems->{$item} eq '') {
                   9433:                 push(@{$trails},$trailstr);
                   9434:                 $allitems->{$item} = scalar(@{$trails})-1;
                   9435:             }
                   9436:             my $deeper = $depth+1;
                   9437:             push(@{$parents},$category);
1.665     raeburn  9438:             if (ref($subcats) eq 'HASH') {
                   9439:                 my $subcat = &escape($name).':'.$category.':'.$depth;
                   9440:                 for (my $j=@{$parents}; $j>=0; $j--) {
                   9441:                     my $higher;
                   9442:                     if ($j > 0) {
                   9443:                         $higher = &escape($parents->[$j]).':'.
                   9444:                                   &escape($parents->[$j-1]).':'.$j;
                   9445:                     } else {
                   9446:                         $higher = &escape($parents->[$j]).'::'.$j;
                   9447:                     }
                   9448:                     push(@{$subcats->{$higher}},$subcat);
                   9449:                 }
                   9450:             }
                   9451:             &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
                   9452:                                 $subcats);
1.655     raeburn  9453:             pop(@{$parents});
                   9454:         }
                   9455:     } else {
                   9456:         my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   9457:         my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   9458:         if ($allitems->{$item} eq '') {
                   9459:             push(@{$trails},$trailstr);
                   9460:             $allitems->{$item} = scalar(@{$trails})-1;
                   9461:         }
                   9462:     }
                   9463:     return;
                   9464: }
                   9465: 
1.663     raeburn  9466: =pod
                   9467: 
                   9468: =item *&assign_categories_table()
                   9469: 
                   9470: Create a datatable for display of hierarchical categories in a domain,
                   9471: with checkboxes to allow a course to be categorized. 
                   9472: 
                   9473: Inputs:
                   9474: 
                   9475: cathash - reference to hash of categories defined for the domain (from
                   9476:           configuration.db)
                   9477: 
                   9478: currcat - scalar with an & separated list of categories assigned to a course. 
                   9479: 
                   9480: Returns: $output (markup to be displayed) 
                   9481: 
                   9482: =cut
                   9483: 
                   9484: sub assign_categories_table {
                   9485:     my ($cathash,$currcat) = @_;
                   9486:     my $output;
                   9487:     if (ref($cathash) eq 'HASH') {
                   9488:         my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
                   9489:         &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
                   9490:         $maxdepth = scalar(@cats);
                   9491:         if (@cats > 0) {
                   9492:             my $itemcount = 0;
                   9493:             if (ref($cats[0]) eq 'ARRAY') {
                   9494:                 $output = &Apache::loncommon::start_data_table();
                   9495:                 my @currcategories;
                   9496:                 if ($currcat ne '') {
                   9497:                     @currcategories = split('&',$currcat);
                   9498:                 }
                   9499:                 for (my $i=0; $i<@{$cats[0]}; $i++) {
                   9500:                     my $parent = $cats[0][$i];
                   9501:                     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9502:                     next if ($parent eq 'instcode');
                   9503:                     my $item = &escape($parent).'::0';
                   9504:                     my $checked = '';
                   9505:                     if (@currcategories > 0) {
                   9506:                         if (grep(/^\Q$item\E$/,@currcategories)) {
1.772     bisitz   9507:                             $checked = ' checked="checked"';
1.663     raeburn  9508:                         }
                   9509:                     }
1.675     raeburn  9510:                     $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
                   9511:                                '<input type="checkbox" name="usecategory" value="'.
                   9512:                                $item.'"'.$checked.' />'.$parent.'</span>'.
                   9513:                                '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663     raeburn  9514:                     my $depth = 1;
                   9515:                     push(@path,$parent);
                   9516:                     $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
                   9517:                     pop(@path);
                   9518:                     $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   9519:                     $itemcount ++;
                   9520:                 }
                   9521:                 $output .= &Apache::loncommon::end_data_table();
                   9522:             }
                   9523:         }
                   9524:     }
                   9525:     return $output;
                   9526: }
                   9527: 
                   9528: =pod
                   9529: 
                   9530: =item *&assign_category_rows()
                   9531: 
                   9532: Create a datatable row for display of nested categories in a domain,
                   9533: with checkboxes to allow a course to be categorized,called recursively.
                   9534: 
                   9535: Inputs:
                   9536: 
                   9537: itemcount - track row number for alternating colors
                   9538: 
                   9539: cats - reference to array of arrays/hashes which encapsulates hierarchy of
                   9540:       categories and subcategories.
                   9541: 
                   9542: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
                   9543: 
                   9544: parent - parent of current category item
                   9545: 
                   9546: path - Array containing all categories back up through the hierarchy from the
                   9547:        current category to the top level.
                   9548: 
                   9549: currcategories - reference to array of current categories assigned to the course
                   9550: 
                   9551: Returns: $output (markup to be displayed).
                   9552: 
                   9553: =cut
                   9554: 
                   9555: sub assign_category_rows {
                   9556:     my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
                   9557:     my ($text,$name,$item,$chgstr);
                   9558:     if (ref($cats) eq 'ARRAY') {
                   9559:         my $maxdepth = scalar(@{$cats});
                   9560:         if (ref($cats->[$depth]) eq 'HASH') {
                   9561:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   9562:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   9563:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9564:                 $text .= '<td><table class="LC_datatable">';
                   9565:                 for (my $j=0; $j<$numchildren; $j++) {
                   9566:                     $name = $cats->[$depth]{$parent}[$j];
                   9567:                     $item = &escape($name).':'.&escape($parent).':'.$depth;
                   9568:                     my $deeper = $depth+1;
                   9569:                     my $checked = '';
                   9570:                     if (ref($currcategories) eq 'ARRAY') {
                   9571:                         if (@{$currcategories} > 0) {
                   9572:                             if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772     bisitz   9573:                                 $checked = ' checked="checked"';
1.663     raeburn  9574:                             }
                   9575:                         }
                   9576:                     }
1.664     raeburn  9577:                     $text .= '<tr><td><span class="LC_nobreak"><label>'.
                   9578:                              '<input type="checkbox" name="usecategory" value="'.
1.675     raeburn  9579:                              $item.'"'.$checked.' />'.$name.'</label></span>'.
                   9580:                              '<input type="hidden" name="catname" value="'.$name.'" />'.
                   9581:                              '</td><td>';
1.663     raeburn  9582:                     if (ref($path) eq 'ARRAY') {
                   9583:                         push(@{$path},$name);
                   9584:                         $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
                   9585:                         pop(@{$path});
                   9586:                     }
                   9587:                     $text .= '</td></tr>';
                   9588:                 }
                   9589:                 $text .= '</table></td>';
                   9590:             }
                   9591:         }
                   9592:     }
                   9593:     return $text;
                   9594: }
                   9595: 
1.655     raeburn  9596: ############################################################
                   9597: ############################################################
                   9598: 
                   9599: 
1.443     albertel 9600: sub commit_customrole {
1.664     raeburn  9601:     my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630     raeburn  9602:     my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443     albertel 9603:                          ($start?', '.&mt('starting').' '.localtime($start):'').
                   9604:                          ($end?', ending '.localtime($end):'').': <b>'.
                   9605:               &Apache::lonnet::assigncustomrole(
1.664     raeburn  9606:                  $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443     albertel 9607:                  '</b><br />';
                   9608:     return $output;
                   9609: }
                   9610: 
                   9611: sub commit_standardrole {
1.541     raeburn  9612:     my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
                   9613:     my ($output,$logmsg,$linefeed);
                   9614:     if ($context eq 'auto') {
                   9615:         $linefeed = "\n";
                   9616:     } else {
                   9617:         $linefeed = "<br />\n";
                   9618:     }  
1.443     albertel 9619:     if ($three eq 'st') {
1.541     raeburn  9620:         my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
                   9621:                                          $one,$two,$sec,$context);
                   9622:         if (($result =~ /^error/) || ($result eq 'not_in_class') || 
1.626     raeburn  9623:             ($result eq 'unknown_course') || ($result eq 'refused')) {
                   9624:             $output = $logmsg.' '.&mt('Error: ').$result."\n"; 
1.443     albertel 9625:         } else {
1.541     raeburn  9626:             $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443     albertel 9627:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  9628:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
                   9629:             if ($context eq 'auto') {
                   9630:                 $output .= $result.$linefeed.&mt('Add to classlist').': ok';
                   9631:             } else {
                   9632:                $output .= '<b>'.$result.'</b>'.$linefeed.
                   9633:                &mt('Add to classlist').': <b>ok</b>';
                   9634:             }
                   9635:             $output .= $linefeed;
1.443     albertel 9636:         }
                   9637:     } else {
                   9638:         $output = &mt('Assigning').' '.$three.' in '.$url.
                   9639:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  9640:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652     raeburn  9641:         my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541     raeburn  9642:         if ($context eq 'auto') {
                   9643:             $output .= $result.$linefeed;
                   9644:         } else {
                   9645:             $output .= '<b>'.$result.'</b>'.$linefeed;
                   9646:         }
1.443     albertel 9647:     }
                   9648:     return $output;
                   9649: }
                   9650: 
                   9651: sub commit_studentrole {
1.541     raeburn  9652:     my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626     raeburn  9653:     my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541     raeburn  9654:     if ($context eq 'auto') {
                   9655:         $linefeed = "\n";
                   9656:     } else {
                   9657:         $linefeed = '<br />'."\n";
                   9658:     }
1.443     albertel 9659:     if (defined($one) && defined($two)) {
                   9660:         my $cid=$one.'_'.$two;
                   9661:         my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
                   9662:         my $secchange = 0;
                   9663:         my $expire_role_result;
                   9664:         my $modify_section_result;
1.628     raeburn  9665:         if ($oldsec ne '-1') { 
                   9666:             if ($oldsec ne $sec) {
1.443     albertel 9667:                 $secchange = 1;
1.628     raeburn  9668:                 my $now = time;
1.443     albertel 9669:                 my $uurl='/'.$cid;
                   9670:                 $uurl=~s/\_/\//g;
                   9671:                 if ($oldsec) {
                   9672:                     $uurl.='/'.$oldsec;
                   9673:                 }
1.626     raeburn  9674:                 $oldsecurl = $uurl;
1.628     raeburn  9675:                 $expire_role_result = 
1.652     raeburn  9676:                     &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628     raeburn  9677:                 if ($env{'request.course.sec'} ne '') { 
                   9678:                     if ($expire_role_result eq 'refused') {
                   9679:                         my @roles = ('st');
                   9680:                         my @statuses = ('previous');
                   9681:                         my @roledoms = ($one);
                   9682:                         my $withsec = 1;
                   9683:                         my %roleshash = 
                   9684:                             &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
                   9685:                                               \@statuses,\@roles,\@roledoms,$withsec);
                   9686:                         if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
                   9687:                             my ($oldstart,$oldend) = 
                   9688:                                 split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
                   9689:                             if ($oldend > 0 && $oldend <= $now) {
                   9690:                                 $expire_role_result = 'ok';
                   9691:                             }
                   9692:                         }
                   9693:                     }
                   9694:                 }
1.443     albertel 9695:                 $result = $expire_role_result;
                   9696:             }
                   9697:         }
                   9698:         if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652     raeburn  9699:             $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443     albertel 9700:             if ($modify_section_result =~ /^ok/) {
                   9701:                 if ($secchange == 1) {
1.628     raeburn  9702:                     if ($sec eq '') {
                   9703:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
                   9704:                     } else {
                   9705:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
                   9706:                     }
1.443     albertel 9707:                 } elsif ($oldsec eq '-1') {
1.628     raeburn  9708:                     if ($sec eq '') {
                   9709:                         $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
                   9710:                     } else {
                   9711:                         $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   9712:                     }
1.443     albertel 9713:                 } else {
1.628     raeburn  9714:                     if ($sec eq '') {
                   9715:                         $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
                   9716:                     } else {
                   9717:                         $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   9718:                     }
1.443     albertel 9719:                 }
                   9720:             } else {
1.628     raeburn  9721:                 if ($secchange) {       
                   9722:                     $$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;
                   9723:                 } else {
                   9724:                     $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
                   9725:                 }
1.443     albertel 9726:             }
                   9727:             $result = $modify_section_result;
                   9728:         } elsif ($secchange == 1) {
1.628     raeburn  9729:             if ($oldsec eq '') {
                   9730:                 $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
                   9731:             } else {
                   9732:                 $$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;
                   9733:             }
1.626     raeburn  9734:             if ($expire_role_result eq 'refused') {
                   9735:                 my $newsecurl = '/'.$cid;
                   9736:                 $newsecurl =~ s/\_/\//g;
                   9737:                 if ($sec ne '') {
                   9738:                     $newsecurl.='/'.$sec;
                   9739:                 }
                   9740:                 if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
                   9741:                     if ($sec eq '') {
                   9742:                         $$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;
                   9743:                     } else {
                   9744:                         $$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;
                   9745:                     }
                   9746:                 }
                   9747:             }
1.443     albertel 9748:         }
                   9749:     } else {
1.626     raeburn  9750:         $$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 9751:         $result = "error: incomplete course id\n";
                   9752:     }
                   9753:     return $result;
                   9754: }
                   9755: 
                   9756: ############################################################
                   9757: ############################################################
                   9758: 
1.566     albertel 9759: sub check_clone {
1.578     raeburn  9760:     my ($args,$linefeed) = @_;
1.566     albertel 9761:     my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
                   9762:     my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
                   9763:     my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
                   9764:     my $clonemsg;
                   9765:     my $can_clone = 0;
                   9766: 
                   9767:     if ($clonehome eq 'no_host') {
1.578     raeburn  9768:         $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 9769:     } else {
                   9770: 	my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568     albertel 9771: 	if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566     albertel 9772: 	    $can_clone = 1;
                   9773: 	} else {
                   9774: 	    my %clonehash = &Apache::lonnet::get('environment',['cloners'],
                   9775: 						 $args->{'clonedomain'},$args->{'clonecourse'});
                   9776: 	    my @cloners = split(/,/,$clonehash{'cloners'});
1.578     raeburn  9777:             if (grep(/^\*$/,@cloners)) {
                   9778:                 $can_clone = 1;
                   9779:             } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
                   9780:                 $can_clone = 1;
                   9781:             } else {
                   9782: 	        my %roleshash =
                   9783: 		    &Apache::lonnet::get_my_roles($args->{'ccuname'},
                   9784: 					 $args->{'ccdomain'},
                   9785:                                          'userroles',['active'],['cc'],
                   9786: 					 [$args->{'clonedomain'}]);
                   9787: 	        if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
                   9788: 		    $can_clone = 1;
                   9789: 	        } else {
                   9790:                     $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'});
                   9791: 	        }
1.566     albertel 9792: 	    }
1.578     raeburn  9793:         }
1.566     albertel 9794:     }
                   9795:     return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   9796: }
                   9797: 
1.444     albertel 9798: sub construct_course {
1.541     raeburn  9799:     my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444     albertel 9800:     my $outcome;
1.541     raeburn  9801:     my $linefeed =  '<br />'."\n";
                   9802:     if ($context eq 'auto') {
                   9803:         $linefeed = "\n";
                   9804:     }
1.566     albertel 9805: 
                   9806: #
                   9807: # Are we cloning?
                   9808: #
                   9809:     my ($can_clone, $clonemsg, $cloneid, $clonehome);
                   9810:     if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578     raeburn  9811: 	($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566     albertel 9812: 	if ($context ne 'auto') {
1.578     raeburn  9813:             if ($clonemsg ne '') {
                   9814: 	        $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
                   9815:             }
1.566     albertel 9816: 	}
                   9817: 	$outcome .= $clonemsg.$linefeed;
                   9818: 
                   9819:         if (!$can_clone) {
                   9820: 	    return (0,$outcome);
                   9821: 	}
                   9822:     }
                   9823: 
1.444     albertel 9824: #
                   9825: # Open course
                   9826: #
                   9827:     my $crstype = lc($args->{'crstype'});
                   9828:     my %cenv=();
                   9829:     $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
                   9830:                                              $args->{'cdescr'},
                   9831:                                              $args->{'curl'},
                   9832:                                              $args->{'course_home'},
                   9833:                                              $args->{'nonstandard'},
                   9834:                                              $args->{'crscode'},
                   9835:                                              $args->{'ccuname'}.':'.
                   9836:                                              $args->{'ccdomain'},
                   9837:                                              $args->{'crstype'});
                   9838: 
                   9839:     # Note: The testing routines depend on this being output; see 
                   9840:     # Utils::Course. This needs to at least be output as a comment
                   9841:     # if anyone ever decides to not show this, and Utils::Course::new
                   9842:     # will need to be suitably modified.
1.541     raeburn  9843:     $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444     albertel 9844: #
                   9845: # Check if created correctly
                   9846: #
1.479     albertel 9847:     ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444     albertel 9848:     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541     raeburn  9849:     $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566     albertel 9850: 
1.444     albertel 9851: #
1.566     albertel 9852: # Do the cloning
                   9853: #   
                   9854:     if ($can_clone && $cloneid) {
                   9855: 	$clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
                   9856: 	if ($context ne 'auto') {
                   9857: 	    $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
                   9858: 	}
                   9859: 	$outcome .= $clonemsg.$linefeed;
                   9860: 	my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444     albertel 9861: # Copy all files
1.637     www      9862: 	&Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444     albertel 9863: # Restore URL
1.566     albertel 9864: 	$cenv{'url'}=$oldcenv{'url'};
1.444     albertel 9865: # Restore title
1.566     albertel 9866: 	$cenv{'description'}=$oldcenv{'description'};
1.444     albertel 9867: # Mark as cloned
1.566     albertel 9868: 	$cenv{'clonedfrom'}=$cloneid;
1.638     www      9869: # Need to clone grading mode
                   9870:         my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
                   9871:         $cenv{'grading'}=$newenv{'grading'};
                   9872: # Do not clone these environment entries
                   9873:         &Apache::lonnet::del('environment',
                   9874:                   ['default_enrollment_start_date',
                   9875:                    'default_enrollment_end_date',
                   9876:                    'question.email',
                   9877:                    'policy.email',
                   9878:                    'comment.email',
                   9879:                    'pch.users.denied',
1.725     raeburn  9880:                    'plc.users.denied',
                   9881:                    'hidefromcat',
                   9882:                    'categories'],
1.638     www      9883:                    $$crsudom,$$crsunum);
1.444     albertel 9884:     }
1.566     albertel 9885: 
1.444     albertel 9886: #
                   9887: # Set environment (will override cloned, if existing)
                   9888: #
                   9889:     my @sections = ();
                   9890:     my @xlists = ();
                   9891:     if ($args->{'crstype'}) {
                   9892:         $cenv{'type'}=$args->{'crstype'};
                   9893:     }
                   9894:     if ($args->{'crsid'}) {
                   9895:         $cenv{'courseid'}=$args->{'crsid'};
                   9896:     }
                   9897:     if ($args->{'crscode'}) {
                   9898:         $cenv{'internal.coursecode'}=$args->{'crscode'};
                   9899:     }
                   9900:     if ($args->{'crsquota'} ne '') {
                   9901:         $cenv{'internal.coursequota'}=$args->{'crsquota'};
                   9902:     } else {
                   9903:         $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
                   9904:     }
                   9905:     if ($args->{'ccuname'}) {
                   9906:         $cenv{'internal.courseowner'} = $args->{'ccuname'}.
                   9907:                                         ':'.$args->{'ccdomain'};
                   9908:     } else {
                   9909:         $cenv{'internal.courseowner'} = $args->{'curruser'};
                   9910:     }
                   9911:     my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
                   9912:     if ($args->{'crssections'}) {
                   9913:         $cenv{'internal.sectionnums'} = '';
                   9914:         if ($args->{'crssections'} =~ m/,/) {
                   9915:             @sections = split/,/,$args->{'crssections'};
                   9916:         } else {
                   9917:             $sections[0] = $args->{'crssections'};
                   9918:         }
                   9919:         if (@sections > 0) {
                   9920:             foreach my $item (@sections) {
                   9921:                 my ($sec,$gp) = split/:/,$item;
                   9922:                 my $class = $args->{'crscode'}.$sec;
                   9923:                 my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
                   9924:                 $cenv{'internal.sectionnums'} .= $item.',';
                   9925:                 unless ($addcheck eq 'ok') {
                   9926:                     push @badclasses, $class;
                   9927:                 }
                   9928:             }
                   9929:             $cenv{'internal.sectionnums'} =~ s/,$//;
                   9930:         }
                   9931:     }
                   9932: # do not hide course coordinator from staff listing, 
                   9933: # even if privileged
                   9934:     $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   9935: # add crosslistings
                   9936:     if ($args->{'crsxlist'}) {
                   9937:         $cenv{'internal.crosslistings'}='';
                   9938:         if ($args->{'crsxlist'} =~ m/,/) {
                   9939:             @xlists = split/,/,$args->{'crsxlist'};
                   9940:         } else {
                   9941:             $xlists[0] = $args->{'crsxlist'};
                   9942:         }
                   9943:         if (@xlists > 0) {
                   9944:             foreach my $item (@xlists) {
                   9945:                 my ($xl,$gp) = split/:/,$item;
                   9946:                 my $addcheck =  &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
                   9947:                 $cenv{'internal.crosslistings'} .= $item.',';
                   9948:                 unless ($addcheck eq 'ok') {
                   9949:                     push @badclasses, $xl;
                   9950:                 }
                   9951:             }
                   9952:             $cenv{'internal.crosslistings'} =~ s/,$//;
                   9953:         }
                   9954:     }
                   9955:     if ($args->{'autoadds'}) {
                   9956:         $cenv{'internal.autoadds'}=$args->{'autoadds'};
                   9957:     }
                   9958:     if ($args->{'autodrops'}) {
                   9959:         $cenv{'internal.autodrops'}=$args->{'autodrops'};
                   9960:     }
                   9961: # check for notification of enrollment changes
                   9962:     my @notified = ();
                   9963:     if ($args->{'notify_owner'}) {
                   9964:         if ($args->{'ccuname'} ne '') {
                   9965:             push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
                   9966:         }
                   9967:     }
                   9968:     if ($args->{'notify_dc'}) {
                   9969:         if ($uname ne '') { 
1.630     raeburn  9970:             push(@notified,$uname.':'.$udom);
1.444     albertel 9971:         }
                   9972:     }
                   9973:     if (@notified > 0) {
                   9974:         my $notifylist;
                   9975:         if (@notified > 1) {
                   9976:             $notifylist = join(',',@notified);
                   9977:         } else {
                   9978:             $notifylist = $notified[0];
                   9979:         }
                   9980:         $cenv{'internal.notifylist'} = $notifylist;
                   9981:     }
                   9982:     if (@badclasses > 0) {
                   9983:         my %lt=&Apache::lonlocal::texthash(
                   9984:                 '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',
                   9985:                 'dnhr' => 'does not have rights to access enrollment in these classes',
                   9986:                 'adby' => 'as determined by the policies of your institution on access to official classlists'
                   9987:         );
1.541     raeburn  9988:         my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
                   9989:                            ' ('.$lt{'adby'}.')';
                   9990:         if ($context eq 'auto') {
                   9991:             $outcome .= $badclass_msg.$linefeed;
1.566     albertel 9992:             $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541     raeburn  9993:             foreach my $item (@badclasses) {
                   9994:                 if ($context eq 'auto') {
                   9995:                     $outcome .= " - $item\n";
                   9996:                 } else {
                   9997:                     $outcome .= "<li>$item</li>\n";
                   9998:                 }
                   9999:             }
                   10000:             if ($context eq 'auto') {
                   10001:                 $outcome .= $linefeed;
                   10002:             } else {
1.566     albertel 10003:                 $outcome .= "</ul><br /><br /></div>\n";
1.541     raeburn  10004:             }
                   10005:         } 
1.444     albertel 10006:     }
                   10007:     if ($args->{'no_end_date'}) {
                   10008:         $args->{'endaccess'} = 0;
                   10009:     }
                   10010:     $cenv{'internal.autostart'}=$args->{'enrollstart'};
                   10011:     $cenv{'internal.autoend'}=$args->{'enrollend'};
                   10012:     $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
                   10013:     $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
                   10014:     if ($args->{'showphotos'}) {
                   10015:       $cenv{'internal.showphotos'}=$args->{'showphotos'};
                   10016:     }
                   10017:     $cenv{'internal.authtype'} = $args->{'authtype'};
                   10018:     $cenv{'internal.autharg'} = $args->{'autharg'}; 
                   10019:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
                   10020:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
1.541     raeburn  10021:             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'); 
                   10022:             if ($context eq 'auto') {
                   10023:                 $outcome .= $krb_msg;
                   10024:             } else {
1.566     albertel 10025:                 $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541     raeburn  10026:             }
                   10027:             $outcome .= $linefeed;
1.444     albertel 10028:         }
                   10029:     }
                   10030:     if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
                   10031:        if ($args->{'setpolicy'}) {
                   10032:            $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   10033:        }
                   10034:        if ($args->{'setcontent'}) {
                   10035:            $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   10036:        }
                   10037:     }
                   10038:     if ($args->{'reshome'}) {
                   10039: 	$cenv{'reshome'}=$args->{'reshome'}.'/';
                   10040: 	$cenv{'reshome'}=~s/\/+$/\//;
                   10041:     }
                   10042: #
                   10043: # course has keyed access
                   10044: #
                   10045:     if ($args->{'setkeys'}) {
                   10046:        $cenv{'keyaccess'}='yes';
                   10047:     }
                   10048: # if specified, key authority is not course, but user
                   10049: # only active if keyaccess is yes
                   10050:     if ($args->{'keyauth'}) {
1.487     albertel 10051: 	my ($user,$domain) = split(':',$args->{'keyauth'});
                   10052: 	$user = &LONCAPA::clean_username($user);
                   10053: 	$domain = &LONCAPA::clean_username($domain);
1.488     foxr     10054: 	if ($user ne '' && $domain ne '') {
1.487     albertel 10055: 	    $cenv{'keyauth'}=$user.':'.$domain;
1.444     albertel 10056: 	}
                   10057:     }
                   10058: 
                   10059:     if ($args->{'disresdis'}) {
                   10060:         $cenv{'pch.roles.denied'}='st';
                   10061:     }
                   10062:     if ($args->{'disablechat'}) {
                   10063:         $cenv{'plc.roles.denied'}='st';
                   10064:     }
                   10065: 
                   10066:     # Record we've not yet viewed the Course Initialization Helper for this 
                   10067:     # course
                   10068:     $cenv{'course.helper.not.run'} = 1;
                   10069:     #
                   10070:     # Use new Randomseed
                   10071:     #
                   10072:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
                   10073:     $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
                   10074:     #
                   10075:     # The encryption code and receipt prefix for this course
                   10076:     #
                   10077:     $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
                   10078:     $cenv{'internal.encpref'}=100+int(9*rand(99));
                   10079:     #
                   10080:     # By default, use standard grading
                   10081:     if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
                   10082: 
1.541     raeburn  10083:     $outcome .= $linefeed.&mt('Setting environment').': '.                 
                   10084:           &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 10085: #
                   10086: # Open all assignments
                   10087: #
                   10088:     if ($args->{'openall'}) {
                   10089:        my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
                   10090:        my %storecontent = ($storeunder         => time,
                   10091:                            $storeunder.'.type' => 'date_start');
                   10092:        
                   10093:        $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541     raeburn  10094:                  ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 10095:    }
                   10096: #
                   10097: # Set first page
                   10098: #
                   10099:     unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
                   10100: 	    || ($cloneid)) {
1.445     albertel 10101: 	use LONCAPA::map;
1.444     albertel 10102: 	$outcome .= &mt('Setting first resource').': ';
1.445     albertel 10103: 
                   10104: 	my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
                   10105:         my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
                   10106: 
1.444     albertel 10107:         $outcome .= ($fatal?$errtext:'read ok').' - ';
                   10108:         my $title; my $url;
                   10109:         if ($args->{'firstres'} eq 'syl') {
1.690     bisitz   10110: 	    $title=&mt('Syllabus');
1.444     albertel 10111:             $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
                   10112:         } else {
1.690     bisitz   10113:             $title=&mt('Navigate Contents');
1.444     albertel 10114:             $url='/adm/navmaps';
                   10115:         }
1.445     albertel 10116: 
                   10117:         $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
                   10118: 	(my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
                   10119: 
                   10120: 	if ($errtext) { $fatal=2; }
1.541     raeburn  10121:         $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444     albertel 10122:     }
1.566     albertel 10123: 
                   10124:     return (1,$outcome);
1.444     albertel 10125: }
                   10126: 
                   10127: ############################################################
                   10128: ############################################################
                   10129: 
1.378     raeburn  10130: sub course_type {
                   10131:     my ($cid) = @_;
                   10132:     if (!defined($cid)) {
                   10133:         $cid = $env{'request.course.id'};
                   10134:     }
1.404     albertel 10135:     if (defined($env{'course.'.$cid.'.type'})) {
                   10136:         return $env{'course.'.$cid.'.type'};
1.378     raeburn  10137:     } else {
                   10138:         return 'Course';
1.377     raeburn  10139:     }
                   10140: }
1.156     albertel 10141: 
1.406     raeburn  10142: sub group_term {
                   10143:     my $crstype = &course_type();
                   10144:     my %names = (
                   10145:                   'Course' => 'group',
                   10146:                   'Group' => 'team',
                   10147:                 );
                   10148:     return $names{$crstype};
                   10149: }
                   10150: 
1.156     albertel 10151: sub icon {
                   10152:     my ($file)=@_;
1.505     albertel 10153:     my $curfext = lc((split(/\./,$file))[-1]);
1.168     albertel 10154:     my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156     albertel 10155:     my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168     albertel 10156:     if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
                   10157: 	if (-e  $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
                   10158: 	          $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   10159: 	            $curfext.".gif") {
                   10160: 	    $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   10161: 		$curfext.".gif";
                   10162: 	}
                   10163:     }
1.249     albertel 10164:     return &lonhttpdurl($iconname);
1.154     albertel 10165: } 
1.84      albertel 10166: 
1.575     albertel 10167: sub lonhttpdurl {
1.692     www      10168: #
                   10169: # Had been used for "small fry" static images on separate port 8080.
                   10170: # Modify here if lightweight http functionality desired again.
                   10171: # Currently eliminated due to increasing firewall issues.
                   10172: #
1.575     albertel 10173:     my ($url)=@_;
1.692     www      10174:     return $url;
1.215     albertel 10175: }
                   10176: 
1.213     albertel 10177: sub connection_aborted {
                   10178:     my ($r)=@_;
                   10179:     $r->print(" ");$r->rflush();
                   10180:     my $c = $r->connection;
                   10181:     return $c->aborted();
                   10182: }
                   10183: 
1.221     foxr     10184: #    Escapes strings that may have embedded 's that will be put into
1.222     foxr     10185: #    strings as 'strings'.
                   10186: sub escape_single {
1.221     foxr     10187:     my ($input) = @_;
1.223     albertel 10188:     $input =~ s/\\/\\\\/g;	# Escape the \'s..(must be first)>
1.221     foxr     10189:     $input =~ s/\'/\\\'/g;	# Esacpe the 's....
                   10190:     return $input;
                   10191: }
1.223     albertel 10192: 
1.222     foxr     10193: #  Same as escape_single, but escape's "'s  This 
                   10194: #  can be used for  "strings"
                   10195: sub escape_double {
                   10196:     my ($input) = @_;
                   10197:     $input =~ s/\\/\\\\/g;	# Escape the /'s..(must be first)>
                   10198:     $input =~ s/\"/\\\"/g;	# Esacpe the "s....
                   10199:     return $input;
                   10200: }
1.223     albertel 10201:  
1.222     foxr     10202: #   Escapes the last element of a full URL.
                   10203: sub escape_url {
                   10204:     my ($url)   = @_;
1.238     raeburn  10205:     my @urlslices = split(/\//, $url,-1);
1.369     www      10206:     my $lastitem = &escape(pop(@urlslices));
1.223     albertel 10207:     return join('/',@urlslices).'/'.$lastitem;
1.222     foxr     10208: }
1.462     albertel 10209: 
                   10210: # -------------------------------------------------------- Initliaze user login
                   10211: sub init_user_environment {
1.463     albertel 10212:     my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462     albertel 10213:     my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
                   10214: 
                   10215:     my $public=($username eq 'public' && $domain eq 'public');
                   10216: 
                   10217: # See if old ID present, if so, remove
                   10218: 
                   10219:     my ($filename,$cookie,$userroles);
                   10220:     my $now=time;
                   10221: 
                   10222:     if ($public) {
                   10223: 	my $max_public=100;
                   10224: 	my $oldest;
                   10225: 	my $oldest_time=0;
                   10226: 	for(my $next=1;$next<=$max_public;$next++) {
                   10227: 	    if (-e $lonids."/publicuser_$next.id") {
                   10228: 		my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
                   10229: 		if ($mtime<$oldest_time || !$oldest_time) {
                   10230: 		    $oldest_time=$mtime;
                   10231: 		    $oldest=$next;
                   10232: 		}
                   10233: 	    } else {
                   10234: 		$cookie="publicuser_$next";
                   10235: 		last;
                   10236: 	    }
                   10237: 	}
                   10238: 	if (!$cookie) { $cookie="publicuser_$oldest"; }
                   10239:     } else {
1.463     albertel 10240: 	# if this isn't a robot, kill any existing non-robot sessions
                   10241: 	if (!$args->{'robot'}) {
                   10242: 	    opendir(DIR,$lonids);
                   10243: 	    while ($filename=readdir(DIR)) {
                   10244: 		if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
                   10245: 		    unlink($lonids.'/'.$filename);
                   10246: 		}
1.462     albertel 10247: 	    }
1.463     albertel 10248: 	    closedir(DIR);
1.462     albertel 10249: 	}
                   10250: # Give them a new cookie
1.463     albertel 10251: 	my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684     www      10252: 		                   : $now.$$.int(rand(10000)));
1.463     albertel 10253: 	$cookie="$username\_$id\_$domain\_$authhost";
1.462     albertel 10254:     
                   10255: # Initialize roles
                   10256: 
                   10257: 	$userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
                   10258:     }
                   10259: # ------------------------------------ Check browser type and MathML capability
                   10260: 
                   10261:     my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   10262:         $clientunicode,$clientos) = &decode_user_agent($r);
                   10263: 
                   10264: # -------------------------------------- Any accessibility options to remember?
                   10265:     if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
                   10266: 	foreach my $option ('imagesuppress','appletsuppress',
                   10267: 			    'embedsuppress','fontenhance','blackwhite') {
                   10268: 	    if ($form->{$option} eq 'true') {
                   10269: 		&Apache::lonnet::put('environment',{$option => 'on'},
                   10270: 				     $domain,$username);
                   10271: 	    } else {
                   10272: 		&Apache::lonnet::del('environment',[$option],
                   10273: 				     $domain,$username);
                   10274: 	    }
                   10275: 	}
                   10276:     }
                   10277: # ------------------------------------------------------------- Get environment
                   10278: 
                   10279:     my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
                   10280:     my ($tmp) = keys(%userenv);
                   10281:     if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   10282: 	# default remote control to off
                   10283: 	if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
                   10284:     } else {
                   10285: 	undef(%userenv);
                   10286:     }
                   10287:     if (($userenv{'interface'}) && (!$form->{'interface'})) {
                   10288: 	$form->{'interface'}=$userenv{'interface'};
                   10289:     }
                   10290:     $env{'environment.remote'}=$userenv{'remote'};
                   10291:     if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
                   10292: 
                   10293: # --------------- Do not trust query string to be put directly into environment
                   10294:     foreach my $option ('imagesuppress','appletsuppress',
                   10295: 			'embedsuppress','fontenhance','blackwhite',
                   10296: 			'interface','localpath','localres') {
                   10297: 	$form->{$option}=~s/[\n\r\=]//gs;
                   10298:     }
                   10299: # --------------------------------------------------------- Write first profile
                   10300: 
                   10301:     {
                   10302: 	my %initial_env = 
                   10303: 	    ("user.name"          => $username,
                   10304: 	     "user.domain"        => $domain,
                   10305: 	     "user.home"          => $authhost,
                   10306: 	     "browser.type"       => $clientbrowser,
                   10307: 	     "browser.version"    => $clientversion,
                   10308: 	     "browser.mathml"     => $clientmathml,
                   10309: 	     "browser.unicode"    => $clientunicode,
                   10310: 	     "browser.os"         => $clientos,
                   10311: 	     "server.domain"      => $Apache::lonnet::perlvar{'lonDefDomain'},
                   10312: 	     "request.course.fn"  => '',
                   10313: 	     "request.course.uri" => '',
                   10314: 	     "request.course.sec" => '',
                   10315: 	     "request.role"       => 'cm',
                   10316: 	     "request.role.adv"   => $env{'user.adv'},
                   10317: 	     "request.host"       => $ENV{'REMOTE_ADDR'},);
                   10318: 
                   10319:         if ($form->{'localpath'}) {
                   10320: 	    $initial_env{"browser.localpath"}  = $form->{'localpath'};
                   10321: 	    $initial_env{"browser.localres"}   = $form->{'localres'};
                   10322:         }
                   10323: 	
                   10324: 	if ($public) {
                   10325: 	    $initial_env{"environment.remote"} = "off";
                   10326: 	}
                   10327: 	if ($form->{'interface'}) {
                   10328: 	    $form->{'interface'}=~s/\W//gs;
                   10329: 	    $initial_env{"browser.interface"} = $form->{'interface'};
                   10330: 	    $env{'browser.interface'}=$form->{'interface'};
                   10331: 	    foreach my $option ('imagesuppress','appletsuppress',
                   10332: 				'embedsuppress','fontenhance','blackwhite') {
                   10333: 		if (($form->{$option} eq 'true') ||
                   10334: 		    ($userenv{$option} eq 'on')) {
                   10335: 		    $initial_env{"browser.$option"} = "on";
                   10336: 		}
                   10337: 	    }
                   10338: 	}
                   10339: 
1.724     raeburn  10340:         foreach my $tool ('aboutme','blog','portfolio') {
                   10341:             $userenv{'availabletools.'.$tool} = 
                   10342:                 &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
                   10343:         }
                   10344: 
1.765     raeburn  10345:         foreach my $crstype ('official','unofficial') {
                   10346:             $userenv{'canrequest.'.$crstype} =
                   10347:                 &Apache::lonnet::usertools_access($username,$domain,$crstype,
                   10348:                                                   'reload','requestcourses');
                   10349:         }
                   10350: 
1.462     albertel 10351: 	$env{'user.environment'} = "$lonids/$cookie.id";
                   10352: 	
                   10353: 	if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
                   10354: 		 &GDBM_WRCREAT(),0640)) {
                   10355: 	    &_add_to_env(\%disk_env,\%initial_env);
                   10356: 	    &_add_to_env(\%disk_env,\%userenv,'environment.');
                   10357: 	    &_add_to_env(\%disk_env,$userroles);
1.463     albertel 10358: 	    if (ref($args->{'extra_env'})) {
                   10359: 		&_add_to_env(\%disk_env,$args->{'extra_env'});
                   10360: 	    }
1.462     albertel 10361: 	    untie(%disk_env);
                   10362: 	} else {
1.705     tempelho 10363: 	    &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
                   10364: 			   'Could not create environment storage in lonauth: '.$!.'</span>');
1.462     albertel 10365: 	    return 'error: '.$!;
                   10366: 	}
                   10367:     }
                   10368:     $env{'request.role'}='cm';
                   10369:     $env{'request.role.adv'}=$env{'user.adv'};
                   10370:     $env{'browser.type'}=$clientbrowser;
                   10371: 
                   10372:     return $cookie;
                   10373: 
                   10374: }
                   10375: 
                   10376: sub _add_to_env {
                   10377:     my ($idf,$env_data,$prefix) = @_;
1.676     raeburn  10378:     if (ref($env_data) eq 'HASH') {
                   10379:         while (my ($key,$value) = each(%$env_data)) {
                   10380: 	    $idf->{$prefix.$key} = $value;
                   10381: 	    $env{$prefix.$key}   = $value;
                   10382:         }
1.462     albertel 10383:     }
                   10384: }
                   10385: 
1.685     tempelho 10386: # --- Get the symbolic name of a problem and the url
                   10387: sub get_symb {
                   10388:     my ($request,$silent) = @_;
1.726     raeburn  10389:     (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685     tempelho 10390:     my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
                   10391:     if ($symb eq '') {
                   10392:         if (!$silent) {
                   10393:             $request->print("Unable to handle ambiguous references:$url:.");
                   10394:             return ();
                   10395:         }
                   10396:     }
                   10397:     &Apache::lonenc::check_decrypt(\$symb);
                   10398:     return ($symb);
                   10399: }
                   10400: 
                   10401: # --------------------------------------------------------------Get annotation
                   10402: 
                   10403: sub get_annotation {
                   10404:     my ($symb,$enc) = @_;
                   10405: 
                   10406:     my $key = $symb;
                   10407:     if (!$enc) {
                   10408:         $key =
                   10409:             &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
                   10410:     }
                   10411:     my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
                   10412:     return $annotation{$key};
                   10413: }
                   10414: 
                   10415: sub clean_symb {
1.731     raeburn  10416:     my ($symb,$delete_enc) = @_;
1.685     tempelho 10417: 
                   10418:     &Apache::lonenc::check_decrypt(\$symb);
                   10419:     my $enc = $env{'request.enc'};
1.731     raeburn  10420:     if ($delete_enc) {
1.730     raeburn  10421:         delete($env{'request.enc'});
                   10422:     }
1.685     tempelho 10423: 
                   10424:     return ($symb,$enc);
                   10425: }
1.462     albertel 10426: 
1.41      ng       10427: =pod
                   10428: 
                   10429: =back
                   10430: 
1.112     bowersj2 10431: =cut
1.41      ng       10432: 
1.112     bowersj2 10433: 1;
                   10434: __END__;
1.41      ng       10435: 

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