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

1.10      albertel    1: # The LearningOnline Network with CAPA
1.1       albertel    2: # a pile of common routines
1.10      albertel    3: #
1.770   ! droeschl    4: # $Id: loncommon.pm,v 1.769 2009/03/17 20:07:45 schulted 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');
                    409: <script type="text/javascript" language="Javascript" >
                    410:     var stdeditbrowser;
1.558     albertel  411:     function openstdbrowser(formname,uname,udom,roleflag,ignorefilter) {
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.102     www       425:         var title = 'Student_Browser';
1.74      www       426:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    427:         options += ',width=700,height=600';
                    428:         stdeditbrowser = open(url,title,options,'1');
                    429:         stdeditbrowser.focus();
                    430:     }
                    431: </script>
                    432: ENDSTDBRW
                    433: }
1.42      matthew   434: 
1.74      www       435: sub selectstudent_link {
1.111     www       436:    my ($form,$unameele,$udomele)=@_;
1.258     albertel  437:    if ($env{'request.course.id'}) {  
1.302     albertel  438:        if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
                    439: 	   && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
                    440: 					'/'.$env{'request.course.sec'})) {
1.111     www       441: 	   return '';
                    442:        }
                    443:        return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
1.607     albertel  444:         '","'.$udomele.'");'."'>".&mt('Select User')."</a>";
1.74      www       445:    }
1.258     albertel  446:    if ($env{'request.role'}=~/^(au|dc|su)/) {
1.111     www       447:        return "<a href='".'javascript:openstdbrowser("'.$form.'","'.$unameele.
1.119     www       448:         '","'.$udomele.'",1);'."'>".&mt('Select User')."</a>";
1.111     www       449:    }
                    450:    return '';
1.91      www       451: }
                    452: 
1.653     raeburn   453: sub authorbrowser_javascript {
                    454:     return <<"ENDAUTHORBRW";
                    455: <script type="text/javascript">
                    456: var stdeditbrowser;
                    457: 
                    458: function openauthorbrowser(formname,udom) {
                    459:     var url = '/adm/pickauthor?';
                    460:     url += 'form='+formname+'&roledom='+udom;
                    461:     var title = 'Author_Browser';
                    462:     var options = 'scrollbars=1,resizable=1,menubar=0';
                    463:     options += ',width=700,height=600';
                    464:     stdeditbrowser = open(url,title,options,'1');
                    465:     stdeditbrowser.focus();
                    466: }
                    467: 
                    468: </script>
                    469: ENDAUTHORBRW
                    470: }
                    471: 
1.91      www       472: sub coursebrowser_javascript {
1.468     raeburn   473:     my ($domainfilter,$sec_element,$formname)=@_;
1.377     raeburn   474:     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   475:    my $output = '
1.538     albertel  476: <script type="text/javascript">
1.468     raeburn   477:     var stdeditbrowser;'."\n";
                    478:    $output .= <<"ENDSTDBRW";
1.377     raeburn   479:     function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,crstype) {
1.91      www       480:         var url = '/adm/pickcourse?';
1.468     raeburn   481:         var domainfilter = '';
                    482:         var formid = getFormIdByName(formname);
                    483:         if (formid > -1) {
                    484:             var domid = getIndexByName(formid,udom);
                    485:             if (domid > -1) {
                    486:                 if (document.forms[formid].elements[domid].type == 'select-one') {
                    487:                     domainfilter=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
                    488:                 }
                    489:                 if (document.forms[formid].elements[domid].type == 'hidden') {
                    490:                     domainfilter=document.forms[formid].elements[domid].value;
                    491:                 }
                    492:             }
1.91      www       493:         }
1.128     albertel  494:         if (domainfilter != null) {
                    495:            if (domainfilter != '') {
                    496:                url += 'domainfilter='+domainfilter+'&';
                    497: 	   }
                    498:         }
1.91      www       499:         url += 'form=' + formname + '&cnumelement='+uname+
1.187     albertel  500: 	                            '&cdomelement='+udom+
                    501:                                     '&cnameelement='+desc;
1.468     raeburn   502:         if (extra_element !=null && extra_element != '') {
1.594     raeburn   503:             if (formname == 'rolechoice' || formname == 'studentform') {
1.468     raeburn   504:                 url += '&roleelement='+extra_element;
                    505:                 if (domainfilter == null || domainfilter == '') {
                    506:                     url += '&domainfilter='+extra_element;
                    507:                 }
1.234     raeburn   508:             }
1.468     raeburn   509:             else {
                    510:                 if (formname == 'portform') {
                    511:                     url += '&setroles='+extra_element;
                    512:                 }
                    513:             }     
1.230     raeburn   514:         }
1.293     raeburn   515:         if (multflag !=null && multflag != '') {
                    516:             url += '&multiple='+multflag;
                    517:         }
1.377     raeburn   518:         if (crstype == 'Course/Group') {
                    519:             if (formname == 'cu') {
                    520:                 crstype = document.cu.crstype.options[document.cu.crstype.selectedIndex].value; 
                    521:                 if (crstype == "") {
                    522:                     alert("$crs_or_grp_alert");
                    523:                     return;
                    524:                 }
                    525:             }
                    526:         }
                    527:         if (crstype !=null && crstype != '') {
                    528:             url += '&type='+crstype;
                    529:         }
1.102     www       530:         var title = 'Course_Browser';
1.91      www       531:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    532:         options += ',width=700,height=600';
                    533:         stdeditbrowser = open(url,title,options,'1');
                    534:         stdeditbrowser.focus();
                    535:     }
1.468     raeburn   536: 
                    537:     function getFormIdByName(formname) {
                    538:         for (var i=0;i<document.forms.length;i++) {
                    539:             if (document.forms[i].name == formname) {
                    540:                 return i;
                    541:             }
                    542:         }
                    543:         return -1; 
                    544:     }
                    545: 
                    546:     function getIndexByName(formid,item) {
                    547:         for (var i=0;i<document.forms[formid].elements.length;i++) {
                    548:             if (document.forms[formid].elements[i].name == item) {
                    549:                 return i;
                    550:             }
                    551:         }
                    552:         return -1;
                    553:     }
1.91      www       554: ENDSTDBRW
1.468     raeburn   555:     if ($sec_element ne '') {
                    556:         $output .= &setsec_javascript($sec_element,$formname);
                    557:     }
                    558:     $output .= '
                    559: </script>';
                    560:     return $output;
                    561: }
                    562: 
                    563: sub setsec_javascript {
                    564:     my ($sec_element,$formname) = @_;
                    565:     my $setsections = qq|
                    566: function setSect(sectionlist) {
1.629     raeburn   567:     var sectionsArray = new Array();
                    568:     if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
                    569:         sectionsArray = sectionlist.split(",");
                    570:     }
1.468     raeburn   571:     var numSections = sectionsArray.length;
                    572:     document.$formname.$sec_element.length = 0;
                    573:     if (numSections == 0) {
                    574:         document.$formname.$sec_element.multiple=false;
                    575:         document.$formname.$sec_element.size=1;
                    576:         document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
                    577:     } else {
                    578:         if (numSections == 1) {
                    579:             document.$formname.$sec_element.multiple=false;
                    580:             document.$formname.$sec_element.size=1;
                    581:             document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
                    582:             document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
                    583:             document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
                    584:         } else {
                    585:             for (var i=0; i<numSections; i++) {
                    586:                 document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
                    587:             }
                    588:             document.$formname.$sec_element.multiple=true
                    589:             if (numSections < 3) {
                    590:                 document.$formname.$sec_element.size=numSections;
                    591:             } else {
                    592:                 document.$formname.$sec_element.size=3;
                    593:             }
                    594:             document.$formname.$sec_element.options[0].selected = false
                    595:         }
                    596:     }
1.91      www       597: }
1.468     raeburn   598: |;
                    599:     return $setsections;
                    600: }
                    601: 
1.91      www       602: 
                    603: sub selectcourse_link {
1.377     raeburn   604:    my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype)=@_;
1.492     albertel  605:    return "<a href='".'javascript:opencrsbrowser("'.$form.'","'.$unameele.
                    606:         '","'.$udomele.'","'.$desc.'","'.$extra_element.'","'.$multflag.'","'.$selecttype.'");'."'>".&mt('Select Course')."</a>";
1.74      www       607: }
1.42      matthew   608: 
1.653     raeburn   609: sub selectauthor_link {
                    610:    my ($form,$udom)=@_;
                    611:    return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
                    612:           &mt('Select Author').'</a>';
                    613: }
                    614: 
1.273     raeburn   615: sub check_uncheck_jscript {
                    616:     my $jscript = <<"ENDSCRT";
                    617: function checkAll(field) {
                    618:     if (field.length > 0) {
                    619:         for (i = 0; i < field.length; i++) {
                    620:             field[i].checked = true ;
                    621:         }
                    622:     } else {
                    623:         field.checked = true
                    624:     }
                    625: }
                    626:  
                    627: function uncheckAll(field) {
                    628:     if (field.length > 0) {
                    629:         for (i = 0; i < field.length; i++) {
                    630:             field[i].checked = false ;
1.543     albertel  631:         }
                    632:     } else {
1.273     raeburn   633:         field.checked = false ;
                    634:     }
                    635: }
                    636: ENDSCRT
                    637:     return $jscript;
                    638: }
                    639: 
1.656     www       640: sub select_timezone {
1.659     raeburn   641:    my ($name,$selected,$onchange,$includeempty)=@_;
                    642:    my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    643:    if ($includeempty) {
                    644:        $output .= '<option value=""';
                    645:        if (($selected eq '') || ($selected eq 'local')) {
                    646:            $output .= ' selected="selected" ';
                    647:        }
                    648:        $output .= '> </option>';
                    649:    }
1.657     raeburn   650:    my @timezones = DateTime::TimeZone->all_names;
                    651:    foreach my $tzone (@timezones) {
                    652:        $output.= '<option value="'.$tzone.'"';
                    653:        if ($tzone eq $selected) {
                    654:            $output.=' selected="selected"';
                    655:        }
                    656:        $output.=">$tzone</option>\n";
1.656     www       657:    }
                    658:    $output.="</select>";
                    659:    return $output;
                    660: }
1.273     raeburn   661: 
1.687     raeburn   662: sub select_datelocale {
                    663:     my ($name,$selected,$onchange,$includeempty)=@_;
                    664:     my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
                    665:     if ($includeempty) {
                    666:         $output .= '<option value=""';
                    667:         if ($selected eq '') {
                    668:             $output .= ' selected="selected" ';
                    669:         }
                    670:         $output .= '> </option>';
                    671:     }
                    672:     my (@possibles,%locale_names);
                    673:     my @locales = DateTime::Locale::Catalog::Locales;
                    674:     foreach my $locale (@locales) {
                    675:         if (ref($locale) eq 'HASH') {
                    676:             my $id = $locale->{'id'};
                    677:             if ($id ne '') {
                    678:                 my $en_terr = $locale->{'en_territory'};
                    679:                 my $native_terr = $locale->{'native_territory'};
1.695     raeburn   680:                 my @languages = &Apache::lonlocal::preferred_languages();
1.687     raeburn   681:                 if (grep(/^en$/,@languages) || !@languages) {
                    682:                     if ($en_terr ne '') {
                    683:                         $locale_names{$id} = '('.$en_terr.')';
                    684:                     } elsif ($native_terr ne '') {
                    685:                         $locale_names{$id} = $native_terr;
                    686:                     }
                    687:                 } else {
                    688:                     if ($native_terr ne '') {
                    689:                         $locale_names{$id} = $native_terr.' ';
                    690:                     } elsif ($en_terr ne '') {
                    691:                         $locale_names{$id} = '('.$en_terr.')';
                    692:                     }
                    693:                 }
                    694:                 push (@possibles,$id);
                    695:             }
                    696:         }
                    697:     }
                    698:     foreach my $item (sort(@possibles)) {
                    699:         $output.= '<option value="'.$item.'"';
                    700:         if ($item eq $selected) {
                    701:             $output.=' selected="selected"';
                    702:         }
                    703:         $output.=">$item";
                    704:         if ($locale_names{$item} ne '') {
                    705:             $output.="  $locale_names{$item}</option>\n";
                    706:         }
                    707:         $output.="</option>\n";
                    708:     }
                    709:     $output.="</select>";
                    710:     return $output;
                    711: }
                    712: 
1.42      matthew   713: =pod
1.36      matthew   714: 
1.648     raeburn   715: =item * &linked_select_forms(...)
1.36      matthew   716: 
                    717: linked_select_forms returns a string containing a <script></script> block
                    718: and html for two <select> menus.  The select menus will be linked in that
                    719: changing the value of the first menu will result in new values being placed
                    720: in the second menu.  The values in the select menu will appear in alphabetical
1.609     raeburn   721: order unless a defined order is provided.
1.36      matthew   722: 
                    723: linked_select_forms takes the following ordered inputs:
                    724: 
                    725: =over 4
                    726: 
1.112     bowersj2  727: =item * $formname, the name of the <form> tag
1.36      matthew   728: 
1.112     bowersj2  729: =item * $middletext, the text which appears between the <select> tags
1.36      matthew   730: 
1.112     bowersj2  731: =item * $firstdefault, the default value for the first menu
1.36      matthew   732: 
1.112     bowersj2  733: =item * $firstselectname, the name of the first <select> tag
1.36      matthew   734: 
1.112     bowersj2  735: =item * $secondselectname, the name of the second <select> tag
1.36      matthew   736: 
1.112     bowersj2  737: =item * $hashref, a reference to a hash containing the data for the menus.
1.36      matthew   738: 
1.609     raeburn   739: =item * $menuorder, the order of values in the first menu
                    740: 
1.41      ng        741: =back 
                    742: 
1.36      matthew   743: Below is an example of such a hash.  Only the 'text', 'default', and 
                    744: 'select2' keys must appear as stated.  keys(%menu) are the possible 
                    745: values for the first select menu.  The text that coincides with the 
1.41      ng        746: first menu value is given in $menu{$choice1}->{'text'}.  The values 
1.36      matthew   747: and text for the second menu are given in the hash pointed to by 
                    748: $menu{$choice1}->{'select2'}.  
                    749: 
1.112     bowersj2  750:  my %menu = ( A1 => { text =>"Choice A1" ,
                    751:                        default => "B3",
                    752:                        select2 => { 
                    753:                            B1 => "Choice B1",
                    754:                            B2 => "Choice B2",
                    755:                            B3 => "Choice B3",
                    756:                            B4 => "Choice B4"
1.609     raeburn   757:                            },
                    758:                        order => ['B4','B3','B1','B2'],
1.112     bowersj2  759:                    },
                    760:                A2 => { text =>"Choice A2" ,
                    761:                        default => "C2",
                    762:                        select2 => { 
                    763:                            C1 => "Choice C1",
                    764:                            C2 => "Choice C2",
                    765:                            C3 => "Choice C3"
1.609     raeburn   766:                            },
                    767:                        order => ['C2','C1','C3'],
1.112     bowersj2  768:                    },
                    769:                A3 => { text =>"Choice A3" ,
                    770:                        default => "D6",
                    771:                        select2 => { 
                    772:                            D1 => "Choice D1",
                    773:                            D2 => "Choice D2",
                    774:                            D3 => "Choice D3",
                    775:                            D4 => "Choice D4",
                    776:                            D5 => "Choice D5",
                    777:                            D6 => "Choice D6",
                    778:                            D7 => "Choice D7"
1.609     raeburn   779:                            },
                    780:                        order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112     bowersj2  781:                    }
                    782:                );
1.36      matthew   783: 
                    784: =cut
                    785: 
                    786: sub linked_select_forms {
                    787:     my ($formname,
                    788:         $middletext,
                    789:         $firstdefault,
                    790:         $firstselectname,
                    791:         $secondselectname, 
1.609     raeburn   792:         $hashref,
                    793:         $menuorder,
1.36      matthew   794:         ) = @_;
                    795:     my $second = "document.$formname.$secondselectname";
                    796:     my $first = "document.$formname.$firstselectname";
                    797:     # output the javascript to do the changing
                    798:     my $result = '';
1.219     albertel  799:     $result.="<script type=\"text/javascript\">\n";
1.36      matthew   800:     $result.="var select2data = new Object();\n";
                    801:     $" = '","';
                    802:     my $debug = '';
                    803:     foreach my $s1 (sort(keys(%$hashref))) {
                    804:         $result.="select2data.d_$s1 = new Object();\n";        
                    805:         $result.="select2data.d_$s1.def = new String('".
                    806:             $hashref->{$s1}->{'default'}."');\n";
1.609     raeburn   807:         $result.="select2data.d_$s1.values = new Array(";
1.36      matthew   808:         my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609     raeburn   809:         if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
                    810:             @s2values = @{$hashref->{$s1}->{'order'}};
                    811:         }
1.36      matthew   812:         $result.="\"@s2values\");\n";
                    813:         $result.="select2data.d_$s1.texts = new Array(";        
                    814:         my @s2texts;
                    815:         foreach my $value (@s2values) {
                    816:             push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
                    817:         }
                    818:         $result.="\"@s2texts\");\n";
                    819:     }
                    820:     $"=' ';
                    821:     $result.= <<"END";
                    822: 
                    823: function select1_changed() {
                    824:     // Determine new choice
                    825:     var newvalue = "d_" + $first.value;
                    826:     // update select2
                    827:     var values     = select2data[newvalue].values;
                    828:     var texts      = select2data[newvalue].texts;
                    829:     var select2def = select2data[newvalue].def;
                    830:     var i;
                    831:     // out with the old
                    832:     for (i = 0; i < $second.options.length; i++) {
                    833:         $second.options[i] = null;
                    834:     }
                    835:     // in with the nuclear
                    836:     for (i=0;i<values.length; i++) {
                    837:         $second.options[i] = new Option(values[i]);
1.143     matthew   838:         $second.options[i].value = values[i];
1.36      matthew   839:         $second.options[i].text = texts[i];
                    840:         if (values[i] == select2def) {
                    841:             $second.options[i].selected = true;
                    842:         }
                    843:     }
                    844: }
                    845: </script>
                    846: END
                    847:     # output the initial values for the selection lists
                    848:     $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed()\">\n";
1.609     raeburn   849:     my @order = sort(keys(%{$hashref}));
                    850:     if (ref($menuorder) eq 'ARRAY') {
                    851:         @order = @{$menuorder};
                    852:     }
                    853:     foreach my $value (@order) {
1.36      matthew   854:         $result.="    <option value=\"$value\" ";
1.253     albertel  855:         $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119     www       856:         $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36      matthew   857:     }
                    858:     $result .= "</select>\n";
                    859:     my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
                    860:     $result .= $middletext;
                    861:     $result .= "<select size=\"1\" name=\"$secondselectname\">\n";
                    862:     my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609     raeburn   863:     
                    864:     my @secondorder = sort(keys(%select2));
                    865:     if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
                    866:         @secondorder = @{$hashref->{$firstdefault}->{'order'}};
                    867:     }
                    868:     foreach my $value (@secondorder) {
1.36      matthew   869:         $result.="    <option value=\"$value\" ";        
1.253     albertel  870:         $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119     www       871:         $result.=">".&mt($select2{$value})."</option>\n";
1.36      matthew   872:     }
                    873:     $result .= "</select>\n";
                    874:     #    return $debug;
                    875:     return $result;
                    876: }   #  end of sub linked_select_forms {
                    877: 
1.45      matthew   878: =pod
1.44      bowersj2  879: 
1.648     raeburn   880: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height)
1.44      bowersj2  881: 
1.112     bowersj2  882: Returns a string corresponding to an HTML link to the given help
                    883: $topic, where $topic corresponds to the name of a .tex file in
                    884: /home/httpd/html/adm/help/tex, with underscores replaced by
                    885: spaces. 
                    886: 
                    887: $text will optionally be linked to the same topic, allowing you to
                    888: link text in addition to the graphic. If you do not want to link
                    889: text, but wish to specify one of the later parameters, pass an
                    890: empty string. 
                    891: 
                    892: $stayOnPage is a value that will be interpreted as a boolean. If true,
                    893: the link will not open a new window. If false, the link will open
                    894: a new window using Javascript. (Default is false.) 
                    895: 
                    896: $width and $height are optional numerical parameters that will
                    897: override the width and height of the popped up window, which may
                    898: be useful for certain help topics with big pictures included. 
1.44      bowersj2  899: 
                    900: =cut
                    901: 
                    902: sub help_open_topic {
1.48      bowersj2  903:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
                    904:     $text = "" if (not defined $text);
1.44      bowersj2  905:     $stayOnPage = 0 if (not defined $stayOnPage);
1.552     banghart  906:     if ($env{'browser.interface'} eq 'textual') {
1.79      www       907: 	$stayOnPage=1;
                    908:     }
1.44      bowersj2  909:     $width = 350 if (not defined $width);
                    910:     $height = 400 if (not defined $height);
                    911:     my $filename = $topic;
                    912:     $filename =~ s/ /_/g;
                    913: 
1.48      bowersj2  914:     my $template = "";
                    915:     my $link;
1.572     banghart  916:     
1.159     www       917:     $topic=~s/\W/\_/g;
1.44      bowersj2  918: 
1.572     banghart  919:     if (!$stayOnPage) {
1.72      bowersj2  920: 	$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  921:     } else {
1.48      bowersj2  922: 	$link = "/adm/help/${filename}.hlp";
                    923:     }
                    924: 
                    925:     # Add the text
1.755     neumanie  926:     if ($text ne "") {	
1.763     bisitz    927: 	$template.='<span class="LC_help_open_topic">'
                    928:                   .'<a target="_top" href="'.$link.'">'
                    929:                   .$text.'</a>';
1.48      bowersj2  930:     }
                    931: 
1.763     bisitz    932:     # (Always) Add the graphic
1.179     matthew   933:     my $title = &mt('Online Help');
1.667     raeburn   934:     my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.763     bisitz    935:     $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
                    936:               .'<img src="'.$helpicon.'" border="0"'
                    937:               .' alt="'.&mt('Help: [_1]',$topic).'"'
                    938:               .' title="'.$title.'"'
                    939:               .' /></a>';
                    940:     if ($text ne "") {	
                    941:         $template.='</span>';
                    942:     }
1.44      bowersj2  943:     return $template;
                    944: 
1.106     bowersj2  945: }
                    946: 
                    947: # This is a quicky function for Latex cheatsheet editing, since it 
                    948: # appears in at least four places
                    949: sub helpLatexCheatsheet {
1.732     raeburn   950:     my ($topic,$text,$not_author) = @_;
                    951:     my $out;
1.106     bowersj2  952:     my $addOther = '';
1.732     raeburn   953:     if ($topic) {
1.763     bisitz    954: 	$addOther = '<span>'.&Apache::loncommon::help_open_topic($topic,&mt($text),
                    955: 							       undef, undef, 600).
                    956: 								   '</span> ';
                    957:     }
                    958:     $out = '<span>' # Start cheatsheet
                    959: 	  .$addOther
                    960:           .'<span>'
                    961: 	  .&Apache::loncommon::help_open_topic('Greek_Symbols',&mt('Greek Symbols'),
                    962: 					       undef,undef,600)
                    963: 	  .'</span> <span>'
                    964: 	  .&Apache::loncommon::help_open_topic('Other_Symbols',&mt('Other Symbols'),
                    965: 					       undef,undef,600)
                    966: 	  .'</span>';
1.732     raeburn   967:     unless ($not_author) {
1.763     bisitz    968:         $out .= ' <span>'
                    969: 	       .&Apache::loncommon::help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),
                    970: 	                                            undef,undef,600)
                    971: 	       .'</span>';
1.732     raeburn   972:     }
1.763     bisitz    973:     $out .= '</span>'; # End cheatsheet
1.732     raeburn   974:     return $out;
1.172     www       975: }
                    976: 
1.430     albertel  977: sub general_help {
                    978:     my $helptopic='Student_Intro';
                    979:     if ($env{'request.role'}=~/^(ca|au)/) {
                    980: 	$helptopic='Authoring_Intro';
                    981:     } elsif ($env{'request.role'}=~/^cc/) {
                    982: 	$helptopic='Course_Coordination_Intro';
1.672     raeburn   983:     } elsif ($env{'request.role'}=~/^dc/) {
                    984:         $helptopic='Domain_Coordination_Intro';
1.430     albertel  985:     }
                    986:     return $helptopic;
                    987: }
                    988: 
                    989: sub update_help_link {
                    990:     my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
                    991:     my $origurl = $ENV{'REQUEST_URI'};
                    992:     $origurl=~s|^/~|/priv/|;
                    993:     my $timestamp = time;
                    994:     foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
                    995:         $$datum = &escape($$datum);
                    996:     }
                    997: 
                    998:     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";
                    999:     my $output .= <<"ENDOUTPUT";
                   1000: <script type="text/javascript">
                   1001: banner_link = '$banner_link';
                   1002: </script>
                   1003: ENDOUTPUT
                   1004:     return $output;
                   1005: }
                   1006: 
                   1007: # now just updates the help link and generates a blue icon
1.193     raeburn  1008: sub help_open_menu {
1.430     albertel 1009:     my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text) 
1.552     banghart 1010: 	= @_;    
1.430     albertel 1011:     $stayOnPage = 0 if (not defined $stayOnPage);
1.572     banghart 1012:     # only use pop-up help (stayOnPage == 0)
1.552     banghart 1013:     # if environment.remote is on (using remote control UI)
1.572     banghart 1014:     if ($env{'browser.interface'} eq 'textual' ||
                   1015:     	$env{'environment.remote'} eq 'off' ) {
1.552     banghart 1016:         $stayOnPage=1;
1.430     albertel 1017:     }
                   1018:     my $output;
                   1019:     if ($component_help) {
                   1020: 	if (!$text) {
                   1021: 	    $output=&help_open_topic($component_help,undef,$stayOnPage,
                   1022: 				       $width,$height);
                   1023: 	} else {
                   1024: 	    my $help_text;
                   1025: 	    $help_text=&unescape($topic);
                   1026: 	    $output='<table><tr><td>'.
                   1027: 		&help_open_topic($component_help,$help_text,$stayOnPage,
                   1028: 				 $width,$height).'</td></tr></table>';
                   1029: 	}
                   1030:     }
                   1031:     my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
                   1032:     return $output.$banner_link;
                   1033: }
                   1034: 
                   1035: sub top_nav_help {
                   1036:     my ($text) = @_;
1.436     albertel 1037:     $text = &mt($text);
1.572     banghart 1038:     my $stay_on_page = 
1.436     albertel 1039: 	($env{'browser.interface'}  eq 'textual' ||
                   1040: 	 $env{'environment.remote'} eq 'off' );
1.572     banghart 1041:     my $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1.436     albertel 1042: 	                     : "javascript:helpMenu('open')";
1.572     banghart 1043:     my $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1.436     albertel 1044: 
1.201     raeburn  1045:     my $title = &mt('Get help');
1.436     albertel 1046: 
                   1047:     return <<"END";
                   1048: $banner_link
                   1049:  <a href="$link" title="$title">$text</a>
                   1050: END
                   1051: }
                   1052: 
                   1053: sub help_menu_js {
                   1054:     my ($text) = @_;
                   1055: 
                   1056:     my $stayOnPage = 
                   1057: 	($env{'browser.interface'}  eq 'textual' ||
                   1058: 	 $env{'environment.remote'} eq 'off' );
                   1059: 
                   1060:     my $width = 620;
                   1061:     my $height = 600;
1.430     albertel 1062:     my $helptopic=&general_help();
                   1063:     my $details_link = '/adm/help/'.$helptopic.'.hlp';
1.261     albertel 1064:     my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331     albertel 1065:     my $start_page =
                   1066:         &Apache::loncommon::start_page('Help Menu', undef,
                   1067: 				       {'frameset'    => 1,
                   1068: 					'js_ready'    => 1,
                   1069: 					'add_entries' => {
                   1070: 					    'border' => '0',
1.579     raeburn  1071: 					    'rows'   => "110,*",},});
1.331     albertel 1072:     my $end_page =
                   1073:         &Apache::loncommon::end_page({'frameset' => 1,
                   1074: 				      'js_ready' => 1,});
                   1075: 
1.436     albertel 1076:     my $template .= <<"ENDTEMPLATE";
                   1077: <script type="text/javascript">
1.253     albertel 1078: // <!-- BEGIN LON-CAPA Internal
                   1079: // <![CDATA[
1.430     albertel 1080: var banner_link = '';
1.243     raeburn  1081: function helpMenu(target) {
                   1082:     var caller = this;
                   1083:     if (target == 'open') {
                   1084:         var newWindow = null;
                   1085:         try {
1.262     albertel 1086:             newWindow =  window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243     raeburn  1087:         }
                   1088:         catch(error) {
                   1089:             writeHelp(caller);
                   1090:             return;
                   1091:         }
                   1092:         if (newWindow) {
                   1093:             caller = newWindow;
                   1094:         }
1.193     raeburn  1095:     }
1.243     raeburn  1096:     writeHelp(caller);
                   1097:     return;
                   1098: }
                   1099: function writeHelp(caller) {
1.430     albertel 1100:     caller.document.writeln('$start_page<frame name="bannerframe"  src="'+banner_link+'" /><frame name="bodyframe" src="$details_link" /> $end_page')
1.243     raeburn  1101:     caller.document.close()
                   1102:     caller.focus()
1.193     raeburn  1103: }
1.253     albertel 1104: // ]]>
1.219     albertel 1105: // END LON-CAPA Internal -->
1.436     albertel 1106: </script>
1.193     raeburn  1107: ENDTEMPLATE
                   1108:     return $template;
                   1109: }
                   1110: 
1.172     www      1111: sub help_open_bug {
                   1112:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1113:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1114:     unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
                   1115:     $text = "" if (not defined $text);
                   1116:     $stayOnPage = 0 if (not defined $stayOnPage);
1.258     albertel 1117:     if ($env{'browser.interface'} eq 'textual' ||
                   1118: 	$env{'environment.remote'} eq 'off' ) {
1.172     www      1119: 	$stayOnPage=1;
                   1120:     }
1.184     albertel 1121:     $width = 600 if (not defined $width);
                   1122:     $height = 600 if (not defined $height);
1.172     www      1123: 
                   1124:     $topic=~s/\W+/\+/g;
                   1125:     my $link='';
                   1126:     my $template='';
1.379     albertel 1127:     my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&amp;bug_file_loc='.
                   1128: 	&escape($ENV{'REQUEST_URI'}).'&amp;component='.$topic;
1.172     www      1129:     if (!$stayOnPage)
                   1130:     {
                   1131: 	$link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1132:     }
                   1133:     else
                   1134:     {
                   1135: 	$link = $url;
                   1136:     }
                   1137:     # Add the text
                   1138:     if ($text ne "")
                   1139:     {
                   1140: 	$template .= 
                   1141:   "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1142:   "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172     www      1143:     }
                   1144: 
                   1145:     # Add the graphic
1.179     matthew  1146:     my $title = &mt('Report a Bug');
1.215     albertel 1147:     my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172     www      1148:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1149:  <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172     www      1150: ENDTEMPLATE
                   1151:     if ($text ne '') { $template.='</td></tr></table>' };
                   1152:     return $template;
                   1153: 
                   1154: }
                   1155: 
                   1156: sub help_open_faq {
                   1157:     my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258     albertel 1158:     unless ($env{'user.adv'}) { return ''; }
1.172     www      1159:     unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
                   1160:     $text = "" if (not defined $text);
                   1161:     $stayOnPage = 0 if (not defined $stayOnPage);
1.258     albertel 1162:     if ($env{'browser.interface'} eq 'textual' ||
                   1163: 	$env{'environment.remote'} eq 'off' ) {
1.172     www      1164: 	$stayOnPage=1;
                   1165:     }
                   1166:     $width = 350 if (not defined $width);
                   1167:     $height = 400 if (not defined $height);
                   1168: 
                   1169:     $topic=~s/\W+/\+/g;
                   1170:     my $link='';
                   1171:     my $template='';
                   1172:     my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
                   1173:     if (!$stayOnPage)
                   1174:     {
                   1175: 	$link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
                   1176:     }
                   1177:     else
                   1178:     {
                   1179: 	$link = $url;
                   1180:     }
                   1181: 
                   1182:     # Add the text
                   1183:     if ($text ne "")
                   1184:     {
                   1185: 	$template .= 
1.173     www      1186:   "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705     tempelho 1187:   "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172     www      1188:     }
                   1189: 
                   1190:     # Add the graphic
1.179     matthew  1191:     my $title = &mt('View the FAQ');
1.215     albertel 1192:     my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172     www      1193:     $template .= <<"ENDTEMPLATE";
1.436     albertel 1194:  <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172     www      1195: ENDTEMPLATE
                   1196:     if ($text ne '') { $template.='</td></tr></table>' };
                   1197:     return $template;
                   1198: 
1.44      bowersj2 1199: }
1.37      matthew  1200: 
1.180     matthew  1201: ###############################################################
                   1202: ###############################################################
                   1203: 
1.45      matthew  1204: =pod
                   1205: 
1.648     raeburn  1206: =item * &change_content_javascript():
1.256     matthew  1207: 
                   1208: This and the next function allow you to create small sections of an
                   1209: otherwise static HTML page that you can update on the fly with
                   1210: Javascript, even in Netscape 4.
                   1211: 
                   1212: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
                   1213: must be written to the HTML page once. It will prove the Javascript
                   1214: function "change(name, content)". Calling the change function with the
                   1215: name of the section 
                   1216: you want to update, matching the name passed to C<changable_area>, and
                   1217: the new content you want to put in there, will put the content into
                   1218: that area.
                   1219: 
                   1220: B<Note>: Netscape 4 only reserves enough space for the changable area
                   1221: to contain room for the original contents. You need to "make space"
                   1222: for whatever changes you wish to make, and be B<sure> to check your
                   1223: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
                   1224: it's adequate for updating a one-line status display, but little more.
                   1225: This script will set the space to 100% width, so you only need to
                   1226: worry about height in Netscape 4.
                   1227: 
                   1228: Modern browsers are much less limiting, and if you can commit to the
                   1229: user not using Netscape 4, this feature may be used freely with
                   1230: pretty much any HTML.
                   1231: 
                   1232: =cut
                   1233: 
                   1234: sub change_content_javascript {
                   1235:     # If we're on Netscape 4, we need to use Layer-based code
1.258     albertel 1236:     if ($env{'browser.type'} eq 'netscape' &&
                   1237: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1238: 	return (<<NETSCAPE4);
                   1239: 	function change(name, content) {
                   1240: 	    doc = document.layers[name+"___escape"].layers[0].document;
                   1241: 	    doc.open();
                   1242: 	    doc.write(content);
                   1243: 	    doc.close();
                   1244: 	}
                   1245: NETSCAPE4
                   1246:     } else {
                   1247: 	# Otherwise, we need to use semi-standards-compliant code
                   1248: 	# (technically, "innerHTML" isn't standard but the equivalent
                   1249: 	# is really scary, and every useful browser supports it
                   1250: 	return (<<DOMBASED);
                   1251: 	function change(name, content) {
                   1252: 	    element = document.getElementById(name);
                   1253: 	    element.innerHTML = content;
                   1254: 	}
                   1255: DOMBASED
                   1256:     }
                   1257: }
                   1258: 
                   1259: =pod
                   1260: 
1.648     raeburn  1261: =item * &changable_area($name,$origContent):
1.256     matthew  1262: 
                   1263: This provides a "changable area" that can be modified on the fly via
                   1264: the Javascript code provided in C<change_content_javascript>. $name is
                   1265: the name you will use to reference the area later; do not repeat the
                   1266: same name on a given HTML page more then once. $origContent is what
                   1267: the area will originally contain, which can be left blank.
                   1268: 
                   1269: =cut
                   1270: 
                   1271: sub changable_area {
                   1272:     my ($name, $origContent) = @_;
                   1273: 
1.258     albertel 1274:     if ($env{'browser.type'} eq 'netscape' &&
                   1275: 	$env{'browser.version'} =~ /^4\./) {
1.256     matthew  1276: 	# If this is netscape 4, we need to use the Layer tag
                   1277: 	return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
                   1278:     } else {
                   1279: 	return "<span id='$name'>$origContent</span>";
                   1280:     }
                   1281: }
                   1282: 
                   1283: =pod
                   1284: 
1.648     raeburn  1285: =item * &viewport_geometry_js 
1.590     raeburn  1286: 
                   1287: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
                   1288: 
                   1289: =cut
                   1290: 
                   1291: 
                   1292: sub viewport_geometry_js { 
                   1293:     return <<"GEOMETRY";
                   1294: var Geometry = {};
                   1295: function init_geometry() {
                   1296:     if (Geometry.init) { return };
                   1297:     Geometry.init=1;
                   1298:     if (window.innerHeight) {
                   1299:         Geometry.getViewportHeight   = function() { return window.innerHeight; };
                   1300:         Geometry.getViewportWidth   = function() { return window.innerWidth; };
                   1301:         Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
                   1302:         Geometry.getVerticalScroll   = function() { return window.pageYOffset; };
                   1303:     }
                   1304:     else if (document.documentElement && document.documentElement.clientHeight) {
                   1305:         Geometry.getViewportHeight =
                   1306:             function() { return document.documentElement.clientHeight; };
                   1307:         Geometry.getViewportWidth =
                   1308:             function() { return document.documentElement.clientWidth; };
                   1309: 
                   1310:         Geometry.getHorizontalScroll =
                   1311:             function() { return document.documentElement.scrollLeft; };
                   1312:         Geometry.getVerticalScroll =
                   1313:             function() { return document.documentElement.scrollTop; };
                   1314:     }
                   1315:     else if (document.body.clientHeight) {
                   1316:         Geometry.getViewportHeight =
                   1317:             function() { return document.body.clientHeight; };
                   1318:         Geometry.getViewportWidth =
                   1319:             function() { return document.body.clientWidth; };
                   1320:         Geometry.getHorizontalScroll =
                   1321:             function() { return document.body.scrollLeft; };
                   1322:         Geometry.getVerticalScroll =
                   1323:             function() { return document.body.scrollTop; };
                   1324:     }
                   1325: }
                   1326: 
                   1327: GEOMETRY
                   1328: }
                   1329: 
                   1330: =pod
                   1331: 
1.648     raeburn  1332: =item * &viewport_size_js()
1.590     raeburn  1333: 
                   1334: 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. 
                   1335: 
                   1336: =cut
                   1337: 
                   1338: sub viewport_size_js {
                   1339:     my $geometry = &viewport_geometry_js();
                   1340:     return <<"DIMS";
                   1341: 
                   1342: $geometry
                   1343: 
                   1344: function getViewportDims(width,height) {
                   1345:     init_geometry();
                   1346:     width.value = Geometry.getViewportWidth();
                   1347:     height.value = Geometry.getViewportHeight();
                   1348:     return;
                   1349: }
                   1350: 
                   1351: DIMS
                   1352: }
                   1353: 
                   1354: =pod
                   1355: 
1.648     raeburn  1356: =item * &resize_textarea_js()
1.565     albertel 1357: 
                   1358: emits the needed javascript to resize a textarea to be as big as possible
                   1359: 
                   1360: creates a function resize_textrea that takes two IDs first should be
                   1361: the id of the element to resize, second should be the id of a div that
                   1362: surrounds everything that comes after the textarea, this routine needs
                   1363: to be attached to the <body> for the onload and onresize events.
                   1364: 
1.648     raeburn  1365: =back
1.565     albertel 1366: 
                   1367: =cut
                   1368: 
                   1369: sub resize_textarea_js {
1.590     raeburn  1370:     my $geometry = &viewport_geometry_js();
1.565     albertel 1371:     return <<"RESIZE";
                   1372:     <script type="text/javascript">
1.590     raeburn  1373: $geometry
1.565     albertel 1374: 
1.588     albertel 1375: function getX(element) {
                   1376:     var x = 0;
                   1377:     while (element) {
                   1378: 	x += element.offsetLeft;
                   1379: 	element = element.offsetParent;
                   1380:     }
                   1381:     return x;
                   1382: }
                   1383: function getY(element) {
                   1384:     var y = 0;
                   1385:     while (element) {
                   1386: 	y += element.offsetTop;
                   1387: 	element = element.offsetParent;
                   1388:     }
                   1389:     return y;
                   1390: }
                   1391: 
                   1392: 
1.565     albertel 1393: function resize_textarea(textarea_id,bottom_id) {
                   1394:     init_geometry();
                   1395:     var textarea        = document.getElementById(textarea_id);
                   1396:     //alert(textarea);
                   1397: 
1.588     albertel 1398:     var textarea_top    = getY(textarea);
1.565     albertel 1399:     var textarea_height = textarea.offsetHeight;
                   1400:     var bottom          = document.getElementById(bottom_id);
1.588     albertel 1401:     var bottom_top      = getY(bottom);
1.565     albertel 1402:     var bottom_height   = bottom.offsetHeight;
                   1403:     var window_height   = Geometry.getViewportHeight();
1.588     albertel 1404:     var fudge           = 23;
1.565     albertel 1405:     var new_height      = window_height-fudge-textarea_top-bottom_height;
                   1406:     if (new_height < 300) {
                   1407: 	new_height = 300;
                   1408:     }
                   1409:     textarea.style.height=new_height+'px';
                   1410: }
                   1411: </script>
                   1412: RESIZE
                   1413: 
                   1414: }
                   1415: 
                   1416: =pod
                   1417: 
1.256     matthew  1418: =head1 Excel and CSV file utility routines
                   1419: 
                   1420: =over 4
                   1421: 
                   1422: =cut
                   1423: 
                   1424: ###############################################################
                   1425: ###############################################################
                   1426: 
                   1427: =pod
                   1428: 
1.648     raeburn  1429: =item * &csv_translate($text) 
1.37      matthew  1430: 
1.185     www      1431: Translate $text to allow it to be output as a 'comma separated values' 
1.37      matthew  1432: format.
                   1433: 
                   1434: =cut
                   1435: 
1.180     matthew  1436: ###############################################################
                   1437: ###############################################################
1.37      matthew  1438: sub csv_translate {
                   1439:     my $text = shift;
                   1440:     $text =~ s/\"/\"\"/g;
1.209     albertel 1441:     $text =~ s/\n/ /g;
1.37      matthew  1442:     return $text;
                   1443: }
1.180     matthew  1444: 
                   1445: ###############################################################
                   1446: ###############################################################
                   1447: 
                   1448: =pod
                   1449: 
1.648     raeburn  1450: =item * &define_excel_formats()
1.180     matthew  1451: 
                   1452: Define some commonly used Excel cell formats.
                   1453: 
                   1454: Currently supported formats:
                   1455: 
                   1456: =over 4
                   1457: 
                   1458: =item header
                   1459: 
                   1460: =item bold
                   1461: 
                   1462: =item h1
                   1463: 
                   1464: =item h2
                   1465: 
                   1466: =item h3
                   1467: 
1.256     matthew  1468: =item h4
                   1469: 
                   1470: =item i
                   1471: 
1.180     matthew  1472: =item date
                   1473: 
                   1474: =back
                   1475: 
                   1476: Inputs: $workbook
                   1477: 
                   1478: Returns: $format, a hash reference.
                   1479: 
                   1480: =cut
                   1481: 
                   1482: ###############################################################
                   1483: ###############################################################
                   1484: sub define_excel_formats {
                   1485:     my ($workbook) = @_;
                   1486:     my $format;
                   1487:     $format->{'header'} = $workbook->add_format(bold      => 1, 
                   1488:                                                 bottom    => 1,
                   1489:                                                 align     => 'center');
                   1490:     $format->{'bold'} = $workbook->add_format(bold=>1);
                   1491:     $format->{'h1'}   = $workbook->add_format(bold=>1, size=>18);
                   1492:     $format->{'h2'}   = $workbook->add_format(bold=>1, size=>16);
                   1493:     $format->{'h3'}   = $workbook->add_format(bold=>1, size=>14);
1.255     matthew  1494:     $format->{'h4'}   = $workbook->add_format(bold=>1, size=>12);
1.246     matthew  1495:     $format->{'i'}    = $workbook->add_format(italic=>1);
1.180     matthew  1496:     $format->{'date'} = $workbook->add_format(num_format=>
1.207     matthew  1497:                                             'mm/dd/yyyy hh:mm:ss');
1.180     matthew  1498:     return $format;
                   1499: }
                   1500: 
                   1501: ###############################################################
                   1502: ###############################################################
1.113     bowersj2 1503: 
                   1504: =pod
                   1505: 
1.648     raeburn  1506: =item * &create_workbook()
1.255     matthew  1507: 
                   1508: Create an Excel worksheet.  If it fails, output message on the
                   1509: request object and return undefs.
                   1510: 
                   1511: Inputs: Apache request object
                   1512: 
                   1513: Returns (undef) on failure, 
                   1514:     Excel worksheet object, scalar with filename, and formats 
                   1515:     from &Apache::loncommon::define_excel_formats on success
                   1516: 
                   1517: =cut
                   1518: 
                   1519: ###############################################################
                   1520: ###############################################################
                   1521: sub create_workbook {
                   1522:     my ($r) = @_;
                   1523:         #
                   1524:     # Create the excel spreadsheet
                   1525:     my $filename = '/prtspool/'.
1.258     albertel 1526:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255     matthew  1527:         time.'_'.rand(1000000000).'.xls';
                   1528:     my $workbook  = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
                   1529:     if (! defined($workbook)) {
                   1530:         $r->log_error("Error creating excel spreadsheet $filename: $!");
                   1531:         $r->print('<p>'.&mt("Unable to create new Excel file.  ".
                   1532:                             "This error has been logged.  ".
                   1533:                             "Please alert your LON-CAPA administrator").
                   1534:                   '</p>');
                   1535:         return (undef);
                   1536:     }
                   1537:     #
                   1538:     $workbook->set_tempdir('/home/httpd/perl/tmp');
                   1539:     #
                   1540:     my $format = &Apache::loncommon::define_excel_formats($workbook);
                   1541:     return ($workbook,$filename,$format);
                   1542: }
                   1543: 
                   1544: ###############################################################
                   1545: ###############################################################
                   1546: 
                   1547: =pod
                   1548: 
1.648     raeburn  1549: =item * &create_text_file()
1.113     bowersj2 1550: 
1.542     raeburn  1551: Create a file to write to and eventually make available to the user.
1.256     matthew  1552: If file creation fails, outputs an error message on the request object and 
                   1553: return undefs.
1.113     bowersj2 1554: 
1.256     matthew  1555: Inputs: Apache request object, and file suffix
1.113     bowersj2 1556: 
1.256     matthew  1557: Returns (undef) on failure, 
                   1558:     Filehandle and filename on success.
1.113     bowersj2 1559: 
                   1560: =cut
                   1561: 
1.256     matthew  1562: ###############################################################
                   1563: ###############################################################
                   1564: sub create_text_file {
                   1565:     my ($r,$suffix) = @_;
                   1566:     if (! defined($suffix)) { $suffix = 'txt'; };
                   1567:     my $fh;
                   1568:     my $filename = '/prtspool/'.
1.258     albertel 1569:         $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256     matthew  1570:         time.'_'.rand(1000000000).'.'.$suffix;
                   1571:     $fh = Apache::File->new('>/home/httpd'.$filename);
                   1572:     if (! defined($fh)) {
                   1573:         $r->log_error("Couldn't open $filename for output $!");
1.683     bisitz   1574:         $r->print(&mt('Problems occurred in creating the output file. '
                   1575:                      .'This error has been logged. '
                   1576:                      .'Please alert your LON-CAPA administrator.'));
1.113     bowersj2 1577:     }
1.256     matthew  1578:     return ($fh,$filename)
1.113     bowersj2 1579: }
                   1580: 
                   1581: 
1.256     matthew  1582: =pod 
1.113     bowersj2 1583: 
                   1584: =back
                   1585: 
                   1586: =cut
1.37      matthew  1587: 
                   1588: ###############################################################
1.33      matthew  1589: ##        Home server <option> list generating code          ##
                   1590: ###############################################################
1.35      matthew  1591: 
1.169     www      1592: # ------------------------------------------
                   1593: 
                   1594: sub domain_select {
                   1595:     my ($name,$value,$multiple)=@_;
                   1596:     my %domains=map { 
1.514     albertel 1597: 	$_ => $_.' '. &Apache::lonnet::domain($_,'description') 
1.512     albertel 1598:     } &Apache::lonnet::all_domains();
1.169     www      1599:     if ($multiple) {
                   1600: 	$domains{''}=&mt('Any domain');
1.550     albertel 1601: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287     albertel 1602: 	return &multiple_select_form($name,$value,4,\%domains);
1.169     www      1603:     } else {
1.550     albertel 1604: 	$domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.169     www      1605: 	return &select_form($name,$value,%domains);
                   1606:     }
                   1607: }
                   1608: 
1.282     albertel 1609: #-------------------------------------------
                   1610: 
                   1611: =pod
                   1612: 
1.519     raeburn  1613: =head1 Routines for form select boxes
                   1614: 
                   1615: =over 4
                   1616: 
1.648     raeburn  1617: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282     albertel 1618: 
                   1619: Returns a string containing a <select> element int multiple mode
                   1620: 
                   1621: 
                   1622: Args:
                   1623:   $name - name of the <select> element
1.506     raeburn  1624:   $value - scalar or array ref of values that should already be selected
1.282     albertel 1625:   $size - number of rows long the select element is
1.283     albertel 1626:   $hash - the elements should be 'option' => 'shown text'
1.282     albertel 1627:           (shown text should already have been &mt())
1.506     raeburn  1628:   $order - (optional) array ref of the order to show the elements in
1.283     albertel 1629: 
1.282     albertel 1630: =cut
                   1631: 
                   1632: #-------------------------------------------
1.169     www      1633: sub multiple_select_form {
1.284     albertel 1634:     my ($name,$value,$size,$hash,$order)=@_;
1.169     www      1635:     my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
                   1636:     my $output='';
1.191     matthew  1637:     if (! defined($size)) {
                   1638:         $size = 4;
1.283     albertel 1639:         if (scalar(keys(%$hash))<4) {
                   1640:             $size = scalar(keys(%$hash));
1.191     matthew  1641:         }
                   1642:     }
1.734     bisitz   1643:     $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501     banghart 1644:     my @order;
1.506     raeburn  1645:     if (ref($order) eq 'ARRAY')  {
                   1646:         @order = @{$order};
                   1647:     } else {
                   1648:         @order = sort(keys(%$hash));
1.501     banghart 1649:     }
                   1650:     if (exists($$hash{'select_form_order'})) {
                   1651:         @order = @{$$hash{'select_form_order'}};
                   1652:     }
                   1653:         
1.284     albertel 1654:     foreach my $key (@order) {
1.356     albertel 1655:         $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284     albertel 1656:         $output.='selected="selected" ' if ($selected{$key});
                   1657:         $output.='>'.$hash->{$key}."</option>\n";
1.169     www      1658:     }
                   1659:     $output.="</select>\n";
                   1660:     return $output;
                   1661: }
                   1662: 
1.88      www      1663: #-------------------------------------------
                   1664: 
                   1665: =pod
                   1666: 
1.648     raeburn  1667: =item * &select_form($defdom,$name,%hash)
1.88      www      1668: 
                   1669: Returns a string containing a <select name='$name' size='1'> form to 
                   1670: allow a user to select options from a hash option_name => displayed text.  
                   1671: See lonrights.pm for an example invocation and use.
                   1672: 
                   1673: =cut
                   1674: 
                   1675: #-------------------------------------------
                   1676: sub select_form {
                   1677:     my ($def,$name,%hash) = @_;
                   1678:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
1.128     albertel 1679:     my @keys;
                   1680:     if (exists($hash{'select_form_order'})) {
                   1681: 	@keys=@{$hash{'select_form_order'}};
                   1682:     } else {
                   1683: 	@keys=sort(keys(%hash));
                   1684:     }
1.356     albertel 1685:     foreach my $key (@keys) {
                   1686:         $selectform.=
                   1687: 	    '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
                   1688:             ($key eq $def ? 'selected="selected" ' : '').
                   1689:                 ">".&mt($hash{$key})."</option>\n";
1.88      www      1690:     }
                   1691:     $selectform.="</select>";
                   1692:     return $selectform;
                   1693: }
                   1694: 
1.475     www      1695: # For display filters
                   1696: 
                   1697: sub display_filter {
                   1698:     if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477     www      1699:     if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.714     bisitz   1700:     return '<span class="LC_nobreak"><label>'.&mt('Records [_1]',
1.475     www      1701: 			       &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
                   1702: 							   (&mt('all'),10,20,50,100,1000,10000))).
1.714     bisitz   1703: 	   '</label></span> <span class="LC_nobreak">'.
1.475     www      1704:            &mt('Filter [_1]',
1.477     www      1705: 	   &select_form($env{'form.displayfilter'},
                   1706: 			'displayfilter',
                   1707: 			('currentfolder' => 'Current folder/page',
                   1708: 			 'containing' => 'Containing phrase',
                   1709: 			 'none' => 'None'))).
1.714     bisitz   1710: 			 '<input type="text" name="containingphrase" size="30" value="'.&HTML::Entities::encode($env{'form.containingphrase'}).'" /></span>';
1.475     www      1711: }
                   1712: 
1.167     www      1713: sub gradeleveldescription {
                   1714:     my $gradelevel=shift;
                   1715:     my %gradelevels=(0 => 'Not specified',
                   1716: 		     1 => 'Grade 1',
                   1717: 		     2 => 'Grade 2',
                   1718: 		     3 => 'Grade 3',
                   1719: 		     4 => 'Grade 4',
                   1720: 		     5 => 'Grade 5',
                   1721: 		     6 => 'Grade 6',
                   1722: 		     7 => 'Grade 7',
                   1723: 		     8 => 'Grade 8',
                   1724: 		     9 => 'Grade 9',
                   1725: 		     10 => 'Grade 10',
                   1726: 		     11 => 'Grade 11',
                   1727: 		     12 => 'Grade 12',
                   1728: 		     13 => 'Grade 13',
                   1729: 		     14 => '100 Level',
                   1730: 		     15 => '200 Level',
                   1731: 		     16 => '300 Level',
                   1732: 		     17 => '400 Level',
                   1733: 		     18 => 'Graduate Level');
                   1734:     return &mt($gradelevels{$gradelevel});
                   1735: }
                   1736: 
1.163     www      1737: sub select_level_form {
                   1738:     my ($deflevel,$name)=@_;
                   1739:     unless ($deflevel) { $deflevel=0; }
1.167     www      1740:     my $selectform = "<select name=\"$name\" size=\"1\">\n";
                   1741:     for (my $i=0; $i<=18; $i++) {
                   1742:         $selectform.="<option value=\"$i\" ".
1.253     albertel 1743:             ($i==$deflevel ? 'selected="selected" ' : '').
1.167     www      1744:                 ">".&gradeleveldescription($i)."</option>\n";
                   1745:     }
                   1746:     $selectform.="</select>";
                   1747:     return $selectform;
1.163     www      1748: }
1.167     www      1749: 
1.35      matthew  1750: #-------------------------------------------
                   1751: 
1.45      matthew  1752: =pod
                   1753: 
1.743     raeburn  1754: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$autosubmit)
1.35      matthew  1755: 
                   1756: Returns a string containing a <select name='$name' size='1'> form to 
                   1757: allow a user to select the domain to preform an operation in.  
                   1758: See loncreateuser.pm for an example invocation and use.
                   1759: 
1.90      www      1760: If the $includeempty flag is set, it also includes an empty choice ("no domain
                   1761: selected");
                   1762: 
1.743     raeburn  1763: If the $showdomdesc flag is set, the domain name is followed by the domain description.
                   1764: 
                   1765: If the $autosubmit flag is set, the form containing the domain selector will be auto-submitted by an onchange action.  
1.563     raeburn  1766: 
1.35      matthew  1767: =cut
                   1768: 
                   1769: #-------------------------------------------
1.34      matthew  1770: sub select_dom_form {
1.743     raeburn  1771:     my ($defdom,$name,$includeempty,$showdomdesc,$autosubmit) = @_;
                   1772:     my $onchange;
                   1773:     if ($autosubmit) {
                   1774:         $onchange = ' onchange="this.form.submit()"';
                   1775:     }
1.550     albertel 1776:     my @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
1.90      www      1777:     if ($includeempty) { @domains=('',@domains); }
1.743     raeburn  1778:     my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356     albertel 1779:     foreach my $dom (@domains) {
                   1780:         $selectdomain.="<option value=\"$dom\" ".
1.563     raeburn  1781:             ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
                   1782:         if ($showdomdesc) {
                   1783:             if ($dom ne '') {
                   1784:                 my $domdesc = &Apache::lonnet::domain($dom,'description');
                   1785:                 if ($domdesc ne '') {
                   1786:                     $selectdomain .= ' ('.$domdesc.')';
                   1787:                 }
                   1788:             } 
                   1789:         }
                   1790:         $selectdomain .= "</option>\n";
1.34      matthew  1791:     }
                   1792:     $selectdomain.="</select>";
                   1793:     return $selectdomain;
                   1794: }
                   1795: 
1.35      matthew  1796: #-------------------------------------------
                   1797: 
1.45      matthew  1798: =pod
                   1799: 
1.648     raeburn  1800: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35      matthew  1801: 
1.586     raeburn  1802: input: 4 arguments (two required, two optional) - 
                   1803:     $domain - domain of new user
                   1804:     $name - name of form element
                   1805:     $default - Value of 'default' causes a default item to be first 
                   1806:                             option, and selected by default. 
                   1807:     $hide - Value of 'hide' causes hiding of the name of the server, 
                   1808:                             if 1 server found, or default, if 0 found.
1.594     raeburn  1809: output: returns 2 items: 
1.586     raeburn  1810: (a) form element which contains either:
                   1811:    (i) <select name="$name">
                   1812:         <option value="$hostid1">$hostid $servers{$hostid}</option>
                   1813:         <option value="$hostid2">$hostid $servers{$hostid}</option>       
                   1814:        </select>
                   1815:        form item if there are multiple library servers in $domain, or
                   1816:    (ii) an <input type="hidden" name="$name" value="$hostid" /> form item 
                   1817:        if there is only one library server in $domain.
                   1818: 
                   1819: (b) number of library servers found.
                   1820: 
                   1821: See loncreateuser.pm for example of use.
1.35      matthew  1822: 
                   1823: =cut
                   1824: 
                   1825: #-------------------------------------------
1.586     raeburn  1826: sub home_server_form_item {
                   1827:     my ($domain,$name,$default,$hide) = @_;
1.513     albertel 1828:     my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586     raeburn  1829:     my $result;
                   1830:     my $numlib = keys(%servers);
                   1831:     if ($numlib > 1) {
                   1832:         $result .= '<select name="'.$name.'" />'."\n";
                   1833:         if ($default) {
                   1834:             $result .= '<option value="default" selected>'.&mt('default').
                   1835:                        '</option>'."\n";
                   1836:         }
                   1837:         foreach my $hostid (sort(keys(%servers))) {
                   1838:             $result.= '<option value="'.$hostid.'">'.
                   1839: 	              $hostid.' '.$servers{$hostid}."</option>\n";
                   1840:         }
                   1841:         $result .= '</select>'."\n";
                   1842:     } elsif ($numlib == 1) {
                   1843:         my $hostid;
                   1844:         foreach my $item (keys(%servers)) {
                   1845:             $hostid = $item;
                   1846:         }
                   1847:         $result .= '<input type="hidden" name="'.$name.'" value="'.
                   1848:                    $hostid.'" />';
                   1849:                    if (!$hide) {
                   1850:                        $result .= $hostid.' '.$servers{$hostid};
                   1851:                    }
                   1852:                    $result .= "\n";
                   1853:     } elsif ($default) {
                   1854:         $result .= '<input type="hidden" name="'.$name.
                   1855:                    '" value="default" />';
                   1856:                    if (!$hide) {
                   1857:                        $result .= &mt('default');
                   1858:                    }
                   1859:                    $result .= "\n";
1.33      matthew  1860:     }
1.586     raeburn  1861:     return ($result,$numlib);
1.33      matthew  1862: }
1.112     bowersj2 1863: 
                   1864: =pod
                   1865: 
1.534     albertel 1866: =back 
                   1867: 
1.112     bowersj2 1868: =cut
1.87      matthew  1869: 
                   1870: ###############################################################
1.112     bowersj2 1871: ##                  Decoding User Agent                      ##
1.87      matthew  1872: ###############################################################
                   1873: 
                   1874: =pod
                   1875: 
1.112     bowersj2 1876: =head1 Decoding the User Agent
                   1877: 
                   1878: =over 4
                   1879: 
                   1880: =item * &decode_user_agent()
1.87      matthew  1881: 
                   1882: Inputs: $r
                   1883: 
                   1884: Outputs:
                   1885: 
                   1886: =over 4
                   1887: 
1.112     bowersj2 1888: =item * $httpbrowser
1.87      matthew  1889: 
1.112     bowersj2 1890: =item * $clientbrowser
1.87      matthew  1891: 
1.112     bowersj2 1892: =item * $clientversion
1.87      matthew  1893: 
1.112     bowersj2 1894: =item * $clientmathml
1.87      matthew  1895: 
1.112     bowersj2 1896: =item * $clientunicode
1.87      matthew  1897: 
1.112     bowersj2 1898: =item * $clientos
1.87      matthew  1899: 
                   1900: =back
                   1901: 
1.157     matthew  1902: =back 
                   1903: 
1.87      matthew  1904: =cut
                   1905: 
                   1906: ###############################################################
                   1907: ###############################################################
                   1908: sub decode_user_agent {
1.247     albertel 1909:     my ($r)=@_;
1.87      matthew  1910:     my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
                   1911:     my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
                   1912:     my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247     albertel 1913:     if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87      matthew  1914:     my $clientbrowser='unknown';
                   1915:     my $clientversion='0';
                   1916:     my $clientmathml='';
                   1917:     my $clientunicode='0';
                   1918:     for (my $i=0;$i<=$#browsertype;$i++) {
                   1919:         my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\:/,$browsertype[$i]);
                   1920: 	if (($httpbrowser=~/$match/i)  && ($httpbrowser!~/$notmatch/i)) {
                   1921: 	    $clientbrowser=$bname;
                   1922:             $httpbrowser=~/$vreg/i;
                   1923: 	    $clientversion=$1;
                   1924:             $clientmathml=($clientversion>=$minv);
                   1925:             $clientunicode=($clientversion>=$univ);
                   1926: 	}
                   1927:     }
                   1928:     my $clientos='unknown';
                   1929:     if (($httpbrowser=~/linux/i) ||
                   1930:         ($httpbrowser=~/unix/i) ||
                   1931:         ($httpbrowser=~/ux/i) ||
                   1932:         ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
                   1933:     if (($httpbrowser=~/vax/i) ||
                   1934:         ($httpbrowser=~/vms/i)) { $clientos='vms'; }
                   1935:     if ($httpbrowser=~/next/i) { $clientos='next'; }
                   1936:     if (($httpbrowser=~/mac/i) ||
                   1937:         ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
                   1938:     if ($httpbrowser=~/win/i) { $clientos='win'; }
                   1939:     if ($httpbrowser=~/embed/i) { $clientos='pda'; }
                   1940:     return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   1941:             $clientunicode,$clientos,);
                   1942: }
                   1943: 
1.32      matthew  1944: ###############################################################
                   1945: ##    Authentication changing form generation subroutines    ##
                   1946: ###############################################################
                   1947: ##
                   1948: ## All of the authform_xxxxxxx subroutines take their inputs in a
                   1949: ## hash, and have reasonable default values.
                   1950: ##
                   1951: ##    formname = the name given in the <form> tag.
1.35      matthew  1952: #-------------------------------------------
                   1953: 
1.45      matthew  1954: =pod
                   1955: 
1.112     bowersj2 1956: =head1 Authentication Routines
                   1957: 
                   1958: =over 4
                   1959: 
1.648     raeburn  1960: =item * &authform_xxxxxx()
1.35      matthew  1961: 
                   1962: The authform_xxxxxx subroutines provide javascript and html forms which 
                   1963: handle some of the conveniences required for authentication forms.  
                   1964: This is not an optimal method, but it works.  
                   1965: 
                   1966: =over 4
                   1967: 
1.112     bowersj2 1968: =item * authform_header
1.35      matthew  1969: 
1.112     bowersj2 1970: =item * authform_authorwarning
1.35      matthew  1971: 
1.112     bowersj2 1972: =item * authform_nochange
1.35      matthew  1973: 
1.112     bowersj2 1974: =item * authform_kerberos
1.35      matthew  1975: 
1.112     bowersj2 1976: =item * authform_internal
1.35      matthew  1977: 
1.112     bowersj2 1978: =item * authform_filesystem
1.35      matthew  1979: 
                   1980: =back
                   1981: 
1.648     raeburn  1982: See loncreateuser.pm for invocation and use examples.
1.157     matthew  1983: 
1.35      matthew  1984: =cut
                   1985: 
                   1986: #-------------------------------------------
1.32      matthew  1987: sub authform_header{  
                   1988:     my %in = (
                   1989:         formname => 'cu',
1.80      albertel 1990:         kerb_def_dom => '',
1.32      matthew  1991:         @_,
                   1992:     );
                   1993:     $in{'formname'} = 'document.' . $in{'formname'};
                   1994:     my $result='';
1.80      albertel 1995: 
                   1996: #---------------------------------------------- Code for upper case translation
                   1997:     my $Javascript_toUpperCase;
                   1998:     unless ($in{kerb_def_dom}) {
                   1999:         $Javascript_toUpperCase =<<"END";
                   2000:         switch (choice) {
                   2001:            case 'krb': currentform.elements[choicearg].value =
                   2002:                currentform.elements[choicearg].value.toUpperCase();
                   2003:                break;
                   2004:            default:
                   2005:         }
                   2006: END
                   2007:     } else {
                   2008:         $Javascript_toUpperCase = "";
                   2009:     }
                   2010: 
1.165     raeburn  2011:     my $radioval = "'nochange'";
1.591     raeburn  2012:     if (defined($in{'curr_authtype'})) {
                   2013:         if ($in{'curr_authtype'} ne '') {
                   2014:             $radioval = "'".$in{'curr_authtype'}."arg'";
                   2015:         }
1.174     matthew  2016:     }
1.165     raeburn  2017:     my $argfield = 'null';
1.591     raeburn  2018:     if (defined($in{'mode'})) {
1.165     raeburn  2019:         if ($in{'mode'} eq 'modifycourse')  {
1.591     raeburn  2020:             if (defined($in{'curr_autharg'})) {
                   2021:                 if ($in{'curr_autharg'} ne '') {
1.165     raeburn  2022:                     $argfield = "'$in{'curr_autharg'}'";
                   2023:                 }
                   2024:             }
                   2025:         }
                   2026:     }
                   2027: 
1.32      matthew  2028:     $result.=<<"END";
                   2029: var current = new Object();
1.165     raeburn  2030: current.radiovalue = $radioval;
                   2031: current.argfield = $argfield;
1.32      matthew  2032: 
                   2033: function changed_radio(choice,currentform) {
                   2034:     var choicearg = choice + 'arg';
                   2035:     // If a radio button in changed, we need to change the argfield
                   2036:     if (current.radiovalue != choice) {
                   2037:         current.radiovalue = choice;
                   2038:         if (current.argfield != null) {
                   2039:             currentform.elements[current.argfield].value = '';
                   2040:         }
                   2041:         if (choice == 'nochange') {
                   2042:             current.argfield = null;
                   2043:         } else {
                   2044:             current.argfield = choicearg;
                   2045:             switch(choice) {
                   2046:                 case 'krb': 
                   2047:                     currentform.elements[current.argfield].value = 
                   2048:                         "$in{'kerb_def_dom'}";
                   2049:                 break;
                   2050:               default:
                   2051:                 break;
                   2052:             }
                   2053:         }
                   2054:     }
                   2055:     return;
                   2056: }
1.22      www      2057: 
1.32      matthew  2058: function changed_text(choice,currentform) {
                   2059:     var choicearg = choice + 'arg';
                   2060:     if (currentform.elements[choicearg].value !='') {
1.80      albertel 2061:         $Javascript_toUpperCase
1.32      matthew  2062:         // clear old field
                   2063:         if ((current.argfield != choicearg) && (current.argfield != null)) {
                   2064:             currentform.elements[current.argfield].value = '';
                   2065:         }
                   2066:         current.argfield = choicearg;
                   2067:     }
                   2068:     set_auth_radio_buttons(choice,currentform);
                   2069:     return;
1.20      www      2070: }
1.32      matthew  2071: 
                   2072: function set_auth_radio_buttons(newvalue,currentform) {
                   2073:     var i=0;
                   2074:     while (i < currentform.login.length) {
                   2075:         if (currentform.login[i].value == newvalue) { break; }
                   2076:         i++;
                   2077:     }
                   2078:     if (i == currentform.login.length) {
                   2079:         return;
                   2080:     }
                   2081:     current.radiovalue = newvalue;
                   2082:     currentform.login[i].checked = true;
                   2083:     return;
                   2084: }
                   2085: END
                   2086:     return $result;
                   2087: }
                   2088: 
                   2089: sub authform_authorwarning{
                   2090:     my $result='';
1.144     matthew  2091:     $result='<i>'.
                   2092:         &mt('As a general rule, only authors or co-authors should be '.
                   2093:             'filesystem authenticated '.
                   2094:             '(which allows access to the server filesystem).')."</i>\n";
1.32      matthew  2095:     return $result;
                   2096: }
                   2097: 
                   2098: sub authform_nochange{  
                   2099:     my %in = (
                   2100:               formname => 'document.cu',
                   2101:               kerb_def_dom => 'MSU.EDU',
                   2102:               @_,
                   2103:           );
1.586     raeburn  2104:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'}); 
                   2105:     my $result;
                   2106:     if (keys(%can_assign) == 0) {
                   2107:         $result = &mt('Under you current role you are not permitted to change login settings for this user');  
                   2108:     } else {
                   2109:         $result = '<label>'.&mt('[_1] Do not change login data',
                   2110:                   '<input type="radio" name="login" value="nochange" '.
                   2111:                   'checked="checked" onclick="'.
1.281     albertel 2112:             "javascript:changed_radio('nochange',$in{'formname'});".'" />').
                   2113: 	    '</label>';
1.586     raeburn  2114:     }
1.32      matthew  2115:     return $result;
                   2116: }
                   2117: 
1.591     raeburn  2118: sub authform_kerberos {
1.32      matthew  2119:     my %in = (
                   2120:               formname => 'document.cu',
                   2121:               kerb_def_dom => 'MSU.EDU',
1.80      albertel 2122:               kerb_def_auth => 'krb4',
1.32      matthew  2123:               @_,
                   2124:               );
1.586     raeburn  2125:     my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
                   2126:         $autharg,$jscall);
                   2127:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.80      albertel 2128:     if ($in{'kerb_def_auth'} eq 'krb5') {
1.586     raeburn  2129:        $check5 = ' checked="on"';
1.80      albertel 2130:     } else {
1.586     raeburn  2131:        $check4 = ' checked="on"';
1.80      albertel 2132:     }
1.165     raeburn  2133:     $krbarg = $in{'kerb_def_dom'};
1.591     raeburn  2134:     if (defined($in{'curr_authtype'})) {
                   2135:         if ($in{'curr_authtype'} eq 'krb') {
1.586     raeburn  2136:             $krbcheck = ' checked="on"';
1.623     raeburn  2137:             if (defined($in{'mode'})) {
                   2138:                 if ($in{'mode'} eq 'modifyuser') {
                   2139:                     $krbcheck = '';
                   2140:                 }
                   2141:             }
1.591     raeburn  2142:             if (defined($in{'curr_kerb_ver'})) {
                   2143:                 if ($in{'curr_krb_ver'} eq '5') {
                   2144:                     $check5 = ' checked="on"';
                   2145:                     $check4 = '';
                   2146:                 } else {
                   2147:                     $check4 = ' checked="on"';
                   2148:                     $check5 = '';
                   2149:                 }
1.586     raeburn  2150:             }
1.591     raeburn  2151:             if (defined($in{'curr_autharg'})) {
1.165     raeburn  2152:                 $krbarg = $in{'curr_autharg'};
                   2153:             }
1.586     raeburn  2154:             if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591     raeburn  2155:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2156:                     $result = 
                   2157:     &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
                   2158:         $in{'curr_autharg'},$krbver);
                   2159:                 } else {
                   2160:                     $result =
                   2161:     &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
                   2162:                 }
                   2163:                 return $result; 
                   2164:             }
                   2165:         }
                   2166:     } else {
                   2167:         if ($authnum == 1) {
                   2168:             $authtype = '<input type="hidden" name="login" value="krb">';
1.165     raeburn  2169:         }
                   2170:     }
1.586     raeburn  2171:     if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
                   2172:         return;
1.587     raeburn  2173:     } elsif ($authtype eq '') {
1.591     raeburn  2174:         if (defined($in{'mode'})) {
1.587     raeburn  2175:             if ($in{'mode'} eq 'modifycourse') {
                   2176:                 if ($authnum == 1) {
                   2177:                     $authtype = '<input type="hidden" name="login" value="krb">';
                   2178:                 }
                   2179:             }
                   2180:         }
1.586     raeburn  2181:     }
                   2182:     $jscall = "javascript:changed_radio('krb',$in{'formname'});";
                   2183:     if ($authtype eq '') {
                   2184:         $authtype = '<input type="radio" name="login" value="krb" '.
                   2185:                     'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
                   2186:                     $krbcheck.' />';
                   2187:     }
                   2188:     if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
                   2189:         ($can_assign{'krb4'} && !$can_assign{'krb5'} && 
                   2190:          $in{'curr_authtype'} eq 'krb5') ||
                   2191:         (!$can_assign{'krb4'} && $can_assign{'krb5'} && 
                   2192:          $in{'curr_authtype'} eq 'krb4')) {
                   2193:         $result .= &mt
1.144     matthew  2194:         ('[_1] Kerberos authenticated with domain [_2] '.
1.281     albertel 2195:          '[_3] Version 4 [_4] Version 5 [_5]',
1.586     raeburn  2196:          '<label>'.$authtype,
1.281     albertel 2197:          '</label><input type="text" size="10" name="krbarg" '.
1.165     raeburn  2198:              'value="'.$krbarg.'" '.
1.144     matthew  2199:              'onchange="'.$jscall.'" />',
1.281     albertel 2200:          '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
                   2201:          '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
                   2202: 	 '</label>');
1.586     raeburn  2203:     } elsif ($can_assign{'krb4'}) {
                   2204:         $result .= &mt
                   2205:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2206:          '[_3] Version 4 [_4]',
                   2207:          '<label>'.$authtype,
                   2208:          '</label><input type="text" size="10" name="krbarg" '.
                   2209:              'value="'.$krbarg.'" '.
                   2210:              'onchange="'.$jscall.'" />',
                   2211:          '<label><input type="hidden" name="krbver" value="4" />',
                   2212:          '</label>');
                   2213:     } elsif ($can_assign{'krb5'}) {
                   2214:         $result .= &mt
                   2215:         ('[_1] Kerberos authenticated with domain [_2] '.
                   2216:          '[_3] Version 5 [_4]',
                   2217:          '<label>'.$authtype,
                   2218:          '</label><input type="text" size="10" name="krbarg" '.
                   2219:              'value="'.$krbarg.'" '.
                   2220:              'onchange="'.$jscall.'" />',
                   2221:          '<label><input type="hidden" name="krbver" value="5" />',
                   2222:          '</label>');
                   2223:     }
1.32      matthew  2224:     return $result;
                   2225: }
                   2226: 
                   2227: sub authform_internal{  
1.586     raeburn  2228:     my %in = (
1.32      matthew  2229:                 formname => 'document.cu',
                   2230:                 kerb_def_dom => 'MSU.EDU',
                   2231:                 @_,
                   2232:                 );
1.586     raeburn  2233:     my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
                   2234:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2235:     if (defined($in{'curr_authtype'})) {
                   2236:         if ($in{'curr_authtype'} eq 'int') {
1.586     raeburn  2237:             if ($can_assign{'int'}) {
                   2238:                 $intcheck = 'checked="on" ';
1.623     raeburn  2239:                 if (defined($in{'mode'})) {
                   2240:                     if ($in{'mode'} eq 'modifyuser') {
                   2241:                         $intcheck = '';
                   2242:                     }
                   2243:                 }
1.591     raeburn  2244:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2245:                     $intarg = $in{'curr_autharg'};
                   2246:                 }
                   2247:             } else {
                   2248:                 $result = &mt('Currently internally authenticated.');
                   2249:                 return $result;
1.165     raeburn  2250:             }
                   2251:         }
1.586     raeburn  2252:     } else {
                   2253:         if ($authnum == 1) {
                   2254:             $authtype = '<input type="hidden" name="login" value="int">';
                   2255:         }
                   2256:     }
                   2257:     if (!$can_assign{'int'}) {
                   2258:         return;
1.587     raeburn  2259:     } elsif ($authtype eq '') {
1.591     raeburn  2260:         if (defined($in{'mode'})) {
1.587     raeburn  2261:             if ($in{'mode'} eq 'modifycourse') {
                   2262:                 if ($authnum == 1) {
                   2263:                     $authtype = '<input type="hidden" name="login" value="int">';
                   2264:                 }
                   2265:             }
                   2266:         }
1.165     raeburn  2267:     }
1.586     raeburn  2268:     $jscall = "javascript:changed_radio('int',$in{'formname'});";
                   2269:     if ($authtype eq '') {
                   2270:         $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
                   2271:                     ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
                   2272:     }
1.605     bisitz   2273:     $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586     raeburn  2274:                $intarg.'" onchange="'.$jscall.'" />';
                   2275:     $result = &mt
1.144     matthew  2276:         ('[_1] Internally authenticated (with initial password [_2])',
1.586     raeburn  2277:          '<label>'.$authtype,'</label>'.$autharg);
1.620     www      2278:     $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  2279:     return $result;
                   2280: }
                   2281: 
                   2282: sub authform_local{  
                   2283:     my %in = (
                   2284:               formname => 'document.cu',
                   2285:               kerb_def_dom => 'MSU.EDU',
                   2286:               @_,
                   2287:               );
1.586     raeburn  2288:     my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
                   2289:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2290:     if (defined($in{'curr_authtype'})) {
                   2291:         if ($in{'curr_authtype'} eq 'loc') {
1.586     raeburn  2292:             if ($can_assign{'loc'}) {
                   2293:                 $loccheck = 'checked="on" ';
1.623     raeburn  2294:                 if (defined($in{'mode'})) {
                   2295:                     if ($in{'mode'} eq 'modifyuser') {
                   2296:                         $loccheck = '';
                   2297:                     }
                   2298:                 }
1.591     raeburn  2299:                 if (defined($in{'curr_autharg'})) {
1.586     raeburn  2300:                     $locarg = $in{'curr_autharg'};
                   2301:                 }
                   2302:             } else {
                   2303:                 $result = &mt('Currently using local (institutional) authentication.');
                   2304:                 return $result;
1.165     raeburn  2305:             }
                   2306:         }
1.586     raeburn  2307:     } else {
                   2308:         if ($authnum == 1) {
                   2309:             $authtype = '<input type="hidden" name="login" value="loc">';
                   2310:         }
                   2311:     }
                   2312:     if (!$can_assign{'loc'}) {
                   2313:         return;
1.587     raeburn  2314:     } elsif ($authtype eq '') {
1.591     raeburn  2315:         if (defined($in{'mode'})) {
1.587     raeburn  2316:             if ($in{'mode'} eq 'modifycourse') {
                   2317:                 if ($authnum == 1) {
                   2318:                     $authtype = '<input type="hidden" name="login" value="loc">';
                   2319:                 }
                   2320:             }
                   2321:         }
1.165     raeburn  2322:     }
1.586     raeburn  2323:     $jscall = "javascript:changed_radio('loc',$in{'formname'});";
                   2324:     if ($authtype eq '') {
                   2325:         $authtype = '<input type="radio" name="login" value="loc" '.
                   2326:                     $loccheck.' onchange="'.$jscall.'" onclick="'.
                   2327:                     $jscall.'" />';
                   2328:     }
                   2329:     $autharg = '<input type="text" size="10" name="locarg" value="'.
                   2330:                $locarg.'" onchange="'.$jscall.'" />';
                   2331:     $result = &mt('[_1] Local Authentication with argument [_2]',
                   2332:                   '<label>'.$authtype,'</label>'.$autharg);
1.32      matthew  2333:     return $result;
                   2334: }
                   2335: 
                   2336: sub authform_filesystem{  
                   2337:     my %in = (
                   2338:               formname => 'document.cu',
                   2339:               kerb_def_dom => 'MSU.EDU',
                   2340:               @_,
                   2341:               );
1.586     raeburn  2342:     my ($fsyscheck,$result,$authtype,$autharg,$jscall);
                   2343:     my ($authnum,%can_assign) =  &get_assignable_auth($in{'domain'});
1.591     raeburn  2344:     if (defined($in{'curr_authtype'})) {
                   2345:         if ($in{'curr_authtype'} eq 'fsys') {
1.586     raeburn  2346:             if ($can_assign{'fsys'}) {
                   2347:                 $fsyscheck = 'checked="on" ';
1.623     raeburn  2348:                 if (defined($in{'mode'})) {
                   2349:                     if ($in{'mode'} eq 'modifyuser') {
                   2350:                         $fsyscheck = '';
                   2351:                     }
                   2352:                 }
1.586     raeburn  2353:             } else {
                   2354:                 $result = &mt('Currently Filesystem Authenticated.');
                   2355:                 return $result;
                   2356:             }           
                   2357:         }
                   2358:     } else {
                   2359:         if ($authnum == 1) {
                   2360:             $authtype = '<input type="hidden" name="login" value="fsys">';
                   2361:         }
                   2362:     }
                   2363:     if (!$can_assign{'fsys'}) {
                   2364:         return;
1.587     raeburn  2365:     } elsif ($authtype eq '') {
1.591     raeburn  2366:         if (defined($in{'mode'})) {
1.587     raeburn  2367:             if ($in{'mode'} eq 'modifycourse') {
                   2368:                 if ($authnum == 1) {
                   2369:                     $authtype = '<input type="hidden" name="login" value="fsys">';
                   2370:                 }
                   2371:             }
                   2372:         }
1.586     raeburn  2373:     }
                   2374:     $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
                   2375:     if ($authtype eq '') {
                   2376:         $authtype = '<input type="radio" name="login" value="fsys" '.
                   2377:                     $fsyscheck.' onchange="'.$jscall.'" onclick="'.
                   2378:                     $jscall.'" />';
                   2379:     }
                   2380:     $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
                   2381:                ' onchange="'.$jscall.'" />';
                   2382:     $result = &mt
1.144     matthew  2383:         ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281     albertel 2384:          '<label><input type="radio" name="login" value="fsys" '.
1.586     raeburn  2385:          $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605     bisitz   2386:          '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144     matthew  2387:                   'onchange="'.$jscall.'" />');
1.32      matthew  2388:     return $result;
                   2389: }
                   2390: 
1.586     raeburn  2391: sub get_assignable_auth {
                   2392:     my ($dom) = @_;
                   2393:     if ($dom eq '') {
                   2394:         $dom = $env{'request.role.domain'};
                   2395:     }
                   2396:     my %can_assign = (
                   2397:                           krb4 => 1,
                   2398:                           krb5 => 1,
                   2399:                           int  => 1,
                   2400:                           loc  => 1,
                   2401:                      );
                   2402:     my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
                   2403:     if (ref($domconfig{'usercreation'}) eq 'HASH') {
                   2404:         if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
                   2405:             my $authhash = $domconfig{'usercreation'}{'authtypes'};
                   2406:             my $context;
                   2407:             if ($env{'request.role'} =~ /^au/) {
                   2408:                 $context = 'author';
                   2409:             } elsif ($env{'request.role'} =~ /^dc/) {
                   2410:                 $context = 'domain';
                   2411:             } elsif ($env{'request.course.id'}) {
                   2412:                 $context = 'course';
                   2413:             }
                   2414:             if ($context) {
                   2415:                 if (ref($authhash->{$context}) eq 'HASH') {
                   2416:                    %can_assign = %{$authhash->{$context}}; 
                   2417:                 }
                   2418:             }
                   2419:         }
                   2420:     }
                   2421:     my $authnum = 0;
                   2422:     foreach my $key (keys(%can_assign)) {
                   2423:         if ($can_assign{$key}) {
                   2424:             $authnum ++;
                   2425:         }
                   2426:     }
                   2427:     if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
                   2428:         $authnum --;
                   2429:     }
                   2430:     return ($authnum,%can_assign);
                   2431: }
                   2432: 
1.80      albertel 2433: ###############################################################
                   2434: ##    Get Kerberos Defaults for Domain                 ##
                   2435: ###############################################################
                   2436: ##
                   2437: ## Returns default kerberos version and an associated argument
                   2438: ## as listed in file domain.tab. If not listed, provides
                   2439: ## appropriate default domain and kerberos version.
                   2440: ##
                   2441: #-------------------------------------------
                   2442: 
                   2443: =pod
                   2444: 
1.648     raeburn  2445: =item * &get_kerberos_defaults()
1.80      albertel 2446: 
                   2447: get_kerberos_defaults($target_domain) returns the default kerberos
1.641     raeburn  2448: version and domain. If not found, it defaults to version 4 and the 
                   2449: domain of the server.
1.80      albertel 2450: 
1.648     raeburn  2451: =over 4
                   2452: 
1.80      albertel 2453: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
                   2454: 
1.648     raeburn  2455: =back
                   2456: 
                   2457: =back
                   2458: 
1.80      albertel 2459: =cut
                   2460: 
                   2461: #-------------------------------------------
                   2462: sub get_kerberos_defaults {
                   2463:     my $domain=shift;
1.641     raeburn  2464:     my ($krbdef,$krbdefdom);
                   2465:     my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
                   2466:     if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
                   2467:         $krbdef = $domdefaults{'auth_def'};
                   2468:         $krbdefdom = $domdefaults{'auth_arg_def'};
                   2469:     } else {
1.80      albertel 2470:         $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
                   2471:         my $krbdefdom=$1;
                   2472:         $krbdefdom=~tr/a-z/A-Z/;
                   2473:         $krbdef = "krb4";
                   2474:     }
                   2475:     return ($krbdef,$krbdefdom);
                   2476: }
1.112     bowersj2 2477: 
1.32      matthew  2478: 
1.46      matthew  2479: ###############################################################
                   2480: ##                Thesaurus Functions                        ##
                   2481: ###############################################################
1.20      www      2482: 
1.46      matthew  2483: =pod
1.20      www      2484: 
1.112     bowersj2 2485: =head1 Thesaurus Functions
                   2486: 
                   2487: =over 4
                   2488: 
1.648     raeburn  2489: =item * &initialize_keywords()
1.46      matthew  2490: 
                   2491: Initializes the package variable %Keywords if it is empty.  Uses the
                   2492: package variable $thesaurus_db_file.
                   2493: 
                   2494: =cut
                   2495: 
                   2496: ###################################################
                   2497: 
                   2498: sub initialize_keywords {
                   2499:     return 1 if (scalar keys(%Keywords));
                   2500:     # If we are here, %Keywords is empty, so fill it up
                   2501:     #   Make sure the file we need exists...
                   2502:     if (! -e $thesaurus_db_file) {
                   2503:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
                   2504:                                  " failed because it does not exist");
                   2505:         return 0;
                   2506:     }
                   2507:     #   Set up the hash as a database
                   2508:     my %thesaurus_db;
                   2509:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2510:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2511:         &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
                   2512:                                  $thesaurus_db_file);
                   2513:         return 0;
                   2514:     } 
                   2515:     #  Get the average number of appearances of a word.
                   2516:     my $avecount = $thesaurus_db{'average.count'};
                   2517:     #  Put keywords (those that appear > average) into %Keywords
                   2518:     while (my ($word,$data)=each (%thesaurus_db)) {
                   2519:         my ($count,undef) = split /:/,$data;
                   2520:         $Keywords{$word}++ if ($count > $avecount);
                   2521:     }
                   2522:     untie %thesaurus_db;
                   2523:     # Remove special values from %Keywords.
1.356     albertel 2524:     foreach my $value ('total.count','average.count') {
                   2525:         delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586     raeburn  2526:   }
1.46      matthew  2527:     return 1;
                   2528: }
                   2529: 
                   2530: ###################################################
                   2531: 
                   2532: =pod
                   2533: 
1.648     raeburn  2534: =item * &keyword($word)
1.46      matthew  2535: 
                   2536: Returns true if $word is a keyword.  A keyword is a word that appears more 
                   2537: than the average number of times in the thesaurus database.  Calls 
                   2538: &initialize_keywords
                   2539: 
                   2540: =cut
                   2541: 
                   2542: ###################################################
1.20      www      2543: 
                   2544: sub keyword {
1.46      matthew  2545:     return if (!&initialize_keywords());
                   2546:     my $word=lc(shift());
                   2547:     $word=~s/\W//g;
                   2548:     return exists($Keywords{$word});
1.20      www      2549: }
1.46      matthew  2550: 
                   2551: ###############################################################
                   2552: 
                   2553: =pod 
1.20      www      2554: 
1.648     raeburn  2555: =item * &get_related_words()
1.46      matthew  2556: 
1.160     matthew  2557: Look up a word in the thesaurus.  Takes a scalar argument and returns
1.46      matthew  2558: an array of words.  If the keyword is not in the thesaurus, an empty array
                   2559: will be returned.  The order of the words returned is determined by the
                   2560: database which holds them.
                   2561: 
                   2562: Uses global $thesaurus_db_file.
                   2563: 
                   2564: =cut
                   2565: 
                   2566: ###############################################################
                   2567: sub get_related_words {
                   2568:     my $keyword = shift;
                   2569:     my %thesaurus_db;
                   2570:     if (! -e $thesaurus_db_file) {
                   2571:         &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
                   2572:                                  "failed because the file does not exist");
                   2573:         return ();
                   2574:     }
                   2575:     if (! tie(%thesaurus_db,'GDBM_File',
1.53      albertel 2576:               $thesaurus_db_file,&GDBM_READER(),0640)){
1.46      matthew  2577:         return ();
                   2578:     } 
                   2579:     my @Words=();
1.429     www      2580:     my $count=0;
1.46      matthew  2581:     if (exists($thesaurus_db{$keyword})) {
1.356     albertel 2582: 	# The first element is the number of times
                   2583: 	# the word appears.  We do not need it now.
1.429     www      2584: 	my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
                   2585: 	my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
                   2586: 	my $threshold=$mostfrequentcount/10;
                   2587:         foreach my $possibleword (@RelatedWords) {
                   2588:             my ($word,$wordcount)=split(/\,/,$possibleword);
                   2589:             if ($wordcount>$threshold) {
                   2590: 		push(@Words,$word);
                   2591:                 $count++;
                   2592:                 if ($count>10) { last; }
                   2593: 	    }
1.20      www      2594:         }
                   2595:     }
1.46      matthew  2596:     untie %thesaurus_db;
                   2597:     return @Words;
1.14      harris41 2598: }
1.46      matthew  2599: 
1.112     bowersj2 2600: =pod
                   2601: 
                   2602: =back
                   2603: 
                   2604: =cut
1.61      www      2605: 
                   2606: # -------------------------------------------------------------- Plaintext name
1.81      albertel 2607: =pod
                   2608: 
1.112     bowersj2 2609: =head1 User Name Functions
                   2610: 
                   2611: =over 4
                   2612: 
1.648     raeburn  2613: =item * &plainname($uname,$udom,$first)
1.81      albertel 2614: 
1.112     bowersj2 2615: Takes a users logon name and returns it as a string in
1.226     albertel 2616: "first middle last generation" form 
                   2617: if $first is set to 'lastname' then it returns it as
                   2618: 'lastname generation, firstname middlename' if their is a lastname
1.81      albertel 2619: 
                   2620: =cut
1.61      www      2621: 
1.295     www      2622: 
1.81      albertel 2623: ###############################################################
1.61      www      2624: sub plainname {
1.226     albertel 2625:     my ($uname,$udom,$first)=@_;
1.537     albertel 2626:     return if (!defined($uname) || !defined($udom));
1.295     www      2627:     my %names=&getnames($uname,$udom);
1.226     albertel 2628:     my $name=&Apache::lonnet::format_name($names{'firstname'},
                   2629: 					  $names{'middlename'},
                   2630: 					  $names{'lastname'},
                   2631: 					  $names{'generation'},$first);
                   2632:     $name=~s/^\s+//;
1.62      www      2633:     $name=~s/\s+$//;
                   2634:     $name=~s/\s+/ /g;
1.353     albertel 2635:     if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62      www      2636:     return $name;
1.61      www      2637: }
1.66      www      2638: 
                   2639: # -------------------------------------------------------------------- Nickname
1.81      albertel 2640: =pod
                   2641: 
1.648     raeburn  2642: =item * &nickname($uname,$udom)
1.81      albertel 2643: 
                   2644: Gets a users name and returns it as a string as
                   2645: 
                   2646: "&quot;nickname&quot;"
1.66      www      2647: 
1.81      albertel 2648: if the user has a nickname or
                   2649: 
                   2650: "first middle last generation"
                   2651: 
                   2652: if the user does not
                   2653: 
                   2654: =cut
1.66      www      2655: 
                   2656: sub nickname {
                   2657:     my ($uname,$udom)=@_;
1.537     albertel 2658:     return if (!defined($uname) || !defined($udom));
1.295     www      2659:     my %names=&getnames($uname,$udom);
1.68      albertel 2660:     my $name=$names{'nickname'};
1.66      www      2661:     if ($name) {
                   2662:        $name='&quot;'.$name.'&quot;'; 
                   2663:     } else {
                   2664:        $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
                   2665: 	     $names{'lastname'}.' '.$names{'generation'};
                   2666:        $name=~s/\s+$//;
                   2667:        $name=~s/\s+/ /g;
                   2668:     }
                   2669:     return $name;
                   2670: }
                   2671: 
1.295     www      2672: sub getnames {
                   2673:     my ($uname,$udom)=@_;
1.537     albertel 2674:     return if (!defined($uname) || !defined($udom));
1.433     albertel 2675:     if ($udom eq 'public' && $uname eq 'public') {
                   2676: 	return ('lastname' => &mt('Public'));
                   2677:     }
1.295     www      2678:     my $id=$uname.':'.$udom;
                   2679:     my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
                   2680:     if ($cached) {
                   2681: 	return %{$names};
                   2682:     } else {
                   2683: 	my %loadnames=&Apache::lonnet::get('environment',
                   2684:                     ['firstname','middlename','lastname','generation','nickname'],
                   2685: 					 $udom,$uname);
                   2686: 	&Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
                   2687: 	return %loadnames;
                   2688:     }
                   2689: }
1.61      www      2690: 
1.542     raeburn  2691: # -------------------------------------------------------------------- getemails
1.648     raeburn  2692: 
1.542     raeburn  2693: =pod
                   2694: 
1.648     raeburn  2695: =item * &getemails($uname,$udom)
1.542     raeburn  2696: 
                   2697: Gets a user's email information and returns it as a hash with keys:
                   2698: notification, critnotification, permanentemail
                   2699: 
                   2700: For notification and critnotification, values are comma-separated lists 
1.648     raeburn  2701: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542     raeburn  2702:  
1.648     raeburn  2703: 
1.542     raeburn  2704: =cut
                   2705: 
1.648     raeburn  2706: 
1.466     albertel 2707: sub getemails {
                   2708:     my ($uname,$udom)=@_;
                   2709:     if ($udom eq 'public' && $uname eq 'public') {
                   2710: 	return;
                   2711:     }
1.467     www      2712:     if (!$udom) { $udom=$env{'user.domain'}; }
                   2713:     if (!$uname) { $uname=$env{'user.name'}; }
1.466     albertel 2714:     my $id=$uname.':'.$udom;
                   2715:     my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
                   2716:     if ($cached) {
                   2717: 	return %{$names};
                   2718:     } else {
                   2719: 	my %loadnames=&Apache::lonnet::get('environment',
                   2720:                     			   ['notification','critnotification',
                   2721: 					    'permanentemail'],
                   2722: 					   $udom,$uname);
                   2723: 	&Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
                   2724: 	return %loadnames;
                   2725:     }
                   2726: }
                   2727: 
1.551     albertel 2728: sub flush_email_cache {
                   2729:     my ($uname,$udom)=@_;
                   2730:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2731:     if (!$uname) { $uname=$env{'user.name'};   }
                   2732:     return if ($udom eq 'public' && $uname eq 'public');
                   2733:     my $id=$uname.':'.$udom;
                   2734:     &Apache::lonnet::devalidate_cache_new('emailscache',$id);
                   2735: }
                   2736: 
1.728     raeburn  2737: # -------------------------------------------------------------------- getlangs
                   2738: 
                   2739: =pod
                   2740: 
                   2741: =item * &getlangs($uname,$udom)
                   2742: 
                   2743: Gets a user's language preference and returns it as a hash with key:
                   2744: language.
                   2745: 
                   2746: =cut
                   2747: 
                   2748: 
                   2749: sub getlangs {
                   2750:     my ($uname,$udom) = @_;
                   2751:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2752:     if (!$uname) { $uname=$env{'user.name'};   }
                   2753:     my $id=$uname.':'.$udom;
                   2754:     my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
                   2755:     if ($cached) {
                   2756:         return %{$langs};
                   2757:     } else {
                   2758:         my %loadlangs=&Apache::lonnet::get('environment',['languages'],
                   2759:                                            $udom,$uname);
                   2760:         &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
                   2761:         return %loadlangs;
                   2762:     }
                   2763: }
                   2764: 
                   2765: sub flush_langs_cache {
                   2766:     my ($uname,$udom)=@_;
                   2767:     if (!$udom)  { $udom =$env{'user.domain'}; }
                   2768:     if (!$uname) { $uname=$env{'user.name'};   }
                   2769:     return if ($udom eq 'public' && $uname eq 'public');
                   2770:     my $id=$uname.':'.$udom;
                   2771:     &Apache::lonnet::devalidate_cache_new('userlangs',$id);
                   2772: }
                   2773: 
1.61      www      2774: # ------------------------------------------------------------------ Screenname
1.81      albertel 2775: 
                   2776: =pod
                   2777: 
1.648     raeburn  2778: =item * &screenname($uname,$udom)
1.81      albertel 2779: 
                   2780: Gets a users screenname and returns it as a string
                   2781: 
                   2782: =cut
1.61      www      2783: 
                   2784: sub screenname {
                   2785:     my ($uname,$udom)=@_;
1.258     albertel 2786:     if ($uname eq $env{'user.name'} &&
                   2787: 	$udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212     albertel 2788:     my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68      albertel 2789:     return $names{'screenname'};
1.62      www      2790: }
                   2791: 
1.212     albertel 2792: 
1.62      www      2793: # ------------------------------------------------------------- Message Wrapper
                   2794: 
                   2795: sub messagewrapper {
1.369     www      2796:     my ($link,$username,$domain,$subject,$text)=@_;
1.62      www      2797:     return 
1.441     albertel 2798:         '<a href="/adm/email?compose=individual&amp;'.
                   2799:         'recname='.$username.'&amp;recdom='.$domain.
                   2800: 	'&amp;subject='.&escape($subject).'&amp;text='.&escape($text).'" '.
1.200     matthew  2801:         'title="'.&mt('Send message').'">'.$link.'</a>';
1.74      www      2802: }
                   2803: # --------------------------------------------------------------- Notes Wrapper
                   2804: 
                   2805: sub noteswrapper {
                   2806:     my ($link,$un,$do)=@_;
                   2807:     return 
                   2808: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62      www      2809: }
                   2810: # ------------------------------------------------------------- Aboutme Wrapper
                   2811: 
                   2812: sub aboutmewrapper {
1.166     www      2813:     my ($link,$username,$domain,$target)=@_;
1.447     raeburn  2814:     if (!defined($username)  && !defined($domain)) {
                   2815:         return;
                   2816:     }
1.205     www      2817:     return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.756     weissno  2818: 	($target?' target="$target"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62      www      2819: }
                   2820: 
                   2821: # ------------------------------------------------------------ Syllabus Wrapper
                   2822: 
                   2823: 
                   2824: sub syllabuswrapper {
1.707     bisitz   2825:     my ($linktext,$coursedir,$domain)=@_;
1.208     matthew  2826:     return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61      www      2827: }
1.14      harris41 2828: 
1.208     matthew  2829: sub track_student_link {
1.268     albertel 2830:     my ($linktext,$sname,$sdom,$target,$start) = @_;
                   2831:     my $link ="/adm/trackstudent?";
1.208     matthew  2832:     my $title = 'View recent activity';
                   2833:     if (defined($sname) && $sname !~ /^\s*$/ &&
                   2834:         defined($sdom)  && $sdom  !~ /^\s*$/) {
1.268     albertel 2835:         $link .= "selected_student=$sname:$sdom";
1.208     matthew  2836:         $title .= ' of this student';
1.268     albertel 2837:     } 
1.208     matthew  2838:     if (defined($target) && $target !~ /^\s*$/) {
                   2839:         $target = qq{target="$target"};
                   2840:     } else {
                   2841:         $target = '';
                   2842:     }
1.268     albertel 2843:     if ($start) { $link.='&amp;start='.$start; }
1.554     albertel 2844:     $title = &mt($title);
                   2845:     $linktext = &mt($linktext);
1.448     albertel 2846:     return qq{<a href="$link" title="$title" $target>$linktext</a>}.
                   2847: 	&help_open_topic('View_recent_activity');
1.208     matthew  2848: }
                   2849: 
1.508     www      2850: # ===================================================== Display a student photo
                   2851: 
                   2852: 
1.509     albertel 2853: sub student_image_tag {
1.508     www      2854:     my ($domain,$user)=@_;
                   2855:     my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
                   2856:     if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
                   2857: 	return '<img src="'.$imgsrc.'" align="right" />';
                   2858:     } else {
                   2859: 	return '';
                   2860:     }
                   2861: }
                   2862: 
1.112     bowersj2 2863: =pod
                   2864: 
                   2865: =back
                   2866: 
                   2867: =head1 Access .tab File Data
                   2868: 
                   2869: =over 4
                   2870: 
1.648     raeburn  2871: =item * &languageids() 
1.112     bowersj2 2872: 
                   2873: returns list of all language ids
                   2874: 
                   2875: =cut
                   2876: 
1.14      harris41 2877: sub languageids {
1.16      harris41 2878:     return sort(keys(%language));
1.14      harris41 2879: }
                   2880: 
1.112     bowersj2 2881: =pod
                   2882: 
1.648     raeburn  2883: =item * &languagedescription() 
1.112     bowersj2 2884: 
                   2885: returns description of a specified language id
                   2886: 
                   2887: =cut
                   2888: 
1.14      harris41 2889: sub languagedescription {
1.125     www      2890:     my $code=shift;
                   2891:     return  ($supported_language{$code}?'* ':'').
                   2892:             $language{$code}.
1.126     www      2893: 	    ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145     www      2894: }
                   2895: 
                   2896: sub plainlanguagedescription {
                   2897:     my $code=shift;
                   2898:     return $language{$code};
                   2899: }
                   2900: 
                   2901: sub supportedlanguagecode {
                   2902:     my $code=shift;
                   2903:     return $supported_language{$code};
1.97      www      2904: }
                   2905: 
1.112     bowersj2 2906: =pod
                   2907: 
1.648     raeburn  2908: =item * &copyrightids() 
1.112     bowersj2 2909: 
                   2910: returns list of all copyrights
                   2911: 
                   2912: =cut
                   2913: 
                   2914: sub copyrightids {
                   2915:     return sort(keys(%cprtag));
                   2916: }
                   2917: 
                   2918: =pod
                   2919: 
1.648     raeburn  2920: =item * &copyrightdescription() 
1.112     bowersj2 2921: 
                   2922: returns description of a specified copyright id
                   2923: 
                   2924: =cut
                   2925: 
                   2926: sub copyrightdescription {
1.166     www      2927:     return &mt($cprtag{shift(@_)});
1.112     bowersj2 2928: }
1.197     matthew  2929: 
                   2930: =pod
                   2931: 
1.648     raeburn  2932: =item * &source_copyrightids() 
1.192     taceyjo1 2933: 
                   2934: returns list of all source copyrights
                   2935: 
                   2936: =cut
                   2937: 
                   2938: sub source_copyrightids {
                   2939:     return sort(keys(%scprtag));
                   2940: }
                   2941: 
                   2942: =pod
                   2943: 
1.648     raeburn  2944: =item * &source_copyrightdescription() 
1.192     taceyjo1 2945: 
                   2946: returns description of a specified source copyright id
                   2947: 
                   2948: =cut
                   2949: 
                   2950: sub source_copyrightdescription {
                   2951:     return &mt($scprtag{shift(@_)});
                   2952: }
1.112     bowersj2 2953: 
                   2954: =pod
                   2955: 
1.648     raeburn  2956: =item * &filecategories() 
1.112     bowersj2 2957: 
                   2958: returns list of all file categories
                   2959: 
                   2960: =cut
                   2961: 
                   2962: sub filecategories {
                   2963:     return sort(keys(%category_extensions));
                   2964: }
                   2965: 
                   2966: =pod
                   2967: 
1.648     raeburn  2968: =item * &filecategorytypes() 
1.112     bowersj2 2969: 
                   2970: returns list of file types belonging to a given file
                   2971: category
                   2972: 
                   2973: =cut
                   2974: 
                   2975: sub filecategorytypes {
1.356     albertel 2976:     my ($cat) = @_;
                   2977:     return @{$category_extensions{lc($cat)}};
1.112     bowersj2 2978: }
                   2979: 
                   2980: =pod
                   2981: 
1.648     raeburn  2982: =item * &fileembstyle() 
1.112     bowersj2 2983: 
                   2984: returns embedding style for a specified file type
                   2985: 
                   2986: =cut
                   2987: 
                   2988: sub fileembstyle {
                   2989:     return $fe{lc(shift(@_))};
1.169     www      2990: }
                   2991: 
1.351     www      2992: sub filemimetype {
                   2993:     return $fm{lc(shift(@_))};
                   2994: }
                   2995: 
1.169     www      2996: 
                   2997: sub filecategoryselect {
                   2998:     my ($name,$value)=@_;
1.189     matthew  2999:     return &select_form($value,$name,
1.169     www      3000: 			'' => &mt('Any category'),
                   3001: 			map { $_,$_ } sort(keys(%category_extensions)));
1.112     bowersj2 3002: }
                   3003: 
                   3004: =pod
                   3005: 
1.648     raeburn  3006: =item * &filedescription() 
1.112     bowersj2 3007: 
                   3008: returns description for a specified file type
                   3009: 
                   3010: =cut
                   3011: 
                   3012: sub filedescription {
1.188     matthew  3013:     my $file_description = $fd{lc(shift())};
                   3014:     $file_description =~ s:([\[\]]):~$1:g;
                   3015:     return &mt($file_description);
1.112     bowersj2 3016: }
                   3017: 
                   3018: =pod
                   3019: 
1.648     raeburn  3020: =item * &filedescriptionex() 
1.112     bowersj2 3021: 
                   3022: returns description for a specified file type with
                   3023: extra formatting
                   3024: 
                   3025: =cut
                   3026: 
                   3027: sub filedescriptionex {
                   3028:     my $ex=shift;
1.188     matthew  3029:     my $file_description = $fd{lc($ex)};
                   3030:     $file_description =~ s:([\[\]]):~$1:g;
                   3031:     return '.'.$ex.' '.&mt($file_description);
1.112     bowersj2 3032: }
                   3033: 
                   3034: # End of .tab access
                   3035: =pod
                   3036: 
                   3037: =back
                   3038: 
                   3039: =cut
                   3040: 
                   3041: # ------------------------------------------------------------------ File Types
                   3042: sub fileextensions {
                   3043:     return sort(keys(%fe));
                   3044: }
                   3045: 
1.97      www      3046: # ----------------------------------------------------------- Display Languages
                   3047: # returns a hash with all desired display languages
                   3048: #
                   3049: 
                   3050: sub display_languages {
                   3051:     my %languages=();
1.695     raeburn  3052:     foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356     albertel 3053: 	$languages{$lang}=1;
1.97      www      3054:     }
                   3055:     &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258     albertel 3056:     if ($env{'form.displaylanguage'}) {
1.356     albertel 3057: 	foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
                   3058: 	    $languages{$lang}=1;
1.97      www      3059:         }
                   3060:     }
                   3061:     return %languages;
1.14      harris41 3062: }
                   3063: 
1.582     albertel 3064: sub languages {
                   3065:     my ($possible_langs) = @_;
1.695     raeburn  3066:     my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582     albertel 3067:     if (!ref($possible_langs)) {
                   3068: 	if( wantarray ) {
                   3069: 	    return @preferred_langs;
                   3070: 	} else {
                   3071: 	    return $preferred_langs[0];
                   3072: 	}
                   3073:     }
                   3074:     my %possibilities = map { $_ => 1 } (@$possible_langs);
                   3075:     my @preferred_possibilities;
                   3076:     foreach my $preferred_lang (@preferred_langs) {
                   3077: 	if (exists($possibilities{$preferred_lang})) {
                   3078: 	    push(@preferred_possibilities, $preferred_lang);
                   3079: 	}
                   3080:     }
                   3081:     if( wantarray ) {
                   3082: 	return @preferred_possibilities;
                   3083:     }
                   3084:     return $preferred_possibilities[0];
                   3085: }
                   3086: 
1.742     raeburn  3087: sub user_lang {
                   3088:     my ($touname,$toudom,$fromcid) = @_;
                   3089:     my @userlangs;
                   3090:     if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
                   3091:         @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
                   3092:                     $env{'course.'.$fromcid.'.languages'}));
                   3093:     } else {
                   3094:         my %langhash = &getlangs($touname,$toudom);
                   3095:         if ($langhash{'languages'} ne '') {
                   3096:             @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
                   3097:         } else {
                   3098:             my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
                   3099:             if ($domdefs{'lang_def'} ne '') {
                   3100:                 @userlangs = ($domdefs{'lang_def'});
                   3101:             }
                   3102:         }
                   3103:     }
                   3104:     my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
                   3105:     my $user_lh = Apache::localize->get_handle(@languages);
                   3106:     return $user_lh;
                   3107: }
                   3108: 
                   3109: 
1.112     bowersj2 3110: ###############################################################
                   3111: ##               Student Answer Attempts                     ##
                   3112: ###############################################################
                   3113: 
                   3114: =pod
                   3115: 
                   3116: =head1 Alternate Problem Views
                   3117: 
                   3118: =over 4
                   3119: 
1.648     raeburn  3120: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112     bowersj2 3121:     $getattempt, $regexp, $gradesub)
                   3122: 
                   3123: Return string with previous attempt on problem. Arguments:
                   3124: 
                   3125: =over 4
                   3126: 
                   3127: =item * $symb: Problem, including path
                   3128: 
                   3129: =item * $username: username of the desired student
                   3130: 
                   3131: =item * $domain: domain of the desired student
1.14      harris41 3132: 
1.112     bowersj2 3133: =item * $course: Course ID
1.14      harris41 3134: 
1.112     bowersj2 3135: =item * $getattempt: Leave blank for all attempts, otherwise put
                   3136:     something
1.14      harris41 3137: 
1.112     bowersj2 3138: =item * $regexp: if string matches this regexp, the string will be
                   3139:     sent to $gradesub
1.14      harris41 3140: 
1.112     bowersj2 3141: =item * $gradesub: routine that processes the string if it matches $regexp
1.14      harris41 3142: 
1.112     bowersj2 3143: =back
1.14      harris41 3144: 
1.112     bowersj2 3145: The output string is a table containing all desired attempts, if any.
1.16      harris41 3146: 
1.112     bowersj2 3147: =cut
1.1       albertel 3148: 
                   3149: sub get_previous_attempt {
1.43      ng       3150:   my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1       albertel 3151:   my $prevattempts='';
1.43      ng       3152:   no strict 'refs';
1.1       albertel 3153:   if ($symb) {
1.3       albertel 3154:     my (%returnhash)=
                   3155:       &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1       albertel 3156:     if ($returnhash{'version'}) {
                   3157:       my %lasthash=();
                   3158:       my $version;
                   3159:       for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356     albertel 3160:         foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
                   3161: 	  $lasthash{$key}=$returnhash{$version.':'.$key};
1.19      harris41 3162:         }
1.1       albertel 3163:       }
1.596     albertel 3164:       $prevattempts=&start_data_table().&start_data_table_header_row();
                   3165:       $prevattempts.='<th>'.&mt('History').'</th>';
1.356     albertel 3166:       foreach my $key (sort(keys(%lasthash))) {
                   3167: 	my ($ign,@parts) = split(/\./,$key);
1.41      ng       3168: 	if ($#parts > 0) {
1.31      albertel 3169: 	  my $data=$parts[-1];
                   3170: 	  pop(@parts);
1.596     albertel 3171: 	  $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.'&nbsp;</th>';
1.31      albertel 3172: 	} else {
1.41      ng       3173: 	  if ($#parts == 0) {
                   3174: 	    $prevattempts.='<th>'.$parts[0].'</th>';
                   3175: 	  } else {
                   3176: 	    $prevattempts.='<th>'.$ign.'</th>';
                   3177: 	  }
1.31      albertel 3178: 	}
1.16      harris41 3179:       }
1.596     albertel 3180:       $prevattempts.=&end_data_table_header_row();
1.40      ng       3181:       if ($getattempt eq '') {
                   3182: 	for ($version=1;$version<=$returnhash{'version'};$version++) {
1.596     albertel 3183: 	  $prevattempts.=&start_data_table_row().
                   3184: 	      '<td>'.&mt('Transaction [_1]',$version).'</td>';
1.356     albertel 3185: 	    foreach my $key (sort(keys(%lasthash))) {
1.581     albertel 3186: 		my $value = &format_previous_attempt_value($key,
                   3187: 							   $returnhash{$version.':'.$key});
                   3188: 		$prevattempts.='<td>'.$value.'&nbsp;</td>';   
1.40      ng       3189: 	    }
1.596     albertel 3190: 	  $prevattempts.=&end_data_table_row();
1.40      ng       3191: 	 }
1.1       albertel 3192:       }
1.596     albertel 3193:       $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356     albertel 3194:       foreach my $key (sort(keys(%lasthash))) {
1.581     albertel 3195: 	my $value = &format_previous_attempt_value($key,$lasthash{$key});
1.356     albertel 3196: 	if ($key =~/$regexp$/ && (defined &$gradesub)) {$value = &$gradesub($value)}
1.40      ng       3197: 	$prevattempts.='<td>'.$value.'&nbsp;</td>';
1.16      harris41 3198:       }
1.596     albertel 3199:       $prevattempts.= &end_data_table_row().&end_data_table();
1.1       albertel 3200:     } else {
1.596     albertel 3201:       $prevattempts=
                   3202: 	  &start_data_table().&start_data_table_row().
                   3203: 	  '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
                   3204: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3205:     }
                   3206:   } else {
1.596     albertel 3207:     $prevattempts=
                   3208: 	  &start_data_table().&start_data_table_row().
                   3209: 	  '<td>'.&mt('No data.').'</td>'.
                   3210: 	  &end_data_table_row().&end_data_table();
1.1       albertel 3211:   }
1.10      albertel 3212: }
                   3213: 
1.581     albertel 3214: sub format_previous_attempt_value {
                   3215:     my ($key,$value) = @_;
                   3216:     if ($key =~ /timestamp/) {
                   3217: 	$value = &Apache::lonlocal::locallocaltime($value);
                   3218:     } elsif (ref($value) eq 'ARRAY') {
                   3219: 	$value = '('.join(', ', @{ $value }).')';
                   3220:     } else {
                   3221: 	$value = &unescape($value);
                   3222:     }
                   3223:     return $value;
                   3224: }
                   3225: 
                   3226: 
1.107     albertel 3227: sub relative_to_absolute {
                   3228:     my ($url,$output)=@_;
                   3229:     my $parser=HTML::TokeParser->new(\$output);
                   3230:     my $token;
                   3231:     my $thisdir=$url;
                   3232:     my @rlinks=();
                   3233:     while ($token=$parser->get_token) {
                   3234: 	if ($token->[0] eq 'S') {
                   3235: 	    if ($token->[1] eq 'a') {
                   3236: 		if ($token->[2]->{'href'}) {
                   3237: 		    $rlinks[$#rlinks+1]=$token->[2]->{'href'};
                   3238: 		}
                   3239: 	    } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
                   3240: 		$rlinks[$#rlinks+1]=$token->[2]->{'src'};
                   3241: 	    } elsif ($token->[1] eq 'base') {
                   3242: 		$thisdir=$token->[2]->{'href'};
                   3243: 	    }
                   3244: 	}
                   3245:     }
                   3246:     $thisdir=~s-/[^/]*$--;
1.356     albertel 3247:     foreach my $link (@rlinks) {
1.726     raeburn  3248: 	unless (($link=~/^https?\:\/\//i) ||
1.356     albertel 3249: 		($link=~/^\//) ||
                   3250: 		($link=~/^javascript:/i) ||
                   3251: 		($link=~/^mailto:/i) ||
                   3252: 		($link=~/^\#/)) {
                   3253: 	    my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
                   3254: 	    $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107     albertel 3255: 	}
                   3256:     }
                   3257: # -------------------------------------------------- Deal with Applet codebases
                   3258:     $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
                   3259:     return $output;
                   3260: }
                   3261: 
1.112     bowersj2 3262: =pod
                   3263: 
1.648     raeburn  3264: =item * &get_student_view()
1.112     bowersj2 3265: 
                   3266: show a snapshot of what student was looking at
                   3267: 
                   3268: =cut
                   3269: 
1.10      albertel 3270: sub get_student_view {
1.186     albertel 3271:   my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114     www      3272:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3273:   my (%form);
1.10      albertel 3274:   my @elements=('symb','courseid','domain','username');
                   3275:   foreach my $element (@elements) {
1.186     albertel 3276:       $form{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3277:   }
1.186     albertel 3278:   if (defined($moreenv)) {
                   3279:       %form=(%form,%{$moreenv});
                   3280:   }
1.236     albertel 3281:   if (defined($target)) { $form{'grade_target'} = $target; }
1.107     albertel 3282:   $feedurl=&Apache::lonnet::clutter($feedurl);
1.650     www      3283:   my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11      albertel 3284:   $userview=~s/\<body[^\>]*\>//gi;
                   3285:   $userview=~s/\<\/body\>//gi;
                   3286:   $userview=~s/\<html\>//gi;
                   3287:   $userview=~s/\<\/html\>//gi;
                   3288:   $userview=~s/\<head\>//gi;
                   3289:   $userview=~s/\<\/head\>//gi;
                   3290:   $userview=~s/action\s*\=/would_be_action\=/gi;
1.107     albertel 3291:   $userview=&relative_to_absolute($feedurl,$userview);
1.650     www      3292:   if (wantarray) {
                   3293:      return ($userview,$response);
                   3294:   } else {
                   3295:      return $userview;
                   3296:   }
                   3297: }
                   3298: 
                   3299: sub get_student_view_with_retries {
                   3300:   my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
                   3301: 
                   3302:     my $ok = 0;                 # True if we got a good response.
                   3303:     my $content;
                   3304:     my $response;
                   3305: 
                   3306:     # Try to get the student_view done. within the retries count:
                   3307:     
                   3308:     do {
                   3309:          ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
                   3310:          $ok      = $response->is_success;
                   3311:          if (!$ok) {
                   3312:             &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
                   3313:          }
                   3314:          $retries--;
                   3315:     } while (!$ok && ($retries > 0));
                   3316:     
                   3317:     if (!$ok) {
                   3318:        $content = '';          # On error return an empty content.
                   3319:     }
1.651     www      3320:     if (wantarray) {
                   3321:        return ($content, $response);
                   3322:     } else {
                   3323:        return $content;
                   3324:     }
1.11      albertel 3325: }
                   3326: 
1.112     bowersj2 3327: =pod
                   3328: 
1.648     raeburn  3329: =item * &get_student_answers() 
1.112     bowersj2 3330: 
                   3331: show a snapshot of how student was answering problem
                   3332: 
                   3333: =cut
                   3334: 
1.11      albertel 3335: sub get_student_answers {
1.100     sakharuk 3336:   my ($symb,$username,$domain,$courseid,%form) = @_;
1.114     www      3337:   my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186     albertel 3338:   my (%moreenv);
1.11      albertel 3339:   my @elements=('symb','courseid','domain','username');
                   3340:   foreach my $element (@elements) {
1.186     albertel 3341:     $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10      albertel 3342:   }
1.186     albertel 3343:   $moreenv{'grade_target'}='answer';
                   3344:   %moreenv=(%form,%moreenv);
1.497     raeburn  3345:   $feedurl = &Apache::lonnet::clutter($feedurl);
                   3346:   my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10      albertel 3347:   return $userview;
1.1       albertel 3348: }
1.116     albertel 3349: 
                   3350: =pod
                   3351: 
                   3352: =item * &submlink()
                   3353: 
1.242     albertel 3354: Inputs: $text $uname $udom $symb $target
1.116     albertel 3355: 
                   3356: Returns: A link to grades.pm such as to see the SUBM view of a student
                   3357: 
                   3358: =cut
                   3359: 
                   3360: ###############################################
                   3361: sub submlink {
1.242     albertel 3362:     my ($text,$uname,$udom,$symb,$target)=@_;
1.116     albertel 3363:     if (!($uname && $udom)) {
                   3364: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3365: 	    &Apache::lonnet::whichuser($symb);
1.116     albertel 3366: 	if (!$symb) { $symb=$cursymb; }
                   3367:     }
1.254     matthew  3368:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3369:     $symb=&escape($symb);
1.242     albertel 3370:     if ($target) { $target="target=\"$target\""; }
                   3371:     return '<a href="/adm/grades?&command=submission&'.
                   3372: 	'symb='.$symb.'&student='.$uname.
                   3373: 	'&userdom='.$udom.'" '.$target.'>'.$text.'</a>';
                   3374: }
                   3375: ##############################################
                   3376: 
                   3377: =pod
                   3378: 
                   3379: =item * &pgrdlink()
                   3380: 
                   3381: Inputs: $text $uname $udom $symb $target
                   3382: 
                   3383: Returns: A link to grades.pm such as to see the PGRD view of a student
                   3384: 
                   3385: =cut
                   3386: 
                   3387: ###############################################
                   3388: sub pgrdlink {
                   3389:     my $link=&submlink(@_);
                   3390:     $link=~s/(&command=submission)/$1&showgrading=yes/;
                   3391:     return $link;
                   3392: }
                   3393: ##############################################
                   3394: 
                   3395: =pod
                   3396: 
                   3397: =item * &pprmlink()
                   3398: 
                   3399: Inputs: $text $uname $udom $symb $target
                   3400: 
                   3401: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283     albertel 3402: student and a specific resource
1.242     albertel 3403: 
                   3404: =cut
                   3405: 
                   3406: ###############################################
                   3407: sub pprmlink {
                   3408:     my ($text,$uname,$udom,$symb,$target)=@_;
                   3409:     if (!($uname && $udom)) {
                   3410: 	(my $cursymb, my $courseid,$udom,$uname)=
1.463     albertel 3411: 	    &Apache::lonnet::whichuser($symb);
1.242     albertel 3412: 	if (!$symb) { $symb=$cursymb; }
                   3413:     }
1.254     matthew  3414:     if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369     www      3415:     $symb=&escape($symb);
1.242     albertel 3416:     if ($target) { $target="target=\"$target\""; }
1.595     albertel 3417:     return '<a href="/adm/parmset?command=set&amp;'.
                   3418: 	'symb='.$symb.'&amp;uname='.$uname.
                   3419: 	'&amp;udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116     albertel 3420: }
                   3421: ##############################################
1.37      matthew  3422: 
1.112     bowersj2 3423: =pod
                   3424: 
                   3425: =back
                   3426: 
                   3427: =cut
                   3428: 
1.37      matthew  3429: ###############################################
1.51      www      3430: 
                   3431: 
                   3432: sub timehash {
1.687     raeburn  3433:     my ($thistime) = @_;
                   3434:     my $timezone = &Apache::lonlocal::gettimezone();
                   3435:     my $dt = DateTime->from_epoch(epoch => $thistime)
                   3436:                      ->set_time_zone($timezone);
                   3437:     my $wday = $dt->day_of_week();
                   3438:     if ($wday == 7) { $wday = 0; }
                   3439:     return ( 'second' => $dt->second(),
                   3440:              'minute' => $dt->minute(),
                   3441:              'hour'   => $dt->hour(),
                   3442:              'day'     => $dt->day_of_month(),
                   3443:              'month'   => $dt->month(),
                   3444:              'year'    => $dt->year(),
                   3445:              'weekday' => $wday,
                   3446:              'dayyear' => $dt->day_of_year(),
                   3447:              'dlsav'   => $dt->is_dst() );
1.51      www      3448: }
                   3449: 
1.370     www      3450: sub utc_string {
                   3451:     my ($date)=@_;
1.371     www      3452:     return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370     www      3453: }
                   3454: 
1.51      www      3455: sub maketime {
                   3456:     my %th=@_;
1.687     raeburn  3457:     my ($epoch_time,$timezone,$dt);
                   3458:     $timezone = &Apache::lonlocal::gettimezone();
                   3459:     eval {
                   3460:         $dt = DateTime->new( year   => $th{'year'},
                   3461:                              month  => $th{'month'},
                   3462:                              day    => $th{'day'},
                   3463:                              hour   => $th{'hour'},
                   3464:                              minute => $th{'minute'},
                   3465:                              second => $th{'second'},
                   3466:                              time_zone => $timezone,
                   3467:                          );
                   3468:     };
                   3469:     if (!$@) {
                   3470:         $epoch_time = $dt->epoch;
                   3471:         if ($epoch_time) {
                   3472:             return $epoch_time;
                   3473:         }
                   3474:     }
1.51      www      3475:     return POSIX::mktime(
                   3476:         ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210     www      3477:          $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70      www      3478: }
                   3479: 
                   3480: #########################################
1.51      www      3481: 
                   3482: sub findallcourses {
1.482     raeburn  3483:     my ($roles,$uname,$udom) = @_;
1.355     albertel 3484:     my %roles;
                   3485:     if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348     albertel 3486:     my %courses;
1.51      www      3487:     my $now=time;
1.482     raeburn  3488:     if (!defined($uname)) {
                   3489:         $uname = $env{'user.name'};
                   3490:     }
                   3491:     if (!defined($udom)) {
                   3492:         $udom = $env{'user.domain'};
                   3493:     }
                   3494:     if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
                   3495:         my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
                   3496:         if (!%roles) {
                   3497:             %roles = (
                   3498:                        cc => 1,
                   3499:                        in => 1,
                   3500:                        ep => 1,
                   3501:                        ta => 1,
                   3502:                        cr => 1,
                   3503:                        st => 1,
                   3504:              );
                   3505:         }
                   3506:         foreach my $entry (keys(%roleshash)) {
                   3507:             my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
                   3508:             if ($trole =~ /^cr/) { 
                   3509:                 next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
                   3510:             } else {
                   3511:                 next if (!exists($roles{$trole}));
                   3512:             }
                   3513:             if ($tend) {
                   3514:                 next if ($tend < $now);
                   3515:             }
                   3516:             if ($tstart) {
                   3517:                 next if ($tstart > $now);
                   3518:             }
                   3519:             my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role,$realsec);
                   3520:             (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
                   3521:             if ($secpart eq '') {
                   3522:                 ($cnum,$role) = split(/_/,$cnumpart); 
                   3523:                 $sec = 'none';
                   3524:                 $realsec = '';
                   3525:             } else {
                   3526:                 $cnum = $cnumpart;
                   3527:                 ($sec,$role) = split(/_/,$secpart);
                   3528:                 $realsec = $sec;
1.490     raeburn  3529:             }
1.482     raeburn  3530:             $courses{$cdom.'_'.$cnum}{$sec} = $trole.'/'.$cdom.'/'.$cnum.'/'.$realsec;
                   3531:         }
                   3532:     } else {
                   3533:         foreach my $key (keys(%env)) {
1.483     albertel 3534: 	    if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
                   3535:                  $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482     raeburn  3536: 	        my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
                   3537: 	        next if ($role eq 'ca' || $role eq 'aa');
                   3538: 	        next if (%roles && !exists($roles{$role}));
                   3539: 	        my ($starttime,$endtime)=split(/\./,$env{$key});
                   3540:                 my $active=1;
                   3541:                 if ($starttime) {
                   3542: 		    if ($now<$starttime) { $active=0; }
                   3543:                 }
                   3544:                 if ($endtime) {
                   3545:                     if ($now>$endtime) { $active=0; }
                   3546:                 }
                   3547:                 if ($active) {
                   3548:                     if ($sec eq '') {
                   3549:                         $sec = 'none';
                   3550:                     }
                   3551:                     $courses{$cdom.'_'.$cnum}{$sec} = 
                   3552:                                      $role.'/'.$cdom.'/'.$cnum.'/'.$sec;
1.474     raeburn  3553:                 }
                   3554:             }
1.51      www      3555:         }
                   3556:     }
1.474     raeburn  3557:     return %courses;
1.51      www      3558: }
1.37      matthew  3559: 
1.54      www      3560: ###############################################
1.474     raeburn  3561: 
                   3562: sub blockcheck {
1.482     raeburn  3563:     my ($setters,$activity,$uname,$udom) = @_;
1.490     raeburn  3564: 
                   3565:     if (!defined($udom)) {
                   3566:         $udom = $env{'user.domain'};
                   3567:     }
                   3568:     if (!defined($uname)) {
                   3569:         $uname = $env{'user.name'};
                   3570:     }
                   3571: 
                   3572:     # If uname and udom are for a course, check for blocks in the course.
                   3573: 
                   3574:     if (&Apache::lonnet::is_course($udom,$uname)) {
                   3575:         my %records = &Apache::lonnet::dump('comm_block',$udom,$uname);
1.502     raeburn  3576:         my ($startblock,$endblock)=&get_blocks($setters,$activity,$udom,$uname);
1.490     raeburn  3577:         return ($startblock,$endblock);
                   3578:     }
1.474     raeburn  3579: 
1.502     raeburn  3580:     my $startblock = 0;
                   3581:     my $endblock = 0;
1.482     raeburn  3582:     my %live_courses = &findallcourses(undef,$uname,$udom);
1.474     raeburn  3583: 
1.490     raeburn  3584:     # If uname is for a user, and activity is course-specific, i.e.,
                   3585:     # boards, chat or groups, check for blocking in current course only.
1.474     raeburn  3586: 
1.490     raeburn  3587:     if (($activity eq 'boards' || $activity eq 'chat' ||
                   3588:          $activity eq 'groups') && ($env{'request.course.id'})) {
                   3589:         foreach my $key (keys(%live_courses)) {
                   3590:             if ($key ne $env{'request.course.id'}) {
                   3591:                 delete($live_courses{$key});
                   3592:             }
                   3593:         }
                   3594:     }
                   3595: 
                   3596:     my $otheruser = 0;
                   3597:     my %own_courses;
                   3598:     if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
                   3599:         # Resource belongs to user other than current user.
                   3600:         $otheruser = 1;
                   3601:         # Gather courses for current user
                   3602:         %own_courses = 
                   3603:             &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
                   3604:     }
                   3605: 
                   3606:     # Gather active course roles - course coordinator, instructor, 
                   3607:     # exam proctor, ta, student, or custom role.
1.474     raeburn  3608: 
                   3609:     foreach my $course (keys(%live_courses)) {
1.482     raeburn  3610:         my ($cdom,$cnum);
                   3611:         if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
                   3612:             $cdom = $env{'course.'.$course.'.domain'};
                   3613:             $cnum = $env{'course.'.$course.'.num'};
                   3614:         } else {
1.490     raeburn  3615:             ($cdom,$cnum) = split(/_/,$course); 
1.482     raeburn  3616:         }
                   3617:         my $no_ownblock = 0;
                   3618:         my $no_userblock = 0;
1.533     raeburn  3619:         if ($otheruser && $activity ne 'com') {
1.490     raeburn  3620:             # Check if current user has 'evb' priv for this
                   3621:             if (defined($own_courses{$course})) {
                   3622:                 foreach my $sec (keys(%{$own_courses{$course}})) {
                   3623:                     my $checkrole = 'cm./'.$cdom.'/'.$cnum;
                   3624:                     if ($sec ne 'none') {
                   3625:                         $checkrole .= '/'.$sec;
                   3626:                     }
                   3627:                     if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   3628:                         $no_ownblock = 1;
                   3629:                         last;
                   3630:                     }
                   3631:                 }
                   3632:             }
                   3633:             # if they have 'evb' priv and are currently not playing student
                   3634:             next if (($no_ownblock) &&
                   3635:                  ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
                   3636:         }
1.474     raeburn  3637:         foreach my $sec (keys(%{$live_courses{$course}})) {
1.482     raeburn  3638:             my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474     raeburn  3639:             if ($sec ne 'none') {
1.482     raeburn  3640:                 $checkrole .= '/'.$sec;
1.474     raeburn  3641:             }
1.490     raeburn  3642:             if ($otheruser) {
                   3643:                 # Resource belongs to user other than current user.
                   3644:                 # Assemble privs for that user, and check for 'evb' priv.
1.482     raeburn  3645:                 my ($trole,$tdom,$tnum,$tsec);
                   3646:                 my $entry = $live_courses{$course}{$sec};
                   3647:                 if ($entry =~ /^cr/) {
                   3648:                     ($trole,$tdom,$tnum,$tsec) = 
                   3649:                       ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
                   3650:                 } else {
                   3651:                     ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
                   3652:                 }
                   3653:                 my ($spec,$area,$trest,%allroles,%userroles);
                   3654:                 $area = '/'.$tdom.'/'.$tnum;
                   3655:                 $trest = $tnum;
                   3656:                 if ($tsec ne '') {
                   3657:                     $area .= '/'.$tsec;
                   3658:                     $trest .= '/'.$tsec;
                   3659:                 }
                   3660:                 $spec = $trole.'.'.$area;
                   3661:                 if ($trole =~ /^cr/) {
                   3662:                     &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
                   3663:                                                       $tdom,$spec,$trest,$area);
                   3664:                 } else {
                   3665:                     &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
                   3666:                                                        $tdom,$spec,$trest,$area);
                   3667:                 }
                   3668:                 my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.486     raeburn  3669:                 if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
                   3670:                     if ($1) {
                   3671:                         $no_userblock = 1;
                   3672:                         last;
                   3673:                     }
                   3674:                 }
1.490     raeburn  3675:             } else {
                   3676:                 # Resource belongs to current user
                   3677:                 # Check for 'evb' priv via lonnet::allowed().
1.482     raeburn  3678:                 if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
                   3679:                     $no_ownblock = 1;
                   3680:                     last;
                   3681:                 }
1.474     raeburn  3682:             }
                   3683:         }
                   3684:         # if they have the evb priv and are currently not playing student
1.482     raeburn  3685:         next if (($no_ownblock) &&
1.491     albertel 3686:                  ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482     raeburn  3687:         next if ($no_userblock);
1.474     raeburn  3688: 
1.490     raeburn  3689:         # Retrieve blocking times and identity of blocker for course
                   3690:         # of specified user, unless user has 'evb' privilege.
1.502     raeburn  3691:         
                   3692:         my ($start,$end)=&get_blocks($setters,$activity,$cdom,$cnum);
                   3693:         if (($start != 0) && 
                   3694:             (($startblock == 0) || ($startblock > $start))) {
                   3695:             $startblock = $start;
                   3696:         }
                   3697:         if (($end != 0)  &&
                   3698:             (($endblock == 0) || ($endblock < $end))) {
                   3699:             $endblock = $end;
                   3700:         }
1.490     raeburn  3701:     }
                   3702:     return ($startblock,$endblock);
                   3703: }
                   3704: 
                   3705: sub get_blocks {
                   3706:     my ($setters,$activity,$cdom,$cnum) = @_;
                   3707:     my $startblock = 0;
                   3708:     my $endblock = 0;
                   3709:     my $course = $cdom.'_'.$cnum;
                   3710:     $setters->{$course} = {};
                   3711:     $setters->{$course}{'staff'} = [];
                   3712:     $setters->{$course}{'times'} = [];
                   3713:     my %records = &Apache::lonnet::dump('comm_block',$cdom,$cnum);
                   3714:     foreach my $record (keys(%records)) {
                   3715:         my ($start,$end) = ($record =~ m/^(\d+)____(\d+)$/);
                   3716:         if ($start <= time && $end >= time) {
                   3717:             my ($staff_name,$staff_dom,$title,$blocks) =
                   3718:                 &parse_block_record($records{$record});
                   3719:             if ($blocks->{$activity} eq 'on') {
                   3720:                 push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
                   3721:                 push(@{$$setters{$course}{'times'}}, [$start,$end]);
1.491     albertel 3722:                 if ( ($startblock == 0) || ($startblock > $start) ) {
                   3723:                     $startblock = $start;
1.490     raeburn  3724:                 }
1.491     albertel 3725:                 if ( ($endblock == 0) || ($endblock < $end) ) {
                   3726:                     $endblock = $end;
1.474     raeburn  3727:                 }
                   3728:             }
                   3729:         }
                   3730:     }
                   3731:     return ($startblock,$endblock);
                   3732: }
                   3733: 
                   3734: sub parse_block_record {
                   3735:     my ($record) = @_;
                   3736:     my ($setuname,$setudom,$title,$blocks);
                   3737:     if (ref($record) eq 'HASH') {
                   3738:         ($setuname,$setudom) = split(/:/,$record->{'setter'});
                   3739:         $title = &unescape($record->{'event'});
                   3740:         $blocks = $record->{'blocks'};
                   3741:     } else {
                   3742:         my @data = split(/:/,$record,3);
                   3743:         if (scalar(@data) eq 2) {
                   3744:             $title = $data[1];
                   3745:             ($setuname,$setudom) = split(/@/,$data[0]);
                   3746:         } else {
                   3747:             ($setuname,$setudom,$title) = @data;
                   3748:         }
                   3749:         $blocks = { 'com' => 'on' };
                   3750:     }
                   3751:     return ($setuname,$setudom,$title,$blocks);
                   3752: }
                   3753: 
                   3754: sub build_block_table {
                   3755:     my ($startblock,$endblock,$setters) = @_;
                   3756:     my %lt = &Apache::lonlocal::texthash(
                   3757:         'cacb' => 'Currently active communication blocks',
                   3758:         'cour' => 'Course',
                   3759:         'dura' => 'Duration',
                   3760:         'blse' => 'Block set by'
                   3761:     );
                   3762:     my $output;
1.476     raeburn  3763:     $output = '<br />'.$lt{'cacb'}.':<br />';
1.474     raeburn  3764:     $output .= &start_data_table();
                   3765:     $output .= '
                   3766: <tr>
                   3767:  <th>'.$lt{'cour'}.'</th>
                   3768:  <th>'.$lt{'dura'}.'</th>
                   3769:  <th>'.$lt{'blse'}.'</th>
                   3770: </tr>
                   3771: ';
                   3772:     foreach my $course (keys(%{$setters})) {
                   3773:         my %courseinfo=&Apache::lonnet::coursedescription($course);
                   3774:         for (my $i=0; $i<@{$$setters{$course}{staff}}; $i++) {
                   3775:             my ($uname,$udom) = @{$$setters{$course}{staff}[$i]};
1.490     raeburn  3776:             my $fullname = &plainname($uname,$udom);
                   3777:             if (defined($env{'user.name'}) && defined($env{'user.domain'})
                   3778:                 && $env{'user.name'} ne 'public' 
                   3779:                 && $env{'user.domain'} ne 'public') {
                   3780:                 $fullname = &aboutmewrapper($fullname,$uname,$udom);
                   3781:             }
1.474     raeburn  3782:             my ($openblock,$closeblock) = @{$$setters{$course}{times}[$i]};
                   3783:             $openblock = &Apache::lonlocal::locallocaltime($openblock);
                   3784:             $closeblock= &Apache::lonlocal::locallocaltime($closeblock);
                   3785:             $output .= &Apache::loncommon::start_data_table_row().
                   3786:                        '<td>'.$courseinfo{'description'}.'</td>'.
                   3787:                        '<td>'.$openblock.' to '.$closeblock.'</td>'.
1.490     raeburn  3788:                        '<td>'.$fullname.'</td>'.
1.474     raeburn  3789:                         &Apache::loncommon::end_data_table_row();
                   3790:         }
                   3791:     }
                   3792:     $output .= &end_data_table();
                   3793: }
                   3794: 
1.490     raeburn  3795: sub blocking_status {
                   3796:     my ($activity,$uname,$udom) = @_;
                   3797:     my %setters;
                   3798:     my ($blocked,$output,$ownitem,$is_course);
                   3799:     my ($startblock,$endblock)=&blockcheck(\%setters,$activity,$uname,$udom);
                   3800:     if ($startblock && $endblock) {
                   3801:         $blocked = 1;
                   3802:         if (wantarray) {
                   3803:             my $category;
                   3804:             if ($activity eq 'boards') {
                   3805:                 $category = 'Discussion posts in this course';
                   3806:             } elsif ($activity eq 'blogs') {
                   3807:                 $category = 'Blogs';
                   3808:             } elsif ($activity eq 'port') {
                   3809:                 if (defined($uname) && defined($udom)) {
                   3810:                     if ($uname eq $env{'user.name'} &&
                   3811:                         $udom eq $env{'user.domain'}) {
                   3812:                         $ownitem = 1;
                   3813:                     }
                   3814:                 }
                   3815:                 $is_course = &Apache::lonnet::is_course($udom,$uname);
                   3816:                 if ($ownitem) { 
                   3817:                     $category = 'Your portfolio files';  
                   3818:                 } elsif ($is_course) {
                   3819:                     my $coursedesc;
                   3820:                     foreach my $course (keys(%setters)) {
                   3821:                         my %courseinfo =
                   3822:                              &Apache::lonnet::coursedescription($course);
                   3823:                         $coursedesc = $courseinfo{'description'};
                   3824:                     }
1.764     weissno  3825:                     $category = "Group portfolio in the course '$coursedesc'";
1.490     raeburn  3826:                 } else {
                   3827:                     $category = 'Portfolio files belonging to ';
                   3828:                     if ($env{'user.name'} eq 'public' && 
                   3829:                         $env{'user.domain'} eq 'public') {
                   3830:                         $category .= &plainname($uname,$udom);
                   3831:                     } else {
                   3832:                         $category .= &aboutmewrapper(&plainname($uname,$udom),$uname,$udom);  
                   3833:                     }
                   3834:                 }
                   3835:             } elsif ($activity eq 'groups') {
                   3836:                 $category = 'Groups in this course';
                   3837:             }
                   3838:             my $showstart = &Apache::lonlocal::locallocaltime($startblock);
                   3839:             my $showend = &Apache::lonlocal::locallocaltime($endblock);
                   3840:             $output = '<br />'.&mt('[_1] will be inaccessible between [_2] and [_3] because communication is being blocked.',$category,$showstart,$showend).'<br />';
                   3841:             if (!($activity eq 'port' && !($ownitem) && !($is_course))) { 
                   3842:                 $output .= &build_block_table($startblock,$endblock,\%setters);
                   3843:             }
                   3844:         }
                   3845:     }
                   3846:     if (wantarray) {
                   3847:         return ($blocked,$output);
                   3848:     } else {
                   3849:         return $blocked;
                   3850:     }
                   3851: }
                   3852: 
1.60      matthew  3853: ###############################################
                   3854: 
1.682     raeburn  3855: sub check_ip_acc {
                   3856:     my ($acc)=@_;
                   3857:     &Apache::lonxml::debug("acc is $acc");
                   3858:     if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
                   3859:         return 1;
                   3860:     }
                   3861:     my $allowed=0;
                   3862:     my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
                   3863: 
                   3864:     my $name;
                   3865:     foreach my $pattern (split(',',$acc)) {
                   3866:         $pattern =~ s/^\s*//;
                   3867:         $pattern =~ s/\s*$//;
                   3868:         if ($pattern =~ /\*$/) {
                   3869:             #35.8.*
                   3870:             $pattern=~s/\*//;
                   3871:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   3872:         } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
                   3873:             #35.8.3.[34-56]
                   3874:             my $low=$2;
                   3875:             my $high=$3;
                   3876:             $pattern=$1;
                   3877:             if ($ip =~ /^\Q$pattern\E/) {
                   3878:                 my $last=(split(/\./,$ip))[3];
                   3879:                 if ($last <=$high && $last >=$low) { $allowed=1; }
                   3880:             }
                   3881:         } elsif ($pattern =~ /^\*/) {
                   3882:             #*.msu.edu
                   3883:             $pattern=~s/\*//;
                   3884:             if (!defined($name)) {
                   3885:                 use Socket;
                   3886:                 my $netaddr=inet_aton($ip);
                   3887:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   3888:             }
                   3889:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   3890:         } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
                   3891:             #127.0.0.1
                   3892:             if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
                   3893:         } else {
                   3894:             #some.name.com
                   3895:             if (!defined($name)) {
                   3896:                 use Socket;
                   3897:                 my $netaddr=inet_aton($ip);
                   3898:                 ($name)=gethostbyaddr($netaddr,AF_INET);
                   3899:             }
                   3900:             if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
                   3901:         }
                   3902:         if ($allowed) { last; }
                   3903:     }
                   3904:     return $allowed;
                   3905: }
                   3906: 
                   3907: ###############################################
                   3908: 
1.60      matthew  3909: =pod
                   3910: 
1.112     bowersj2 3911: =head1 Domain Template Functions
                   3912: 
                   3913: =over 4
                   3914: 
                   3915: =item * &determinedomain()
1.60      matthew  3916: 
                   3917: Inputs: $domain (usually will be undef)
                   3918: 
1.63      www      3919: Returns: Determines which domain should be used for designs
1.60      matthew  3920: 
                   3921: =cut
1.54      www      3922: 
1.60      matthew  3923: ###############################################
1.63      www      3924: sub determinedomain {
                   3925:     my $domain=shift;
1.531     albertel 3926:     if (! $domain) {
1.60      matthew  3927:         # Determine domain if we have not been given one
                   3928:         $domain = $Apache::lonnet::perlvar{'lonDefDomain'};
1.258     albertel 3929:         if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
                   3930:         if ($env{'request.role.domain'}) { 
                   3931:             $domain=$env{'request.role.domain'}; 
1.60      matthew  3932:         }
                   3933:     }
1.63      www      3934:     return $domain;
                   3935: }
                   3936: ###############################################
1.517     raeburn  3937: 
1.518     albertel 3938: sub devalidate_domconfig_cache {
                   3939:     my ($udom)=@_;
                   3940:     &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
                   3941: }
                   3942: 
                   3943: # ---------------------- Get domain configuration for a domain
                   3944: sub get_domainconf {
                   3945:     my ($udom) = @_;
                   3946:     my $cachetime=1800;
                   3947:     my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
                   3948:     if (defined($cached)) { return %{$result}; }
                   3949: 
                   3950:     my %domconfig = &Apache::lonnet::get_dom('configuration',
                   3951: 					     ['login','rolecolors'],$udom);
1.632     raeburn  3952:     my (%designhash,%legacy);
1.518     albertel 3953:     if (keys(%domconfig) > 0) {
                   3954:         if (ref($domconfig{'login'}) eq 'HASH') {
1.632     raeburn  3955:             if (keys(%{$domconfig{'login'}})) {
                   3956:                 foreach my $key (keys(%{$domconfig{'login'}})) {
1.699     raeburn  3957:                     if (ref($domconfig{'login'}{$key}) eq 'HASH') {
                   3958:                         foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
                   3959:                             $designhash{$udom.'.login.'.$key.'_'.$img} = 
                   3960:                                 $domconfig{'login'}{$key}{$img};
                   3961:                         }
                   3962:                     } else {
                   3963:                         $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
                   3964:                     }
1.632     raeburn  3965:                 }
                   3966:             } else {
                   3967:                 $legacy{'login'} = 1;
1.518     albertel 3968:             }
1.632     raeburn  3969:         } else {
                   3970:             $legacy{'login'} = 1;
1.518     albertel 3971:         }
                   3972:         if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632     raeburn  3973:             if (keys(%{$domconfig{'rolecolors'}})) {
                   3974:                 foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
                   3975:                     if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
                   3976:                         foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
                   3977:                             $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
                   3978:                         }
1.518     albertel 3979:                     }
                   3980:                 }
1.632     raeburn  3981:             } else {
                   3982:                 $legacy{'rolecolors'} = 1;
1.518     albertel 3983:             }
1.632     raeburn  3984:         } else {
                   3985:             $legacy{'rolecolors'} = 1;
1.518     albertel 3986:         }
1.632     raeburn  3987:         if (keys(%legacy) > 0) {
                   3988:             my %legacyhash = &get_legacy_domconf($udom);
                   3989:             foreach my $item (keys(%legacyhash)) {
                   3990:                 if ($item =~ /^\Q$udom\E\.login/) {
                   3991:                     if ($legacy{'login'}) { 
                   3992:                         $designhash{$item} = $legacyhash{$item};
                   3993:                     }
                   3994:                 } else {
                   3995:                     if ($legacy{'rolecolors'}) {
                   3996:                         $designhash{$item} = $legacyhash{$item};
                   3997:                     }
1.518     albertel 3998:                 }
                   3999:             }
                   4000:         }
1.632     raeburn  4001:     } else {
                   4002:         %designhash = &get_legacy_domconf($udom); 
1.518     albertel 4003:     }
                   4004:     &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
                   4005: 				  $cachetime);
                   4006:     return %designhash;
                   4007: }
                   4008: 
1.632     raeburn  4009: sub get_legacy_domconf {
                   4010:     my ($udom) = @_;
                   4011:     my %legacyhash;
                   4012:     my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
                   4013:     my $designfile =  $designdir.'/'.$udom.'.tab';
                   4014:     if (-e $designfile) {
                   4015:         if ( open (my $fh,"<$designfile") ) {
                   4016:             while (my $line = <$fh>) {
                   4017:                 next if ($line =~ /^\#/);
                   4018:                 chomp($line);
                   4019:                 my ($key,$val)=(split(/\=/,$line));
                   4020:                 if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
                   4021:             }
                   4022:             close($fh);
                   4023:         }
                   4024:     }
                   4025:     if (-e '/home/httpd/html/adm/lonDomLogos/'.$udom.'.gif') {
                   4026:         $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
                   4027:     }
                   4028:     return %legacyhash;
                   4029: }
                   4030: 
1.63      www      4031: =pod
                   4032: 
1.112     bowersj2 4033: =item * &domainlogo()
1.63      www      4034: 
                   4035: Inputs: $domain (usually will be undef)
                   4036: 
                   4037: Returns: A link to a domain logo, if the domain logo exists.
                   4038: If the domain logo does not exist, a description of the domain.
                   4039: 
                   4040: =cut
1.112     bowersj2 4041: 
1.63      www      4042: ###############################################
                   4043: sub domainlogo {
1.517     raeburn  4044:     my $domain = &determinedomain(shift);
1.518     albertel 4045:     my %designhash = &get_domainconf($domain);    
1.517     raeburn  4046:     # See if there is a logo
                   4047:     if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519     raeburn  4048:         my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538     albertel 4049:         if ($imgsrc =~ m{^/(adm|res)/}) {
                   4050: 	    if ($imgsrc =~ m{^/res/}) {
                   4051: 		my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
                   4052: 		&Apache::lonnet::repcopy($local_name);
                   4053: 	    }
                   4054: 	   $imgsrc = &lonhttpdurl($imgsrc);
1.519     raeburn  4055:         } 
                   4056:         return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514     albertel 4057:     } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
                   4058:         return &Apache::lonnet::domain($domain,'description');
1.59      www      4059:     } else {
1.60      matthew  4060:         return '';
1.59      www      4061:     }
                   4062: }
1.63      www      4063: ##############################################
                   4064: 
                   4065: =pod
                   4066: 
1.112     bowersj2 4067: =item * &designparm()
1.63      www      4068: 
                   4069: Inputs: $which parameter; $domain (usually will be undef)
                   4070: 
                   4071: Returns: value of designparamter $which
                   4072: 
                   4073: =cut
1.112     bowersj2 4074: 
1.397     albertel 4075: 
1.400     albertel 4076: ##############################################
1.397     albertel 4077: sub designparm {
                   4078:     my ($which,$domain)=@_;
1.258     albertel 4079:     if ($env{'browser.blackwhite'} eq 'on') {
1.635     raeburn  4080: 	if ($which=~/\.(font|alink|vlink|link|textcol)$/) {
1.110     www      4081: 	    return '#000000';
                   4082: 	}
1.635     raeburn  4083: 	if ($which=~/\.(pgbg|sidebg|bgcol)$/) {
1.110     www      4084: 	    return '#FFFFFF';
                   4085: 	}
                   4086: 	if ($which=~/\.tabbg$/) {
                   4087: 	    return '#CCCCCC';
                   4088: 	}
                   4089:     }
1.397     albertel 4090:     if (exists($env{'environment.color.'.$which})) {
1.258     albertel 4091: 	return $env{'environment.color.'.$which};
1.96      www      4092:     }
1.63      www      4093:     $domain=&determinedomain($domain);
1.518     albertel 4094:     my %domdesign = &get_domainconf($domain);
1.520     raeburn  4095:     my $output;
1.517     raeburn  4096:     if ($domdesign{$domain.'.'.$which} ne '') {
1.520     raeburn  4097: 	$output = $domdesign{$domain.'.'.$which};
1.63      www      4098:     } else {
1.520     raeburn  4099:         $output = $defaultdesign{$which};
                   4100:     }
                   4101:     if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635     raeburn  4102:         ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538     albertel 4103:         if ($output =~ m{^/(adm|res)/}) {
                   4104: 	    if ($output =~ m{^/res/}) {
                   4105: 		my $local_name = &Apache::lonnet::filelocation('',$output);
                   4106: 		&Apache::lonnet::repcopy($local_name);
                   4107: 	    }
1.520     raeburn  4108:             $output = &lonhttpdurl($output);
                   4109:         }
1.63      www      4110:     }
1.520     raeburn  4111:     return $output;
1.63      www      4112: }
1.59      www      4113: 
1.60      matthew  4114: ###############################################
                   4115: ###############################################
                   4116: 
                   4117: =pod
                   4118: 
1.112     bowersj2 4119: =back
                   4120: 
1.549     albertel 4121: =head1 HTML Helpers
1.112     bowersj2 4122: 
                   4123: =over 4
                   4124: 
                   4125: =item * &bodytag()
1.60      matthew  4126: 
                   4127: Returns a uniform header for LON-CAPA web pages.
                   4128: 
                   4129: Inputs: 
                   4130: 
1.112     bowersj2 4131: =over 4
                   4132: 
                   4133: =item * $title, A title to be displayed on the page.
                   4134: 
                   4135: =item * $function, the current role (can be undef).
                   4136: 
                   4137: =item * $addentries, extra parameters for the <body> tag.
                   4138: 
                   4139: =item * $bodyonly, if defined, only return the <body> tag.
                   4140: 
                   4141: =item * $domain, if defined, force a given domain.
                   4142: 
                   4143: =item * $forcereg, if page should register as content page (relevant for 
1.86      www      4144:             text interface only)
1.60      matthew  4145: 
1.326     albertel 4146: =item * $customtitle, alternate text to use instead of $title
                   4147:                       in the title box that appears, this text
                   4148:                       is not auto translated like the $title is
1.309     albertel 4149: 
                   4150: =item * $notopbar, if true, keep the 'what is this' info but remove the
                   4151:                    navigational links
1.317     albertel 4152: 
1.338     albertel 4153: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
                   4154: 
                   4155: =item * $notitle, if true keep the nav controls, but remove the title bar
                   4156: 
1.361     albertel 4157: =item * $no_inline_link, if true and in remote mode, don't show the 
                   4158:          'Switch To Inline Menu' link
                   4159: 
1.460     albertel 4160: =item * $args, optional argument valid values are
                   4161:             no_auto_mt_title -> prevents &mt()ing the title arg
1.562     albertel 4162:             inherit_jsmath -> when creating popup window in a page,
                   4163:                               should it have jsmath forced on by the
                   4164:                               current page
1.460     albertel 4165: 
1.112     bowersj2 4166: =back
                   4167: 
1.60      matthew  4168: Returns: A uniform header for LON-CAPA web pages.  
                   4169: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
                   4170: If $bodyonly is undef or zero, an html string containing a <body> tag and 
                   4171: other decorations will be returned.
                   4172: 
                   4173: =cut
                   4174: 
1.54      www      4175: sub bodytag {
1.309     albertel 4176:     my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,$customtitle,
1.460     albertel 4177: 	$notopbar,$bgcolor,$notitle,$no_inline_link,$args)=@_;
1.339     albertel 4178: 
1.460     albertel 4179:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.339     albertel 4180: 
1.183     matthew  4181:     $function = &get_users_function() if (!$function);
1.339     albertel 4182:     my $img =    &designparm($function.'.img',$domain);
                   4183:     my $font =   &designparm($function.'.font',$domain);
                   4184:     my $pgbg   = $bgcolor || &designparm($function.'.pgbg',$domain);
                   4185: 
                   4186:     my %design = ( 'style'   => 'margin-top: 0px',
1.535     albertel 4187: 		   'bgcolor' => $pgbg,
1.339     albertel 4188: 		   'text'    => $font,
                   4189:                    'alink'   => &designparm($function.'.alink',$domain),
                   4190: 		   'vlink'   => &designparm($function.'.vlink',$domain),
                   4191: 		   'link'    => &designparm($function.'.link',$domain),);
1.438     albertel 4192:     @design{keys(%$addentries)} = @$addentries{keys(%$addentries)}; 
1.339     albertel 4193: 
1.63      www      4194:  # role and realm
1.378     raeburn  4195:     my ($role,$realm) = split(/\./,$env{'request.role'},2);
                   4196:     if ($role  eq 'ca') {
1.479     albertel 4197:         my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500     albertel 4198:         $realm = &plainname($rname,$rdom);
1.378     raeburn  4199:     } 
1.55      www      4200: # realm
1.258     albertel 4201:     if ($env{'request.course.id'}) {
1.378     raeburn  4202:         if ($env{'request.role'} !~ /^cr/) {
                   4203:             $role = &Apache::lonnet::plaintext($role,&course_type());
                   4204:         }
1.359     albertel 4205: 	$realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378     raeburn  4206:     } else {
                   4207:         $role = &Apache::lonnet::plaintext($role);
1.54      www      4208:     }
1.433     albertel 4209: 
1.359     albertel 4210:     if (!$realm) { $realm='&nbsp;'; }
1.55      www      4211: # Set messages
1.60      matthew  4212:     my $messages=&domainlogo($domain);
1.330     albertel 4213: 
1.438     albertel 4214:     my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329     albertel 4215: 
1.101     www      4216: # construct main body tag
1.359     albertel 4217:     my $bodytag = "<body $extra_body_attr>".
1.562     albertel 4218: 	&Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252     albertel 4219: 
1.530     albertel 4220:     if ($bodyonly) {
1.60      matthew  4221:         return $bodytag;
1.258     albertel 4222:     } elsif ($env{'browser.interface'} eq 'textual') {
1.95      www      4223: # Accessibility
1.224     raeburn  4224:           
1.337     albertel 4225: 	$bodytag.=&Apache::lonmenu::menubuttons($forcereg,$forcereg);
1.338     albertel 4226: 	if (!$notitle) {
1.337     albertel 4227: 	    $bodytag.='<h1>LON-CAPA: '.$title.'</h1>';
                   4228: 	}
                   4229: 	return $bodytag;
1.359     albertel 4230:     }
                   4231: 
1.410     albertel 4232:     my $name = &plainname($env{'user.name'},$env{'user.domain'});
1.433     albertel 4233:     if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') {
                   4234: 	undef($role);
1.434     albertel 4235:     } else {
                   4236: 	$name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'});
1.433     albertel 4237:     }
1.359     albertel 4238:     
                   4239:     my $roleinfo=(<<ENDROLE);
                   4240: <td class="LC_title_bar_who">
                   4241: <div class="LC_title_bar_name">
1.410     albertel 4242:     $name
1.361     albertel 4243:     &nbsp;
1.359     albertel 4244: </div>
                   4245: <div class="LC_title_bar_role">
1.361     albertel 4246: $role&nbsp;
1.359     albertel 4247: </div>
                   4248: <div class="LC_title_bar_realm">
1.361     albertel 4249: $realm&nbsp;
1.359     albertel 4250: </div>
1.206     albertel 4251: </td>
                   4252: ENDROLE
1.235     raeburn  4253: 
1.762     bisitz   4254:     my $titleinfo = '<h1>'.$title.'</h1>';
1.359     albertel 4255:     if ($customtitle) {
                   4256:         $titleinfo = $customtitle;
                   4257:     }
                   4258:     #
                   4259:     # Extra info if you are the DC
                   4260:     my $dc_info = '';
                   4261:     if ($env{'user.adv'} && exists($env{'user.role.dc./'.
                   4262:                         $env{'course.'.$env{'request.course.id'}.
                   4263:                                  '.domain'}.'/'})) {
                   4264:         my $cid = $env{'request.course.id'};
                   4265:         $dc_info.= $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380     www      4266:         $dc_info =~ s/\s+$//;
1.359     albertel 4267:         $dc_info = '('.$dc_info.')';
                   4268:     }
                   4269: 
1.644     www      4270:     if (($env{'environment.remote'} eq 'off') || ($args->{'suppress_header_logos'})) {
1.359     albertel 4271:         # No Remote
1.258     albertel 4272: 	if ($env{'request.state'} eq 'construct') {
1.359     albertel 4273: 	    $forcereg=1;
                   4274: 	}
                   4275: 
                   4276: 	if (!$customtitle && $env{'request.state'} eq 'construct') {
                   4277: 	    # this is for resources; directories have customtitle, and crumbs
                   4278:             # and select recent are created in lonpubdir.pm  
1.229     albertel 4279: 	    my ($uname,$thisdisfn)=
1.258     albertel 4280: 		($env{'request.filename'} =~ m|^/home/([^/]+)/public_html/(.*)|);
1.229     albertel 4281: 	    my $formaction='/priv/'.$uname.'/'.$thisdisfn;
                   4282: 	    $formaction=~s/\/+/\//g;
                   4283: 
1.359     albertel 4284: 	    my $parentpath = '';
                   4285: 	    my $lastitem = '';
                   4286: 	    if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
                   4287: 		$parentpath = $1;
                   4288: 		$lastitem = $2;
                   4289: 	    } else {
                   4290: 		$lastitem = $thisdisfn;
                   4291: 	    }
                   4292: 	    $titleinfo = 
1.640     bisitz   4293: 		&Apache::loncommon::help_open_menu('','',3,'Authoring')
                   4294: 		.'<b>'.&mt('Construction Space').'</b>:&nbsp;'
                   4295: 		.'<form name="dirs" method="post" action="'.$formaction
1.359     albertel 4296: 		.'" target="_top"><tt><b>'
1.705     tempelho 4297: 		.&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv','','+1',1)."<span class=\"LC_fontsize_big\">$lastitem</span></b></tt><br />"
1.359     albertel 4298: 		.&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
                   4299: 		.'</form>'
                   4300: 		.&Apache::lonmenu::constspaceform();
1.235     raeburn  4301:         }
1.359     albertel 4302: 
1.337     albertel 4303:         my $titletable;
1.338     albertel 4304: 	if (!$notitle) {
1.337     albertel 4305: 	    $titletable =
1.359     albertel 4306: 		'<table id="LC_title_bar">'.
                   4307:                          "<tr><td> $titleinfo $dc_info</td>".$roleinfo.
                   4308: 			 '</tr></table>';
1.337     albertel 4309: 	}
1.359     albertel 4310: 	if ($notopbar) {
                   4311: 	    $bodytag .= $titletable;
                   4312: 	} else {
                   4313: 	    if ($env{'request.state'} eq 'construct') {
1.337     albertel 4314:                 $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg,
                   4315: 							  $titletable);
1.272     raeburn  4316:             } else {
1.336     albertel 4317:                 $bodytag .= &Apache::lonmenu::menubuttons($forcereg,$forcereg).
1.359     albertel 4318: 		    $titletable;
1.272     raeburn  4319:             }
1.235     raeburn  4320:         }
                   4321:         return $bodytag;
1.94      www      4322:     }
1.95      www      4323: 
1.93      www      4324: #
1.95      www      4325: # Top frame rendering, Remote is up
1.93      www      4326: #
1.359     albertel 4327: 
1.517     raeburn  4328:     my $imgsrc = $img;
                   4329:     if ($img =~ /^\/adm/) {
1.575     albertel 4330:         $imgsrc = &lonhttpdurl($img);
1.517     raeburn  4331:     }
                   4332:     my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
1.359     albertel 4333: 
1.305     www      4334:     # Explicit link to get inline menu
1.361     albertel 4335:     my $menu= ($no_inline_link?''
                   4336: 	       :'<br /><a href="/adm/remote?action=collapse">'.&mt('Switch to Inline Menu Mode').'</a>');
1.245     matthew  4337:     #
1.338     albertel 4338:     if ($notitle) {
1.337     albertel 4339: 	return $bodytag;
                   4340:     }
1.94      www      4341:     return(<<ENDBODY);
1.60      matthew  4342: $bodytag
1.359     albertel 4343: <table id="LC_title_bar" class="LC_with_remote">
1.368     albertel 4344: <tr><td class="LC_title_bar_role_logo">$upperleft</td>
1.359     albertel 4345:     <td class="LC_title_bar_domain_logo">$messages&nbsp;</td>
1.54      www      4346: </tr>
1.359     albertel 4347: <tr><td>$titleinfo $dc_info $menu</td>
                   4348: $roleinfo
1.368     albertel 4349: </tr>
1.356     albertel 4350: </table>
1.54      www      4351: ENDBODY
1.182     matthew  4352: }
                   4353: 
1.330     albertel 4354: sub make_attr_string {
                   4355:     my ($register,$attr_ref) = @_;
                   4356: 
                   4357:     if ($attr_ref && !ref($attr_ref)) {
                   4358: 	die("addentries Must be a hash ref ".
                   4359: 	    join(':',caller(1))." ".
                   4360: 	    join(':',caller(0))." ");
                   4361:     }
                   4362: 
                   4363:     if ($register) {
1.339     albertel 4364: 	my ($on_load,$on_unload);
                   4365: 	foreach my $key (keys(%{$attr_ref})) {
                   4366: 	    if      (lc($key) eq 'onload') {
                   4367: 		$on_load.=$attr_ref->{$key}.';';
                   4368: 		delete($attr_ref->{$key});
                   4369: 
                   4370: 	    } elsif (lc($key) eq 'onunload') {
                   4371: 		$on_unload.=$attr_ref->{$key}.';';
                   4372: 		delete($attr_ref->{$key});
                   4373: 	    }
                   4374: 	}
                   4375: 	$attr_ref->{'onload'}  =
                   4376: 	    &Apache::lonmenu::loadevents().  $on_load;
                   4377: 	$attr_ref->{'onunload'}=
                   4378: 	    &Apache::lonmenu::unloadevents().$on_unload;
                   4379:     }
                   4380: 
                   4381: # Accessibility font enhance
                   4382:     if ($env{'browser.fontenhance'} eq 'on') {
                   4383: 	my $style;
                   4384: 	foreach my $key (keys(%{$attr_ref})) {
                   4385: 	    if (lc($key) eq 'style') {
                   4386: 		$style.=$attr_ref->{$key}.';';
                   4387: 		delete($attr_ref->{$key});
                   4388: 	    }
                   4389: 	}
                   4390: 	$attr_ref->{'style'}=$style.'; font-size: x-large;';
1.330     albertel 4391:     }
1.339     albertel 4392: 
                   4393:     if ($env{'browser.blackwhite'} eq 'on') {
                   4394: 	delete($attr_ref->{'font'});
                   4395: 	delete($attr_ref->{'link'});
                   4396: 	delete($attr_ref->{'alink'});
                   4397: 	delete($attr_ref->{'vlink'});
                   4398: 	delete($attr_ref->{'bgcolor'});
                   4399: 	delete($attr_ref->{'background'});
                   4400:     }
                   4401: 
1.330     albertel 4402:     my $attr_string;
                   4403:     foreach my $attr (keys(%$attr_ref)) {
                   4404: 	$attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
                   4405:     }
                   4406:     return $attr_string;
                   4407: }
                   4408: 
                   4409: 
1.182     matthew  4410: ###############################################
1.251     albertel 4411: ###############################################
                   4412: 
                   4413: =pod
                   4414: 
                   4415: =item * &endbodytag()
                   4416: 
                   4417: Returns a uniform footer for LON-CAPA web pages.
                   4418: 
1.635     raeburn  4419: Inputs: 1 - optional reference to an args hash
                   4420: If in the hash, key for noredirectlink has a value which evaluates to true,
                   4421: a 'Continue' link is not displayed if the page contains an
                   4422: internal redirect in the <head></head> section,
                   4423: i.e., $env{'internal.head.redirect'} exists   
1.251     albertel 4424: 
                   4425: =cut
                   4426: 
                   4427: sub endbodytag {
1.635     raeburn  4428:     my ($args) = @_;
1.251     albertel 4429:     my $endbodytag='</body>';
1.269     albertel 4430:     $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315     albertel 4431:     if ( exists( $env{'internal.head.redirect'} ) ) {
1.635     raeburn  4432:         if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
                   4433: 	    $endbodytag=
                   4434: 	        "<br /><a href=\"$env{'internal.head.redirect'}\">".
                   4435: 	        &mt('Continue').'</a>'.
                   4436: 	        $endbodytag;
                   4437:         }
1.315     albertel 4438:     }
1.251     albertel 4439:     return $endbodytag;
                   4440: }
                   4441: 
1.352     albertel 4442: =pod
                   4443: 
                   4444: =item * &standard_css()
                   4445: 
                   4446: Returns a style sheet
                   4447: 
                   4448: Inputs: (all optional)
                   4449:             domain         -> force to color decorate a page for a specific
                   4450:                                domain
                   4451:             function       -> force usage of a specific rolish color scheme
                   4452:             bgcolor        -> override the default page bgcolor
                   4453: 
                   4454: =cut
                   4455: 
1.343     albertel 4456: sub standard_css {
1.345     albertel 4457:     my ($function,$domain,$bgcolor) = @_;
1.352     albertel 4458:     $function  = &get_users_function() if (!$function);
                   4459:     my $img    = &designparm($function.'.img',   $domain);
                   4460:     my $tabbg  = &designparm($function.'.tabbg', $domain);
                   4461:     my $font   = &designparm($function.'.font',  $domain);
1.345     albertel 4462:     my $sidebg = &designparm($function.'.sidebg',$domain);
1.382     albertel 4463:     my $pgbg_or_bgcolor =
                   4464: 	         $bgcolor ||
1.352     albertel 4465: 	         &designparm($function.'.pgbg',  $domain);
1.382     albertel 4466:     my $pgbg   = &designparm($function.'.pgbg',  $domain);
1.352     albertel 4467:     my $alink  = &designparm($function.'.alink', $domain);
                   4468:     my $vlink  = &designparm($function.'.vlink', $domain);
                   4469:     my $link   = &designparm($function.'.link',  $domain);
                   4470: 
1.704     muellerd 4471:     my $loginbg = &designparm('login.sidebg',$domain);
1.712     muellerd 4472:     my $bgcol = &designparm('login.bgcol',$domain);
                   4473:     my $textcol = &designparm('login.textcol',$domain);
1.704     muellerd 4474: 
1.602     albertel 4475:     my $sans                 = 'Verdana,Arial,Helvetica,sans-serif';
1.395     albertel 4476:     my $mono                 = 'monospace';
1.352     albertel 4477:     my $data_table_head      = $tabbg;
                   4478:     my $data_table_light     = '#EEEEEE';
1.470     banghart 4479:     my $data_table_dark      = '#DDDDDD';
                   4480:     my $data_table_darker    = '#CCCCCC';
1.349     albertel 4481:     my $data_table_highlight = '#FFFF00';
1.352     albertel 4482:     my $mail_new             = '#FFBB77';
                   4483:     my $mail_new_hover       = '#DD9955';
                   4484:     my $mail_read            = '#BBBB77';
                   4485:     my $mail_read_hover      = '#999944';
                   4486:     my $mail_replied         = '#AAAA88';
                   4487:     my $mail_replied_hover   = '#888855';
                   4488:     my $mail_other           = '#99BBBB';
                   4489:     my $mail_other_hover     = '#669999';
1.391     albertel 4490:     my $table_header         = '#DDDDDD';
1.489     raeburn  4491:     my $feedback_link_bg     = '#BBBBBB';
1.701     harmsja  4492:     my $lg_border_color	     = '#C8C8C8';
1.392     albertel 4493: 
1.608     albertel 4494:     my $border = ($env{'browser.type'} eq 'explorer' ||
                   4495: 		  $env{'browser.type'} eq 'safari'     ) ? '0px 2px 0px 2px'
                   4496: 	                                                 : '0px 3px 0px 4px';
1.448     albertel 4497: 
1.523     albertel 4498: 
1.343     albertel 4499:     return <<END;
1.698     harmsja  4500: body{
                   4501:      font-family: $sans;
                   4502:      line-height:130%;
1.701     harmsja  4503:      font-size:0.83em;
1.698     harmsja  4504:      color:$font;
                   4505:   }
1.701     harmsja  4506: a:link, a:visited { font-size:100%; }
1.698     harmsja  4507: 
1.343     albertel 4508: a:focus { color: red; background: yellow } 
1.510     albertel 4509: table.thinborder,
                   4510: table.thinborder tr th {
                   4511:   border-style: solid;
                   4512:   border-width: 1px;
1.698     harmsja  4513:   border-color: $lg_border_color;
1.510     albertel 4514:   background: $tabbg;
                   4515: }
1.523     albertel 4516: table.thinborder tr td {
1.510     albertel 4517:   border-style: solid;
1.698     harmsja  4518:   border-width: 1px;
                   4519:   border-color: $lg_border_color;
1.510     albertel 4520: }
1.426     albertel 4521: 
1.343     albertel 4522: form, .inline { display: inline; }
1.721     harmsja  4523: 
                   4524: .LC_center { text-align: center; }
                   4525: .LC_left { text-align:left; }
                   4526: .LC_right {text-align:right;}
                   4527: .LC_middle {vertical-align:middle;}
                   4528: .LC_top {vertical-align:top;}
                   4529: .LC_bottom {vertical-align:bottom;}
                   4530: 
                   4531: /* just for tests */
                   4532: .LC_300Box { width:300px; }
1.754     droeschl 4533: .LC_400Box {width:400px; }
1.721     harmsja  4534: .LC_500Box {width:500px; }
                   4535: .LC_600Box {width:600px; }
1.741     harmsja  4536: .LC_800Box {width:800px;}
1.721     harmsja  4537: /* end */
                   4538: 
1.593     albertel 4539: .LC_filename {font-family: $mono; white-space:pre;}
1.350     albertel 4540: .LC_error {
                   4541:   color: red;
                   4542:   font-size: larger;
                   4543: }
1.457     albertel 4544: .LC_warning,
                   4545: .LC_diff_removed {
1.733     bisitz   4546:   color: red;
1.394     albertel 4547: }
1.532     albertel 4548: 
                   4549: .LC_info,
1.457     albertel 4550: .LC_success,
                   4551: .LC_diff_added {
1.350     albertel 4552:   color: green;
                   4553: }
1.543     albertel 4554: .LC_unknown {
                   4555:   color: yellow;
                   4556: }
                   4557: 
1.440     albertel 4558: .LC_icon {
                   4559:   border: 0px;
                   4560: }
1.539     albertel 4561: .LC_indexer_icon {
                   4562:   border: 0px;
                   4563:   height: 22px;
                   4564: }
1.543     albertel 4565: .LC_docs_spacer {
                   4566:   width: 25px;
                   4567:   height: 1px;
                   4568:   border: 0px;
                   4569: }
1.346     albertel 4570: 
1.532     albertel 4571: .LC_internal_info {
1.735     bisitz   4572:   color: #999999;
1.532     albertel 4573: }
                   4574: 
1.458     albertel 4575: table.LC_pastsubmission {
                   4576:   border: 1px solid black;
                   4577:   margin: 2px;
                   4578: }
                   4579: 
1.606     albertel 4580: table#LC_top_nav, table#LC_menubuttons,table#LC_nav_location {
1.345     albertel 4581:   width: 100%;
                   4582:   background: $pgbg;
1.392     albertel 4583:   border: 2px;
1.402     albertel 4584:   border-collapse: separate;
1.403     albertel 4585:   padding: 0px;
1.345     albertel 4586: }
1.392     albertel 4587: 
1.606     albertel 4588: table#LC_title_bar, table.LC_breadcrumbs, 
1.393     albertel 4589: table#LC_title_bar.LC_with_remote {
1.359     albertel 4590:   width: 100%;
1.392     albertel 4591:   border-color: $pgbg;
                   4592:   border-style: solid;
                   4593:   border-width: $border;
                   4594: 
1.379     albertel 4595:   background: $pgbg;
                   4596:   font-family: $sans;
1.392     albertel 4597:   border-collapse: collapse;
1.403     albertel 4598:   padding: 0px;
1.359     albertel 4599: }
1.409     albertel 4600: table.LC_docs_path {
                   4601:   width: 100%;
                   4602:   border: 0;
                   4603:   background: $pgbg;
                   4604:   font-family: $sans;
                   4605:   border-collapse: collapse;
                   4606:   padding: 0px;
                   4607: }
                   4608: 
1.359     albertel 4609: table#LC_title_bar td {
                   4610:   background: $tabbg;
                   4611: }
                   4612: table#LC_title_bar td.LC_title_bar_who {
                   4613:   background: $tabbg;
                   4614:   color: $font;
1.427     albertel 4615:   font: small $sans;
1.359     albertel 4616:   text-align: right;
                   4617: }
1.469     banghart 4618: span.LC_metadata {
                   4619:     font-family: $sans;
                   4620: }
1.359     albertel 4621: table#LC_title_bar td.LC_title_bar_domain_logo {
                   4622:   background: $sidebg;
                   4623:   text-align: right;
1.368     albertel 4624:   padding: 0px;
                   4625: }
                   4626: table#LC_title_bar td.LC_title_bar_role_logo {
                   4627:   background: $sidebg;
                   4628:   padding: 0px;
1.359     albertel 4629: }
                   4630: 
1.706     harmsja  4631: table#LC_menubuttons img{
1.346     albertel 4632:   border: 0px;
                   4633: }
1.345     albertel 4634: table#LC_top_nav td {
                   4635:   background: $tabbg;
1.392     albertel 4636:   border: 0px;
1.407     albertel 4637:   font-size: small;
1.706     harmsja  4638:   vertical-align:top;
                   4639:   padding:2px 5px 2px 5px;
1.345     albertel 4640: }
                   4641: table#LC_top_nav td a, div#LC_top_nav a {
                   4642:   color: $font;
                   4643:   font-family: $sans;
                   4644: }
1.364     albertel 4645: table#LC_top_nav td.LC_top_nav_logo {
                   4646:   background: $tabbg;
1.432     albertel 4647:   text-align: left;
1.408     albertel 4648:   white-space: nowrap;
1.432     albertel 4649:   width: 31px;
1.408     albertel 4650: }
                   4651: table#LC_top_nav td.LC_top_nav_logo img {
1.432     albertel 4652:   border: 0px;
1.408     albertel 4653:   vertical-align: bottom;
1.364     albertel 4654: }
1.432     albertel 4655: table#LC_top_nav td.LC_top_nav_exit,
                   4656: table#LC_top_nav td.LC_top_nav_help {
                   4657:   width: 2.0em;
                   4658: }
1.442     albertel 4659: table#LC_top_nav td.LC_top_nav_login {
                   4660:   width: 4.0em;
                   4661:   text-align: center;
                   4662: }
1.409     albertel 4663: table.LC_breadcrumbs td, table.LC_docs_path td  {
1.357     albertel 4664:   background: $tabbg;
                   4665:   color: $font;
                   4666:   font-family: $sans;
1.358     albertel 4667:   font-size: smaller;
1.357     albertel 4668: }
1.411     albertel 4669: table.LC_breadcrumbs td.LC_breadcrumbs_component,
1.409     albertel 4670: table.LC_docs_path td.LC_docs_path_component {
1.357     albertel 4671:   background: $tabbg;
                   4672:   color: $font;
                   4673:   font-family: $sans;
                   4674:   font-size: larger;
                   4675:   text-align: right;
                   4676: }
1.383     albertel 4677: td.LC_table_cell_checkbox {
                   4678:   text-align: center;
                   4679: }
1.522     albertel 4680: table#LC_mainmenu td.LC_mainmenu_column {
                   4681:     vertical-align: top;
                   4682: }
                   4683: 
1.705     tempelho 4684: .LC_fontsize_small
                   4685: {
                   4686:  font-size: 70%;
                   4687: }
                   4688: 
                   4689: .LC_fontsize_medium
                   4690: {
                   4691:  font-size: 85%;
                   4692: }
                   4693: 
                   4694: .LC_fontsize_large
                   4695: {
                   4696:  font-size: 120%;
                   4697: }
                   4698: 
                   4699: .LC_fontcolor_red
                   4700: {
                   4701:  color: #FF0000;
                   4702: }
                   4703: 
1.346     albertel 4704: .LC_menubuttons_inline_text {
                   4705:   color: $font;
                   4706:   font-family: $sans;
1.698     harmsja  4707:   font-size: 90%;
1.701     harmsja  4708:   padding-left:3px;
1.346     albertel 4709: }
                   4710: 
1.526     www      4711: .LC_menubuttons_link {
                   4712:   text-decoration: none;
                   4713: }
1.698     harmsja  4714: /*2008--9-5: new menu style sheet.Changed category*/
1.522     albertel 4715: .LC_menubuttons_category {
1.521     www      4716:   color: $font;
1.526     www      4717:   background: $pgbg;
1.521     www      4718:   font-family: $sans;
                   4719:   font-size: larger;
                   4720:   font-weight: bold;
                   4721: }
                   4722: 
1.346     albertel 4723: td.LC_menubuttons_text {
1.701     harmsja  4724:  	color: $font; 	
1.346     albertel 4725: }
1.706     harmsja  4726: 
                   4727: 
1.526     www      4728: 
1.346     albertel 4729: .LC_current_location {
                   4730:   font-family: $sans;
                   4731:   background: $tabbg;
                   4732: }
                   4733: .LC_new_mail {
                   4734:   font-family: $sans;
1.634     www      4735:   background: $tabbg;
1.346     albertel 4736:   font-weight: bold;
                   4737: }
1.347     albertel 4738: 
1.526     www      4739: 
1.527     www      4740: .LC_dropadd_labeltext {
                   4741:   font-family: $sans;
                   4742:   text-align: right;
                   4743: }
                   4744: 
                   4745: .LC_preferences_labeltext {
                   4746:   font-family: $sans;
                   4747:   text-align: right;
                   4748: }
                   4749: 
1.666     raeburn  4750: .LC_roleslog_note {
1.701     harmsja  4751:   font-size: small;
1.666     raeburn  4752: }
                   4753: 
1.715     raeburn  4754: .LC_mail_functions {
                   4755:     font-weight: bold;
                   4756: }
                   4757: 
1.440     albertel 4758: table.LC_aboutme_port {
                   4759:   border: 0px;
                   4760:   border-collapse: collapse;
                   4761:   border-spacing: 0px;
                   4762: }
1.349     albertel 4763: table.LC_data_table, table.LC_mail_list {
1.347     albertel 4764:   border: 1px solid #000000;
1.402     albertel 4765:   border-collapse: separate;
1.426     albertel 4766:   border-spacing: 1px;
1.610     albertel 4767:   background: $pgbg;
1.347     albertel 4768: }
1.422     albertel 4769: .LC_data_table_dense {
                   4770:   font-size: small;
                   4771: }
1.507     raeburn  4772: table.LC_nested_outer {
                   4773:   border: 1px solid #000000;
1.589     raeburn  4774:   border-collapse: collapse;
1.507     raeburn  4775:   border-spacing: 0px;
                   4776:   width: 100%;
                   4777: }
                   4778: table.LC_nested {
                   4779:   border: 0px;
1.589     raeburn  4780:   border-collapse: collapse;
1.507     raeburn  4781:   border-spacing: 0px;
                   4782:   width: 100%;
                   4783: }
1.523     albertel 4784: table.LC_data_table tr th, table.LC_calendar tr th, table.LC_mail_list tr th,
                   4785: table.LC_prior_tries tr th {
1.349     albertel 4786:   font-weight: bold;
                   4787:   background-color: $data_table_head;
1.701     harmsja  4788:   font-size:90%;
1.347     albertel 4789: }
1.711     raeburn  4790: table.LC_data_table tr.LC_info_row > td {
1.735     bisitz   4791:   background-color: #CCCCCC;
1.711     raeburn  4792:   font-weight: bold;
                   4793:   text-align: left;
                   4794: }
1.610     albertel 4795: table.LC_data_table tr.LC_odd_row > td, 
1.709     bisitz   4796: table.LC_pick_box tr > td.LC_odd_row,
1.440     albertel 4797: table.LC_aboutme_port tr td {
1.349     albertel 4798:   background-color: $data_table_light;
1.425     albertel 4799:   padding: 2px;
1.347     albertel 4800: }
1.610     albertel 4801: table.LC_data_table tr.LC_even_row > td,
1.709     bisitz   4802: table.LC_pick_box tr > td.LC_even_row,
1.440     albertel 4803: table.LC_aboutme_port tr.LC_even_row td {
1.349     albertel 4804:   background-color: $data_table_dark;
1.709     bisitz   4805:   padding: 2px;
1.347     albertel 4806: }
1.425     albertel 4807: table.LC_data_table tr.LC_data_table_highlight td {
                   4808:   background-color: $data_table_darker;
                   4809: }
1.639     raeburn  4810: table.LC_data_table tr td.LC_leftcol_header {
                   4811:   background-color: $data_table_head;
                   4812:   font-weight: bold;
                   4813: }
1.451     albertel 4814: table.LC_data_table tr.LC_empty_row td,
1.507     raeburn  4815: table.LC_nested tr.LC_empty_row td {
1.347     albertel 4816:   background-color: #FFFFFF;
1.421     albertel 4817:   font-weight: bold;
                   4818:   font-style: italic;
                   4819:   text-align: center;
                   4820:   padding: 8px;
1.347     albertel 4821: }
1.507     raeburn  4822: table.LC_nested tr.LC_empty_row td {
1.465     albertel 4823:   padding: 4ex
                   4824: }
1.507     raeburn  4825: table.LC_nested_outer tr th {
                   4826:   font-weight: bold;
                   4827:   background-color: $data_table_head;
1.701     harmsja  4828:   font-size: small;
1.507     raeburn  4829:   border-bottom: 1px solid #000000;
                   4830: }
                   4831: table.LC_nested_outer tr td.LC_subheader {
                   4832:   background-color: $data_table_head;
                   4833:   font-weight: bold;
                   4834:   font-size: small;
                   4835:   border-bottom: 1px solid #000000;
                   4836:   text-align: right;
1.451     albertel 4837: }
1.507     raeburn  4838: table.LC_nested tr.LC_info_row td {
1.735     bisitz   4839:   background-color: #CCCCCC;
1.451     albertel 4840:   font-weight: bold;
                   4841:   font-size: small;
1.507     raeburn  4842:   text-align: center;
                   4843: }
1.589     raeburn  4844: table.LC_nested tr.LC_info_row td.LC_left_item,
                   4845: table.LC_nested_outer tr th.LC_left_item {
1.507     raeburn  4846:   text-align: left;
1.451     albertel 4847: }
1.507     raeburn  4848: table.LC_nested td {
1.735     bisitz   4849:   background-color: #FFFFFF;
1.451     albertel 4850:   font-size: small;
1.507     raeburn  4851: }
                   4852: table.LC_nested_outer tr th.LC_right_item,
                   4853: table.LC_nested tr.LC_info_row td.LC_right_item,
                   4854: table.LC_nested tr.LC_odd_row td.LC_right_item,
                   4855: table.LC_nested tr td.LC_right_item {
1.451     albertel 4856:   text-align: right;
                   4857: }
                   4858: 
1.507     raeburn  4859: table.LC_nested tr.LC_odd_row td {
1.735     bisitz   4860:   background-color: #EEEEEE;
1.451     albertel 4861: }
                   4862: 
1.473     raeburn  4863: table.LC_createuser {
                   4864: }
                   4865: 
                   4866: table.LC_createuser tr.LC_section_row td {
1.701     harmsja  4867:   font-size: small;
1.473     raeburn  4868: }
                   4869: 
                   4870: table.LC_createuser tr.LC_info_row td  {
1.735     bisitz   4871:   background-color: #CCCCCC;
1.473     raeburn  4872:   font-weight: bold;
                   4873:   text-align: center;
                   4874: }
                   4875: 
1.349     albertel 4876: table.LC_calendar {
                   4877:   border: 1px solid #000000;
                   4878:   border-collapse: collapse;
                   4879: }
                   4880: table.LC_calendar_pickdate {
                   4881:   font-size: xx-small;
                   4882: }
                   4883: table.LC_calendar tr td {
                   4884:   border: 1px solid #000000;
                   4885:   vertical-align: top;
                   4886: }
                   4887: table.LC_calendar tr td.LC_calendar_day_empty {
                   4888:   background-color: $data_table_dark;
                   4889: }
                   4890: table.LC_calendar tr td.LC_calendar_day_current {
                   4891:   background-color: $data_table_highlight;
                   4892: }
                   4893: 
                   4894: table.LC_mail_list tr.LC_mail_new {
                   4895:   background-color: $mail_new;
                   4896: }
                   4897: table.LC_mail_list tr.LC_mail_new:hover {
                   4898:   background-color: $mail_new_hover;
                   4899: }
                   4900: table.LC_mail_list tr.LC_mail_read {
                   4901:   background-color: $mail_read;
                   4902: }
                   4903: table.LC_mail_list tr.LC_mail_read:hover {
                   4904:   background-color: $mail_read_hover;
                   4905: }
                   4906: table.LC_mail_list tr.LC_mail_replied {
                   4907:   background-color: $mail_replied;
                   4908: }
                   4909: table.LC_mail_list tr.LC_mail_replied:hover {
                   4910:   background-color: $mail_replied_hover;
                   4911: }
                   4912: table.LC_mail_list tr.LC_mail_other {
                   4913:   background-color: $mail_other;
                   4914: }
                   4915: table.LC_mail_list tr.LC_mail_other:hover {
                   4916:   background-color: $mail_other_hover;
                   4917: }
1.494     raeburn  4918: table.LC_mail_list tr.LC_mail_even {
                   4919: }
                   4920: table.LC_mail_list tr.LC_mail_odd {
                   4921: }
                   4922: 
1.696     bisitz   4923: table.LC_data_table tr > td.LC_browser_file,
                   4924: table.LC_data_table tr > td.LC_browser_file_published {
1.389     albertel 4925:   background: #CCFF88;
                   4926: }
1.696     bisitz   4927: table.LC_data_table tr > td.LC_browser_file_locked,
                   4928: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389     albertel 4929:   background: #FFAA99;
1.387     albertel 4930: }
1.696     bisitz   4931: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.389     albertel 4932:   background: #AAAAAA;
1.387     albertel 4933: }
1.696     bisitz   4934: table.LC_data_table tr > td.LC_browser_file_modified,
                   4935: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.389     albertel 4936:   background: #FFFF77;
1.387     albertel 4937: }
1.696     bisitz   4938: table.LC_data_table tr.LC_browser_folder > td {
1.389     albertel 4939:   background: #CCCCFF;
1.387     albertel 4940: }
1.696     bisitz   4941: 
1.707     bisitz   4942: table.LC_data_table tr > td.LC_roles_is {
                   4943: /*  background: #77FF77; */
                   4944: }
                   4945: table.LC_data_table tr > td.LC_roles_future {
                   4946:   background: #FFFF77;
                   4947: }
                   4948: table.LC_data_table tr > td.LC_roles_will {
                   4949:   background: #FFAA77;
                   4950: }
                   4951: table.LC_data_table tr > td.LC_roles_expired {
                   4952:   background: #FF7777;
                   4953: }
                   4954: table.LC_data_table tr > td.LC_roles_will_not {
                   4955:   background: #AAFF77;
                   4956: }
                   4957: table.LC_data_table tr > td.LC_roles_selected {
                   4958:   background: #11CC55;
                   4959: }
                   4960: 
1.388     albertel 4961: span.LC_current_location {
1.701     harmsja  4962:   font-size:larger;
1.388     albertel 4963:   background: $pgbg;
                   4964: }
1.387     albertel 4965: 
1.395     albertel 4966: span.LC_parm_menu_item {
                   4967:   font-size: larger;
                   4968:   font-family: $sans;
                   4969: }
                   4970: span.LC_parm_scope_all {
                   4971:   color: red;
                   4972: }
                   4973: span.LC_parm_scope_folder {
                   4974:   color: green;
                   4975: }
                   4976: span.LC_parm_scope_resource {
                   4977:   color: orange;
                   4978: }
                   4979: span.LC_parm_part {
                   4980:   color: blue;
                   4981: }
                   4982: span.LC_parm_folder, span.LC_parm_symb {
                   4983:   font-size: x-small;
                   4984:   font-family: $mono;
                   4985:   color: #AAAAAA;
                   4986: }
                   4987: 
1.396     albertel 4988: td.LC_parm_overview_level_menu, td.LC_parm_overview_map_menu,
                   4989: td.LC_parm_overview_parm_selectors, td.LC_parm_overview_parm_restrictions {
                   4990:   border: 1px solid black;
                   4991:   border-collapse: collapse;
                   4992: }
                   4993: table.LC_parm_overview_restrictions td {
                   4994:   border-width: 1px 4px 1px 4px;
                   4995:   border-style: solid;
                   4996:   border-color: $pgbg;
                   4997:   text-align: center;
                   4998: }
                   4999: table.LC_parm_overview_restrictions th {
                   5000:   background: $tabbg;
                   5001:   border-width: 1px 4px 1px 4px;
                   5002:   border-style: solid;
                   5003:   border-color: $pgbg;
                   5004: }
1.398     albertel 5005: table#LC_helpmenu {
                   5006:   border: 0px;
                   5007:   height: 55px;
                   5008:   border-spacing: 0px;
                   5009: }
                   5010: 
                   5011: table#LC_helpmenu fieldset legend {
                   5012:   font-size: larger;
                   5013:   font-weight: bold;
                   5014: }
1.397     albertel 5015: table#LC_helpmenu_links {
                   5016:   width: 100%;
                   5017:   border: 1px solid black;
                   5018:   background: $pgbg;
                   5019:   padding: 0px;
                   5020:   border-spacing: 1px;
                   5021: }
                   5022: table#LC_helpmenu_links tr td {
                   5023:   padding: 1px;
                   5024:   background: $tabbg;
1.399     albertel 5025:   text-align: center;
                   5026:   font-weight: bold;
1.397     albertel 5027: }
1.396     albertel 5028: 
1.397     albertel 5029: table#LC_helpmenu_links a:link, table#LC_helpmenu_links a:visited,
                   5030: table#LC_helpmenu_links a:active {
                   5031:   text-decoration: none;
                   5032:   color: $font;
                   5033: }
                   5034: table#LC_helpmenu_links a:hover {
                   5035:   text-decoration: underline;
                   5036:   color: $vlink;
                   5037: }
1.396     albertel 5038: 
1.417     albertel 5039: .LC_chrt_popup_exists {
                   5040:   border: 1px solid #339933;
                   5041:   margin: -1px;
                   5042: }
                   5043: .LC_chrt_popup_up {
                   5044:   border: 1px solid yellow;
                   5045:   margin: -1px;
                   5046: }
                   5047: .LC_chrt_popup {
                   5048:   border: 1px solid #8888FF;
                   5049:   background: #CCCCFF;
                   5050: }
1.421     albertel 5051: table.LC_pick_box {
                   5052:   border-collapse: separate;
                   5053:   background: white;
                   5054:   border: 1px solid black;
                   5055:   border-spacing: 1px;
                   5056: }
                   5057: table.LC_pick_box td.LC_pick_box_title {
                   5058:   background: $tabbg;
                   5059:   font-weight: bold;
                   5060:   text-align: right;
1.740     bisitz   5061:   vertical-align: top;
1.421     albertel 5062:   width: 184px;
                   5063:   padding: 8px;
                   5064: }
1.645     raeburn  5065: table.LC_pick_box td.LC_selfenroll_pick_box_title {
                   5066:   background: $tabbg;
                   5067:   font-weight: bold;
                   5068:   text-align: right;
                   5069:   width: 350px;
                   5070:   padding: 8px;
                   5071: }
                   5072: 
1.579     raeburn  5073: table.LC_pick_box td.LC_pick_box_value {
                   5074:   text-align: left;
                   5075:   padding: 8px;
                   5076: }
                   5077: table.LC_pick_box td.LC_pick_box_select {
                   5078:   text-align: left;
                   5079:   padding: 8px;
                   5080: }
1.424     albertel 5081: table.LC_pick_box td.LC_pick_box_separator {
1.421     albertel 5082:   padding: 0px;
                   5083:   height: 1px;
                   5084:   background: black;
                   5085: }
                   5086: table.LC_pick_box td.LC_pick_box_submit {
                   5087:   text-align: right;
                   5088: }
1.579     raeburn  5089: table.LC_pick_box td.LC_evenrow_value {
                   5090:   text-align: left;
                   5091:   padding: 8px;
                   5092:   background-color: $data_table_light;
                   5093: }
                   5094: table.LC_pick_box td.LC_oddrow_value {
                   5095:   text-align: left;
                   5096:   padding: 8px;
                   5097:   background-color: $data_table_light;
                   5098: }
                   5099: table.LC_helpform_receipt {
                   5100:   width: 620px;
                   5101:   border-collapse: separate;
                   5102:   background: white;
                   5103:   border: 1px solid black;
                   5104:   border-spacing: 1px;
                   5105: }
                   5106: table.LC_helpform_receipt td.LC_pick_box_title {
                   5107:   background: $tabbg;
                   5108:   font-weight: bold;
                   5109:   text-align: right;
                   5110:   width: 184px;
                   5111:   padding: 8px;
                   5112: }
                   5113: table.LC_helpform_receipt td.LC_evenrow_value {
                   5114:   text-align: left;
                   5115:   padding: 8px;
                   5116:   background-color: $data_table_light;
                   5117: }
                   5118: table.LC_helpform_receipt td.LC_oddrow_value {
                   5119:   text-align: left;
                   5120:   padding: 8px;
                   5121:   background-color: $data_table_light;
                   5122: }
                   5123: table.LC_helpform_receipt td.LC_pick_box_separator {
                   5124:   padding: 0px;
                   5125:   height: 1px;
                   5126:   background: black;
                   5127: }
                   5128: span.LC_helpform_receipt_cat {
                   5129:   font-weight: bold;
                   5130: }
1.424     albertel 5131: table.LC_group_priv_box {
                   5132:   background: white;
                   5133:   border: 1px solid black;
                   5134:   border-spacing: 1px;
                   5135: }
                   5136: table.LC_group_priv_box td.LC_pick_box_title {
                   5137:   background: $tabbg;
                   5138:   font-weight: bold;
                   5139:   text-align: right;
                   5140:   width: 184px;
                   5141: }
                   5142: table.LC_group_priv_box td.LC_groups_fixed {
                   5143:   background: $data_table_light;
                   5144:   text-align: center;
                   5145: }
                   5146: table.LC_group_priv_box td.LC_groups_optional {
                   5147:   background: $data_table_dark;
                   5148:   text-align: center;
                   5149: }
                   5150: table.LC_group_priv_box td.LC_groups_functionality {
                   5151:   background: $data_table_darker;
                   5152:   text-align: center;
                   5153:   font-weight: bold;
                   5154: }
                   5155: table.LC_group_priv td {
                   5156:   text-align: left;
                   5157:   padding: 0px;
                   5158: }
                   5159: 
1.421     albertel 5160: table.LC_notify_front_page {
                   5161:   background: white;
                   5162:   border: 1px solid black;
                   5163:   padding: 8px;
                   5164: }
                   5165: table.LC_notify_front_page td {
                   5166:   padding: 8px;
                   5167: }
1.424     albertel 5168: .LC_navbuttons {
                   5169:   margin: 2ex 0ex 2ex 0ex;
                   5170: }
1.423     albertel 5171: .LC_topic_bar {
                   5172:   font-family: $sans;
                   5173:   font-weight: bold;
                   5174:   width: 100%;
                   5175:   background: $tabbg;
                   5176:   vertical-align: middle;
                   5177:   margin: 2ex 0ex 2ex 0ex;
                   5178: }
                   5179: .LC_topic_bar span {
                   5180:   vertical-align: middle;
                   5181: }
                   5182: .LC_topic_bar img {
                   5183:   vertical-align: bottom;
                   5184: }
                   5185: table.LC_course_group_status {
                   5186:   margin: 20px;
                   5187: }
                   5188: table.LC_status_selector td {
                   5189:   vertical-align: top;
                   5190:   text-align: center;
1.424     albertel 5191:   padding: 4px;
                   5192: }
                   5193: table.LC_descriptive_input td.LC_description {
                   5194:   vertical-align: top;
                   5195:   text-align: right;
                   5196:   font-weight: bold;
1.423     albertel 5197: }
1.599     albertel 5198: div.LC_feedback_link {
1.616     albertel 5199:   clear: both;
1.599     albertel 5200:   background: white;
                   5201:   width: 100%;  
1.489     raeburn  5202: }
                   5203: span.LC_feedback_link {
1.599     albertel 5204:   background: $feedback_link_bg;
                   5205:   font-size: larger;
                   5206: }
                   5207: span.LC_message_link {
                   5208:   background: $feedback_link_bg;
                   5209:   font-size: larger;
                   5210:   position: absolute;
                   5211:   right: 1em;
1.489     raeburn  5212: }
1.421     albertel 5213: 
1.515     albertel 5214: table.LC_prior_tries {
1.524     albertel 5215:   border: 1px solid #000000;
                   5216:   border-collapse: separate;
                   5217:   border-spacing: 1px;
1.515     albertel 5218: }
1.523     albertel 5219: 
1.515     albertel 5220: table.LC_prior_tries td {
1.524     albertel 5221:   padding: 2px;
1.515     albertel 5222: }
1.523     albertel 5223: 
                   5224: .LC_answer_correct {
                   5225:   background: #AAFFAA;
                   5226:   color: black;
                   5227: }
                   5228: .LC_answer_charged_try {
                   5229:   background: #FFAAAA ! important;
                   5230:   color: black;
                   5231: }
                   5232: .LC_answer_not_charged_try, 
                   5233: .LC_answer_no_grade,
                   5234: .LC_answer_late {
                   5235:   background: #FFFFAA;
                   5236:   color: black;
                   5237: }
                   5238: .LC_answer_previous {
                   5239:   background: #AAAAFF;
                   5240:   color: black;
                   5241: }
                   5242: .LC_answer_no_message {
                   5243:   background: #FFFFFF;
                   5244:   color: black;
                   5245: }
                   5246: .LC_answer_unknown {
                   5247:   background: orange;
                   5248:   color: black;
                   5249: }
                   5250: 
                   5251: 
1.529     albertel 5252: span.LC_prior_numerical,
                   5253: span.LC_prior_string,
                   5254: span.LC_prior_custom,
                   5255: span.LC_prior_reaction,
                   5256: span.LC_prior_math {
1.523     albertel 5257:   font-family: monospace;
                   5258:   white-space: pre;
                   5259: }
                   5260: 
1.525     albertel 5261: span.LC_prior_string {
                   5262:   font-family: monospace;
                   5263:   white-space: pre;
                   5264: }
                   5265: 
1.523     albertel 5266: table.LC_prior_option {
                   5267:   width: 100%;
                   5268:   border-collapse: collapse;
                   5269: }
1.528     albertel 5270: table.LC_prior_rank, table.LC_prior_match {
                   5271:   border-collapse: collapse;
                   5272: }
                   5273: table.LC_prior_option tr td,
                   5274: table.LC_prior_rank tr td,
                   5275: table.LC_prior_match tr td {
1.524     albertel 5276:   border: 1px solid #000000;
1.515     albertel 5277: }
                   5278: 
1.770   ! droeschl 5279: td.LC_nobreak,
1.519     raeburn  5280: span.LC_nobreak {
1.544     albertel 5281:   white-space: nowrap;
1.519     raeburn  5282: }
                   5283: 
1.576     raeburn  5284: span.LC_cusr_emph {
                   5285:   font-style: italic;
                   5286: }
                   5287: 
1.633     raeburn  5288: span.LC_cusr_subheading {
                   5289:   font-weight: normal;
                   5290:   font-size: 85%;
                   5291: }
                   5292: 
1.545     albertel 5293: table.LC_docs_documents {
                   5294:   background: #BBBBBB;
1.547     albertel 5295:   border-width: 0px;
1.545     albertel 5296:   border-collapse: collapse;
                   5297: }
                   5298: 
                   5299: table.LC_docs_documents td.LC_docs_document {
                   5300:   border: 2px solid black;
                   5301:   padding: 4px;
                   5302: }
                   5303: 
                   5304: .LC_docs_entry_move {
                   5305:   border: 0px;
                   5306:   border-collapse: collapse;
1.544     albertel 5307: }
                   5308: 
1.545     albertel 5309: .LC_docs_entry_move td {
                   5310:   border: 2px solid #BBBBBB;
                   5311:   background: #DDDDDD;
                   5312: }
                   5313: 
                   5314: .LC_docs_editor td.LC_docs_entry_commands {
                   5315:   background: #DDDDDD;
                   5316:   font-size: x-small;
                   5317: }
1.544     albertel 5318: .LC_docs_copy {
1.545     albertel 5319:   color: #000099;
1.544     albertel 5320: }
                   5321: .LC_docs_cut {
1.545     albertel 5322:   color: #550044;
1.544     albertel 5323: }
                   5324: .LC_docs_rename {
1.545     albertel 5325:   color: #009900;
1.544     albertel 5326: }
                   5327: .LC_docs_remove {
1.545     albertel 5328:   color: #990000;
                   5329: }
                   5330: 
1.547     albertel 5331: .LC_docs_reinit_warn,
                   5332: .LC_docs_ext_edit {
                   5333:   font-size: x-small;
                   5334: }
                   5335: 
1.545     albertel 5336: .LC_docs_editor td.LC_docs_entry_title,
                   5337: .LC_docs_editor td.LC_docs_entry_icon {
                   5338:   background: #FFFFBB;
                   5339: }
                   5340: .LC_docs_editor td.LC_docs_entry_parameter {
                   5341:   background: #BBBBFF;
                   5342:   font-size: x-small;
                   5343:   white-space: nowrap;
                   5344: }
                   5345: 
                   5346: table.LC_docs_adddocs td,
                   5347: table.LC_docs_adddocs th {
                   5348:   border: 1px solid #BBBBBB;
                   5349:   padding: 4px;
                   5350:   background: #DDDDDD;
1.543     albertel 5351: }
                   5352: 
1.584     albertel 5353: table.LC_sty_begin {
                   5354:   background: #BBFFBB;
                   5355: }
                   5356: table.LC_sty_end {
                   5357:   background: #FFBBBB;
                   5358: }
                   5359: 
1.589     raeburn  5360: table.LC_double_column {
                   5361:   border-width: 0px;
                   5362:   border-collapse: collapse;
                   5363:   width: 100%;
                   5364:   padding: 2px;
                   5365: }
                   5366: 
                   5367: table.LC_double_column tr td.LC_left_col {
1.590     raeburn  5368:   top: 2px;
1.589     raeburn  5369:   left: 2px;
                   5370:   width: 47%;
                   5371:   vertical-align: top;
                   5372: }
                   5373: 
                   5374: table.LC_double_column tr td.LC_right_col {
                   5375:   top: 2px;
                   5376:   right: 2px; 
                   5377:   width: 47%;
                   5378:   vertical-align: top;
                   5379: }
                   5380: 
1.594     raeburn  5381: span.LC_role_level {
                   5382:   font-weight: bold;
                   5383: }
                   5384: 
1.591     raeburn  5385: div.LC_left_float {
                   5386:   float: left;
                   5387:   padding-right: 5%;
1.597     albertel 5388:   padding-bottom: 4px;
1.591     raeburn  5389: }
                   5390: 
                   5391: div.LC_clear_float_header {
1.597     albertel 5392:   padding-bottom: 2px;
1.591     raeburn  5393: }
                   5394: 
                   5395: div.LC_clear_float_footer {
1.597     albertel 5396:   padding-top: 10px;
1.591     raeburn  5397:   clear: both;
                   5398: }
                   5399: 
1.597     albertel 5400: 
                   5401: div.LC_grade_show_user {
                   5402:   margin-top: 20px;
                   5403:   border: 1px solid black;
                   5404: }
                   5405: div.LC_grade_user_name {
                   5406:   background: #DDDDEE;
                   5407:   border-bottom: 1px solid black;
1.705     tempelho 5408:   font-weight: bold;
                   5409:   font-size: large;
1.597     albertel 5410: }
                   5411: div.LC_grade_show_user_odd_row div.LC_grade_user_name {
                   5412:   background: #DDEEDD;
                   5413: }
                   5414: 
                   5415: div.LC_grade_show_problem,
                   5416: div.LC_grade_submissions,
                   5417: div.LC_grade_message_center,
                   5418: div.LC_grade_info_links,
                   5419: div.LC_grade_assign {
                   5420:   margin: 5px;
                   5421:   width: 99%;
                   5422:   background: #FFFFFF;
                   5423: }
                   5424: div.LC_grade_show_problem_header,
                   5425: div.LC_grade_submissions_header,
                   5426: div.LC_grade_message_center_header,
                   5427: div.LC_grade_assign_header {
1.705     tempelho 5428:   font-weight: bold;
                   5429:   font-size: large;
1.597     albertel 5430: }
                   5431: div.LC_grade_show_problem_problem,
                   5432: div.LC_grade_submissions_body,
                   5433: div.LC_grade_message_center_body,
                   5434: div.LC_grade_assign_body {
                   5435:   border: 1px solid black;
                   5436:   width: 99%;
                   5437:   background: #FFFFFF;
                   5438: }
1.598     albertel 5439: span.LC_grade_check_note {
1.705     tempelho 5440:   font-weight: normal;
                   5441:   font-size: medium;
1.598     albertel 5442:   display: inline;
                   5443:   position: absolute;
                   5444:   right: 1em;
                   5445: }
1.597     albertel 5446: 
1.613     albertel 5447: table.LC_scantron_action {
                   5448:   width: 100%;
                   5449: }
                   5450: table.LC_scantron_action tr th {
1.698     harmsja  5451:   font-weight:bold;
                   5452:   font-style:normal;
1.613     albertel 5453: }
1.698     harmsja  5454: .LC_edit_problem_header, 
1.614     albertel 5455: div.LC_edit_problem_footer {
1.705     tempelho 5456:   font-weight: normal;
                   5457:   font-size:  medium;
1.602     albertel 5458:   margin: 2px;
1.600     albertel 5459: }
                   5460: div.LC_edit_problem_header,
1.602     albertel 5461: div.LC_edit_problem_header div,
1.614     albertel 5462: div.LC_edit_problem_footer,
                   5463: div.LC_edit_problem_footer div,
1.602     albertel 5464: div.LC_edit_problem_editxml_header,
                   5465: div.LC_edit_problem_editxml_header div {
1.600     albertel 5466:   margin-top: 5px;
                   5467: }
1.602     albertel 5468: div.LC_edit_problem_header_edit_row {
                   5469:   background: $tabbg;
                   5470:   padding: 3px;
                   5471:   margin-bottom: 5px;
                   5472: }
1.600     albertel 5473: div.LC_edit_problem_header_title {
1.705     tempelho 5474:   font-weight: bold;
                   5475:   font-size: larger;
1.602     albertel 5476:   background: $tabbg;
                   5477:   padding: 3px;
                   5478: }
                   5479: table.LC_edit_problem_header_title {
1.705     tempelho 5480:   font-size: larger;
                   5481:   font-weight:  bold;
1.602     albertel 5482:   width: 100%;
                   5483:   border-color: $pgbg;
                   5484:   border-style: solid;
                   5485:   border-width: $border;
                   5486: 
1.600     albertel 5487:   background: $tabbg;
1.602     albertel 5488:   border-collapse: collapse;
                   5489:   padding: 0px
                   5490: }
                   5491: 
                   5492: div.LC_edit_problem_discards {
                   5493:   float: left;
                   5494:   padding-bottom: 5px;
                   5495: }
                   5496: div.LC_edit_problem_saves {
                   5497:   float: right;
                   5498:   padding-bottom: 5px;
1.600     albertel 5499: }
                   5500: hr.LC_edit_problem_divide {
1.602     albertel 5501:   clear: both;
1.600     albertel 5502:   color: $tabbg;
                   5503:   background-color: $tabbg;
                   5504:   height: 3px;
                   5505:   border: 0px;
                   5506: }
1.679     riegler  5507: img.stift{
1.678     riegler  5508:   border-width:0;
1.679     riegler  5509:   vertical-align:middle;
1.677     riegler  5510: }
1.680     riegler  5511: 
1.681     riegler  5512: table#LC_mainmenu{
                   5513:  margin-top:10px;
                   5514:  width:80%;
                   5515: 
                   5516: }
                   5517: 
1.680     riegler  5518: table#LC_mainmenu td.LC_mainmenu_col_fieldset{
                   5519:   vertical-align: top;
                   5520:   width: 45%;
                   5521: }
                   5522: .LC_mainmenu_fieldset_category {
                   5523:   color: $font;
                   5524:   background: $pgbg;
                   5525:   font-family: $sans;
                   5526:   font-size: small;
                   5527:   font-weight: bold;
                   5528: }
                   5529: 
1.716     raeburn  5530: div.LC_createcourse {
                   5531:     margin: 10px 10px 10px 10px;
                   5532: }
                   5533: 
1.693     droeschl 5534: /* ---- Remove when done ----
                   5535: # The following styles is part of the redesign of LON-CAPA and are
                   5536: # subject to change during this project.
                   5537: # Don't rely on their current functionality as they might be 
                   5538: # changed or removed.
                   5539: # --------------------------*/
                   5540: 
1.698     harmsja  5541: a:hover,
1.721     harmsja  5542: ol.LC_smallMenu a:hover,
                   5543: ol#LC_MenuBreadcrumbs a:hover,
                   5544: ol#LC_PathBreadcrumbs a:hover,
                   5545: ul#LC_TabMainMenuContent a:hover,
                   5546: .LC_FormSectionClearButton input:hover
                   5547: ul.LC_TabContent   li:hover a{
1.698     harmsja  5548: 	color:#BF2317;
                   5549:         text-decoration:none;
1.693     droeschl 5550: }
                   5551: 
                   5552: h1 { 
1.721     harmsja  5553: 	padding:5px 10px 5px 20px;
1.693     droeschl 5554: 	line-height:130%;
                   5555: }
1.698     harmsja  5556: 
1.693     droeschl 5557: h2,h3,h4,h5,h6
                   5558: {
1.721     harmsja  5559: 	margin:5px 0px 5px 0px;
                   5560: 	padding:0px;
                   5561: 	line-height:130%;
1.693     droeschl 5562: }
1.721     harmsja  5563: .LC_hcell{
1.698     harmsja  5564:         padding:3px 15px 3px 15px;
                   5565:         margin:0px;
1.703     harmsja  5566: 	background-color:$tabbg;
                   5567: 	border-bottom:solid 1px $lg_border_color;       
1.693     droeschl 5568: }
1.721     harmsja  5569: .LC_noBorder {
1.698     harmsja  5570:         border:0px;
                   5571: }
1.693     droeschl 5572: 
1.722     harmsja  5573: .LC_bgLightGrey{
1.741     harmsja  5574: 	background:URL(/adm/lonIcons/lightGreyBG.png) repeat-x left bottom;
1.722     harmsja  5575: }
1.741     harmsja  5576: 
1.693     droeschl 5577: 
1.698     harmsja  5578: /* Main Header with discription of Person, Course, etc. */
1.721     harmsja  5579: .LC_HeadRight {
1.693     droeschl 5580: 	text-align: right;
                   5581: 	float: right;
                   5582: 	margin: 0px;
                   5583: 	padding: 0px;
1.698     harmsja  5584:         right:0;
1.693     droeschl 5585:         position:absolute;
1.698     harmsja  5586:         overflow:hidden;
1.693     droeschl 5587: }
                   5588: 
1.761     tempelho 5589: .LC_Right {
                   5590:         float: right;
                   5591:         margin: 0px;
                   5592:         padding: 0px;
                   5593: }
                   5594: 
1.721     harmsja  5595: p, .LC_ContentBox {
1.698     harmsja  5596: 	padding: 10px;
                   5597: 
                   5598: }
1.721     harmsja  5599: .LC_FormSectionClearButton input {
1.741     harmsja  5600:         background-color:transparent;    	    
1.698     harmsja  5601:         border:0px;
                   5602:         cursor:pointer;
                   5603:         text-decoration:underline;
1.693     droeschl 5604: }
1.763     bisitz   5605: 
                   5606: .LC_help_open_topic {
                   5607:         color: #FFFFFF;
                   5608:         background-color: #EEEEFF;
                   5609:         margin: 1px;
                   5610:         padding: 4px;
                   5611:         border: 1px solid #000033;
                   5612:         white-space: nowrap;
1.759     neumanie 5613: }
1.693     droeschl 5614: 
1.698     harmsja  5615: dl,ul,div,fieldset {
                   5616: 	margin: 10px 10px 10px 0px;
1.693     droeschl 5617: 	overflow:hidden;
                   5618: }
1.721     harmsja  5619: ol.LC_smallMenu, ol#LC_PathBreadcrumbs {
1.698     harmsja  5620: 	margin: 0px;
1.693     droeschl 5621: }
                   5622: 
1.721     harmsja  5623: ol.LC_smallMenu li {
1.693     droeschl 5624: 	display: inline;
                   5625: 	padding: 5px 5px 0px 10px;
                   5626: 	vertical-align: top;
                   5627: }
                   5628: 
1.721     harmsja  5629: ol.LC_smallMenu li img {
1.693     droeschl 5630: 	vertical-align: bottom;
                   5631: }
                   5632: 
1.721     harmsja  5633: ol.LC_smallMenu a {
1.693     droeschl 5634: 	font-size: 90%;
                   5635: 	color: RGB(80, 80, 80);
                   5636: 	text-decoration: none;
                   5637: }
1.760     harmsja  5638: ol#LC_TabMainMenuContent, ul.LC_TabContent ,
1.741     harmsja  5639: ul.LC_TabContentBigger {
1.721     harmsja  5640: 	display:block;
                   5641: 	list-style:none;
1.741     harmsja  5642: 	margin: 0px;
1.693     droeschl 5643: 	padding: 0px;
                   5644: }
                   5645: 
1.744     ehlerst  5646: ol#LC_TabMainMenuContent li, ul.LC_TabContent li,
1.741     harmsja  5647: ul.LC_TabContentBigger li{
1.693     droeschl 5648: 	display: inline;
1.741     harmsja  5649: 	border-right: solid 1px $lg_border_color;
                   5650: 	float:left;
                   5651: 	line-height:140%;
                   5652: 	white-space:nowrap;
                   5653: }
                   5654: ol#LC_TabMainMenuContent li{
1.693     droeschl 5655: 	vertical-align: bottom;
                   5656: 	border-bottom: solid 1px RGB(175, 175, 175);
1.721     harmsja  5657: 	padding: 5px 10px 5px 10px;
1.741     harmsja  5658: 	margin-right:5px;
                   5659: 	margin-bottom:3px;
1.693     droeschl 5660: 	font-weight: bold;
1.723     riegler  5661: 	background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693     droeschl 5662: }
                   5663: 
1.721     harmsja  5664: ol#LC_TabMainMenuContent li a{
1.693     droeschl 5665: 	color: RGB(47, 47, 47);
                   5666: 	text-decoration: none;
                   5667: }
1.721     harmsja  5668: ul.LC_TabContent {
1.741     harmsja  5669: 	min-height:1.6em;
1.721     harmsja  5670: }
                   5671: ul.LC_TabContent li{
1.741     harmsja  5672: 	vertical-align:middle;
                   5673: 	padding:0px 10px 0px 10px;
1.745     ehlerst  5674: 	background-color:$tabbg;
                   5675: 	border-bottom:solid 1px $lg_border_color;
1.721     harmsja  5676: }
1.744     ehlerst  5677: ul.LC_TabContent li a, ul.LC_TabContent li{ 
1.721     harmsja  5678: 	color:rgb(47,47,47);
                   5679: 	text-decoration:none;
                   5680: 	font-size:95%;
                   5681: 	font-weight:bold;
1.761     tempelho 5682: 	padding-right: 16px;
1.721     harmsja  5683: }
1.744     ehlerst  5684: ul.LC_TabContent li:hover, ul.LC_TabContent li.active{
1.761     tempelho 5685:         background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.745     ehlerst  5686: 	border-bottom:solid 1px #FFFFFF;
1.761     tempelho 5687: 	padding-right: 16px;
1.744     ehlerst  5688: }
1.741     harmsja  5689: ul.LC_TabContentBigger li{
                   5690: 	vertical-align:bottom;
                   5691: 	border-top:solid 1px $lg_border_color;
                   5692: 	border-left:solid 1px $lg_border_color;
                   5693: 	padding:5px 10px 5px 10px;
                   5694: 	margin-left:2px;
                   5695: 	background:url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
                   5696: }
1.744     ehlerst  5697: ul.LC_TabContentBigger li:hover, ul.LC_TabContentBigger li.active{
                   5698: 	background:url(/adm/lonIcons/lightGreyBG.png) repeat-x right bottom;
                   5699: }
1.741     harmsja  5700: ul.LC_TabContentBigger li, ul.LC_TabContentBigger li a{
                   5701: 	font-size:110%;
                   5702: 	font-weight:bold;
                   5703: }
                   5704: #LC_CourseDocuments, #LC_SupplementalCourseDocuments
                   5705: {
                   5706: 	margin:0px;
1.737     tempelho 5707: }
                   5708: 
1.721     harmsja  5709: .LC_hideThis
                   5710: {
                   5711: 	display:none;
                   5712: 	visibility:hidden;
1.693     droeschl 5713: }
                   5714: 
1.721     harmsja  5715: ol#LC_MenuBreadcrumbs, ol#LC_PathBreadcrumbs {
1.693     droeschl 5716: 	border-top: solid 1px RGB(255, 255, 255);
                   5717: 	height: 20px;
                   5718: 	line-height: 20px;
                   5719: 	vertical-align: bottom;
                   5720: 	margin: 0px 0px 30px 0px;
                   5721: 	padding-left: 10px;
                   5722: 	list-style-position: inside;
1.723     riegler  5723: 	background: url(/adm/lonIcons/lightGreyBG.png) repeat-x left top;
1.693     droeschl 5724: }
                   5725: 
1.721     harmsja  5726: ol#LC_MenuBreadcrumbs li, ol#LC_PathBreadcrumbs li {
1.741     harmsja  5727: /*
1.723     riegler  5728: 	background: url(/adm/lonIcons/arrow_white.png) no-repeat left center;
1.741     harmsja  5729: */	
1.693     droeschl 5730: 	display: inline;
                   5731: 	padding: 0px 0px 0px 10px;
                   5732: 	vertical-align: bottom;
                   5733: 	overflow:hidden;
                   5734: }
                   5735: 
1.721     harmsja  5736: ol#LC_MenuBreadcrumbs li a {
1.693     droeschl 5737: 	text-decoration: none;
                   5738: 	font-size:90%;
                   5739: }
1.721     harmsja  5740: ol#LC_PathBreadcrumbs li a{
1.698     harmsja  5741: 	text-decoration:none;
                   5742: 	font-size:100%;
                   5743: 	font-weight:bold;
1.693     droeschl 5744: }
1.721     harmsja  5745: .LC_ContentBoxSpecial
1.693     droeschl 5746: {
1.701     harmsja  5747: 	border: solid 1px $lg_border_color;
1.746     neumanie 5748: }
                   5749: .LC_ContentBoxSpecialContactInfo
                   5750: {
                   5751: 	border: solid 1px $lg_border_color;
                   5752: 	max-width:25%;
                   5753: 	min-width:25%;
1.698     harmsja  5754: }
1.747     neumanie 5755: .LC_AboutMe_Image
                   5756: {
                   5757: 	float:left;
                   5758: 	margin-right:10px;
                   5759: }
                   5760: .LC_Clear_AboutMe_Image
                   5761: {
                   5762: 	clear:left;
                   5763: }
1.721     harmsja  5764: dl.LC_ListStyleClean dt {
1.693     droeschl 5765: 	padding-right: 5px;
                   5766: 	display: table-header-group;
                   5767: }
                   5768: 
1.721     harmsja  5769: dl.LC_ListStyleClean dd {
1.693     droeschl 5770: 	display: table-row;
                   5771: }
                   5772: 
1.721     harmsja  5773: .LC_ListStyleClean,
                   5774: .LC_ListStyleSimple,
                   5775: .LC_ListStyleNormal,
                   5776: .LC_ListStyleNormal_Border,
                   5777: .LC_ListStyleSpecial
1.693     droeschl 5778: 	{
                   5779: 	/*display:block;	*/
                   5780: 	list-style-position: inside;
                   5781: 	list-style-type: none;
                   5782: 	overflow: hidden;
                   5783: 	padding: 0px;
                   5784: }
                   5785: 
1.721     harmsja  5786: .LC_ListStyleSimple li,
                   5787: .LC_ListStyleSimple dd,
                   5788: .LC_ListStyleNormal li,
                   5789: .LC_ListStyleNormal dd,
                   5790: .LC_ListStyleSpecial li,
                   5791: .LC_ListStyleSpecial dd
1.693     droeschl 5792: 	{
                   5793: 	margin: 0px;
                   5794: 	padding: 5px 5px 5px 10px;
                   5795: 	clear: both;
                   5796: }
                   5797: 
1.721     harmsja  5798: .LC_ListStyleClean li,
                   5799: .LC_ListStyleClean dd {
1.693     droeschl 5800: 	padding-top: 0px;
                   5801: 	padding-bottom: 0px;
                   5802: }
                   5803: 
1.721     harmsja  5804: .LC_ListStyleSimple dd,
                   5805: .LC_ListStyleSimple li{
1.698     harmsja  5806: 	border-bottom: solid 1px $lg_border_color;
1.693     droeschl 5807: }
                   5808: 
1.721     harmsja  5809: .LC_ListStyleSpecial li,
                   5810: .LC_ListStyleSpecial dd {
1.693     droeschl 5811: 	list-style-type: none;
                   5812: 	background-color: RGB(220, 220, 220);
                   5813: 	margin-bottom: 4px;
                   5814: }
                   5815: 
1.721     harmsja  5816: table.LC_SimpleTable {
1.698     harmsja  5817: 	margin:5px;
                   5818: 	border:solid 1px $lg_border_color;
1.693     droeschl 5819: 	}
                   5820: 
1.721     harmsja  5821: table.LC_SimpleTable tr {
1.698     harmsja  5822: 	padding:0px;
                   5823: 	border:solid 1px $lg_border_color;
1.693     droeschl 5824: }
1.721     harmsja  5825: table.LC_SimpleTable thead{
1.698     harmsja  5826: 	 background:rgb(220,220,220);
1.693     droeschl 5827: }
                   5828: 
1.721     harmsja  5829: div.LC_columnSection {
1.693     droeschl 5830: 	display: block;
                   5831: 	clear: both;
                   5832: 	overflow: hidden;
                   5833: 	margin:0px;
                   5834: }
                   5835: 
1.721     harmsja  5836: div.LC_columnSection>* {
1.693     droeschl 5837: 	float: left;
                   5838: 	margin: 10px 20px 10px 0px;
1.747     neumanie 5839: 	overflow:hidden;
1.693     droeschl 5840: }
1.721     harmsja  5841: 
1.719     ehlerst  5842: .ContentBoxSpecialTemplate
                   5843: {
1.747     neumanie 5844:         border: solid 1px $lg_border_color;
1.719     ehlerst  5845: }
                   5846: .ContentBoxTemplate {
                   5847:         padding:10px;
                   5848: }
                   5849: 
1.721     harmsja  5850: div.LC_columnSection > .ContentBoxTemplate,
                   5851: div.LC_columnSection > .ContentBoxSpecialTemplate
1.719     ehlerst  5852:         {
                   5853:         width: 600px;
                   5854: }
1.753     droeschl 5855: 
1.720     ehlerst  5856: .clear{
                   5857: 	clear: both;
                   5858: 	line-height: 0px;
                   5859: 	font-size: 0px;
                   5860: 	height: 0px;
                   5861: }
1.693     droeschl 5862: 
1.694     tempelho 5863: .LC_loginpage_container {
                   5864: 	text-align:left;
                   5865: 	margin : 0 auto;
                   5866: 	width:65%;
                   5867: 	padding: 10px;
                   5868: 	height: auto;
1.712     muellerd 5869: 	background-color:#FFFFFF;
1.694     tempelho 5870: 	border:1px solid #CCCCCC;
                   5871: }
                   5872: 
                   5873: 
                   5874: .LC_loginpage_loginContainer {
                   5875: 	float:left;
1.712     muellerd 5876: 	width: 182px;
                   5877: 	border:1px solid #CCCCCC;
                   5878: 	background-color:$loginbg;
1.694     tempelho 5879: }
                   5880: 
1.717     tempelho 5881: .LC_loginpage_loginContainer h2{
1.712     muellerd 5882: 	margin-top:0;
                   5883: 	display:block;
                   5884: 	background:$bgcol;
                   5885: 	color:$textcol;
                   5886: 	padding-left:5px;
                   5887: }
1.694     tempelho 5888: .LC_loginpage_loginInfo {
                   5889: 	margin-left:20px;
                   5890: 	float:left;
                   5891: 	width:30%;
                   5892: 	border:1px solid #CCCCCC;
                   5893: 	padding:10px;
                   5894: }
                   5895: 
1.712     muellerd 5896: .LC_loginpage_loginDomain {
                   5897: 	margin-right:20px;
                   5898: 	width:20%;
                   5899: 	float:left;
                   5900: 	padding:10px;
                   5901: }
                   5902: 
1.694     tempelho 5903: .LC_loginpage_space {
1.754     droeschl 5904: 	clear: both;
                   5905: 	margin-bottom: 20px;
1.694     tempelho 5906: 	border-bottom: 1px solid #CCCCCC;
                   5907: }
                   5908: 
1.748     schulted 5909: table em{
1.754     droeschl 5910: 	font-weight: bold;
                   5911: 	font-style: normal;
1.748     schulted 5912: }
                   5913: 
1.768     schulted 5914: table.LC_tableOfContent{
1.769     schulted 5915:         border:none;
                   5916: 	border-spacing: 1;
1.754     droeschl 5917: 	padding: 3px;
                   5918: 	background-color: #FFFFFF;
                   5919: 	font-size: 90%;
1.753     droeschl 5920: }
1.768     schulted 5921: table.LC_tableOfContent a {
                   5922:         background-color:transparent;
1.753     droeschl 5923: 	text-decoration: none;
                   5924: }
                   5925: 
1.768     schulted 5926: table.LC_tableOfContent tr.LC_trOdd{
1.754     droeschl 5927: 	background-color: #EEEEEE;
1.753     droeschl 5928: }
                   5929: 
1.768     schulted 5930: table.LC_tableOfContent img{
1.753     droeschl 5931: 	border: none;
                   5932: 	height: 1.3em;
                   5933: 	vertical-align: text-bottom;
                   5934: 	margin-right: 0.3em;
                   5935: }
1.757     schulted 5936: 
                   5937: a#LC_content_toolbar_firsthomework{
                   5938: 	background-image:url(/res/adm/pages/open-first-problem.gif);
                   5939: }
                   5940: 
                   5941: a#LC_content_toolbar_launchnav{	
                   5942: 	background-image:url(/res/adm/pages/start-navigation.gif);
                   5943: }
                   5944: 
                   5945: a#LC_content_toolbar_closenav{
                   5946: 	background-image:url(/res/adm/pages/close-navigation.gif);
                   5947: }
                   5948: 
                   5949: a#LC_content_toolbar_everything{
                   5950: 	background-image:url(/res/adm/pages/show-all.gif);
                   5951: }
                   5952: 
                   5953: a#LC_content_toolbar_uncompleted{
                   5954: 	background-image:url(/res/adm/pages/show-incomplete-problems.gif);
                   5955: }
                   5956: 
                   5957: #LC_content_toolbar_clearbubbles{
                   5958: 	background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
                   5959: }
                   5960: 
                   5961: a#LC_content_toolbar_changefolder{
                   5962: 	background : url(/res/adm/pages/close-all-folders.gif) top center ;
                   5963: }
                   5964: 
                   5965: a#LC_content_toolbar_changefolder_toggled{
                   5966: 	background-image:url(/res/adm/pages/open-all-folders.gif);
                   5967: }
                   5968: 
                   5969: ul#LC_toolbar li a:hover{
                   5970: 	background-position: bottom center;
                   5971: }
                   5972: 
                   5973: ul#LC_toolbar{
                   5974: 	padding:0; 
                   5975: 	margin: 2px;
                   5976: 	list-style:none;
                   5977: 	position:relative;
                   5978: 	background-color:white;
                   5979: }
                   5980: 
                   5981: ul#LC_toolbar li{
                   5982: 	border:1px solid white;
                   5983: 	padding:0;
                   5984: 	margin: 0;
1.767     droeschl 5985:     float: left;
                   5986: 	display:inline;
1.757     schulted 5987: 	vertical-align:middle;
                   5988: }
                   5989: 
                   5990: a.LC_toolbarItem{
1.767     droeschl 5991: 	display:block;
1.757     schulted 5992: 	padding:0;
                   5993: 	margin:0;
                   5994: 	height: 32px;
                   5995: 	width: 32px;
                   5996: 	color:white; 
                   5997: 	border:0 none;	
                   5998: 	background-repeat:no-repeat;
                   5999: 	background-color:transparent;
                   6000: }
                   6001: 
                   6002: 
1.343     albertel 6003: END
                   6004: }
                   6005: 
1.306     albertel 6006: =pod
                   6007: 
                   6008: =item * &headtag()
                   6009: 
                   6010: Returns a uniform footer for LON-CAPA web pages.
                   6011: 
1.307     albertel 6012: Inputs: $title - optional title for the head
                   6013:         $head_extra - optional extra HTML to put inside the <head>
1.315     albertel 6014:         $args - optional arguments
1.319     albertel 6015:             force_register - if is true call registerurl so the remote is 
                   6016:                              informed
1.415     albertel 6017:             redirect       -> array ref of
                   6018:                                    1- seconds before redirect occurs
                   6019:                                    2- url to redirect to
                   6020:                                    3- whether the side effect should occur
1.315     albertel 6021:                            (side effect of setting 
                   6022:                                $env{'internal.head.redirect'} to the url 
                   6023:                                redirected too)
1.352     albertel 6024:             domain         -> force to color decorate a page for a specific
                   6025:                                domain
                   6026:             function       -> force usage of a specific rolish color scheme
                   6027:             bgcolor        -> override the default page bgcolor
1.460     albertel 6028:             no_auto_mt_title
                   6029:                            -> prevent &mt()ing the title arg
1.464     albertel 6030: 
1.306     albertel 6031: =cut
                   6032: 
                   6033: sub headtag {
1.313     albertel 6034:     my ($title,$head_extra,$args) = @_;
1.306     albertel 6035:     
1.363     albertel 6036:     my $function = $args->{'function'} || &get_users_function();
                   6037:     my $domain   = $args->{'domain'}   || &determinedomain();
                   6038:     my $bgcolor  = $args->{'bgcolor'}  || &designparm($function.'.pgbg',$domain);
1.418     albertel 6039:     my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458     albertel 6040: 		   $Apache::lonnet::perlvar{'lonVersion'},
1.531     albertel 6041: 		   #time(),
1.418     albertel 6042: 		   $env{'environment.color.timestamp'},
1.363     albertel 6043: 		   $function,$domain,$bgcolor);
                   6044: 
1.369     www      6045:     $url = '/adm/css/'.&escape($url).'.css';
1.363     albertel 6046: 
1.308     albertel 6047:     my $result =
                   6048: 	'<head>'.
1.461     albertel 6049: 	&font_settings();
1.319     albertel 6050: 
1.461     albertel 6051:     if (!$args->{'frameset'}) {
                   6052: 	$result .= &Apache::lonhtmlcommon::htmlareaheaders();
                   6053:     }
1.319     albertel 6054:     if ($args->{'force_register'}) {
                   6055: 	$result .= &Apache::lonmenu::registerurl(1);
                   6056:     }
1.436     albertel 6057:     if (!$args->{'no_nav_bar'} 
                   6058: 	&& !$args->{'only_body'}
                   6059: 	&& !$args->{'frameset'}) {
                   6060: 	$result .= &help_menu_js();
                   6061:     }
1.319     albertel 6062: 
1.314     albertel 6063:     if (ref($args->{'redirect'})) {
1.414     albertel 6064: 	my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315     albertel 6065: 	$url = &Apache::lonenc::check_encrypt($url);
1.414     albertel 6066: 	if (!$inhibit_continue) {
                   6067: 	    $env{'internal.head.redirect'} = $url;
                   6068: 	}
1.313     albertel 6069: 	$result.=<<ADDMETA
                   6070: <meta http-equiv="pragma" content="no-cache" />
1.344     albertel 6071: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313     albertel 6072: ADDMETA
                   6073:     }
1.306     albertel 6074:     if (!defined($title)) {
                   6075: 	$title = 'The LearningOnline Network with CAPA';
                   6076:     }
1.460     albertel 6077:     if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
                   6078:     $result .= '<title> LON-CAPA '.$title.'</title>'
1.414     albertel 6079: 	.'<link rel="stylesheet" type="text/css" href="'.$url.'" />'
                   6080: 	.$head_extra;
1.306     albertel 6081:     return $result;
                   6082: }
                   6083: 
                   6084: =pod
                   6085: 
1.340     albertel 6086: =item * &font_settings()
                   6087: 
                   6088: Returns neccessary <meta> to set the proper encoding
                   6089: 
                   6090: Inputs: none
                   6091: 
                   6092: =cut
                   6093: 
                   6094: sub font_settings {
                   6095:     my $headerstring='';
1.647     www      6096:     if (!$env{'browser.mathml'} && $env{'browser.unicode'}) {
1.340     albertel 6097: 	$headerstring.=
                   6098: 	    '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />';
                   6099:     }
                   6100:     return $headerstring;
                   6101: }
                   6102: 
1.341     albertel 6103: =pod
                   6104: 
                   6105: =item * &xml_begin()
                   6106: 
                   6107: Returns the needed doctype and <html>
                   6108: 
                   6109: Inputs: none
                   6110: 
                   6111: =cut
                   6112: 
                   6113: sub xml_begin {
                   6114:     my $output='';
                   6115: 
1.592     albertel 6116:     if ($env{'internal.start_page'}==1) {
                   6117: 	&Apache::lonhtmlcommon::init_htmlareafields();
                   6118:     }
1.342     albertel 6119: 
1.341     albertel 6120:     if ($env{'browser.mathml'}) {
                   6121: 	$output='<?xml version="1.0"?>'
                   6122:             #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
                   6123: #            .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
                   6124:             
                   6125: #	    .'<!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">] >'
                   6126: 	    .'<!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">'
                   6127:             .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" ' 
                   6128: 	    .'xmlns="http://www.w3.org/1999/xhtml">';
                   6129:     } else {
                   6130: 	$output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html>';
                   6131:     }
                   6132:     return $output;
                   6133: }
1.340     albertel 6134: 
                   6135: =pod
                   6136: 
1.306     albertel 6137: =item * &endheadtag()
                   6138: 
                   6139: Returns a uniform </head> for LON-CAPA web pages.
                   6140: 
                   6141: Inputs: none
                   6142: 
                   6143: =cut
                   6144: 
                   6145: sub endheadtag {
                   6146:     return '</head>';
                   6147: }
                   6148: 
                   6149: =pod
                   6150: 
                   6151: =item * &head()
                   6152: 
                   6153: Returns a uniform complete <head>..</head> section for LON-CAPA web pages.
                   6154: 
1.648     raeburn  6155: Inputs:
                   6156: 
                   6157: =over 4
                   6158: 
                   6159: $title - optional title for the page
                   6160: 
                   6161: $head_extra - optional extra HTML to put inside the <head>
                   6162: 
                   6163: =back
1.405     albertel 6164: 
1.306     albertel 6165: =cut
                   6166: 
                   6167: sub head {
1.325     albertel 6168:     my ($title,$head_extra,$args) = @_;
                   6169:     return &headtag($title,$head_extra,$args).&endheadtag();
1.306     albertel 6170: }
                   6171: 
                   6172: =pod
                   6173: 
                   6174: =item * &start_page()
                   6175: 
                   6176: Returns a complete <html> .. <body> section for LON-CAPA web pages.
                   6177: 
1.648     raeburn  6178: Inputs:
                   6179: 
                   6180: =over 4
                   6181: 
                   6182: $title - optional title for the page
                   6183: 
                   6184: $head_extra - optional extra HTML to incude inside the <head>
                   6185: 
                   6186: $args - additional optional args supported are:
                   6187: 
                   6188: =over 8
                   6189: 
                   6190:              only_body      -> is true will set &bodytag() onlybodytag
1.317     albertel 6191:                                     arg on
1.648     raeburn  6192:              no_nav_bar     -> is true will set &bodytag() notopbar arg on
                   6193:              add_entries    -> additional attributes to add to the  <body>
                   6194:              domain         -> force to color decorate a page for a 
1.317     albertel 6195:                                     specific domain
1.648     raeburn  6196:              function       -> force usage of a specific rolish color
1.317     albertel 6197:                                     scheme
1.648     raeburn  6198:              redirect       -> see &headtag()
                   6199:              bgcolor        -> override the default page bg color
                   6200:              js_ready       -> return a string ready for being used in 
1.317     albertel 6201:                                     a javascript writeln
1.648     raeburn  6202:              html_encode    -> return a string ready for being used in 
1.320     albertel 6203:                                     a html attribute
1.648     raeburn  6204:              force_register -> if is true will turn on the &bodytag()
1.317     albertel 6205:                                     $forcereg arg
1.648     raeburn  6206:              body_title     -> alternate text to use instead of $title
1.326     albertel 6207:                                     in the title box that appears, this text
                   6208:                                     is not auto translated like the $title is
1.648     raeburn  6209:              frameset       -> if true will start with a <frameset>
1.330     albertel 6210:                                     rather than <body>
1.648     raeburn  6211:              no_title       -> if true the title bar won't be shown
                   6212:              skip_phases    -> hash ref of 
1.338     albertel 6213:                                     head -> skip the <html><head> generation
                   6214:                                     body -> skip all <body> generation
1.648     raeburn  6215:              no_inline_link -> if true and in remote mode, don't show the 
1.361     albertel 6216:                                     'Switch To Inline Menu' link
1.648     raeburn  6217:              no_auto_mt_title -> prevent &mt()ing the title arg
                   6218:              inherit_jsmath -> when creating popup window in a page,
                   6219:                                     should it have jsmath forced on by the
                   6220:                                     current page
1.361     albertel 6221: 
1.648     raeburn  6222: =back
1.460     albertel 6223: 
1.648     raeburn  6224: =back
1.562     albertel 6225: 
1.306     albertel 6226: =cut
                   6227: 
                   6228: sub start_page {
1.309     albertel 6229:     my ($title,$head_extra,$args) = @_;
1.318     albertel 6230:     #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.313     albertel 6231:     my %head_args;
1.352     albertel 6232:     foreach my $arg ('redirect','force_register','domain','function',
1.460     albertel 6233: 		     'bgcolor','frameset','no_nav_bar','only_body',
                   6234: 		     'no_auto_mt_title') {
1.319     albertel 6235: 	if (defined($args->{$arg})) {
1.324     raeburn  6236: 	    $head_args{$arg} = $args->{$arg};
1.319     albertel 6237: 	}
1.313     albertel 6238:     }
1.319     albertel 6239: 
1.315     albertel 6240:     $env{'internal.start_page'}++;
1.338     albertel 6241:     my $result;
                   6242:     if (! exists($args->{'skip_phases'}{'head'}) ) {
                   6243: 	$result.=
1.341     albertel 6244: 	    &xml_begin().
1.338     albertel 6245: 	    &headtag($title,$head_extra,\%head_args).&endheadtag();
                   6246:     }
                   6247:     
                   6248:     if (! exists($args->{'skip_phases'}{'body'}) ) {
                   6249: 	if ($args->{'frameset'}) {
                   6250: 	    my $attr_string = &make_attr_string($args->{'force_register'},
                   6251: 						$args->{'add_entries'});
                   6252: 	    $result .= "\n<frameset $attr_string>\n";
                   6253: 	} else {
                   6254: 	    $result .=
                   6255: 		&bodytag($title, 
                   6256: 			 $args->{'function'},       $args->{'add_entries'},
                   6257: 			 $args->{'only_body'},      $args->{'domain'},
                   6258: 			 $args->{'force_register'}, $args->{'body_title'},
                   6259: 			 $args->{'no_nav_bar'},     $args->{'bgcolor'},
1.460     albertel 6260: 			 $args->{'no_title'},       $args->{'no_inline_link'},
                   6261: 			 $args);
1.338     albertel 6262: 	}
1.330     albertel 6263:     }
1.338     albertel 6264: 
1.315     albertel 6265:     if ($args->{'js_ready'}) {
1.713     kaisler  6266: 		$result = &js_ready($result);
1.315     albertel 6267:     }
1.320     albertel 6268:     if ($args->{'html_encode'}) {
1.713     kaisler  6269: 		$result = &html_encode($result);
                   6270:     }
                   6271: 
1.758     kaisler  6272: 	#Breadcrumbs
                   6273:     if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
                   6274: 		&Apache::lonhtmlcommon::clear_breadcrumbs();
                   6275: 		#if any br links exists, add them to the breadcrumbs
                   6276: 		if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {         
                   6277: 			foreach my $crumb (@{$args->{'bread_crumbs'}}){
                   6278: 				&Apache::lonhtmlcommon::add_breadcrumb($crumb);
                   6279: 			}
                   6280: 		}
                   6281: 
                   6282: 		#if bread_crumbs_component exists show it as headline else show only the breadcrumbs
                   6283: 		if(exists($args->{'bread_crumbs_component'})){
                   6284: 			$result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
                   6285: 		}else{
                   6286: 			$result .= &Apache::lonhtmlcommon::breadcrumbs();
                   6287: 		}
1.320     albertel 6288:     }
1.315     albertel 6289:     return $result;
1.306     albertel 6290: }
                   6291: 
1.330     albertel 6292: 
1.306     albertel 6293: =pod
                   6294: 
                   6295: =item * &head()
                   6296: 
                   6297: Returns a complete </body></html> section for LON-CAPA web pages.
                   6298: 
1.315     albertel 6299: Inputs:         $args - additional optional args supported are:
                   6300:                  js_ready     -> return a string ready for being used in 
                   6301:                                  a javascript writeln
1.320     albertel 6302:                  html_encode  -> return a string ready for being used in 
                   6303:                                  a html attribute
1.330     albertel 6304:                  frameset     -> if true will start with a <frameset>
                   6305:                                  rather than <body>
1.493     albertel 6306:                  dicsussion   -> if true will get discussion from
                   6307:                                   lonxml::xmlend
                   6308:                                  (you can pass the target and parser arguments
                   6309:                                   through optional 'target' and 'parser' args
                   6310:                                   to this routine)
1.306     albertel 6311: 
                   6312: =cut
                   6313: 
                   6314: sub end_page {
1.315     albertel 6315:     my ($args) = @_;
                   6316:     $env{'internal.end_page'}++;
1.330     albertel 6317:     my $result;
1.335     albertel 6318:     if ($args->{'discussion'}) {
                   6319: 	my ($target,$parser);
                   6320: 	if (ref($args->{'discussion'})) {
                   6321: 	    ($target,$parser) =($args->{'discussion'}{'target'},
                   6322: 				$args->{'discussion'}{'parser'});
                   6323: 	}
                   6324: 	$result .= &Apache::lonxml::xmlend($target,$parser);
                   6325:     }
                   6326: 
1.330     albertel 6327:     if ($args->{'frameset'}) {
                   6328: 	$result .= '</frameset>';
                   6329:     } else {
1.635     raeburn  6330: 	$result .= &endbodytag($args);
1.330     albertel 6331:     }
                   6332:     $result .= "\n</html>";
                   6333: 
1.315     albertel 6334:     if ($args->{'js_ready'}) {
1.317     albertel 6335: 	$result = &js_ready($result);
1.315     albertel 6336:     }
1.335     albertel 6337: 
1.320     albertel 6338:     if ($args->{'html_encode'}) {
                   6339: 	$result = &html_encode($result);
                   6340:     }
1.335     albertel 6341: 
1.315     albertel 6342:     return $result;
                   6343: }
                   6344: 
1.320     albertel 6345: sub html_encode {
                   6346:     my ($result) = @_;
                   6347: 
1.322     albertel 6348:     $result = &HTML::Entities::encode($result,'<>&"');
1.320     albertel 6349:     
                   6350:     return $result;
                   6351: }
1.317     albertel 6352: sub js_ready {
                   6353:     my ($result) = @_;
                   6354: 
1.323     albertel 6355:     $result =~ s/[\n\r]/ /xmsg;
                   6356:     $result =~ s/\\/\\\\/xmsg;
                   6357:     $result =~ s/'/\\'/xmsg;
1.372     albertel 6358:     $result =~ s{</}{<\\/}xmsg;
1.317     albertel 6359:     
                   6360:     return $result;
                   6361: }
                   6362: 
1.315     albertel 6363: sub validate_page {
                   6364:     if (  exists($env{'internal.start_page'})
1.316     albertel 6365: 	  &&     $env{'internal.start_page'} > 1) {
                   6366: 	&Apache::lonnet::logthis('start_page called multiple times '.
1.318     albertel 6367: 				 $env{'internal.start_page'}.' '.
1.316     albertel 6368: 				 $ENV{'request.filename'});
1.315     albertel 6369:     }
                   6370:     if (  exists($env{'internal.end_page'})
1.316     albertel 6371: 	  &&     $env{'internal.end_page'} > 1) {
                   6372: 	&Apache::lonnet::logthis('end_page called multiple times '.
1.318     albertel 6373: 				 $env{'internal.end_page'}.' '.
1.316     albertel 6374: 				 $env{'request.filename'});
1.315     albertel 6375:     }
                   6376:     if (     exists($env{'internal.start_page'})
                   6377: 	&& ! exists($env{'internal.end_page'})) {
1.316     albertel 6378: 	&Apache::lonnet::logthis('start_page called without end_page '.
                   6379: 				 $env{'request.filename'});
1.315     albertel 6380:     }
                   6381:     if (   ! exists($env{'internal.start_page'})
                   6382: 	&&   exists($env{'internal.end_page'})) {
1.316     albertel 6383: 	&Apache::lonnet::logthis('end_page called without start_page'.
                   6384: 				 $env{'request.filename'});
1.315     albertel 6385:     }
1.306     albertel 6386: }
1.315     albertel 6387: 
1.318     albertel 6388: sub simple_error_page {
                   6389:     my ($r,$title,$msg) = @_;
                   6390:     my $page =
                   6391: 	&Apache::loncommon::start_page($title).
                   6392: 	&mt($msg).
                   6393: 	&Apache::loncommon::end_page();
                   6394:     if (ref($r)) {
                   6395: 	$r->print($page);
1.327     albertel 6396: 	return;
1.318     albertel 6397:     }
                   6398:     return $page;
                   6399: }
1.347     albertel 6400: 
                   6401: {
1.610     albertel 6402:     my @row_count;
1.347     albertel 6403:     sub start_data_table {
1.422     albertel 6404: 	my ($add_class) = @_;
                   6405: 	my $css_class = (join(' ','LC_data_table',$add_class));
1.610     albertel 6406: 	unshift(@row_count,0);
1.422     albertel 6407: 	return '<table class="'.$css_class.'">'."\n";
1.347     albertel 6408:     }
                   6409: 
                   6410:     sub end_data_table {
1.610     albertel 6411: 	shift(@row_count);
1.389     albertel 6412: 	return '</table>'."\n";;
1.347     albertel 6413:     }
                   6414: 
                   6415:     sub start_data_table_row {
1.422     albertel 6416: 	my ($add_class) = @_;
1.610     albertel 6417: 	$row_count[0]++;
                   6418: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.428     albertel 6419: 	$css_class = (join(' ',$css_class,$add_class));
1.422     albertel 6420: 	return  '<tr class="'.$css_class.'">'."\n";;
1.347     albertel 6421:     }
1.471     banghart 6422:     
                   6423:     sub continue_data_table_row {
                   6424: 	my ($add_class) = @_;
1.610     albertel 6425: 	my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.471     banghart 6426: 	$css_class = (join(' ',$css_class,$add_class));
                   6427: 	return  '<tr class="'.$css_class.'">'."\n";;
                   6428:     }
1.347     albertel 6429: 
                   6430:     sub end_data_table_row {
1.389     albertel 6431: 	return '</tr>'."\n";;
1.347     albertel 6432:     }
1.367     www      6433: 
1.421     albertel 6434:     sub start_data_table_empty_row {
1.707     bisitz   6435: #	$row_count[0]++;
1.421     albertel 6436: 	return  '<tr class="LC_empty_row" >'."\n";;
                   6437:     }
                   6438: 
                   6439:     sub end_data_table_empty_row {
                   6440: 	return '</tr>'."\n";;
                   6441:     }
                   6442: 
1.367     www      6443:     sub start_data_table_header_row {
1.389     albertel 6444: 	return  '<tr class="LC_header_row">'."\n";;
1.367     www      6445:     }
                   6446: 
                   6447:     sub end_data_table_header_row {
1.389     albertel 6448: 	return '</tr>'."\n";;
1.367     www      6449:     }
1.347     albertel 6450: }
                   6451: 
1.548     albertel 6452: =pod
                   6453: 
                   6454: =item * &inhibit_menu_check($arg)
                   6455: 
                   6456: Checks for a inhibitmenu state and generates output to preserve it
                   6457: 
                   6458: Inputs:         $arg - can be any of
                   6459:                      - undef - in which case the return value is a string 
                   6460:                                to add  into arguments list of a uri
                   6461:                      - 'input' - in which case the return value is a HTML
                   6462:                                  <form> <input> field of type hidden to
                   6463:                                  preserve the value
                   6464:                      - a url - in which case the return value is the url with
                   6465:                                the neccesary cgi args added to preserve the
                   6466:                                inhibitmenu state
                   6467:                      - a ref to a url - no return value, but the string is
                   6468:                                         updated to include the neccessary cgi
                   6469:                                         args to preserve the inhibitmenu state
                   6470: 
                   6471: =cut
                   6472: 
                   6473: sub inhibit_menu_check {
                   6474:     my ($arg) = @_;
                   6475:     &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
                   6476:     if ($arg eq 'input') {
                   6477: 	if ($env{'form.inhibitmenu'}) {
                   6478: 	    return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
                   6479: 	} else {
                   6480: 	    return
                   6481: 	}
                   6482:     }
                   6483:     if ($env{'form.inhibitmenu'}) {
                   6484: 	if (ref($arg)) {
                   6485: 	    $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   6486: 	} elsif ($arg eq '') {
                   6487: 	    $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
                   6488: 	} else {
                   6489: 	    $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
                   6490: 	}
                   6491:     }
                   6492:     if (!ref($arg)) {
                   6493: 	return $arg;
                   6494:     }
                   6495: }
                   6496: 
1.251     albertel 6497: ###############################################
1.182     matthew  6498: 
                   6499: =pod
                   6500: 
1.549     albertel 6501: =back
                   6502: 
                   6503: =head1 User Information Routines
                   6504: 
                   6505: =over 4
                   6506: 
1.405     albertel 6507: =item * &get_users_function()
1.182     matthew  6508: 
                   6509: Used by &bodytag to determine the current users primary role.
                   6510: Returns either 'student','coordinator','admin', or 'author'.
                   6511: 
                   6512: =cut
                   6513: 
                   6514: ###############################################
                   6515: sub get_users_function {
                   6516:     my $function = 'student';
1.258     albertel 6517:     if ($env{'request.role'}=~/^(cc|in|ta|ep)/) {
1.182     matthew  6518:         $function='coordinator';
                   6519:     }
1.258     albertel 6520:     if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182     matthew  6521:         $function='admin';
                   6522:     }
1.258     albertel 6523:     if (($env{'request.role'}=~/^(au|ca)/) ||
1.182     matthew  6524:         ($ENV{'REQUEST_URI'}=~/^(\/priv|\~)/)) {
                   6525:         $function='author';
                   6526:     }
                   6527:     return $function;
1.54      www      6528: }
1.99      www      6529: 
                   6530: ###############################################
                   6531: 
1.233     raeburn  6532: =pod
                   6533: 
1.542     raeburn  6534: =item * &check_user_status()
1.274     raeburn  6535: 
                   6536: Determines current status of supplied role for a
                   6537: specific user. Roles can be active, previous or future.
                   6538: 
                   6539: Inputs: 
                   6540: user's domain, user's username, course's domain,
1.375     raeburn  6541: course's number, optional section ID.
1.274     raeburn  6542: 
                   6543: Outputs:
                   6544: role status: active, previous or future. 
                   6545: 
                   6546: =cut
                   6547: 
                   6548: sub check_user_status {
1.412     raeburn  6549:     my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.274     raeburn  6550:     my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
                   6551:     my @uroles = keys %userinfo;
                   6552:     my $srchstr;
                   6553:     my $active_chk = 'none';
1.412     raeburn  6554:     my $now = time;
1.274     raeburn  6555:     if (@uroles > 0) {
1.412     raeburn  6556:         if (($role eq 'cc') || ($sec eq '') || (!defined($sec))) {
1.274     raeburn  6557:             $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
                   6558:         } else {
1.412     raeburn  6559:             $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
                   6560:         }
                   6561:         if (grep/^\Q$srchstr\E$/,@uroles) {
1.274     raeburn  6562:             my $role_end = 0;
                   6563:             my $role_start = 0;
                   6564:             $active_chk = 'active';
1.412     raeburn  6565:             if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
                   6566:                 $role_end = $1;
                   6567:                 if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
                   6568:                     $role_start = $1;
1.274     raeburn  6569:                 }
                   6570:             }
                   6571:             if ($role_start > 0) {
1.412     raeburn  6572:                 if ($now < $role_start) {
1.274     raeburn  6573:                     $active_chk = 'future';
                   6574:                 }
                   6575:             }
                   6576:             if ($role_end > 0) {
1.412     raeburn  6577:                 if ($now > $role_end) {
1.274     raeburn  6578:                     $active_chk = 'previous';
                   6579:                 }
                   6580:             }
                   6581:         }
                   6582:     }
                   6583:     return $active_chk;
                   6584: }
                   6585: 
                   6586: ###############################################
                   6587: 
                   6588: =pod
                   6589: 
1.405     albertel 6590: =item * &get_sections()
1.233     raeburn  6591: 
                   6592: Determines all the sections for a course including
                   6593: sections with students and sections containing other roles.
1.419     raeburn  6594: Incoming parameters: 
                   6595: 
                   6596: 1. domain
                   6597: 2. course number 
                   6598: 3. reference to array containing roles for which sections should 
                   6599: be gathered (optional).
                   6600: 4. reference to array containing status types for which sections 
                   6601: should be gathered (optional).
                   6602: 
                   6603: If the third argument is undefined, sections are gathered for any role. 
                   6604: If the fourth argument is undefined, sections are gathered for any status.
                   6605: Permissible values are 'active' or 'future' or 'previous'.
1.233     raeburn  6606:  
1.374     raeburn  6607: Returns section hash (keys are section IDs, values are
                   6608: number of users in each section), subject to the
1.419     raeburn  6609: optional roles filter, optional status filter 
1.233     raeburn  6610: 
                   6611: =cut
                   6612: 
                   6613: ###############################################
                   6614: sub get_sections {
1.419     raeburn  6615:     my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366     albertel 6616:     if (!defined($cdom) || !defined($cnum)) {
                   6617:         my $cid =  $env{'request.course.id'};
                   6618: 
                   6619: 	return if (!defined($cid));
                   6620: 
                   6621:         $cdom = $env{'course.'.$cid.'.domain'};
                   6622:         $cnum = $env{'course.'.$cid.'.num'};
                   6623:     }
                   6624: 
                   6625:     my %sectioncount;
1.419     raeburn  6626:     my $now = time;
1.240     albertel 6627: 
1.366     albertel 6628:     if (!defined($possible_roles) || (grep(/^st$/,@$possible_roles))) {
1.276     albertel 6629: 	my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240     albertel 6630: 	my $sec_index = &Apache::loncoursedata::CL_SECTION();
                   6631: 	my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419     raeburn  6632:         my $start_index = &Apache::loncoursedata::CL_START();
                   6633:         my $end_index = &Apache::loncoursedata::CL_END();
                   6634:         my $status;
1.366     albertel 6635: 	while (my ($student,$data) = each(%$classlist)) {
1.419     raeburn  6636: 	    my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
                   6637: 				                     $data->[$status_index],
                   6638:                                                      $data->[$start_index],
                   6639:                                                      $data->[$end_index]);
                   6640:             if ($stu_status eq 'Active') {
                   6641:                 $status = 'active';
                   6642:             } elsif ($end < $now) {
                   6643:                 $status = 'previous';
                   6644:             } elsif ($start > $now) {
                   6645:                 $status = 'future';
                   6646:             } 
                   6647: 	    if ($section ne '-1' && $section !~ /^\s*$/) {
                   6648:                 if ((!defined($possible_status)) || (($status ne '') && 
                   6649:                     (grep/^\Q$status\E$/,@{$possible_status}))) { 
                   6650: 		    $sectioncount{$section}++;
                   6651:                 }
1.240     albertel 6652: 	    }
                   6653: 	}
                   6654:     }
                   6655:     my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   6656:     foreach my $user (sort(keys(%courseroles))) {
                   6657: 	if ($user !~ /^(\w{2})/) { next; }
                   6658: 	my ($role) = ($user =~ /^(\w{2})/);
                   6659: 	if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419     raeburn  6660: 	my ($section,$status);
1.240     albertel 6661: 	if ($role eq 'cr' &&
                   6662: 	    $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
                   6663: 	    $section=$1;
                   6664: 	}
                   6665: 	if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
                   6666: 	if (!defined($section) || $section eq '-1') { next; }
1.419     raeburn  6667:         my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
                   6668:         if ($end == -1 && $start == -1) {
                   6669:             next; #deleted role
                   6670:         }
                   6671:         if (!defined($possible_status)) { 
                   6672:             $sectioncount{$section}++;
                   6673:         } else {
                   6674:             if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
                   6675:                 $status = 'active';
                   6676:             } elsif ($end < $now) {
                   6677:                 $status = 'future';
                   6678:             } elsif ($start > $now) {
                   6679:                 $status = 'previous';
                   6680:             }
                   6681:             if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
                   6682:                 $sectioncount{$section}++;
                   6683:             }
                   6684:         }
1.233     raeburn  6685:     }
1.366     albertel 6686:     return %sectioncount;
1.233     raeburn  6687: }
                   6688: 
1.274     raeburn  6689: ###############################################
1.294     raeburn  6690: 
                   6691: =pod
1.405     albertel 6692: 
                   6693: =item * &get_course_users()
                   6694: 
1.275     raeburn  6695: Retrieves usernames:domains for users in the specified course
                   6696: with specific role(s), and access status. 
                   6697: 
                   6698: Incoming parameters:
1.277     albertel 6699: 1. course domain
                   6700: 2. course number
                   6701: 3. access status: users must have - either active, 
1.275     raeburn  6702: previous, future, or all.
1.277     albertel 6703: 4. reference to array of permissible roles
1.288     raeburn  6704: 5. reference to array of section restrictions (optional)
                   6705: 6. reference to results object (hash of hashes).
                   6706: 7. reference to optional userdata hash
1.609     raeburn  6707: 8. reference to optional statushash
1.630     raeburn  6708: 9. flag if privileged users (except those set to unhide in
                   6709:    course settings) should be excluded    
1.609     raeburn  6710: Keys of top level results hash are roles.
1.275     raeburn  6711: Keys of inner hashes are username:domain, with 
                   6712: values set to access type.
1.288     raeburn  6713: Optional userdata hash returns an array with arguments in the 
                   6714: same order as loncoursedata::get_classlist() for student data.
                   6715: 
1.609     raeburn  6716: Optional statushash returns
                   6717: 
1.288     raeburn  6718: Entries for end, start, section and status are blank because
                   6719: of the possibility of multiple values for non-student roles.
                   6720: 
1.275     raeburn  6721: =cut
1.405     albertel 6722: 
1.275     raeburn  6723: ###############################################
1.405     albertel 6724: 
1.275     raeburn  6725: sub get_course_users {
1.630     raeburn  6726:     my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288     raeburn  6727:     my %idx = ();
1.419     raeburn  6728:     my %seclists;
1.288     raeburn  6729: 
                   6730:     $idx{udom} = &Apache::loncoursedata::CL_SDOM();
                   6731:     $idx{uname} =  &Apache::loncoursedata::CL_SNAME();
                   6732:     $idx{end} = &Apache::loncoursedata::CL_END();
                   6733:     $idx{start} = &Apache::loncoursedata::CL_START();
                   6734:     $idx{id} = &Apache::loncoursedata::CL_ID();
                   6735:     $idx{section} = &Apache::loncoursedata::CL_SECTION();
                   6736:     $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
                   6737:     $idx{status} = &Apache::loncoursedata::CL_STATUS();
                   6738: 
1.290     albertel 6739:     if (grep(/^st$/,@{$roles})) {
1.276     albertel 6740:         my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278     raeburn  6741:         my $now = time;
1.277     albertel 6742:         foreach my $student (keys(%{$classlist})) {
1.288     raeburn  6743:             my $match = 0;
1.412     raeburn  6744:             my $secmatch = 0;
1.419     raeburn  6745:             my $section = $$classlist{$student}[$idx{section}];
1.609     raeburn  6746:             my $status = $$classlist{$student}[$idx{status}];
1.419     raeburn  6747:             if ($section eq '') {
                   6748:                 $section = 'none';
                   6749:             }
1.291     albertel 6750:             if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 6751:                 if (grep(/^all$/,@{$sections})) {
1.412     raeburn  6752:                     $secmatch = 1;
                   6753:                 } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420     albertel 6754:                     if (grep(/^none$/,@{$sections})) {
1.412     raeburn  6755:                         $secmatch = 1;
                   6756:                     }
                   6757:                 } else {  
1.419     raeburn  6758: 		    if (grep(/^\Q$section\E$/,@{$sections})) {
1.412     raeburn  6759: 		        $secmatch = 1;
                   6760:                     }
1.290     albertel 6761: 		}
1.412     raeburn  6762:                 if (!$secmatch) {
                   6763:                     next;
                   6764:                 }
1.419     raeburn  6765:             }
1.275     raeburn  6766:             if (defined($$types{'active'})) {
1.288     raeburn  6767:                 if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275     raeburn  6768:                     push(@{$$users{st}{$student}},'active');
1.288     raeburn  6769:                     $match = 1;
1.275     raeburn  6770:                 }
                   6771:             }
                   6772:             if (defined($$types{'previous'})) {
1.609     raeburn  6773:                 if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275     raeburn  6774:                     push(@{$$users{st}{$student}},'previous');
1.288     raeburn  6775:                     $match = 1;
1.275     raeburn  6776:                 }
                   6777:             }
                   6778:             if (defined($$types{'future'})) {
1.609     raeburn  6779:                 if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275     raeburn  6780:                     push(@{$$users{st}{$student}},'future');
1.288     raeburn  6781:                     $match = 1;
1.275     raeburn  6782:                 }
                   6783:             }
1.609     raeburn  6784:             if ($match) {
                   6785:                 push(@{$seclists{$student}},$section);
                   6786:                 if (ref($userdata) eq 'HASH') {
                   6787:                     $$userdata{$student} = $$classlist{$student};
                   6788:                 }
                   6789:                 if (ref($statushash) eq 'HASH') {
                   6790:                     $statushash->{$student}{'st'}{$section} = $status;
                   6791:                 }
1.288     raeburn  6792:             }
1.275     raeburn  6793:         }
                   6794:     }
1.412     raeburn  6795:     if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439     raeburn  6796:         my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   6797:         my $now = time;
1.609     raeburn  6798:         my %displaystatus = ( previous => 'Expired',
                   6799:                               active   => 'Active',
                   6800:                               future   => 'Future',
                   6801:                             );
1.630     raeburn  6802:         my %nothide;
                   6803:         if ($hidepriv) {
                   6804:             my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
                   6805:             foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
                   6806:                 if ($user !~ /:/) {
                   6807:                     $nothide{join(':',split(/[\@]/,$user))}=1;
                   6808:                 } else {
                   6809:                     $nothide{$user} = 1;
                   6810:                 }
                   6811:             }
                   6812:         }
1.439     raeburn  6813:         foreach my $person (sort(keys(%coursepersonnel))) {
1.288     raeburn  6814:             my $match = 0;
1.412     raeburn  6815:             my $secmatch = 0;
1.439     raeburn  6816:             my $status;
1.412     raeburn  6817:             my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275     raeburn  6818:             $user =~ s/:$//;
1.439     raeburn  6819:             my ($end,$start) = split(/:/,$coursepersonnel{$person});
                   6820:             if ($end == -1 || $start == -1) {
                   6821:                 next;
                   6822:             }
                   6823:             if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
                   6824:                 (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412     raeburn  6825:                 my ($uname,$udom) = split(/:/,$user);
                   6826:                 if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420     albertel 6827:                     if (grep(/^all$/,@{$sections})) {
1.412     raeburn  6828:                         $secmatch = 1;
                   6829:                     } elsif ($usec eq '') {
1.420     albertel 6830:                         if (grep(/^none$/,@{$sections})) {
1.412     raeburn  6831:                             $secmatch = 1;
                   6832:                         }
                   6833:                     } else {
                   6834:                         if (grep(/^\Q$usec\E$/,@{$sections})) {
                   6835:                             $secmatch = 1;
                   6836:                         }
                   6837:                     }
                   6838:                     if (!$secmatch) {
                   6839:                         next;
                   6840:                     }
1.288     raeburn  6841:                 }
1.419     raeburn  6842:                 if ($usec eq '') {
                   6843:                     $usec = 'none';
                   6844:                 }
1.275     raeburn  6845:                 if ($uname ne '' && $udom ne '') {
1.630     raeburn  6846:                     if ($hidepriv) {
                   6847:                         if ((&Apache::lonnet::privileged($uname,$udom)) &&
                   6848:                             (!$nothide{$uname.':'.$udom})) {
                   6849:                             next;
                   6850:                         }
                   6851:                     }
1.503     raeburn  6852:                     if ($end > 0 && $end < $now) {
1.439     raeburn  6853:                         $status = 'previous';
                   6854:                     } elsif ($start > $now) {
                   6855:                         $status = 'future';
                   6856:                     } else {
                   6857:                         $status = 'active';
                   6858:                     }
1.277     albertel 6859:                     foreach my $type (keys(%{$types})) { 
1.275     raeburn  6860:                         if ($status eq $type) {
1.420     albertel 6861:                             if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419     raeburn  6862:                                 push(@{$$users{$role}{$user}},$type);
                   6863:                             }
1.288     raeburn  6864:                             $match = 1;
                   6865:                         }
                   6866:                     }
1.419     raeburn  6867:                     if (($match) && (ref($userdata) eq 'HASH')) {
                   6868:                         if (!exists($$userdata{$uname.':'.$udom})) {
                   6869: 			    &get_user_info($udom,$uname,\%idx,$userdata);
                   6870:                         }
1.420     albertel 6871:                         if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419     raeburn  6872:                             push(@{$seclists{$uname.':'.$udom}},$usec);
                   6873:                         }
1.609     raeburn  6874:                         if (ref($statushash) eq 'HASH') {
                   6875:                             $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
                   6876:                         }
1.275     raeburn  6877:                     }
                   6878:                 }
                   6879:             }
                   6880:         }
1.290     albertel 6881:         if (grep(/^ow$/,@{$roles})) {
1.279     raeburn  6882:             if ((defined($cdom)) && (defined($cnum))) {
                   6883:                 my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
                   6884:                 if ( defined($csettings{'internal.courseowner'}) ) {
                   6885:                     my $owner = $csettings{'internal.courseowner'};
1.609     raeburn  6886:                     next if ($owner eq '');
                   6887:                     my ($ownername,$ownerdom);
                   6888:                     if ($owner =~ /^([^:]+):([^:]+)$/) {
                   6889:                         $ownername = $1;
                   6890:                         $ownerdom = $2;
                   6891:                     } else {
                   6892:                         $ownername = $owner;
                   6893:                         $ownerdom = $cdom;
                   6894:                         $owner = $ownername.':'.$ownerdom;
1.439     raeburn  6895:                     }
                   6896:                     @{$$users{'ow'}{$owner}} = 'any';
1.290     albertel 6897:                     if (defined($userdata) && 
1.609     raeburn  6898: 			!exists($$userdata{$owner})) {
                   6899: 			&get_user_info($ownerdom,$ownername,\%idx,$userdata);
                   6900:                         if (!grep(/^none$/,@{$seclists{$owner}})) {
                   6901:                             push(@{$seclists{$owner}},'none');
                   6902:                         }
                   6903:                         if (ref($statushash) eq 'HASH') {
                   6904:                             $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419     raeburn  6905:                         }
1.290     albertel 6906: 		    }
1.279     raeburn  6907:                 }
                   6908:             }
                   6909:         }
1.419     raeburn  6910:         foreach my $user (keys(%seclists)) {
                   6911:             @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
                   6912:             $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
                   6913:         }
1.275     raeburn  6914:     }
                   6915:     return;
                   6916: }
                   6917: 
1.288     raeburn  6918: sub get_user_info {
                   6919:     my ($udom,$uname,$idx,$userdata) = @_;
1.289     albertel 6920:     $$userdata{$uname.':'.$udom}[$$idx{fullname}] = 
                   6921: 	&plainname($uname,$udom,'lastname');
1.291     albertel 6922:     $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297     raeburn  6923:     $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609     raeburn  6924:     my %idhash =  &Apache::lonnet::idrget($udom,($uname));
                   6925:     $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname}; 
1.288     raeburn  6926:     return;
                   6927: }
1.275     raeburn  6928: 
1.472     raeburn  6929: ###############################################
                   6930: 
                   6931: =pod
                   6932: 
                   6933: =item * &get_user_quota()
                   6934: 
                   6935: Retrieves quota assigned for storage of portfolio files for a user  
                   6936: 
                   6937: Incoming parameters:
                   6938: 1. user's username
                   6939: 2. user's domain
                   6940: 
                   6941: Returns:
1.536     raeburn  6942: 1. Disk quota (in Mb) assigned to student.
                   6943: 2. (Optional) Type of setting: custom or default
                   6944:    (individually assigned or default for user's 
                   6945:    institutional status).
                   6946: 3. (Optional) - User's institutional status (e.g., faculty, staff
                   6947:    or student - types as defined in localenroll::inst_usertypes 
                   6948:    for user's domain, which determines default quota for user.
                   6949: 4. (Optional) - Default quota which would apply to the user.
1.472     raeburn  6950: 
                   6951: If a value has been stored in the user's environment, 
1.536     raeburn  6952: it will return that, otherwise it returns the maximal default
                   6953: defined for the user's instituional status(es) in the domain.
1.472     raeburn  6954: 
                   6955: =cut
                   6956: 
                   6957: ###############################################
                   6958: 
                   6959: 
                   6960: sub get_user_quota {
                   6961:     my ($uname,$udom) = @_;
1.536     raeburn  6962:     my ($quota,$quotatype,$settingstatus,$defquota);
1.472     raeburn  6963:     if (!defined($udom)) {
                   6964:         $udom = $env{'user.domain'};
                   6965:     }
                   6966:     if (!defined($uname)) {
                   6967:         $uname = $env{'user.name'};
                   6968:     }
                   6969:     if (($udom eq '' || $uname eq '') ||
                   6970:         ($udom eq 'public') && ($uname eq 'public')) {
                   6971:         $quota = 0;
1.536     raeburn  6972:         $quotatype = 'default';
                   6973:         $defquota = 0; 
1.472     raeburn  6974:     } else {
1.536     raeburn  6975:         my $inststatus;
1.472     raeburn  6976:         if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
                   6977:             $quota = $env{'environment.portfolioquota'};
1.536     raeburn  6978:             $inststatus = $env{'environment.inststatus'};
1.472     raeburn  6979:         } else {
1.536     raeburn  6980:             my %userenv = 
                   6981:                 &Apache::lonnet::get('environment',['portfolioquota',
                   6982:                                      'inststatus'],$udom,$uname);
1.472     raeburn  6983:             my ($tmp) = keys(%userenv);
                   6984:             if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   6985:                 $quota = $userenv{'portfolioquota'};
1.536     raeburn  6986:                 $inststatus = $userenv{'inststatus'};
1.472     raeburn  6987:             } else {
                   6988:                 undef(%userenv);
                   6989:             }
                   6990:         }
1.536     raeburn  6991:         ($defquota,$settingstatus) = &default_quota($udom,$inststatus);
1.472     raeburn  6992:         if ($quota eq '') {
1.536     raeburn  6993:             $quota = $defquota;
                   6994:             $quotatype = 'default';
                   6995:         } else {
                   6996:             $quotatype = 'custom';
1.472     raeburn  6997:         }
                   6998:     }
1.536     raeburn  6999:     if (wantarray) {
                   7000:         return ($quota,$quotatype,$settingstatus,$defquota);
                   7001:     } else {
                   7002:         return $quota;
                   7003:     }
1.472     raeburn  7004: }
                   7005: 
                   7006: ###############################################
                   7007: 
                   7008: =pod
                   7009: 
                   7010: =item * &default_quota()
                   7011: 
1.536     raeburn  7012: Retrieves default quota assigned for storage of user portfolio files,
                   7013: given an (optional) user's institutional status.
1.472     raeburn  7014: 
                   7015: Incoming parameters:
                   7016: 1. domain
1.536     raeburn  7017: 2. (Optional) institutional status(es).  This is a : separated list of 
                   7018:    status types (e.g., faculty, staff, student etc.)
                   7019:    which apply to the user for whom the default is being retrieved.
                   7020:    If the institutional status string in undefined, the domain
                   7021:    default quota will be returned. 
1.472     raeburn  7022: 
                   7023: Returns:
                   7024: 1. Default disk quota (in Mb) for user portfolios in the domain.
1.536     raeburn  7025: 2. (Optional) institutional type which determined the value of the
                   7026:    default quota.
1.472     raeburn  7027: 
                   7028: If a value has been stored in the domain's configuration db,
                   7029: it will return that, otherwise it returns 20 (for backwards 
                   7030: compatibility with domains which have not set up a configuration
                   7031: db file; the original statically defined portfolio quota was 20 Mb). 
                   7032: 
1.536     raeburn  7033: If the user's status includes multiple types (e.g., staff and student),
                   7034: the largest default quota which applies to the user determines the
                   7035: default quota returned.
                   7036: 
1.472     raeburn  7037: =cut
                   7038: 
                   7039: ###############################################
                   7040: 
                   7041: 
                   7042: sub default_quota {
1.536     raeburn  7043:     my ($udom,$inststatus) = @_;
                   7044:     my ($defquota,$settingstatus);
                   7045:     my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622     raeburn  7046:                                             ['quotas'],$udom);
                   7047:     if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536     raeburn  7048:         if ($inststatus ne '') {
1.765     raeburn  7049:             my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536     raeburn  7050:             foreach my $item (@statuses) {
1.711     raeburn  7051:                 if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7052:                     if ($quotahash{'quotas'}{'defaultquota'}{$item} ne '') {
                   7053:                         if ($defquota eq '') {
                   7054:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7055:                             $settingstatus = $item;
                   7056:                         } elsif ($quotahash{'quotas'}{'defaultquota'}{$item} > $defquota) {
                   7057:                             $defquota = $quotahash{'quotas'}{'defaultquota'}{$item};
                   7058:                             $settingstatus = $item;
                   7059:                         }
                   7060:                     }
                   7061:                 } else {
                   7062:                     if ($quotahash{'quotas'}{$item} ne '') {
                   7063:                         if ($defquota eq '') {
                   7064:                             $defquota = $quotahash{'quotas'}{$item};
                   7065:                             $settingstatus = $item;
                   7066:                         } elsif ($quotahash{'quotas'}{$item} > $defquota) {
                   7067:                             $defquota = $quotahash{'quotas'}{$item};
                   7068:                             $settingstatus = $item;
                   7069:                         }
1.536     raeburn  7070:                     }
                   7071:                 }
                   7072:             }
                   7073:         }
                   7074:         if ($defquota eq '') {
1.711     raeburn  7075:             if (ref($quotahash{'quotas'}{'defaultquota'}) eq 'HASH') {
                   7076:                 $defquota = $quotahash{'quotas'}{'defaultquota'}{'default'};
                   7077:             } else {
                   7078:                 $defquota = $quotahash{'quotas'}{'default'};
                   7079:             }
1.536     raeburn  7080:             $settingstatus = 'default';
                   7081:         }
                   7082:     } else {
                   7083:         $settingstatus = 'default';
                   7084:         $defquota = 20;
                   7085:     }
                   7086:     if (wantarray) {
                   7087:         return ($defquota,$settingstatus);
1.472     raeburn  7088:     } else {
1.536     raeburn  7089:         return $defquota;
1.472     raeburn  7090:     }
                   7091: }
                   7092: 
1.384     raeburn  7093: sub get_secgrprole_info {
                   7094:     my ($cdom,$cnum,$needroles,$type)  = @_;
                   7095:     my %sections_count = &get_sections($cdom,$cnum);
                   7096:     my @sections =  (sort {$a <=> $b} keys(%sections_count));
                   7097:     my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
                   7098:     my @groups = sort(keys(%curr_groups));
                   7099:     my $allroles = [];
                   7100:     my $rolehash;
                   7101:     my $accesshash = {
                   7102:                      active => 'Currently has access',
                   7103:                      future => 'Will have future access',
                   7104:                      previous => 'Previously had access',
                   7105:                   };
                   7106:     if ($needroles) {
                   7107:         $rolehash = {'all' => 'all'};
1.385     albertel 7108:         my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
                   7109: 	if (&Apache::lonnet::error(%user_roles)) {
                   7110: 	    undef(%user_roles);
                   7111: 	}
                   7112:         foreach my $item (keys(%user_roles)) {
1.384     raeburn  7113:             my ($role)=split(/\:/,$item,2);
                   7114:             if ($role eq 'cr') { next; }
                   7115:             if ($role =~ /^cr/) {
                   7116:                 $$rolehash{$role} = (split('/',$role))[3];
                   7117:             } else {
                   7118:                 $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
                   7119:             }
                   7120:         }
                   7121:         foreach my $key (sort(keys(%{$rolehash}))) {
                   7122:             push(@{$allroles},$key);
                   7123:         }
                   7124:         push (@{$allroles},'st');
                   7125:         $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
                   7126:     }
                   7127:     return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
                   7128: }
                   7129: 
1.555     raeburn  7130: sub user_picker {
1.627     raeburn  7131:     my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype) = @_;
1.555     raeburn  7132:     my $currdom = $dom;
                   7133:     my %curr_selected = (
                   7134:                         srchin => 'dom',
1.580     raeburn  7135:                         srchby => 'lastname',
1.555     raeburn  7136:                       );
                   7137:     my $srchterm;
1.625     raeburn  7138:     if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555     raeburn  7139:         if ($srch->{'srchby'} ne '') {
                   7140:             $curr_selected{'srchby'} = $srch->{'srchby'};
                   7141:         }
                   7142:         if ($srch->{'srchin'} ne '') {
                   7143:             $curr_selected{'srchin'} = $srch->{'srchin'};
                   7144:         }
                   7145:         if ($srch->{'srchtype'} ne '') {
                   7146:             $curr_selected{'srchtype'} = $srch->{'srchtype'};
                   7147:         }
                   7148:         if ($srch->{'srchdomain'} ne '') {
                   7149:             $currdom = $srch->{'srchdomain'};
                   7150:         }
                   7151:         $srchterm = $srch->{'srchterm'};
                   7152:     }
                   7153:     my %lt=&Apache::lonlocal::texthash(
1.573     raeburn  7154:                     'usr'       => 'Search criteria',
1.563     raeburn  7155:                     'doma'      => 'Domain/institution to search',
1.558     albertel 7156:                     'uname'     => 'username',
                   7157:                     'lastname'  => 'last name',
1.555     raeburn  7158:                     'lastfirst' => 'last name, first name',
1.558     albertel 7159:                     'crs'       => 'in this course',
1.576     raeburn  7160:                     'dom'       => 'in selected LON-CAPA domain', 
1.558     albertel 7161:                     'alc'       => 'all LON-CAPA',
1.573     raeburn  7162:                     'instd'     => 'in institutional directory for selected domain',
1.558     albertel 7163:                     'exact'     => 'is',
                   7164:                     'contains'  => 'contains',
1.569     raeburn  7165:                     'begins'    => 'begins with',
1.571     raeburn  7166:                     'youm'      => "You must include some text to search for.",
                   7167:                     'thte'      => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
                   7168:                     'thet'      => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
                   7169:                     'yomc'      => "You must choose a domain when using an institutional directory search.",
                   7170:                     'ymcd'      => "You must choose a domain when using a domain search.",
                   7171:                     'whus'      => "When using searching by last,first you must include a comma as separator between last name and first name.",
                   7172:                     'whse'      => "When searching by last,first you must include at least one character in the first name.",
                   7173:                      'thfo'     => "The following need to be corrected before the search can be run:",
1.555     raeburn  7174:                                        );
1.563     raeburn  7175:     my $domform = &select_dom_form($currdom,'srchdomain',1,1);
                   7176:     my $srchinsel = ' <select name="srchin">';
1.555     raeburn  7177: 
                   7178:     my @srchins = ('crs','dom','alc','instd');
                   7179: 
                   7180:     foreach my $option (@srchins) {
                   7181:         # FIXME 'alc' option unavailable until 
                   7182:         #       loncreateuser::print_user_query_page()
                   7183:         #       has been completed.
                   7184:         next if ($option eq 'alc');
                   7185:         next if ($option eq 'crs' && !$env{'request.course.id'});
1.563     raeburn  7186:         if ($curr_selected{'srchin'} eq $option) {
                   7187:             $srchinsel .= ' 
                   7188:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7189:         } else {
                   7190:             $srchinsel .= '
                   7191:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7192:         }
1.555     raeburn  7193:     }
1.563     raeburn  7194:     $srchinsel .= "\n  </select>\n";
1.555     raeburn  7195: 
                   7196:     my $srchbysel =  ' <select name="srchby">';
1.580     raeburn  7197:     foreach my $option ('lastname','lastfirst','uname') {
1.555     raeburn  7198:         if ($curr_selected{'srchby'} eq $option) {
                   7199:             $srchbysel .= '
                   7200:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7201:         } else {
                   7202:             $srchbysel .= '
                   7203:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7204:          }
                   7205:     }
                   7206:     $srchbysel .= "\n  </select>\n";
                   7207: 
                   7208:     my $srchtypesel = ' <select name="srchtype">';
1.580     raeburn  7209:     foreach my $option ('begins','contains','exact') {
1.555     raeburn  7210:         if ($curr_selected{'srchtype'} eq $option) {
                   7211:             $srchtypesel .= '
                   7212:    <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
                   7213:         } else {
                   7214:             $srchtypesel .= '
                   7215:    <option value="'.$option.'">'.$lt{$option}.'</option>';
                   7216:         }
                   7217:     }
                   7218:     $srchtypesel .= "\n  </select>\n";
                   7219: 
1.558     albertel 7220:     my ($newuserscript,$new_user_create);
1.556     raeburn  7221: 
                   7222:     if ($forcenewuser) {
1.576     raeburn  7223:         if (ref($srch) eq 'HASH') {
                   7224:             if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $env{'request.role.domain'}) {
1.627     raeburn  7225:                 if ($cancreate) {
                   7226:                     $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>';
                   7227:                 } else {
                   7228:                     my $helplink = ' href="javascript:helpMenu('."'display'".')"';
                   7229:                     my %usertypetext = (
                   7230:                         official   => 'institutional',
                   7231:                         unofficial => 'non-institutional',
                   7232:                     );
                   7233:                     $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 />';
                   7234:                 }
1.576     raeburn  7235:             }
                   7236:         }
                   7237: 
1.556     raeburn  7238:         $newuserscript = <<"ENDSCRIPT";
                   7239: 
1.570     raeburn  7240: function setSearch(createnew,callingForm) {
1.556     raeburn  7241:     if (createnew == 1) {
1.570     raeburn  7242:         for (var i=0; i<callingForm.srchby.length; i++) {
                   7243:             if (callingForm.srchby.options[i].value == 'uname') {
                   7244:                 callingForm.srchby.selectedIndex = i;
1.556     raeburn  7245:             }
                   7246:         }
1.570     raeburn  7247:         for (var i=0; i<callingForm.srchin.length; i++) {
                   7248:             if ( callingForm.srchin.options[i].value == 'dom') {
                   7249: 		callingForm.srchin.selectedIndex = i;
1.556     raeburn  7250:             }
                   7251:         }
1.570     raeburn  7252:         for (var i=0; i<callingForm.srchtype.length; i++) {
                   7253:             if (callingForm.srchtype.options[i].value == 'exact') {
                   7254:                 callingForm.srchtype.selectedIndex = i;
1.556     raeburn  7255:             }
                   7256:         }
1.570     raeburn  7257:         for (var i=0; i<callingForm.srchdomain.length; i++) {
                   7258:             if (callingForm.srchdomain.options[i].value == '$env{'request.role.domain'}') {
                   7259:                 callingForm.srchdomain.selectedIndex = i;
1.556     raeburn  7260:             }
                   7261:         }
                   7262:     }
                   7263: }
                   7264: ENDSCRIPT
1.558     albertel 7265: 
1.556     raeburn  7266:     }
                   7267: 
1.555     raeburn  7268:     my $output = <<"END_BLOCK";
1.556     raeburn  7269: <script type="text/javascript">
1.570     raeburn  7270: function validateEntry(callingForm) {
1.558     albertel 7271: 
1.556     raeburn  7272:     var checkok = 1;
1.558     albertel 7273:     var srchin;
1.570     raeburn  7274:     for (var i=0; i<callingForm.srchin.length; i++) {
                   7275: 	if ( callingForm.srchin[i].checked ) {
                   7276: 	    srchin = callingForm.srchin[i].value;
1.558     albertel 7277: 	}
                   7278:     }
                   7279: 
1.570     raeburn  7280:     var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
                   7281:     var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
                   7282:     var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
                   7283:     var srchterm =  callingForm.srchterm.value;
                   7284:     var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556     raeburn  7285:     var msg = "";
                   7286: 
                   7287:     if (srchterm == "") {
                   7288:         checkok = 0;
1.571     raeburn  7289:         msg += "$lt{'youm'}\\n";
1.556     raeburn  7290:     }
                   7291: 
1.569     raeburn  7292:     if (srchtype== 'begins') {
                   7293:         if (srchterm.length < 2) {
                   7294:             checkok = 0;
1.571     raeburn  7295:             msg += "$lt{'thte'}\\n";
1.569     raeburn  7296:         }
                   7297:     }
                   7298: 
1.556     raeburn  7299:     if (srchtype== 'contains') {
                   7300:         if (srchterm.length < 3) {
                   7301:             checkok = 0;
1.571     raeburn  7302:             msg += "$lt{'thet'}\\n";
1.556     raeburn  7303:         }
                   7304:     }
                   7305:     if (srchin == 'instd') {
                   7306:         if (srchdomain == '') {
                   7307:             checkok = 0;
1.571     raeburn  7308:             msg += "$lt{'yomc'}\\n";
1.556     raeburn  7309:         }
                   7310:     }
                   7311:     if (srchin == 'dom') {
                   7312:         if (srchdomain == '') {
                   7313:             checkok = 0;
1.571     raeburn  7314:             msg += "$lt{'ymcd'}\\n";
1.556     raeburn  7315:         }
                   7316:     }
                   7317:     if (srchby == 'lastfirst') {
                   7318:         if (srchterm.indexOf(",") == -1) {
                   7319:             checkok = 0;
1.571     raeburn  7320:             msg += "$lt{'whus'}\\n";
1.556     raeburn  7321:         }
                   7322:         if (srchterm.indexOf(",") == srchterm.length -1) {
                   7323:             checkok = 0;
1.571     raeburn  7324:             msg += "$lt{'whse'}\\n";
1.556     raeburn  7325:         }
                   7326:     }
                   7327:     if (checkok == 0) {
1.571     raeburn  7328:         alert("$lt{'thfo'}\\n"+msg);
1.556     raeburn  7329:         return;
                   7330:     }
                   7331:     if (checkok == 1) {
1.570     raeburn  7332:         callingForm.submit();
1.556     raeburn  7333:     }
                   7334: }
                   7335: 
                   7336: $newuserscript
                   7337: 
                   7338: </script>
1.558     albertel 7339: 
                   7340: $new_user_create
                   7341: 
1.555     raeburn  7342: <table>
1.558     albertel 7343:  <tr>
1.573     raeburn  7344:   <td>$lt{'doma'}:</td>
                   7345:   <td>$domform</td>
                   7346:   </td>
                   7347:  </tr>
                   7348:  <tr>
                   7349:   <td>$lt{'usr'}:</td>
1.563     raeburn  7350:   <td>$srchbysel
                   7351:       $srchtypesel 
                   7352:       <input type="text" size="15" name="srchterm" value="$srchterm" />
1.564     albertel 7353:       $srchinsel 
1.563     raeburn  7354:   </td>
                   7355:  </tr>
1.555     raeburn  7356: </table>
                   7357: <br />
                   7358: END_BLOCK
1.558     albertel 7359: 
1.555     raeburn  7360:     return $output;
                   7361: }
                   7362: 
1.612     raeburn  7363: sub user_rule_check {
1.615     raeburn  7364:     my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612     raeburn  7365:     my $response;
                   7366:     if (ref($usershash) eq 'HASH') {
                   7367:         foreach my $user (keys(%{$usershash})) {
                   7368:             my ($uname,$udom) = split(/:/,$user);
                   7369:             next if ($udom eq '' || $uname eq '');
1.615     raeburn  7370:             my ($id,$newuser);
1.612     raeburn  7371:             if (ref($usershash->{$user}) eq 'HASH') {
1.615     raeburn  7372:                 $newuser = $usershash->{$user}->{'newuser'};
1.612     raeburn  7373:                 $id = $usershash->{$user}->{'id'};
                   7374:             }
                   7375:             my $inst_response;
                   7376:             if (ref($checks) eq 'HASH') {
                   7377:                 if (defined($checks->{'username'})) {
1.615     raeburn  7378:                     ($inst_response,%{$inst_results->{$user}}) = 
1.612     raeburn  7379:                         &Apache::lonnet::get_instuser($udom,$uname);
                   7380:                 } elsif (defined($checks->{'id'})) {
1.615     raeburn  7381:                     ($inst_response,%{$inst_results->{$user}}) =
1.612     raeburn  7382:                         &Apache::lonnet::get_instuser($udom,undef,$id);
                   7383:                 }
1.615     raeburn  7384:             } else {
                   7385:                 ($inst_response,%{$inst_results->{$user}}) =
                   7386:                     &Apache::lonnet::get_instuser($udom,$uname);
                   7387:                 return;
1.612     raeburn  7388:             }
1.615     raeburn  7389:             if (!$got_rules->{$udom}) {
1.612     raeburn  7390:                 my %domconfig = &Apache::lonnet::get_dom('configuration',
                   7391:                                                   ['usercreation'],$udom);
                   7392:                 if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615     raeburn  7393:                     foreach my $item ('username','id') {
1.612     raeburn  7394:                         if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
                   7395:                             $$curr_rules{$udom}{$item} = 
                   7396:                                 $domconfig{'usercreation'}{$item.'_rule'};
1.585     raeburn  7397:                         }
                   7398:                     }
                   7399:                 }
1.615     raeburn  7400:                 $got_rules->{$udom} = 1;  
1.585     raeburn  7401:             }
1.612     raeburn  7402:             foreach my $item (keys(%{$checks})) {
                   7403:                 if (ref($$curr_rules{$udom}) eq 'HASH') {
                   7404:                     if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
                   7405:                         if (@{$$curr_rules{$udom}{$item}} > 0) {
                   7406:                             my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
                   7407:                             foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
                   7408:                                 if ($rule_check{$rule}) {
                   7409:                                     $$rulematch{$user}{$item} = $rule;
                   7410:                                     if ($inst_response eq 'ok') {
1.615     raeburn  7411:                                         if (ref($inst_results) eq 'HASH') {
                   7412:                                             if (ref($inst_results->{$user}) eq 'HASH') {
                   7413:                                                 if (keys(%{$inst_results->{$user}}) == 0) {
                   7414:                                                     $$alerts{$item}{$udom}{$uname} = 1;
                   7415:                                                 }
1.612     raeburn  7416:                                             }
                   7417:                                         }
1.615     raeburn  7418:                                     }
                   7419:                                     last;
1.585     raeburn  7420:                                 }
                   7421:                             }
                   7422:                         }
                   7423:                     }
                   7424:                 }
                   7425:             }
                   7426:         }
                   7427:     }
1.612     raeburn  7428:     return;
                   7429: }
                   7430: 
                   7431: sub user_rule_formats {
                   7432:     my ($domain,$domdesc,$curr_rules,$check) = @_;
                   7433:     my %text = ( 
                   7434:                  'username' => 'Usernames',
                   7435:                  'id'       => 'IDs',
                   7436:                );
                   7437:     my $output;
                   7438:     my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
                   7439:     if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
                   7440:         if (@{$ruleorder} > 0) {
                   7441:             $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>';
                   7442:             foreach my $rule (@{$ruleorder}) {
                   7443:                 if (ref($curr_rules) eq 'ARRAY') {
                   7444:                     if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
                   7445:                         if (ref($rules->{$rule}) eq 'HASH') {
                   7446:                             $output .= '<li>'.$rules->{$rule}{'name'}.': '.
                   7447:                                         $rules->{$rule}{'desc'}.'</li>';
                   7448:                         }
                   7449:                     }
                   7450:                 }
                   7451:             }
                   7452:             $output .= '</ul>';
                   7453:         }
                   7454:     }
                   7455:     return $output;
                   7456: }
                   7457: 
                   7458: sub instrule_disallow_msg {
1.615     raeburn  7459:     my ($checkitem,$domdesc,$count,$mode) = @_;
1.612     raeburn  7460:     my $response;
                   7461:     my %text = (
                   7462:                   item   => 'username',
                   7463:                   items  => 'usernames',
                   7464:                   match  => 'matches',
                   7465:                   do     => 'does',
                   7466:                   action => 'a username',
                   7467:                   one    => 'one',
                   7468:                );
                   7469:     if ($count > 1) {
                   7470:         $text{'item'} = 'usernames';
                   7471:         $text{'match'} ='match';
                   7472:         $text{'do'} = 'do';
                   7473:         $text{'action'} = 'usernames',
                   7474:         $text{'one'} = 'ones';
                   7475:     }
                   7476:     if ($checkitem eq 'id') {
                   7477:         $text{'items'} = 'IDs';
                   7478:         $text{'item'} = 'ID';
                   7479:         $text{'action'} = 'an ID';
1.615     raeburn  7480:         if ($count > 1) {
                   7481:             $text{'item'} = 'IDs';
                   7482:             $text{'action'} = 'IDs';
                   7483:         }
1.612     raeburn  7484:     }
1.674     bisitz   7485:     $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  7486:     if ($mode eq 'upload') {
                   7487:         if ($checkitem eq 'username') {
                   7488:             $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'}.");
                   7489:         } elsif ($checkitem eq 'id') {
1.674     bisitz   7490:             $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  7491:         }
1.669     raeburn  7492:     } elsif ($mode eq 'selfcreate') {
                   7493:         if ($checkitem eq 'id') {
                   7494:             $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.");
                   7495:         }
1.615     raeburn  7496:     } else {
                   7497:         if ($checkitem eq 'username') {
                   7498:             $response .= &mt("You must choose $text{'action'} with a different format --  $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
                   7499:         } elsif ($checkitem eq 'id') {
                   7500:             $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.");
                   7501:         }
1.612     raeburn  7502:     }
                   7503:     return $response;
1.585     raeburn  7504: }
                   7505: 
1.624     raeburn  7506: sub personal_data_fieldtitles {
                   7507:     my %fieldtitles = &Apache::lonlocal::texthash (
                   7508:                         id => 'Student/Employee ID',
                   7509:                         permanentemail => 'E-mail address',
                   7510:                         lastname => 'Last Name',
                   7511:                         firstname => 'First Name',
                   7512:                         middlename => 'Middle Name',
                   7513:                         generation => 'Generation',
                   7514:                         gen => 'Generation',
1.765     raeburn  7515:                         inststatus => 'Affiliation',
1.624     raeburn  7516:                    );
                   7517:     return %fieldtitles;
                   7518: }
                   7519: 
1.642     raeburn  7520: sub sorted_inst_types {
                   7521:     my ($dom) = @_;
                   7522:     my ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
                   7523:     my $othertitle = &mt('All users');
                   7524:     if ($env{'request.course.id'}) {
1.668     raeburn  7525:         $othertitle  = &mt('Any users');
1.642     raeburn  7526:     }
                   7527:     my @types;
                   7528:     if (ref($order) eq 'ARRAY') {
                   7529:         @types = @{$order};
                   7530:     }
                   7531:     if (@types == 0) {
                   7532:         if (ref($usertypes) eq 'HASH') {
                   7533:             @types = sort(keys(%{$usertypes}));
                   7534:         }
                   7535:     }
                   7536:     if (keys(%{$usertypes}) > 0) {
                   7537:         $othertitle = &mt('Other users');
                   7538:     }
                   7539:     return ($othertitle,$usertypes,\@types);
                   7540: }
                   7541: 
1.645     raeburn  7542: sub get_institutional_codes {
                   7543:     my ($settings,$allcourses,$LC_code) = @_;
                   7544: # Get complete list of course sections to update
                   7545:     my @currsections = ();
                   7546:     my @currxlists = ();
                   7547:     my $coursecode = $$settings{'internal.coursecode'};
                   7548: 
                   7549:     if ($$settings{'internal.sectionnums'} ne '') {
                   7550:         @currsections = split(/,/,$$settings{'internal.sectionnums'});
                   7551:     }
                   7552: 
                   7553:     if ($$settings{'internal.crosslistings'} ne '') {
                   7554:         @currxlists = split(/,/,$$settings{'internal.crosslistings'});
                   7555:     }
                   7556: 
                   7557:     if (@currxlists > 0) {
                   7558:         foreach (@currxlists) {
                   7559:             if (m/^([^:]+):(\w*)$/) {
                   7560:                 unless (grep/^$1$/,@{$allcourses}) {
                   7561:                     push @{$allcourses},$1;
                   7562:                     $$LC_code{$1} = $2;
                   7563:                 }
                   7564:             }
                   7565:         }
                   7566:     }
                   7567:  
                   7568:     if (@currsections > 0) {
                   7569:         foreach (@currsections) {
                   7570:             if (m/^(\w+):(\w*)$/) {
                   7571:                 my $sec = $coursecode.$1;
                   7572:                 my $lc_sec = $2;
                   7573:                 unless (grep/^$sec$/,@{$allcourses}) {
                   7574:                     push @{$allcourses},$sec;
                   7575:                     $$LC_code{$sec} = $lc_sec;
                   7576:                 }
                   7577:             }
                   7578:         }
                   7579:     }
                   7580:     return;
                   7581: }
                   7582: 
1.112     bowersj2 7583: =pod
                   7584: 
1.549     albertel 7585: =back
                   7586: 
                   7587: =head1 HTTP Helpers
                   7588: 
                   7589: =over 4
                   7590: 
1.648     raeburn  7591: =item * &get_unprocessed_cgi($query,$possible_names)
1.112     bowersj2 7592: 
1.258     albertel 7593: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112     bowersj2 7594: $query.  The parameters listed in $possible_names (an array reference),
1.258     albertel 7595: will be set in $env{'form.name'} if they do not already exist.
1.112     bowersj2 7596: 
                   7597: Typically called with $ENV{'QUERY_STRING'} as the first parameter.  
                   7598: $possible_names is an ref to an array of form element names.  As an example:
                   7599: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258     albertel 7600: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112     bowersj2 7601: 
                   7602: =cut
1.1       albertel 7603: 
1.6       albertel 7604: sub get_unprocessed_cgi {
1.25      albertel 7605:   my ($query,$possible_names)= @_;
1.26      matthew  7606:   # $Apache::lonxml::debug=1;
1.356     albertel 7607:   foreach my $pair (split(/&/,$query)) {
                   7608:     my ($name, $value) = split(/=/,$pair);
1.369     www      7609:     $name = &unescape($name);
1.25      albertel 7610:     if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
                   7611:       $value =~ tr/+/ /;
                   7612:       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258     albertel 7613:       unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25      albertel 7614:     }
1.16      harris41 7615:   }
1.6       albertel 7616: }
                   7617: 
1.112     bowersj2 7618: =pod
                   7619: 
1.648     raeburn  7620: =item * &cacheheader() 
1.112     bowersj2 7621: 
                   7622: returns cache-controlling header code
                   7623: 
                   7624: =cut
                   7625: 
1.7       albertel 7626: sub cacheheader {
1.258     albertel 7627:     unless ($env{'request.method'} eq 'GET') { return ''; }
1.216     albertel 7628:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
                   7629:     my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7       albertel 7630:                 <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
                   7631:                 <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216     albertel 7632:     return $output;
1.7       albertel 7633: }
                   7634: 
1.112     bowersj2 7635: =pod
                   7636: 
1.648     raeburn  7637: =item * &no_cache($r) 
1.112     bowersj2 7638: 
                   7639: specifies header code to not have cache
                   7640: 
                   7641: =cut
                   7642: 
1.9       albertel 7643: sub no_cache {
1.216     albertel 7644:     my ($r) = @_;
                   7645:     if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258     albertel 7646: 	$env{'request.method'} ne 'GET') { return ''; }
1.216     albertel 7647:     my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
                   7648:     $r->no_cache(1);
                   7649:     $r->header_out("Expires" => $date);
                   7650:     $r->header_out("Pragma" => "no-cache");
1.123     www      7651: }
                   7652: 
                   7653: sub content_type {
1.181     albertel 7654:     my ($r,$type,$charset) = @_;
1.299     foxr     7655:     if ($r) {
                   7656: 	#  Note that printout.pl calls this with undef for $r.
                   7657: 	&no_cache($r);
                   7658:     }
1.258     albertel 7659:     if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181     albertel 7660:     unless ($charset) {
                   7661: 	$charset=&Apache::lonlocal::current_encoding;
                   7662:     }
                   7663:     if ($charset) { $type.='; charset='.$charset; }
                   7664:     if ($r) {
                   7665: 	$r->content_type($type);
                   7666:     } else {
                   7667: 	print("Content-type: $type\n\n");
                   7668:     }
1.9       albertel 7669: }
1.25      albertel 7670: 
1.112     bowersj2 7671: =pod
                   7672: 
1.648     raeburn  7673: =item * &add_to_env($name,$value) 
1.112     bowersj2 7674: 
1.258     albertel 7675: adds $name to the %env hash with value
1.112     bowersj2 7676: $value, if $name already exists, the entry is converted to an array
                   7677: reference and $value is added to the array.
                   7678: 
                   7679: =cut
                   7680: 
1.25      albertel 7681: sub add_to_env {
                   7682:   my ($name,$value)=@_;
1.258     albertel 7683:   if (defined($env{$name})) {
                   7684:     if (ref($env{$name})) {
1.25      albertel 7685:       #already have multiple values
1.258     albertel 7686:       push(@{ $env{$name} },$value);
1.25      albertel 7687:     } else {
                   7688:       #first time seeing multiple values, convert hash entry to an arrayref
1.258     albertel 7689:       my $first=$env{$name};
                   7690:       undef($env{$name});
                   7691:       push(@{ $env{$name} },$first,$value);
1.25      albertel 7692:     }
                   7693:   } else {
1.258     albertel 7694:     $env{$name}=$value;
1.25      albertel 7695:   }
1.31      albertel 7696: }
1.149     albertel 7697: 
                   7698: =pod
                   7699: 
1.648     raeburn  7700: =item * &get_env_multiple($name) 
1.149     albertel 7701: 
1.258     albertel 7702: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149     albertel 7703: values may be defined and end up as an array ref.
                   7704: 
                   7705: returns an array of values
                   7706: 
                   7707: =cut
                   7708: 
                   7709: sub get_env_multiple {
                   7710:     my ($name) = @_;
                   7711:     my @values;
1.258     albertel 7712:     if (defined($env{$name})) {
1.149     albertel 7713:         # exists is it an array
1.258     albertel 7714:         if (ref($env{$name})) {
                   7715:             @values=@{ $env{$name} };
1.149     albertel 7716:         } else {
1.258     albertel 7717:             $values[0]=$env{$name};
1.149     albertel 7718:         }
                   7719:     }
                   7720:     return(@values);
                   7721: }
                   7722: 
1.660     raeburn  7723: sub ask_for_embedded_content {
                   7724:     my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
                   7725:     my $upload_output = '
                   7726:    <form name="upload_embedded" action="'.$actionurl.'"
                   7727:                   method="post" enctype="multipart/form-data">';
                   7728:     $upload_output .= $state;
1.661     raeburn  7729:     $upload_output .= '<b>Upload embedded files</b>:<br />'.&start_data_table();
1.660     raeburn  7730: 
                   7731:     my $num = 0;
                   7732:     foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%{$allfiles})) {
                   7733:         $upload_output .= &start_data_table_row().
                   7734:             '<td>'.$embed_file.'</td><td>';
                   7735:         if ($args->{'ignore_remote_references'}
                   7736:             && $embed_file =~ m{^\w+://}) {
                   7737:             $upload_output.='<span class="LC_warning">'.&mt("URL points to other server.").'</span>';
                   7738:         } elsif ($args->{'error_on_invalid_names'}
                   7739:             && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
                   7740: 
                   7741:             $upload_output.='<span class="LC_warning">'.&mt("Invalid characters").'</span>';
                   7742: 
                   7743:         } else {
                   7744:             $upload_output .='
1.661     raeburn  7745:            <input name="embedded_item_'.$num.'" type="file" value="" />
1.660     raeburn  7746:            <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
                   7747:             my $attrib = join(':',@{$$allfiles{$embed_file}});
                   7748:             $upload_output .=
                   7749:                 "\n\t\t".
                   7750:                 '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
                   7751:                 $attrib.'" />';
                   7752:             if (exists($$codebase{$embed_file})) {
                   7753:                 $upload_output .=
                   7754:                     "\n\t\t".
                   7755:                     '<input name="codebase_'.$num.'" type="hidden" value="'.
                   7756:                     &escape($$codebase{$embed_file}).'" />';
                   7757:             }
                   7758:         }
                   7759:         $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row();
                   7760:         $num++;
                   7761:     }
                   7762:     $upload_output .= &Apache::loncommon::end_data_table().'<br />
                   7763:    <input type ="hidden" name="number_embedded_items" value="'.$num.'" />
                   7764:    <input type ="submit" value="'.&mt('Upload Listed Files').'" />
                   7765:    '.&mt('(only files for which a location has been provided will be uploaded)').'
                   7766:    </form>';
                   7767:     return $upload_output;
                   7768: }
                   7769: 
1.661     raeburn  7770: sub upload_embedded {
                   7771:     my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
                   7772:         $current_disk_usage) = @_;
                   7773:     my $output;
                   7774:     for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
                   7775:         next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
                   7776:         my $orig_uploaded_filename =
                   7777:             $env{'form.embedded_item_'.$i.'.filename'};
                   7778: 
                   7779:         $env{'form.embedded_orig_'.$i} =
                   7780:             &unescape($env{'form.embedded_orig_'.$i});
                   7781:         my ($path,$fname) =
                   7782:             ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
                   7783:         # no path, whole string is fname
                   7784:         if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
                   7785: 
                   7786:         $path = $env{'form.currentpath'}.$path;
                   7787:         $fname = &Apache::lonnet::clean_filename($fname);
                   7788:         # See if there is anything left
                   7789:         next if ($fname eq '');
                   7790: 
                   7791:         # Check if file already exists as a file or directory.
                   7792:         my ($state,$msg);
                   7793:         if ($context eq 'portfolio') {
                   7794:             my $port_path = $dirpath;
                   7795:             if ($group ne '') {
                   7796:                 $port_path = "groups/$group/$port_path";
                   7797:             }
                   7798:             ($state,$msg) = &check_for_upload($path,$fname,$group,'embedded_item_'.$i,
                   7799:                                               $dir_root,$port_path,$disk_quota,
                   7800:                                               $current_disk_usage,$uname,$udom);
                   7801:             if ($state eq 'will_exceed_quota'
                   7802:                 || $state eq 'file_locked'
                   7803:                 || $state eq 'file_exists' ) {
                   7804:                 $output .= $msg;
                   7805:                 next;
                   7806:             }
                   7807:         } elsif (($context eq 'author') || ($context eq 'testbank')) {
                   7808:             ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
                   7809:             if ($state eq 'exists') {
                   7810:                 $output .= $msg;
                   7811:                 next;
                   7812:             }
                   7813:         }
                   7814:         # Check if extension is valid
                   7815:         if (($fname =~ /\.(\w+)$/) &&
                   7816:             (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
                   7817:             $output .= &mt('Invalid file extension ([_1]) - reserved for LONCAPA use - rename the file with a different extension and re-upload. ',$1);
                   7818:             next;
                   7819:         } elsif (($fname =~ /\.(\w+)$/) &&
                   7820:                  (!defined(&Apache::loncommon::fileembstyle($1)))) {
                   7821:             $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
                   7822:             next;
                   7823:         } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
                   7824:             $output .= &mt('File name not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
                   7825:             next;
                   7826:         }
                   7827: 
                   7828:         $env{'form.embedded_item_'.$i.'.filename'}=$fname;
                   7829:         if ($context eq 'portfolio') {
                   7830:             my $result=
                   7831:                 &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
                   7832:                                                 $dirpath.$path);
                   7833:             if ($result !~ m|^/uploaded/|) {
                   7834:                 $output .= '<span class="LC_error">'
                   7835:                       .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
                   7836:                            ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
                   7837:                       .'</span><br />';
                   7838:                 next;
                   7839:             } else {
                   7840:                 $output .= '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
                   7841:                            $path.$fname.'</span>').'</p>';     
                   7842:             }
                   7843:         } else {
                   7844: # Save the file
                   7845:             my $target = $env{'form.embedded_item_'.$i};
                   7846:             my $fullpath = $dir_root.$dirpath.'/'.$path;
                   7847:             my $dest = $fullpath.$fname;
                   7848:             my $url = $url_root.$dirpath.'/'.$path.$fname;
                   7849:             my @parts=split(/\//,$fullpath);
                   7850:             my $count;
                   7851:             my $filepath = $dir_root;
                   7852:             for ($count=4;$count<=$#parts;$count++) {
                   7853:                 $filepath .= "/$parts[$count]";
                   7854:                 if ((-e $filepath)!=1) {
                   7855:                     mkdir($filepath,0770);
                   7856:                 }
                   7857:             }
                   7858:             my $fh;
                   7859:             if (!open($fh,'>'.$dest)) {
                   7860:                 &Apache::lonnet::logthis('Failed to create '.$dest);
                   7861:                 $output .= '<span class="LC_error">'.
                   7862:                            &mt('An error occurred while trying to upload [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   7863:                            '</span><br />';
                   7864:             } else {
                   7865:                 if (!print $fh $env{'form.embedded_item_'.$i}) {
                   7866:                     &Apache::lonnet::logthis('Failed to write to '.$dest);
                   7867:                     $output .= '<span class="LC_error">'.
                   7868:                               &mt('An error occurred while writing the file [_1] for embedded element [_2].',$orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
                   7869:                               '</span><br />';
                   7870:                 } else {
                   7871:                     if ($context eq 'testbank') {
                   7872:                         $output .= &mt('Embedded file uploaded successfully:').
                   7873:                                    '&nbsp;<a href="'.$url.'">'.
                   7874:                                    $orig_uploaded_filename.'</a><br />';
                   7875:                     } else {
1.705     tempelho 7876:                         $output .= '<span class=\"LC_fontsize_large\">'.
1.661     raeburn  7877:                                    &mt('View embedded file: [_1]','<a href="'.$url.'">'.
1.705     tempelho 7878:                                    $orig_uploaded_filename.'</a>').'</span><br />';
1.661     raeburn  7879:                     }
                   7880:                 }
                   7881:                 close($fh);
                   7882:             }
                   7883:         }
                   7884:     }
                   7885:     return $output;
                   7886: }
                   7887: 
                   7888: sub check_for_existing {
                   7889:     my ($path,$fname,$element) = @_;
                   7890:     my ($state,$msg);
                   7891:     if (-d $path.'/'.$fname) {
                   7892:         $state = 'exists';
                   7893:         $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   7894:     } elsif (-e $path.'/'.$fname) {
                   7895:         $state = 'exists';
                   7896:         $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
                   7897:     }
                   7898:     if ($state eq 'exists') {
                   7899:         $msg = '<span class="LC_error">'.$msg.'</span><br />';
                   7900:     }
                   7901:     return ($state,$msg);
                   7902: }
                   7903: 
                   7904: sub check_for_upload {
                   7905:     my ($path,$fname,$group,$element,$portfolio_root,$port_path,
                   7906:         $disk_quota,$current_disk_usage,$uname,$udom) = @_;
                   7907:     my $filesize = (length($env{'form.'.$element})) / 1000; #express in k (1024?)
                   7908:     my $getpropath = 1;
                   7909:     my @dir_list = &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,
                   7910:                                             $getpropath);
                   7911:     my $found_file = 0;
                   7912:     my $locked_file = 0;
                   7913:     foreach my $line (@dir_list) {
                   7914:         my ($file_name)=split(/\&/,$line,2);
                   7915:         if ($file_name eq $fname){
                   7916:             $file_name = $path.$file_name;
                   7917:             if ($group ne '') {
                   7918:                 $file_name = $group.$file_name;
                   7919:             }
                   7920:             $found_file = 1;
                   7921:             if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
                   7922:                 $locked_file = 1;
                   7923:             }
                   7924:         }
                   7925:     }
                   7926:     if (($current_disk_usage + $filesize) > $disk_quota){
                   7927:         my $msg = '<span class="LC_error">'.
                   7928:                 &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</span>'.
                   7929:                   '<br />'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage);
                   7930:         return ('will_exceed_quota',$msg);
                   7931:     } elsif ($found_file) {
                   7932:         if ($locked_file) {
                   7933:             my $msg = '<span class="LC_error">';
                   7934:             $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>');
                   7935:             $msg .= '</span><br />';
                   7936:             $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
                   7937:             return ('file_locked',$msg);
                   7938:         } else {
                   7939:             my $msg = '<span class="LC_error">';
                   7940:             $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'});
                   7941:             $msg .= '</span>';
                   7942:             $msg .= '<br />';
                   7943:             $msg .= &mt('To upload, rename or delete existing [_1] in [_2].','<span class="LC_filename">'.$fname.'</span>', $port_path.$env{'form.currentpath'});
                   7944:             return ('file_exists',$msg);
                   7945:         }
                   7946:     }
                   7947: }
                   7948: 
1.31      albertel 7949: 
1.41      ng       7950: =pod
1.45      matthew  7951: 
1.464     albertel 7952: =back
1.41      ng       7953: 
1.112     bowersj2 7954: =head1 CSV Upload/Handling functions
1.38      albertel 7955: 
1.41      ng       7956: =over 4
                   7957: 
1.648     raeburn  7958: =item * &upfile_store($r)
1.41      ng       7959: 
                   7960: Store uploaded file, $r should be the HTTP Request object,
1.258     albertel 7961: needs $env{'form.upfile'}
1.41      ng       7962: returns $datatoken to be put into hidden field
                   7963: 
                   7964: =cut
1.31      albertel 7965: 
                   7966: sub upfile_store {
                   7967:     my $r=shift;
1.258     albertel 7968:     $env{'form.upfile'}=~s/\r/\n/gs;
                   7969:     $env{'form.upfile'}=~s/\f/\n/gs;
                   7970:     $env{'form.upfile'}=~s/\n+/\n/gs;
                   7971:     $env{'form.upfile'}=~s/\n+$//gs;
1.31      albertel 7972: 
1.258     albertel 7973:     my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
                   7974: 	'_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31      albertel 7975:     {
1.158     raeburn  7976:         my $datafile = $r->dir_config('lonDaemons').
                   7977:                            '/tmp/'.$datatoken.'.tmp';
                   7978:         if ( open(my $fh,">$datafile") ) {
1.258     albertel 7979:             print $fh $env{'form.upfile'};
1.158     raeburn  7980:             close($fh);
                   7981:         }
1.31      albertel 7982:     }
                   7983:     return $datatoken;
                   7984: }
                   7985: 
1.56      matthew  7986: =pod
                   7987: 
1.648     raeburn  7988: =item * &load_tmp_file($r)
1.41      ng       7989: 
                   7990: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258     albertel 7991: needs $env{'form.datatoken'},
                   7992: sets $env{'form.upfile'} to the contents of the file
1.41      ng       7993: 
                   7994: =cut
1.31      albertel 7995: 
                   7996: sub load_tmp_file {
                   7997:     my $r=shift;
                   7998:     my @studentdata=();
                   7999:     {
1.158     raeburn  8000:         my $studentfile = $r->dir_config('lonDaemons').
1.258     albertel 8001:                               '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158     raeburn  8002:         if ( open(my $fh,"<$studentfile") ) {
                   8003:             @studentdata=<$fh>;
                   8004:             close($fh);
                   8005:         }
1.31      albertel 8006:     }
1.258     albertel 8007:     $env{'form.upfile'}=join('',@studentdata);
1.31      albertel 8008: }
                   8009: 
1.56      matthew  8010: =pod
                   8011: 
1.648     raeburn  8012: =item * &upfile_record_sep()
1.41      ng       8013: 
                   8014: Separate uploaded file into records
                   8015: returns array of records,
1.258     albertel 8016: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41      ng       8017: 
                   8018: =cut
1.31      albertel 8019: 
                   8020: sub upfile_record_sep {
1.258     albertel 8021:     if ($env{'form.upfiletype'} eq 'xml') {
1.31      albertel 8022:     } else {
1.248     albertel 8023: 	my @records;
1.258     albertel 8024: 	foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248     albertel 8025: 	    if ($line=~/^\s*$/) { next; }
                   8026: 	    push(@records,$line);
                   8027: 	}
                   8028: 	return @records;
1.31      albertel 8029:     }
                   8030: }
                   8031: 
1.56      matthew  8032: =pod
                   8033: 
1.648     raeburn  8034: =item * &record_sep($record)
1.41      ng       8035: 
1.258     albertel 8036: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41      ng       8037: 
                   8038: =cut
                   8039: 
1.263     www      8040: sub takeleft {
                   8041:     my $index=shift;
                   8042:     return substr('0000'.$index,-4,4);
                   8043: }
                   8044: 
1.31      albertel 8045: sub record_sep {
                   8046:     my $record=shift;
                   8047:     my %components=();
1.258     albertel 8048:     if ($env{'form.upfiletype'} eq 'xml') {
                   8049:     } elsif ($env{'form.upfiletype'} eq 'space') {
1.31      albertel 8050:         my $i=0;
1.356     albertel 8051:         foreach my $field (split(/\s+/,$record)) {
1.31      albertel 8052:             $field=~s/^(\"|\')//;
                   8053:             $field=~s/(\"|\')$//;
1.263     www      8054:             $components{&takeleft($i)}=$field;
1.31      albertel 8055:             $i++;
                   8056:         }
1.258     albertel 8057:     } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31      albertel 8058:         my $i=0;
1.356     albertel 8059:         foreach my $field (split(/\t/,$record)) {
1.31      albertel 8060:             $field=~s/^(\"|\')//;
                   8061:             $field=~s/(\"|\')$//;
1.263     www      8062:             $components{&takeleft($i)}=$field;
1.31      albertel 8063:             $i++;
                   8064:         }
                   8065:     } else {
1.561     www      8066:         my $separator=',';
1.480     banghart 8067:         if ($env{'form.upfiletype'} eq 'semisv') {
1.561     www      8068:             $separator=';';
1.480     banghart 8069:         }
1.31      albertel 8070:         my $i=0;
1.561     www      8071: # the character we are looking for to indicate the end of a quote or a record 
                   8072:         my $looking_for=$separator;
                   8073: # do not add the characters to the fields
                   8074:         my $ignore=0;
                   8075: # we just encountered a separator (or the beginning of the record)
                   8076:         my $just_found_separator=1;
                   8077: # store the field we are working on here
                   8078:         my $field='';
                   8079: # work our way through all characters in record
                   8080:         foreach my $character ($record=~/(.)/g) {
                   8081:             if ($character eq $looking_for) {
                   8082:                if ($character ne $separator) {
                   8083: # Found the end of a quote, again looking for separator
                   8084:                   $looking_for=$separator;
                   8085:                   $ignore=1;
                   8086:                } else {
                   8087: # Found a separator, store away what we got
                   8088:                   $components{&takeleft($i)}=$field;
                   8089: 	          $i++;
                   8090:                   $just_found_separator=1;
                   8091:                   $ignore=0;
                   8092:                   $field='';
                   8093:                }
                   8094:                next;
                   8095:             }
                   8096: # single or double quotation marks after a separator indicate beginning of a quote
                   8097: # we are now looking for the end of the quote and need to ignore separators
                   8098:             if ((($character eq '"') || ($character eq "'")) && ($just_found_separator))  {
                   8099:                $looking_for=$character;
                   8100:                next;
                   8101:             }
                   8102: # ignore would be true after we reached the end of a quote
                   8103:             if ($ignore) { next; }
                   8104:             if (($just_found_separator) && ($character=~/\s/)) { next; }
                   8105:             $field.=$character;
                   8106:             $just_found_separator=0; 
1.31      albertel 8107:         }
1.561     www      8108: # catch the very last entry, since we never encountered the separator
                   8109:         $components{&takeleft($i)}=$field;
1.31      albertel 8110:     }
                   8111:     return %components;
                   8112: }
                   8113: 
1.144     matthew  8114: ######################################################
                   8115: ######################################################
                   8116: 
1.56      matthew  8117: =pod
                   8118: 
1.648     raeburn  8119: =item * &upfile_select_html()
1.41      ng       8120: 
1.144     matthew  8121: Return HTML code to select a file from the users machine and specify 
                   8122: the file type.
1.41      ng       8123: 
                   8124: =cut
                   8125: 
1.144     matthew  8126: ######################################################
                   8127: ######################################################
1.31      albertel 8128: sub upfile_select_html {
1.144     matthew  8129:     my %Types = (
                   8130:                  csv   => &mt('CSV (comma separated values, spreadsheet)'),
1.480     banghart 8131:                  semisv => &mt('Semicolon separated values'),
1.144     matthew  8132:                  space => &mt('Space separated'),
                   8133:                  tab   => &mt('Tabulator separated'),
                   8134: #                 xml   => &mt('HTML/XML'),
                   8135:                  );
                   8136:     my $Str = '<input type="file" name="upfile" size="50" />'.
1.727     riegler  8137:         '<br />'.&mt('Type').': <select name="upfiletype">';
1.144     matthew  8138:     foreach my $type (sort(keys(%Types))) {
                   8139:         $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
                   8140:     }
                   8141:     $Str .= "</select>\n";
                   8142:     return $Str;
1.31      albertel 8143: }
                   8144: 
1.301     albertel 8145: sub get_samples {
                   8146:     my ($records,$toget) = @_;
                   8147:     my @samples=({});
                   8148:     my $got=0;
                   8149:     foreach my $rec (@$records) {
                   8150: 	my %temp = &record_sep($rec);
                   8151: 	if (! grep(/\S/, values(%temp))) { next; }
                   8152: 	if (%temp) {
                   8153: 	    $samples[$got]=\%temp;
                   8154: 	    $got++;
                   8155: 	    if ($got == $toget) { last; }
                   8156: 	}
                   8157:     }
                   8158:     return \@samples;
                   8159: }
                   8160: 
1.144     matthew  8161: ######################################################
                   8162: ######################################################
                   8163: 
1.56      matthew  8164: =pod
                   8165: 
1.648     raeburn  8166: =item * &csv_print_samples($r,$records)
1.41      ng       8167: 
                   8168: Prints a table of sample values from each column uploaded $r is an
                   8169: Apache Request ref, $records is an arrayref from
                   8170: &Apache::loncommon::upfile_record_sep
                   8171: 
                   8172: =cut
                   8173: 
1.144     matthew  8174: ######################################################
                   8175: ######################################################
1.31      albertel 8176: sub csv_print_samples {
                   8177:     my ($r,$records) = @_;
1.662     bisitz   8178:     my $samples = &get_samples($records,5);
1.301     albertel 8179: 
1.594     raeburn  8180:     $r->print(&mt('Samples').'<br />'.&start_data_table().
                   8181:               &start_data_table_header_row());
1.356     albertel 8182:     foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) { 
                   8183:         $r->print('<th>'.&mt('Column&nbsp;[_1]',($sample+1)).'</th>'); }
1.594     raeburn  8184:     $r->print(&end_data_table_header_row());
1.301     albertel 8185:     foreach my $hash (@$samples) {
1.594     raeburn  8186: 	$r->print(&start_data_table_row());
1.356     albertel 8187: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31      albertel 8188: 	    $r->print('<td>');
1.356     albertel 8189: 	    if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31      albertel 8190: 	    $r->print('</td>');
                   8191: 	}
1.594     raeburn  8192: 	$r->print(&end_data_table_row());
1.31      albertel 8193:     }
1.594     raeburn  8194:     $r->print(&end_data_table().'<br />'."\n");
1.31      albertel 8195: }
                   8196: 
1.144     matthew  8197: ######################################################
                   8198: ######################################################
                   8199: 
1.56      matthew  8200: =pod
                   8201: 
1.648     raeburn  8202: =item * &csv_print_select_table($r,$records,$d)
1.41      ng       8203: 
                   8204: Prints a table to create associations between values and table columns.
1.144     matthew  8205: 
1.41      ng       8206: $r is an Apache Request ref,
                   8207: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174     matthew  8208: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41      ng       8209: 
                   8210: =cut
                   8211: 
1.144     matthew  8212: ######################################################
                   8213: ######################################################
1.31      albertel 8214: sub csv_print_select_table {
                   8215:     my ($r,$records,$d) = @_;
1.301     albertel 8216:     my $i=0;
                   8217:     my $samples = &get_samples($records,1);
1.144     matthew  8218:     $r->print(&mt('Associate columns with student attributes.')."\n".
1.594     raeburn  8219: 	      &start_data_table().&start_data_table_header_row().
1.144     matthew  8220:               '<th>'.&mt('Attribute').'</th>'.
1.594     raeburn  8221:               '<th>'.&mt('Column').'</th>'.
                   8222:               &end_data_table_header_row()."\n");
1.356     albertel 8223:     foreach my $array_ref (@$d) {
                   8224: 	my ($value,$display,$defaultcol)=@{ $array_ref };
1.729     raeburn  8225: 	$r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31      albertel 8226: 
                   8227: 	$r->print('<td><select name=f'.$i.
1.32      matthew  8228: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.31      albertel 8229: 	$r->print('<option value="none"></option>');
1.356     albertel 8230: 	foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
                   8231: 	    $r->print('<option value="'.$sample.'"'.
                   8232:                       ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662     bisitz   8233:                       '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31      albertel 8234: 	}
1.594     raeburn  8235: 	$r->print('</select></td>'.&end_data_table_row()."\n");
1.31      albertel 8236: 	$i++;
                   8237:     }
1.594     raeburn  8238:     $r->print(&end_data_table());
1.31      albertel 8239:     $i--;
                   8240:     return $i;
                   8241: }
1.56      matthew  8242: 
1.144     matthew  8243: ######################################################
                   8244: ######################################################
                   8245: 
1.56      matthew  8246: =pod
1.31      albertel 8247: 
1.648     raeburn  8248: =item * &csv_samples_select_table($r,$records,$d)
1.41      ng       8249: 
                   8250: Prints a table of sample values from the upload and can make associate samples to internal names.
                   8251: 
                   8252: $r is an Apache Request ref,
                   8253: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
                   8254: $d is an array of 2 element arrays (internal name, displayed name)
                   8255: 
                   8256: =cut
                   8257: 
1.144     matthew  8258: ######################################################
                   8259: ######################################################
1.31      albertel 8260: sub csv_samples_select_table {
                   8261:     my ($r,$records,$d) = @_;
                   8262:     my $i=0;
1.144     matthew  8263:     #
1.662     bisitz   8264:     my $max_samples = 5;
                   8265:     my $samples = &get_samples($records,$max_samples);
1.594     raeburn  8266:     $r->print(&start_data_table().
                   8267:               &start_data_table_header_row().'<th>'.
                   8268:               &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
                   8269:               &end_data_table_header_row());
1.301     albertel 8270: 
                   8271:     foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594     raeburn  8272: 	$r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32      matthew  8273: 		  ' onchange="javascript:flip(this.form,'.$i.');">');
1.301     albertel 8274: 	foreach my $option (@$d) {
                   8275: 	    my ($value,$display,$defaultcol)=@{ $option };
1.174     matthew  8276: 	    $r->print('<option value="'.$value.'"'.
1.253     albertel 8277:                       ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174     matthew  8278:                       $display.'</option>');
1.31      albertel 8279: 	}
                   8280: 	$r->print('</select></td><td>');
1.662     bisitz   8281: 	foreach my $line (0..($max_samples-1)) {
1.301     albertel 8282: 	    if (defined($samples->[$line]{$key})) { 
                   8283: 		$r->print($samples->[$line]{$key}."<br />\n"); 
                   8284: 	    }
                   8285: 	}
1.594     raeburn  8286: 	$r->print('</td>'.&end_data_table_row());
1.31      albertel 8287: 	$i++;
                   8288:     }
1.594     raeburn  8289:     $r->print(&end_data_table());
1.31      albertel 8290:     $i--;
                   8291:     return($i);
1.115     matthew  8292: }
                   8293: 
1.144     matthew  8294: ######################################################
                   8295: ######################################################
                   8296: 
1.115     matthew  8297: =pod
                   8298: 
1.648     raeburn  8299: =item * &clean_excel_name($name)
1.115     matthew  8300: 
                   8301: Returns a replacement for $name which does not contain any illegal characters.
                   8302: 
                   8303: =cut
                   8304: 
1.144     matthew  8305: ######################################################
                   8306: ######################################################
1.115     matthew  8307: sub clean_excel_name {
                   8308:     my ($name) = @_;
                   8309:     $name =~ s/[:\*\?\/\\]//g;
                   8310:     if (length($name) > 31) {
                   8311:         $name = substr($name,0,31);
                   8312:     }
                   8313:     return $name;
1.25      albertel 8314: }
1.84      albertel 8315: 
1.85      albertel 8316: =pod
                   8317: 
1.648     raeburn  8318: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85      albertel 8319: 
                   8320: Returns either 1 or undef
                   8321: 
                   8322: 1 if the part is to be hidden, undef if it is to be shown
                   8323: 
                   8324: Arguments are:
                   8325: 
                   8326: $id the id of the part to be checked
                   8327: $symb, optional the symb of the resource to check
                   8328: $udom, optional the domain of the user to check for
                   8329: $uname, optional the username of the user to check for
                   8330: 
                   8331: =cut
1.84      albertel 8332: 
                   8333: sub check_if_partid_hidden {
                   8334:     my ($id,$symb,$udom,$uname) = @_;
1.133     albertel 8335:     my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84      albertel 8336: 					 $symb,$udom,$uname);
1.141     albertel 8337:     my $truth=1;
                   8338:     #if the string starts with !, then the list is the list to show not hide
                   8339:     if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84      albertel 8340:     my @hiddenlist=split(/,/,$hiddenparts);
                   8341:     foreach my $checkid (@hiddenlist) {
1.141     albertel 8342: 	if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84      albertel 8343:     }
1.141     albertel 8344:     return !$truth;
1.84      albertel 8345: }
1.127     matthew  8346: 
1.138     matthew  8347: 
                   8348: ############################################################
                   8349: ############################################################
                   8350: 
                   8351: =pod
                   8352: 
1.157     matthew  8353: =back 
                   8354: 
1.138     matthew  8355: =head1 cgi-bin script and graphing routines
                   8356: 
1.157     matthew  8357: =over 4
                   8358: 
1.648     raeburn  8359: =item * &get_cgi_id()
1.138     matthew  8360: 
                   8361: Inputs: none
                   8362: 
                   8363: Returns an id which can be used to pass environment variables
                   8364: to various cgi-bin scripts.  These environment variables will
                   8365: be removed from the users environment after a given time by
                   8366: the routine &Apache::lonnet::transfer_profile_to_env.
                   8367: 
                   8368: =cut
                   8369: 
                   8370: ############################################################
                   8371: ############################################################
1.152     albertel 8372: my $uniq=0;
1.136     matthew  8373: sub get_cgi_id {
1.154     albertel 8374:     $uniq=($uniq+1)%100000;
1.280     albertel 8375:     return (time.'_'.$$.'_'.$uniq);
1.136     matthew  8376: }
                   8377: 
1.127     matthew  8378: ############################################################
                   8379: ############################################################
                   8380: 
                   8381: =pod
                   8382: 
1.648     raeburn  8383: =item * &DrawBarGraph()
1.127     matthew  8384: 
1.138     matthew  8385: Facilitates the plotting of data in a (stacked) bar graph.
                   8386: Puts plot definition data into the users environment in order for 
                   8387: graph.png to plot it.  Returns an <img> tag for the plot.
                   8388: The bars on the plot are labeled '1','2',...,'n'.
                   8389: 
                   8390: Inputs:
                   8391: 
                   8392: =over 4
                   8393: 
                   8394: =item $Title: string, the title of the plot
                   8395: 
                   8396: =item $xlabel: string, text describing the X-axis of the plot
                   8397: 
                   8398: =item $ylabel: string, text describing the Y-axis of the plot
                   8399: 
                   8400: =item $Max: scalar, the maximum Y value to use in the plot
                   8401: If $Max is < any data point, the graph will not be rendered.
                   8402: 
1.140     matthew  8403: =item $colors: array ref holding the colors to be used for the data sets when
1.138     matthew  8404: they are plotted.  If undefined, default values will be used.
                   8405: 
1.178     matthew  8406: =item $labels: array ref holding the labels to use on the x-axis for the bars.
                   8407: 
1.138     matthew  8408: =item @Values: An array of array references.  Each array reference holds data
                   8409: to be plotted in a stacked bar chart.
                   8410: 
1.239     matthew  8411: =item If the final element of @Values is a hash reference the key/value
                   8412: pairs will be added to the graph definition.
                   8413: 
1.138     matthew  8414: =back
                   8415: 
                   8416: Returns:
                   8417: 
                   8418: An <img> tag which references graph.png and the appropriate identifying
                   8419: information for the plot.
                   8420: 
1.127     matthew  8421: =cut
                   8422: 
                   8423: ############################################################
                   8424: ############################################################
1.134     matthew  8425: sub DrawBarGraph {
1.178     matthew  8426:     my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134     matthew  8427:     #
                   8428:     if (! defined($colors)) {
                   8429:         $colors = ['#33ff00', 
                   8430:                   '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
                   8431:                   '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
                   8432:                   ]; 
                   8433:     }
1.228     matthew  8434:     my $extra_settings = {};
                   8435:     if (ref($Values[-1]) eq 'HASH') {
                   8436:         $extra_settings = pop(@Values);
                   8437:     }
1.127     matthew  8438:     #
1.136     matthew  8439:     my $identifier = &get_cgi_id();
                   8440:     my $id = 'cgi.'.$identifier;        
1.129     matthew  8441:     if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127     matthew  8442:         return '';
                   8443:     }
1.225     matthew  8444:     #
                   8445:     my @Labels;
                   8446:     if (defined($labels)) {
                   8447:         @Labels = @$labels;
                   8448:     } else {
                   8449:         for (my $i=0;$i<@{$Values[0]};$i++) {
                   8450:             push (@Labels,$i+1);
                   8451:         }
                   8452:     }
                   8453:     #
1.129     matthew  8454:     my $NumBars = scalar(@{$Values[0]});
1.225     matthew  8455:     if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129     matthew  8456:     my %ValuesHash;
                   8457:     my $NumSets=1;
                   8458:     foreach my $array (@Values) {
                   8459:         next if (! ref($array));
1.136     matthew  8460:         $ValuesHash{$id.'.data.'.$NumSets++} = 
1.132     matthew  8461:             join(',',@$array);
1.129     matthew  8462:     }
1.127     matthew  8463:     #
1.136     matthew  8464:     my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225     matthew  8465:     if ($NumBars < 3) {
                   8466:         $width = 120+$NumBars*32;
1.220     matthew  8467:         $xskip = 1;
1.225     matthew  8468:         $bar_width = 30;
                   8469:     } elsif ($NumBars < 5) {
                   8470:         $width = 120+$NumBars*20;
                   8471:         $xskip = 1;
                   8472:         $bar_width = 20;
1.220     matthew  8473:     } elsif ($NumBars < 10) {
1.136     matthew  8474:         $width = 120+$NumBars*15;
                   8475:         $xskip = 1;
                   8476:         $bar_width = 15;
                   8477:     } elsif ($NumBars <= 25) {
                   8478:         $width = 120+$NumBars*11;
                   8479:         $xskip = 5;
                   8480:         $bar_width = 8;
                   8481:     } elsif ($NumBars <= 50) {
                   8482:         $width = 120+$NumBars*8;
                   8483:         $xskip = 5;
                   8484:         $bar_width = 4;
                   8485:     } else {
                   8486:         $width = 120+$NumBars*8;
                   8487:         $xskip = 5;
                   8488:         $bar_width = 4;
                   8489:     }
                   8490:     #
1.137     matthew  8491:     $Max = 1 if ($Max < 1);
                   8492:     if ( int($Max) < $Max ) {
                   8493:         $Max++;
                   8494:         $Max = int($Max);
                   8495:     }
1.127     matthew  8496:     $Title  = '' if (! defined($Title));
                   8497:     $xlabel = '' if (! defined($xlabel));
                   8498:     $ylabel = '' if (! defined($ylabel));
1.369     www      8499:     $ValuesHash{$id.'.title'}    = &escape($Title);
                   8500:     $ValuesHash{$id.'.xlabel'}   = &escape($xlabel);
                   8501:     $ValuesHash{$id.'.ylabel'}   = &escape($ylabel);
1.137     matthew  8502:     $ValuesHash{$id.'.y_max_value'} = $Max;
1.136     matthew  8503:     $ValuesHash{$id.'.NumBars'}  = $NumBars;
                   8504:     $ValuesHash{$id.'.NumSets'}  = $NumSets;
                   8505:     $ValuesHash{$id.'.PlotType'} = 'bar';
                   8506:     $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8507:     $ValuesHash{$id.'.height'}   = $height;
                   8508:     $ValuesHash{$id.'.width'}    = $width;
                   8509:     $ValuesHash{$id.'.xskip'}    = $xskip;
                   8510:     $ValuesHash{$id.'.bar_width'} = $bar_width;
                   8511:     $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127     matthew  8512:     #
1.228     matthew  8513:     # Deal with other parameters
                   8514:     while (my ($key,$value) = each(%$extra_settings)) {
                   8515:         $ValuesHash{$id.'.'.$key} = $value;
                   8516:     }
                   8517:     #
1.646     raeburn  8518:     &Apache::lonnet::appenv(\%ValuesHash);
1.137     matthew  8519:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   8520: }
                   8521: 
                   8522: ############################################################
                   8523: ############################################################
                   8524: 
                   8525: =pod
                   8526: 
1.648     raeburn  8527: =item * &DrawXYGraph()
1.137     matthew  8528: 
1.138     matthew  8529: Facilitates the plotting of data in an XY graph.
                   8530: Puts plot definition data into the users environment in order for 
                   8531: graph.png to plot it.  Returns an <img> tag for the plot.
                   8532: 
                   8533: Inputs:
                   8534: 
                   8535: =over 4
                   8536: 
                   8537: =item $Title: string, the title of the plot
                   8538: 
                   8539: =item $xlabel: string, text describing the X-axis of the plot
                   8540: 
                   8541: =item $ylabel: string, text describing the Y-axis of the plot
                   8542: 
                   8543: =item $Max: scalar, the maximum Y value to use in the plot
                   8544: If $Max is < any data point, the graph will not be rendered.
                   8545: 
                   8546: =item $colors: Array ref containing the hex color codes for the data to be 
                   8547: plotted in.  If undefined, default values will be used.
                   8548: 
                   8549: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   8550: 
                   8551: =item $Ydata: Array ref containing Array refs.  
1.185     www      8552: Each of the contained arrays will be plotted as a separate curve.
1.138     matthew  8553: 
                   8554: =item %Values: hash indicating or overriding any default values which are 
                   8555: passed to graph.png.  
                   8556: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   8557: 
                   8558: =back
                   8559: 
                   8560: Returns:
                   8561: 
                   8562: An <img> tag which references graph.png and the appropriate identifying
                   8563: information for the plot.
                   8564: 
1.137     matthew  8565: =cut
                   8566: 
                   8567: ############################################################
                   8568: ############################################################
                   8569: sub DrawXYGraph {
                   8570:     my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
                   8571:     #
                   8572:     # Create the identifier for the graph
                   8573:     my $identifier = &get_cgi_id();
                   8574:     my $id = 'cgi.'.$identifier;
                   8575:     #
                   8576:     $Title  = '' if (! defined($Title));
                   8577:     $xlabel = '' if (! defined($xlabel));
                   8578:     $ylabel = '' if (! defined($ylabel));
                   8579:     my %ValuesHash = 
                   8580:         (
1.369     www      8581:          $id.'.title'  => &escape($Title),
                   8582:          $id.'.xlabel' => &escape($xlabel),
                   8583:          $id.'.ylabel' => &escape($ylabel),
1.137     matthew  8584:          $id.'.y_max_value'=> $Max,
                   8585:          $id.'.labels'     => join(',',@$Xlabels),
                   8586:          $id.'.PlotType'   => 'XY',
                   8587:          );
                   8588:     #
                   8589:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   8590:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8591:     }
                   8592:     #
                   8593:     if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
                   8594:         return '';
                   8595:     }
                   8596:     my $NumSets=1;
1.138     matthew  8597:     foreach my $array (@{$Ydata}){
1.137     matthew  8598:         next if (! ref($array));
                   8599:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
                   8600:     }
1.138     matthew  8601:     $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137     matthew  8602:     #
                   8603:     # Deal with other parameters
                   8604:     while (my ($key,$value) = each(%Values)) {
                   8605:         $ValuesHash{$id.'.'.$key} = $value;
1.127     matthew  8606:     }
                   8607:     #
1.646     raeburn  8608:     &Apache::lonnet::appenv(\%ValuesHash);
1.136     matthew  8609:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
                   8610: }
                   8611: 
                   8612: ############################################################
                   8613: ############################################################
                   8614: 
                   8615: =pod
                   8616: 
1.648     raeburn  8617: =item * &DrawXYYGraph()
1.138     matthew  8618: 
                   8619: Facilitates the plotting of data in an XY graph with two Y axes.
                   8620: Puts plot definition data into the users environment in order for 
                   8621: graph.png to plot it.  Returns an <img> tag for the plot.
                   8622: 
                   8623: Inputs:
                   8624: 
                   8625: =over 4
                   8626: 
                   8627: =item $Title: string, the title of the plot
                   8628: 
                   8629: =item $xlabel: string, text describing the X-axis of the plot
                   8630: 
                   8631: =item $ylabel: string, text describing the Y-axis of the plot
                   8632: 
                   8633: =item $colors: Array ref containing the hex color codes for the data to be 
                   8634: plotted in.  If undefined, default values will be used.
                   8635: 
                   8636: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
                   8637: 
                   8638: =item $Ydata1: The first data set
                   8639: 
                   8640: =item $Min1: The minimum value of the left Y-axis
                   8641: 
                   8642: =item $Max1: The maximum value of the left Y-axis
                   8643: 
                   8644: =item $Ydata2: The second data set
                   8645: 
                   8646: =item $Min2: The minimum value of the right Y-axis
                   8647: 
                   8648: =item $Max2: The maximum value of the left Y-axis
                   8649: 
                   8650: =item %Values: hash indicating or overriding any default values which are 
                   8651: passed to graph.png.  
                   8652: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
                   8653: 
                   8654: =back
                   8655: 
                   8656: Returns:
                   8657: 
                   8658: An <img> tag which references graph.png and the appropriate identifying
                   8659: information for the plot.
1.136     matthew  8660: 
                   8661: =cut
                   8662: 
                   8663: ############################################################
                   8664: ############################################################
1.137     matthew  8665: sub DrawXYYGraph {
                   8666:     my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
                   8667:                                         $Ydata2,$Min2,$Max2,%Values)=@_;
1.136     matthew  8668:     #
                   8669:     # Create the identifier for the graph
                   8670:     my $identifier = &get_cgi_id();
                   8671:     my $id = 'cgi.'.$identifier;
                   8672:     #
                   8673:     $Title  = '' if (! defined($Title));
                   8674:     $xlabel = '' if (! defined($xlabel));
                   8675:     $ylabel = '' if (! defined($ylabel));
                   8676:     my %ValuesHash = 
                   8677:         (
1.369     www      8678:          $id.'.title'  => &escape($Title),
                   8679:          $id.'.xlabel' => &escape($xlabel),
                   8680:          $id.'.ylabel' => &escape($ylabel),
1.136     matthew  8681:          $id.'.labels' => join(',',@$Xlabels),
                   8682:          $id.'.PlotType' => 'XY',
                   8683:          $id.'.NumSets' => 2,
1.137     matthew  8684:          $id.'.two_axes' => 1,
                   8685:          $id.'.y1_max_value' => $Max1,
                   8686:          $id.'.y1_min_value' => $Min1,
                   8687:          $id.'.y2_max_value' => $Max2,
                   8688:          $id.'.y2_min_value' => $Min2,
1.136     matthew  8689:          );
                   8690:     #
1.137     matthew  8691:     if (defined($colors) && ref($colors) eq 'ARRAY') {
                   8692:         $ValuesHash{$id.'.Colors'}   = join(',',@{$colors});
                   8693:     }
                   8694:     #
                   8695:     if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
                   8696:         ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136     matthew  8697:         return '';
                   8698:     }
                   8699:     my $NumSets=1;
1.137     matthew  8700:     foreach my $array ($Ydata1,$Ydata2){
1.136     matthew  8701:         next if (! ref($array));
                   8702:         $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137     matthew  8703:     }
                   8704:     #
                   8705:     # Deal with other parameters
                   8706:     while (my ($key,$value) = each(%Values)) {
                   8707:         $ValuesHash{$id.'.'.$key} = $value;
1.136     matthew  8708:     }
                   8709:     #
1.646     raeburn  8710:     &Apache::lonnet::appenv(\%ValuesHash);
1.130     albertel 8711:     return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139     matthew  8712: }
                   8713: 
                   8714: ############################################################
                   8715: ############################################################
                   8716: 
                   8717: =pod
                   8718: 
1.157     matthew  8719: =back 
                   8720: 
1.139     matthew  8721: =head1 Statistics helper routines?  
                   8722: 
                   8723: Bad place for them but what the hell.
                   8724: 
1.157     matthew  8725: =over 4
                   8726: 
1.648     raeburn  8727: =item * &chartlink()
1.139     matthew  8728: 
                   8729: Returns a link to the chart for a specific student.  
                   8730: 
                   8731: Inputs:
                   8732: 
                   8733: =over 4
                   8734: 
                   8735: =item $linktext: The text of the link
                   8736: 
                   8737: =item $sname: The students username
                   8738: 
                   8739: =item $sdomain: The students domain
                   8740: 
                   8741: =back
                   8742: 
1.157     matthew  8743: =back
                   8744: 
1.139     matthew  8745: =cut
                   8746: 
                   8747: ############################################################
                   8748: ############################################################
                   8749: sub chartlink {
                   8750:     my ($linktext, $sname, $sdomain) = @_;
                   8751:     my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369     www      8752:         '&amp;SelectedStudent='.&escape($sname.':'.$sdomain).
1.219     albertel 8753:         '&amp;chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139     matthew  8754:        '">'.$linktext.'</a>';
1.153     matthew  8755: }
                   8756: 
                   8757: #######################################################
                   8758: #######################################################
                   8759: 
                   8760: =pod
                   8761: 
                   8762: =head1 Course Environment Routines
1.157     matthew  8763: 
                   8764: =over 4
1.153     matthew  8765: 
1.648     raeburn  8766: =item * &restore_course_settings()
1.153     matthew  8767: 
1.648     raeburn  8768: =item * &store_course_settings()
1.153     matthew  8769: 
                   8770: Restores/Store indicated form parameters from the course environment.
                   8771: Will not overwrite existing values of the form parameters.
                   8772: 
                   8773: Inputs: 
                   8774: a scalar describing the data (e.g. 'chart', 'problem_analysis')
                   8775: 
                   8776: a hash ref describing the data to be stored.  For example:
                   8777:    
                   8778: %Save_Parameters = ('Status' => 'scalar',
                   8779:     'chartoutputmode' => 'scalar',
                   8780:     'chartoutputdata' => 'scalar',
                   8781:     'Section' => 'array',
1.373     raeburn  8782:     'Group' => 'array',
1.153     matthew  8783:     'StudentData' => 'array',
                   8784:     'Maps' => 'array');
                   8785: 
                   8786: Returns: both routines return nothing
                   8787: 
1.631     raeburn  8788: =back
                   8789: 
1.153     matthew  8790: =cut
                   8791: 
                   8792: #######################################################
                   8793: #######################################################
                   8794: sub store_course_settings {
1.496     albertel 8795:     return &store_settings($env{'request.course.id'},@_);
                   8796: }
                   8797: 
                   8798: sub store_settings {
1.153     matthew  8799:     # save to the environment
                   8800:     # appenv the same items, just to be safe
1.300     albertel 8801:     my $udom  = $env{'user.domain'};
                   8802:     my $uname = $env{'user.name'};
1.496     albertel 8803:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  8804:     my %SaveHash;
                   8805:     my %AppHash;
                   8806:     while (my ($setting,$type) = each(%$Settings)) {
1.496     albertel 8807:         my $basename = join('.','internal',$context,$prefix,$setting);
1.300     albertel 8808:         my $envname = 'environment.'.$basename;
1.258     albertel 8809:         if (exists($env{'form.'.$setting})) {
1.153     matthew  8810:             # Save this value away
                   8811:             if ($type eq 'scalar' &&
1.258     albertel 8812:                 (! exists($env{$envname}) || 
                   8813:                  $env{$envname} ne $env{'form.'.$setting})) {
                   8814:                 $SaveHash{$basename} = $env{'form.'.$setting};
                   8815:                 $AppHash{$envname}   = $env{'form.'.$setting};
1.153     matthew  8816:             } elsif ($type eq 'array') {
                   8817:                 my $stored_form;
1.258     albertel 8818:                 if (ref($env{'form.'.$setting})) {
1.153     matthew  8819:                     $stored_form = join(',',
                   8820:                                         map {
1.369     www      8821:                                             &escape($_);
1.258     albertel 8822:                                         } sort(@{$env{'form.'.$setting}}));
1.153     matthew  8823:                 } else {
                   8824:                     $stored_form = 
1.369     www      8825:                         &escape($env{'form.'.$setting});
1.153     matthew  8826:                 }
                   8827:                 # Determine if the array contents are the same.
1.258     albertel 8828:                 if ($stored_form ne $env{$envname}) {
1.153     matthew  8829:                     $SaveHash{$basename} = $stored_form;
                   8830:                     $AppHash{$envname}   = $stored_form;
                   8831:                 }
                   8832:             }
                   8833:         }
                   8834:     }
                   8835:     my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300     albertel 8836:                                           $udom,$uname);
1.153     matthew  8837:     if ($put_result !~ /^(ok|delayed)/) {
                   8838:         &Apache::lonnet::logthis('unable to save form parameters, '.
                   8839:                                  'got error:'.$put_result);
                   8840:     }
                   8841:     # Make sure these settings stick around in this session, too
1.646     raeburn  8842:     &Apache::lonnet::appenv(\%AppHash);
1.153     matthew  8843:     return;
                   8844: }
                   8845: 
                   8846: sub restore_course_settings {
1.499     albertel 8847:     return &restore_settings($env{'request.course.id'},@_);
1.496     albertel 8848: }
                   8849: 
                   8850: sub restore_settings {
                   8851:     my ($context,$prefix,$Settings) = @_;
1.153     matthew  8852:     while (my ($setting,$type) = each(%$Settings)) {
1.258     albertel 8853:         next if (exists($env{'form.'.$setting}));
1.496     albertel 8854:         my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153     matthew  8855:             '.'.$setting;
1.258     albertel 8856:         if (exists($env{$envname})) {
1.153     matthew  8857:             if ($type eq 'scalar') {
1.258     albertel 8858:                 $env{'form.'.$setting} = $env{$envname};
1.153     matthew  8859:             } elsif ($type eq 'array') {
1.258     albertel 8860:                 $env{'form.'.$setting} = [ 
1.153     matthew  8861:                                            map { 
1.369     www      8862:                                                &unescape($_); 
1.258     albertel 8863:                                            } split(',',$env{$envname})
1.153     matthew  8864:                                            ];
                   8865:             }
                   8866:         }
                   8867:     }
1.127     matthew  8868: }
                   8869: 
1.618     raeburn  8870: #######################################################
                   8871: #######################################################
                   8872: 
                   8873: =pod
                   8874: 
                   8875: =head1 Domain E-mail Routines  
                   8876: 
                   8877: =over 4
                   8878: 
1.648     raeburn  8879: =item * &build_recipient_list()
1.618     raeburn  8880: 
1.766     raeburn  8881: Build recipient lists for four types of e-mail:
                   8882: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
                   8883: (d) Help requests, generated by
                   8884: lonerrorhandler.pm, CHECKRPMS, loncron, and lonsupportreq.pm respectively.
1.618     raeburn  8885: 
                   8886: Inputs:
1.619     raeburn  8887: defmail (scalar - email address of default recipient), 
1.618     raeburn  8888: mailing type (scalar - errormail, packagesmail, or helpdeskmail), 
1.619     raeburn  8889: defdom (domain for which to retrieve configuration settings),
                   8890: origmail (scalar - email address of recipient from loncapa.conf, 
                   8891: i.e., predates configuration by DC via domainprefs.pm 
1.618     raeburn  8892: 
1.655     raeburn  8893: Returns: comma separated list of addresses to which to send e-mail.
                   8894: 
                   8895: =back
1.618     raeburn  8896: 
                   8897: =cut
                   8898: 
                   8899: ############################################################
                   8900: ############################################################
                   8901: sub build_recipient_list {
1.619     raeburn  8902:     my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618     raeburn  8903:     my @recipients;
                   8904:     my $otheremails;
                   8905:     my %domconfig =
                   8906:          &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
                   8907:     if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766     raeburn  8908:         if (exists($domconfig{'contacts'}{$mailing})) {
                   8909:             if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
                   8910:                 my @contacts = ('adminemail','supportemail');
                   8911:                 foreach my $item (@contacts) {
                   8912:                     if ($domconfig{'contacts'}{$mailing}{$item}) {
                   8913:                         my $addr = $domconfig{'contacts'}{$item}; 
                   8914:                         if (!grep(/^\Q$addr\E$/,@recipients)) {
                   8915:                             push(@recipients,$addr);
                   8916:                         }
1.619     raeburn  8917:                     }
1.766     raeburn  8918:                     $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618     raeburn  8919:                 }
                   8920:             }
1.766     raeburn  8921:         } elsif ($origmail ne '') {
                   8922:             push(@recipients,$origmail);
1.618     raeburn  8923:         }
1.619     raeburn  8924:     } elsif ($origmail ne '') {
                   8925:         push(@recipients,$origmail);
1.618     raeburn  8926:     }
1.688     raeburn  8927:     if (defined($defmail)) {
                   8928:         if ($defmail ne '') {
                   8929:             push(@recipients,$defmail);
                   8930:         }
1.618     raeburn  8931:     }
                   8932:     if ($otheremails) {
1.619     raeburn  8933:         my @others;
                   8934:         if ($otheremails =~ /,/) {
                   8935:             @others = split(/,/,$otheremails);
1.618     raeburn  8936:         } else {
1.619     raeburn  8937:             push(@others,$otheremails);
                   8938:         }
                   8939:         foreach my $addr (@others) {
                   8940:             if (!grep(/^\Q$addr\E$/,@recipients)) {
                   8941:                 push(@recipients,$addr);
                   8942:             }
1.618     raeburn  8943:         }
                   8944:     }
1.619     raeburn  8945:     my $recipientlist = join(',',@recipients); 
1.618     raeburn  8946:     return $recipientlist;
                   8947: }
                   8948: 
1.127     matthew  8949: ############################################################
                   8950: ############################################################
1.154     albertel 8951: 
1.655     raeburn  8952: =pod
                   8953: 
                   8954: =head1 Course Catalog Routines
                   8955: 
                   8956: =over 4
                   8957: 
                   8958: =item * &gather_categories()
                   8959: 
                   8960: Converts category definitions - keys of categories hash stored in  
                   8961: coursecategories in configuration.db on the primary library server in a 
                   8962: domain - to an array.  Also generates javascript and idx hash used to 
                   8963: generate Domain Coordinator interface for editing Course Categories.
                   8964: 
                   8965: Inputs:
1.663     raeburn  8966: 
1.655     raeburn  8967: categories (reference to hash of category definitions).
1.663     raeburn  8968: 
1.655     raeburn  8969: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   8970:       categories and subcategories).
1.663     raeburn  8971: 
1.655     raeburn  8972: idx (reference to hash of counters used in Domain Coordinator interface for 
                   8973:       editing Course Categories).
1.663     raeburn  8974: 
1.655     raeburn  8975: jsarray (reference to array of categories used to create Javascript arrays for
                   8976:          Domain Coordinator interface for editing Course Categories).
                   8977: 
                   8978: Returns: nothing
                   8979: 
                   8980: Side effects: populates cats, idx and jsarray. 
                   8981: 
                   8982: =cut
                   8983: 
                   8984: sub gather_categories {
                   8985:     my ($categories,$cats,$idx,$jsarray) = @_;
                   8986:     my %counters;
                   8987:     my $num = 0;
                   8988:     foreach my $item (keys(%{$categories})) {
                   8989:         my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
                   8990:         if ($container eq '' && $depth == 0) {
                   8991:             $cats->[$depth][$categories->{$item}] = $cat;
                   8992:         } else {
                   8993:             $cats->[$depth]{$container}[$categories->{$item}] = $cat;
                   8994:         }
                   8995:         my ($escitem,$tail) = split(/:/,$item,2);
                   8996:         if ($counters{$tail} eq '') {
                   8997:             $counters{$tail} = $num;
                   8998:             $num ++;
                   8999:         }
                   9000:         if (ref($idx) eq 'HASH') {
                   9001:             $idx->{$item} = $counters{$tail};
                   9002:         }
                   9003:         if (ref($jsarray) eq 'ARRAY') {
                   9004:             push(@{$jsarray->[$counters{$tail}]},$item);
                   9005:         }
                   9006:     }
                   9007:     return;
                   9008: }
                   9009: 
                   9010: =pod
                   9011: 
                   9012: =item * &extract_categories()
                   9013: 
                   9014: Used to generate breadcrumb trails for course categories.
                   9015: 
                   9016: Inputs:
1.663     raeburn  9017: 
1.655     raeburn  9018: categories (reference to hash of category definitions).
1.663     raeburn  9019: 
1.655     raeburn  9020: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9021:       categories and subcategories).
1.663     raeburn  9022: 
1.655     raeburn  9023: trails (reference to array of breacrumb trails for each category).
1.663     raeburn  9024: 
1.655     raeburn  9025: allitems (reference to hash - key is category key 
                   9026:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  9027: 
1.655     raeburn  9028: idx (reference to hash of counters used in Domain Coordinator interface for
                   9029:       editing Course Categories).
1.663     raeburn  9030: 
1.655     raeburn  9031: jsarray (reference to array of categories used to create Javascript arrays for
                   9032:          Domain Coordinator interface for editing Course Categories).
                   9033: 
1.665     raeburn  9034: subcats (reference to hash of arrays containing all subcategories within each 
                   9035:          category, -recursive)
                   9036: 
1.655     raeburn  9037: Returns: nothing
                   9038: 
                   9039: Side effects: populates trails and allitems hash references.
                   9040: 
                   9041: =cut
                   9042: 
                   9043: sub extract_categories {
1.665     raeburn  9044:     my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655     raeburn  9045:     if (ref($categories) eq 'HASH') {
                   9046:         &gather_categories($categories,$cats,$idx,$jsarray);
                   9047:         if (ref($cats->[0]) eq 'ARRAY') {
                   9048:             for (my $i=0; $i<@{$cats->[0]}; $i++) {
                   9049:                 my $name = $cats->[0][$i];
                   9050:                 my $item = &escape($name).'::0';
                   9051:                 my $trailstr;
                   9052:                 if ($name eq 'instcode') {
                   9053:                     $trailstr = &mt('Official courses (with institutional codes)');
                   9054:                 } else {
                   9055:                     $trailstr = $name;
                   9056:                 }
                   9057:                 if ($allitems->{$item} eq '') {
                   9058:                     push(@{$trails},$trailstr);
                   9059:                     $allitems->{$item} = scalar(@{$trails})-1;
                   9060:                 }
                   9061:                 my @parents = ($name);
                   9062:                 if (ref($cats->[1]{$name}) eq 'ARRAY') {
                   9063:                     for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
                   9064:                         my $category = $cats->[1]{$name}[$j];
1.665     raeburn  9065:                         if (ref($subcats) eq 'HASH') {
                   9066:                             push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
                   9067:                         }
                   9068:                         &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
                   9069:                     }
                   9070:                 } else {
                   9071:                     if (ref($subcats) eq 'HASH') {
                   9072:                         $subcats->{$item} = [];
1.655     raeburn  9073:                     }
                   9074:                 }
                   9075:             }
                   9076:         }
                   9077:     }
                   9078:     return;
                   9079: }
                   9080: 
                   9081: =pod
                   9082: 
                   9083: =item *&recurse_categories()
                   9084: 
                   9085: Recursively used to generate breadcrumb trails for course categories.
                   9086: 
                   9087: Inputs:
1.663     raeburn  9088: 
1.655     raeburn  9089: cats (reference to array of arrays/hashes which encapsulates hierarchy of
                   9090:       categories and subcategories).
1.663     raeburn  9091: 
1.655     raeburn  9092: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663     raeburn  9093: 
                   9094: category (current course category, for which breadcrumb trail is being generated).
                   9095: 
                   9096: trails (reference to array of breadcrumb trails for each category).
                   9097: 
1.655     raeburn  9098: allitems (reference to hash - key is category key
                   9099:          (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663     raeburn  9100: 
1.655     raeburn  9101: parents (array containing containers directories for current category, 
                   9102:          back to top level). 
                   9103: 
                   9104: Returns: nothing
                   9105: 
                   9106: Side effects: populates trails and allitems hash references
                   9107: 
                   9108: =cut
                   9109: 
                   9110: sub recurse_categories {
1.665     raeburn  9111:     my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655     raeburn  9112:     my $shallower = $depth - 1;
                   9113:     if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
                   9114:         for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
                   9115:             my $name = $cats->[$depth]{$category}[$k];
                   9116:             my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   9117:             my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   9118:             if ($allitems->{$item} eq '') {
                   9119:                 push(@{$trails},$trailstr);
                   9120:                 $allitems->{$item} = scalar(@{$trails})-1;
                   9121:             }
                   9122:             my $deeper = $depth+1;
                   9123:             push(@{$parents},$category);
1.665     raeburn  9124:             if (ref($subcats) eq 'HASH') {
                   9125:                 my $subcat = &escape($name).':'.$category.':'.$depth;
                   9126:                 for (my $j=@{$parents}; $j>=0; $j--) {
                   9127:                     my $higher;
                   9128:                     if ($j > 0) {
                   9129:                         $higher = &escape($parents->[$j]).':'.
                   9130:                                   &escape($parents->[$j-1]).':'.$j;
                   9131:                     } else {
                   9132:                         $higher = &escape($parents->[$j]).'::'.$j;
                   9133:                     }
                   9134:                     push(@{$subcats->{$higher}},$subcat);
                   9135:                 }
                   9136:             }
                   9137:             &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
                   9138:                                 $subcats);
1.655     raeburn  9139:             pop(@{$parents});
                   9140:         }
                   9141:     } else {
                   9142:         my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
                   9143:         my $trailstr = join(' -&gt; ',(@{$parents},$category));
                   9144:         if ($allitems->{$item} eq '') {
                   9145:             push(@{$trails},$trailstr);
                   9146:             $allitems->{$item} = scalar(@{$trails})-1;
                   9147:         }
                   9148:     }
                   9149:     return;
                   9150: }
                   9151: 
1.663     raeburn  9152: =pod
                   9153: 
                   9154: =item *&assign_categories_table()
                   9155: 
                   9156: Create a datatable for display of hierarchical categories in a domain,
                   9157: with checkboxes to allow a course to be categorized. 
                   9158: 
                   9159: Inputs:
                   9160: 
                   9161: cathash - reference to hash of categories defined for the domain (from
                   9162:           configuration.db)
                   9163: 
                   9164: currcat - scalar with an & separated list of categories assigned to a course. 
                   9165: 
                   9166: Returns: $output (markup to be displayed) 
                   9167: 
                   9168: =cut
                   9169: 
                   9170: sub assign_categories_table {
                   9171:     my ($cathash,$currcat) = @_;
                   9172:     my $output;
                   9173:     if (ref($cathash) eq 'HASH') {
                   9174:         my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
                   9175:         &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
                   9176:         $maxdepth = scalar(@cats);
                   9177:         if (@cats > 0) {
                   9178:             my $itemcount = 0;
                   9179:             if (ref($cats[0]) eq 'ARRAY') {
                   9180:                 $output = &Apache::loncommon::start_data_table();
                   9181:                 my @currcategories;
                   9182:                 if ($currcat ne '') {
                   9183:                     @currcategories = split('&',$currcat);
                   9184:                 }
                   9185:                 for (my $i=0; $i<@{$cats[0]}; $i++) {
                   9186:                     my $parent = $cats[0][$i];
                   9187:                     my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9188:                     next if ($parent eq 'instcode');
                   9189:                     my $item = &escape($parent).'::0';
                   9190:                     my $checked = '';
                   9191:                     if (@currcategories > 0) {
                   9192:                         if (grep(/^\Q$item\E$/,@currcategories)) {
                   9193:                             $checked = ' checked="checked" ';
                   9194:                         }
                   9195:                     }
1.675     raeburn  9196:                     $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
                   9197:                                '<input type="checkbox" name="usecategory" value="'.
                   9198:                                $item.'"'.$checked.' />'.$parent.'</span>'.
                   9199:                                '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663     raeburn  9200:                     my $depth = 1;
                   9201:                     push(@path,$parent);
                   9202:                     $output .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
                   9203:                     pop(@path);
                   9204:                     $output .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
                   9205:                     $itemcount ++;
                   9206:                 }
                   9207:                 $output .= &Apache::loncommon::end_data_table();
                   9208:             }
                   9209:         }
                   9210:     }
                   9211:     return $output;
                   9212: }
                   9213: 
                   9214: =pod
                   9215: 
                   9216: =item *&assign_category_rows()
                   9217: 
                   9218: Create a datatable row for display of nested categories in a domain,
                   9219: with checkboxes to allow a course to be categorized,called recursively.
                   9220: 
                   9221: Inputs:
                   9222: 
                   9223: itemcount - track row number for alternating colors
                   9224: 
                   9225: cats - reference to array of arrays/hashes which encapsulates hierarchy of
                   9226:       categories and subcategories.
                   9227: 
                   9228: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
                   9229: 
                   9230: parent - parent of current category item
                   9231: 
                   9232: path - Array containing all categories back up through the hierarchy from the
                   9233:        current category to the top level.
                   9234: 
                   9235: currcategories - reference to array of current categories assigned to the course
                   9236: 
                   9237: Returns: $output (markup to be displayed).
                   9238: 
                   9239: =cut
                   9240: 
                   9241: sub assign_category_rows {
                   9242:     my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
                   9243:     my ($text,$name,$item,$chgstr);
                   9244:     if (ref($cats) eq 'ARRAY') {
                   9245:         my $maxdepth = scalar(@{$cats});
                   9246:         if (ref($cats->[$depth]) eq 'HASH') {
                   9247:             if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
                   9248:                 my $numchildren = @{$cats->[$depth]{$parent}};
                   9249:                 my $css_class = $itemcount%2?' class="LC_odd_row"':'';
                   9250:                 $text .= '<td><table class="LC_datatable">';
                   9251:                 for (my $j=0; $j<$numchildren; $j++) {
                   9252:                     $name = $cats->[$depth]{$parent}[$j];
                   9253:                     $item = &escape($name).':'.&escape($parent).':'.$depth;
                   9254:                     my $deeper = $depth+1;
                   9255:                     my $checked = '';
                   9256:                     if (ref($currcategories) eq 'ARRAY') {
                   9257:                         if (@{$currcategories} > 0) {
                   9258:                             if (grep(/^\Q$item\E$/,@{$currcategories})) {
                   9259:                                 $checked = ' checked="checked" ';
                   9260:                             }
                   9261:                         }
                   9262:                     }
1.664     raeburn  9263:                     $text .= '<tr><td><span class="LC_nobreak"><label>'.
                   9264:                              '<input type="checkbox" name="usecategory" value="'.
1.675     raeburn  9265:                              $item.'"'.$checked.' />'.$name.'</label></span>'.
                   9266:                              '<input type="hidden" name="catname" value="'.$name.'" />'.
                   9267:                              '</td><td>';
1.663     raeburn  9268:                     if (ref($path) eq 'ARRAY') {
                   9269:                         push(@{$path},$name);
                   9270:                         $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
                   9271:                         pop(@{$path});
                   9272:                     }
                   9273:                     $text .= '</td></tr>';
                   9274:                 }
                   9275:                 $text .= '</table></td>';
                   9276:             }
                   9277:         }
                   9278:     }
                   9279:     return $text;
                   9280: }
                   9281: 
1.655     raeburn  9282: ############################################################
                   9283: ############################################################
                   9284: 
                   9285: 
1.443     albertel 9286: sub commit_customrole {
1.664     raeburn  9287:     my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630     raeburn  9288:     my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443     albertel 9289:                          ($start?', '.&mt('starting').' '.localtime($start):'').
                   9290:                          ($end?', ending '.localtime($end):'').': <b>'.
                   9291:               &Apache::lonnet::assigncustomrole(
1.664     raeburn  9292:                  $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443     albertel 9293:                  '</b><br />';
                   9294:     return $output;
                   9295: }
                   9296: 
                   9297: sub commit_standardrole {
1.541     raeburn  9298:     my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
                   9299:     my ($output,$logmsg,$linefeed);
                   9300:     if ($context eq 'auto') {
                   9301:         $linefeed = "\n";
                   9302:     } else {
                   9303:         $linefeed = "<br />\n";
                   9304:     }  
1.443     albertel 9305:     if ($three eq 'st') {
1.541     raeburn  9306:         my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
                   9307:                                          $one,$two,$sec,$context);
                   9308:         if (($result =~ /^error/) || ($result eq 'not_in_class') || 
1.626     raeburn  9309:             ($result eq 'unknown_course') || ($result eq 'refused')) {
                   9310:             $output = $logmsg.' '.&mt('Error: ').$result."\n"; 
1.443     albertel 9311:         } else {
1.541     raeburn  9312:             $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443     albertel 9313:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  9314:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
                   9315:             if ($context eq 'auto') {
                   9316:                 $output .= $result.$linefeed.&mt('Add to classlist').': ok';
                   9317:             } else {
                   9318:                $output .= '<b>'.$result.'</b>'.$linefeed.
                   9319:                &mt('Add to classlist').': <b>ok</b>';
                   9320:             }
                   9321:             $output .= $linefeed;
1.443     albertel 9322:         }
                   9323:     } else {
                   9324:         $output = &mt('Assigning').' '.$three.' in '.$url.
                   9325:                ($start?', '.&mt('starting').' '.localtime($start):'').
1.541     raeburn  9326:                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652     raeburn  9327:         my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541     raeburn  9328:         if ($context eq 'auto') {
                   9329:             $output .= $result.$linefeed;
                   9330:         } else {
                   9331:             $output .= '<b>'.$result.'</b>'.$linefeed;
                   9332:         }
1.443     albertel 9333:     }
                   9334:     return $output;
                   9335: }
                   9336: 
                   9337: sub commit_studentrole {
1.541     raeburn  9338:     my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context) = @_;
1.626     raeburn  9339:     my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541     raeburn  9340:     if ($context eq 'auto') {
                   9341:         $linefeed = "\n";
                   9342:     } else {
                   9343:         $linefeed = '<br />'."\n";
                   9344:     }
1.443     albertel 9345:     if (defined($one) && defined($two)) {
                   9346:         my $cid=$one.'_'.$two;
                   9347:         my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
                   9348:         my $secchange = 0;
                   9349:         my $expire_role_result;
                   9350:         my $modify_section_result;
1.628     raeburn  9351:         if ($oldsec ne '-1') { 
                   9352:             if ($oldsec ne $sec) {
1.443     albertel 9353:                 $secchange = 1;
1.628     raeburn  9354:                 my $now = time;
1.443     albertel 9355:                 my $uurl='/'.$cid;
                   9356:                 $uurl=~s/\_/\//g;
                   9357:                 if ($oldsec) {
                   9358:                     $uurl.='/'.$oldsec;
                   9359:                 }
1.626     raeburn  9360:                 $oldsecurl = $uurl;
1.628     raeburn  9361:                 $expire_role_result = 
1.652     raeburn  9362:                     &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628     raeburn  9363:                 if ($env{'request.course.sec'} ne '') { 
                   9364:                     if ($expire_role_result eq 'refused') {
                   9365:                         my @roles = ('st');
                   9366:                         my @statuses = ('previous');
                   9367:                         my @roledoms = ($one);
                   9368:                         my $withsec = 1;
                   9369:                         my %roleshash = 
                   9370:                             &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
                   9371:                                               \@statuses,\@roles,\@roledoms,$withsec);
                   9372:                         if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
                   9373:                             my ($oldstart,$oldend) = 
                   9374:                                 split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
                   9375:                             if ($oldend > 0 && $oldend <= $now) {
                   9376:                                 $expire_role_result = 'ok';
                   9377:                             }
                   9378:                         }
                   9379:                     }
                   9380:                 }
1.443     albertel 9381:                 $result = $expire_role_result;
                   9382:             }
                   9383:         }
                   9384:         if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.652     raeburn  9385:             $modify_section_result = &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,undef,undef,undef,$sec,$end,$start,'','',$cid,'',$context);
1.443     albertel 9386:             if ($modify_section_result =~ /^ok/) {
                   9387:                 if ($secchange == 1) {
1.628     raeburn  9388:                     if ($sec eq '') {
                   9389:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
                   9390:                     } else {
                   9391:                         $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
                   9392:                     }
1.443     albertel 9393:                 } elsif ($oldsec eq '-1') {
1.628     raeburn  9394:                     if ($sec eq '') {
                   9395:                         $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
                   9396:                     } else {
                   9397:                         $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   9398:                     }
1.443     albertel 9399:                 } else {
1.628     raeburn  9400:                     if ($sec eq '') {
                   9401:                         $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
                   9402:                     } else {
                   9403:                         $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
                   9404:                     }
1.443     albertel 9405:                 }
                   9406:             } else {
1.628     raeburn  9407:                 if ($secchange) {       
                   9408:                     $$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;
                   9409:                 } else {
                   9410:                     $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
                   9411:                 }
1.443     albertel 9412:             }
                   9413:             $result = $modify_section_result;
                   9414:         } elsif ($secchange == 1) {
1.628     raeburn  9415:             if ($oldsec eq '') {
                   9416:                 $$logmsg .= &mt('Error when attempting to expire existing role without a section for [_1] in course [_3] -error: ',$uname,$cid).' '.$expire_role_result.$linefeed;
                   9417:             } else {
                   9418:                 $$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;
                   9419:             }
1.626     raeburn  9420:             if ($expire_role_result eq 'refused') {
                   9421:                 my $newsecurl = '/'.$cid;
                   9422:                 $newsecurl =~ s/\_/\//g;
                   9423:                 if ($sec ne '') {
                   9424:                     $newsecurl.='/'.$sec;
                   9425:                 }
                   9426:                 if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
                   9427:                     if ($sec eq '') {
                   9428:                         $$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;
                   9429:                     } else {
                   9430:                         $$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;
                   9431:                     }
                   9432:                 }
                   9433:             }
1.443     albertel 9434:         }
                   9435:     } else {
1.626     raeburn  9436:         $$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 9437:         $result = "error: incomplete course id\n";
                   9438:     }
                   9439:     return $result;
                   9440: }
                   9441: 
                   9442: ############################################################
                   9443: ############################################################
                   9444: 
1.566     albertel 9445: sub check_clone {
1.578     raeburn  9446:     my ($args,$linefeed) = @_;
1.566     albertel 9447:     my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
                   9448:     my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
                   9449:     my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
                   9450:     my $clonemsg;
                   9451:     my $can_clone = 0;
                   9452: 
                   9453:     if ($clonehome eq 'no_host') {
1.578     raeburn  9454:         $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 9455:     } else {
                   9456: 	my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.568     albertel 9457: 	if ($env{'request.role.domain'} eq $args->{'clonedomain'}) {
1.566     albertel 9458: 	    $can_clone = 1;
                   9459: 	} else {
                   9460: 	    my %clonehash = &Apache::lonnet::get('environment',['cloners'],
                   9461: 						 $args->{'clonedomain'},$args->{'clonecourse'});
                   9462: 	    my @cloners = split(/,/,$clonehash{'cloners'});
1.578     raeburn  9463:             if (grep(/^\*$/,@cloners)) {
                   9464:                 $can_clone = 1;
                   9465:             } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
                   9466:                 $can_clone = 1;
                   9467:             } else {
                   9468: 	        my %roleshash =
                   9469: 		    &Apache::lonnet::get_my_roles($args->{'ccuname'},
                   9470: 					 $args->{'ccdomain'},
                   9471:                                          'userroles',['active'],['cc'],
                   9472: 					 [$args->{'clonedomain'}]);
                   9473: 	        if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':cc'}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
                   9474: 		    $can_clone = 1;
                   9475: 	        } else {
                   9476:                     $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'});
                   9477: 	        }
1.566     albertel 9478: 	    }
1.578     raeburn  9479:         }
1.566     albertel 9480:     }
                   9481:     return ($can_clone, $clonemsg, $cloneid, $clonehome);
                   9482: }
                   9483: 
1.444     albertel 9484: sub construct_course {
1.541     raeburn  9485:     my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context) = @_;
1.444     albertel 9486:     my $outcome;
1.541     raeburn  9487:     my $linefeed =  '<br />'."\n";
                   9488:     if ($context eq 'auto') {
                   9489:         $linefeed = "\n";
                   9490:     }
1.566     albertel 9491: 
                   9492: #
                   9493: # Are we cloning?
                   9494: #
                   9495:     my ($can_clone, $clonemsg, $cloneid, $clonehome);
                   9496:     if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578     raeburn  9497: 	($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566     albertel 9498: 	if ($context ne 'auto') {
1.578     raeburn  9499:             if ($clonemsg ne '') {
                   9500: 	        $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
                   9501:             }
1.566     albertel 9502: 	}
                   9503: 	$outcome .= $clonemsg.$linefeed;
                   9504: 
                   9505:         if (!$can_clone) {
                   9506: 	    return (0,$outcome);
                   9507: 	}
                   9508:     }
                   9509: 
1.444     albertel 9510: #
                   9511: # Open course
                   9512: #
                   9513:     my $crstype = lc($args->{'crstype'});
                   9514:     my %cenv=();
                   9515:     $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
                   9516:                                              $args->{'cdescr'},
                   9517:                                              $args->{'curl'},
                   9518:                                              $args->{'course_home'},
                   9519:                                              $args->{'nonstandard'},
                   9520:                                              $args->{'crscode'},
                   9521:                                              $args->{'ccuname'}.':'.
                   9522:                                              $args->{'ccdomain'},
                   9523:                                              $args->{'crstype'});
                   9524: 
                   9525:     # Note: The testing routines depend on this being output; see 
                   9526:     # Utils::Course. This needs to at least be output as a comment
                   9527:     # if anyone ever decides to not show this, and Utils::Course::new
                   9528:     # will need to be suitably modified.
1.541     raeburn  9529:     $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.444     albertel 9530: #
                   9531: # Check if created correctly
                   9532: #
1.479     albertel 9533:     ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444     albertel 9534:     my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.541     raeburn  9535:     $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566     albertel 9536: 
1.444     albertel 9537: #
1.566     albertel 9538: # Do the cloning
                   9539: #   
                   9540:     if ($can_clone && $cloneid) {
                   9541: 	$clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
                   9542: 	if ($context ne 'auto') {
                   9543: 	    $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
                   9544: 	}
                   9545: 	$outcome .= $clonemsg.$linefeed;
                   9546: 	my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444     albertel 9547: # Copy all files
1.637     www      9548: 	&Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444     albertel 9549: # Restore URL
1.566     albertel 9550: 	$cenv{'url'}=$oldcenv{'url'};
1.444     albertel 9551: # Restore title
1.566     albertel 9552: 	$cenv{'description'}=$oldcenv{'description'};
1.444     albertel 9553: # Mark as cloned
1.566     albertel 9554: 	$cenv{'clonedfrom'}=$cloneid;
1.638     www      9555: # Need to clone grading mode
                   9556:         my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
                   9557:         $cenv{'grading'}=$newenv{'grading'};
                   9558: # Do not clone these environment entries
                   9559:         &Apache::lonnet::del('environment',
                   9560:                   ['default_enrollment_start_date',
                   9561:                    'default_enrollment_end_date',
                   9562:                    'question.email',
                   9563:                    'policy.email',
                   9564:                    'comment.email',
                   9565:                    'pch.users.denied',
1.725     raeburn  9566:                    'plc.users.denied',
                   9567:                    'hidefromcat',
                   9568:                    'categories'],
1.638     www      9569:                    $$crsudom,$$crsunum);
1.444     albertel 9570:     }
1.566     albertel 9571: 
1.444     albertel 9572: #
                   9573: # Set environment (will override cloned, if existing)
                   9574: #
                   9575:     my @sections = ();
                   9576:     my @xlists = ();
                   9577:     if ($args->{'crstype'}) {
                   9578:         $cenv{'type'}=$args->{'crstype'};
                   9579:     }
                   9580:     if ($args->{'crsid'}) {
                   9581:         $cenv{'courseid'}=$args->{'crsid'};
                   9582:     }
                   9583:     if ($args->{'crscode'}) {
                   9584:         $cenv{'internal.coursecode'}=$args->{'crscode'};
                   9585:     }
                   9586:     if ($args->{'crsquota'} ne '') {
                   9587:         $cenv{'internal.coursequota'}=$args->{'crsquota'};
                   9588:     } else {
                   9589:         $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
                   9590:     }
                   9591:     if ($args->{'ccuname'}) {
                   9592:         $cenv{'internal.courseowner'} = $args->{'ccuname'}.
                   9593:                                         ':'.$args->{'ccdomain'};
                   9594:     } else {
                   9595:         $cenv{'internal.courseowner'} = $args->{'curruser'};
                   9596:     }
                   9597:     my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
                   9598:     if ($args->{'crssections'}) {
                   9599:         $cenv{'internal.sectionnums'} = '';
                   9600:         if ($args->{'crssections'} =~ m/,/) {
                   9601:             @sections = split/,/,$args->{'crssections'};
                   9602:         } else {
                   9603:             $sections[0] = $args->{'crssections'};
                   9604:         }
                   9605:         if (@sections > 0) {
                   9606:             foreach my $item (@sections) {
                   9607:                 my ($sec,$gp) = split/:/,$item;
                   9608:                 my $class = $args->{'crscode'}.$sec;
                   9609:                 my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
                   9610:                 $cenv{'internal.sectionnums'} .= $item.',';
                   9611:                 unless ($addcheck eq 'ok') {
                   9612:                     push @badclasses, $class;
                   9613:                 }
                   9614:             }
                   9615:             $cenv{'internal.sectionnums'} =~ s/,$//;
                   9616:         }
                   9617:     }
                   9618: # do not hide course coordinator from staff listing, 
                   9619: # even if privileged
                   9620:     $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   9621: # add crosslistings
                   9622:     if ($args->{'crsxlist'}) {
                   9623:         $cenv{'internal.crosslistings'}='';
                   9624:         if ($args->{'crsxlist'} =~ m/,/) {
                   9625:             @xlists = split/,/,$args->{'crsxlist'};
                   9626:         } else {
                   9627:             $xlists[0] = $args->{'crsxlist'};
                   9628:         }
                   9629:         if (@xlists > 0) {
                   9630:             foreach my $item (@xlists) {
                   9631:                 my ($xl,$gp) = split/:/,$item;
                   9632:                 my $addcheck =  &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
                   9633:                 $cenv{'internal.crosslistings'} .= $item.',';
                   9634:                 unless ($addcheck eq 'ok') {
                   9635:                     push @badclasses, $xl;
                   9636:                 }
                   9637:             }
                   9638:             $cenv{'internal.crosslistings'} =~ s/,$//;
                   9639:         }
                   9640:     }
                   9641:     if ($args->{'autoadds'}) {
                   9642:         $cenv{'internal.autoadds'}=$args->{'autoadds'};
                   9643:     }
                   9644:     if ($args->{'autodrops'}) {
                   9645:         $cenv{'internal.autodrops'}=$args->{'autodrops'};
                   9646:     }
                   9647: # check for notification of enrollment changes
                   9648:     my @notified = ();
                   9649:     if ($args->{'notify_owner'}) {
                   9650:         if ($args->{'ccuname'} ne '') {
                   9651:             push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
                   9652:         }
                   9653:     }
                   9654:     if ($args->{'notify_dc'}) {
                   9655:         if ($uname ne '') { 
1.630     raeburn  9656:             push(@notified,$uname.':'.$udom);
1.444     albertel 9657:         }
                   9658:     }
                   9659:     if (@notified > 0) {
                   9660:         my $notifylist;
                   9661:         if (@notified > 1) {
                   9662:             $notifylist = join(',',@notified);
                   9663:         } else {
                   9664:             $notifylist = $notified[0];
                   9665:         }
                   9666:         $cenv{'internal.notifylist'} = $notifylist;
                   9667:     }
                   9668:     if (@badclasses > 0) {
                   9669:         my %lt=&Apache::lonlocal::texthash(
                   9670:                 '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',
                   9671:                 'dnhr' => 'does not have rights to access enrollment in these classes',
                   9672:                 'adby' => 'as determined by the policies of your institution on access to official classlists'
                   9673:         );
1.541     raeburn  9674:         my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
                   9675:                            ' ('.$lt{'adby'}.')';
                   9676:         if ($context eq 'auto') {
                   9677:             $outcome .= $badclass_msg.$linefeed;
1.566     albertel 9678:             $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541     raeburn  9679:             foreach my $item (@badclasses) {
                   9680:                 if ($context eq 'auto') {
                   9681:                     $outcome .= " - $item\n";
                   9682:                 } else {
                   9683:                     $outcome .= "<li>$item</li>\n";
                   9684:                 }
                   9685:             }
                   9686:             if ($context eq 'auto') {
                   9687:                 $outcome .= $linefeed;
                   9688:             } else {
1.566     albertel 9689:                 $outcome .= "</ul><br /><br /></div>\n";
1.541     raeburn  9690:             }
                   9691:         } 
1.444     albertel 9692:     }
                   9693:     if ($args->{'no_end_date'}) {
                   9694:         $args->{'endaccess'} = 0;
                   9695:     }
                   9696:     $cenv{'internal.autostart'}=$args->{'enrollstart'};
                   9697:     $cenv{'internal.autoend'}=$args->{'enrollend'};
                   9698:     $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
                   9699:     $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
                   9700:     if ($args->{'showphotos'}) {
                   9701:       $cenv{'internal.showphotos'}=$args->{'showphotos'};
                   9702:     }
                   9703:     $cenv{'internal.authtype'} = $args->{'authtype'};
                   9704:     $cenv{'internal.autharg'} = $args->{'autharg'}; 
                   9705:     if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
                   9706:         if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'}  eq '') {
1.541     raeburn  9707:             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'); 
                   9708:             if ($context eq 'auto') {
                   9709:                 $outcome .= $krb_msg;
                   9710:             } else {
1.566     albertel 9711:                 $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541     raeburn  9712:             }
                   9713:             $outcome .= $linefeed;
1.444     albertel 9714:         }
                   9715:     }
                   9716:     if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
                   9717:        if ($args->{'setpolicy'}) {
                   9718:            $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   9719:        }
                   9720:        if ($args->{'setcontent'}) {
                   9721:            $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
                   9722:        }
                   9723:     }
                   9724:     if ($args->{'reshome'}) {
                   9725: 	$cenv{'reshome'}=$args->{'reshome'}.'/';
                   9726: 	$cenv{'reshome'}=~s/\/+$/\//;
                   9727:     }
                   9728: #
                   9729: # course has keyed access
                   9730: #
                   9731:     if ($args->{'setkeys'}) {
                   9732:        $cenv{'keyaccess'}='yes';
                   9733:     }
                   9734: # if specified, key authority is not course, but user
                   9735: # only active if keyaccess is yes
                   9736:     if ($args->{'keyauth'}) {
1.487     albertel 9737: 	my ($user,$domain) = split(':',$args->{'keyauth'});
                   9738: 	$user = &LONCAPA::clean_username($user);
                   9739: 	$domain = &LONCAPA::clean_username($domain);
1.488     foxr     9740: 	if ($user ne '' && $domain ne '') {
1.487     albertel 9741: 	    $cenv{'keyauth'}=$user.':'.$domain;
1.444     albertel 9742: 	}
                   9743:     }
                   9744: 
                   9745:     if ($args->{'disresdis'}) {
                   9746:         $cenv{'pch.roles.denied'}='st';
                   9747:     }
                   9748:     if ($args->{'disablechat'}) {
                   9749:         $cenv{'plc.roles.denied'}='st';
                   9750:     }
                   9751: 
                   9752:     # Record we've not yet viewed the Course Initialization Helper for this 
                   9753:     # course
                   9754:     $cenv{'course.helper.not.run'} = 1;
                   9755:     #
                   9756:     # Use new Randomseed
                   9757:     #
                   9758:     $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
                   9759:     $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
                   9760:     #
                   9761:     # The encryption code and receipt prefix for this course
                   9762:     #
                   9763:     $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
                   9764:     $cenv{'internal.encpref'}=100+int(9*rand(99));
                   9765:     #
                   9766:     # By default, use standard grading
                   9767:     if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
                   9768: 
1.541     raeburn  9769:     $outcome .= $linefeed.&mt('Setting environment').': '.                 
                   9770:           &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 9771: #
                   9772: # Open all assignments
                   9773: #
                   9774:     if ($args->{'openall'}) {
                   9775:        my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
                   9776:        my %storecontent = ($storeunder         => time,
                   9777:                            $storeunder.'.type' => 'date_start');
                   9778:        
                   9779:        $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541     raeburn  9780:                  ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444     albertel 9781:    }
                   9782: #
                   9783: # Set first page
                   9784: #
                   9785:     unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
                   9786: 	    || ($cloneid)) {
1.445     albertel 9787: 	use LONCAPA::map;
1.444     albertel 9788: 	$outcome .= &mt('Setting first resource').': ';
1.445     albertel 9789: 
                   9790: 	my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
                   9791:         my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
                   9792: 
1.444     albertel 9793:         $outcome .= ($fatal?$errtext:'read ok').' - ';
                   9794:         my $title; my $url;
                   9795:         if ($args->{'firstres'} eq 'syl') {
1.690     bisitz   9796: 	    $title=&mt('Syllabus');
1.444     albertel 9797:             $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
                   9798:         } else {
1.690     bisitz   9799:             $title=&mt('Navigate Contents');
1.444     albertel 9800:             $url='/adm/navmaps';
                   9801:         }
1.445     albertel 9802: 
                   9803:         $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
                   9804: 	(my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
                   9805: 
                   9806: 	if ($errtext) { $fatal=2; }
1.541     raeburn  9807:         $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444     albertel 9808:     }
1.566     albertel 9809: 
                   9810:     return (1,$outcome);
1.444     albertel 9811: }
                   9812: 
                   9813: ############################################################
                   9814: ############################################################
                   9815: 
1.378     raeburn  9816: sub course_type {
                   9817:     my ($cid) = @_;
                   9818:     if (!defined($cid)) {
                   9819:         $cid = $env{'request.course.id'};
                   9820:     }
1.404     albertel 9821:     if (defined($env{'course.'.$cid.'.type'})) {
                   9822:         return $env{'course.'.$cid.'.type'};
1.378     raeburn  9823:     } else {
                   9824:         return 'Course';
1.377     raeburn  9825:     }
                   9826: }
1.156     albertel 9827: 
1.406     raeburn  9828: sub group_term {
                   9829:     my $crstype = &course_type();
                   9830:     my %names = (
                   9831:                   'Course' => 'group',
                   9832:                   'Group' => 'team',
                   9833:                 );
                   9834:     return $names{$crstype};
                   9835: }
                   9836: 
1.156     albertel 9837: sub icon {
                   9838:     my ($file)=@_;
1.505     albertel 9839:     my $curfext = lc((split(/\./,$file))[-1]);
1.168     albertel 9840:     my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156     albertel 9841:     my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168     albertel 9842:     if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
                   9843: 	if (-e  $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
                   9844: 	          $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   9845: 	            $curfext.".gif") {
                   9846: 	    $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
                   9847: 		$curfext.".gif";
                   9848: 	}
                   9849:     }
1.249     albertel 9850:     return &lonhttpdurl($iconname);
1.154     albertel 9851: } 
1.84      albertel 9852: 
1.575     albertel 9853: sub lonhttpdurl {
1.692     www      9854: #
                   9855: # Had been used for "small fry" static images on separate port 8080.
                   9856: # Modify here if lightweight http functionality desired again.
                   9857: # Currently eliminated due to increasing firewall issues.
                   9858: #
1.575     albertel 9859:     my ($url)=@_;
1.692     www      9860:     return $url;
1.215     albertel 9861: }
                   9862: 
1.213     albertel 9863: sub connection_aborted {
                   9864:     my ($r)=@_;
                   9865:     $r->print(" ");$r->rflush();
                   9866:     my $c = $r->connection;
                   9867:     return $c->aborted();
                   9868: }
                   9869: 
1.221     foxr     9870: #    Escapes strings that may have embedded 's that will be put into
1.222     foxr     9871: #    strings as 'strings'.
                   9872: sub escape_single {
1.221     foxr     9873:     my ($input) = @_;
1.223     albertel 9874:     $input =~ s/\\/\\\\/g;	# Escape the \'s..(must be first)>
1.221     foxr     9875:     $input =~ s/\'/\\\'/g;	# Esacpe the 's....
                   9876:     return $input;
                   9877: }
1.223     albertel 9878: 
1.222     foxr     9879: #  Same as escape_single, but escape's "'s  This 
                   9880: #  can be used for  "strings"
                   9881: sub escape_double {
                   9882:     my ($input) = @_;
                   9883:     $input =~ s/\\/\\\\/g;	# Escape the /'s..(must be first)>
                   9884:     $input =~ s/\"/\\\"/g;	# Esacpe the "s....
                   9885:     return $input;
                   9886: }
1.223     albertel 9887:  
1.222     foxr     9888: #   Escapes the last element of a full URL.
                   9889: sub escape_url {
                   9890:     my ($url)   = @_;
1.238     raeburn  9891:     my @urlslices = split(/\//, $url,-1);
1.369     www      9892:     my $lastitem = &escape(pop(@urlslices));
1.223     albertel 9893:     return join('/',@urlslices).'/'.$lastitem;
1.222     foxr     9894: }
1.462     albertel 9895: 
                   9896: # -------------------------------------------------------- Initliaze user login
                   9897: sub init_user_environment {
1.463     albertel 9898:     my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462     albertel 9899:     my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
                   9900: 
                   9901:     my $public=($username eq 'public' && $domain eq 'public');
                   9902: 
                   9903: # See if old ID present, if so, remove
                   9904: 
                   9905:     my ($filename,$cookie,$userroles);
                   9906:     my $now=time;
                   9907: 
                   9908:     if ($public) {
                   9909: 	my $max_public=100;
                   9910: 	my $oldest;
                   9911: 	my $oldest_time=0;
                   9912: 	for(my $next=1;$next<=$max_public;$next++) {
                   9913: 	    if (-e $lonids."/publicuser_$next.id") {
                   9914: 		my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
                   9915: 		if ($mtime<$oldest_time || !$oldest_time) {
                   9916: 		    $oldest_time=$mtime;
                   9917: 		    $oldest=$next;
                   9918: 		}
                   9919: 	    } else {
                   9920: 		$cookie="publicuser_$next";
                   9921: 		last;
                   9922: 	    }
                   9923: 	}
                   9924: 	if (!$cookie) { $cookie="publicuser_$oldest"; }
                   9925:     } else {
1.463     albertel 9926: 	# if this isn't a robot, kill any existing non-robot sessions
                   9927: 	if (!$args->{'robot'}) {
                   9928: 	    opendir(DIR,$lonids);
                   9929: 	    while ($filename=readdir(DIR)) {
                   9930: 		if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
                   9931: 		    unlink($lonids.'/'.$filename);
                   9932: 		}
1.462     albertel 9933: 	    }
1.463     albertel 9934: 	    closedir(DIR);
1.462     albertel 9935: 	}
                   9936: # Give them a new cookie
1.463     albertel 9937: 	my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684     www      9938: 		                   : $now.$$.int(rand(10000)));
1.463     albertel 9939: 	$cookie="$username\_$id\_$domain\_$authhost";
1.462     albertel 9940:     
                   9941: # Initialize roles
                   9942: 
                   9943: 	$userroles=&Apache::lonnet::rolesinit($domain,$username,$authhost);
                   9944:     }
                   9945: # ------------------------------------ Check browser type and MathML capability
                   9946: 
                   9947:     my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
                   9948:         $clientunicode,$clientos) = &decode_user_agent($r);
                   9949: 
                   9950: # -------------------------------------- Any accessibility options to remember?
                   9951:     if (($form->{'interface'}) && ($form->{'remember'} eq 'true')) {
                   9952: 	foreach my $option ('imagesuppress','appletsuppress',
                   9953: 			    'embedsuppress','fontenhance','blackwhite') {
                   9954: 	    if ($form->{$option} eq 'true') {
                   9955: 		&Apache::lonnet::put('environment',{$option => 'on'},
                   9956: 				     $domain,$username);
                   9957: 	    } else {
                   9958: 		&Apache::lonnet::del('environment',[$option],
                   9959: 				     $domain,$username);
                   9960: 	    }
                   9961: 	}
                   9962:     }
                   9963: # ------------------------------------------------------------- Get environment
                   9964: 
                   9965:     my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
                   9966:     my ($tmp) = keys(%userenv);
                   9967:     if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
                   9968: 	# default remote control to off
                   9969: 	if ($userenv{'remote'} ne 'on') { $userenv{'remote'} = 'off'; }
                   9970:     } else {
                   9971: 	undef(%userenv);
                   9972:     }
                   9973:     if (($userenv{'interface'}) && (!$form->{'interface'})) {
                   9974: 	$form->{'interface'}=$userenv{'interface'};
                   9975:     }
                   9976:     $env{'environment.remote'}=$userenv{'remote'};
                   9977:     if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
                   9978: 
                   9979: # --------------- Do not trust query string to be put directly into environment
                   9980:     foreach my $option ('imagesuppress','appletsuppress',
                   9981: 			'embedsuppress','fontenhance','blackwhite',
                   9982: 			'interface','localpath','localres') {
                   9983: 	$form->{$option}=~s/[\n\r\=]//gs;
                   9984:     }
                   9985: # --------------------------------------------------------- Write first profile
                   9986: 
                   9987:     {
                   9988: 	my %initial_env = 
                   9989: 	    ("user.name"          => $username,
                   9990: 	     "user.domain"        => $domain,
                   9991: 	     "user.home"          => $authhost,
                   9992: 	     "browser.type"       => $clientbrowser,
                   9993: 	     "browser.version"    => $clientversion,
                   9994: 	     "browser.mathml"     => $clientmathml,
                   9995: 	     "browser.unicode"    => $clientunicode,
                   9996: 	     "browser.os"         => $clientos,
                   9997: 	     "server.domain"      => $Apache::lonnet::perlvar{'lonDefDomain'},
                   9998: 	     "request.course.fn"  => '',
                   9999: 	     "request.course.uri" => '',
                   10000: 	     "request.course.sec" => '',
                   10001: 	     "request.role"       => 'cm',
                   10002: 	     "request.role.adv"   => $env{'user.adv'},
                   10003: 	     "request.host"       => $ENV{'REMOTE_ADDR'},);
                   10004: 
                   10005:         if ($form->{'localpath'}) {
                   10006: 	    $initial_env{"browser.localpath"}  = $form->{'localpath'};
                   10007: 	    $initial_env{"browser.localres"}   = $form->{'localres'};
                   10008:         }
                   10009: 	
                   10010: 	if ($public) {
                   10011: 	    $initial_env{"environment.remote"} = "off";
                   10012: 	}
                   10013: 	if ($form->{'interface'}) {
                   10014: 	    $form->{'interface'}=~s/\W//gs;
                   10015: 	    $initial_env{"browser.interface"} = $form->{'interface'};
                   10016: 	    $env{'browser.interface'}=$form->{'interface'};
                   10017: 	    foreach my $option ('imagesuppress','appletsuppress',
                   10018: 				'embedsuppress','fontenhance','blackwhite') {
                   10019: 		if (($form->{$option} eq 'true') ||
                   10020: 		    ($userenv{$option} eq 'on')) {
                   10021: 		    $initial_env{"browser.$option"} = "on";
                   10022: 		}
                   10023: 	    }
                   10024: 	}
                   10025: 
1.724     raeburn  10026:         foreach my $tool ('aboutme','blog','portfolio') {
                   10027:             $userenv{'availabletools.'.$tool} = 
                   10028:                 &Apache::lonnet::usertools_access($username,$domain,$tool,'reload');
                   10029:         }
                   10030: 
1.765     raeburn  10031:         foreach my $crstype ('official','unofficial') {
                   10032:             $userenv{'canrequest.'.$crstype} =
                   10033:                 &Apache::lonnet::usertools_access($username,$domain,$crstype,
                   10034:                                                   'reload','requestcourses');
                   10035:         }
                   10036: 
1.462     albertel 10037: 	$env{'user.environment'} = "$lonids/$cookie.id";
                   10038: 	
                   10039: 	if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
                   10040: 		 &GDBM_WRCREAT(),0640)) {
                   10041: 	    &_add_to_env(\%disk_env,\%initial_env);
                   10042: 	    &_add_to_env(\%disk_env,\%userenv,'environment.');
                   10043: 	    &_add_to_env(\%disk_env,$userroles);
1.463     albertel 10044: 	    if (ref($args->{'extra_env'})) {
                   10045: 		&_add_to_env(\%disk_env,$args->{'extra_env'});
                   10046: 	    }
1.462     albertel 10047: 	    untie(%disk_env);
                   10048: 	} else {
1.705     tempelho 10049: 	    &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
                   10050: 			   'Could not create environment storage in lonauth: '.$!.'</span>');
1.462     albertel 10051: 	    return 'error: '.$!;
                   10052: 	}
                   10053:     }
                   10054:     $env{'request.role'}='cm';
                   10055:     $env{'request.role.adv'}=$env{'user.adv'};
                   10056:     $env{'browser.type'}=$clientbrowser;
                   10057: 
                   10058:     return $cookie;
                   10059: 
                   10060: }
                   10061: 
                   10062: sub _add_to_env {
                   10063:     my ($idf,$env_data,$prefix) = @_;
1.676     raeburn  10064:     if (ref($env_data) eq 'HASH') {
                   10065:         while (my ($key,$value) = each(%$env_data)) {
                   10066: 	    $idf->{$prefix.$key} = $value;
                   10067: 	    $env{$prefix.$key}   = $value;
                   10068:         }
1.462     albertel 10069:     }
                   10070: }
                   10071: 
1.685     tempelho 10072: # --- Get the symbolic name of a problem and the url
                   10073: sub get_symb {
                   10074:     my ($request,$silent) = @_;
1.726     raeburn  10075:     (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685     tempelho 10076:     my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
                   10077:     if ($symb eq '') {
                   10078:         if (!$silent) {
                   10079:             $request->print("Unable to handle ambiguous references:$url:.");
                   10080:             return ();
                   10081:         }
                   10082:     }
                   10083:     &Apache::lonenc::check_decrypt(\$symb);
                   10084:     return ($symb);
                   10085: }
                   10086: 
                   10087: # --------------------------------------------------------------Get annotation
                   10088: 
                   10089: sub get_annotation {
                   10090:     my ($symb,$enc) = @_;
                   10091: 
                   10092:     my $key = $symb;
                   10093:     if (!$enc) {
                   10094:         $key =
                   10095:             &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
                   10096:     }
                   10097:     my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
                   10098:     return $annotation{$key};
                   10099: }
                   10100: 
                   10101: sub clean_symb {
1.731     raeburn  10102:     my ($symb,$delete_enc) = @_;
1.685     tempelho 10103: 
                   10104:     &Apache::lonenc::check_decrypt(\$symb);
                   10105:     my $enc = $env{'request.enc'};
1.731     raeburn  10106:     if ($delete_enc) {
1.730     raeburn  10107:         delete($env{'request.enc'});
                   10108:     }
1.685     tempelho 10109: 
                   10110:     return ($symb,$enc);
                   10111: }
1.462     albertel 10112: 
1.41      ng       10113: =pod
                   10114: 
                   10115: =back
                   10116: 
1.112     bowersj2 10117: =cut
1.41      ng       10118: 
1.112     bowersj2 10119: 1;
                   10120: __END__;
1.41      ng       10121: 

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